@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
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* key-dir.ts — the keys-directory walk shared by `flair keys prune`,
|
|
3
|
+
* `flair doctor` and `flair status` (flair#3077).
|
|
4
|
+
*
|
|
5
|
+
* Prune retains its entry classification; mode checks cover every file with a
|
|
6
|
+
* location's key suffix, because signing can read any such file.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, lstatSync, readdirSync, realpathSync } from "node:fs";
|
|
9
|
+
import { join, resolve } from "node:path";
|
|
10
|
+
import { invalidAgentIdMessage, isValidAgentId } from "./agent-id-rule.js";
|
|
11
|
+
import { resolveHome } from "./home.js";
|
|
12
|
+
/** Read the keys directory, following a symlink at keysDir. The caller owns the
|
|
13
|
+
* "directory absent" decision; this reports only what readdir returned. */
|
|
14
|
+
export function scanKeyDir(keysDir) {
|
|
15
|
+
let dirents;
|
|
16
|
+
try {
|
|
17
|
+
dirents = readdirSync(keysDir, { withFileTypes: true });
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
return { state: "unreadable", error };
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
state: "ok",
|
|
24
|
+
entries: dirents.map((dirent) => {
|
|
25
|
+
if (dirent.isDirectory())
|
|
26
|
+
return { name: dirent.name, kind: "dir" };
|
|
27
|
+
if (!dirent.name.endsWith(".key"))
|
|
28
|
+
return { name: dirent.name, kind: "other" };
|
|
29
|
+
return { name: dirent.name, kind: "key" };
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** The ordered locations `resolveKeyPath` tries for an agent id. Read at CALL
|
|
34
|
+
* time, so `FLAIR_KEY_DIR` set later in the process is seen. */
|
|
35
|
+
export function agentKeyLocations() {
|
|
36
|
+
const home = resolveHome();
|
|
37
|
+
const locations = [];
|
|
38
|
+
if (process.env.FLAIR_KEY_DIR) {
|
|
39
|
+
locations.push({ dir: process.env.FLAIR_KEY_DIR, suffix: ".key" });
|
|
40
|
+
}
|
|
41
|
+
locations.push({ dir: join(home, ".flair", "keys"), suffix: ".key" });
|
|
42
|
+
locations.push({ dir: join(home, ".tps", "secrets", "flair"), suffix: "-priv.key" });
|
|
43
|
+
return locations;
|
|
44
|
+
}
|
|
45
|
+
/** A refusal for an agent id that cannot name a key file: the id is checked
|
|
46
|
+
* before it is joined into a path. Callers map it to their own error style. */
|
|
47
|
+
export class AgentKeyPathRefusal extends Error {
|
|
48
|
+
code = "invalid_agent_id";
|
|
49
|
+
/** The CLI prints the message alone and exits 1 when a command lets it propagate. */
|
|
50
|
+
flairFriendly = true;
|
|
51
|
+
constructor(message) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = "AgentKeyPathRefusal";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Apply the shared agent-ID rule to an id a command is about to sign as. */
|
|
57
|
+
export function requireAgentId(agentId) {
|
|
58
|
+
if (!isValidAgentId(agentId))
|
|
59
|
+
throw new AgentKeyPathRefusal(invalidAgentIdMessage(agentId));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The private-key path for `agentId`; the shared agent-ID rule runs before
|
|
63
|
+
* the join.
|
|
64
|
+
*/
|
|
65
|
+
export function agentKeyPath(keysDir, agentId) {
|
|
66
|
+
requireAgentId(agentId);
|
|
67
|
+
return join(keysDir, `${agentId}.key`);
|
|
68
|
+
}
|
|
69
|
+
/** The public-key path for `agentId`; the shared agent-ID rule runs before
|
|
70
|
+
* the join. */
|
|
71
|
+
export function agentPubKeyPath(keysDir, agentId) {
|
|
72
|
+
requireAgentId(agentId);
|
|
73
|
+
return join(keysDir, `${agentId}.pub`);
|
|
74
|
+
}
|
|
75
|
+
/** The path signing reads for `agentId` in `location`. */
|
|
76
|
+
export function keyPathIn(location, agentId) {
|
|
77
|
+
requireAgentId(agentId);
|
|
78
|
+
return join(location.dir, `${agentId}${location.suffix}`);
|
|
79
|
+
}
|
|
80
|
+
/** The legacy `~/.tps/secrets/flair/<id>-priv.key` signing key for `agentId`;
|
|
81
|
+
* the shared agent-ID rule runs before the join. */
|
|
82
|
+
export function legacyAgentKeyPath(agentId) {
|
|
83
|
+
requireAgentId(agentId);
|
|
84
|
+
return join(resolveHome(), ".tps", "secrets", "flair", `${agentId}-priv.key`);
|
|
85
|
+
}
|
|
86
|
+
function errorCode(error) {
|
|
87
|
+
const code = error?.code;
|
|
88
|
+
return typeof code === "string" ? code : "lstat failed";
|
|
89
|
+
}
|
|
90
|
+
/** lstat one key path and report a wide or uncheckable file. No content is read
|
|
91
|
+
* and no file is changed; entry symlinks are not followed. */
|
|
92
|
+
function keyModeFindingForPath(path) {
|
|
93
|
+
let stats;
|
|
94
|
+
try {
|
|
95
|
+
stats = lstatSync(path);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
return { kind: "not-checked", path, reason: errorCode(error) };
|
|
99
|
+
}
|
|
100
|
+
if (!stats.isFile()) {
|
|
101
|
+
return {
|
|
102
|
+
kind: "not-checked",
|
|
103
|
+
path,
|
|
104
|
+
reason: stats.isSymbolicLink() ? "symbolic link" : "not a regular file",
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (stats.mode & 0o077) {
|
|
108
|
+
return { kind: "wide", path, mode: (stats.mode & 0o777).toString(8).padStart(4, "0") };
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
function canonicalDir(dir) {
|
|
113
|
+
try {
|
|
114
|
+
return realpathSync(dir);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return resolve(dir);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Whether two key-location paths name the same directory entry after resolving symlinks. */
|
|
121
|
+
export function sameKeyDir(a, b) {
|
|
122
|
+
return canonicalDir(a) === canonicalDir(b);
|
|
123
|
+
}
|
|
124
|
+
/** The mode scan over the standard `resolveKeyPath` locations. A path reached
|
|
125
|
+
* through two locations (e.g. `FLAIR_KEY_DIR` pointing at the default
|
|
126
|
+
* directory) is reported once. */
|
|
127
|
+
export function scanAgentKeyModes(locations = agentKeyLocations()) {
|
|
128
|
+
const findings = [];
|
|
129
|
+
const unreadable = [];
|
|
130
|
+
const seenPaths = new Set();
|
|
131
|
+
const seenUnreadable = new Set();
|
|
132
|
+
for (const location of locations) {
|
|
133
|
+
const dirKey = canonicalDir(location.dir);
|
|
134
|
+
const scan = scanKeyDir(location.dir);
|
|
135
|
+
if (scan.state === "unreadable") {
|
|
136
|
+
const code = scan.error?.code;
|
|
137
|
+
if (code !== "ENOENT" && !seenUnreadable.has(dirKey)) {
|
|
138
|
+
seenUnreadable.add(dirKey);
|
|
139
|
+
unreadable.push({ dir: location.dir, code: code ?? "error" });
|
|
140
|
+
}
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const names = scan.entries.map((e) => e.name).filter((name) => name.endsWith(location.suffix)).sort();
|
|
144
|
+
for (const name of names) {
|
|
145
|
+
const path = join(location.dir, name);
|
|
146
|
+
const pathKey = join(dirKey, name);
|
|
147
|
+
if (seenPaths.has(pathKey))
|
|
148
|
+
continue;
|
|
149
|
+
seenPaths.add(pathKey);
|
|
150
|
+
const finding = keyModeFindingForPath(path);
|
|
151
|
+
if (finding)
|
|
152
|
+
findings.push(finding);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { findings, unreadable };
|
|
156
|
+
}
|
|
157
|
+
/** POSIX single-quoting for a path used in a command an operator will run. A
|
|
158
|
+
* relative path that starts with `-` is prefixed with `./`, so the command
|
|
159
|
+
* does not read it as an option. */
|
|
160
|
+
function shellQuotePath(path) {
|
|
161
|
+
const operand = path.startsWith("-") ? `./${path}` : path;
|
|
162
|
+
if (/^[A-Za-z0-9._\-/]+$/.test(operand))
|
|
163
|
+
return operand;
|
|
164
|
+
return `'${operand.replace(/'/g, `'\\''`)}'`;
|
|
165
|
+
}
|
|
166
|
+
/** The one rendering of a finding, so doctor and status cannot word it
|
|
167
|
+
* differently. The `chmod` remedy shell-quotes the path. */
|
|
168
|
+
export function formatKeyModeFinding(finding) {
|
|
169
|
+
if (finding.kind === "wide") {
|
|
170
|
+
return `agent key file ${finding.path} has mode ${finding.mode}, wider than owner-only — fix: chmod 600 ${shellQuotePath(finding.path)}`;
|
|
171
|
+
}
|
|
172
|
+
return `agent key file ${finding.path} not checked (${finding.reason})`;
|
|
173
|
+
}
|
|
174
|
+
/** Mode bits carry no owner-only meaning on Windows. */
|
|
175
|
+
export function keyModesUnsupported() {
|
|
176
|
+
return process.platform === "win32";
|
|
177
|
+
}
|
|
178
|
+
export const KEY_MODES_UNSUPPORTED_MESSAGE = "key file modes are not checked on Windows";
|
|
179
|
+
/** The keys directory `~/.flair/keys`, resolved at CALL time. */
|
|
180
|
+
export function defaultKeysDir() {
|
|
181
|
+
return join(resolveHome(), ".flair", "keys");
|
|
182
|
+
}
|
|
183
|
+
/** Node-shaped file ids. */
|
|
184
|
+
const NODE_KEY_ID_RE = /^flair_[0-9a-f]{8}$/;
|
|
185
|
+
/** Match node-shaped ids without a sibling .pub; file type is unproven. */
|
|
186
|
+
export function isNodeKeyId(id, keysDir) {
|
|
187
|
+
if (!NODE_KEY_ID_RE.test(id))
|
|
188
|
+
return false;
|
|
189
|
+
return !existsSync(agentPubKeyPath(keysDir, id));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Partition `.key`-derived ids by file name: an id that `isNodeKeyId` matches
|
|
193
|
+
* (node-shaped, no sibling `.pub`) goes to `nodeKeyIds`, every other id to
|
|
194
|
+
* `agentKeyIds`. Key contents are not read.
|
|
195
|
+
*/
|
|
196
|
+
export function partitionKeyIds(ids, keysDir) {
|
|
197
|
+
const agentKeyIds = [];
|
|
198
|
+
const nodeKeyIds = [];
|
|
199
|
+
for (const id of ids) {
|
|
200
|
+
(isNodeKeyId(id, keysDir) ? nodeKeyIds : agentKeyIds).push(id);
|
|
201
|
+
}
|
|
202
|
+
return { agentKeyIds, nodeKeyIds };
|
|
203
|
+
}
|
|
@@ -249,11 +249,15 @@ export function classifyServiceNodePin(input, deps = {}) {
|
|
|
249
249
|
kind: "pinned",
|
|
250
250
|
unitNodeBin,
|
|
251
251
|
currentNodeBin,
|
|
252
|
-
//
|
|
253
|
-
//
|
|
252
|
+
// With valid targets and existing other runtime paths, `flair init`
|
|
253
|
+
// reports `pinned-node`, except for a plist's eligible Cellar-to-opt
|
|
254
|
+
// replacement (flair#3056). A plist can replace a missing runtime path
|
|
255
|
+
// and an eligible Cellar node together; systemd refuses missing paths.
|
|
256
|
+
// Moving the pin to this CLI's runtime is a hand edit.
|
|
254
257
|
message: `${unitDescription} pins node ${unitNodeBin} while this CLI runs ${currentNodeBin}, and it serves this ` +
|
|
255
258
|
`CLI's own install tree (${unitTree}). That is treated as a deliberate runtime pin and left as it is; ` +
|
|
256
|
-
"`flair init` does not change it
|
|
259
|
+
"`flair init` does not change it, except that it can replace a Homebrew Cellar node path in a launchd plist " +
|
|
260
|
+
"with its `opt` alias (the same binary). To move the service to this CLI's runtime, change that node path to " +
|
|
257
261
|
`${currentNodeBin} in the unit by hand, then run: flair restart`,
|
|
258
262
|
remedy: [],
|
|
259
263
|
};
|
|
@@ -308,12 +312,17 @@ export function readLaunchctlJobState(label, list) {
|
|
|
308
312
|
res = list(label);
|
|
309
313
|
}
|
|
310
314
|
catch {
|
|
311
|
-
return { registered: false, pid: null, lastExitStatus: null };
|
|
315
|
+
return { registered: false, readable: false, pid: null, lastExitStatus: null };
|
|
312
316
|
}
|
|
317
|
+
// 113 is launchd's "service not found": an ANSWER that the job is not
|
|
318
|
+
// loaded. Any other non-zero code is a failed lookup, which must not be read
|
|
319
|
+
// as "not loaded" by a caller that acts on the answer (flair#3067).
|
|
320
|
+
if (res.code === 113)
|
|
321
|
+
return { registered: false, readable: true, pid: null, lastExitStatus: null };
|
|
313
322
|
if (res.code !== 0)
|
|
314
|
-
return { registered: false, pid: null, lastExitStatus: null };
|
|
323
|
+
return { registered: false, readable: false, pid: null, lastExitStatus: null };
|
|
315
324
|
const { pid, lastExitStatus } = parseLaunchctlList(res.stdout);
|
|
316
|
-
return { registered: true, pid, lastExitStatus };
|
|
325
|
+
return { registered: true, readable: true, pid, lastExitStatus };
|
|
317
326
|
}
|
|
318
327
|
/**
|
|
319
328
|
* Which PID to treat as "the process serving this instance".
|
|
@@ -400,6 +409,7 @@ export function assessLaunchdManagement(input) {
|
|
|
400
409
|
return { state: "no-service", detail: `no launchd service is registered for this instance (${plistPath})` };
|
|
401
410
|
}
|
|
402
411
|
const job = readLaunchctlJobState(label, list);
|
|
412
|
+
const jobLoaded = !job.readable ? "unknown" : job.registered ? "loaded" : "not-loaded";
|
|
403
413
|
const diagnose = input.diagnose ?? ((p) => diagnoseLaunchdPlistPaths(p));
|
|
404
414
|
const detachedRemedy = () => {
|
|
405
415
|
const stale = diagnose(plistPath);
|
|
@@ -416,6 +426,7 @@ export function assessLaunchdManagement(input) {
|
|
|
416
426
|
return {
|
|
417
427
|
state: "detached",
|
|
418
428
|
label,
|
|
429
|
+
jobLoaded,
|
|
419
430
|
detail: `the launchd service ${label} is registered on disk but not loaded, so launchd is not managing this instance.${because}`,
|
|
420
431
|
remedy,
|
|
421
432
|
};
|
|
@@ -428,6 +439,7 @@ export function assessLaunchdManagement(input) {
|
|
|
428
439
|
return {
|
|
429
440
|
state: "detached",
|
|
430
441
|
label,
|
|
442
|
+
jobLoaded,
|
|
431
443
|
detail: `the launchd job ${label} is loaded but not running, so whatever is serving this instance was not started by launchd.${exit}${because}`,
|
|
432
444
|
remedy,
|
|
433
445
|
};
|
|
@@ -437,6 +449,7 @@ export function assessLaunchdManagement(input) {
|
|
|
437
449
|
return {
|
|
438
450
|
state: "detached",
|
|
439
451
|
label,
|
|
452
|
+
jobLoaded,
|
|
440
453
|
detail: `this instance is served by process ${instancePid}, but launchd's job ${label} is process ${job.pid} — ` +
|
|
441
454
|
`the running instance is not the one launchd manages.${because}`,
|
|
442
455
|
remedy,
|
|
@@ -452,6 +465,7 @@ export function assessLaunchdManagement(input) {
|
|
|
452
465
|
return {
|
|
453
466
|
state: "unverified",
|
|
454
467
|
label,
|
|
468
|
+
jobLoaded,
|
|
455
469
|
detail: `launchd job ${label} is running as process ${job.pid}, but the process serving this instance could not be ` +
|
|
456
470
|
"identified (no live hdb.pid, and no listener found on its port), so launchd management is NOT verified",
|
|
457
471
|
remedy: ["flair restart"],
|
|
@@ -462,6 +476,7 @@ export function assessLaunchdManagement(input) {
|
|
|
462
476
|
return {
|
|
463
477
|
state: "managed",
|
|
464
478
|
label,
|
|
479
|
+
jobLoaded,
|
|
465
480
|
detail: `launchd job ${label} is running as process ${job.pid}`,
|
|
466
481
|
launchdPid: job.pid,
|
|
467
482
|
servingPid: instancePid,
|
|
@@ -64,6 +64,13 @@ import { readProcessBirth, readTcpListenerPids, LISTENER_VISIBILITY_REMEDY } fro
|
|
|
64
64
|
import { defaultReadProcessCmdline } from "./upgrade-exec-path.js";
|
|
65
65
|
/** The host halves of an `http.port` binding that bind on loopback or on all interfaces. */
|
|
66
66
|
const LOCAL_HTTP_BIND_HOSTS = ["127.0.0.1", "localhost", "0.0.0.0", "[::]", ""];
|
|
67
|
+
export class IncompleteInstancePairError extends Error {
|
|
68
|
+
reason;
|
|
69
|
+
constructor(message, supplied, missing) {
|
|
70
|
+
super(message);
|
|
71
|
+
this.reason = { kind: "one-sided", supplied, missing };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
67
74
|
const DEFAULT_OS_READS = {
|
|
68
75
|
listeners: (port) => readTcpListenerPids(port),
|
|
69
76
|
birth: (pid) => readProcessBirth(pid),
|
|
@@ -227,7 +234,7 @@ function harperListenerRefusal(os, pid, label, port) {
|
|
|
227
234
|
/** The one process listening on `port`, or an `unproven` proof naming why not. */
|
|
228
235
|
function soleListener(read, label, port) {
|
|
229
236
|
if (read.kind === "unavailable") {
|
|
230
|
-
return { kind: "unproven", status: null, detail: `the listener table for ${label} port ${port} cannot be read: ${read.reason}`, remedy: read.remedy };
|
|
237
|
+
return { kind: "unproven", status: null, detail: `the listener table for ${label} port ${port} cannot be read: ${read.reason}`, remedy: read.remedy, reason: "listener-table-unavailable" };
|
|
231
238
|
}
|
|
232
239
|
if (read.pids.length === 0) {
|
|
233
240
|
return {
|
package/dist/lib/mcp-enable.js
CHANGED
|
@@ -486,14 +486,15 @@ export function buildMcpOAuthConfigBlock(params) {
|
|
|
486
486
|
},
|
|
487
487
|
mcp: {
|
|
488
488
|
// flair#1152: whole-token env reference — same flag flair's in-process
|
|
489
|
-
// route gates on. ASYMMETRY (load-bearing, measured on
|
|
490
|
-
// the component's coerceConfigBoolean
|
|
491
|
-
//
|
|
492
|
-
//
|
|
493
|
-
//
|
|
494
|
-
//
|
|
495
|
-
//
|
|
496
|
-
//
|
|
489
|
+
// route gates on. ASYMMETRY (load-bearing, measured on
|
|
490
|
+
// @harperfast/oauth 2.9.0): the component's coerceConfigBoolean trims
|
|
491
|
+
// and lowercases, mapping "true"/"false" to a boolean, and
|
|
492
|
+
// normalizeBooleanField deletes strings it cannot coerce (unresolved
|
|
493
|
+
// placeholder, "1", "yes", garbage), so its disabled default applies
|
|
494
|
+
// (dist/lib/config.js); flair's mcpOAuthEnabled()
|
|
495
|
+
// (resources/mcp-oauth-flag.ts) accepts 1/true/yes/on. Both readers
|
|
496
|
+
// accept "true". "1"/"yes"/"on" leave the component AS off; /mcp is
|
|
497
|
+
// not mounted. Garbage and an unset variable disable both. On oauth
|
|
497
498
|
// <2.5.0 there is NO normalization and an unresolved placeholder is a
|
|
498
499
|
// truthy string (fail-open) — which is why the resolved-version
|
|
499
500
|
// assertion in mcp-oauth-boot-safety.test.ts exists. If component
|
|
@@ -940,13 +941,11 @@ export function buildSecretsBundle(params) {
|
|
|
940
941
|
throw new IdpRedirectOriginError(envPrefix);
|
|
941
942
|
}
|
|
942
943
|
return {
|
|
943
|
-
// "true" is the
|
|
944
|
-
//
|
|
945
|
-
//
|
|
946
|
-
//
|
|
947
|
-
//
|
|
948
|
-
// component's AS stays OFF — fail-closed but broken-on (every request
|
|
949
|
-
// 401s, no AS is advertised). Keep this "true".
|
|
944
|
+
// "true" is the recommended value both readers of this flag accept
|
|
945
|
+
// (flair#1152): flair's strict mcpOAuthEnabled() takes 1/true/yes/on, but
|
|
946
|
+
// the component's coerceConfigBoolean maps only true/false strings
|
|
947
|
+
// (trimmed, any case) to a boolean and returns undefined otherwise, and
|
|
948
|
+
// normalizeBooleanField then deletes the field (disabled default applies).
|
|
950
949
|
FLAIR_MCP_OAUTH: "true",
|
|
951
950
|
FLAIR_MCP_ISSUER: params.issuer.replace(/\/+$/, ""),
|
|
952
951
|
[`${envPrefix}_CLIENT_ID`]: params.idpClientId,
|
|
@@ -26,9 +26,11 @@ export const DECLARED_MEMORY_ATTRIBUTES = Object.freeze([
|
|
|
26
26
|
"retrievalCount",
|
|
27
27
|
"lastRetrieved",
|
|
28
28
|
"usageCount",
|
|
29
|
+
"writeBackWriteId",
|
|
29
30
|
"promotionStatus",
|
|
30
31
|
"promotedAt",
|
|
31
32
|
"promotedBy",
|
|
33
|
+
"promotionContentHash",
|
|
32
34
|
"archived",
|
|
33
35
|
"archivedAt",
|
|
34
36
|
"archivedBy",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The embedding provider's write refusal, shared by the writers that retry it.
|
|
3
|
+
*
|
|
4
|
+
* The server answers `503` with error code `memory_provider_timeout` when the
|
|
5
|
+
* provider did not answer within its bound. The write-lock contract states
|
|
6
|
+
* such a refusal wrote nothing, so replaying the write with the same id
|
|
7
|
+
* cannot double-write the row.
|
|
8
|
+
*/
|
|
9
|
+
import { ApiHttpError, apiErrorRawBody } from "./auth-resolve.js";
|
|
10
|
+
/** Base wait before a retry of a memory write refused with `503 memory_provider_timeout`. */
|
|
11
|
+
export const MEMORY_PROVIDER_RETRY_DELAY_MS = 1_000;
|
|
12
|
+
/**
|
|
13
|
+
* The server's `error` code on an `ApiHttpError`, parsed from the response body
|
|
14
|
+
* that error carries (`apiErrorRawBody`; the message is never read). Returns
|
|
15
|
+
* undefined for a non-HTTP error, an error that carries no body, or a body
|
|
16
|
+
* without a string `error` field.
|
|
17
|
+
*/
|
|
18
|
+
export function apiErrorCode(err) {
|
|
19
|
+
const text = apiErrorRawBody(err);
|
|
20
|
+
if (text === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
try {
|
|
23
|
+
const body = JSON.parse(text);
|
|
24
|
+
return body && typeof body === "object" && typeof body.error === "string" ? body.error : undefined;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** A memory write refused with exactly 503 and `memory_provider_timeout`. */
|
|
31
|
+
export function isProviderTimeoutRefusal(err) {
|
|
32
|
+
return err instanceof ApiHttpError && err.status === 503 && apiErrorCode(err) === "memory_provider_timeout";
|
|
33
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mqtt-config.ts — the MQTT-off configuration flair runs Harper with, in the
|
|
3
|
+
* two shapes Harper accepts it, and the reading of an instance's `mqtt`
|
|
4
|
+
* configuration section.
|
|
5
|
+
*
|
|
6
|
+
* Flair does not use MQTT. Harper's mqtt component (server/mqtt.ts
|
|
7
|
+
* `handleApplication`) binds a TCP listener on `mqtt.network.port` (1883) and
|
|
8
|
+
* a TLS listener on `mqtt.network.securePort` (8883) whenever EITHER is truthy
|
|
9
|
+
* (`if (port || securePort)`), plus a WebSocket upgrade path on the HTTP port
|
|
10
|
+
* when `mqtt.webSocket` is true. Nulling only `network.port` leaves
|
|
11
|
+
* `network.securePort` at its 8883 default, so the TLS listener still binds.
|
|
12
|
+
* Fully disabling MQTT requires nulling BOTH ports and turning off the
|
|
13
|
+
* WebSocket path.
|
|
14
|
+
*
|
|
15
|
+
* Where it is applied:
|
|
16
|
+
* - flair's local spawns: the HARPER_SET_CONFIG builders (src/cli.ts,
|
|
17
|
+
* src/commands/init.ts) carry MQTT_DISABLED_CONFIG, and the direct-spawn
|
|
18
|
+
* environment and launchd plist re-assert it with MQTT_* variables;
|
|
19
|
+
* - a component deployment (`flair deploy`, `flair upgrade --target`):
|
|
20
|
+
* src/mqtt-off-deploy.ts sends MQTT_DISABLED_SET_CONFIGURATION to the
|
|
21
|
+
* target's operations API before the deploy, requests the shared worker
|
|
22
|
+
* threads' restart when the application is isolated, and after the
|
|
23
|
+
* deploy's restart reads the saved configuration back, which must be a
|
|
24
|
+
* recognizable root configuration (rootConfigurationProblem) showing
|
|
25
|
+
* those values (mqttOffConfirmed). It does not probe the listeners. A
|
|
26
|
+
* component's own config.yaml cannot set it: `mqtt` is a section of the
|
|
27
|
+
* instance's root configuration, not of an application's.
|
|
28
|
+
* `flair doctor` reports an instance whose saved configuration starts an MQTT
|
|
29
|
+
* listener (src/lib/mqtt-listener-doctor.ts); it reads the configuration, not
|
|
30
|
+
* the running listeners.
|
|
31
|
+
*
|
|
32
|
+
* Note: config-root.schema.json still documents a flat `mqtt.port` /
|
|
33
|
+
* `mqtt.securePort`, but the runtime reads the nested `mqtt.network.*` form
|
|
34
|
+
* (see static/defaultConfig.yaml) — the flat keys are stale.
|
|
35
|
+
*/
|
|
36
|
+
import { harperPortValue } from "./harper-port-value.js";
|
|
37
|
+
/** Harper's `mqtt` configuration section with every MQTT listener off. */
|
|
38
|
+
export const MQTT_DISABLED_CONFIG = {
|
|
39
|
+
network: { port: null, securePort: null },
|
|
40
|
+
webSocket: false,
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* MQTT_DISABLED_CONFIG as the operations API's `set_configuration`
|
|
44
|
+
* parameters: Harper's flattened config names, each set on its own, so the
|
|
45
|
+
* rest of the instance's `mqtt` section (requireAuthentication, mtls) is left
|
|
46
|
+
* as it is.
|
|
47
|
+
*/
|
|
48
|
+
export const MQTT_DISABLED_SET_CONFIGURATION = Object.freeze({
|
|
49
|
+
mqtt_network_port: MQTT_DISABLED_CONFIG.network.port,
|
|
50
|
+
mqtt_network_securePort: MQTT_DISABLED_CONFIG.network.securePort,
|
|
51
|
+
mqtt_webSocket: MQTT_DISABLED_CONFIG.webSocket,
|
|
52
|
+
});
|
|
53
|
+
function isObject(value) {
|
|
54
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Why `config` is not taken for an instance's root configuration (the
|
|
58
|
+
* operations API's `get_configuration` answer), or null when it is: it must be
|
|
59
|
+
* an object with an object `http`, an object `operationsApi` and a non-empty
|
|
60
|
+
* string `rootPath`, which every root configuration Harper returns carries.
|
|
61
|
+
* It checks only those three fields: an answer missing any of them (`{}`, an
|
|
62
|
+
* error object) is refused, and nothing is concluded from it; any object that
|
|
63
|
+
* carries all three is accepted, whatever else it lacks.
|
|
64
|
+
*/
|
|
65
|
+
export function rootConfigurationProblem(config) {
|
|
66
|
+
if (!isObject(config))
|
|
67
|
+
return "the answer is not an object";
|
|
68
|
+
const missing = [
|
|
69
|
+
isObject(config.http) ? null : "http",
|
|
70
|
+
isObject(config.operationsApi) ? null : "operationsApi",
|
|
71
|
+
typeof config.rootPath === "string" && config.rootPath !== "" ? null : "rootPath",
|
|
72
|
+
].filter((m) => m !== null);
|
|
73
|
+
return missing.length ? `it has no ${missing.join(", ")}` : null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The MQTT listeners Harper starts for an instance whose root configuration
|
|
77
|
+
* holds `config` (the operations API's `get_configuration` answer), in
|
|
78
|
+
* Harper's own terms: none when the configuration has no `mqtt` section
|
|
79
|
+
* (Harper does not load the component), a WebSocket path when
|
|
80
|
+
* `mqtt.webSocket` is truthy, a TCP listener when `mqtt.network.port` is
|
|
81
|
+
* truthy and a TLS listener when `mqtt.network.securePort` is. Returns a
|
|
82
|
+
* description of each, empty when MQTT is off.
|
|
83
|
+
*/
|
|
84
|
+
export function mqttListenersOn(config) {
|
|
85
|
+
const mqtt = isObject(config) ? config.mqtt : undefined;
|
|
86
|
+
if (!isObject(mqtt))
|
|
87
|
+
return [];
|
|
88
|
+
const listeners = [];
|
|
89
|
+
if (mqtt.webSocket)
|
|
90
|
+
listeners.push("MQTT over WebSocket on the HTTP port (mqtt.webSocket)");
|
|
91
|
+
const network = isObject(mqtt.network) ? mqtt.network : {};
|
|
92
|
+
// A port is printed only as the integer it parses to; any other value is not.
|
|
93
|
+
const portText = (value) => {
|
|
94
|
+
const port = harperPortValue(value);
|
|
95
|
+
return port === null ? "" : ` ${port}`;
|
|
96
|
+
};
|
|
97
|
+
if (network.port)
|
|
98
|
+
listeners.push(`MQTT on TCP port${portText(network.port)} (mqtt.network.port)`);
|
|
99
|
+
if (network.securePort)
|
|
100
|
+
listeners.push(`MQTT on TLS port${portText(network.securePort)} (mqtt.network.securePort)`);
|
|
101
|
+
return listeners;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Why `config` (a `get_configuration` answer read after the MQTT-off
|
|
105
|
+
* configuration was set) does not show those values, or null when it does:
|
|
106
|
+
* an `mqtt` section whose `network.port` and `network.securePort` are null and
|
|
107
|
+
* whose `webSocket` is false. Unlike mqttListenersOn, an empty or malformed
|
|
108
|
+
* answer is not taken for "off". The reason names fixed field names and
|
|
109
|
+
* categories only ("mqtt.webSocket is not false"), never a value the answer
|
|
110
|
+
* carries.
|
|
111
|
+
*/
|
|
112
|
+
export function mqttOffConfirmed(config) {
|
|
113
|
+
if (!isObject(config))
|
|
114
|
+
return "the answer is not a configuration object";
|
|
115
|
+
const mqtt = config.mqtt;
|
|
116
|
+
if (!isObject(mqtt))
|
|
117
|
+
return "the answer has no mqtt section";
|
|
118
|
+
const problems = [];
|
|
119
|
+
if (mqtt.webSocket !== false)
|
|
120
|
+
problems.push(mqtt.webSocket === undefined ? "mqtt.webSocket is missing" : "mqtt.webSocket is not false");
|
|
121
|
+
const network = mqtt.network;
|
|
122
|
+
if (!isObject(network)) {
|
|
123
|
+
problems.push("mqtt.network is missing");
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
if (network.port !== null)
|
|
127
|
+
problems.push(network.port === undefined ? "mqtt.network.port is missing" : "mqtt.network.port is not null");
|
|
128
|
+
if (network.securePort !== null)
|
|
129
|
+
problems.push(network.securePort === undefined ? "mqtt.network.securePort is missing" : "mqtt.network.securePort is not null");
|
|
130
|
+
}
|
|
131
|
+
return problems.length ? problems.join(", ") : null;
|
|
132
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mqtt-listener-doctor.ts — the `flair doctor` check that reports when the
|
|
3
|
+
* saved configuration of the instance it inspects starts an MQTT listener.
|
|
4
|
+
*
|
|
5
|
+
* Flair runs Harper with MQTT off (src/lib/mqtt-config.ts): its local spawns
|
|
6
|
+
* assert it, and `flair deploy` / `flair upgrade --target` set it on a
|
|
7
|
+
* component deployment and request the restart that applies it. This check reads the
|
|
8
|
+
* instance's root configuration through the operations API
|
|
9
|
+
* (`get_configuration`) and names each MQTT listener that configuration starts
|
|
10
|
+
* — the TCP and TLS listeners and the WebSocket path — with the operation that
|
|
11
|
+
* sets them off in the configuration, as Flair sets them by default. It never
|
|
12
|
+
* changes the configuration.
|
|
13
|
+
*
|
|
14
|
+
* It reads the CONFIGURATION, not the running listeners: Harper applies a
|
|
15
|
+
* changed `mqtt` section when the HTTP worker threads restart, so worker
|
|
16
|
+
* threads that have not restarted since it changed may still serve their
|
|
17
|
+
* previous listener configuration. The section says so on every path, including the NOT RUN
|
|
18
|
+
* ones doctor prints itself (src/commands/doctor.ts), and names how to
|
|
19
|
+
* confirm on a node: connect an MQTT client to its MQTT ports or WebSocket
|
|
20
|
+
* path. Flair does not probe the listeners.
|
|
21
|
+
*
|
|
22
|
+
* The read answers "not run" when it fails or when the answer is not a
|
|
23
|
+
* recognizable root configuration (rootConfigurationProblem: an answer without
|
|
24
|
+
* an object `http`, an object `operationsApi` and a non-empty string
|
|
25
|
+
* `rootPath`, such as `{}`, a lone `mqtt` section or an error object; an object
|
|
26
|
+
* carrying all three is accepted, whatever else it lacks), so a doctor that
|
|
27
|
+
* cannot establish the configuration reports the check as NOT RUN and counts
|
|
28
|
+
* it, rather than passing it.
|
|
29
|
+
*/
|
|
30
|
+
import { MQTT_DISABLED_SET_CONFIGURATION, mqttListenersOn, rootConfigurationProblem } from "./mqtt-config.js";
|
|
31
|
+
/** The doctor line when the instance's configuration starts no MQTT listener. */
|
|
32
|
+
export const MQTT_LISTENERS_OFF_LINE = "No MQTT listener is configured on this instance (mqtt.network.port, mqtt.network.securePort and mqtt.webSocket are off).";
|
|
33
|
+
/** What every MQTT line adds: the check reads the saved configuration, not the running listeners, and how to confirm on a node. */
|
|
34
|
+
export const MQTT_CONFIGURATION_NOTE = "This reads the saved configuration, not the running listeners: worker threads that have not restarted since it changed may still serve their previous listener configuration. " +
|
|
35
|
+
"To confirm on a node, connect an MQTT client to its MQTT ports or WebSocket path.";
|
|
36
|
+
/** The set_configuration call that sets every MQTT listener off in the configuration, as an operator would send it. */
|
|
37
|
+
export function mqttOffOperation() {
|
|
38
|
+
return JSON.stringify({ operation: "set_configuration", ...MQTT_DISABLED_SET_CONFIGURATION });
|
|
39
|
+
}
|
|
40
|
+
/** The doctor finding for an instance configuration: null when no MQTT listener is on. */
|
|
41
|
+
export function describeMqttListenerFinding(config) {
|
|
42
|
+
const listeners = mqttListenersOn(config);
|
|
43
|
+
if (listeners.length === 0)
|
|
44
|
+
return null;
|
|
45
|
+
return {
|
|
46
|
+
message: `This instance's configuration starts ${listeners.length === 1 ? "an MQTT listener" : `${listeners.length} MQTT listeners`}: ${listeners.join("; ")}. Flair sets MQTT off in Harper's configuration by default.`,
|
|
47
|
+
fixHint: `send ${mqttOffOperation()} to the operations API: it sets every MQTT listener off in the configuration, as Flair does by default ` +
|
|
48
|
+
"(flair's local spawns on every start; flair deploy and flair upgrade --target for a component deployment). The listeners stop when Harper's worker threads restart, so restart them.",
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Read the instance's root configuration through the operations API. A
|
|
53
|
+
* redirect is not followed: any 3xx answer is NOT RUN (named by its status;
|
|
54
|
+
* the location it names is not printed and receives nothing), so the check
|
|
55
|
+
* reads only the endpoint it was given.
|
|
56
|
+
*/
|
|
57
|
+
export async function readInstanceConfiguration(args) {
|
|
58
|
+
const fetchImpl = args.fetchImpl ?? fetch;
|
|
59
|
+
let res;
|
|
60
|
+
try {
|
|
61
|
+
res = await fetchImpl(args.opsUrl, {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: { "Content-Type": "application/json", Authorization: args.authHeader },
|
|
64
|
+
body: JSON.stringify({ operation: "get_configuration" }),
|
|
65
|
+
signal: AbortSignal.timeout(args.timeoutMs ?? 5000),
|
|
66
|
+
redirect: "manual",
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return { kind: "not-run", reason: "the configuration read failed" };
|
|
71
|
+
}
|
|
72
|
+
if (res.status >= 300 && res.status < 400) {
|
|
73
|
+
return { kind: "not-run", reason: `the configuration read was answered with a redirect (HTTP ${res.status}), which is not followed` };
|
|
74
|
+
}
|
|
75
|
+
if (!res.ok)
|
|
76
|
+
return { kind: "not-run", reason: `the configuration read was answered HTTP ${res.status}` };
|
|
77
|
+
let data;
|
|
78
|
+
try {
|
|
79
|
+
data = await res.json();
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return { kind: "not-run", reason: "the configuration answer is not JSON" };
|
|
83
|
+
}
|
|
84
|
+
const problem = rootConfigurationProblem(data);
|
|
85
|
+
if (problem)
|
|
86
|
+
return { kind: "not-run", reason: `the answer is not a recognizable root configuration (${problem})` };
|
|
87
|
+
return { kind: "ok", config: data };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The doctor's "MQTT listeners (configuration)" section for a configuration
|
|
91
|
+
* read: `ok` with the all-off line, `issue` with the listeners on and the fix,
|
|
92
|
+
* or `not-run` with why the configuration could not be established; each with
|
|
93
|
+
* MQTT_CONFIGURATION_NOTE (the configuration, not the running listeners).
|
|
94
|
+
* Doctor counts every status but `ok` as an issue.
|
|
95
|
+
*/
|
|
96
|
+
export function mqttListenerSection(read) {
|
|
97
|
+
if (read.kind === "not-run") {
|
|
98
|
+
return { status: "not-run", line: `MQTT listeners: NOT RUN — ${read.reason}, so the MQTT listener configuration check did not run.`, note: MQTT_CONFIGURATION_NOTE };
|
|
99
|
+
}
|
|
100
|
+
const finding = describeMqttListenerFinding(read.config);
|
|
101
|
+
if (!finding)
|
|
102
|
+
return { status: "ok", line: MQTT_LISTENERS_OFF_LINE, note: MQTT_CONFIGURATION_NOTE };
|
|
103
|
+
return { status: "issue", line: finding.message, note: MQTT_CONFIGURATION_NOTE, fix: finding.fixHint };
|
|
104
|
+
}
|