@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.
Files changed (232) hide show
  1. package/README.md +6 -6
  2. package/SECURITY.md +18 -10
  3. package/config.yaml +11 -11
  4. package/dist/bridges/runtime/execute.js +1 -0
  5. package/dist/bridges/types.js +1 -0
  6. package/dist/build-info.json +3 -3
  7. package/dist/cli.js +66 -122
  8. package/dist/commands/agent.js +27 -65
  9. package/dist/commands/backup-approval.js +218 -0
  10. package/dist/commands/backup.js +37 -33
  11. package/dist/commands/bootstrap.js +3 -1
  12. package/dist/commands/deploy.js +37 -7
  13. package/dist/commands/doctor.js +119 -0
  14. package/dist/commands/export.js +3 -4
  15. package/dist/commands/federation.js +653 -68
  16. package/dist/commands/grant.js +5 -6
  17. package/dist/commands/help.js +25 -0
  18. package/dist/commands/idp.js +14 -19
  19. package/dist/commands/import.js +131 -19
  20. package/dist/commands/init.js +7 -7
  21. package/dist/commands/integrity.js +5 -6
  22. package/dist/commands/mcp.js +11 -17
  23. package/dist/commands/memory.js +33 -15
  24. package/dist/commands/orgevent.js +5 -10
  25. package/dist/commands/principal.js +13 -25
  26. package/dist/commands/quality.js +3 -0
  27. package/dist/commands/rem.js +484 -65
  28. package/dist/commands/restore.js +352 -44
  29. package/dist/commands/service.js +84 -2
  30. package/dist/commands/soul.js +0 -6
  31. package/dist/commands/status.js +51 -33
  32. package/dist/commands/test.js +4 -1
  33. package/dist/commands/upgrade.js +53 -22
  34. package/dist/commands/workspace.js +7 -8
  35. package/dist/deploy.js +59 -3
  36. package/dist/doctor-client.js +7 -2
  37. package/dist/fabric-upgrade.js +12 -2
  38. package/dist/federation/presence-send.js +139 -0
  39. package/dist/federation-verify.js +269 -177
  40. package/dist/install/clients.js +171 -35
  41. package/dist/lib/agent-id-rule.js +44 -2
  42. package/dist/lib/atomic-write.js +1 -1
  43. package/dist/lib/auth-resolve.js +1028 -52
  44. package/dist/lib/backup-approval-store.js +612 -0
  45. package/dist/lib/backup-artifact.js +343 -0
  46. package/dist/lib/config-critical-section.js +212 -25
  47. package/dist/lib/connect-phase.js +33 -0
  48. package/dist/lib/daemon-liveness.js +2 -1
  49. package/dist/lib/federation-pair-access.js +4 -0
  50. package/dist/lib/federation-retry-queue.js +283 -0
  51. package/dist/lib/federation-retry-row.js +101 -0
  52. package/dist/lib/instruction-event-contract.js +17 -0
  53. package/dist/lib/instruction-event-doctor.js +102 -0
  54. package/dist/lib/launchd-management.js +14 -3
  55. package/dist/lib/mcp-enable.js +14 -15
  56. package/dist/lib/memory-attributes.js +2 -0
  57. package/dist/lib/memory-provider-timeout.js +33 -0
  58. package/dist/lib/mqtt-config.js +132 -0
  59. package/dist/lib/mqtt-listener-doctor.js +104 -0
  60. package/dist/lib/open-live-row.js +20 -0
  61. package/dist/lib/ops-url.js +52 -0
  62. package/dist/lib/promotion-content-hash.js +20 -0
  63. package/dist/lib/restore-archive.js +760 -0
  64. package/dist/lib/restore-verify.js +1 -1
  65. package/dist/lib/skill-assignment-preflight.js +159 -0
  66. package/dist/lib/skill-seed.js +91 -8
  67. package/dist/lib/skill-tombstone-doctor.js +133 -0
  68. package/dist/lib/soul-scope-fields.js +26 -0
  69. package/dist/lib/uninstall-purge.js +266 -11
  70. package/dist/lib/upgrade-prior-liveness.js +2 -1
  71. package/dist/mcp-client-assertion.js +2 -10
  72. package/dist/memory-id-checkpoint.js +28 -7
  73. package/dist/mqtt-off-deploy.js +550 -0
  74. package/dist/rem/promote-policy.js +3 -3
  75. package/dist/rem/restore.js +302 -26
  76. package/dist/rem/runner.js +220 -58
  77. package/dist/rem/scheduler.js +21 -4
  78. package/dist/resources/A2AAdapter.js +131 -178
  79. package/dist/resources/AdminMemory.js +2 -0
  80. package/dist/resources/AdminMemoryCandidates.js +116 -0
  81. package/dist/resources/Agent.js +155 -45
  82. package/dist/resources/AgentCard.js +4 -0
  83. package/dist/resources/AgentKeyRegister.js +56 -22
  84. package/dist/resources/AgentReadPosition.js +7 -0
  85. package/dist/resources/AgentSeed.js +232 -107
  86. package/dist/resources/AutoPromoteCandidates.js +413 -84
  87. package/dist/resources/Credential.js +6 -8
  88. package/dist/resources/Federation.js +219 -57
  89. package/dist/resources/FederationRetry.js +4 -4
  90. package/dist/resources/InstructionVersion.js +1 -1
  91. package/dist/resources/MCPClientMetadata.js +6 -3
  92. package/dist/resources/Memory.js +1303 -270
  93. package/dist/resources/MemoryArchive.js +149 -64
  94. package/dist/resources/MemoryBootstrap.js +12 -22
  95. package/dist/resources/MemoryCandidate.js +16 -2
  96. package/dist/resources/MemoryConsolidate.js +2 -2
  97. package/dist/resources/MemoryFeed.js +360 -147
  98. package/dist/resources/MemoryMaintenance.js +290 -72
  99. package/dist/resources/MemoryPurge.js +138 -22
  100. package/dist/resources/MemoryReflect.js +68 -14
  101. package/dist/resources/MemoryReindex.js +91 -13
  102. package/dist/resources/Message.js +11 -2
  103. package/dist/resources/OAuth.js +156 -39
  104. package/dist/resources/OAuthClient.js +1 -1
  105. package/dist/resources/OrgEvent.js +292 -29
  106. package/dist/resources/OrgEventCatchup.js +7 -0
  107. package/dist/resources/OrgEventMaintenance.js +48 -10
  108. package/dist/resources/PairingToken.js +1 -1
  109. package/dist/resources/Presence.js +31 -11
  110. package/dist/resources/PromoteMemoryCandidate.js +8 -2
  111. package/dist/resources/RecordUsage.js +2 -4
  112. package/dist/resources/Soul.js +2 -0
  113. package/dist/resources/SoulFeed.js +2 -1
  114. package/dist/resources/WorkspaceLatest.js +4 -0
  115. package/dist/resources/XAA.js +36 -10
  116. package/dist/resources/a2a-stream.js +313 -0
  117. package/dist/resources/a2a-url.js +4 -5
  118. package/dist/resources/agent-admin.js +10 -1
  119. package/dist/resources/agent-auth.js +98 -68
  120. package/dist/resources/agent-read-position-lib.js +4 -1
  121. package/dist/resources/agent-status-guard.js +9 -7
  122. package/dist/resources/auth-middleware.js +166 -42
  123. package/dist/resources/authority-field-guard.js +9 -11
  124. package/dist/resources/auto-promote-lib.js +8 -5
  125. package/dist/resources/basic-auth-header.js +21 -0
  126. package/dist/resources/bm25-index-service.js +4 -5
  127. package/dist/resources/dedup-cluster.js +6 -1
  128. package/dist/resources/embeddings-provider.js +25 -0
  129. package/dist/resources/federation-classify.js +89 -0
  130. package/dist/resources/federation-retry-lib.js +6 -81
  131. package/dist/resources/health.js +43 -4
  132. package/dist/resources/host-pointer/registry.js +29 -0
  133. package/dist/resources/host-pointer-adapter.js +1 -0
  134. package/dist/resources/in-process.js +24 -22
  135. package/dist/resources/instruction-version-record.js +251 -7
  136. package/dist/resources/internal-authority.js +13 -0
  137. package/dist/resources/mcp-handler.js +106 -12
  138. package/dist/resources/mcp-oauth-flag.js +12 -14
  139. package/dist/resources/mcp-oauth.js +430 -53
  140. package/dist/resources/mcp-tools.js +60 -22
  141. package/dist/resources/memory-declared-attributes.js +1 -0
  142. package/dist/resources/memory-embed-hash.js +56 -0
  143. package/dist/resources/memory-host-source.js +5 -2
  144. package/dist/resources/memory-reflect-lib.js +1 -1
  145. package/dist/resources/memory-write-lock.js +202 -23
  146. package/dist/resources/memory-write-response.js +1 -1
  147. package/dist/resources/memory-write-transaction.js +243 -0
  148. package/dist/resources/migration-boot.js +17 -12
  149. package/dist/resources/migrations/boot-progress.js +25 -0
  150. package/dist/resources/migrations/data-dir.js +16 -3
  151. package/dist/resources/migrations/dir-safety.js +60 -2
  152. package/dist/resources/migrations/embedding-stamp.js +315 -49
  153. package/dist/resources/migrations/graph-heal.js +9 -2
  154. package/dist/resources/migrations/ledger.js +5 -2
  155. package/dist/resources/migrations/lock.js +867 -80
  156. package/dist/resources/migrations/progress.js +71 -10
  157. package/dist/resources/migrations/runner.js +212 -18
  158. package/dist/resources/migrations/state.js +36 -1
  159. package/dist/resources/migrations/status.js +2 -13
  160. package/dist/resources/migrations/synthetic-test-migration.js +78 -12
  161. package/dist/resources/migrations/types.js +26 -1
  162. package/dist/resources/migrations/visibility-backfill.js +111 -70
  163. package/dist/resources/oauth-discovery.js +0 -5
  164. package/dist/resources/object-body-guard.js +12 -5
  165. package/dist/resources/org-event-reserved.js +92 -0
  166. package/dist/resources/org-event-write-fault.js +19 -0
  167. package/dist/resources/owner-field-guard.js +1 -1
  168. package/dist/resources/owner-scoped-write-policy.js +65 -21
  169. package/dist/resources/owner-scoped-writes.js +37 -6
  170. package/dist/resources/path-id-rewrite.js +76 -0
  171. package/dist/resources/presence-internal.js +5 -5
  172. package/dist/resources/promotion-binding.js +43 -0
  173. package/dist/resources/promotion-stamp.js +124 -33
  174. package/dist/resources/protocol-context.js +189 -0
  175. package/dist/resources/record-type-kit.js +2 -4
  176. package/dist/resources/request-target.js +28 -1
  177. package/dist/resources/request-transaction.js +11 -1
  178. package/dist/resources/seed-reservation.js +1 -2
  179. package/dist/resources/semantic-retrieval-core.js +7 -6
  180. package/dist/resources/server-row-validation.js +71 -0
  181. package/dist/resources/skill-manifest.js +4 -3
  182. package/dist/resources/skill-version-write.js +384 -27
  183. package/dist/resources/skill-write-fault.js +6 -3
  184. package/dist/resources/skill-write-policy.js +2 -1
  185. package/dist/resources/soul-write-policy.js +26 -7
  186. package/dist/resources/table-helpers.js +1 -1
  187. package/dist/resources/table-subscription-policy.js +518 -85
  188. package/dist/resources/table-subscriptions.js +20 -7
  189. package/dist/resources/txn-pause-point.js +122 -5
  190. package/dist/resources/usage-recording.js +54 -46
  191. package/dist/resources/write-back.js +176 -11
  192. package/dist/resources/write-journal-context.js +5 -0
  193. package/dist/resources/write-journal.js +289 -0
  194. package/dist/src/lib/agent-id-rule.js +44 -2
  195. package/dist/src/lib/atomic-write.js +1 -1
  196. package/dist/src/lib/federation-retry-row.js +101 -0
  197. package/dist/src/lib/instruction-event-contract.js +17 -0
  198. package/dist/src/lib/memory-attributes.js +2 -0
  199. package/dist/src/lib/open-live-row.js +20 -0
  200. package/dist/src/lib/soul-scope-fields.js +26 -0
  201. package/dist/src/rem/promote-policy.js +3 -3
  202. package/dist/src/rem/scheduler.js +21 -4
  203. package/docs/access-control.md +18 -9
  204. package/docs/api-reference.md +126 -28
  205. package/docs/auth.md +40 -18
  206. package/docs/claude-code.md +3 -3
  207. package/docs/deploying-on-fabric.md +108 -0
  208. package/docs/deployment.md +17 -0
  209. package/docs/embedding-in-a-harper-app.md +16 -14
  210. package/docs/entity-vocabulary.md +3 -6
  211. package/docs/federation.md +29 -2
  212. package/docs/integrations.md +11 -11
  213. package/docs/mcp-clients.md +7 -5
  214. package/docs/notes/mcp-agent-auth-consumer.md +4 -9
  215. package/docs/notes/mcp-oauth-model2.md +6 -6
  216. package/docs/openclaw.md +1 -1
  217. package/docs/quickstart-fabric.md +2 -2
  218. package/docs/quickstart.md +3 -3
  219. package/docs/releasing.md +13 -13
  220. package/docs/rem.md +24 -3
  221. package/docs/secrets-and-keys.md +2 -2
  222. package/docs/standalone-local.md +29 -2
  223. package/docs/supply-chain-policy.md +28 -20
  224. package/docs/the-team.md +2 -2
  225. package/docs/upgrade.md +14 -0
  226. package/package.json +18 -11
  227. package/schemas/agent.graphql +3 -3
  228. package/schemas/federation.graphql +10 -7
  229. package/schemas/memory.graphql +7 -2
  230. package/templates/bin/flair-rem-nightly.sh.tmpl +7 -1
  231. package/templates/launchd/start-flair-with-admin-pass.sh +188 -10
  232. package/dist/resources/soul-adk-guard.js +0 -68
@@ -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
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * open-live-row.ts — the skill writer's "open live" Memory-row predicate
3
+ * (flair#2662), shared so `flair doctor` asks the same question the writer
4
+ * answers. It checks the row's fields and the current time (for `expiresAt`). Deliberately imports nothing (resources
5
+ * importing this compiled helper require it to be load-free).
6
+ *
7
+ * A row is open-live when it is not archived, is not expired (`expiresAt`
8
+ * absent, or a string later than now), and carries no `validTo`.
9
+ */
10
+ export function isOpenLiveRow(row) {
11
+ if (!row || typeof row !== "object")
12
+ return false;
13
+ if (row.archived === true)
14
+ return false;
15
+ if (row.expiresAt != null && (typeof row.expiresAt !== "string" || !(Date.parse(row.expiresAt) > Date.now())))
16
+ return false;
17
+ if (typeof row.validTo === "string" && row.validTo.length > 0)
18
+ return false;
19
+ return true;
20
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * ops-url.ts — derive a remote instance's operations API URL from its Flair
3
+ * base URL, the way every remote flair command does (resolveEffectiveOpsUrl in
4
+ * src/cli.ts, which also honours --ops-target / FLAIR_OPS_TARGET). Shared by
5
+ * src/cli.ts and the deploy channel (src/deploy.ts).
6
+ */
7
+ /** The default operations API port for a self-hosted instance on plain HTTP with no explicit port. */
8
+ export const DEFAULT_OPS_PORT = 19925;
9
+ /** The operations API port of a Harper Fabric cluster. */
10
+ export const FABRIC_OPS_PORT = 9925;
11
+ /** Derive the ops API URL from a Flair base URL.
12
+ * https with effective port 443 (no explicit port, or explicit :443): returns
13
+ * <host>:9925 (FABRIC_OPS_PORT) — the Fabric managed case where port-1/:442
14
+ * is a dead-end.
15
+ * All other cases unchanged:
16
+ * https with non-443 explicit port → port-1 (self-hosted TLS: 19926→19925, 8443→8442)
17
+ * http with explicit port → port-1 (19926→19925)
18
+ * http with no port → DEFAULT_OPS_PORT (19925)
19
+ * Bare hosts are normalised to https:// (effective-443 → Fabric path).
20
+ * Throws on unparseable URLs or out-of-range ports.
21
+ */
22
+ export function resolveOpsUrlFromTarget(targetUrl) {
23
+ // Normalise bare hosts: add https:// prefix so URL parser can handle them.
24
+ const normalised = targetUrl.includes("://") ? targetUrl : `https://${targetUrl}`;
25
+ const url = new URL(normalised);
26
+ // https target with effective port 443 (no explicit port, or explicit :443):
27
+ // this is the Fabric managed case — the ops API is on the well-known Fabric
28
+ // ops port, never REST-adjacent. The port-1 / :442 logic is a dead-end here.
29
+ if (url.protocol === "https:" && (url.port === "" || url.port === "443")) {
30
+ url.port = String(FABRIC_OPS_PORT);
31
+ return url.toString().replace(/\/$/, "");
32
+ }
33
+ // All other cases: unchanged port-1 convention.
34
+ // https with non-443 explicit port → port-1 (self-hosted TLS: 19926→19925, 8443→8442)
35
+ // http with explicit port → port-1 (19926→19925)
36
+ // http with no port → DEFAULT_OPS_PORT (19925)
37
+ const port = parseInt(url.port, 10);
38
+ if (!isNaN(port) && port > 0 && port <= 65535) {
39
+ const opsPort = port - 1;
40
+ if (opsPort < 1)
41
+ throw new Error(`Derived ops port ${opsPort} is out of range; target port must be > 1`);
42
+ url.port = String(opsPort);
43
+ return url.toString().replace(/\/$/, "");
44
+ }
45
+ // No valid explicit port — reject port 0 or out-of-range
46
+ if (url.port !== "" && url.port !== undefined) {
47
+ throw new Error(`Invalid target port: ${url.port} (must be 1-65535)`);
48
+ }
49
+ // No explicit port on http — use the default ops port.
50
+ url.port = String(DEFAULT_OPS_PORT);
51
+ return url.toString().replace(/\/$/, "");
52
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * promotion-content-hash.ts — the promotion content-binding hash (flair#2478)
3
+ * for `src/` callers: restore admission (src/lib/restore-archive.ts,
4
+ * flair#2664).
5
+ *
6
+ * The server computes the same binding in resources/promotion-binding.ts,
7
+ * which the read accessor and the trusted stamp use. The two are separate
8
+ * implementations of one algorithm, SHA-256 over the content as UTF-8, because
9
+ * neither side may import the other: `src/` must not import `resources/`
10
+ * (those imports do not survive npm packaging), and a resource may statically
11
+ * import only `src/` helpers that load no modules at all (flair#1775), while
12
+ * this one loads node:crypto. test/unit/restore-archive-2664.test.ts pins
13
+ * their parity and that no resource imports this module.
14
+ */
15
+ import { createHash } from "node:crypto";
16
+ /** SHA-256 of the supplied content as UTF-8 (non-string content is converted with String(); null and undefined hash as ""). */
17
+ export function promotionContentHash(content) {
18
+ const text = typeof content === "string" ? content : content == null ? "" : String(content);
19
+ return createHash("sha256").update(text, "utf8").digest("hex");
20
+ }