@tpsdev-ai/flair 0.62.0 → 0.63.1
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 +14 -13
- package/SECURITY.md +73 -43
- package/config.yaml +11 -11
- package/dist/bridges/runtime/execute.js +1 -0
- package/dist/bridges/runtime/import-runner.js +4 -0
- package/dist/bridges/types.js +1 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +309 -205
- package/dist/commands/agent.js +325 -137
- package/dist/commands/attention.js +2 -0
- package/dist/commands/backup-approval.js +218 -0
- package/dist/commands/backup.js +37 -33
- package/dist/commands/bootstrap.js +5 -1
- package/dist/commands/bridge.js +10 -0
- package/dist/commands/deploy.js +37 -7
- package/dist/commands/doctor.js +206 -42
- package/dist/commands/export.js +144 -15
- package/dist/commands/federation.js +653 -68
- package/dist/commands/grant.js +5 -6
- package/dist/commands/help.js +25 -0
- package/dist/commands/idp.js +14 -19
- package/dist/commands/import.js +167 -34
- package/dist/commands/init.js +380 -164
- package/dist/commands/integrity.js +5 -6
- package/dist/commands/keys.js +12 -8
- package/dist/commands/mcp.js +157 -79
- package/dist/commands/memory.js +38 -17
- package/dist/commands/migrate-harness-memory.js +9 -3
- package/dist/commands/orgevent.js +5 -10
- package/dist/commands/principal.js +32 -39
- package/dist/commands/quality.js +26 -3
- package/dist/commands/reembed.js +468 -111
- package/dist/commands/rem.js +484 -65
- package/dist/commands/restore.js +352 -44
- package/dist/commands/search.js +2 -0
- package/dist/commands/service.js +109 -2
- package/dist/commands/soul.js +0 -6
- package/dist/commands/status.js +165 -124
- package/dist/commands/test.js +4 -1
- package/dist/commands/upgrade.js +53 -22
- package/dist/commands/workspace.js +7 -8
- package/dist/deploy.js +59 -3
- package/dist/doctor-client.js +9 -25
- package/dist/fabric-upgrade.js +12 -2
- package/dist/federation/presence-send.js +139 -0
- package/dist/federation/scheduler.js +148 -12
- package/dist/federation-verify.js +269 -177
- package/dist/install/clients.js +171 -35
- package/dist/keystore.js +77 -10
- package/dist/lib/agent-id-rule.js +44 -2
- package/dist/lib/agent-key-file.js +509 -0
- package/dist/lib/agent-rotation-lock.js +249 -0
- package/dist/lib/atomic-write.js +3 -3
- package/dist/lib/auth-resolve.js +1040 -64
- package/dist/lib/backup-approval-store.js +612 -0
- package/dist/lib/backup-artifact.js +343 -0
- package/dist/lib/config-critical-section.js +212 -25
- package/dist/lib/connect-phase.js +33 -0
- package/dist/lib/daemon-liveness.js +2 -1
- 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/instruction-event-contract.js +17 -0
- package/dist/lib/instruction-event-doctor.js +102 -0
- package/dist/lib/key-dir.js +203 -0
- package/dist/lib/launchd-management.js +21 -6
- package/dist/lib/local-instance-pair.js +8 -1
- package/dist/lib/mcp-enable.js +14 -15
- package/dist/lib/memory-attributes.js +2 -0
- package/dist/lib/memory-provider-timeout.js +33 -0
- package/dist/lib/mqtt-config.js +132 -0
- package/dist/lib/mqtt-listener-doctor.js +104 -0
- package/dist/lib/node-alias-path.js +50 -2
- package/dist/lib/open-live-row.js +20 -0
- package/dist/lib/ops-url.js +52 -0
- package/dist/lib/promotion-content-hash.js +20 -0
- package/dist/lib/remote-admin-pass.js +157 -0
- package/dist/lib/restore-archive.js +760 -0
- package/dist/lib/restore-verify.js +1 -1
- package/dist/lib/scheduler-platform.js +13 -0
- package/dist/lib/service-repoint.js +13 -4
- package/dist/lib/skill-assignment-preflight.js +159 -0
- package/dist/lib/skill-seed.js +125 -10
- package/dist/lib/skill-tombstone-doctor.js +133 -0
- package/dist/lib/soul-scope-fields.js +26 -0
- package/dist/lib/terminal-text.js +32 -0
- package/dist/lib/uninstall-purge.js +266 -11
- package/dist/lib/upgrade-prior-liveness.js +2 -1
- package/dist/mcp-client-assertion.js +7 -14
- package/dist/memory-id-checkpoint.js +28 -7
- package/dist/mqtt-off-deploy.js +550 -0
- package/dist/rem/promote-policy.js +3 -3
- package/dist/rem/restore.js +302 -26
- package/dist/rem/runner.js +220 -58
- 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 +155 -45
- package/dist/resources/AgentCard.js +4 -0
- package/dist/resources/AgentKeyRegister.js +56 -22
- package/dist/resources/AgentReadPosition.js +7 -0
- package/dist/resources/AgentSeed.js +232 -107
- package/dist/resources/AutoPromoteCandidates.js +413 -84
- package/dist/resources/Credential.js +6 -8
- package/dist/resources/Federation.js +219 -57
- package/dist/resources/FederationRetry.js +4 -4
- package/dist/resources/InstructionVersion.js +1 -1
- package/dist/resources/MCPClientMetadata.js +6 -3
- package/dist/resources/Memory.js +1348 -271
- package/dist/resources/MemoryArchive.js +149 -64
- package/dist/resources/MemoryBootstrap.js +12 -22
- package/dist/resources/MemoryCandidate.js +16 -2
- package/dist/resources/MemoryConsolidate.js +2 -2
- package/dist/resources/MemoryFeed.js +360 -147
- package/dist/resources/MemoryMaintenance.js +290 -72
- package/dist/resources/MemoryPurge.js +138 -22
- package/dist/resources/MemoryReflect.js +68 -14
- package/dist/resources/MemoryReindex.js +91 -13
- package/dist/resources/Message.js +11 -2
- package/dist/resources/OAuth.js +156 -39
- package/dist/resources/OAuthClient.js +1 -1
- package/dist/resources/OrgEvent.js +292 -29
- 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 +31 -11
- package/dist/resources/PromoteMemoryCandidate.js +8 -2
- package/dist/resources/RecordUsage.js +2 -4
- package/dist/resources/Soul.js +2 -0
- package/dist/resources/SoulFeed.js +2 -1
- package/dist/resources/WorkspaceLatest.js +4 -0
- package/dist/resources/XAA.js +36 -10
- 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 +98 -68
- 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 +166 -42
- 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/embeddings-provider.js +25 -0
- package/dist/resources/federation-classify.js +89 -0
- package/dist/resources/federation-retry-lib.js +6 -81
- package/dist/resources/health.js +75 -19
- package/dist/resources/host-pointer/registry.js +29 -0
- package/dist/resources/host-pointer-adapter.js +1 -0
- package/dist/resources/in-process-api.js +74 -11
- package/dist/resources/in-process.js +24 -22
- package/dist/resources/instruction-version-record.js +251 -7
- package/dist/resources/internal-authority.js +13 -0
- package/dist/resources/mcp-client-metadata-fields.js +4 -0
- package/dist/resources/mcp-handler.js +146 -13
- package/dist/resources/mcp-oauth-flag.js +12 -14
- package/dist/resources/mcp-oauth.js +446 -53
- package/dist/resources/mcp-tool-scopes.js +69 -0
- package/dist/resources/mcp-tools.js +70 -22
- package/dist/resources/memory-declared-attributes.js +1 -0
- package/dist/resources/memory-embed-hash.js +56 -0
- package/dist/resources/memory-host-source.js +5 -2
- package/dist/resources/memory-reflect-lib.js +1 -1
- package/dist/resources/memory-write-lock.js +202 -23
- package/dist/resources/memory-write-response.js +1 -1
- 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 +16 -3
- package/dist/resources/migrations/dir-safety.js +60 -2
- package/dist/resources/migrations/embedding-stamp.js +315 -49
- package/dist/resources/migrations/graph-heal.js +9 -2
- package/dist/resources/migrations/ledger.js +5 -2
- package/dist/resources/migrations/lock.js +867 -80
- package/dist/resources/migrations/progress.js +71 -10
- package/dist/resources/migrations/runner.js +212 -18
- package/dist/resources/migrations/state.js +36 -1
- package/dist/resources/migrations/status.js +2 -13
- package/dist/resources/migrations/synthetic-test-migration.js +78 -12
- package/dist/resources/migrations/types.js +26 -1
- package/dist/resources/migrations/visibility-backfill.js +111 -70
- package/dist/resources/oauth-discovery.js +0 -5
- package/dist/resources/object-body-guard.js +12 -5
- package/dist/resources/org-event-reserved.js +92 -0
- package/dist/resources/org-event-write-fault.js +19 -0
- package/dist/resources/owner-field-guard.js +1 -1
- package/dist/resources/owner-scoped-write-policy.js +65 -21
- package/dist/resources/owner-scoped-writes.js +37 -6
- package/dist/resources/path-id-rewrite.js +76 -0
- package/dist/resources/presence-internal.js +5 -5
- package/dist/resources/promotion-binding.js +43 -0
- package/dist/resources/promotion-stamp.js +124 -33
- package/dist/resources/protocol-context.js +189 -0
- package/dist/resources/record-type-kit.js +2 -4
- package/dist/resources/request-target.js +28 -1
- package/dist/resources/request-transaction.js +11 -1
- package/dist/resources/seed-reservation.js +1 -2
- package/dist/resources/semantic-retrieval-core.js +7 -6
- package/dist/resources/server-row-validation.js +71 -0
- package/dist/resources/skill-manifest.js +4 -3
- package/dist/resources/skill-version-write.js +400 -27
- package/dist/resources/skill-write-fault.js +6 -3
- package/dist/resources/skill-write-policy.js +2 -1
- package/dist/resources/soul-write-policy.js +26 -7
- package/dist/resources/table-helpers.js +1 -1
- package/dist/resources/table-subscription-policy.js +518 -85
- package/dist/resources/table-subscriptions.js +20 -7
- package/dist/resources/txn-pause-point.js +122 -5
- package/dist/resources/usage-recording.js +54 -46
- package/dist/resources/write-back.js +176 -11
- package/dist/resources/write-journal-context.js +5 -0
- package/dist/resources/write-journal.js +289 -0
- package/dist/src/keystore.js +77 -10
- package/dist/src/lib/agent-id-rule.js +44 -2
- package/dist/src/lib/atomic-write.js +3 -3
- package/dist/src/lib/federation-retry-row.js +101 -0
- package/dist/src/lib/instruction-event-contract.js +17 -0
- package/dist/src/lib/key-dir.js +203 -0
- package/dist/src/lib/memory-attributes.js +2 -0
- package/dist/src/lib/open-live-row.js +20 -0
- package/dist/src/lib/scheduler-platform.js +13 -0
- package/dist/src/lib/soul-scope-fields.js +26 -0
- package/dist/src/rem/promote-policy.js +3 -3
- package/dist/src/rem/scheduler.js +21 -4
- package/docs/access-control.md +39 -21
- package/docs/api-reference.md +161 -52
- package/docs/auth.md +69 -38
- package/docs/claude-code.md +3 -3
- package/docs/deploying-on-fabric.md +118 -2
- package/docs/deployment.md +17 -0
- package/docs/embedding-in-a-harper-app.md +23 -21
- package/docs/entity-vocabulary.md +7 -11
- package/docs/federation.md +29 -2
- package/docs/hosted-on-fabric.md +1 -1
- package/docs/integrations.md +11 -11
- package/docs/mcp-clients.md +7 -5
- package/docs/notes/mcp-agent-auth-consumer.md +4 -9
- package/docs/notes/mcp-oauth-model2.md +6 -6
- package/docs/openclaw.md +1 -1
- package/docs/quickstart-fabric.md +2 -2
- package/docs/quickstart.md +3 -3
- package/docs/releasing.md +13 -13
- package/docs/rem.md +24 -3
- package/docs/secrets-and-keys.md +9 -14
- package/docs/standalone-local.md +29 -2
- package/docs/supply-chain-policy.md +28 -20
- package/docs/the-team.md +2 -2
- package/docs/upgrade.md +29 -5
- package/package.json +18 -11
- package/schemas/agent.graphql +3 -3
- package/schemas/federation.graphql +10 -7
- package/schemas/memory.graphql +7 -2
- 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/doctor.js
CHANGED
|
@@ -8,8 +8,11 @@ import { ALL_CLIENTS, decideCodexPinOnly, decideJsonPinOnly, detectClients, wire
|
|
|
8
8
|
import { checkGlobalBinOnPath, resolveNpmGlobalPrefix } from "../install/global-bin-path.js";
|
|
9
9
|
import { buildEd25519Auth, defaultAdminPassPath, defaultKeysDir, requestTarget, requestUrl, resolveAdminUser, resolveKeyPath, resolveLocalAdminPass } from "../lib/auth-resolve.js";
|
|
10
10
|
import { proveLocalHarperListener } from "../lib/local-instance-pair.js";
|
|
11
|
-
import { AGENT_ID_RULE } from "../lib/agent-id-rule.js";
|
|
11
|
+
import { AGENT_ID_RULE, isValidAgentId } from "../lib/agent-id-rule.js";
|
|
12
12
|
import { agentHomeEndpoint, readAgentHomeRows, resolveTargetInstanceIdentity } from "../lib/agent-home.js";
|
|
13
|
+
import { describeInstructionEventImpostors, readInstructionEventTables } from "../lib/instruction-event-doctor.js";
|
|
14
|
+
import { describeLiveSkillTombstones, readSkillTombstoneTables } from "../lib/skill-tombstone-doctor.js";
|
|
15
|
+
import { MQTT_CONFIGURATION_NOTE, mqttListenerSection, readInstanceConfiguration } from "../lib/mqtt-listener-doctor.js";
|
|
13
16
|
import { readAgentRoster } from "../lib/agent-roster.js";
|
|
14
17
|
import { flairConfigYamlCandidates, readPortFromYamlFile, resolveFlairConfigYaml } from "../lib/doctor-config-path.js";
|
|
15
18
|
import { collectFederationEnv, describeFederationDriverFinding, federationPeersConfigured, loadYamlDoc } from "../lib/doctor-federation-driver.js";
|
|
@@ -19,6 +22,7 @@ import { describeEmbedGpuDoctorFinding } from "../lib/embed-gpu-doctor.js";
|
|
|
19
22
|
import { describeEmbeddingSpaceDoctorFinding } from "../lib/embedding-space-doctor.js";
|
|
20
23
|
import { adminPassDesyncFinding, detectPersistedAdminUser } from "../lib/init-admin-pass.js";
|
|
21
24
|
import { opsApiBindFinding } from "../lib/ops-api-bind.js";
|
|
25
|
+
import { agentKeyPath, formatKeyModeFinding, keyModesUnsupported, KEY_MODES_UNSUPPORTED_MESSAGE, scanAgentKeyModes, scanKeyDir, sameKeyDir } from "../lib/key-dir.js";
|
|
22
26
|
import { instanceIdentityLines, probeInstanceIdentity, } from "../lib/instance-identity-row.js";
|
|
23
27
|
import { flairCliVersion, unpinnedSpecWarning } from "../lib/mcp-spec.js";
|
|
24
28
|
import { discriminateMcpOAuthDiscovery, reportMcpOAuthDiscovery } from "../lib/mcp-enable.js";
|
|
@@ -310,8 +314,8 @@ export function renderEmbeddingSpaceDoctorFinding(embeddingSpace, write = (line)
|
|
|
310
314
|
* - `--fix` counts the divergence FIXED only after the unit was re-pointed,
|
|
311
315
|
* the instance restarted, and the serving tree re-proven to be this CLI's —
|
|
312
316
|
* "nothing to rewrite" or a failed restart is never a fix;
|
|
313
|
-
* - a federation-sync shim
|
|
314
|
-
*
|
|
317
|
+
* - a federation-sync shim the dry run would re-point is one issue, fixed
|
|
318
|
+
* only when re-pointed AND re-read as current or as a node pin.
|
|
315
319
|
*
|
|
316
320
|
* Extracted from the action (like renderEmbedGpuDoctorFinding) so the counting
|
|
317
321
|
* is exercised directly; the action passes the real adapters.
|
|
@@ -399,14 +403,15 @@ export async function runInstallTreeDoctorSection(mode, deps, write = (line) =>
|
|
|
399
403
|
break;
|
|
400
404
|
case "would-rewrite": {
|
|
401
405
|
issues++;
|
|
402
|
-
write(` ${bad} the federation-sync shim
|
|
406
|
+
write(` ${bad} the federation-sync shim would be re-pointed — ${f.detail}`);
|
|
403
407
|
if (mode.autoFix && mode.dryRun) {
|
|
404
408
|
write(` ${info} ${render.wrap(render.c.dim, "[dry-run] would re-point the shim's exec line (the scheduler unit is not rewritten)")}`);
|
|
405
409
|
}
|
|
406
410
|
else if (mode.autoFix) {
|
|
407
411
|
const r = deps.rewriteFederation(false);
|
|
408
412
|
const verify = r.status === "rewritten" ? deps.rewriteFederation(true) : null;
|
|
409
|
-
|
|
413
|
+
// A re-pointed Homebrew Cellar node that is not this CLI's node re-reads as a pin (flair#3056).
|
|
414
|
+
if (verify?.status === "current" || verify?.status === "pinned-node") {
|
|
410
415
|
fixed++;
|
|
411
416
|
write(` ${ok} ${r.detail}`);
|
|
412
417
|
}
|
|
@@ -453,6 +458,16 @@ export function register(program) {
|
|
|
453
458
|
.option("--dry-run", "Show what --fix would do without making changes")
|
|
454
459
|
.action(async (opts) => {
|
|
455
460
|
signedOnlyTransport = false; // flair#2526: decided per run, below
|
|
461
|
+
const namedAgentId = opts.agent ?? (process.env.FLAIR_AGENT_ID || undefined);
|
|
462
|
+
if (namedAgentId !== undefined) {
|
|
463
|
+
try {
|
|
464
|
+
agentKeyPath(defaultKeysDir(), namedAgentId);
|
|
465
|
+
}
|
|
466
|
+
catch (err) {
|
|
467
|
+
console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
468
|
+
process.exit(1);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
456
471
|
const port = resolveHttpPort(opts);
|
|
457
472
|
const autoFix = opts.fix ?? false;
|
|
458
473
|
const dryRun = opts.dryRun ?? false;
|
|
@@ -849,46 +864,59 @@ export function register(program) {
|
|
|
849
864
|
}
|
|
850
865
|
// 2. Keys directory
|
|
851
866
|
const keysDir = defaultKeysDir();
|
|
867
|
+
let keysDirUnreadable = false;
|
|
868
|
+
if (keyModesUnsupported()) {
|
|
869
|
+
console.log(` ${render.icons.info} ${render.wrap(render.c.dim, KEY_MODES_UNSUPPORTED_MESSAGE)}`);
|
|
870
|
+
}
|
|
852
871
|
if (existsSync(keysDir)) {
|
|
853
|
-
const
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
// inferred as, an agent. Partition them out here so every downstream
|
|
858
|
-
// consumer of keyAgentIds (registration checks, --fix inference,
|
|
859
|
-
// fixCommandAgentHint) is node-free by construction.
|
|
860
|
-
const partitioned = partitionKeyIds(keyFiles.map((f) => f.replace(/\.key$/, "")), keysDir);
|
|
861
|
-
keyAgentIds = partitioned.agentKeyIds;
|
|
862
|
-
nodeKeyIds = partitioned.nodeKeyIds;
|
|
863
|
-
if (keyAgentIds.length > 0) {
|
|
864
|
-
console.log(` ${render.icons.ok} Keys found: ${render.wrap(render.c.bold, String(keyAgentIds.length))} agent(s) in ${render.wrap(render.c.dim, keysDir)}`);
|
|
865
|
-
if (partitioned.nodeKeyIds.length > 0) {
|
|
866
|
-
console.log(` ${render.icons.info} ${render.wrap(render.c.dim, `${partitioned.nodeKeyIds.length} node-scoped federation key(s) present — not agent signing keys; skipping`)}`);
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
else if (partitioned.nodeKeyIds.length > 0) {
|
|
870
|
-
// Node keys but no agent key: functionally there is no agent identity
|
|
871
|
-
// here. Report it plainly (not the old DECODER false alarm) and point
|
|
872
|
-
// at the real remedy. Kept a warn — not an issues++ — so a genuine
|
|
873
|
-
// federation-only host doesn't newly fail doctor's exit code.
|
|
874
|
-
console.log(` ${render.icons.warn} No agent signing key found — only ${render.wrap(render.c.bold, String(nodeKeyIds.length))} node-scoped federation key(s) in ${render.wrap(render.c.dim, keysDir)}`);
|
|
875
|
-
console.log(` ${render.wrap(render.c.dim, "These are Fabric node keys, not agent identities. Fix:")} flair init --agent-id <your-agent>`);
|
|
876
|
-
}
|
|
877
|
-
else {
|
|
878
|
-
console.log(` ${render.icons.error} Keys directory exists but no .key files found`);
|
|
879
|
-
console.log(` ${render.wrap(render.c.dim, "Fix:")} flair init --agent-id <your-agent>`);
|
|
872
|
+
const keyScan = scanKeyDir(keysDir);
|
|
873
|
+
if (keyScan.state === "unreadable") {
|
|
874
|
+
// A keys directory doctor cannot read is not a clean result.
|
|
875
|
+
keysDirUnreadable = true;
|
|
880
876
|
issues++;
|
|
877
|
+
console.log(` ${render.icons.warn} Keys directory could not be read: ${render.wrap(render.c.dim, keysDir)} — key checks skipped`);
|
|
881
878
|
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
879
|
+
else {
|
|
880
|
+
const keyFiles = keyScan.entries.filter((e) => e.kind === "key").map((e) => e.name);
|
|
881
|
+
// ~/.flair/keys is shared by agent Ed25519 signing keys and node-scoped
|
|
882
|
+
// federation keys (flair#1193). Partition by file name (see
|
|
883
|
+
// partitionKeyIds): downstream consumers of keyAgentIds (registration
|
|
884
|
+
// checks, --fix inference, fixCommandAgentHint) skip ids classified as
|
|
885
|
+
// node keys. A node-shaped id with a sibling `.pub` is classified as an
|
|
886
|
+
// agent key.
|
|
887
|
+
const partitioned = partitionKeyIds(keyFiles.map((f) => f.replace(/\.key$/, "")), keysDir);
|
|
888
|
+
keyAgentIds = partitioned.agentKeyIds.filter((id) => isValidAgentId(id));
|
|
889
|
+
nodeKeyIds = partitioned.nodeKeyIds;
|
|
890
|
+
if (keyAgentIds.length > 0) {
|
|
891
|
+
console.log(` ${render.icons.ok} Keys found: ${render.wrap(render.c.bold, String(keyAgentIds.length))} agent(s) in ${render.wrap(render.c.dim, keysDir)}`);
|
|
892
|
+
if (partitioned.nodeKeyIds.length > 0) {
|
|
893
|
+
console.log(` ${render.icons.info} ${render.wrap(render.c.dim, `${partitioned.nodeKeyIds.length} node-scoped federation key(s) present — not agent signing keys; skipping`)}`);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
else if (partitioned.nodeKeyIds.length > 0) {
|
|
897
|
+
// Node keys but no agent key: functionally there is no agent identity
|
|
898
|
+
// here. Report it plainly (not the old DECODER false alarm) and point
|
|
899
|
+
// at the real remedy. Kept a warn — not an issues++ — so a genuine
|
|
900
|
+
// federation-only host doesn't newly fail doctor's exit code.
|
|
901
|
+
console.log(` ${render.icons.warn} No agent signing key found — only ${render.wrap(render.c.bold, String(nodeKeyIds.length))} node-scoped federation key(s) in ${render.wrap(render.c.dim, keysDir)}`);
|
|
902
|
+
console.log(` ${render.wrap(render.c.dim, "These are Fabric node keys, not agent identities. Fix:")} flair init --agent-id <your-agent>`);
|
|
885
903
|
}
|
|
886
904
|
else {
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
905
|
+
console.log(` ${render.icons.error} Keys directory exists but no .key files found`);
|
|
906
|
+
console.log(` ${render.wrap(render.c.dim, "Fix:")} flair init --agent-id <your-agent>`);
|
|
907
|
+
issues++;
|
|
908
|
+
}
|
|
909
|
+
if (nodeKeyIds.length > 0 && harperResponding) {
|
|
910
|
+
if (pairNotRun) {
|
|
911
|
+
reportPairNotRun("Node key instance check");
|
|
912
|
+
}
|
|
913
|
+
else {
|
|
914
|
+
const advisory = await readNodeSeedAdvisory({
|
|
915
|
+
nodeKeyIds, keysDir, baseUrl, port: opts.port, resolveHttpPort, resolveOpsPort,
|
|
916
|
+
});
|
|
917
|
+
if (advisory)
|
|
918
|
+
console.log(` ${render.icons.info} ${advisory}`);
|
|
919
|
+
}
|
|
892
920
|
}
|
|
893
921
|
}
|
|
894
922
|
}
|
|
@@ -897,6 +925,22 @@ export function register(program) {
|
|
|
897
925
|
console.log(` ${render.wrap(render.c.dim, "Fix:")} flair init --agent-id <your-agent>`);
|
|
898
926
|
issues++;
|
|
899
927
|
}
|
|
928
|
+
// Agent key files must be owner-only on POSIX (flair#3077). Read-only:
|
|
929
|
+
// this never changes a file. It covers the standard `resolveKeyPath` locations,
|
|
930
|
+
// not only the default keys directory.
|
|
931
|
+
if (!keyModesUnsupported()) {
|
|
932
|
+
const modeScan = scanAgentKeyModes();
|
|
933
|
+
for (const { dir, code } of modeScan.unreadable) {
|
|
934
|
+
if (keysDirUnreadable && sameKeyDir(dir, keysDir))
|
|
935
|
+
continue;
|
|
936
|
+
issues++;
|
|
937
|
+
console.log(` ${render.icons.warn} agent key directory ${render.wrap(render.c.dim, dir)} could not be read (${code}) — key file modes not checked`);
|
|
938
|
+
}
|
|
939
|
+
for (const finding of modeScan.findings) {
|
|
940
|
+
issues++;
|
|
941
|
+
console.log(` ${render.icons.warn} ${render.wrap(render.c.yellow, formatKeyModeFinding(finding))}`);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
900
944
|
// 3. Config file (flair#1514) — same resolution Harper uses: cwd, then
|
|
901
945
|
// the component/package dir, then ~/.flair. Looking only at
|
|
902
946
|
// ~/.flair/config.yaml printed "using defaults" on wrapper-launched
|
|
@@ -2261,7 +2305,7 @@ export function register(program) {
|
|
|
2261
2305
|
const registered = renderAgentGateHeader(gate);
|
|
2262
2306
|
if (!registered)
|
|
2263
2307
|
continue;
|
|
2264
|
-
const keyPath = resolveKeyPath(gate.id) ??
|
|
2308
|
+
const keyPath = resolveKeyPath(gate.id) ?? agentKeyPath(defaultKeysDir(), gate.id);
|
|
2265
2309
|
const headers = { Authorization: buildEd25519Auth(gate.id, "GET", requestTarget(presenceUrl), keyPath) };
|
|
2266
2310
|
await fetchAndRenderFleetPresence(headers, true, " ");
|
|
2267
2311
|
}
|
|
@@ -2362,6 +2406,122 @@ export function register(program) {
|
|
|
2362
2406
|
}
|
|
2363
2407
|
}
|
|
2364
2408
|
}
|
|
2409
|
+
// 8d. Instruction events (flair#2139 slice 3a) — name every stored
|
|
2410
|
+
// OrgEvent that carries a reserved kind or the reserved id prefix but
|
|
2411
|
+
// does not satisfy the reader rule. Read-only: nothing is rewritten.
|
|
2412
|
+
console.log(`\n ${render.wrap(render.c.bold, "Instruction events")}`);
|
|
2413
|
+
if (rosterNotRun) {
|
|
2414
|
+
issues++;
|
|
2415
|
+
console.log(` ${render.icons.warn} Instruction events: NOT RUN — ${rosterNotRun.reason}`);
|
|
2416
|
+
console.log(` ${render.wrap(render.c.dim, "Fix:")} ${rosterNotRun.remedy}`);
|
|
2417
|
+
}
|
|
2418
|
+
else if (!rosterAdminPass || rosterOpsPort === null) {
|
|
2419
|
+
console.log(` ${render.icons.info} Instruction-event check skipped (no admin credential or unverified ops endpoint).`);
|
|
2420
|
+
}
|
|
2421
|
+
else {
|
|
2422
|
+
const instructionAuth = `Basic ${Buffer.from(`${resolveAdminUser()}:${rosterAdminPass}`).toString("base64")}`;
|
|
2423
|
+
const tables = await readInstructionEventTables({
|
|
2424
|
+
opsUrl: `http://127.0.0.1:${rosterOpsPort}/`,
|
|
2425
|
+
authHeader: instructionAuth,
|
|
2426
|
+
timeoutMs: 5000,
|
|
2427
|
+
});
|
|
2428
|
+
if (tables === null) {
|
|
2429
|
+
issues++;
|
|
2430
|
+
console.log(` ${render.icons.warn} Could not read the stored OrgEvent and InstructionVersion tables, so the instruction-event check did not run.`);
|
|
2431
|
+
}
|
|
2432
|
+
else {
|
|
2433
|
+
const finding = describeInstructionEventImpostors(tables.events, tables.versions);
|
|
2434
|
+
if (!finding) {
|
|
2435
|
+
console.log(` ${render.icons.ok} No stored OrgEvent with a reserved kind or id fails the instruction-event reader rule.`);
|
|
2436
|
+
}
|
|
2437
|
+
else {
|
|
2438
|
+
issues++;
|
|
2439
|
+
console.log(` ${render.icons.warn} ${finding}`);
|
|
2440
|
+
console.log(` ${render.wrap(render.c.dim, "Fix:")} confirm it is not a genuine instruction event, then delete the row through the operations API.`);
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
// 8e. Skill tombstones (flair#2662) — for each skill subject whose
|
|
2445
|
+
// newest InstructionVersion is a `delete` tombstone, report the subject
|
|
2446
|
+
// when its Memory row is still open-live (the skill writer's predicate:
|
|
2447
|
+
// not archived, not expired, no validTo). Read-only: nothing is
|
|
2448
|
+
// rewritten. A table read that fails while this section runs is NOT RUN
|
|
2449
|
+
// and counted; when Harper is not responding, the enclosing gate skips
|
|
2450
|
+
// the section and doctor counts the server problem elsewhere.
|
|
2451
|
+
console.log(`\n ${render.wrap(render.c.bold, "Skill tombstones")}`);
|
|
2452
|
+
if (rosterNotRun) {
|
|
2453
|
+
issues++;
|
|
2454
|
+
console.log(` ${render.icons.warn} Skill tombstones: NOT RUN — ${rosterNotRun.reason}`);
|
|
2455
|
+
console.log(` ${render.wrap(render.c.dim, "Fix:")} ${rosterNotRun.remedy}`);
|
|
2456
|
+
}
|
|
2457
|
+
else if (!rosterAdminPass || rosterOpsPort === null) {
|
|
2458
|
+
issues++;
|
|
2459
|
+
const reason = rosterProbe.credIssue
|
|
2460
|
+
? `the admin credential could not be resolved (${rosterProbe.credIssue})`
|
|
2461
|
+
: rosterAdminPass ? "the ops endpoint was not verified" : "no admin credentials to read the stored tables";
|
|
2462
|
+
console.log(` ${render.icons.warn} Skill tombstones: NOT RUN — ${reason}.`);
|
|
2463
|
+
}
|
|
2464
|
+
else {
|
|
2465
|
+
const tombstoneAuth = `Basic ${Buffer.from(`${resolveAdminUser()}:${rosterAdminPass}`).toString("base64")}`;
|
|
2466
|
+
const tables = await readSkillTombstoneTables({
|
|
2467
|
+
opsUrl: `http://127.0.0.1:${rosterOpsPort}/`,
|
|
2468
|
+
authHeader: tombstoneAuth,
|
|
2469
|
+
timeoutMs: 5000,
|
|
2470
|
+
});
|
|
2471
|
+
if (tables === null) {
|
|
2472
|
+
issues++;
|
|
2473
|
+
console.log(` ${render.icons.warn} Could not read the stored InstructionVersion and Memory tables, so the skill-tombstone check did not run.`);
|
|
2474
|
+
}
|
|
2475
|
+
else {
|
|
2476
|
+
const finding = describeLiveSkillTombstones(tables.versions, tables.memories);
|
|
2477
|
+
if (!finding) {
|
|
2478
|
+
console.log(` ${render.icons.ok} No delete tombstone is the newest version of a skill with an open-live Memory row (not archived, not expired, no validTo).`);
|
|
2479
|
+
}
|
|
2480
|
+
else {
|
|
2481
|
+
issues++;
|
|
2482
|
+
console.log(` ${render.icons.warn} ${finding}`);
|
|
2483
|
+
console.log(` ${render.wrap(render.c.dim, "Report only:")} this check does not modify the store.`);
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
// 8f. MQTT listeners — report when the instance's root configuration
|
|
2488
|
+
// starts an MQTT listener (TCP, TLS or the WebSocket path). Flair runs
|
|
2489
|
+
// Harper with MQTT off; the read is the instance's own configuration,
|
|
2490
|
+
// through the same verified ops endpoint and admin credential as the
|
|
2491
|
+
// sections above. Read-only: nothing is changed. A configuration read
|
|
2492
|
+
// that fails, or an answer that is not a recognizable root
|
|
2493
|
+
// configuration (`{}` included), is NOT RUN and counted. It reports the
|
|
2494
|
+
// saved configuration, not the running listeners, and prints that note
|
|
2495
|
+
// on every path below, the two NOT RUN paths included.
|
|
2496
|
+
console.log(`\n ${render.wrap(render.c.bold, "MQTT listeners (configuration)")}`);
|
|
2497
|
+
if (rosterNotRun) {
|
|
2498
|
+
issues++;
|
|
2499
|
+
console.log(` ${render.icons.warn} MQTT listeners: NOT RUN — ${rosterNotRun.reason}`);
|
|
2500
|
+
console.log(` ${render.wrap(render.c.dim, MQTT_CONFIGURATION_NOTE)}`);
|
|
2501
|
+
console.log(` ${render.wrap(render.c.dim, "Fix:")} ${rosterNotRun.remedy}`);
|
|
2502
|
+
}
|
|
2503
|
+
else if (!rosterAdminPass || rosterOpsPort === null) {
|
|
2504
|
+
issues++;
|
|
2505
|
+
const reason = rosterProbe.credIssue
|
|
2506
|
+
? `the admin credential could not be resolved (${rosterProbe.credIssue})`
|
|
2507
|
+
: rosterAdminPass ? "the ops endpoint was not verified" : "no admin credentials to read the instance configuration";
|
|
2508
|
+
console.log(` ${render.icons.warn} MQTT listeners: NOT RUN — ${reason}.`);
|
|
2509
|
+
console.log(` ${render.wrap(render.c.dim, MQTT_CONFIGURATION_NOTE)}`);
|
|
2510
|
+
}
|
|
2511
|
+
else {
|
|
2512
|
+
const configuration = await readInstanceConfiguration({
|
|
2513
|
+
opsUrl: `http://127.0.0.1:${rosterOpsPort}/`,
|
|
2514
|
+
authHeader: `Basic ${Buffer.from(`${resolveAdminUser()}:${rosterAdminPass}`).toString("base64")}`,
|
|
2515
|
+
timeoutMs: 5000,
|
|
2516
|
+
});
|
|
2517
|
+
const section = mqttListenerSection(configuration);
|
|
2518
|
+
if (section.status !== "ok")
|
|
2519
|
+
issues++;
|
|
2520
|
+
console.log(` ${section.status === "ok" ? render.icons.ok : render.icons.warn} ${section.line}`);
|
|
2521
|
+
console.log(` ${render.wrap(render.c.dim, section.note)}`);
|
|
2522
|
+
if (section.fix)
|
|
2523
|
+
console.log(` ${render.wrap(render.c.dim, "Fix:")} ${section.fix}`);
|
|
2524
|
+
}
|
|
2365
2525
|
}
|
|
2366
2526
|
// 9. Migration state (flair#695) — pending/in-progress/blocked + last
|
|
2367
2527
|
// ledger-derived outcome per registered migration, read off the same
|
|
@@ -2394,7 +2554,7 @@ export function register(program) {
|
|
|
2394
2554
|
const passedGates = agentGates.filter((g) => describeAgentGateFinding(g.id, g.state, g.detail, { instanceReachable: harperResponding }) === null);
|
|
2395
2555
|
for (const gate of passedGates) {
|
|
2396
2556
|
renderAgentGateHeader(gate);
|
|
2397
|
-
const keyPath = resolveKeyPath(gate.id) ??
|
|
2557
|
+
const keyPath = resolveKeyPath(gate.id) ?? agentKeyPath(defaultKeysDir(), gate.id);
|
|
2398
2558
|
const headers = { Authorization: buildEd25519Auth(gate.id, "GET", requestTarget(healthDetailUrl), keyPath) };
|
|
2399
2559
|
issues += await fetchAndRenderMigrations(healthDetailUrl, headers, " ");
|
|
2400
2560
|
}
|
|
@@ -2488,6 +2648,9 @@ export function register(program) {
|
|
|
2488
2648
|
const lastExit = d.status.installed && d.status.active === true
|
|
2489
2649
|
? queryLastExitStatus({ plat: d.status.platform, darwinTarget: d.darwinTarget, linuxServiceUnit: d.linuxServiceUnit })
|
|
2490
2650
|
: null;
|
|
2651
|
+
// flair#3056: set when the unit file names the flair-generated shim as
|
|
2652
|
+
// its program and the node path on the shim's exec line does not exist.
|
|
2653
|
+
const shimMissingNode = d.kind === "federation" && d.status.installed ? fedSched.inspectFederationShimNode() : null;
|
|
2491
2654
|
const facts = {
|
|
2492
2655
|
label: d.label,
|
|
2493
2656
|
enableCommand: d.enableCommand,
|
|
@@ -2495,6 +2658,7 @@ export function register(program) {
|
|
|
2495
2658
|
installed: d.status.installed,
|
|
2496
2659
|
active: d.status.active,
|
|
2497
2660
|
lastExit,
|
|
2661
|
+
shimMissingNode,
|
|
2498
2662
|
stderrLogPath: d.stderrLogPath,
|
|
2499
2663
|
};
|
|
2500
2664
|
const finding = d.kind === "federation"
|
package/dist/commands/export.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { defaultKeysDir, resolveAdminUser } from "../lib/auth-resolve.js";
|
|
1
|
+
import { defaultKeysDir, resolveAdminUser, addAdminPassOptions } from "../lib/auth-resolve.js";
|
|
2
2
|
import * as render from "../render.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { closeSync, constants as fsConstants, existsSync, fsyncSync, linkSync, mkdirSync, openSync, readFileSync, realpathSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { randomBytes } from "node:crypto";
|
|
5
|
+
import { writeFilesAtomically } from "../lib/atomic-write.js";
|
|
6
|
+
import { invalidAgentIdMessage, isValidAgentId } from "../lib/agent-id-rule.js";
|
|
7
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
5
8
|
import { resolveHome } from "../lib/home.js";
|
|
6
9
|
import { encodeRecordId } from "../lib/record-id-path.js";
|
|
7
10
|
let cli;
|
|
@@ -19,6 +22,96 @@ const AGENT_REQUIRED_FIELDS = ["id", "name", "publicKey", "createdAt"];
|
|
|
19
22
|
const MEMORY_REQUIRED_FIELDS = ["id", "agentId", "content", "createdAt"];
|
|
20
23
|
const SOUL_REQUIRED_FIELDS = ["id", "agentId", "key", "value", "createdAt"];
|
|
21
24
|
const GRANT_REQUIRED_FIELDS = ["id", "ownerId", "granteeId", "scope"];
|
|
25
|
+
export function exportFileMode(outputPath, platform = process.platform) {
|
|
26
|
+
return platform === "win32" ? "mode bits are not enforced on Windows" : (statSync(outputPath).mode & 0o7777).toString(8);
|
|
27
|
+
}
|
|
28
|
+
/** The default export path for `agentId` inside `exportsDir`, or null when the
|
|
29
|
+
* resolved path is not a direct child of the resolved exports directory. */
|
|
30
|
+
export function defaultExportOutputPath(exportsDir, agentId, now = Date.now()) {
|
|
31
|
+
const dir = resolve(exportsDir);
|
|
32
|
+
const candidate = resolve(dir, `${agentId}-${now}.json`);
|
|
33
|
+
return dirname(candidate) === dir ? candidate : null;
|
|
34
|
+
}
|
|
35
|
+
/** The clock the default export name reads. `FLAIR_TEST_EXPORT_CLOCK_MS` fixes
|
|
36
|
+
* it so a test can plant a path at the exact default name. */
|
|
37
|
+
function defaultExportClockMs() {
|
|
38
|
+
const raw = process.env.FLAIR_TEST_EXPORT_CLOCK_MS;
|
|
39
|
+
const parsed = raw === undefined ? NaN : Number(raw);
|
|
40
|
+
return Number.isFinite(parsed) ? parsed : Date.now();
|
|
41
|
+
}
|
|
42
|
+
/** The file operations `writeDefaultExport` performs. A test replaces a member
|
|
43
|
+
* to inject a failure through the module seam. */
|
|
44
|
+
export const defaultExportWriteOps = {
|
|
45
|
+
openTemp: (tempPath, mode) => openSync(tempPath, fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_EXCL | (fsConstants.O_NOFOLLOW ?? 0), mode),
|
|
46
|
+
write: (fd, content) => { writeFileSync(fd, content); },
|
|
47
|
+
fsync: (fd) => { fsyncSync(fd); },
|
|
48
|
+
close: (fd) => { closeSync(fd); },
|
|
49
|
+
link: (tempPath, outputPath) => { linkSync(tempPath, outputPath); },
|
|
50
|
+
unlink: (path) => { unlinkSync(path); },
|
|
51
|
+
};
|
|
52
|
+
/** Report a temp file this call could not remove. */
|
|
53
|
+
function removeExportTemp(tempPath) {
|
|
54
|
+
try {
|
|
55
|
+
defaultExportWriteOps.unlink(tempPath);
|
|
56
|
+
}
|
|
57
|
+
catch (cleanupErr) {
|
|
58
|
+
console.error(`Error: failed to remove the temporary export at ${tempPath}: ${cleanupErr instanceof Error ? cleanupErr.message : String(cleanupErr)}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** With no concurrent changes to directory entries by another writer, write
|
|
62
|
+
* `content` to a complete temp file in the same directory and link it to
|
|
63
|
+
* `outputPath`. An existing path — file, symlink or anything else — is refused
|
|
64
|
+
* and survives. A failed write, fsync, close or link attempts to remove only this
|
|
65
|
+
* call's temp; a failed removal is reported with its path. */
|
|
66
|
+
function writeDefaultExport(outputPath, content, mode) {
|
|
67
|
+
const name = basename(outputPath);
|
|
68
|
+
let tempPath = "";
|
|
69
|
+
let fd;
|
|
70
|
+
for (let attempt = 0; attempt < 5 && fd === undefined; attempt += 1) {
|
|
71
|
+
const candidate = join(dirname(outputPath), `.${name}.tmp-${randomBytes(8).toString("hex")}`);
|
|
72
|
+
try {
|
|
73
|
+
fd = defaultExportWriteOps.openTemp(candidate, mode);
|
|
74
|
+
tempPath = candidate;
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (err.code !== "EEXIST" || attempt === 4)
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (fd === undefined)
|
|
82
|
+
throw new Error(`could not create a temporary export beside ${outputPath}`);
|
|
83
|
+
try {
|
|
84
|
+
defaultExportWriteOps.write(fd, content);
|
|
85
|
+
defaultExportWriteOps.fsync(fd);
|
|
86
|
+
const owned = fd;
|
|
87
|
+
fd = undefined;
|
|
88
|
+
defaultExportWriteOps.close(owned);
|
|
89
|
+
try {
|
|
90
|
+
defaultExportWriteOps.link(tempPath, outputPath);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
if (err.code === "EEXIST") {
|
|
94
|
+
removeExportTemp(tempPath);
|
|
95
|
+
console.error(`Error: refusing to write to existing path ${outputPath}`);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (fd !== undefined) {
|
|
103
|
+
try {
|
|
104
|
+
defaultExportWriteOps.close(fd);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// The original write or fsync failure is what this call reports.
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
removeExportTemp(tempPath);
|
|
111
|
+
throw err;
|
|
112
|
+
}
|
|
113
|
+
removeExportTemp(tempPath);
|
|
114
|
+
}
|
|
22
115
|
function hasRequiredStringFields(value, fields) {
|
|
23
116
|
return !!value
|
|
24
117
|
&& typeof value === "object"
|
|
@@ -27,17 +120,21 @@ function hasRequiredStringFields(value, fields) {
|
|
|
27
120
|
}
|
|
28
121
|
export function register(program) {
|
|
29
122
|
// ─── flair export ────────────────────────────────────────────────────────────
|
|
30
|
-
program
|
|
123
|
+
addAdminPassOptions(program
|
|
31
124
|
.command("export <agent-id>")
|
|
32
125
|
.description("Export a single agent's identity (soul + memories) to a portable file")
|
|
33
126
|
.option("--output <path>", "Output file path")
|
|
34
127
|
.option("--include-key", "Include private key in export (UNENCRYPTED — keep the output file secure)")
|
|
35
128
|
.option("--port <port>", "Harper HTTP port")
|
|
36
|
-
.option("--url <url>", "Flair base URL (overrides --port)")
|
|
37
|
-
.option("--admin-pass <pass>", "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
129
|
+
.option("--url <url>", "Flair base URL (overrides --port)"), "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
38
130
|
.option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
|
|
39
131
|
.option("--keys-dir <dir>", "Keys directory", defaultKeysDir())
|
|
40
132
|
.action(async (agentId, opts) => {
|
|
133
|
+
// flair#3136 — the ONE agent-ID rule, before this action reads export data or a key or writes its file.
|
|
134
|
+
if (!isValidAgentId(agentId)) {
|
|
135
|
+
console.error(`Error: ${invalidAgentIdMessage(agentId)}`);
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
41
138
|
const baseUrl = opts.url ?? `http://127.0.0.1:${resolveHttpPort(opts)}`;
|
|
42
139
|
const adminPass = opts.adminPass ?? process.env.FLAIR_ADMIN_PASS ?? "";
|
|
43
140
|
if (!adminPass) {
|
|
@@ -123,14 +220,46 @@ export function register(program) {
|
|
|
123
220
|
grants,
|
|
124
221
|
...(privateKey ? { privateKey } : {}),
|
|
125
222
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
223
|
+
let outputPath;
|
|
224
|
+
let wroteDefault = false;
|
|
225
|
+
if (opts.output !== undefined) {
|
|
226
|
+
outputPath = resolve(opts.output);
|
|
227
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
const home = resolveHome();
|
|
231
|
+
const exportsDir = join(home, ".flair", "exports");
|
|
232
|
+
const lexicalPath = defaultExportOutputPath(exportsDir, agentId, defaultExportClockMs());
|
|
233
|
+
if (lexicalPath === null) {
|
|
234
|
+
console.error(`Error: refusing to write agent '${agentId}' outside the exports directory ${resolve(exportsDir)}`);
|
|
235
|
+
process.exit(1);
|
|
236
|
+
}
|
|
237
|
+
mkdirSync(dirname(lexicalPath), { recursive: true });
|
|
238
|
+
// The exports directory must be the one under the REAL home. Checked once,
|
|
239
|
+
// after the directory exists and before any temp file is created; a
|
|
240
|
+
// concurrent replacement of .flair or exports between this check and the
|
|
241
|
+
// write is not prevented: the Node filesystem API used here has no directory-relative
|
|
242
|
+
// create or link anchored to a held directory descriptor.
|
|
243
|
+
const resolvedExports = realpathSync(exportsDir);
|
|
244
|
+
if (resolvedExports !== join(realpathSync(home), ".flair", "exports")) {
|
|
245
|
+
console.error(`Error: refusing to write agent '${agentId}' outside the exports directory ${resolve(exportsDir)}`);
|
|
246
|
+
process.exit(1);
|
|
247
|
+
}
|
|
248
|
+
outputPath = join(resolvedExports, basename(lexicalPath));
|
|
249
|
+
wroteDefault = true;
|
|
250
|
+
}
|
|
251
|
+
const fileMode = opts.includeKey ? 0o600 : 0o644;
|
|
252
|
+
const content = JSON.stringify(exportData, null, 2);
|
|
253
|
+
if (wroteDefault) {
|
|
254
|
+
writeDefaultExport(outputPath, content, fileMode);
|
|
255
|
+
}
|
|
256
|
+
else if (opts.includeKey) {
|
|
257
|
+
// Stage at 0600 to avoid retaining an existing output file's wider mode.
|
|
258
|
+
writeFilesAtomically([{ path: outputPath, content, mode: 0o600 }]);
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
writeFileSync(outputPath, content, { mode: fileMode });
|
|
262
|
+
}
|
|
134
263
|
console.log(`\n${render.icons.ok} ${render.wrap(render.c.green, `Agent '${agentId}' exported`)}`);
|
|
135
264
|
console.log(render.kv("Memories", render.wrap(render.c.bold, String(memories.length))));
|
|
136
265
|
console.log(render.kv("Souls", render.wrap(render.c.bold, String(souls.length))));
|
|
@@ -139,7 +268,7 @@ export function register(program) {
|
|
|
139
268
|
? `${render.wrap(render.c.magenta, "included")} ${render.wrap(render.c.red, "(UNENCRYPTED — protect this file)")}`
|
|
140
269
|
: render.wrap(render.c.dim, "not included");
|
|
141
270
|
console.log(render.kv("Key", keyText));
|
|
142
|
-
console.log(render.kv("Mode",
|
|
271
|
+
console.log(render.kv("Mode", exportFileMode(outputPath)));
|
|
143
272
|
console.log(render.kv("Output", render.wrap(render.c.dim, outputPath)));
|
|
144
273
|
});
|
|
145
274
|
}
|