@tpsdev-ai/flair 0.56.0 → 0.58.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 (153) hide show
  1. package/README.md +19 -20
  2. package/SECURITY.md +4 -1
  3. package/dist/build-info.json +3 -3
  4. package/dist/cli.js +1800 -293
  5. package/dist/commands/agent.js +22 -15
  6. package/dist/commands/bridge.js +40 -3
  7. package/dist/commands/doctor.js +214 -4
  8. package/dist/commands/federation.js +265 -38
  9. package/dist/commands/hook.js +10 -2
  10. package/dist/commands/init.js +179 -48
  11. package/dist/commands/memory.js +24 -2
  12. package/dist/commands/quality.js +26 -18
  13. package/dist/commands/service.js +137 -22
  14. package/dist/commands/status.js +114 -3
  15. package/dist/commands/upgrade.js +204 -84
  16. package/dist/doctor-client.js +50 -4
  17. package/dist/federation/scheduler.js +253 -4
  18. package/dist/install/clients.js +89 -23
  19. package/dist/install/global-bin-path.js +26 -6
  20. package/dist/lib/atomic-write.js +256 -0
  21. package/dist/lib/auth-resolve.js +46 -0
  22. package/dist/lib/daemon-liveness.js +61 -0
  23. package/dist/lib/doctor-run.js +5 -0
  24. package/dist/lib/embed-gpu-doctor.js +49 -26
  25. package/dist/lib/federation-memory-attributes.js +15 -0
  26. package/dist/lib/init-admin-pass.js +4 -2
  27. package/dist/lib/init-listener-environ.js +38 -0
  28. package/dist/lib/init-occupied-listener.js +165 -0
  29. package/dist/lib/instance-identity-row.js +580 -0
  30. package/dist/lib/launchd-domain-preflight.js +448 -0
  31. package/dist/lib/launchd-management.js +176 -6
  32. package/dist/lib/launchd-repair.js +95 -0
  33. package/dist/lib/memory-attributes.js +77 -0
  34. package/dist/lib/node-alias-path.js +95 -0
  35. package/dist/lib/npm-registry.js +119 -6
  36. package/dist/lib/owned-pins.js +20 -6
  37. package/dist/lib/redact-token-id.js +197 -0
  38. package/dist/lib/service-repoint-apply.js +267 -0
  39. package/dist/lib/service-repoint.js +575 -0
  40. package/dist/lib/toml-string-array.js +104 -0
  41. package/dist/lib/tree-divergence.js +716 -0
  42. package/dist/lib/upgrade-plain-tree.js +18 -8
  43. package/dist/lib/upgrade-prior-liveness.js +69 -0
  44. package/dist/lib/upgrade-rollback.js +116 -0
  45. package/dist/rem/runner.js +11 -0
  46. package/dist/resources/Agent.js +27 -14
  47. package/dist/resources/AgentSeed.js +39 -2
  48. package/dist/resources/Asset.js +3 -11
  49. package/dist/resources/Credential.js +4 -10
  50. package/dist/resources/Federation.js +299 -127
  51. package/dist/resources/Integration.js +8 -32
  52. package/dist/resources/Memory.js +623 -86
  53. package/dist/resources/MemoryArchive.js +9 -0
  54. package/dist/resources/MemoryBootstrap.js +23 -12
  55. package/dist/resources/MemoryCandidate.js +3 -11
  56. package/dist/resources/MemoryDedupStats.js +1 -1
  57. package/dist/resources/MemoryFeed.js +214 -5
  58. package/dist/resources/MemoryGrant.js +19 -40
  59. package/dist/resources/MemoryHostSource.js +90 -0
  60. package/dist/resources/MemoryMaintenance.js +121 -32
  61. package/dist/resources/MemoryReflect.js +4 -1
  62. package/dist/resources/MemoryReindex.js +7 -4
  63. package/dist/resources/MemoryUsage.js +55 -18
  64. package/dist/resources/Presence.js +18 -10
  65. package/dist/resources/RecordUsage.js +30 -40
  66. package/dist/resources/Relationship.js +170 -89
  67. package/dist/resources/SemanticSearch.js +44 -19
  68. package/dist/resources/Soul.js +31 -19
  69. package/dist/resources/XAA.js +7 -3
  70. package/dist/resources/agent-auth.js +16 -10
  71. package/dist/resources/auth-middleware.js +164 -50
  72. package/dist/resources/auto-promote-lib.js +4 -4
  73. package/dist/resources/bm25-index-service.js +246 -32
  74. package/dist/resources/bm25-status.js +132 -0
  75. package/dist/resources/bm25.js +13 -14
  76. package/dist/resources/ed25519-auth.js +11 -54
  77. package/dist/resources/embed-gpu.js +262 -47
  78. package/dist/resources/embeddings-boot.js +52 -17
  79. package/dist/resources/federation-classify.js +12 -0
  80. package/dist/resources/federation-cleanup.js +289 -51
  81. package/dist/resources/federation-crypto.js +65 -19
  82. package/dist/resources/health.js +105 -22
  83. package/dist/resources/host-pointer/registry.js +35 -0
  84. package/dist/resources/host-pointer-adapter.js +15 -0
  85. package/dist/resources/host-source-visibility.js +167 -0
  86. package/dist/resources/host-source.js +151 -0
  87. package/dist/resources/in-process-api.js +2 -1
  88. package/dist/resources/instance-create-lock.js +363 -0
  89. package/dist/resources/instance-identity-rows.js +43 -0
  90. package/dist/resources/instance-identity.js +97 -12
  91. package/dist/resources/mcp-handler.js +155 -51
  92. package/dist/resources/mcp-tool-arguments.js +83 -0
  93. package/dist/resources/mcp-tools.js +28 -25
  94. package/dist/resources/memory-consolidate-lib.js +3 -1
  95. package/dist/resources/memory-declared-attributes.js +103 -0
  96. package/dist/resources/memory-feed-lib.js +5 -1
  97. package/dist/resources/memory-host-source.js +163 -0
  98. package/dist/resources/memory-visibility.js +10 -7
  99. package/dist/resources/migrations/synthetic-test-migration.js +4 -1
  100. package/dist/resources/migrations/visibility-backfill.js +4 -1
  101. package/dist/resources/originator-instance.js +235 -0
  102. package/dist/resources/promotion-stamp.js +2 -0
  103. package/dist/resources/provenance.js +111 -11
  104. package/dist/resources/rate-limit.js +6 -4
  105. package/dist/resources/record-owner-guard.js +19 -0
  106. package/dist/resources/record-type-kit.js +44 -23
  107. package/dist/resources/record-types.js +6 -6
  108. package/dist/resources/relay-ops.js +28 -3
  109. package/dist/resources/replay-store.js +289 -0
  110. package/dist/resources/request-transaction.js +78 -0
  111. package/dist/resources/search-readiness.js +26 -22
  112. package/dist/resources/semantic-retrieval-core.js +103 -4
  113. package/dist/resources/table-helpers.js +33 -0
  114. package/dist/resources/table-patch-policy.js +109 -0
  115. package/dist/resources/table-patches.js +17 -0
  116. package/dist/resources/table-post-policy.js +138 -0
  117. package/dist/resources/table-posts.js +22 -0
  118. package/dist/resources/table-subscription-policy.js +135 -0
  119. package/dist/resources/table-subscriptions.js +19 -0
  120. package/dist/resources/tool-descriptors/index.js +15 -15
  121. package/dist/resources/trust-block.js +10 -3
  122. package/dist/resources/usage-recording.js +169 -41
  123. package/dist/src/lib/instance-identity-row.js +580 -0
  124. package/dist/src/lib/memory-attributes.js +77 -0
  125. package/dist/src/lib/redact-token-id.js +197 -0
  126. package/docs/api-reference.md +80 -16
  127. package/docs/auth.md +5 -5
  128. package/docs/claude-code.md +137 -6
  129. package/docs/deploying-on-fabric.md +6 -3
  130. package/docs/deployment.md +1 -1
  131. package/docs/embedding-in-a-harper-app.md +3 -3
  132. package/docs/federation.md +17 -10
  133. package/docs/hosted-on-fabric.md +4 -3
  134. package/docs/integrations.md +28 -19
  135. package/docs/mcp-clients.md +26 -32
  136. package/docs/n8n.md +8 -8
  137. package/docs/notes/mcp-oauth-model2.md +27 -18
  138. package/docs/openclaw.md +29 -28
  139. package/docs/quickstart.md +5 -0
  140. package/docs/releasing.md +134 -2
  141. package/docs/spoke-bringup.md +14 -11
  142. package/docs/standalone-local.md +2 -2
  143. package/docs/supply-chain-policy.md +28 -10
  144. package/docs/system-requirements.md +1 -1
  145. package/docs/troubleshooting.md +11 -0
  146. package/docs/upgrade.md +189 -63
  147. package/package.json +9 -5
  148. package/schemas/agent.graphql +9 -6
  149. package/schemas/federation.graphql +2 -11
  150. package/schemas/memory.graphql +106 -17
  151. package/schemas/replay.graphql +18 -0
  152. package/templates/launchd/start-flair-with-admin-pass.sh +22 -0
  153. package/dist/resources/federation-nonce-store.js +0 -195
@@ -0,0 +1,165 @@
1
+ /**
2
+ * init-occupied-listener.ts — flair#1749
3
+ *
4
+ * `flair init` used to treat "something already answered /health" as "our
5
+ * Harper is up", skip its own start, and then explain an operations-API 401
6
+ * as a wrong `--admin-pass`. Two claims that message must not make:
7
+ *
8
+ * - A different data directory does not prove the admin passwords differ.
9
+ * - The process holding the HTTP port is not necessarily the one that
10
+ * rejected an operations-port request. Those ports are resolved separately
11
+ * and can have different owners.
12
+ *
13
+ * Init can name a different data directory only when that one read could
14
+ * read one. An unreadable ROOTPATH is not proof of a foreign instance.
15
+ * On macOS the directory is unavailable, so init does not refuse before
16
+ * auth from a parsed ROOTPATH.
17
+ *
18
+ * That pre-auth observation is a single read. It is not the operations-port
19
+ * 401 check. A 401 names a pid only when the read before the insert and the
20
+ * read after the 401 are the same sole PID. Several holders, or a holder
21
+ * that changed during the request, stay "a Harper instance this init did
22
+ * not start".
23
+ *
24
+ * These messages do not offer `flair stop`. `flair stop` cannot be promised
25
+ * to act on this listener. The remedy is `kill <pid>` when one process is
26
+ * named. Init never signals a process it did not start.
27
+ */
28
+ import { canonicalLexicalPath } from "./daemon-liveness.js";
29
+ /**
30
+ * One observation of who is listening. An unreadable ROOTPATH is omitted,
31
+ * so it cannot become a pre-auth refusal. Does not decide `flair stop`.
32
+ */
33
+ export function listenerFromLookup(port, lookup) {
34
+ const pids = lookup.pids(port) ?? [];
35
+ const dataDirs = [];
36
+ for (const pid of pids) {
37
+ const read = lookup.rootPath(pid);
38
+ if (read.environReadable && read.rootPath && !dataDirs.includes(read.rootPath))
39
+ dataDirs.push(read.rootPath);
40
+ }
41
+ return { port, pids, dataDirs };
42
+ }
43
+ /**
44
+ * The process a 401 can be tied to.
45
+ *
46
+ * One pid, the same sole PID on both sides of the insert: that holder. Zero
47
+ * pids, several pids, or a different pid after the 401: nobody. The
48
+ * fallback does not keep data directories from a set of processes the 401
49
+ * was not tied to. This is not the pre-auth observation, which is one read.
50
+ */
51
+ export function stableAnsweredHolder(before, after) {
52
+ const sameSingle = before.pids.length === 1 &&
53
+ after.pids.length === 1 &&
54
+ before.pids[0] === after.pids[0];
55
+ if (!sameSingle) {
56
+ return { port: after.port, pids: [], dataDirs: [] };
57
+ }
58
+ return {
59
+ port: after.port,
60
+ pids: [after.pids[0]],
61
+ dataDirs: after.dataDirs,
62
+ };
63
+ }
64
+ const UNATTRIBUTED = "a Harper instance this init did not start";
65
+ /**
66
+ * Name the listener for an operator. A pid is included only when exactly one
67
+ * was read — several holders are not a kill list. Pid and data directory
68
+ * when both were read; whichever was read, plus the fallback phrase, when
69
+ * only one was; the fallback phrase alone when neither was.
70
+ */
71
+ export function describeOccupiedListener(listener) {
72
+ const pid = listener.pids.length === 1 ? `pid ${listener.pids[0]}` : null;
73
+ const dir = listener.dataDirs.length > 0 ? `data dir ${listener.dataDirs.join(", ")}` : null;
74
+ if (pid && dir)
75
+ return `${pid}, ${dir}`;
76
+ if (pid || dir)
77
+ return `${pid ?? dir} (${UNATTRIBUTED})`;
78
+ return UNATTRIBUTED;
79
+ }
80
+ /** Sentence carried wherever a different directory might be misread as a password fact. */
81
+ export const DIFFERENT_DIR_DOES_NOT_PROVE_PASSWORD = "A different data directory does not prove the admin passwords differ.";
82
+ /** Sentence carried on an operations-port rejection. The HTTP holder is a different fact. */
83
+ export const HTTP_HOLDER_DID_NOT_NECESSARILY_REJECT = "The process holding the HTTP port is not necessarily the one that rejected the operations request.";
84
+ function foreignDataDirs(expectedDataDir, dataDirs) {
85
+ const expected = canonicalLexicalPath(expectedDataDir);
86
+ return dataDirs.filter((dir) => canonicalLexicalPath(dir) !== expected);
87
+ }
88
+ /**
89
+ * Printed from the single pre-auth read of the HTTP listener, when that
90
+ * read included a ROOTPATH other than this init's data directory. Init
91
+ * exits on it — before the authenticated health request and before the
92
+ * operations insert. This is not the before-and-after 401 attribution.
93
+ * A different directory is not proof the passwords differ. Returns null
94
+ * when the directory matches or could not be read: an unreadable lookup
95
+ * is not a foreign instance.
96
+ */
97
+ export function staleHarperBeforeAuthNotice(expectedDataDir, listener) {
98
+ const foreign = foreignDataDirs(expectedDataDir, listener.dataDirs);
99
+ if (foreign.length === 0)
100
+ return null;
101
+ const who = describeOccupiedListener({ pids: listener.pids, dataDirs: foreign });
102
+ const lines = [
103
+ `Harper on port ${listener.port} is ${who}, not this init's data dir ${expectedDataDir}.`,
104
+ ` ${DIFFERENT_DIR_DOES_NOT_PROVE_PASSWORD}`,
105
+ ` This init will not send its admin password to that process.`,
106
+ ` This init will not stop a process it did not start.`,
107
+ ];
108
+ appendRemedy(lines, listener);
109
+ return lines.join("\n");
110
+ }
111
+ /**
112
+ * Appended when init refuses before start because the port is already
113
+ * answering and this data directory has no persisted admin user. Names only
114
+ * what was read. Does not claim the passwords differ.
115
+ */
116
+ export function foreignOccupiedListenerDetail(listener, expectedDataDir) {
117
+ const lines = [
118
+ `The process listening on port ${listener.port} is ${describeOccupiedListener(listener)}.`,
119
+ `This init will not send its admin password to a process it did not start.`,
120
+ ];
121
+ if (expectedDataDir && foreignDataDirs(expectedDataDir, listener.dataDirs).length > 0) {
122
+ lines.push(DIFFERENT_DIR_DOES_NOT_PROVE_PASSWORD);
123
+ }
124
+ lines.push(`This init will not stop a process it did not start.`);
125
+ appendRemedy(lines, listener);
126
+ return lines.join("\n");
127
+ }
128
+ /**
129
+ * The operations-API 401 after init skipped its own start. Unlike the
130
+ * pre-auth notice, which is one read, `listener` here is the before-and-after
131
+ * attribution for the operations port: the same sole PID on both sides,
132
+ * or the unattributed fallback. Do not pass the HTTP port's pids through.
133
+ * The rejection is not proof the passwords differ, and it is not proof the
134
+ * HTTP listener caused it. The message does not offer `flair stop`.
135
+ */
136
+ export function occupiedListenerAuthFailure(input) {
137
+ const who = describeOccupiedListener(input.listener);
138
+ const lines = [
139
+ `${input.lead}${input.bodyText}`,
140
+ ` The operations port ${input.listener.port} rejected this init's admin credentials.`,
141
+ ` ${HTTP_HOLDER_DID_NOT_NECESSARILY_REJECT}`,
142
+ ` ${DIFFERENT_DIR_DOES_NOT_PROVE_PASSWORD}`,
143
+ ` The process holding the operations port is ${who}.`,
144
+ ` This init will not stop a process it did not start.`,
145
+ ];
146
+ appendRemedy(lines, input.listener);
147
+ return lines.join("\n");
148
+ }
149
+ /**
150
+ * `kill` only for the one pid this message named. `flair stop` cannot be
151
+ * promised to act on this listener.
152
+ */
153
+ function appendRemedy(lines, listener) {
154
+ if (listener.pids.length === 1)
155
+ lines.push(` kill ${listener.pids[0]}`);
156
+ for (const dir of listener.dataDirs) {
157
+ lines.push(` flair init --data-dir ${commandArg(dir)}`);
158
+ }
159
+ }
160
+ /** Quote a path that would split on the shell. Numbers and plain paths stay bare. */
161
+ function commandArg(value) {
162
+ if (/^[A-Za-z0-9_./:@+-]+$/.test(value))
163
+ return value;
164
+ return `'${value.replace(/'/g, `'\\''`)}'`;
165
+ }