@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/agent.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import nacl from "tweetnacl";
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync, readFileSync, chmodSync } from "node:fs";
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync, chmodSync, unlinkSync, realpathSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import * as render from "../render.js";
|
|
5
|
-
import {
|
|
5
|
+
import { addAdminPassOptions, credentialsInHeader, defaultKeysDir, describeHttpFailure, resolveLocalAdminPass, resolveAdminUser, resolveKeyPath, authFetch, authFetchWithSentCredentials, } from "../lib/auth-resolve.js";
|
|
6
|
+
import { encodeRecordId } from "../lib/record-id-path.js";
|
|
7
|
+
import { resolveLocalDeleteInstance } from "../lib/local-delete-instance.js";
|
|
8
|
+
import { invalidAgentIdMessage, isValidAgentId } from "../lib/agent-id-rule.js";
|
|
9
|
+
import { agentHomeEndpoint, resolveTargetInstanceId, runAgentHomeStamp, stampLeftoverLines, } from "../lib/agent-home.js";
|
|
10
|
+
import { confirmedPurgeIds } from "../lib/memory-purge-response.js";
|
|
6
11
|
let cli;
|
|
7
12
|
/** Bind shared CLI helpers. cli.ts calls this immediately before register(program). */
|
|
8
13
|
export function bindCli(fns) {
|
|
@@ -12,12 +17,48 @@ const api = (method, path, body, options) => cli.api(method, path, body, options
|
|
|
12
17
|
const b64url = (bytes) => cli.b64url(bytes);
|
|
13
18
|
const privKeyPath = (agentId, keysDir) => cli.privKeyPath(agentId, keysDir);
|
|
14
19
|
const pubKeyPath = (agentId, keysDir) => cli.pubKeyPath(agentId, keysDir);
|
|
20
|
+
/**
|
|
21
|
+
* flair#2479 — check each key's canonical target before unlinking.
|
|
22
|
+
* Return successful unlinks; invalid ids require manual cleanup.
|
|
23
|
+
*/
|
|
24
|
+
export function removeAgentKeyFiles(agentId, keysDir) {
|
|
25
|
+
if (!isValidAgentId(agentId))
|
|
26
|
+
return { removed: [], manual: true };
|
|
27
|
+
let root;
|
|
28
|
+
try {
|
|
29
|
+
root = realpathSync(keysDir);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return { removed: [], manual: false }; // directory resolution failed
|
|
33
|
+
}
|
|
34
|
+
const removed = [];
|
|
35
|
+
for (const name of [`${agentId}.key`, `${agentId}.pub`, `${agentId}.key.bak`]) {
|
|
36
|
+
let real;
|
|
37
|
+
try {
|
|
38
|
+
real = realpathSync(join(keysDir, name));
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
continue; // candidate resolution failed
|
|
42
|
+
}
|
|
43
|
+
if (real !== join(root, name))
|
|
44
|
+
continue; // unexpected canonical target; skip
|
|
45
|
+
try {
|
|
46
|
+
unlinkSync(real);
|
|
47
|
+
removed.push(real);
|
|
48
|
+
}
|
|
49
|
+
catch { /* best effort */ }
|
|
50
|
+
}
|
|
51
|
+
return { removed, manual: false };
|
|
52
|
+
}
|
|
15
53
|
const shouldShowInlineSecretWarning = (optValue, fromEnv, secretFlagNames, flagName) => cli.shouldShowInlineSecretWarning(optValue, fromEnv, secretFlagNames, flagName);
|
|
16
54
|
const resolveHttpPort = (opts, mode) => cli.resolveHttpPort(opts, mode);
|
|
17
55
|
const resolveOpsPort = (opts) => cli.resolveOpsPort(opts);
|
|
56
|
+
const resolveAgentHomeTarget = (opts) => cli.resolveAgentHomeTarget(opts);
|
|
18
57
|
const resolveEffectiveOpsUrl = (opts) => cli.resolveEffectiveOpsUrl(opts);
|
|
19
|
-
const
|
|
58
|
+
const seedAgentWithLocalHome = (opsPortOrUrl, agentId, pubKeyB64url, adminUser, adminPass) => cli.seedAgentWithLocalHome(opsPortOrUrl, agentId, pubKeyB64url, adminUser, adminPass);
|
|
20
59
|
const agentRecordIsAdmin = (record) => cli.agentRecordIsAdmin(record);
|
|
60
|
+
const INLINE_ADMIN_PASS_WARNING = "warning: --admin-pass passed inline. Use FLAIR_ADMIN_PASS without typing its value into a recorded " +
|
|
61
|
+
"shell line (for example, read it from the admin-pass file).";
|
|
21
62
|
/** Operations API URL, same shape as `seedAgentViaOpsApi` (trailing slash). */
|
|
22
63
|
function opsApiUrl(opsPortOrUrl) {
|
|
23
64
|
return typeof opsPortOrUrl === "number"
|
|
@@ -165,19 +206,25 @@ async function readStoredAgent(opsPortOrUrl, id, adminUser, adminPass) {
|
|
|
165
206
|
export function register(program) {
|
|
166
207
|
// ─── flair agent ─────────────────────────────────────────────────────────────
|
|
167
208
|
const agent = program.command("agent").description("Manage Flair agents");
|
|
168
|
-
agent
|
|
209
|
+
addAdminPassOptions(agent
|
|
169
210
|
.command("add <id>")
|
|
170
211
|
.description("Register a new agent. Refuses an id whose Agent record already exists")
|
|
171
212
|
.option("--name <name>", "Display name (defaults to id)")
|
|
172
|
-
.option("--port <port>", "Harper HTTP port")
|
|
173
|
-
.
|
|
174
|
-
|
|
213
|
+
.option("--port <port>", "Harper HTTP port"), "Admin password for registration", {
|
|
214
|
+
adminPassFileHelp: "Read the admin password from a file (owner-only permissions enforced). Preferred over inline --admin-pass — keeps the secret out of ps and shell history; works for remote targets too (an explicit flag is operator intent).",
|
|
215
|
+
})
|
|
175
216
|
.option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
|
|
176
217
|
.option("--keys-dir <dir>", "Directory for Ed25519 keys")
|
|
177
218
|
.option("--ops-port <port>", "Harper operations API port")
|
|
178
|
-
.option("--target <url>", "Remote Flair REST URL; derives
|
|
219
|
+
.option("--target <url>", "Remote Flair REST URL; derives ops URL (HTTPS no port/:443 → Fabric ops :9925; HTTP no port/:80 → :19925; other ports 2–65535 → port-1; port 1 refused; env: FLAIR_TARGET)")
|
|
179
220
|
.option("--ops-target <url>", "Explicit ops API URL to seed the Agent on (env: FLAIR_OPS_TARGET; bypasses port derivation)")
|
|
180
221
|
.action(async (id, opts) => {
|
|
222
|
+
// flair#2359 — the ONE agent-ID rule, before any key file is written or
|
|
223
|
+
// any insert is attempted. Refuse a non-matching id by name.
|
|
224
|
+
if (!isValidAgentId(id)) {
|
|
225
|
+
console.error(`Error: ${invalidAgentIdMessage(id)}`);
|
|
226
|
+
process.exit(1);
|
|
227
|
+
}
|
|
181
228
|
const httpPort = resolveHttpPort(opts);
|
|
182
229
|
const opsPort = resolveOpsPort(opts);
|
|
183
230
|
const keysDir = opts.keysDir ?? defaultKeysDir();
|
|
@@ -189,29 +236,13 @@ export function register(program) {
|
|
|
189
236
|
// `flair import`: explicit --ops-target > derive from --target > localhost.
|
|
190
237
|
const seedOpsTarget = resolveEffectiveOpsUrl({ target: opts.target, opsTarget: opts.opsTarget }) ?? opsPort;
|
|
191
238
|
const isRemoteTarget = typeof seedOpsTarget === "string";
|
|
192
|
-
// flair#1259 / #1910 —
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
//
|
|
198
|
-
//
|
|
199
|
-
// the AMBIENT env/local-file fallbacks silently traveling to a third-party
|
|
200
|
-
// host.
|
|
201
|
-
let explicitPass;
|
|
202
|
-
try {
|
|
203
|
-
explicitPass =
|
|
204
|
-
resolveAdminPassFromSources({
|
|
205
|
-
adminPassFile: opts.adminPassFile,
|
|
206
|
-
adminPass: opts.adminPass,
|
|
207
|
-
envPass: undefined,
|
|
208
|
-
}) || undefined;
|
|
209
|
-
}
|
|
210
|
-
catch (err) {
|
|
211
|
-
console.error(`Error: ${err.message}`);
|
|
212
|
-
process.exit(1);
|
|
213
|
-
}
|
|
214
|
-
opts.adminPass = explicitPass;
|
|
239
|
+
// flair#1259 / #1910 — the pair is resolved by addAdminPassOptions' preAction
|
|
240
|
+
// hook, before this action runs. This does NOT weaken the #1085 remote guard
|
|
241
|
+
// below: an explicit flag naming a file IS operator intent toward this
|
|
242
|
+
// target, exactly like an explicit inline --admin-pass — what the guard
|
|
243
|
+
// blocks is the AMBIENT env/local-file fallbacks silently traveling to a
|
|
244
|
+
// third-party host.
|
|
245
|
+
//
|
|
215
246
|
// #590 — local convenience fallback: FLAIR_ADMIN_PASS env, then the secure
|
|
216
247
|
// ~/.flair/admin-pass file `flair init` already writes (mode 0600). Never
|
|
217
248
|
// applied for a remote target — see resolveLocalAdminPass.
|
|
@@ -264,7 +295,7 @@ export function register(program) {
|
|
|
264
295
|
pubKeyB64url = b64url(kp.publicKey);
|
|
265
296
|
console.log(`Keypair written: ${privPath}`);
|
|
266
297
|
}
|
|
267
|
-
await
|
|
298
|
+
await seedAgentWithLocalHome(seedOpsTarget, id, pubKeyB64url, adminUser, adminPass);
|
|
268
299
|
const stored = await readStoredAgent(seedOpsTarget, id, adminUser, adminPass);
|
|
269
300
|
if (!stored || stored.publicKey !== pubKeyB64url) {
|
|
270
301
|
console.error(agentKeyNotStoredMessage(id, stored));
|
|
@@ -283,10 +314,7 @@ export function register(program) {
|
|
|
283
314
|
console.log(` Note: an OAuth /mcp connector maps its own IdP subject to an Agent (distinct from '${id}' by default).\n` +
|
|
284
315
|
` To point a connector at '${id}': flair mcp enable --principal ${id} --idp-subject <your-idp-login>`);
|
|
285
316
|
});
|
|
286
|
-
agent
|
|
287
|
-
.command("list")
|
|
288
|
-
.description("List all agents")
|
|
289
|
-
.option("--admin-pass <pass>", "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
317
|
+
addAdminPassOptions(agent.command("list").description("List all agents"), "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
290
318
|
.option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
|
|
291
319
|
.option("--agent <id>", "Agent ID to authenticate as via Ed25519 (or FLAIR_AGENT_ID env) when no admin pass")
|
|
292
320
|
.option("--keys-dir <dir>", "Directory holding the agent's Ed25519 key")
|
|
@@ -294,11 +322,8 @@ export function register(program) {
|
|
|
294
322
|
.option("--json", "Emit raw JSON array (also: pipe + FLAIR_OUTPUT=json)")
|
|
295
323
|
.action(async (opts) => {
|
|
296
324
|
const port = resolveHttpPort(opts);
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
if (shouldShowInlineSecretWarning(opts.adminPass, adminPassFromEnv, new Set(["--admin-pass"]), "--admin-pass")) {
|
|
300
|
-
console.error("warning: --admin-pass passed inline. Consider --admin-pass-from <file> or FLAIR_ADMIN_PASS env " +
|
|
301
|
-
"to keep secrets out of shell history.");
|
|
325
|
+
if (shouldShowInlineSecretWarning(opts.inlineAdminPass, false, new Set(["--admin-pass"]), "--admin-pass")) {
|
|
326
|
+
console.error(INLINE_ADMIN_PASS_WARNING);
|
|
302
327
|
}
|
|
303
328
|
const adminPass = opts.adminPass ?? process.env.FLAIR_ADMIN_PASS ?? process.env.HDB_ADMIN_PASSWORD ?? "";
|
|
304
329
|
const mode = render.resolveOutputMode(opts);
|
|
@@ -319,7 +344,8 @@ export function register(program) {
|
|
|
319
344
|
});
|
|
320
345
|
if (!res.ok) {
|
|
321
346
|
const text = await res.text().catch(() => "");
|
|
322
|
-
|
|
347
|
+
const sent = credentialsInHeader(`Basic ${auth}`);
|
|
348
|
+
console.error(`${render.icons.error} ${describeHttpFailure(res.status, text, sent.values, sent.withhold)}`);
|
|
323
349
|
process.exit(1);
|
|
324
350
|
}
|
|
325
351
|
agents = await res.json();
|
|
@@ -334,13 +360,14 @@ export function register(program) {
|
|
|
334
360
|
const agentId = opts.agent ?? process.env.FLAIR_AGENT_ID;
|
|
335
361
|
const keysDir = opts.keysDir ?? process.env.FLAIR_KEY_DIR ?? defaultKeysDir();
|
|
336
362
|
let res;
|
|
363
|
+
let sent = { values: [], withhold: false };
|
|
337
364
|
if (agentId) {
|
|
338
365
|
const keyPath = resolveKeyPath(agentId) ?? join(keysDir, `${agentId}.key`);
|
|
339
366
|
if (!existsSync(keyPath)) {
|
|
340
367
|
console.error(`${render.icons.error} no key for agent '${agentId}' (looked in ${keysDir}). Pass --admin-pass, --keys-dir, or a registered --agent.`);
|
|
341
368
|
process.exit(1);
|
|
342
369
|
}
|
|
343
|
-
res = await
|
|
370
|
+
({ res, sent } = await authFetchWithSentCredentials(baseUrl, agentId, keyPath, "GET", "/Agent"));
|
|
344
371
|
}
|
|
345
372
|
else {
|
|
346
373
|
// No agent identity available either. Try anonymously, but if it 403s
|
|
@@ -356,7 +383,7 @@ export function register(program) {
|
|
|
356
383
|
console.error(` or ${render.wrap(render.c.cyan, "--admin-pass")} / FLAIR_ADMIN_PASS for the admin view.`);
|
|
357
384
|
}
|
|
358
385
|
else {
|
|
359
|
-
console.error(`${render.icons.error} ${res.status
|
|
386
|
+
console.error(`${render.icons.error} ${describeHttpFailure(res.status, text, sent.values, sent.withhold)}`);
|
|
360
387
|
}
|
|
361
388
|
process.exit(1);
|
|
362
389
|
}
|
|
@@ -385,7 +412,7 @@ export function register(program) {
|
|
|
385
412
|
.description("Show agent details")
|
|
386
413
|
.option("--json", "Emit raw JSON response (also: pipe + FLAIR_OUTPUT=json)")
|
|
387
414
|
.action(async (id, opts) => {
|
|
388
|
-
const out = await api("GET", `/Agent/${id}`);
|
|
415
|
+
const out = await api("GET", `/Agent/${encodeRecordId(id)}`);
|
|
389
416
|
const mode = render.resolveOutputMode(opts);
|
|
390
417
|
if (mode === "json") {
|
|
391
418
|
console.log(render.asJSON(out));
|
|
@@ -419,22 +446,18 @@ export function register(program) {
|
|
|
419
446
|
console.log(render.kv("updated", `${render.relativeTime(out.updatedAt)} ${render.wrap(render.c.dim, `(${out.updatedAt})`)}`));
|
|
420
447
|
}
|
|
421
448
|
});
|
|
422
|
-
agent
|
|
449
|
+
addAdminPassOptions(agent
|
|
423
450
|
.command("rotate-key <id>")
|
|
424
451
|
.description("Rotate an agent's Ed25519 keypair")
|
|
425
452
|
.option("--port <port>", "Harper HTTP port")
|
|
426
|
-
.option("--ops-port <port>", "Harper operations API port")
|
|
427
|
-
.option("--admin-pass <pass>", "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
453
|
+
.option("--ops-port <port>", "Harper operations API port"), "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
428
454
|
.option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
|
|
429
455
|
.option("--keys-dir <dir>", "Directory for Ed25519 keys")
|
|
430
456
|
.action(async (id, opts) => {
|
|
431
457
|
const httpPort = resolveHttpPort(opts);
|
|
432
458
|
const opsPort = resolveOpsPort(opts);
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
if (shouldShowInlineSecretWarning(opts.adminPass, adminPassFromEnv, new Set(["--admin-pass"]), "--admin-pass")) {
|
|
436
|
-
console.error("warning: --admin-pass passed inline. Consider --admin-pass-from <file> or FLAIR_ADMIN_PASS env " +
|
|
437
|
-
"to keep secrets out of shell history.");
|
|
459
|
+
if (shouldShowInlineSecretWarning(opts.inlineAdminPass, false, new Set(["--admin-pass"]), "--admin-pass")) {
|
|
460
|
+
console.error(INLINE_ADMIN_PASS_WARNING);
|
|
438
461
|
}
|
|
439
462
|
const adminPass = opts.adminPass ?? process.env.FLAIR_ADMIN_PASS ?? "";
|
|
440
463
|
const adminUser = resolveAdminUser(opts.adminUser);
|
|
@@ -491,7 +514,7 @@ export function register(program) {
|
|
|
491
514
|
// Verify new key works
|
|
492
515
|
console.log(`Verifying new Ed25519 auth...`);
|
|
493
516
|
const httpUrl = `http://127.0.0.1:${httpPort}`;
|
|
494
|
-
const verifyRes = await authFetch(httpUrl, id, currentPrivPath, "GET", `/Agent/${id}`);
|
|
517
|
+
const verifyRes = await authFetch(httpUrl, id, currentPrivPath, "GET", `/Agent/${encodeRecordId(id)}`);
|
|
495
518
|
if (!verifyRes.ok) {
|
|
496
519
|
console.error(`⚠️ Auth verification failed (${verifyRes.status}). Old key is backed up at: ${backupPrivPath}`);
|
|
497
520
|
process.exit(1);
|
|
@@ -503,18 +526,16 @@ export function register(program) {
|
|
|
503
526
|
console.log(` Old key backup: ${backupPrivPath}`);
|
|
504
527
|
});
|
|
505
528
|
// ─── flair agent remove ──────────────────────────────────────────────────────
|
|
506
|
-
agent
|
|
529
|
+
addAdminPassOptions(agent
|
|
507
530
|
.command("remove <id>")
|
|
508
531
|
.description("Remove an agent and all its data from Flair")
|
|
509
532
|
.option("--keep-keys", "Do not delete key files from disk")
|
|
510
533
|
.option("--port <port>", "Harper HTTP port")
|
|
511
|
-
.option("--ops-port <port>", "Harper operations API port")
|
|
512
|
-
.option("--admin-pass <pass>", "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
534
|
+
.option("--ops-port <port>", "Harper operations API port"), "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
513
535
|
.option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
|
|
514
536
|
.option("--keys-dir <dir>", "Directory for Ed25519 keys")
|
|
515
537
|
.option("--force", "Skip interactive confirmation (required when stdin is not a TTY)")
|
|
516
538
|
.action(async (id, opts) => {
|
|
517
|
-
const opsPort = resolveOpsPort(opts);
|
|
518
539
|
const adminPass = opts.adminPass ?? process.env.FLAIR_ADMIN_PASS ?? "";
|
|
519
540
|
const adminUser = resolveAdminUser(opts.adminUser);
|
|
520
541
|
const keysDir = opts.keysDir ?? defaultKeysDir();
|
|
@@ -523,9 +544,11 @@ export function register(program) {
|
|
|
523
544
|
process.exit(1);
|
|
524
545
|
}
|
|
525
546
|
const auth = `Basic ${Buffer.from(`${adminUser}:${adminPass}`).toString("base64")}`;
|
|
547
|
+
const instance = await resolveLocalDeleteInstance(opts, resolveOpsPort, auth);
|
|
526
548
|
async function opsPost(body) {
|
|
527
|
-
return fetch(
|
|
549
|
+
return fetch(instance.opsUrl, {
|
|
528
550
|
method: "POST",
|
|
551
|
+
redirect: "error",
|
|
529
552
|
headers: { "Content-Type": "application/json", Authorization: auth },
|
|
530
553
|
body: JSON.stringify(body),
|
|
531
554
|
signal: AbortSignal.timeout(10_000),
|
|
@@ -535,9 +558,41 @@ export function register(program) {
|
|
|
535
558
|
const agentRes = await opsPost({ operation: "search_by_value", database: "flair", table: "Agent", search_attribute: "id", search_value: id, get_attributes: ["id", "name"] });
|
|
536
559
|
const agentData = agentRes.ok ? await agentRes.json().catch(() => null) : null;
|
|
537
560
|
const agentName = agentData?.[0]?.name ?? id;
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
561
|
+
async function scanOwnedIds(table) {
|
|
562
|
+
const res = await opsPost({
|
|
563
|
+
operation: "search_by_conditions", database: "flair", table, operator: "and",
|
|
564
|
+
conditions: [{ search_attribute: "agentId", search_type: "equals", search_value: id }],
|
|
565
|
+
get_attributes: ["id", "agentId"],
|
|
566
|
+
});
|
|
567
|
+
if (!res.ok)
|
|
568
|
+
throw new Error(`operations API returned ${res.status}`);
|
|
569
|
+
const rows = await res.json();
|
|
570
|
+
if (!Array.isArray(rows) || !rows.every((row) => typeof row?.id === "string" && row.id.length > 0)) {
|
|
571
|
+
throw new Error("returned an unexpected response");
|
|
572
|
+
}
|
|
573
|
+
for (const row of rows) {
|
|
574
|
+
if (row.agentId !== id) {
|
|
575
|
+
const error = new Error(`${table} row '${row.id}' does not belong to agent '${id}'`);
|
|
576
|
+
error.name = "AgentRemoveOwnerMismatchError";
|
|
577
|
+
throw error;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return rows.map((row) => row.id);
|
|
581
|
+
}
|
|
582
|
+
async function initialScan(table) {
|
|
583
|
+
try {
|
|
584
|
+
return await scanOwnedIds(table);
|
|
585
|
+
}
|
|
586
|
+
catch (error) {
|
|
587
|
+
const failure = new Error(`The ${table} scan for agent '${id}' failed: ${error instanceof Error ? error.message : String(error)}; nothing was removed.`, { cause: error });
|
|
588
|
+
if (error instanceof Error)
|
|
589
|
+
failure.name = error.name;
|
|
590
|
+
throw failure;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
const memoryIds = await initialScan("Memory");
|
|
594
|
+
const memoryCount = memoryIds.length;
|
|
595
|
+
const soulIds = await initialScan("Soul");
|
|
541
596
|
// Confirmation
|
|
542
597
|
const isInteractive = process.stdin.isTTY;
|
|
543
598
|
if (!opts.force) {
|
|
@@ -568,25 +623,48 @@ export function register(program) {
|
|
|
568
623
|
else {
|
|
569
624
|
console.log(`Removing agent '${agentName}' (${id}) with ${memoryCount} memories...`);
|
|
570
625
|
}
|
|
571
|
-
// Delete
|
|
626
|
+
// Delete the scanned memories through the server's physical-removal
|
|
627
|
+
// path. A skill-tagged row expands to its whole lineage there, so
|
|
628
|
+
// superseded version rows go too. An accepted DELETE of a non-reserved
|
|
629
|
+
// skill closes its head; the reserved `using-flair` seed is physically
|
|
630
|
+
// deleted. A response that does not list every scanned id as
|
|
631
|
+
// removed stops the command before the Agent record is deleted.
|
|
572
632
|
if (memoryCount > 0) {
|
|
573
633
|
console.log(`Deleting ${memoryCount} memories...`);
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
634
|
+
const purge = await api("POST", "/MemoryPurge", { ids: memoryIds }, {
|
|
635
|
+
baseUrl: instance.baseUrl,
|
|
636
|
+
explicitAdminPass: adminPass, adminUser, agentId: null,
|
|
637
|
+
});
|
|
638
|
+
confirmedPurgeIds(purge, memoryIds);
|
|
639
|
+
}
|
|
640
|
+
if (soulIds.length > 0) {
|
|
641
|
+
console.log(`Deleting ${soulIds.length} soul entries...`);
|
|
642
|
+
for (const soulId of soulIds) {
|
|
643
|
+
try {
|
|
644
|
+
const soulDel = await opsPost({ operation: "delete", database: "flair", table: "Soul", ids: [soulId] });
|
|
645
|
+
if (!soulDel.ok) {
|
|
646
|
+
const text = await soulDel.text().catch(() => "");
|
|
647
|
+
throw new Error(`operations API returned ${soulDel.status}: ${text}`);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
catch (error) {
|
|
651
|
+
throw new Error(`Failed to delete Soul '${soulId}': ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
652
|
+
}
|
|
578
653
|
}
|
|
579
654
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
655
|
+
let remainingIds;
|
|
656
|
+
try {
|
|
657
|
+
remainingIds = await scanOwnedIds("Soul");
|
|
658
|
+
}
|
|
659
|
+
catch (error) {
|
|
660
|
+
const failure = new Error(`The Soul deletion for agent '${id}' could not be confirmed: ${error instanceof Error ? error.message : String(error)}; ` +
|
|
661
|
+
`these scanned Soul rows may remain and the Agent record was not deleted: ${soulIds.join(", ") || "(none scanned)"}.`, { cause: error });
|
|
662
|
+
if (error instanceof Error)
|
|
663
|
+
failure.name = error.name;
|
|
664
|
+
throw failure;
|
|
665
|
+
}
|
|
666
|
+
if (remainingIds.length > 0) {
|
|
667
|
+
throw new Error(`The Soul deletion for agent '${id}' was not confirmed; these Soul rows remain and the Agent record was not deleted: ${remainingIds.join(", ")}.`);
|
|
590
668
|
}
|
|
591
669
|
// Delete agent record
|
|
592
670
|
const delRes = await opsPost({ operation: "delete", database: "flair", table: "Agent", ids: [id] });
|
|
@@ -596,23 +674,88 @@ export function register(program) {
|
|
|
596
674
|
}
|
|
597
675
|
// Delete key files (unless --keep-keys)
|
|
598
676
|
if (!opts.keepKeys) {
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
if (existsSync(p)) {
|
|
604
|
-
try {
|
|
605
|
-
const { unlinkSync: ul } = await import("node:fs");
|
|
606
|
-
ul(p);
|
|
607
|
-
}
|
|
608
|
-
catch { /* best effort */ }
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
console.log("Key files deleted.");
|
|
677
|
+
const keys = removeAgentKeyFiles(id, keysDir);
|
|
678
|
+
console.log(keys.manual
|
|
679
|
+
? `Key files for '${id}' are not deleted by this command (the id is outside the agent-ID rule); clean them up manually.`
|
|
680
|
+
: `Removed ${keys.removed.length} key file(s).`);
|
|
612
681
|
}
|
|
613
682
|
else {
|
|
614
683
|
console.log("Key files preserved (--keep-keys).");
|
|
615
684
|
}
|
|
616
685
|
console.log(`\n✅ Agent '${id}' removed successfully`);
|
|
617
686
|
});
|
|
687
|
+
addAdminPassOptions(agent
|
|
688
|
+
.command("stamp-home")
|
|
689
|
+
.description("Back-fill the home instance (originatorInstanceId) on home-less Agent rows with no federation-sync provenance")
|
|
690
|
+
.option("--port <port>", "Harper HTTP port")
|
|
691
|
+
.option("--ops-port <port>", "Harper operations API port"), "Admin password (or set FLAIR_ADMIN_PASS)", { adminPassFileHelp: "Read the admin password from a file (owner-only permissions enforced)" })
|
|
692
|
+
.option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
|
|
693
|
+
.option("--apply", "Write the home; without it the command is a dry run and writes nothing")
|
|
694
|
+
.action(async (opts) => {
|
|
695
|
+
let target;
|
|
696
|
+
try {
|
|
697
|
+
// flair#2474 — pair the ops port (the roster read) with the HTTP port (the
|
|
698
|
+
// guarded PATCH). A target the configured pair contradicts, or one with a
|
|
699
|
+
// single port named and no complete configured pair, is refused by name
|
|
700
|
+
// (see resolveAgentHomeTarget).
|
|
701
|
+
target = resolveAgentHomeTarget(opts);
|
|
702
|
+
}
|
|
703
|
+
catch (err) {
|
|
704
|
+
console.error(`Error: ${err.message}`);
|
|
705
|
+
process.exit(1);
|
|
706
|
+
}
|
|
707
|
+
const opsPort = target.opsPort;
|
|
708
|
+
const adminUser = resolveAdminUser(opts.adminUser);
|
|
709
|
+
let adminPass;
|
|
710
|
+
try {
|
|
711
|
+
adminPass = resolveLocalAdminPass(opts.adminPass);
|
|
712
|
+
}
|
|
713
|
+
catch (err) {
|
|
714
|
+
console.error(`Error: ${err.message}`);
|
|
715
|
+
process.exit(1);
|
|
716
|
+
}
|
|
717
|
+
if (!adminPass) {
|
|
718
|
+
console.error("Error: --admin-pass or FLAIR_ADMIN_PASS required (or ensure ~/.flair/admin-pass exists, created by `flair init`)");
|
|
719
|
+
process.exit(1);
|
|
720
|
+
}
|
|
721
|
+
const opsUrl = `http://127.0.0.1:${opsPort}/`;
|
|
722
|
+
const httpUrl = `http://127.0.0.1:${target.httpPort}/`;
|
|
723
|
+
const auth = `Basic ${Buffer.from(`${adminUser}:${adminPass}`).toString("base64")}`;
|
|
724
|
+
const localInstanceId = await resolveTargetInstanceId(agentHomeEndpoint(opsUrl, adminUser, adminPass));
|
|
725
|
+
const result = await runAgentHomeStamp({
|
|
726
|
+
opsUrl,
|
|
727
|
+
httpUrl,
|
|
728
|
+
authHeader: auth,
|
|
729
|
+
localInstanceId,
|
|
730
|
+
apply: Boolean(opts.apply),
|
|
731
|
+
});
|
|
732
|
+
if (result.reason === "roster-unreadable") {
|
|
733
|
+
console.error("Error: could not read the stored Agent roster; nothing was changed.");
|
|
734
|
+
process.exit(1);
|
|
735
|
+
}
|
|
736
|
+
const plan = result.plan;
|
|
737
|
+
if (plan.homeLess.length === 0) {
|
|
738
|
+
console.log(`${render.icons.ok} Every stored agent row names a home instance.`);
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
console.log(`${plan.homeLess.length} agent row(s) have no home instance` +
|
|
742
|
+
(localInstanceId ? ` (this instance is ${localInstanceId})` : ""));
|
|
743
|
+
for (const id of plan.homeLess) {
|
|
744
|
+
const inSync = plan.sync.includes(id);
|
|
745
|
+
console.log(` ${inSync ? "list only (sync-originated):" : "stamp:"} ${id}`);
|
|
746
|
+
}
|
|
747
|
+
if (result.reason === "no-canonical-id") {
|
|
748
|
+
console.error("Error: could not confirm a single canonical Instance row to stamp as the home; nothing was written.");
|
|
749
|
+
process.exitCode = 1;
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
if (!opts.apply) {
|
|
753
|
+
console.log(`Dry run — nothing written. Re-run with --apply to stamp ${plan.stampable.length} row(s); ` +
|
|
754
|
+
`${plan.sync.length} sync-originated row(s) are never stamped.`);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
for (const line of stampLeftoverLines(result))
|
|
758
|
+
console.log(line);
|
|
759
|
+
console.log(`${render.icons.ok} Stamped the home instance on ${result.stamped.length} row(s).`);
|
|
760
|
+
});
|
|
618
761
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
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
3
|
let cli;
|
|
4
4
|
/** Bind the cli-locals this module depends on. */
|
|
@@ -67,12 +67,13 @@ export function register(program) {
|
|
|
67
67
|
payload.days = n;
|
|
68
68
|
}
|
|
69
69
|
const baseUrl = resolveBaseUrl(opts);
|
|
70
|
+
const url = requestUrl(baseUrl, "/AttentionQuery");
|
|
70
71
|
const headers = { "content-type": "application/json" };
|
|
71
72
|
const keyPath = opts.key || resolveKeyPath(agentId);
|
|
72
73
|
if (keyPath) {
|
|
73
|
-
headers["authorization"] = buildEd25519Auth(agentId, "POST",
|
|
74
|
+
headers["authorization"] = buildEd25519Auth(agentId, "POST", requestTarget(url), keyPath);
|
|
74
75
|
}
|
|
75
|
-
const res = await fetch(
|
|
76
|
+
const res = await fetch(url, {
|
|
76
77
|
method: "POST",
|
|
77
78
|
headers,
|
|
78
79
|
body: JSON.stringify(payload),
|