@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/init.js
CHANGED
|
@@ -2,13 +2,14 @@ import { applyOrReportClaudeMdBootstrap } from "../doctor-client.js";
|
|
|
2
2
|
import { applyOrRepinSessionStartHook } from "../lib/owned-pins.js";
|
|
3
3
|
import { hookSettingsPath } from "../hook-install.js";
|
|
4
4
|
import { claudeCodeMcpEntry, detectClients, renderWiringSummary, wireAntigravity, wireClaudeCodeJson, wireCodex, wireCursor, wireGemini, wirePi } from "../install/clients.js";
|
|
5
|
-
import { DEFAULT_ADMIN_USER, authFetch, defaultAdminPassPath, defaultKeysDir, readAdminPassFileSecure, resolveAdminUser } from "../lib/auth-resolve.js";
|
|
5
|
+
import { DEFAULT_ADMIN_USER, ApiRequestOutcomeUnknown, addAdminPassOptions, authFetch, defaultAdminPassPath, defaultKeysDir, readAdminPassFileSecure, resolveAdminUser } from "../lib/auth-resolve.js";
|
|
6
6
|
import { INIT_RESET_ADMIN_PASS_COMMAND, detectPersistedAdminUser, executeAdminPasswordRotate, initAdminPassRefusalMessage, resolveInitAdminPasswordRefuseReason, resolveInitAdminPasswordSource, } from "../lib/init-admin-pass.js";
|
|
7
7
|
import { canonicalLexicalPath } from "../lib/daemon-liveness.js";
|
|
8
|
+
import { invalidAgentIdMessage, isValidAgentId } from "../lib/agent-id-rule.js";
|
|
8
9
|
import { encodeRecordId } from "../lib/record-id-path.js";
|
|
9
10
|
import { mcpServerSpec, unpinnedSpecWarning } from "../lib/mcp-spec.js";
|
|
10
11
|
import { planRedirectMigration, renderRedirectMigration } from "../lib/mcp-oauth-env.js";
|
|
11
|
-
import { seedUsingFlairSkill } from "../lib/skill-seed.js";
|
|
12
|
+
import { checkUsingFlairSkill, seedUsingFlairSkill } from "../lib/skill-seed.js";
|
|
12
13
|
import { clearSkillSeedPending, markSkillSeedPending } from "../lib/skill-seed-pending.js";
|
|
13
14
|
import { opsSocketPathRefusal } from "../lib/socket-path-limit.js";
|
|
14
15
|
import * as render from "../render.js";
|
|
@@ -16,7 +17,9 @@ import { rewriteFederationSchedulerRuntime } from "../federation/scheduler.js";
|
|
|
16
17
|
import { preferVersionManagerAlias } from "../lib/node-alias-path.js";
|
|
17
18
|
import { spawn } from "node:child_process";
|
|
18
19
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
19
|
-
import {
|
|
20
|
+
import { closeSync, constants, existsSync, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, writeFileSync } from "node:fs";
|
|
21
|
+
import { ensureAgentKeysDir, readOrCreateAgentKey } from "../lib/agent-key-file.js";
|
|
22
|
+
import { stageRemoteAdminPassword } from "../lib/remote-admin-pass.js";
|
|
20
23
|
import { join, resolve } from "node:path";
|
|
21
24
|
import { localPortState } from "../lib/init-tcp-probe.js";
|
|
22
25
|
import { trackInitChild } from "../lib/init-spawn-attribution.js";
|
|
@@ -25,6 +28,11 @@ import { httpCorsAccessList } from "../lib/http-bind.js";
|
|
|
25
28
|
import { resolveHome } from "../lib/home.js";
|
|
26
29
|
import { foreignOccupiedListenerDetail, } from "../lib/init-occupied-listener.js";
|
|
27
30
|
let cli;
|
|
31
|
+
function remoteAdminPasswordRecovery(clusterAdminUser) {
|
|
32
|
+
return clusterAdminUser === DEFAULT_ADMIN_USER
|
|
33
|
+
? ` The cluster password for '${clusterAdminUser}' may already have changed. Remedy: recover with a separate administrator credential or Harper's out-of-band administrator recovery before re-running remote init.`
|
|
34
|
+
: " Remedy: re-run the same remote init command.";
|
|
35
|
+
}
|
|
28
36
|
function ownedInitPidfilePid(dataDir) {
|
|
29
37
|
let fd;
|
|
30
38
|
try {
|
|
@@ -104,8 +112,8 @@ function persistDefaultInstallCoordinates(...args) {
|
|
|
104
112
|
function privKeyPath(...args) {
|
|
105
113
|
return cli.privKeyPath(...args);
|
|
106
114
|
}
|
|
107
|
-
function provisionFabric(
|
|
108
|
-
return cli.provisionFabric(
|
|
115
|
+
function provisionFabric(target, opsTarget, clusterAdminUser, clusterAdminPass, flairAdminPass, hooks) {
|
|
116
|
+
return cli.provisionFabric(target, opsTarget, clusterAdminUser, clusterAdminPass, flairAdminPass, hooks);
|
|
109
117
|
}
|
|
110
118
|
function pubKeyPath(...args) {
|
|
111
119
|
return cli.pubKeyPath(...args);
|
|
@@ -174,6 +182,51 @@ async function seedUsingFlairSkillViaRest(baseUrl, adminUser, adminPass) {
|
|
|
174
182
|
}
|
|
175
183
|
console.log(`using-flair skill: ${outcome.message}`);
|
|
176
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* flair#3126 — run the seed's reads and refusals with no write. A refusal
|
|
187
|
+
* detected by the preflight prevents the role, shared-user and Agent writes in
|
|
188
|
+
* `finishRemoteInit`. Fabric deployment and administrator provisioning may
|
|
189
|
+
* already have occurred; a later seed refusal can follow those writes.
|
|
190
|
+
*/
|
|
191
|
+
async function preflightUsingFlairSkillViaRest(baseUrl, adminUser, adminPass) {
|
|
192
|
+
const outcome = await checkUsingFlairSkill({ baseUrl, user: adminUser, pass: adminPass });
|
|
193
|
+
if (outcome.kind === "refused") {
|
|
194
|
+
console.error(`Error: the using-flair skill seed was refused — ${outcome.message}`);
|
|
195
|
+
process.exit(1);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Refuse the reserved shared agent account as an administrator input on either
|
|
200
|
+
* remote-init leg, before any filesystem or cluster write. `role` and `flag`
|
|
201
|
+
* name the leg's input, so the remedy points at the operator's own flag.
|
|
202
|
+
*/
|
|
203
|
+
function refuseReservedPrincipal(name, role, flag) {
|
|
204
|
+
if (name.trim().toLowerCase() !== cli.FLAIR_AGENT_USERNAME)
|
|
205
|
+
return;
|
|
206
|
+
console.error(`Error: '${cli.FLAIR_AGENT_USERNAME}' is a reserved Flair account and cannot be the ${role}.`);
|
|
207
|
+
console.error(` Use a different ${role} (${flag}).`);
|
|
208
|
+
process.exit(1);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Refuse an `--agent-id` that violates the shared agent-ID rule, or that names
|
|
212
|
+
* an administrator username reserved by this init path, before the keys
|
|
213
|
+
* directory or any key file is created or written, and before any `fetch` call made by the command action.
|
|
214
|
+
*/
|
|
215
|
+
function refuseOperatorAgentId(agentId, administratorNames) {
|
|
216
|
+
// Only an OMITTED id means "no agent ID supplied". A supplied id,
|
|
217
|
+
// including the empty string, goes through the shared rule below.
|
|
218
|
+
if (agentId === undefined)
|
|
219
|
+
return;
|
|
220
|
+
if (!isValidAgentId(agentId)) {
|
|
221
|
+
console.error(`Error: ${invalidAgentIdMessage(agentId)}`);
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
if (!administratorNames.includes(agentId))
|
|
225
|
+
return;
|
|
226
|
+
console.error(`Error: --agent-id "${agentId}" is an administrator username reserved by this init path.`);
|
|
227
|
+
console.error(" Choose another --agent-id.");
|
|
228
|
+
process.exit(1);
|
|
229
|
+
}
|
|
177
230
|
function readOccupiedListener(port) {
|
|
178
231
|
return cli.readOccupiedListener(port);
|
|
179
232
|
}
|
|
@@ -213,11 +266,172 @@ function initLaunchdExitCode(kind) {
|
|
|
213
266
|
function repointMainServiceUnit(...args) {
|
|
214
267
|
return cli.repointMainServiceUnit(...args);
|
|
215
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* The `flair init` summary's password line, which must name the password the
|
|
271
|
+
* principal actually has: the chosen Flair admin password that init wrote to
|
|
272
|
+
* `adminPassPath` when provisioning created or updated `admin`, otherwise the
|
|
273
|
+
* cluster administrator password this run supplied. `principal.created` decides,
|
|
274
|
+
* never the username: a reused super_user may itself be named `admin`.
|
|
275
|
+
*/
|
|
276
|
+
export function adminPasswordHintLine(principal, adminPassPath) {
|
|
277
|
+
if (principal.created) {
|
|
278
|
+
return ` Admin password: the chosen Flair admin password, written to ${adminPassPath}`;
|
|
279
|
+
}
|
|
280
|
+
return " Admin password: the cluster administrator password this run supplied";
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* The calls a `flair init` run makes after provisioning. On the provisioning
|
|
284
|
+
* leg they are the flair_agent role and shared agent user (plus the
|
|
285
|
+
* flair_pair_initiator role and the federation-instance reconcile with
|
|
286
|
+
* `--remote`), the agent seed with `--agent-id`, the org-wide skill seed and
|
|
287
|
+
* the verification read; every one authenticates as the `principal`
|
|
288
|
+
* provisioning returned. On the already-running-instance leg only the
|
|
289
|
+
* `/Health` connectivity check sends no Authorization header; the other calls
|
|
290
|
+
* authenticate as that principal too.
|
|
291
|
+
*/
|
|
292
|
+
export async function finishRemoteInit(principal, opts) {
|
|
293
|
+
const { baseUrl, opsUrl, remote, provisioningLeg, agentId } = opts;
|
|
294
|
+
const adminUser = principal.username;
|
|
295
|
+
const adminPass = principal.password;
|
|
296
|
+
const auth = `Basic ${Buffer.from(`${adminUser}:${adminPass}`).toString("base64")}`;
|
|
297
|
+
const role = remote ? "hub" : undefined;
|
|
298
|
+
// flair#3126 — run the seed's checks before this function's role, user and
|
|
299
|
+
// Agent writes.
|
|
300
|
+
await preflightUsingFlairSkillViaRest(baseUrl, adminUser, adminPass);
|
|
301
|
+
if (provisioningLeg) {
|
|
302
|
+
// Hub instances (--remote) receive federation pair requests and need
|
|
303
|
+
// the flair_pair_initiator role so bootstrap credentials can pass
|
|
304
|
+
// platform auth before reaching the FederationPair resource handler.
|
|
305
|
+
if (remote) {
|
|
306
|
+
await ensureFlairPairInitiatorRole(opsUrl, adminUser, adminPass);
|
|
307
|
+
}
|
|
308
|
+
// Every flair instance has agents, so provision the least-privilege
|
|
309
|
+
// flair_agent role (idempotent, harmless until a user is assigned to it).
|
|
310
|
+
await ensureFlairAgentRole(opsUrl, adminUser, adminPass);
|
|
311
|
+
// THE FLIP (auth-rbac): provision the shared least-privilege flair-agent user.
|
|
312
|
+
// This ACTIVATES the gate's per-agent de-elevation (verified non-admin agents
|
|
313
|
+
// resolve to flair-agent instead of admin super_user). Safe now: #487 gave
|
|
314
|
+
// every agent-facing resource its own allow* + resolveAgentAuth, so they no
|
|
315
|
+
// longer rely on the admin super_user bypass. The gate also falls back to
|
|
316
|
+
// admin if this user is ever absent, so de-elevation degrades gracefully.
|
|
317
|
+
await ensureFlairAgentUser(opsUrl, adminUser, adminPass);
|
|
318
|
+
}
|
|
319
|
+
// Generate or reuse keypair (only if --agent-id provided, or --remote needs
|
|
320
|
+
// a public key for the FederationInstance row)
|
|
321
|
+
let pubKeyB64url;
|
|
322
|
+
let privPath;
|
|
323
|
+
let instanceId;
|
|
324
|
+
// Reconcile the federation Instance identity row if --remote (hub role).
|
|
325
|
+
// flair#1883: this used to INSERT a row with a fresh random id on every
|
|
326
|
+
// run, so a hub that had already answered a `GET /FederationInstance`
|
|
327
|
+
// (which find-or-creates a `spoke` row) ended up with TWO rows and no
|
|
328
|
+
// canonical identity. Reconciling keeps the row peers already know.
|
|
329
|
+
// It runs before the agent seed so the agent's home is the hub's id.
|
|
330
|
+
const reconcileHubInstance = async (publicKey) => {
|
|
331
|
+
instanceId = randomUUID();
|
|
332
|
+
console.log(`Reconciling federation Instance (role=${role}) via ops API...`);
|
|
333
|
+
let reconciled;
|
|
334
|
+
try {
|
|
335
|
+
reconciled = await reconcileFederationInstanceViaOpsApi(opsUrl, { instanceId, publicKey }, adminUser, adminPass);
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
// A refusal (two rows) or an unreachable ops API — both are this
|
|
339
|
+
// command failing, and both already name what to do.
|
|
340
|
+
console.error(`Error: ${err?.message ?? err}`);
|
|
341
|
+
process.exit(1);
|
|
342
|
+
}
|
|
343
|
+
instanceId = reconciled.id;
|
|
344
|
+
if (reconciled.action === "created") {
|
|
345
|
+
console.log(`Federation Instance created: ${reconciled.id} (role=${role}) ✓`);
|
|
346
|
+
}
|
|
347
|
+
else if (reconciled.action === "updated") {
|
|
348
|
+
console.log(`Federation Instance reconciled: ${reconciled.id} is now role=${role} (id and key kept) ✓`);
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
console.log(`Federation Instance already role=${role}: ${reconciled.id} — no change ✓`);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
if (agentId || role) {
|
|
355
|
+
const keysDir = opts.keysDir ?? defaultKeysDir();
|
|
356
|
+
if (agentId) {
|
|
357
|
+
const agentPrivPath = privKeyPath(agentId, keysDir);
|
|
358
|
+
privPath = agentPrivPath;
|
|
359
|
+
const pubPath = pubKeyPath(agentId, keysDir);
|
|
360
|
+
try {
|
|
361
|
+
ensureAgentKeysDir(keysDir);
|
|
362
|
+
const keyFile = readOrCreateAgentKey(agentPrivPath, () => {
|
|
363
|
+
console.log("Generating Ed25519 keypair...");
|
|
364
|
+
const kp = nacl.sign.keyPair();
|
|
365
|
+
return Buffer.from(kp.secretKey.slice(0, 32));
|
|
366
|
+
});
|
|
367
|
+
const kp = nacl.sign.keyPair.fromSeed(new Uint8Array(keyFile.bytes));
|
|
368
|
+
pubKeyB64url = b64url(kp.publicKey);
|
|
369
|
+
if (keyFile.created) {
|
|
370
|
+
writeFileSync(pubPath, Buffer.from(kp.publicKey));
|
|
371
|
+
console.log(`Keypair written: ${privPath} ✓`);
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
console.log(`Reusing existing key: ${privPath}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
catch (err) {
|
|
378
|
+
console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
379
|
+
process.exit(1);
|
|
380
|
+
}
|
|
381
|
+
if (role)
|
|
382
|
+
await reconcileHubInstance(pubKeyB64url);
|
|
383
|
+
// Seed agent via remote ops API
|
|
384
|
+
console.log(`Seeding agent '${agentId}' on ${baseUrl}...`);
|
|
385
|
+
await seedAgentWithLocalHome(opsUrl, agentId, pubKeyB64url, adminUser, adminPass);
|
|
386
|
+
console.log(`Agent '${agentId}' registered on remote instance ✓`);
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
// No agentId -- generate throwaway keypair for FederationInstance row
|
|
390
|
+
console.log("Generating federation instance keypair...");
|
|
391
|
+
const kp = nacl.sign.keyPair();
|
|
392
|
+
pubKeyB64url = b64url(kp.publicKey);
|
|
393
|
+
if (role)
|
|
394
|
+
await reconcileHubInstance(pubKeyB64url);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
console.log("No --agent-id provided -- skipping agent registration");
|
|
399
|
+
}
|
|
400
|
+
// flair#2141 S2 — seed the org-wide using-flair skill on the remote
|
|
401
|
+
// instance, as the operator. Idempotent; a refusal fails this run.
|
|
402
|
+
await seedUsingFlairSkillViaRest(baseUrl, adminUser, adminPass);
|
|
403
|
+
// Verify connectivity
|
|
404
|
+
if (provisioningLeg) {
|
|
405
|
+
// Use /FederationInstance with Basic auth (not /Health which false-401s on Fabric)
|
|
406
|
+
console.log("Verifying remote connectivity...");
|
|
407
|
+
const verifyRes = await fetch(`${baseUrl}/FederationInstance`, {
|
|
408
|
+
headers: { Authorization: auth },
|
|
409
|
+
signal: AbortSignal.timeout(5000),
|
|
410
|
+
});
|
|
411
|
+
if (!verifyRes.ok) {
|
|
412
|
+
const body = await verifyRes.text().catch(() => "");
|
|
413
|
+
console.error(`Remote verification failed (${verifyRes.status}): ${body}`);
|
|
414
|
+
process.exit(1);
|
|
415
|
+
}
|
|
416
|
+
console.log("✓ Hub ready at " + baseUrl);
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
// Existing behavior: /Health check (already-running Flair)
|
|
420
|
+
console.log("Verifying remote connectivity...");
|
|
421
|
+
const verifyRes = await fetch(`${baseUrl}/Health`, { signal: AbortSignal.timeout(5000) });
|
|
422
|
+
if (!verifyRes.ok) {
|
|
423
|
+
console.error(`Remote health check failed: ${verifyRes.status}`);
|
|
424
|
+
process.exit(1);
|
|
425
|
+
}
|
|
426
|
+
console.log("Remote Flair instance healthy ✓");
|
|
427
|
+
}
|
|
428
|
+
return { instanceId, privPath };
|
|
429
|
+
}
|
|
216
430
|
export function register(program) {
|
|
217
431
|
const MQTT_DISABLED_CONFIG = cli.MQTT_DISABLED_CONFIG;
|
|
218
432
|
const STARTUP_TIMEOUT_MS = cli.STARTUP_TIMEOUT_MS;
|
|
219
433
|
// ─── flair init ──────────────────────────────────────────────────────────────
|
|
220
|
-
program
|
|
434
|
+
addAdminPassOptions(program
|
|
221
435
|
.command("init")
|
|
222
436
|
.description("One-command Flair setup — bootstrap the instance, register an agent, and wire MCP clients")
|
|
223
437
|
.option("--agent-id <id>", "Agent ID to register (omit to bootstrap instance without agent)")
|
|
@@ -230,11 +444,9 @@ export function register(program) {
|
|
|
230
444
|
.option("--port <port>", "Harper HTTP port (default: this instance's current port, or 19926 for a new one)")
|
|
231
445
|
.option("--ops-port <port>", "Harper operations API port")
|
|
232
446
|
.option("--ops-bind <addr>", "Harper ops API bind address (env: FLAIR_OPS_BIND; default: 127.0.0.1 loopback-only for single-host — pass e.g. 0.0.0.0 for multi-host/Fabric remote admin)")
|
|
233
|
-
.option("--http-bind <addr>", "Harper HTTP bind address (env: FLAIR_HTTP_BIND; default: 127.0.0.1 loopback-only). The listener MUST include IPv4 loopback (Flair's self-calls hardcode 127.0.0.1), so only 127.0.0.1 or a wildcard (0.0.0.0 / ::) is accepted; a specific non-loopback host is refused.")
|
|
234
|
-
.option("--admin-pass <pass>", "Admin password (generated if omitted)")
|
|
235
|
-
.option("--admin-pass-file <path>", "Read admin password from file (chmod 600 recommended)")
|
|
447
|
+
.option("--http-bind <addr>", "Harper HTTP bind address (env: FLAIR_HTTP_BIND; default: 127.0.0.1 loopback-only). The listener MUST include IPv4 loopback (Flair's self-calls hardcode 127.0.0.1), so only 127.0.0.1 or a wildcard (0.0.0.0 / ::) is accepted; a specific non-loopback host is refused."), "Admin password (generated if omitted)", { adminPassFileHelp: "Read admin password from file (chmod 600 recommended)" })
|
|
236
448
|
.option("--reset-admin-pass", "Rotate Harper's persisted admin hash via the operations socket, then write ~/.flair/admin-pass")
|
|
237
|
-
.option("--admin-user <name>", "Admin username when authenticating to an already-running instance via --target/--ops-target (env: FLAIR_ADMIN_USER; default: admin — local bootstrap
|
|
449
|
+
.option("--admin-user <name>", "Admin username when authenticating to an already-running instance via --target/--ops-target (env: FLAIR_ADMIN_USER; default: admin — local bootstrap creates 'admin'; Fabric provisioning reuses an existing super_user cluster administrator, and otherwise creates or updates 'admin')")
|
|
238
450
|
.option("--keys-dir <dir>", "Directory for Ed25519 keys")
|
|
239
451
|
.option("--data-dir <dir>", "Harper data directory")
|
|
240
452
|
.option("--skip-start", "Do not start Harper; with --agent, defer registration (ignored with --target/--ops-target)")
|
|
@@ -271,8 +483,21 @@ export function register(program) {
|
|
|
271
483
|
const clusterAdminPass = opts.clusterAdminPass || process.env.FLAIR_CLUSTER_ADMIN_PASS;
|
|
272
484
|
let flairAdminPass = opts.flairAdminPass || process.env.FLAIR_ADMIN_PASS;
|
|
273
485
|
let didProvision = false;
|
|
486
|
+
let provisionedPrincipal;
|
|
274
487
|
if (clusterAdminUser && clusterAdminPass) {
|
|
275
488
|
// ── New provisioning path: deploy Flair to Fabric, wait, provision super_user ──
|
|
489
|
+
// The reserved shared agent account must never be used as this run's
|
|
490
|
+
// administrator input on either leg: init authenticates its later calls
|
|
491
|
+
// as the run's principal, and without this guard provisioning could
|
|
492
|
+
// change that account through add_user or alter_user on
|
|
493
|
+
// FLAIR_AGENT_USERNAME (ensureFlairAgentUser), out from under the agent
|
|
494
|
+
// gate. Refuse it first, before the agent-ID check and every filesystem
|
|
495
|
+
// or cluster write.
|
|
496
|
+
refuseReservedPrincipal(clusterAdminUser, "cluster administrator", "--cluster-admin-user");
|
|
497
|
+
// Provisioning either reuses an existing super_user cluster admin or
|
|
498
|
+
// creates or updates DEFAULT_ADMIN_USER, so both names are known before
|
|
499
|
+
// provisionFabric runs. Refuse either one here, before any write.
|
|
500
|
+
refuseOperatorAgentId(agentId, [clusterAdminUser, DEFAULT_ADMIN_USER]);
|
|
276
501
|
if (!opts.force) {
|
|
277
502
|
console.error("Error: --force is required with --target/--ops-target (remote init provisions a live Fabric instance)");
|
|
278
503
|
console.error(" Pass --force to confirm this is intended.");
|
|
@@ -282,34 +507,102 @@ export function register(program) {
|
|
|
282
507
|
if (!flairAdminPass) {
|
|
283
508
|
flairAdminPass = randomBytes(24).toString("base64url");
|
|
284
509
|
}
|
|
285
|
-
//
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
510
|
+
// Provisioning: save unless reusing a super_user, deploy + wait, provision user.
|
|
511
|
+
// The returned principal is the one this run set up: the existing
|
|
512
|
+
// super_user cluster administrator when list_users reports the
|
|
513
|
+
// operator's cluster admin as a super_user, else the `admin` user this
|
|
514
|
+
// run created (or updated).
|
|
515
|
+
const secretPath = join(resolveHome(), ".tps", "secrets", "flair-fabric-hdb");
|
|
516
|
+
let stagedAdminPass;
|
|
517
|
+
let saveAttempted = false;
|
|
518
|
+
let saveApplied = false;
|
|
519
|
+
let requestSent = false;
|
|
520
|
+
try {
|
|
521
|
+
provisionedPrincipal = await provisionFabric(baseUrl, opsUrl, clusterAdminUser, clusterAdminPass, flairAdminPass, {
|
|
522
|
+
// Before the first cluster write, when this run attempts to set
|
|
523
|
+
// `admin`'s password. A throw here leaves the cluster unchanged.
|
|
524
|
+
beforeAdminPasswordApplied: () => {
|
|
525
|
+
saveAttempted = true;
|
|
526
|
+
stagedAdminPass = stageRemoteAdminPassword(secretPath, flairAdminPass, writeAdminPassFile);
|
|
527
|
+
},
|
|
528
|
+
adminPasswordRequestSent: () => {
|
|
529
|
+
requestSent = true;
|
|
530
|
+
},
|
|
531
|
+
afterAdminPasswordApplied: () => {
|
|
532
|
+
saveApplied = true;
|
|
533
|
+
stagedAdminPass.confirm();
|
|
534
|
+
},
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
catch (err) {
|
|
538
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
539
|
+
if (saveAttempted && !stagedAdminPass) {
|
|
540
|
+
console.error(`Error: could not save the Flair administrator password to ${secretPath}: ${message}`);
|
|
541
|
+
console.error(` Remedy: make ${secretPath} a writable regular file you own (mode 0600), then run init again.`);
|
|
542
|
+
console.error(" The cluster was not changed.");
|
|
543
|
+
process.exit(1);
|
|
544
|
+
}
|
|
545
|
+
if (saveApplied) {
|
|
546
|
+
const held = stagedAdminPass.stagedPath;
|
|
547
|
+
// Recheck the stage before advising a move: it may have changed since confirm().
|
|
548
|
+
if (held !== null && stagedAdminPass.stagedFileVerified && stagedAdminPass.stillValid()) {
|
|
549
|
+
console.error(`Error: the cluster accepted the Flair administrator password, but ${held} could not be moved into place: ${message}`);
|
|
550
|
+
console.error(` The cluster now holds the password in ${held}.`);
|
|
551
|
+
console.error(` Remedy: move ${held} over ${secretPath} with mode 0600.`);
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
console.error(`Error: the cluster accepted the Flair administrator password, but the saved credential at ${held ?? secretPath} could not be confirmed: ${message}`);
|
|
555
|
+
console.error(remoteAdminPasswordRecovery(clusterAdminUser));
|
|
556
|
+
}
|
|
557
|
+
process.exit(1);
|
|
558
|
+
}
|
|
559
|
+
if (stagedAdminPass && requestSent) {
|
|
560
|
+
const held = stagedAdminPass.stagedPath;
|
|
561
|
+
console.error(`Error: Fabric provisioning failed after attempting the add/alter request, so the outcome is uncertain: ${message}`);
|
|
562
|
+
if (held !== null) {
|
|
563
|
+
console.error(` The cluster may hold the password in ${held}.`);
|
|
564
|
+
console.error(` If that password logs in, move ${held} over ${secretPath} with mode 0600; if it does not, delete ${held}.`);
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
console.error(` The cluster may hold the password saved at ${secretPath}.`);
|
|
568
|
+
}
|
|
569
|
+
process.exit(1);
|
|
570
|
+
}
|
|
571
|
+
if (stagedAdminPass) {
|
|
572
|
+
const stage = stagedAdminPass;
|
|
573
|
+
try {
|
|
574
|
+
stage.abort();
|
|
575
|
+
}
|
|
576
|
+
catch (cleanupErr) {
|
|
577
|
+
const cleanupMessage = cleanupErr instanceof Error ? cleanupErr.message : String(cleanupErr);
|
|
578
|
+
console.error(`Error: Fabric provisioning failed after the Flair administrator password was saved: ${message}`);
|
|
579
|
+
console.error(`Error: could not remove the staged credential ${stage.stagedPath}: ${cleanupMessage}`);
|
|
580
|
+
process.exit(1);
|
|
581
|
+
}
|
|
582
|
+
console.error(`Error: Fabric provisioning failed after the Flair administrator password was saved: ${message}`);
|
|
583
|
+
if (stage.hadExistingFile) {
|
|
584
|
+
console.error(` The existing credential file at ${secretPath} was left unchanged.`);
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
console.error(` The saved password is kept at ${secretPath}; reuse it on the next run.`);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
throw err;
|
|
591
|
+
}
|
|
293
592
|
didProvision = true;
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (
|
|
298
|
-
|
|
593
|
+
if (!provisionedPrincipal.created && existsSync(secretPath)) {
|
|
594
|
+
console.warn(`⚠ ${secretPath} already exists, but this run reused an existing super_user cluster administrator and neither changed nor verified that file. Verify it by authenticating to the instance with the password it holds before relying on it.`);
|
|
595
|
+
}
|
|
596
|
+
if (provisionedPrincipal.created) {
|
|
597
|
+
console.log(`Admin password written to ${secretPath}`);
|
|
299
598
|
}
|
|
300
|
-
// Every flair instance has agents, so provision the least-privilege
|
|
301
|
-
// flair_agent role (idempotent, harmless until a user is assigned to it).
|
|
302
|
-
await ensureFlairAgentRole(opsUrl, DEFAULT_ADMIN_USER, flairAdminPass);
|
|
303
|
-
// THE FLIP (auth-rbac): provision the shared least-privilege flair-agent user.
|
|
304
|
-
// This ACTIVATES the gate's per-agent de-elevation (verified non-admin agents
|
|
305
|
-
// resolve to flair-agent instead of admin super_user). Safe now: #487 gave
|
|
306
|
-
// every agent-facing resource its own allow* + resolveAgentAuth, so they no
|
|
307
|
-
// longer rely on the admin super_user bypass. The gate also falls back to
|
|
308
|
-
// admin if this user is ever absent, so de-elevation degrades gracefully.
|
|
309
|
-
await ensureFlairAgentUser(opsUrl, DEFAULT_ADMIN_USER, flairAdminPass);
|
|
310
599
|
}
|
|
311
600
|
else {
|
|
312
601
|
// ── Existing behavior: --admin-pass required for already-running Flair ──
|
|
602
|
+
// On this leg the run's principal is --admin-user (or its default), so
|
|
603
|
+
// the reserved-principal refusal must cover that name too, before any
|
|
604
|
+
// filesystem or cluster write.
|
|
605
|
+
refuseReservedPrincipal(resolveAdminUser(opts.adminUser), "admin user", "--admin-user");
|
|
313
606
|
if (!opts.adminPass) {
|
|
314
607
|
console.error("Error: --admin-pass is required with --target/--ops-target (remote init without --cluster-admin-user/--cluster-admin-pass)");
|
|
315
608
|
console.error(" Use --cluster-admin-user and --cluster-admin-pass for automated Fabric provisioning.");
|
|
@@ -322,127 +615,37 @@ export function register(program) {
|
|
|
322
615
|
process.exit(1);
|
|
323
616
|
}
|
|
324
617
|
flairAdminPass = opts.adminPass;
|
|
618
|
+
// flair#1345: only the already-running-instance leg honors --admin-user /
|
|
619
|
+
// FLAIR_ADMIN_USER; provisioning uses the returned principal.
|
|
620
|
+
provisionedPrincipal = {
|
|
621
|
+
username: resolveAdminUser(opts.adminUser),
|
|
622
|
+
password: opts.adminPass,
|
|
623
|
+
created: false,
|
|
624
|
+
};
|
|
325
625
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
// Reconcile the federation Instance identity row if --remote (hub role).
|
|
338
|
-
// flair#1883: this used to INSERT a row with a fresh random id on every
|
|
339
|
-
// run, so a hub that had already answered a `GET /FederationInstance`
|
|
340
|
-
// (which find-or-creates a `spoke` row) ended up with TWO rows and no
|
|
341
|
-
// canonical identity. Reconciling keeps the row peers already know.
|
|
342
|
-
// It runs before the agent seed so the agent's home is the hub's id.
|
|
343
|
-
const reconcileHubInstance = async (publicKey) => {
|
|
344
|
-
instanceId = randomUUID();
|
|
345
|
-
console.log(`Reconciling federation Instance (role=${role}) via ops API...`);
|
|
346
|
-
let reconciled;
|
|
347
|
-
try {
|
|
348
|
-
reconciled = await reconcileFederationInstanceViaOpsApi(opsUrl, { instanceId, publicKey }, adminUser, flairAdminPass);
|
|
349
|
-
}
|
|
350
|
-
catch (err) {
|
|
351
|
-
// A refusal (two rows) or an unreachable ops API — both are this
|
|
352
|
-
// command failing, and both already name what to do.
|
|
353
|
-
console.error(`Error: ${err?.message ?? err}`);
|
|
354
|
-
process.exit(1);
|
|
355
|
-
}
|
|
356
|
-
instanceId = reconciled.id;
|
|
357
|
-
if (reconciled.action === "created") {
|
|
358
|
-
console.log(`Federation Instance created: ${reconciled.id} (role=${role}) ✓`);
|
|
359
|
-
}
|
|
360
|
-
else if (reconciled.action === "updated") {
|
|
361
|
-
console.log(`Federation Instance reconciled: ${reconciled.id} is now role=${role} (id and key kept) ✓`);
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
console.log(`Federation Instance already role=${role}: ${reconciled.id} — no change ✓`);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
if (agentId || role) {
|
|
368
|
-
const keysDir = opts.keysDir ?? defaultKeysDir();
|
|
369
|
-
mkdirSync(keysDir, { recursive: true });
|
|
370
|
-
if (agentId) {
|
|
371
|
-
privPath = privKeyPath(agentId, keysDir);
|
|
372
|
-
const pubPath = pubKeyPath(agentId, keysDir);
|
|
373
|
-
if (existsSync(privPath)) {
|
|
374
|
-
console.log(`Reusing existing key: ${privPath}`);
|
|
375
|
-
const seed = new Uint8Array(readFileSync(privPath));
|
|
376
|
-
const kp = nacl.sign.keyPair.fromSeed(seed);
|
|
377
|
-
pubKeyB64url = b64url(kp.publicKey);
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
console.log("Generating Ed25519 keypair...");
|
|
381
|
-
const kp = nacl.sign.keyPair();
|
|
382
|
-
const seed = kp.secretKey.slice(0, 32);
|
|
383
|
-
writeFileSync(privPath, Buffer.from(seed));
|
|
384
|
-
chmodSync(privPath, 0o600);
|
|
385
|
-
writeFileSync(pubPath, Buffer.from(kp.publicKey));
|
|
386
|
-
pubKeyB64url = b64url(kp.publicKey);
|
|
387
|
-
console.log(`Keypair written: ${privPath} ✓`);
|
|
388
|
-
}
|
|
389
|
-
if (role)
|
|
390
|
-
await reconcileHubInstance(pubKeyB64url);
|
|
391
|
-
// Seed agent via remote ops API
|
|
392
|
-
console.log(`Seeding agent '${agentId}' on ${baseUrl}...`);
|
|
393
|
-
await seedAgentWithLocalHome(opsUrl, agentId, pubKeyB64url, adminUser, flairAdminPass);
|
|
394
|
-
console.log(`Agent '${agentId}' registered on remote instance ✓`);
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
// No agentId -- generate throwaway keypair for FederationInstance row
|
|
398
|
-
console.log("Generating federation instance keypair...");
|
|
399
|
-
const kp = nacl.sign.keyPair();
|
|
400
|
-
pubKeyB64url = b64url(kp.publicKey);
|
|
401
|
-
if (role)
|
|
402
|
-
await reconcileHubInstance(pubKeyB64url);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
console.log("No --agent-id provided -- skipping agent registration");
|
|
407
|
-
}
|
|
408
|
-
// flair#2141 S2 — seed the org-wide using-flair skill on the remote
|
|
409
|
-
// instance, as the operator. Idempotent; a refusal fails this run.
|
|
410
|
-
await seedUsingFlairSkillViaRest(baseUrl, adminUser, flairAdminPass);
|
|
411
|
-
// Verify connectivity
|
|
412
|
-
if (didProvision) {
|
|
413
|
-
// Use /FederationInstance with Basic auth (not /Health which false-401s on Fabric)
|
|
414
|
-
console.log("Verifying remote connectivity...");
|
|
415
|
-
const verifyRes = await fetch(`${baseUrl}/FederationInstance`, {
|
|
416
|
-
headers: { Authorization: auth },
|
|
417
|
-
signal: AbortSignal.timeout(5000),
|
|
418
|
-
});
|
|
419
|
-
if (!verifyRes.ok) {
|
|
420
|
-
const body = await verifyRes.text().catch(() => "");
|
|
421
|
-
console.error(`Remote verification failed (${verifyRes.status}): ${body}`);
|
|
422
|
-
process.exit(1);
|
|
423
|
-
}
|
|
424
|
-
console.log("✓ Hub ready at " + baseUrl);
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
// Existing behavior: /Health check (already-running Flair)
|
|
428
|
-
console.log("Verifying remote connectivity...");
|
|
429
|
-
const verifyRes = await fetch(`${baseUrl}/Health`, { signal: AbortSignal.timeout(5000) });
|
|
430
|
-
if (!verifyRes.ok) {
|
|
431
|
-
console.error(`Remote health check failed: ${verifyRes.status}`);
|
|
432
|
-
process.exit(1);
|
|
433
|
-
}
|
|
434
|
-
console.log("Remote Flair instance healthy ✓");
|
|
435
|
-
}
|
|
626
|
+
const principal = provisionedPrincipal;
|
|
627
|
+
if (!didProvision)
|
|
628
|
+
refuseOperatorAgentId(agentId, [principal.username]);
|
|
629
|
+
const { instanceId, privPath } = await finishRemoteInit(principal, {
|
|
630
|
+
baseUrl,
|
|
631
|
+
opsUrl,
|
|
632
|
+
remote: !!opts.remote,
|
|
633
|
+
provisioningLeg: didProvision,
|
|
634
|
+
agentId,
|
|
635
|
+
keysDir: opts.keysDir,
|
|
636
|
+
});
|
|
436
637
|
// Print summary
|
|
437
638
|
if (didProvision) {
|
|
438
639
|
const pkg = JSON.parse(readFileSync(join(process.cwd(), "package.json"), "utf-8"));
|
|
439
640
|
const flavor = pkg.version || "(unknown)";
|
|
440
641
|
const displayTarget = target || opsTarget;
|
|
642
|
+
const adminPassPath = join(resolveHome(), ".tps", "secrets", "flair-fabric-hdb");
|
|
441
643
|
console.log(`\n✓ Flair hub deployed to ${displayTarget}`);
|
|
442
644
|
console.log(` Component: flair@${flavor}`);
|
|
443
|
-
console.log(` Admin user: ${
|
|
645
|
+
console.log(` Admin user: ${principal.username}`);
|
|
646
|
+
console.log(adminPasswordHintLine(principal, adminPassPath));
|
|
444
647
|
if (instanceId)
|
|
445
|
-
console.log(` Instance: ${instanceId} (role
|
|
648
|
+
console.log(` Instance: ${instanceId} (role=hub)`);
|
|
446
649
|
console.log(` Federation: ready — run \`flair federation token\` to mint a pairing token`);
|
|
447
650
|
}
|
|
448
651
|
else {
|
|
@@ -452,13 +655,16 @@ export function register(program) {
|
|
|
452
655
|
console.log(` Target: ${baseUrl}`);
|
|
453
656
|
if (agentId)
|
|
454
657
|
console.log(` Private key: ${privPath}`);
|
|
455
|
-
if (
|
|
456
|
-
console.log(` Role:
|
|
658
|
+
if (opts.remote)
|
|
659
|
+
console.log(` Role: hub`);
|
|
457
660
|
console.log(`\n Export: FLAIR_URL=${baseUrl}`);
|
|
458
661
|
}
|
|
459
662
|
return;
|
|
460
663
|
}
|
|
461
664
|
// ── Local init (full one-command setup) ──
|
|
665
|
+
// Local init uses DEFAULT_ADMIN_USER, so the
|
|
666
|
+
// check runs here, before any key or Agent write.
|
|
667
|
+
refuseOperatorAgentId(agentId, [DEFAULT_ADMIN_USER]);
|
|
462
668
|
const keysDir = opts.keysDir ?? defaultKeysDir();
|
|
463
669
|
// Resolve ONCE, here: the operator means "relative to my shell's cwd", but
|
|
464
670
|
// Harper is spawned with cwd = the flair package directory, so a raw
|
|
@@ -703,8 +909,8 @@ export function register(program) {
|
|
|
703
909
|
resetRequested: !!opts.resetAdminPass,
|
|
704
910
|
opsSocketAvailable: alreadyRunning || !opts.skipStart,
|
|
705
911
|
};
|
|
706
|
-
// Warn if --admin-pass is passed inline (not from env)
|
|
707
|
-
if (shouldShowInlineSecretWarning(opts.
|
|
912
|
+
// Warn if --admin-pass is passed inline (not from env or a file)
|
|
913
|
+
if (shouldShowInlineSecretWarning(opts.inlineAdminPass, false, new Set(["--admin-pass"]), "--admin-pass")) {
|
|
708
914
|
console.error("warning: --admin-pass passed inline. Consider --admin-pass-file <path> or FLAIR_ADMIN_PASS env " +
|
|
709
915
|
"to keep secrets out of shell history.");
|
|
710
916
|
}
|
|
@@ -1252,29 +1458,37 @@ export function register(program) {
|
|
|
1252
1458
|
};
|
|
1253
1459
|
if (agentId) {
|
|
1254
1460
|
// Generate or reuse keypair
|
|
1255
|
-
mkdirSync(keysDir, { recursive: true });
|
|
1256
1461
|
const privPath = privKeyPath(agentId, keysDir);
|
|
1257
1462
|
const pubPath = pubKeyPath(agentId, keysDir);
|
|
1258
1463
|
let pubKeyB64url;
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
const
|
|
1262
|
-
|
|
1464
|
+
try {
|
|
1465
|
+
ensureAgentKeysDir(keysDir);
|
|
1466
|
+
const keyFile = readOrCreateAgentKey(privPath, () => {
|
|
1467
|
+
console.log("Generating Ed25519 keypair...");
|
|
1468
|
+
const kp = nacl.sign.keyPair();
|
|
1469
|
+
// Store only the 32-byte seed (first 32 bytes of secretKey)
|
|
1470
|
+
return Buffer.from(kp.secretKey.slice(0, 32));
|
|
1471
|
+
});
|
|
1472
|
+
const kp = nacl.sign.keyPair.fromSeed(new Uint8Array(keyFile.bytes));
|
|
1263
1473
|
pubKeyB64url = b64url(kp.publicKey);
|
|
1474
|
+
if (keyFile.created) {
|
|
1475
|
+
writeFileSync(pubPath, Buffer.from(kp.publicKey));
|
|
1476
|
+
console.log(`Keypair written: ${privPath} ✓`);
|
|
1477
|
+
}
|
|
1478
|
+
else {
|
|
1479
|
+
console.log(`Reusing existing key: ${privPath}`);
|
|
1480
|
+
}
|
|
1264
1481
|
}
|
|
1265
|
-
|
|
1266
|
-
console.
|
|
1267
|
-
|
|
1268
|
-
// Store only the 32-byte seed (first 32 bytes of secretKey)
|
|
1269
|
-
const seed = kp.secretKey.slice(0, 32);
|
|
1270
|
-
writeFileSync(privPath, Buffer.from(seed));
|
|
1271
|
-
chmodSync(privPath, 0o600);
|
|
1272
|
-
writeFileSync(pubPath, Buffer.from(kp.publicKey));
|
|
1273
|
-
pubKeyB64url = b64url(kp.publicKey);
|
|
1274
|
-
console.log(`Keypair written: ${privPath} ✓`);
|
|
1482
|
+
catch (err) {
|
|
1483
|
+
console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
1484
|
+
process.exit(1);
|
|
1275
1485
|
}
|
|
1276
1486
|
const httpUrl = `http://127.0.0.1:${httpPort}`;
|
|
1277
1487
|
if (!opts.skipStart) {
|
|
1488
|
+
// flair#3126 — check the seed before the agent write, so a refusal
|
|
1489
|
+
// leaves no Agent row behind.
|
|
1490
|
+
await attributeBeforeCredential(httpPort, httpBind.host);
|
|
1491
|
+
await preflightUsingFlairSkillViaRest(httpUrl, adminUser, adminPass);
|
|
1278
1492
|
console.log(`Seeding agent '${agentId}' via operations API...`);
|
|
1279
1493
|
const opsListener = skippedOwnStart ? operationsPortAttribution(opsPort) : undefined;
|
|
1280
1494
|
await attributeBeforeCredential(opsPort, opsBindHost);
|
|
@@ -1389,6 +1603,8 @@ export function register(program) {
|
|
|
1389
1603
|
console.log(` ✓ soul:${key} set`);
|
|
1390
1604
|
}
|
|
1391
1605
|
catch (err) {
|
|
1606
|
+
if (err instanceof ApiRequestOutcomeUnknown)
|
|
1607
|
+
throw err;
|
|
1392
1608
|
const message = err instanceof Error ? err.message : String(err);
|
|
1393
1609
|
console.warn(` ⚠ soul:${key} failed: ${message}`);
|
|
1394
1610
|
}
|