@tpsdev-ai/flair 0.57.0 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/SECURITY.md +4 -1
- package/config.yaml +3 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1726 -376
- package/dist/commands/agent.js +160 -2
- package/dist/commands/doctor.js +177 -27
- package/dist/commands/federation.js +2 -1
- package/dist/commands/hook.js +10 -2
- package/dist/commands/init.js +150 -44
- package/dist/commands/mcp.js +53 -22
- package/dist/commands/memory.js +24 -2
- package/dist/commands/quality.js +26 -18
- package/dist/commands/service.js +137 -22
- package/dist/commands/status.js +114 -3
- package/dist/commands/upgrade.js +204 -84
- package/dist/doctor-client.js +50 -4
- package/dist/federation/scheduler.js +253 -4
- package/dist/install/clients.js +89 -23
- package/dist/install/global-bin-path.js +26 -6
- package/dist/lib/atomic-write.js +256 -0
- package/dist/lib/daemon-liveness.js +103 -0
- package/dist/lib/doctor-run.js +72 -0
- package/dist/lib/embed-gpu-doctor.js +49 -26
- package/dist/lib/federation-memory-attributes.js +15 -0
- package/dist/lib/flair-agent-role.js +116 -0
- package/dist/lib/init-admin-pass.js +4 -2
- package/dist/lib/init-listener-environ.js +38 -0
- package/dist/lib/init-occupied-listener.js +165 -0
- package/dist/lib/launchd-domain-preflight.js +448 -0
- package/dist/lib/launchd-management.js +179 -8
- package/dist/lib/launchd-repair.js +95 -0
- package/dist/lib/mcp-enable.js +667 -72
- package/dist/lib/memory-attributes.js +77 -0
- package/dist/lib/node-alias-path.js +95 -0
- package/dist/lib/npm-registry.js +119 -6
- package/dist/lib/owned-pins.js +20 -6
- package/dist/lib/process-start-time.js +32 -0
- package/dist/lib/service-repoint-apply.js +267 -0
- package/dist/lib/service-repoint.js +575 -0
- package/dist/lib/toml-string-array.js +104 -0
- package/dist/lib/tree-divergence.js +716 -0
- package/dist/lib/upgrade-plain-tree.js +18 -8
- package/dist/lib/upgrade-prior-liveness.js +69 -0
- package/dist/lib/upgrade-rollback.js +116 -0
- package/dist/rem/runner.js +11 -0
- package/dist/resources/Agent.js +54 -21
- package/dist/resources/AgentSeed.js +44 -1
- package/dist/resources/Federation.js +84 -54
- package/dist/resources/Memory.js +567 -72
- package/dist/resources/MemoryArchive.js +9 -0
- package/dist/resources/MemoryBootstrap.js +125 -29
- package/dist/resources/MemoryFeed.js +204 -3
- package/dist/resources/MemoryHostSource.js +90 -0
- package/dist/resources/MemoryMaintenance.js +121 -32
- package/dist/resources/MemoryReflect.js +4 -1
- package/dist/resources/MemoryReindex.js +7 -4
- package/dist/resources/MemoryUsage.js +53 -3
- package/dist/resources/OrgSkillAssignment.js +209 -0
- package/dist/resources/Presence.js +18 -10
- package/dist/resources/RecordUsage.js +30 -40
- package/dist/resources/Relationship.js +167 -78
- package/dist/resources/SemanticSearch.js +19 -6
- package/dist/resources/Soul.js +31 -19
- package/dist/resources/XAA.js +47 -14
- package/dist/resources/agent-auth.js +16 -10
- package/dist/resources/agent-status-guard.js +63 -0
- package/dist/resources/auth-middleware.js +137 -49
- package/dist/resources/auto-promote-lib.js +4 -4
- package/dist/resources/bm25-index-service.js +246 -32
- package/dist/resources/bm25-status.js +132 -0
- package/dist/resources/ed25519-auth.js +11 -54
- package/dist/resources/embed-gpu.js +262 -47
- package/dist/resources/embeddings-boot.js +52 -17
- package/dist/resources/federation-classify.js +34 -0
- package/dist/resources/federation-crypto.js +65 -19
- package/dist/resources/flair-agent-role-boot.js +26 -0
- package/dist/resources/health.js +67 -16
- package/dist/resources/host-pointer/registry.js +35 -0
- package/dist/resources/host-pointer-adapter.js +15 -0
- package/dist/resources/host-source-visibility.js +167 -0
- package/dist/resources/host-source.js +151 -0
- package/dist/resources/instance-identity.js +3 -2
- package/dist/resources/key-lock.js +31 -0
- package/dist/resources/mcp-handler.js +147 -51
- package/dist/resources/mcp-oauth.js +3 -6
- package/dist/resources/mcp-tools.js +47 -25
- package/dist/resources/memory-consolidate-lib.js +3 -1
- package/dist/resources/memory-declared-attributes.js +103 -0
- package/dist/resources/memory-feed-lib.js +5 -1
- package/dist/resources/memory-host-source.js +163 -0
- package/dist/resources/migrations/synthetic-test-migration.js +4 -1
- package/dist/resources/migrations/visibility-backfill.js +4 -1
- package/dist/resources/multi-worker-guard.js +121 -0
- package/dist/resources/oauth-discovery.js +1 -0
- package/dist/resources/oauth-wellknown.js +8 -4
- package/dist/resources/originator-instance.js +235 -0
- package/dist/resources/promotion-stamp.js +2 -0
- package/dist/resources/provenance.js +111 -11
- package/dist/resources/record-owner-guard.js +19 -0
- package/dist/resources/record-type-kit.js +9 -12
- package/dist/resources/record-types.js +22 -6
- package/dist/resources/relay-ops.js +28 -3
- package/dist/resources/replay-store.js +336 -0
- package/dist/resources/request-transaction.js +78 -0
- package/dist/resources/search-readiness.js +19 -21
- package/dist/resources/semantic-retrieval-core.js +5 -1
- package/dist/resources/skill-manifest.js +181 -0
- package/dist/resources/skill-provenance.js +15 -10
- package/dist/resources/table-patch-policy.js +109 -0
- package/dist/resources/table-patches.js +17 -0
- package/dist/resources/table-post-policy.js +138 -0
- package/dist/resources/table-posts.js +22 -0
- package/dist/resources/table-subscription-policy.js +135 -0
- package/dist/resources/table-subscriptions.js +19 -0
- package/dist/resources/tool-descriptors/index.js +15 -15
- package/dist/resources/trust-block.js +10 -3
- package/dist/resources/usage-recording.js +169 -41
- package/dist/src/lib/flair-agent-role.js +116 -0
- package/dist/src/lib/memory-attributes.js +77 -0
- package/docs/access-control.md +667 -0
- package/docs/api-reference.md +85 -17
- package/docs/auth.md +4 -0
- package/docs/claude-code.md +132 -0
- package/docs/deepseek-harness.md +1 -1
- package/docs/deployment.md +1 -1
- package/docs/federation.md +1 -1
- package/docs/integrations.md +6 -6
- package/docs/mcp-clients.md +16 -24
- package/docs/notes/mcp-oauth-model2.md +15 -1
- package/docs/quickstart.md +5 -0
- package/docs/releasing.md +152 -20
- package/docs/supply-chain-policy.md +10 -5
- package/docs/troubleshooting.md +11 -0
- package/docs/upgrade.md +187 -61
- package/package.json +10 -5
- package/schemas/agent.graphql +9 -6
- package/schemas/federation.graphql +2 -11
- package/schemas/memory.graphql +137 -17
- package/schemas/oauth.graphql +8 -4
- package/schemas/replay.graphql +18 -0
- package/templates/launchd/start-flair-with-admin-pass.sh +95 -0
- package/dist/resources/federation-nonce-store.js +0 -195
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* flair-agent-role.ts — the `flair_agent` Harper role's grant spec, shared by
|
|
3
|
+
* the CLI (`ensureFlairAgentRole`, src/cli.ts) and the server's startup check
|
|
4
|
+
* (resources/flair-agent-role-boot.ts). No Harper imports.
|
|
5
|
+
*/
|
|
6
|
+
// ─── flair_agent role ────────────────────────────────────────────────────────
|
|
7
|
+
//
|
|
8
|
+
// The auth reshape replaces the global gate's "verified agent borrows admin
|
|
9
|
+
// super_user" elevation with a real, least-privilege Harper role. After an
|
|
10
|
+
// agent's Ed25519 signature verifies, resources resolve the request to the
|
|
11
|
+
// shared `flair_agent`-roled user instead of admin. Critically: with no
|
|
12
|
+
// `super_user` and no operations grants, /sql and /graphql become NATIVELY 403
|
|
13
|
+
// for agents (the raw-query block the gate hand-rolled is now enforced by
|
|
14
|
+
// Harper itself).
|
|
15
|
+
// Harper 5.0.21 add_role requires an `attribute_permissions` array on EVERY table
|
|
16
|
+
// grant (empty = no attribute-level restriction, so the table-level CRUD applies);
|
|
17
|
+
// omitting it makes add_role reject the whole spec ("Missing 'attribute_permissions'
|
|
18
|
+
// array"). Validated live against a spawned Harper. This helper guarantees the
|
|
19
|
+
// array is never forgotten. Also: `cluster_user` is NOT a valid top-level key —
|
|
20
|
+
// Harper reads unrecognized top-level keys as database names ("database
|
|
21
|
+
// 'cluster_user' does not exist"); only super_user / structure_user are recognized.
|
|
22
|
+
const grant = (read, insert, update, del) => ({ read, insert, update, delete: del, attribute_permissions: [] });
|
|
23
|
+
/** Canonical permission spec for flair_agent (least-privilege; real @table names). */
|
|
24
|
+
export const FLAIR_AGENT_PERMISSION = {
|
|
25
|
+
super_user: false,
|
|
26
|
+
structure_user: false,
|
|
27
|
+
flair: {
|
|
28
|
+
tables: {
|
|
29
|
+
// Core agent-owned data — CRUD envelope.
|
|
30
|
+
Memory: grant(true, true, true, true),
|
|
31
|
+
MemoryCandidate: grant(true, true, true, true),
|
|
32
|
+
MemoryGrant: grant(true, true, true, true),
|
|
33
|
+
// Asset (images-in-Flair slice 1). Harper authorizes BEFORE Asset.post
|
|
34
|
+
// runs, so a de-elevated flair_agent needs the table grant or signed
|
|
35
|
+
// POST /Asset 403s as AccessViolation (Kern P0). CRUD envelope;
|
|
36
|
+
// owner-only + write-time size/MIME gates live in resources/Asset.ts.
|
|
37
|
+
Asset: grant(true, true, true, true),
|
|
38
|
+
Soul: grant(true, true, true, false),
|
|
39
|
+
OrgEvent: grant(true, true, true, true),
|
|
40
|
+
WorkspaceState: grant(true, true, true, true),
|
|
41
|
+
Relationship: grant(true, true, true, true),
|
|
42
|
+
// Flair Relay S1 (flair#1521). Harper authorizes BEFORE the resource
|
|
43
|
+
// methods run, so a de-elevated flair_agent needs the table grant OR it
|
|
44
|
+
// 403s on POST /Message before relaySend is reached (Kern P0-2). read =
|
|
45
|
+
// the party-scoped collection (Message.search); insert = send via post().
|
|
46
|
+
// update = FALSE (least privilege, Kern P0 blocker): the ack's write goes
|
|
47
|
+
// through the IN-PROCESS static accessor (relayConsume → deps.messages.put),
|
|
48
|
+
// which bypasses role gates entirely — the same raw-put seam Federation.ts
|
|
49
|
+
// relies on — so update:true is NOT needed for any legitimate path. Leaving
|
|
50
|
+
// it granted let PATCH /Message/<id> reach Table's update verb, whose
|
|
51
|
+
// authorize step consults update:true and PASSES for any de-elevated agent,
|
|
52
|
+
// bypassing Message.put()'s FORBIDDEN guard AND relayConsume's recipient-only
|
|
53
|
+
// check (Message has no patch() at the platform level → TableResource.patch
|
|
54
|
+
// runs update()+save() directly). delete = false: direct deletes are
|
|
55
|
+
// admin/internal only. Message.patch() also guards the verb in-resource.
|
|
56
|
+
Message: grant(true, true, false, false),
|
|
57
|
+
Integration: grant(true, true, true, true),
|
|
58
|
+
Credential: grant(true, true, true, true),
|
|
59
|
+
Presence: grant(true, true, true, false),
|
|
60
|
+
// MemoryUsage (flair#683): the usage-feedback dedup ledger. Read (own
|
|
61
|
+
// contributions, scoped in resources/MemoryUsage.ts) + insert (a fresh
|
|
62
|
+
// contribution row) only — NO update/delete. This is load-bearing, not
|
|
63
|
+
// just least-privilege tidiness: the dedup rule ("(agent, memory)
|
|
64
|
+
// contributes ≤ 1") is enforced by requiring a NEW ledger row before
|
|
65
|
+
// any usageCount bump; if an agent could delete its own row, it could
|
|
66
|
+
// re-trigger the /RecordUsage endpoint for the same memory indefinitely
|
|
67
|
+
// (create → count → delete → count again → repeat), defeating the cap
|
|
68
|
+
// entirely. See resources/MemoryUsage.ts's module doc.
|
|
69
|
+
MemoryUsage: grant(true, true, false, false),
|
|
70
|
+
// MemoryHitStat (flair#1528): internal search-hit ledger. No agent REST
|
|
71
|
+
// surface (@table without @export). Counts overlay onto Memory reads.
|
|
72
|
+
MemoryHitStat: grant(false, false, false, false),
|
|
73
|
+
// Agent: read for discovery, update own card; creation/removal is admin.
|
|
74
|
+
Agent: grant(true, false, true, false),
|
|
75
|
+
// Read-only reference data.
|
|
76
|
+
Instance: grant(true, false, false, false),
|
|
77
|
+
// flair#2141 S1: org-scope skill assignments. Agents read them; every
|
|
78
|
+
// write is operator/internal only (resources/OrgSkillAssignment.ts), so
|
|
79
|
+
// no write grant. The history table has no direct REST route.
|
|
80
|
+
OrgSkillAssignment: grant(true, false, false, false),
|
|
81
|
+
OrgSkillAssignmentHistory: grant(false, false, false, false),
|
|
82
|
+
// Federation / OAuth / IdP / internal — system + admin only; agents get none.
|
|
83
|
+
Peer: grant(false, false, false, false),
|
|
84
|
+
PairingToken: grant(false, false, false, false),
|
|
85
|
+
SyncLog: grant(false, false, false, false),
|
|
86
|
+
OAuthClient: grant(false, false, false, false),
|
|
87
|
+
OAuthToken: grant(false, false, false, false),
|
|
88
|
+
OAuthAuthCode: grant(false, false, false, false),
|
|
89
|
+
IdpConfig: grant(false, false, false, false),
|
|
90
|
+
IdJagReplay: grant(false, false, false, false),
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
export const FLAIR_AGENT_ROLE_NAME = "flair_agent";
|
|
95
|
+
/**
|
|
96
|
+
* Brings an existing `flair_agent` role to FLAIR_AGENT_PERMISSION (flair#2141
|
|
97
|
+
* S1): "updated" after an `alter_role`, "unchanged" when it already matches,
|
|
98
|
+
* "absent" when the instance has no such role (this never creates it). Throws
|
|
99
|
+
* when the role list cannot be read; nothing is written then.
|
|
100
|
+
*/
|
|
101
|
+
export async function alignFlairAgentRole(op) {
|
|
102
|
+
const roles = await op({ operation: "list_roles" });
|
|
103
|
+
if (!Array.isArray(roles))
|
|
104
|
+
throw new Error("list_roles did not return a list of roles");
|
|
105
|
+
const existing = roles.find((r) => r?.role === FLAIR_AGENT_ROLE_NAME || r?.name === FLAIR_AGENT_ROLE_NAME);
|
|
106
|
+
if (!existing)
|
|
107
|
+
return "absent";
|
|
108
|
+
const permission = existing.permission ?? existing.role?.permission;
|
|
109
|
+
if (JSON.stringify(permission) === JSON.stringify(FLAIR_AGENT_PERMISSION))
|
|
110
|
+
return "unchanged";
|
|
111
|
+
// Harper's alter_role addresses the role by its `id`.
|
|
112
|
+
if (typeof existing.id !== "string" || existing.id.length === 0)
|
|
113
|
+
throw new Error("the flair_agent role has no id");
|
|
114
|
+
await op({ operation: "alter_role", id: existing.id, role: FLAIR_AGENT_ROLE_NAME, permission: FLAIR_AGENT_PERMISSION });
|
|
115
|
+
return "updated";
|
|
116
|
+
}
|
|
@@ -96,8 +96,10 @@ export function detectPersistedAdminUser(dataDir) {
|
|
|
96
96
|
export function initAdminPassRefusalMessage(reason, opts = {}) {
|
|
97
97
|
if (reason === "foreign-instance") {
|
|
98
98
|
const port = opts.httpPort ?? 19926;
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
const head = `A Harper instance is already answering on port ${port} and this data directory has no persisted admin user.`;
|
|
100
|
+
if (opts.offerFlairStop === false)
|
|
101
|
+
return head;
|
|
102
|
+
return (`${head} Stop that process before initializing a new instance:\n ${INIT_STOP_FOREIGN_COMMAND}`);
|
|
101
103
|
}
|
|
102
104
|
if (reason === "reset-without-socket") {
|
|
103
105
|
return (`Cannot rotate the admin password: Harper is not running and --skip-start was set, so the operations socket is unreachable. ` +
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ROOTPATH of a process `flair init` did not start (flair#1749).
|
|
3
|
+
*
|
|
4
|
+
* Linux reads `/proc/<pid>/environ` (NUL-separated, so a space in the path
|
|
5
|
+
* stays part of the value). macOS `ps -E` output does not separate arguments
|
|
6
|
+
* from the environment, so it cannot establish ROOTPATH. On macOS, and on
|
|
7
|
+
* any failed read, the directory is unavailable. Init must not refuse
|
|
8
|
+
* before auth from a directory it cannot read, and must not invent one.
|
|
9
|
+
*
|
|
10
|
+
* Daemon sidecar recovery keeps its own reader. This module is init's.
|
|
11
|
+
*/
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
13
|
+
import { extractRootPath, parseNullSeparatedEnviron } from "./daemon-liveness.js";
|
|
14
|
+
const UNAVAILABLE = { rootPath: null, environReadable: false };
|
|
15
|
+
/**
|
|
16
|
+
* Platform gate. Anything other than Linux is unavailable and does not call
|
|
17
|
+
* `readLinuxProc` — macOS must not parse `ps -E` and then treat the result
|
|
18
|
+
* as a data directory.
|
|
19
|
+
*/
|
|
20
|
+
export function listenerRootPathOnPlatform(platform, readLinuxProc) {
|
|
21
|
+
if (platform !== "linux")
|
|
22
|
+
return UNAVAILABLE;
|
|
23
|
+
return readLinuxProc();
|
|
24
|
+
}
|
|
25
|
+
/** Init-only. Linux `/proc/<pid>/environ`. Unavailable on every other platform. */
|
|
26
|
+
export function readInitListenerRootPath(pid) {
|
|
27
|
+
return listenerRootPathOnPlatform(process.platform, () => {
|
|
28
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
29
|
+
return UNAVAILABLE;
|
|
30
|
+
try {
|
|
31
|
+
const raw = readFileSync(`/proc/${pid}/environ`, "utf-8");
|
|
32
|
+
return { rootPath: extractRootPath(parseNullSeparatedEnviron(raw)), environReadable: true };
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return UNAVAILABLE;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -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
|
+
}
|