@tpsdev-ai/flair 0.62.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 +6 -6
- package/SECURITY.md +18 -10
- package/config.yaml +11 -11
- package/dist/bridges/runtime/execute.js +1 -0
- package/dist/bridges/types.js +1 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +66 -122
- package/dist/commands/agent.js +27 -65
- package/dist/commands/backup-approval.js +218 -0
- package/dist/commands/backup.js +37 -33
- package/dist/commands/bootstrap.js +3 -1
- package/dist/commands/deploy.js +37 -7
- package/dist/commands/doctor.js +119 -0
- package/dist/commands/export.js +3 -4
- 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 +131 -19
- package/dist/commands/init.js +7 -7
- package/dist/commands/integrity.js +5 -6
- package/dist/commands/mcp.js +11 -17
- package/dist/commands/memory.js +33 -15
- package/dist/commands/orgevent.js +5 -10
- package/dist/commands/principal.js +13 -25
- package/dist/commands/quality.js +3 -0
- package/dist/commands/rem.js +484 -65
- package/dist/commands/restore.js +352 -44
- package/dist/commands/service.js +84 -2
- package/dist/commands/soul.js +0 -6
- package/dist/commands/status.js +51 -33
- 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 +7 -2
- package/dist/fabric-upgrade.js +12 -2
- package/dist/federation/presence-send.js +139 -0
- package/dist/federation-verify.js +269 -177
- package/dist/install/clients.js +171 -35
- package/dist/lib/agent-id-rule.js +44 -2
- package/dist/lib/atomic-write.js +1 -1
- package/dist/lib/auth-resolve.js +1028 -52
- 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/launchd-management.js +14 -3
- 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/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/restore-archive.js +760 -0
- package/dist/lib/restore-verify.js +1 -1
- package/dist/lib/skill-assignment-preflight.js +159 -0
- package/dist/lib/skill-seed.js +91 -8
- package/dist/lib/skill-tombstone-doctor.js +133 -0
- package/dist/lib/soul-scope-fields.js +26 -0
- package/dist/lib/uninstall-purge.js +266 -11
- package/dist/lib/upgrade-prior-liveness.js +2 -1
- package/dist/mcp-client-assertion.js +2 -10
- 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 +1303 -270
- 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 +43 -4
- package/dist/resources/host-pointer/registry.js +29 -0
- package/dist/resources/host-pointer-adapter.js +1 -0
- 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-handler.js +106 -12
- package/dist/resources/mcp-oauth-flag.js +12 -14
- package/dist/resources/mcp-oauth.js +430 -53
- package/dist/resources/mcp-tools.js +60 -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 +384 -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/lib/agent-id-rule.js +44 -2
- package/dist/src/lib/atomic-write.js +1 -1
- package/dist/src/lib/federation-retry-row.js +101 -0
- package/dist/src/lib/instruction-event-contract.js +17 -0
- package/dist/src/lib/memory-attributes.js +2 -0
- package/dist/src/lib/open-live-row.js +20 -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 +18 -9
- package/docs/api-reference.md +126 -28
- package/docs/auth.md +40 -18
- package/docs/claude-code.md +3 -3
- package/docs/deploying-on-fabric.md +108 -0
- package/docs/deployment.md +17 -0
- package/docs/embedding-in-a-harper-app.md +16 -14
- package/docs/entity-vocabulary.md +3 -6
- package/docs/federation.md +29 -2
- 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 +2 -2
- 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 +14 -0
- 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/restore.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { resolveAdminUser } from "../lib/auth-resolve.js";
|
|
1
|
+
import { addAdminPassOptions, isLocalBase, resolveAdminUser, sendJsonRequest } from "../lib/auth-resolve.js";
|
|
2
|
+
import { readBackupArtifact } from "../lib/backup-artifact.js";
|
|
3
|
+
import { loadApprovedArchive } from "../lib/backup-approval-store.js";
|
|
2
4
|
import { encodeRecordId } from "../lib/record-id-path.js";
|
|
3
5
|
import { comparePreservedFields } from "../lib/restore-verify.js";
|
|
6
|
+
import { refuseSkillAssignmentWrite, skillSourceIsFilesystemPath } from "../lib/skill-assignment-preflight.js";
|
|
7
|
+
import { suppliesSoulScopeFields } from "../lib/soul-scope-fields.js";
|
|
8
|
+
import { listAgentCandidates, requireLiveListing } from "../rem/restore.js";
|
|
4
9
|
import * as render from "../render.js";
|
|
5
|
-
import { existsSync
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
6
11
|
let cli;
|
|
7
12
|
/** Bind the cli-locals this module depends on. */
|
|
8
13
|
export function bindCli(fns) {
|
|
@@ -13,14 +18,13 @@ function resolveHttpPort(...args) {
|
|
|
13
18
|
}
|
|
14
19
|
export function register(program) {
|
|
15
20
|
// ─── flair restore ────────────────────────────────────────────────────────────
|
|
16
|
-
program
|
|
21
|
+
addAdminPassOptions(program
|
|
17
22
|
.command("restore <path>")
|
|
18
23
|
.description("Import a Flair backup archive")
|
|
19
24
|
.option("--merge", "Add/update records without deleting existing (default)")
|
|
20
25
|
.option("--replace", "Delete archived Soul and Memory IDs first, then import")
|
|
21
26
|
.option("--port <port>", "Harper HTTP port")
|
|
22
|
-
.option("--url <url>", "Flair base URL (overrides --port)")
|
|
23
|
-
.option("--admin-pass <pass>", "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
27
|
+
.option("--url <url>", "Flair base URL (overrides --port)"), "Admin password (or set FLAIR_ADMIN_PASS env)")
|
|
24
28
|
.option("--admin-user <name>", "Admin username for Basic auth (env: FLAIR_ADMIN_USER; default: admin)")
|
|
25
29
|
.option("--dry-run", "Show what would be imported without making changes")
|
|
26
30
|
.action(async (backupPath, opts) => {
|
|
@@ -37,12 +41,49 @@ export function register(program) {
|
|
|
37
41
|
console.error(`Error: backup file not found: ${backupPath}`);
|
|
38
42
|
process.exit(1);
|
|
39
43
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
// Preflight (flair#2664), before any request in every mode, dry run
|
|
45
|
+
// included: read the archive once, hash and parse that one buffer, and
|
|
46
|
+
// require the hash to equal the digest flair backup wrote to
|
|
47
|
+
// `<archive>.sha256`. The parse refuses ill-formed UTF-8 or JSON, a
|
|
48
|
+
// repeated key or row id, an unsupported version, and rows restore cannot
|
|
49
|
+
// write (src/lib/restore-archive.ts).
|
|
50
|
+
//
|
|
51
|
+
// An archive with no sidecar (flair#2664 slice 1c) is admitted only by an
|
|
52
|
+
// unrevoked approval in this host's approval store
|
|
53
|
+
// (src/lib/backup-approval-store.ts) for the digest of the bytes just
|
|
54
|
+
// read, and only when the stored copy still hashes to that digest; the
|
|
55
|
+
// rows restored are parsed from that rechecked copy. A sidecar-backed
|
|
56
|
+
// archive needs no approval here.
|
|
57
|
+
const artifact = readBackupArtifact(backupPath);
|
|
58
|
+
let archive;
|
|
59
|
+
let admitted;
|
|
60
|
+
if (artifact.ok === false && (artifact.code !== "digest-missing" || artifact.sha256 === undefined)) {
|
|
61
|
+
console.error(`Error: ${artifact.reason}`);
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (artifact.ok === false) {
|
|
66
|
+
const approved = loadApprovedArchive(artifact.sha256);
|
|
67
|
+
if (approved.ok === false) {
|
|
68
|
+
const reapprove = approved.code === "store-unsafe" || approved.code === "record-invalid"
|
|
69
|
+
? ""
|
|
70
|
+
: ` Approve the archive again on this host with flair backup-approval legacy-admit ${backupPath}.`;
|
|
71
|
+
const reason = approved.code === "not-approved"
|
|
72
|
+
? artifact.reason
|
|
73
|
+
: `archive digest sidecar ${backupPath}.sha256 not found, and ${approved.reason}; restore stopped before any write.${reapprove}`;
|
|
74
|
+
console.error(`Error: ${reason}`);
|
|
75
|
+
process.exitCode = 1;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
archive = approved.archive;
|
|
79
|
+
admitted = `${approved.sha256} (no digest sidecar; approved on this host by ${approved.record.approvedBy} ` +
|
|
80
|
+
`at ${approved.record.approvedAt}, ${approved.record.admission} admission)`;
|
|
44
81
|
}
|
|
45
|
-
|
|
82
|
+
else {
|
|
83
|
+
archive = artifact.archive;
|
|
84
|
+
admitted = `${artifact.sha256} (matches ${artifact.digestPath})`;
|
|
85
|
+
}
|
|
86
|
+
const { agents, memories, souls } = archive;
|
|
46
87
|
const collections = [
|
|
47
88
|
{ name: "Agent", rows: agents },
|
|
48
89
|
{ name: "Soul", rows: souls },
|
|
@@ -54,32 +95,15 @@ export function register(program) {
|
|
|
54
95
|
console.error(`Error: ${failure}`);
|
|
55
96
|
process.exitCode = 1;
|
|
56
97
|
}
|
|
57
|
-
for (const { name, rows } of collections) {
|
|
58
|
-
if (!Array.isArray(rows)) {
|
|
59
|
-
failures.push(`${name}: archive collection is not an array`);
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
for (const [index, row] of rows.entries()) {
|
|
63
|
-
if (!row || typeof row !== "object" || Array.isArray(row)
|
|
64
|
-
|| typeof row.id !== "string" || !row.id
|
|
65
|
-
|| (name !== "Agent" && (typeof row.agentId !== "string" || !row.agentId))) {
|
|
66
|
-
failures.push(`${name} row ${index} (${row?.id ?? "missing ID"}): invalid archived row`);
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
encodeRecordId(row.id);
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
failures.push(`${name} ${row.id}: invalid archived ID`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (failures.length) {
|
|
78
|
-
fail();
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
98
|
const auth = `Basic ${Buffer.from(`${adminUser}:${adminPass}`).toString("base64")}`;
|
|
99
|
+
// Every preflight read and every restore write targets baseUrl and refuses
|
|
100
|
+
// redirects, so a method-specific redirect is named instead of sent to a
|
|
101
|
+
// location the preflight did not check. The read raises ApiHttpError for a
|
|
102
|
+
// non-2xx reply, which is the shape the reused candidate-listing helper
|
|
103
|
+
// turns into its route guidance.
|
|
104
|
+
const preflightCall = (method, path, body) => sendJsonRequest(new URL(`${baseUrl}${path}`), method, body, auth, isLocalBase(baseUrl), { refuseRedirects: true, withholdResponseBodyDebug: true });
|
|
82
105
|
console.log(`Restoring from: ${backupPath}`);
|
|
106
|
+
console.log(`Archive SHA-256: ${admitted}`);
|
|
83
107
|
console.log(`Mode: ${mode}${dryRun ? " (dry run)" : ""}`);
|
|
84
108
|
console.log(` Agents: ${agents.length}`);
|
|
85
109
|
console.log(` Memories: ${memories.length}`);
|
|
@@ -94,9 +118,35 @@ export function register(program) {
|
|
|
94
118
|
method,
|
|
95
119
|
headers: { "Content-Type": "application/json", Authorization: auth },
|
|
96
120
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
121
|
+
redirect: "manual",
|
|
97
122
|
signal: AbortSignal.timeout(10_000),
|
|
98
123
|
});
|
|
99
|
-
|
|
124
|
+
if (res.status >= 300 && res.status < 400) {
|
|
125
|
+
return { status: res.status, error: undefined, redirected: true };
|
|
126
|
+
}
|
|
127
|
+
// The refusal name is read from the body, never the outcome: a body
|
|
128
|
+
// that cannot be read keeps the status this write answered with.
|
|
129
|
+
let error;
|
|
130
|
+
try {
|
|
131
|
+
error = errorName(await res.text());
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
error = undefined;
|
|
135
|
+
}
|
|
136
|
+
return { status: res.status, error, redirected: false };
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return { status: undefined, error: undefined, redirected: false };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** A redirect on a restore write, named rather than followed. */
|
|
143
|
+
const redirectFailure = (name, row, method, status) => `${label(name, row)}: ${method} was answered with HTTP ${status} redirect, which restore does not follow; `
|
|
144
|
+
+ "no request was sent to the redirected location";
|
|
145
|
+
/** The `error` name in a refusal body, when it carries one. */
|
|
146
|
+
function errorName(text) {
|
|
147
|
+
try {
|
|
148
|
+
const error = JSON.parse(text)?.error;
|
|
149
|
+
return typeof error === "string" ? error : undefined;
|
|
100
150
|
}
|
|
101
151
|
catch {
|
|
102
152
|
return undefined;
|
|
@@ -105,22 +155,272 @@ export function register(program) {
|
|
|
105
155
|
const label = (name, row) => `${name} ${row.id} (agent ${name === "Agent" ? row.id : row.agentId})`;
|
|
106
156
|
const diagnostic = (name, row, method, status) => `${label(name, row)}: ${method} failed (HTTP ${status ?? "unavailable"})`;
|
|
107
157
|
if (mode === "replace") {
|
|
158
|
+
// A replace replay sends every archived Soul row back whole after
|
|
159
|
+
// deleting the archived ids. The server refuses a Soul write that
|
|
160
|
+
// supplies a non-empty `scopeTag` or `tags` array (flair#1540) or whose
|
|
161
|
+
// `value` equals a same-agent Memory content or MemoryCandidate claim
|
|
162
|
+
// (resources/soul-write-policy.ts), so a row either rule would refuse
|
|
163
|
+
// must stop the replay before the deletes, or the refused row may lose
|
|
164
|
+
// its live copy (flair#2931, #2941). Merge mode deletes nothing and is
|
|
165
|
+
// not checked here.
|
|
166
|
+
//
|
|
167
|
+
// The learned-content comparison runs against the state each Soul PUT
|
|
168
|
+
// will meet: the archived Memory ids are deleted first, and a failed
|
|
169
|
+
// Memory DELETE stops the run before any Soul delete, so those rows are
|
|
170
|
+
// gone when the Souls are written. They are written back after the Souls,
|
|
171
|
+
// so a live Memory row counts only when its id is not in the archive.
|
|
172
|
+
// Every live candidate counts: replace never deletes MemoryCandidate rows.
|
|
173
|
+
//
|
|
174
|
+
// A concurrent same-agent write between this preflight and the PUT is not
|
|
175
|
+
// covered.
|
|
176
|
+
const LEARNED_REFUSAL = "soul_value_is_learned_content";
|
|
177
|
+
const writtenSouls = souls;
|
|
178
|
+
const refusals = [];
|
|
179
|
+
const scopeRefused = new Set();
|
|
180
|
+
for (const row of writtenSouls) {
|
|
181
|
+
if (!suppliesSoulScopeFields(row))
|
|
182
|
+
continue;
|
|
183
|
+
scopeRefused.add(String(row.id));
|
|
184
|
+
refusals.push(`Error: Soul ${row.id}: the archived row supplies a non-empty scopeTag or tags array, `
|
|
185
|
+
+ "which the Soul scope-field rule refuses; edit that row in the archive, then re-run; no rows were deleted");
|
|
186
|
+
}
|
|
187
|
+
// The copied predicate's filesystem classification reads this CLI
|
|
188
|
+
// process's tmpdir/TMPDIR/TMP/TEMP and working directory, while the
|
|
189
|
+
// server uses its own environment (resources/skill-provenance.ts), so a
|
|
190
|
+
// filesystem-path source can be durable to one and not the other.
|
|
191
|
+
// Non-dry-run replace refuses every such row before any delete; a
|
|
192
|
+
// non-path source keeps the environment-independent copied predicate.
|
|
193
|
+
const filesystemSourceRefused = new Set();
|
|
194
|
+
for (const row of writtenSouls) {
|
|
195
|
+
const id = String(row.id);
|
|
196
|
+
if (scopeRefused.has(id))
|
|
197
|
+
continue;
|
|
198
|
+
if (!skillSourceIsFilesystemPath(row))
|
|
199
|
+
continue;
|
|
200
|
+
filesystemSourceRefused.add(id);
|
|
201
|
+
refusals.push(`Error: Soul ${row.id}: its skill-assignment source is a filesystem path, whose durability `
|
|
202
|
+
+ "the server decides from its own environment; restore without --replace, or edit that "
|
|
203
|
+
+ "row's source in the archive, then re-run; no rows were deleted");
|
|
204
|
+
}
|
|
205
|
+
// The Soul PUT also refuses a skill-assignment row that the copied
|
|
206
|
+
// predicate refuses. The PUT sees no stored row (`existing` is
|
|
207
|
+
// undefined) only after a successful Soul DELETE; a failed DELETE is
|
|
208
|
+
// recorded and the PUT still runs, so the stored row may still exist.
|
|
209
|
+
const writeRuleRefused = new Set();
|
|
210
|
+
for (const row of writtenSouls) {
|
|
211
|
+
const id = String(row.id);
|
|
212
|
+
if (scopeRefused.has(id) || filesystemSourceRefused.has(id))
|
|
213
|
+
continue;
|
|
214
|
+
const skillDenied = refuseSkillAssignmentWrite(row);
|
|
215
|
+
if (!skillDenied)
|
|
216
|
+
continue;
|
|
217
|
+
writeRuleRefused.add(id);
|
|
218
|
+
let code = "skill-assignment";
|
|
219
|
+
try {
|
|
220
|
+
const body = (await skillDenied.json());
|
|
221
|
+
if (typeof body?.error === "string")
|
|
222
|
+
code = body.error;
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
/* keep the rule name */
|
|
226
|
+
}
|
|
227
|
+
refusals.push(`Error: Soul ${row.id}: the archived row would be refused by the Soul skill-assignment rule (${code}); `
|
|
228
|
+
+ "edit that row in the archive, then re-run; no rows were deleted");
|
|
229
|
+
}
|
|
230
|
+
// Soul id -> value each Soul PUT will send, per owning agent.
|
|
231
|
+
const learnedCandidates = new Map();
|
|
232
|
+
for (const row of writtenSouls) {
|
|
233
|
+
const id = String(row.id);
|
|
234
|
+
if (scopeRefused.has(id) || filesystemSourceRefused.has(id) || writeRuleRefused.has(id))
|
|
235
|
+
continue;
|
|
236
|
+
if (typeof row.value !== "string" || row.value === "")
|
|
237
|
+
continue;
|
|
238
|
+
if (typeof row.agentId !== "string" || row.agentId === "")
|
|
239
|
+
continue;
|
|
240
|
+
let byValue = learnedCandidates.get(row.agentId);
|
|
241
|
+
if (byValue === undefined) {
|
|
242
|
+
byValue = new Map();
|
|
243
|
+
learnedCandidates.set(row.agentId, byValue);
|
|
244
|
+
}
|
|
245
|
+
const ids = byValue.get(row.value) ?? [];
|
|
246
|
+
ids.push(id);
|
|
247
|
+
byValue.set(row.value, ids);
|
|
248
|
+
}
|
|
249
|
+
const learnedRefusal = (soulId, table, row) => {
|
|
250
|
+
const field = table === "Memory" ? "content" : "claim";
|
|
251
|
+
const subject = row?.id === undefined || row.id === null || row.id === ""
|
|
252
|
+
? `a ${table} row without an id`
|
|
253
|
+
: `${table} ${row.id}`;
|
|
254
|
+
return `Error: Soul ${soulId}: its value equals the ${field} of the same agent's ${subject}, `
|
|
255
|
+
+ `which the Soul learned-content rule refuses (${LEARNED_REFUSAL}); `
|
|
256
|
+
+ `remove or edit that ${table} row or the archived Soul's value, then re-run; no rows were deleted`;
|
|
257
|
+
};
|
|
258
|
+
// A live Memory row whose id is in the archive is deleted before the
|
|
259
|
+
// Souls are written, so it does not count as a survivor.
|
|
260
|
+
const archivedMemoryIds = new Set(memories.filter((row) => row?.id !== undefined && row.id !== null && row.id !== "").map((row) => String(row.id)));
|
|
261
|
+
try {
|
|
262
|
+
for (const [agentId, byValue] of learnedCandidates) {
|
|
263
|
+
const liveMemories = requireLiveListing(await preflightCall("GET", `/Memory?agentId=${encodeURIComponent(agentId)}`), "Memory", agentId);
|
|
264
|
+
const survivorByContent = new Map();
|
|
265
|
+
for (const memory of liveMemories) {
|
|
266
|
+
if (!memory || typeof memory !== "object" || Array.isArray(memory)) {
|
|
267
|
+
throw new Error(`the Memory listing for agent ${agentId} carries a row that is not an object`);
|
|
268
|
+
}
|
|
269
|
+
if (memory.agentId !== agentId)
|
|
270
|
+
continue;
|
|
271
|
+
if (typeof memory.content !== "string")
|
|
272
|
+
continue;
|
|
273
|
+
const id = memory.id === undefined || memory.id === null || memory.id === "" ? undefined : String(memory.id);
|
|
274
|
+
if (id !== undefined && archivedMemoryIds.has(id))
|
|
275
|
+
continue;
|
|
276
|
+
if (!survivorByContent.has(memory.content))
|
|
277
|
+
survivorByContent.set(memory.content, memory);
|
|
278
|
+
}
|
|
279
|
+
const unmatched = new Map(byValue);
|
|
280
|
+
for (const [value, soulIds] of byValue) {
|
|
281
|
+
const match = survivorByContent.get(value);
|
|
282
|
+
if (match === undefined)
|
|
283
|
+
continue;
|
|
284
|
+
for (const soulId of soulIds)
|
|
285
|
+
refusals.push(learnedRefusal(soulId, "Memory", match));
|
|
286
|
+
unmatched.delete(value);
|
|
287
|
+
}
|
|
288
|
+
if (unmatched.size === 0)
|
|
289
|
+
continue;
|
|
290
|
+
// The admin candidate route lists ids only; each listed row is read
|
|
291
|
+
// until every unmatched value has matched, to compare its claim
|
|
292
|
+
// exactly.
|
|
293
|
+
const candidates = await listAgentCandidates(preflightCall, agentId);
|
|
294
|
+
for (const candidate of candidates) {
|
|
295
|
+
if (unmatched.size === 0)
|
|
296
|
+
break;
|
|
297
|
+
const row = await preflightCall("GET", `/MemoryCandidate/${encodeRecordId(candidate.id)}`);
|
|
298
|
+
if (!row || typeof row !== "object" || Array.isArray(row) || typeof row.claim !== "string") {
|
|
299
|
+
throw new Error(`MemoryCandidate ${candidate.id} could not be read as a row with a claim`);
|
|
300
|
+
}
|
|
301
|
+
if (row.agentId !== agentId)
|
|
302
|
+
continue;
|
|
303
|
+
const soulIds = unmatched.get(row.claim);
|
|
304
|
+
if (soulIds === undefined)
|
|
305
|
+
continue;
|
|
306
|
+
for (const soulId of soulIds)
|
|
307
|
+
refusals.push(learnedRefusal(soulId, "MemoryCandidate", candidate));
|
|
308
|
+
unmatched.delete(row.claim);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
catch (err) {
|
|
313
|
+
// A refusal already collected stays visible even when a later listing
|
|
314
|
+
// read fails: the operator should see each refusal collected so far,
|
|
315
|
+
// not only the error that stopped it (flair#2941).
|
|
316
|
+
for (const refusal of refusals)
|
|
317
|
+
console.error(refusal);
|
|
318
|
+
console.error(`Error: ${err?.message ?? String(err)}`);
|
|
319
|
+
console.error("Error: the replace stopped before any delete: a Soul write rule could not be checked against "
|
|
320
|
+
+ "the live rows; check the target's Memory listing and MemoryCandidate listing responses, "
|
|
321
|
+
+ "then re-run. No rows were deleted.");
|
|
322
|
+
process.exitCode = 1;
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (refusals.length > 0) {
|
|
326
|
+
for (const refusal of refusals)
|
|
327
|
+
console.error(refusal);
|
|
328
|
+
process.exitCode = 1;
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
108
331
|
console.log("\nDeleting existing data (replace mode)...");
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
332
|
+
// Memory rows go first: the learned-content check above assumes the
|
|
333
|
+
// archived Memory ids are gone before a Soul write. A Memory DELETE the
|
|
334
|
+
// server refuses leaves that row in place, so stop here rather than
|
|
335
|
+
// delete a Soul whose PUT the surviving row would refuse.
|
|
336
|
+
// Archived Memories whose DELETE succeeded or whose outcome is unknown:
|
|
337
|
+
// if a later DELETE fails, attempt their write-back, verify each successful
|
|
338
|
+
// PUT, and report any PUT or verification failure by id.
|
|
339
|
+
const memoriesToRestore = [];
|
|
340
|
+
for (const row of memories) {
|
|
341
|
+
const { status, redirected } = await adminWrite("DELETE", `/Memory/${encodeRecordId(row.id)}`);
|
|
342
|
+
if (redirected) {
|
|
343
|
+
failures.push(redirectFailure("Memory", row, "DELETE", status));
|
|
344
|
+
}
|
|
345
|
+
else if (status === undefined || (status !== 404 && (status < 200 || status >= 300))) {
|
|
346
|
+
failures.push(diagnostic("Memory", row, "DELETE", status));
|
|
347
|
+
if (status === undefined)
|
|
348
|
+
memoriesToRestore.push(row);
|
|
349
|
+
}
|
|
350
|
+
else if (status >= 200 && status < 300) {
|
|
351
|
+
memoriesToRestore.push(row);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (failures.length > 0) {
|
|
355
|
+
console.error("Error: a Memory DELETE failed; no Soul row was deleted.");
|
|
356
|
+
// Attempt the archived Memory write-backs, verify each successful PUT,
|
|
357
|
+
// and report any PUT or verification failure by id.
|
|
358
|
+
for (const row of memoriesToRestore) {
|
|
359
|
+
const { status, redirected } = await adminWrite("PUT", `/Memory/${encodeRecordId(row.id)}`, row);
|
|
360
|
+
if (redirected || status === undefined || status < 200 || status >= 300) {
|
|
361
|
+
failures.push(`${label("Memory", row)}: could not be restored after a later DELETE failed (`
|
|
362
|
+
+ `${redirected ? `PUT was answered with HTTP ${status} redirect, which restore does not follow` : `PUT HTTP ${status ?? "unavailable"}`})`);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
let problem;
|
|
366
|
+
try {
|
|
367
|
+
const res = await fetch(`${baseUrl}/Memory/${encodeRecordId(row.id)}`, {
|
|
368
|
+
headers: { Authorization: auth },
|
|
369
|
+
redirect: "manual",
|
|
370
|
+
signal: AbortSignal.timeout(10_000),
|
|
371
|
+
});
|
|
372
|
+
if (res.status >= 300 && res.status < 400) {
|
|
373
|
+
problem = `GET verification was answered with HTTP ${res.status} redirect, which restore does not follow`;
|
|
374
|
+
}
|
|
375
|
+
else if (!res.ok) {
|
|
376
|
+
problem = `GET verification failed (HTTP ${res.status})`;
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
const restored = await res.json();
|
|
380
|
+
const mismatched = comparePreservedFields("Memory", row, restored);
|
|
381
|
+
if (!restored || typeof restored !== "object" || Array.isArray(restored)) {
|
|
382
|
+
problem = "GET verification returned a row that is not an object";
|
|
383
|
+
}
|
|
384
|
+
else if (restored.id !== row.id) {
|
|
385
|
+
problem = "GET verification returned a different id";
|
|
386
|
+
}
|
|
387
|
+
else if (mismatched.length > 0) {
|
|
388
|
+
problem = `GET verification failed (field mismatch: ${mismatched.join(", ")})`;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
114
391
|
}
|
|
392
|
+
catch {
|
|
393
|
+
problem = "GET verification failed";
|
|
394
|
+
}
|
|
395
|
+
if (problem !== undefined) {
|
|
396
|
+
failures.push(`${label("Memory", row)}: could not be restored after a later DELETE failed: ${problem}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
fail();
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
for (const row of souls) {
|
|
403
|
+
const { status, redirected } = await adminWrite("DELETE", `/Soul/${encodeRecordId(row.id)}`);
|
|
404
|
+
if (redirected) {
|
|
405
|
+
failures.push(redirectFailure("Soul", row, "DELETE", status));
|
|
406
|
+
}
|
|
407
|
+
else if (status === undefined || (status !== 404 && (status < 200 || status >= 300))) {
|
|
408
|
+
failures.push(diagnostic("Soul", row, "DELETE", status));
|
|
115
409
|
}
|
|
116
410
|
}
|
|
117
411
|
}
|
|
118
412
|
for (const { name, rows } of collections) {
|
|
119
413
|
console.log(`Restoring ${name} records...`);
|
|
120
414
|
for (const row of rows) {
|
|
121
|
-
const status = await adminWrite("PUT", `/${name}/${encodeRecordId(row.id)}`, row);
|
|
122
|
-
if (
|
|
123
|
-
failures.push(
|
|
415
|
+
const { status, error, redirected } = await adminWrite("PUT", `/${name}/${encodeRecordId(row.id)}`, row);
|
|
416
|
+
if (redirected) {
|
|
417
|
+
failures.push(redirectFailure(name, row, "PUT", status));
|
|
418
|
+
}
|
|
419
|
+
else if (status === undefined || status < 200 || status >= 300) {
|
|
420
|
+
// A failed Soul write appends the refusal name the server returned,
|
|
421
|
+
// so a learned-content 403 is named rather than read as an auth
|
|
422
|
+
// failure (flair#2931, #2941).
|
|
423
|
+
failures.push(`${diagnostic(name, row, "PUT", status)}${name === "Soul" && error ? `: ${error}` : ""}`);
|
|
124
424
|
}
|
|
125
425
|
}
|
|
126
426
|
}
|
|
@@ -129,12 +429,18 @@ export function register(program) {
|
|
|
129
429
|
const path = `/${name}/${encodeRecordId(row.id)}`;
|
|
130
430
|
let status;
|
|
131
431
|
let restored;
|
|
432
|
+
let redirect;
|
|
132
433
|
try {
|
|
133
434
|
const res = await fetch(`${baseUrl}${path}`, {
|
|
134
435
|
headers: { Authorization: auth },
|
|
436
|
+
redirect: "manual",
|
|
135
437
|
signal: AbortSignal.timeout(10_000),
|
|
136
438
|
});
|
|
137
439
|
status = res.status;
|
|
440
|
+
if (res.status >= 300 && res.status < 400) {
|
|
441
|
+
redirect = res.status;
|
|
442
|
+
throw new Error();
|
|
443
|
+
}
|
|
138
444
|
if (!res.ok)
|
|
139
445
|
throw new Error();
|
|
140
446
|
restored = await res.json();
|
|
@@ -145,7 +451,9 @@ export function register(program) {
|
|
|
145
451
|
}
|
|
146
452
|
}
|
|
147
453
|
catch {
|
|
148
|
-
failures.push(
|
|
454
|
+
failures.push(redirect === undefined
|
|
455
|
+
? `${diagnostic(name, row, "GET", status)}: verification failed`
|
|
456
|
+
: `${label(name, row)}: GET verification was answered with HTTP ${redirect} redirect, which restore does not follow`);
|
|
149
457
|
continue;
|
|
150
458
|
}
|
|
151
459
|
// Report mismatched field names without mismatched content values.
|
package/dist/commands/service.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_ADMIN_USER, defaultAdminPassPath, readAdminPassFileSecure } from "../lib/auth-resolve.js";
|
|
2
2
|
import { seedUsingFlairSkill } from "../lib/skill-seed.js";
|
|
3
3
|
import { reconcilePendingSkillSeed, skillSeedPendingPath } from "../lib/skill-seed-pending.js";
|
|
4
|
-
import { classifyDaemonState } from "../lib/daemon-liveness.js";
|
|
4
|
+
import { classifyDaemonState, healthIndicatesListener } from "../lib/daemon-liveness.js";
|
|
5
5
|
import { decideStartOnUnknown, probePortListening } from "../lib/stop-start-recovery.js";
|
|
6
6
|
import { diagnoseLaunchdPlistPaths, isDetached, renderDetachedWarning, renderManagedStartUnconfirmed } from "../lib/launchd-management.js";
|
|
7
7
|
import { LaunchdValidationRefusal, loadabilityAllowsAttempt, renderDirectRunNotice, renderStartLaunchdUnavailable, } from "../lib/launchd-domain-preflight.js";
|
|
@@ -173,6 +173,60 @@ async function seedAfterStart(dataDir, port) {
|
|
|
173
173
|
console.error(`⚠️ Flair started, but the using-flair skill seed is still pending: ${err?.message ?? err}`);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Stop Flair when its launchd job was never loaded (flair#3067).
|
|
178
|
+
*
|
|
179
|
+
* A fresh `flair init` writes the plist but starts Flair directly, so the job
|
|
180
|
+
* an unload would target does not exist; the recorded process still runs.
|
|
181
|
+
* Reuses the five-state liveness machine for identity: a VERIFIED pid is
|
|
182
|
+
* signalled, and the stop waits for it with waitForProcessExit(pid,
|
|
183
|
+
* STARTUP_TIMEOUT_MS) (60 s). Refuses, without signalling, when the evidence
|
|
184
|
+
* is absent or not Flair's.
|
|
185
|
+
*/
|
|
186
|
+
async function stopDirectlyStartedFlair(port, dataDir, label) {
|
|
187
|
+
const evidence = await gatherDaemonEvidence(port, dataDir);
|
|
188
|
+
const state = classifyDaemonState(evidence, { port, dataDir });
|
|
189
|
+
switch (state.state) {
|
|
190
|
+
case "RUNNING":
|
|
191
|
+
case "WEDGED": {
|
|
192
|
+
const pid = state.pid;
|
|
193
|
+
try {
|
|
194
|
+
process.kill(pid, "SIGTERM");
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
if (err?.code !== "ESRCH") {
|
|
198
|
+
console.error(`❌ flair stop: failed to signal pid ${pid} for ${dataDir}: ${err?.code ?? err?.message}`);
|
|
199
|
+
process.exit(1);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
await waitForProcessExit(pid, cli.STARTUP_TIMEOUT_MS);
|
|
203
|
+
removeStaleSidecarIfConfirmedDead(dataDir, pid);
|
|
204
|
+
console.log(`✅ stopped the directly started Flair (pid ${pid}); the launchd job ${label} was not loaded`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
case "NOT_RUNNING":
|
|
208
|
+
console.error(`❌ flair stop: the launchd job ${label} is not loaded, and ${join(dataDir, "hdb.pid")} records no live Flair process.`);
|
|
209
|
+
console.error(" Nothing was signalled. Start Flair with: flair start");
|
|
210
|
+
process.exit(1);
|
|
211
|
+
default: {
|
|
212
|
+
// Name the process this refusal is about, from what was actually read:
|
|
213
|
+
// a pidfile pid, else the sidecar's last-known pid, else the port's
|
|
214
|
+
// listener only when a listener answered, else no identification at all.
|
|
215
|
+
const recorded = evidence.pidfile?.kind === "present" ? `pid ${evidence.pidfile.pid}`
|
|
216
|
+
: evidence.lastKnownPid !== undefined ? `pid ${evidence.lastKnownPid}`
|
|
217
|
+
: healthIndicatesListener(evidence.health) ? "the process serving the port"
|
|
218
|
+
: null;
|
|
219
|
+
if (recorded === null) {
|
|
220
|
+
console.error(`❌ flair stop: refusing to stop ${dataDir} — no Flair process could be identified, and the launchd job ${label} is not loaded. ${state.detail}`);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
console.error(`❌ flair stop: refusing to signal ${recorded} for ${dataDir} — it is not verifiably Flair's, and the launchd job ${label} is not loaded. ${state.detail}`);
|
|
224
|
+
}
|
|
225
|
+
console.error(" Nothing was signalled. Inspect it with: flair doctor");
|
|
226
|
+
process.exit(1);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
176
230
|
export function register(program) {
|
|
177
231
|
const LEGACY_LAUNCHD_LABEL = cli.LEGACY_LAUNCHD_LABEL;
|
|
178
232
|
const STARTUP_TIMEOUT_MS = cli.STARTUP_TIMEOUT_MS;
|
|
@@ -188,9 +242,37 @@ export function register(program) {
|
|
|
188
242
|
// macOS: try launchd first. resolveLaunchdLabel (flair#693) finds
|
|
189
243
|
// whichever label this data dir is actually registered under —
|
|
190
244
|
// the new instance-scoped one, or a pre-flair#693 legacy install.
|
|
191
|
-
const { plistPath } = resolveLaunchdLabel(defaultDataDir());
|
|
245
|
+
const { label, plistPath } = resolveLaunchdLabel(defaultDataDir());
|
|
192
246
|
if (existsSync(plistPath)) {
|
|
193
247
|
const dataDir = defaultDataDir();
|
|
248
|
+
// flair#3067: a fresh `flair init` writes the plist but starts Flair
|
|
249
|
+
// directly, so the job is not loaded. Unloading it stops nothing, and
|
|
250
|
+
// the wait below would spend the full startup budget on a process the
|
|
251
|
+
// unload never signalled. Ask the same question `flair restart` asks;
|
|
252
|
+
// when the job was never loaded, stop the direct process instead.
|
|
253
|
+
const managed = observeLaunchdManagement(dataDir, port);
|
|
254
|
+
if (managed.jobLoaded === "not-loaded") {
|
|
255
|
+
try {
|
|
256
|
+
await stopDirectlyStartedFlair(port, dataDir, label);
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
const failure = mapRepairThrow(err);
|
|
260
|
+
console.error(`❌ flair stop: ${failure.detail}`);
|
|
261
|
+
if (failure.kind === "failed") {
|
|
262
|
+
for (const remedy of failure.remedy ?? [])
|
|
263
|
+
console.error(` Fix: ${remedy}`);
|
|
264
|
+
}
|
|
265
|
+
process.exit(1);
|
|
266
|
+
}
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (managed.jobLoaded !== "loaded") {
|
|
270
|
+
// A lookup that failed is not an answer. Neither an unload nor a
|
|
271
|
+
// signal is licensed by it.
|
|
272
|
+
console.error(`❌ flair stop: refusing to stop ${dataDir} — could not read whether the launchd job ${label} is loaded, so nothing was signalled.`);
|
|
273
|
+
console.error(" Inspect launchd, then run: flair doctor");
|
|
274
|
+
process.exit(1);
|
|
275
|
+
}
|
|
194
276
|
let pid = null;
|
|
195
277
|
try {
|
|
196
278
|
const n = Number(readFileSync(join(dataDir, "hdb.pid"), "utf-8").trim());
|
package/dist/commands/soul.js
CHANGED
|
@@ -11,9 +11,6 @@ function api(...args) {
|
|
|
11
11
|
function resolveSigningAgentId(opts, command) {
|
|
12
12
|
return cli.resolveSigningAgentId(opts, command);
|
|
13
13
|
}
|
|
14
|
-
function applyAdminPassFile(opts) {
|
|
15
|
-
cli.applyAdminPassFile(opts);
|
|
16
|
-
}
|
|
17
14
|
function addSharedCredentialOptions(cmd) {
|
|
18
15
|
return cli.addSharedCredentialOptions(cmd);
|
|
19
16
|
}
|
|
@@ -28,7 +25,6 @@ export function register(program) {
|
|
|
28
25
|
.option("--url <url>", "Flair base URL (overrides the URL resolved from config; env: FLAIR_URL)")
|
|
29
26
|
.option("--json", "Emit raw JSON response (also: pipe + FLAIR_OUTPUT=json)")
|
|
30
27
|
.action(async (opts) => {
|
|
31
|
-
applyAdminPassFile(opts);
|
|
32
28
|
// PUT /Soul/{agentId:key} (upsert by id), matching flair-client's soul.set().
|
|
33
29
|
// The Soul table resource has no POST handler, so a collection POST /Soul
|
|
34
30
|
// 405s; the record must be written by its primary key. (#498)
|
|
@@ -67,7 +63,6 @@ export function register(program) {
|
|
|
67
63
|
.option("--url <url>", "Flair base URL (overrides the URL resolved from config; env: FLAIR_URL)")
|
|
68
64
|
.option("--json", "Emit raw JSON response (also: pipe + FLAIR_OUTPUT=json)")
|
|
69
65
|
.action(async (id, opts) => {
|
|
70
|
-
applyAdminPassFile(opts);
|
|
71
66
|
// flair#1183: /Soul reads are verified (any registered agent). Resolve the
|
|
72
67
|
// signer through the canonical seam so soul get honors the SAME precedence
|
|
73
68
|
// as every other family; a null result lets api() fall to admin-pass/floor.
|
|
@@ -105,7 +100,6 @@ export function register(program) {
|
|
|
105
100
|
.option("--url <url>", "Flair base URL (overrides the URL resolved from config; env: FLAIR_URL)")
|
|
106
101
|
.option("--json", "Emit raw JSON array (also: pipe + FLAIR_OUTPUT=json)")
|
|
107
102
|
.action(async (opts) => {
|
|
108
|
-
applyAdminPassFile(opts);
|
|
109
103
|
const { agentId, source } = resolveSigningAgentId(opts, "soul list");
|
|
110
104
|
if (!agentId) {
|
|
111
105
|
console.error(`${render.icons.error} --agent <id> required (or set FLAIR_AGENT_ID)`);
|