@ipab/cli 0.1.0-rc.5 → 0.1.0-rc.7
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 +128 -22
- package/dist/app-authoring.d.ts +5 -0
- package/dist/app-authoring.d.ts.map +1 -1
- package/dist/app-authoring.js +4 -1
- package/dist/app-authoring.js.map +1 -1
- package/dist/app-templates.d.ts +0 -1
- package/dist/app-templates.d.ts.map +1 -1
- package/dist/app-templates.js +6 -45
- package/dist/app-templates.js.map +1 -1
- package/dist/builtins/skill.ipab.car +0 -0
- package/dist/builtins/template.bundle-viewer.car +0 -0
- package/dist/builtins/template.check.car +0 -0
- package/dist/builtins/template.node.car +0 -0
- package/dist/builtins/template.web-app.car +0 -0
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +1 -39
- package/dist/builtins.js.map +1 -1
- package/dist/cli.d.ts +4 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +934 -336
- package/dist/cli.js.map +1 -1
- package/dist/content-provider.d.ts +1 -1
- package/dist/content-provider.d.ts.map +1 -1
- package/dist/content-provider.js +4 -3
- package/dist/content-provider.js.map +1 -1
- package/dist/context.d.ts +16 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +20 -10
- package/dist/context.js.map +1 -1
- package/dist/doctor.d.ts +29 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +576 -0
- package/dist/doctor.js.map +1 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +9 -9
- package/dist/identity.js.map +1 -1
- package/dist/ipc.d.ts +2 -2
- package/dist/ipc.d.ts.map +1 -1
- package/dist/ipc.js +44 -12
- package/dist/ipc.js.map +1 -1
- package/dist/kubo-install.d.ts +18 -1
- package/dist/kubo-install.d.ts.map +1 -1
- package/dist/kubo-install.js +424 -61
- package/dist/kubo-install.js.map +1 -1
- package/dist/kubo-release.d.ts +19 -0
- package/dist/kubo-release.d.ts.map +1 -1
- package/dist/kubo-release.js +164 -0
- package/dist/kubo-release.js.map +1 -1
- package/dist/kubo.d.ts +1 -0
- package/dist/kubo.d.ts.map +1 -1
- package/dist/kubo.js +102 -96
- package/dist/kubo.js.map +1 -1
- package/dist/pins.d.ts +15 -17
- package/dist/pins.d.ts.map +1 -1
- package/dist/pins.js +144 -106
- package/dist/pins.js.map +1 -1
- package/dist/publish-source.d.ts +3 -0
- package/dist/publish-source.d.ts.map +1 -0
- package/dist/publish-source.js +85 -0
- package/dist/publish-source.js.map +1 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +6 -5
- package/dist/runtime.js.map +1 -1
- package/dist/skill-definition.d.ts +6 -0
- package/dist/skill-definition.d.ts.map +1 -0
- package/dist/skill-definition.js +38 -0
- package/dist/skill-definition.js.map +1 -0
- package/dist/skill-source.d.ts +5 -0
- package/dist/skill-source.d.ts.map +1 -0
- package/dist/skill-source.js +12 -0
- package/dist/skill-source.js.map +1 -0
- package/dist/skills.d.ts +84 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +736 -0
- package/dist/skills.js.map +1 -0
- package/dist/space.d.ts +15 -2
- package/dist/space.d.ts.map +1 -1
- package/dist/space.js +153 -3
- package/dist/space.js.map +1 -1
- package/dist/state-storage-windows.js +1 -1
- package/dist/state-storage.d.ts +3 -1
- package/dist/state-storage.d.ts.map +1 -1
- package/dist/state-storage.js +38 -7
- package/dist/state-storage.js.map +1 -1
- package/dist/state.d.ts +40 -6
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +208 -82
- package/dist/state.js.map +1 -1
- package/dist/swarm-envelope.d.ts +1 -0
- package/dist/swarm-envelope.d.ts.map +1 -1
- package/dist/swarm-envelope.js +12 -0
- package/dist/swarm-envelope.js.map +1 -1
- package/dist/swarm-files.d.ts +1 -1
- package/dist/swarm-files.d.ts.map +1 -1
- package/dist/swarm-files.js +2 -2
- package/dist/swarm-files.js.map +1 -1
- package/dist/swarm-meta.d.ts +17 -0
- package/dist/swarm-meta.d.ts.map +1 -0
- package/dist/swarm-meta.js +96 -0
- package/dist/swarm-meta.js.map +1 -0
- package/dist/swarm.d.ts +117 -8
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +1275 -131
- package/dist/swarm.js.map +1 -1
- package/dist/template-paths.d.ts +7 -0
- package/dist/template-paths.d.ts.map +1 -0
- package/dist/template-paths.js +23 -0
- package/dist/template-paths.js.map +1 -0
- package/dist/template-presentation.d.ts +20 -0
- package/dist/template-presentation.d.ts.map +1 -0
- package/dist/template-presentation.js +133 -0
- package/dist/template-presentation.js.map +1 -0
- package/dist/template-source.d.ts +2 -1
- package/dist/template-source.d.ts.map +1 -1
- package/dist/template-source.js +7 -1
- package/dist/template-source.js.map +1 -1
- package/dist/templates.d.ts +11 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +53 -0
- package/dist/templates.js.map +1 -0
- package/package.json +7 -6
- package/src/app-authoring.ts +18 -2
- package/src/app-templates.ts +8 -72
- package/src/builtins.ts +2 -48
- package/src/cli.ts +1154 -387
- package/src/content-provider.ts +4 -2
- package/src/context.ts +45 -10
- package/src/doctor.ts +902 -0
- package/src/identity.ts +10 -10
- package/src/ipc.ts +63 -10
- package/src/kubo-install.ts +562 -78
- package/src/kubo-release.ts +213 -0
- package/src/kubo.ts +134 -106
- package/src/pins.ts +188 -126
- package/src/publish-source.ts +103 -0
- package/src/runtime.ts +6 -5
- package/src/skill-definition.ts +53 -0
- package/src/skill-source.ts +15 -0
- package/src/skills.ts +1005 -0
- package/src/space.ts +214 -5
- package/src/state-storage-windows.ts +1 -1
- package/src/state-storage.ts +53 -7
- package/src/state.ts +357 -98
- package/src/swarm-envelope.ts +14 -0
- package/src/swarm-files.ts +2 -1
- package/src/swarm-meta.ts +109 -0
- package/src/swarm.ts +1877 -175
- package/src/template-paths.ts +43 -0
- package/src/template-presentation.ts +151 -0
- package/src/template-source.ts +9 -2
- package/src/templates.ts +77 -0
- package/dist/setup.d.ts +0 -8
- package/dist/setup.d.ts.map +0 -1
- package/dist/setup.js +0 -27
- package/dist/setup.js.map +0 -1
- package/src/setup.ts +0 -34
package/src/doctor.ts
ADDED
|
@@ -0,0 +1,902 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lstat,
|
|
3
|
+
mkdtemp,
|
|
4
|
+
readdir,
|
|
5
|
+
readFile,
|
|
6
|
+
rm,
|
|
7
|
+
writeFile,
|
|
8
|
+
} from "node:fs/promises";
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
import { homedir, tmpdir } from "node:os";
|
|
11
|
+
import { join, resolve } from "node:path";
|
|
12
|
+
import { DatabaseSync } from "node:sqlite";
|
|
13
|
+
import { requireAccountOnlyMany } from "@ipab/bundle/pointer/protected-files";
|
|
14
|
+
import { nodeError } from "./authoring.js";
|
|
15
|
+
import { accountIdentity, protectedPath, secureNew } from "./identity.js";
|
|
16
|
+
import {
|
|
17
|
+
effectiveConfig,
|
|
18
|
+
swarmUrl,
|
|
19
|
+
validateUserConfig,
|
|
20
|
+
type ConfigKey,
|
|
21
|
+
type ConfigValue,
|
|
22
|
+
} from "./config.js";
|
|
23
|
+
import { swarmAlias } from "./state.js";
|
|
24
|
+
import {
|
|
25
|
+
prepareStateStorage,
|
|
26
|
+
verifyStateLocation,
|
|
27
|
+
verifyStateStorage,
|
|
28
|
+
} from "./state-storage.js";
|
|
29
|
+
import {
|
|
30
|
+
inspectKubo,
|
|
31
|
+
inspectKuboCache,
|
|
32
|
+
kuboBinary,
|
|
33
|
+
verifyExistingKuboArchive,
|
|
34
|
+
recoverableInstallation,
|
|
35
|
+
runningManagedNodes,
|
|
36
|
+
type InstallOptions,
|
|
37
|
+
} from "./kubo-install.js";
|
|
38
|
+
import {
|
|
39
|
+
KUBO_RANGE,
|
|
40
|
+
compareKuboVersions,
|
|
41
|
+
latestKuboRelease,
|
|
42
|
+
sameVersionKuboArchive,
|
|
43
|
+
type KuboArchive,
|
|
44
|
+
type KuboRelease,
|
|
45
|
+
} from "./kubo-release.js";
|
|
46
|
+
import { HostError } from "./errors.js";
|
|
47
|
+
import { inspectLocalMembership } from "./swarm.js";
|
|
48
|
+
import { nodeRecord } from "./kubo.js";
|
|
49
|
+
import { readPrivate } from "./swarm-files.js";
|
|
50
|
+
import { KUBO_REPO_VERSION } from "./kubo-release.js";
|
|
51
|
+
|
|
52
|
+
export type CheckStatus =
|
|
53
|
+
"ok" | "missing" | "invalid" | "blocked" | "not-checked" | "update-available";
|
|
54
|
+
export interface DoctorCheck {
|
|
55
|
+
id: string;
|
|
56
|
+
capability: "base" | "swarm";
|
|
57
|
+
required: boolean;
|
|
58
|
+
status: CheckStatus;
|
|
59
|
+
message: string;
|
|
60
|
+
repairable: boolean;
|
|
61
|
+
guidance: string;
|
|
62
|
+
}
|
|
63
|
+
export interface DoctorReport {
|
|
64
|
+
ready: boolean;
|
|
65
|
+
checks: DoctorCheck[];
|
|
66
|
+
repairs: {
|
|
67
|
+
id: string;
|
|
68
|
+
action: string;
|
|
69
|
+
status: "completed" | "failed" | "skipped";
|
|
70
|
+
}[];
|
|
71
|
+
}
|
|
72
|
+
export interface DoctorOptions extends InstallOptions {
|
|
73
|
+
fix?: boolean;
|
|
74
|
+
yes?: boolean;
|
|
75
|
+
tty: boolean;
|
|
76
|
+
confirm(text: string, signal?: AbortSignal): Promise<boolean>;
|
|
77
|
+
}
|
|
78
|
+
async function authorize(
|
|
79
|
+
options: DoctorOptions,
|
|
80
|
+
actions: readonly string[],
|
|
81
|
+
): Promise<boolean> {
|
|
82
|
+
const text = `${actions.join("\n")}\nApply these safe repairs? Existing credentials/repos will not be replaced or migrated.`;
|
|
83
|
+
const signal = options.signal;
|
|
84
|
+
if (!signal) return options.confirm(text);
|
|
85
|
+
signal.throwIfAborted();
|
|
86
|
+
let abort: () => void = () => {};
|
|
87
|
+
const cancelled = new Promise<never>((_resolve, reject) => {
|
|
88
|
+
abort = () => {
|
|
89
|
+
reject(
|
|
90
|
+
signal.reason instanceof Error
|
|
91
|
+
? signal.reason
|
|
92
|
+
: new HostError("Doctor cancelled."),
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
96
|
+
});
|
|
97
|
+
try {
|
|
98
|
+
return await Promise.race([options.confirm(text, signal), cancelled]);
|
|
99
|
+
} finally {
|
|
100
|
+
signal.removeEventListener("abort", abort);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function present(path: string): Promise<boolean> {
|
|
104
|
+
try {
|
|
105
|
+
await lstat(path);
|
|
106
|
+
return true;
|
|
107
|
+
} catch (cause) {
|
|
108
|
+
if (nodeError(cause, "ENOENT")) return false;
|
|
109
|
+
throw cause;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function inspectRegistryResources(
|
|
113
|
+
stateDir: string,
|
|
114
|
+
account: string | undefined,
|
|
115
|
+
): Promise<void> {
|
|
116
|
+
const credentials = join(stateDir, "swarm-credentials");
|
|
117
|
+
const peers = new Map<string, string>();
|
|
118
|
+
if (await present(credentials)) {
|
|
119
|
+
await protectedPath(credentials, true);
|
|
120
|
+
await requireAccountOnlyMany([credentials]);
|
|
121
|
+
for (const name of await readdir(credentials)) {
|
|
122
|
+
const file = join(credentials, name);
|
|
123
|
+
await protectedPath(file);
|
|
124
|
+
await requireAccountOnlyMany([file]);
|
|
125
|
+
if (!/^[a-f0-9]{64}\.json$/.test(name)) continue;
|
|
126
|
+
const membership = await inspectLocalMembership(
|
|
127
|
+
await readPrivate(credentials, name),
|
|
128
|
+
account,
|
|
129
|
+
);
|
|
130
|
+
if (
|
|
131
|
+
`${createHash("sha256").update(membership.configUrl).digest("hex")}.json` !==
|
|
132
|
+
name
|
|
133
|
+
)
|
|
134
|
+
throw new Error("Membership filename mismatch.");
|
|
135
|
+
if (membership.peer) {
|
|
136
|
+
const previous = peers.get(membership.scope);
|
|
137
|
+
if (previous && previous !== membership.peer)
|
|
138
|
+
throw new Error("Conflicting node identity bindings.");
|
|
139
|
+
peers.set(membership.scope, membership.peer);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const nodes = join(stateDir, "swarm-nodes");
|
|
144
|
+
if (!(await present(nodes))) return;
|
|
145
|
+
await protectedPath(nodes, true);
|
|
146
|
+
await requireAccountOnlyMany([nodes]);
|
|
147
|
+
for (const scope of await readdir(nodes)) {
|
|
148
|
+
if (!/^[a-f0-9]{64}$/.test(scope))
|
|
149
|
+
throw new Error("Invalid managed node scope.");
|
|
150
|
+
const directory = join(nodes, scope),
|
|
151
|
+
repo = join(directory, "repo");
|
|
152
|
+
await protectedPath(directory, true);
|
|
153
|
+
await protectedPath(repo, true);
|
|
154
|
+
await requireAccountOnlyMany([
|
|
155
|
+
directory,
|
|
156
|
+
repo,
|
|
157
|
+
join(directory, "node.json"),
|
|
158
|
+
join(repo, "config"),
|
|
159
|
+
join(repo, "version"),
|
|
160
|
+
]);
|
|
161
|
+
const node = nodeRecord(await readPrivate(directory, "node.json"), scope);
|
|
162
|
+
const config = await readPrivate<{ Identity?: { PeerID?: unknown } }>(
|
|
163
|
+
repo,
|
|
164
|
+
"config",
|
|
165
|
+
);
|
|
166
|
+
if (
|
|
167
|
+
config?.Identity?.PeerID !== node.peerId ||
|
|
168
|
+
(peers.has(scope) && peers.get(scope) !== node.peerId) ||
|
|
169
|
+
(await readFile(join(repo, "version"), "utf8")).trim() !==
|
|
170
|
+
KUBO_REPO_VERSION
|
|
171
|
+
)
|
|
172
|
+
throw new Error("Managed node identity/repo mismatch.");
|
|
173
|
+
const key = join(repo, "swarm.key");
|
|
174
|
+
if (await present(key)) {
|
|
175
|
+
await requireAccountOnlyMany([key]);
|
|
176
|
+
if (
|
|
177
|
+
(await lstat(key)).size > 128 ||
|
|
178
|
+
!/^\/key\/swarm\/psk\/1\.0\.0\/\n\/base16\/\n[a-f0-9]{64}\n$/.test(
|
|
179
|
+
await readFile(key, "utf8"),
|
|
180
|
+
)
|
|
181
|
+
)
|
|
182
|
+
throw new Error("Invalid managed swarm key.");
|
|
183
|
+
} else if (node.epoch !== undefined)
|
|
184
|
+
throw new Error("Managed node key is missing.");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function check(
|
|
188
|
+
id: string,
|
|
189
|
+
status: CheckStatus,
|
|
190
|
+
message: string,
|
|
191
|
+
repairable = false,
|
|
192
|
+
guidance = "",
|
|
193
|
+
): DoctorCheck {
|
|
194
|
+
return {
|
|
195
|
+
id,
|
|
196
|
+
capability: id === "state" ? "base" : "swarm",
|
|
197
|
+
required: id === "state",
|
|
198
|
+
status,
|
|
199
|
+
message,
|
|
200
|
+
repairable,
|
|
201
|
+
guidance,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function ready(report: DoctorReport): boolean {
|
|
205
|
+
return (
|
|
206
|
+
!report.checks.some(
|
|
207
|
+
(item) =>
|
|
208
|
+
item.status === "invalid" ||
|
|
209
|
+
(item.status === "blocked" && item.id !== "kubo-update") ||
|
|
210
|
+
(item.required && item.status !== "ok"),
|
|
211
|
+
) && !report.repairs.some((item) => item.status === "failed")
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
async function stateSnapshot(file: string, signal?: AbortSignal) {
|
|
215
|
+
const read = async () => {
|
|
216
|
+
if (
|
|
217
|
+
(await present(`${file}-journal`)) &&
|
|
218
|
+
(await lstat(`${file}-journal`)).size > 0
|
|
219
|
+
)
|
|
220
|
+
throw new HostError(
|
|
221
|
+
"A rollback transaction appeared during snapshot capture; preserve its journal and retry.",
|
|
222
|
+
1,
|
|
223
|
+
"STATE_SNAPSHOT_BUSY",
|
|
224
|
+
);
|
|
225
|
+
for (const path of [file, `${file}-wal`]) {
|
|
226
|
+
if (!(await present(path))) continue;
|
|
227
|
+
if ((await lstat(path)).size > 256 * 1024 * 1024)
|
|
228
|
+
throw new HostError(
|
|
229
|
+
"State exceeds the 256 MiB per-file diagnostic snapshot budget.",
|
|
230
|
+
1,
|
|
231
|
+
"STATE_SNAPSHOT_BUSY",
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
const main = await readFile(file, { signal });
|
|
235
|
+
const wal = (await present(`${file}-wal`))
|
|
236
|
+
? await readFile(`${file}-wal`, { signal })
|
|
237
|
+
: undefined;
|
|
238
|
+
return { main, wal };
|
|
239
|
+
};
|
|
240
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
241
|
+
signal?.throwIfAborted();
|
|
242
|
+
let first: Awaited<ReturnType<typeof read>>,
|
|
243
|
+
second: Awaited<ReturnType<typeof read>>;
|
|
244
|
+
try {
|
|
245
|
+
first = await read();
|
|
246
|
+
second = await read();
|
|
247
|
+
} catch (cause) {
|
|
248
|
+
if (nodeError(cause, "ENOENT")) continue;
|
|
249
|
+
throw cause;
|
|
250
|
+
}
|
|
251
|
+
if (
|
|
252
|
+
!first.main.equals(second.main) ||
|
|
253
|
+
(first.wal === undefined
|
|
254
|
+
? second.wal !== undefined
|
|
255
|
+
: second.wal === undefined || !first.wal.equals(second.wal))
|
|
256
|
+
)
|
|
257
|
+
continue;
|
|
258
|
+
const directory = await mkdtemp(join(tmpdir(), "ipab-doctor-state-"));
|
|
259
|
+
let db: DatabaseSync | undefined;
|
|
260
|
+
try {
|
|
261
|
+
await secureNew(directory, true);
|
|
262
|
+
const copy = join(directory, "state.sqlite");
|
|
263
|
+
await writeFile(copy, first.main, { mode: 0o600 });
|
|
264
|
+
if (first.wal) await writeFile(`${copy}-wal`, first.wal, { mode: 0o600 });
|
|
265
|
+
// Only the disposable copy may create SHM or checkpoint committed WAL.
|
|
266
|
+
db = new DatabaseSync(copy);
|
|
267
|
+
if (db.prepare("PRAGMA quick_check").get()?.quick_check !== "ok")
|
|
268
|
+
throw new Error("Invalid database snapshot.");
|
|
269
|
+
const tables = db
|
|
270
|
+
.prepare("SELECT name FROM sqlite_master WHERE type='table'")
|
|
271
|
+
.all();
|
|
272
|
+
if (
|
|
273
|
+
!tables.some((row) => row.name === "config") ||
|
|
274
|
+
!tables.some((row) => row.name === "swarms")
|
|
275
|
+
)
|
|
276
|
+
throw new Error("Invalid state schema.");
|
|
277
|
+
return {
|
|
278
|
+
config: db.prepare("SELECT key,value FROM config").all(),
|
|
279
|
+
swarms: db.prepare("SELECT cid,alias FROM swarms").all(),
|
|
280
|
+
};
|
|
281
|
+
} finally {
|
|
282
|
+
try {
|
|
283
|
+
db?.close();
|
|
284
|
+
} finally {
|
|
285
|
+
await rm(directory, { recursive: true, force: true });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
throw new HostError(
|
|
290
|
+
"State changed during snapshot capture; retry when writes have settled.",
|
|
291
|
+
1,
|
|
292
|
+
"STATE_SNAPSHOT_BUSY",
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
async function inspect(
|
|
296
|
+
stateDir: string,
|
|
297
|
+
env: NodeJS.ProcessEnv,
|
|
298
|
+
options: InstallOptions,
|
|
299
|
+
verificationFact?: KuboArchive,
|
|
300
|
+
): Promise<{
|
|
301
|
+
report: DoctorReport;
|
|
302
|
+
release?: KuboRelease;
|
|
303
|
+
verification?: KuboArchive;
|
|
304
|
+
}> {
|
|
305
|
+
const checks: DoctorCheck[] = [];
|
|
306
|
+
const report: DoctorReport = { ready: false, checks, repairs: [] };
|
|
307
|
+
let registry: Awaited<ReturnType<typeof stateSnapshot>>["swarms"] | undefined;
|
|
308
|
+
let user: Partial<Record<ConfigKey, ConfigValue>> = {};
|
|
309
|
+
try {
|
|
310
|
+
verifyStateLocation(stateDir, env);
|
|
311
|
+
if (!(await present(stateDir))) {
|
|
312
|
+
checks.push(
|
|
313
|
+
check(
|
|
314
|
+
"state",
|
|
315
|
+
"missing",
|
|
316
|
+
"Local state directory is missing.",
|
|
317
|
+
true,
|
|
318
|
+
"Run ipab doctor --fix.",
|
|
319
|
+
),
|
|
320
|
+
);
|
|
321
|
+
} else {
|
|
322
|
+
verifyStateStorage(stateDir, env);
|
|
323
|
+
const file = join(stateDir, "state.sqlite");
|
|
324
|
+
// An active rollback transaction cannot be safely recovered from a copy.
|
|
325
|
+
if (
|
|
326
|
+
(await present(`${file}-journal`)) &&
|
|
327
|
+
(await lstat(`${file}-journal`)).size > 0
|
|
328
|
+
) {
|
|
329
|
+
checks.push(
|
|
330
|
+
check(
|
|
331
|
+
"state",
|
|
332
|
+
"blocked",
|
|
333
|
+
"State has a nonempty rollback journal; its transaction state cannot be safely verified.",
|
|
334
|
+
false,
|
|
335
|
+
"A journal alone does not prove another process is running. Preserve the sidecars and recover the database through normal SQLite operations before retrying.",
|
|
336
|
+
),
|
|
337
|
+
);
|
|
338
|
+
} else {
|
|
339
|
+
if ((await lstat(file)).size > 0) {
|
|
340
|
+
const snapshot = await stateSnapshot(file, options.signal);
|
|
341
|
+
registry = snapshot.swarms;
|
|
342
|
+
const raw = Object.fromEntries(
|
|
343
|
+
snapshot.config.map((row) => {
|
|
344
|
+
if (typeof row.key !== "string" || typeof row.value !== "string")
|
|
345
|
+
throw new Error("Invalid configuration.");
|
|
346
|
+
return [row.key, JSON.parse(row.value) as unknown];
|
|
347
|
+
}),
|
|
348
|
+
);
|
|
349
|
+
user = validateUserConfig(raw);
|
|
350
|
+
}
|
|
351
|
+
effectiveConfig(user, { json: false, stateDir }, env);
|
|
352
|
+
checks.push(
|
|
353
|
+
check("state", "ok", "Local state and configuration are valid."),
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
} catch (cause) {
|
|
358
|
+
options.signal?.throwIfAborted();
|
|
359
|
+
checks.push(
|
|
360
|
+
check(
|
|
361
|
+
"state",
|
|
362
|
+
cause instanceof HostError && cause.code === "STATE_SNAPSHOT_BUSY"
|
|
363
|
+
? "blocked"
|
|
364
|
+
: "invalid",
|
|
365
|
+
cause instanceof HostError && cause.code === "STATE_SNAPSHOT_BUSY"
|
|
366
|
+
? cause.message
|
|
367
|
+
: "Local state or configuration is invalid or unprotected.",
|
|
368
|
+
false,
|
|
369
|
+
"Back up and inspect the existing state/configuration; no permissions or data were changed.",
|
|
370
|
+
),
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
let release: KuboRelease | undefined;
|
|
374
|
+
if (!options.release)
|
|
375
|
+
options.diagnostic?.(
|
|
376
|
+
"Checking official compatible Kubo release metadata...",
|
|
377
|
+
);
|
|
378
|
+
try {
|
|
379
|
+
release = options.release ?? (await latestKuboRelease(options.signal));
|
|
380
|
+
} catch {
|
|
381
|
+
options.signal?.throwIfAborted();
|
|
382
|
+
options.diagnostic?.(
|
|
383
|
+
"Could not check Kubo updates; no claim about the latest compatible release.",
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
let installed: Awaited<ReturnType<typeof inspectKubo>>;
|
|
387
|
+
let verification: KuboArchive | undefined;
|
|
388
|
+
let cacheInvalid = false;
|
|
389
|
+
try {
|
|
390
|
+
installed = await inspectKubo(stateDir, release, options.signal);
|
|
391
|
+
if (installed?.provenance === false) {
|
|
392
|
+
try {
|
|
393
|
+
verification =
|
|
394
|
+
verificationFact?.version === installed.version
|
|
395
|
+
? verificationFact
|
|
396
|
+
: await sameVersionKuboArchive(
|
|
397
|
+
installed.version,
|
|
398
|
+
release,
|
|
399
|
+
options.signal,
|
|
400
|
+
);
|
|
401
|
+
} catch {
|
|
402
|
+
options.signal?.throwIfAborted();
|
|
403
|
+
options.diagnostic?.(
|
|
404
|
+
"Trusted same-version archive metadata is unavailable; no verification archive was downloaded.",
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
if (verification && (await inspectKuboCache(stateDir, verification)))
|
|
408
|
+
installed = await inspectKubo(
|
|
409
|
+
stateDir,
|
|
410
|
+
release,
|
|
411
|
+
options.signal,
|
|
412
|
+
verification,
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
checks.push(
|
|
416
|
+
installed
|
|
417
|
+
? installed.provenance === false
|
|
418
|
+
? check(
|
|
419
|
+
"kubo",
|
|
420
|
+
"not-checked",
|
|
421
|
+
`Managed Kubo ${installed.version} matches its protected receipt, but official archive provenance is unverified.`,
|
|
422
|
+
Boolean(verification),
|
|
423
|
+
verification
|
|
424
|
+
? `Run ipab doctor --fix to download/cache the official ${installed.version} archive for verification only, without reinstall or node stopping.`
|
|
425
|
+
: "Trusted same-version official metadata/digest is unavailable; verification and dependent repairs remain blocked. No archive was downloaded.",
|
|
426
|
+
)
|
|
427
|
+
: check(
|
|
428
|
+
"kubo",
|
|
429
|
+
"ok",
|
|
430
|
+
`Managed Kubo ${installed.version} is verified.`,
|
|
431
|
+
)
|
|
432
|
+
: check(
|
|
433
|
+
"kubo",
|
|
434
|
+
"missing",
|
|
435
|
+
"Managed Kubo is missing (optional Swarm component).",
|
|
436
|
+
true,
|
|
437
|
+
"Run ipab doctor --fix.",
|
|
438
|
+
),
|
|
439
|
+
);
|
|
440
|
+
} catch (cause) {
|
|
441
|
+
verification = undefined;
|
|
442
|
+
let recoverable = false;
|
|
443
|
+
try {
|
|
444
|
+
recoverable = await recoverableInstallation(stateDir);
|
|
445
|
+
} catch {
|
|
446
|
+
/* Unsafe or unrecognized journals remain manual-only. */
|
|
447
|
+
}
|
|
448
|
+
checks.push(
|
|
449
|
+
recoverable
|
|
450
|
+
? check(
|
|
451
|
+
"kubo",
|
|
452
|
+
"blocked",
|
|
453
|
+
"Managed Kubo has a verified recoverable installation journal.",
|
|
454
|
+
true,
|
|
455
|
+
"Run ipab doctor --fix to recover only the journaled installation.",
|
|
456
|
+
)
|
|
457
|
+
: cause instanceof HostError && cause.code === "KUBO_CACHE_INVALID"
|
|
458
|
+
? check(
|
|
459
|
+
"kubo",
|
|
460
|
+
"invalid",
|
|
461
|
+
cause.message,
|
|
462
|
+
false,
|
|
463
|
+
"Restore the vetted protected archive cache; it was not overwritten or redownloaded.",
|
|
464
|
+
)
|
|
465
|
+
: check(
|
|
466
|
+
"kubo",
|
|
467
|
+
"invalid",
|
|
468
|
+
"Existing managed Kubo is invalid, unprotected or interrupted.",
|
|
469
|
+
false,
|
|
470
|
+
"Inspect the protected installation and journal manually; damaged installations are never replaced.",
|
|
471
|
+
),
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
if (
|
|
475
|
+
release &&
|
|
476
|
+
(!installed ||
|
|
477
|
+
compareKuboVersions(release.version, installed.version) > 0) &&
|
|
478
|
+
checks[0]?.status === "ok"
|
|
479
|
+
) {
|
|
480
|
+
try {
|
|
481
|
+
await inspectKuboCache(stateDir, release);
|
|
482
|
+
} catch {
|
|
483
|
+
cacheInvalid = true;
|
|
484
|
+
if (
|
|
485
|
+
!installed &&
|
|
486
|
+
checks.find((item) => item.id === "kubo")?.status === "missing"
|
|
487
|
+
) {
|
|
488
|
+
const item = checks.find((item) => item.id === "kubo")!;
|
|
489
|
+
item.status = "blocked";
|
|
490
|
+
item.repairable = false;
|
|
491
|
+
item.message =
|
|
492
|
+
"Managed Kubo is unavailable and the target official archive cache is invalid or unprotected.";
|
|
493
|
+
item.guidance =
|
|
494
|
+
"Inspect the archive cache manually. It was not deleted, adopted or redownloaded.";
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
const home = resolve(env.HOME ?? env.USERPROFILE ?? homedir());
|
|
499
|
+
const parent = join(home, ".ipab"),
|
|
500
|
+
identity = join(parent, "identity");
|
|
501
|
+
let account: string | undefined;
|
|
502
|
+
try {
|
|
503
|
+
if (!(await present(identity))) {
|
|
504
|
+
if (await present(parent)) {
|
|
505
|
+
await protectedPath(parent, true);
|
|
506
|
+
await requireAccountOnlyMany([parent]);
|
|
507
|
+
}
|
|
508
|
+
if (!(await present(home))) throw new Error("HOME missing.");
|
|
509
|
+
await protectedPath(home, true);
|
|
510
|
+
checks.push(
|
|
511
|
+
check(
|
|
512
|
+
"identity",
|
|
513
|
+
"missing",
|
|
514
|
+
"HOME account identity is missing (optional Swarm component).",
|
|
515
|
+
true,
|
|
516
|
+
"Run ipab doctor --fix.",
|
|
517
|
+
),
|
|
518
|
+
);
|
|
519
|
+
} else {
|
|
520
|
+
account = (await accountIdentity(env, false, true)).publicKey;
|
|
521
|
+
checks.push(
|
|
522
|
+
check("identity", "ok", "HOME identity is consistent and protected."),
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
} catch {
|
|
526
|
+
checks.push(
|
|
527
|
+
check(
|
|
528
|
+
"identity",
|
|
529
|
+
"invalid",
|
|
530
|
+
"Existing HOME identity or its parent path is invalid or unprotected.",
|
|
531
|
+
false,
|
|
532
|
+
"Restore the existing protected key file; do not create a replacement.",
|
|
533
|
+
),
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
try {
|
|
537
|
+
if (checks[0]?.status === "ok")
|
|
538
|
+
await inspectRegistryResources(stateDir, account);
|
|
539
|
+
if (registry) {
|
|
540
|
+
const urls = new Set<string>(),
|
|
541
|
+
aliases = new Set<string>();
|
|
542
|
+
for (const row of registry) {
|
|
543
|
+
if (
|
|
544
|
+
typeof row.cid !== "string" ||
|
|
545
|
+
(row.alias !== null && typeof row.alias !== "string")
|
|
546
|
+
)
|
|
547
|
+
throw new Error("Invalid registry.");
|
|
548
|
+
const url = swarmUrl(row.cid);
|
|
549
|
+
if (url !== row.cid || urls.has(url))
|
|
550
|
+
throw new Error("Invalid registry.");
|
|
551
|
+
urls.add(url);
|
|
552
|
+
if (row.alias !== null) {
|
|
553
|
+
swarmAlias(row.alias);
|
|
554
|
+
if (aliases.has(row.alias)) throw new Error("Duplicate alias.");
|
|
555
|
+
aliases.add(row.alias);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if (
|
|
559
|
+
typeof user["swarm.default"] === "string" &&
|
|
560
|
+
!urls.has(user["swarm.default"])
|
|
561
|
+
)
|
|
562
|
+
throw new Error("Unregistered default.");
|
|
563
|
+
checks.push(
|
|
564
|
+
check(
|
|
565
|
+
"swarm-registry",
|
|
566
|
+
urls.size ? "ok" : "missing",
|
|
567
|
+
urls.size
|
|
568
|
+
? "Local Swarm registry is consistent."
|
|
569
|
+
: "No Swarms are registered (optional).",
|
|
570
|
+
false,
|
|
571
|
+
urls.size
|
|
572
|
+
? ""
|
|
573
|
+
: "Use ipab swarm create or ipab swarm request to prepare sharing.",
|
|
574
|
+
),
|
|
575
|
+
);
|
|
576
|
+
} else
|
|
577
|
+
checks.push(
|
|
578
|
+
check(
|
|
579
|
+
"swarm-registry",
|
|
580
|
+
checks[0]?.status === "missing" || checks[0]?.status === "ok"
|
|
581
|
+
? "missing"
|
|
582
|
+
: "not-checked",
|
|
583
|
+
"Local Swarm registry is absent or cannot be checked.",
|
|
584
|
+
false,
|
|
585
|
+
"Resolve local state issues first; no registry was created.",
|
|
586
|
+
),
|
|
587
|
+
);
|
|
588
|
+
} catch {
|
|
589
|
+
checks.push(
|
|
590
|
+
check(
|
|
591
|
+
"swarm-registry",
|
|
592
|
+
"invalid",
|
|
593
|
+
"Existing local Swarm registry is inconsistent.",
|
|
594
|
+
false,
|
|
595
|
+
"Inspect the saved URLs, aliases and default; no registrations were removed.",
|
|
596
|
+
),
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
if (!release)
|
|
600
|
+
checks.push(
|
|
601
|
+
check(
|
|
602
|
+
"kubo-update",
|
|
603
|
+
"not-checked",
|
|
604
|
+
`Compatible Kubo updates (${KUBO_RANGE}) were not checked.`,
|
|
605
|
+
false,
|
|
606
|
+
"Retry when official release metadata is available.",
|
|
607
|
+
),
|
|
608
|
+
);
|
|
609
|
+
else if (
|
|
610
|
+
installed &&
|
|
611
|
+
compareKuboVersions(release.version, installed.version) > 0
|
|
612
|
+
) {
|
|
613
|
+
try {
|
|
614
|
+
if (installed.provenance === false && !verification)
|
|
615
|
+
checks.push(
|
|
616
|
+
check(
|
|
617
|
+
"kubo-update",
|
|
618
|
+
"blocked",
|
|
619
|
+
"A compatible Kubo update exists, but the existing installation's official provenance is unverified.",
|
|
620
|
+
false,
|
|
621
|
+
"Restore a vetted official archive cache before authorizing an upgrade; the existing installation was retained.",
|
|
622
|
+
),
|
|
623
|
+
);
|
|
624
|
+
else if (cacheInvalid)
|
|
625
|
+
checks.push(
|
|
626
|
+
check(
|
|
627
|
+
"kubo-update",
|
|
628
|
+
"blocked",
|
|
629
|
+
"The target official Kubo archive cache is invalid or unprotected; upgrade is blocked.",
|
|
630
|
+
false,
|
|
631
|
+
"Inspect the cache manually; it was not deleted or redownloaded.",
|
|
632
|
+
),
|
|
633
|
+
);
|
|
634
|
+
else if (await runningManagedNodes(stateDir))
|
|
635
|
+
checks.push(
|
|
636
|
+
check(
|
|
637
|
+
"kubo-update",
|
|
638
|
+
"blocked",
|
|
639
|
+
`Kubo ${installed.version} → ${release.version} is blocked by running or uncertain managed nodes.`,
|
|
640
|
+
false,
|
|
641
|
+
"Stop your managed nodes explicitly before upgrading; doctor never stops or contacts daemons.",
|
|
642
|
+
),
|
|
643
|
+
);
|
|
644
|
+
else
|
|
645
|
+
checks.push(
|
|
646
|
+
check(
|
|
647
|
+
"kubo-update",
|
|
648
|
+
"update-available",
|
|
649
|
+
`Managed Kubo ${installed.version}; latest compatible stable ${release.version} (${KUBO_RANGE})${installed.provenance === false ? "; upgrade depends on successful same-version archive verification" : ""}.`,
|
|
650
|
+
true,
|
|
651
|
+
"Run ipab doctor --fix to authorize the upgrade.",
|
|
652
|
+
),
|
|
653
|
+
);
|
|
654
|
+
} catch {
|
|
655
|
+
checks.push(
|
|
656
|
+
check(
|
|
657
|
+
"kubo-update",
|
|
658
|
+
"blocked",
|
|
659
|
+
"Managed node state cannot be verified for a safe upgrade.",
|
|
660
|
+
false,
|
|
661
|
+
"Inspect local managed node records; no daemon was contacted.",
|
|
662
|
+
),
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
} else if (installed?.provenance === false)
|
|
666
|
+
checks.push(
|
|
667
|
+
check(
|
|
668
|
+
"kubo-update",
|
|
669
|
+
"not-checked",
|
|
670
|
+
`Latest verified compatible stable Kubo is ${release.version} (${KUBO_RANGE}); installed receipt version ${installed.version} has unverified provenance, so its update state is unconfirmed.`,
|
|
671
|
+
false,
|
|
672
|
+
"Restore vetted archive provenance before confirming the installed version or authorizing an upgrade.",
|
|
673
|
+
),
|
|
674
|
+
);
|
|
675
|
+
else
|
|
676
|
+
checks.push(
|
|
677
|
+
check(
|
|
678
|
+
"kubo-update",
|
|
679
|
+
"ok",
|
|
680
|
+
`Latest verified compatible stable Kubo is ${release.version} (${KUBO_RANGE}); installed ${installed?.version ?? "none"}.`,
|
|
681
|
+
),
|
|
682
|
+
);
|
|
683
|
+
report.ready = ready(report);
|
|
684
|
+
options.signal?.throwIfAborted();
|
|
685
|
+
return {
|
|
686
|
+
report,
|
|
687
|
+
...(release ? { release } : {}),
|
|
688
|
+
...(verification ? { verification } : {}),
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
export async function doctorDevice(
|
|
692
|
+
stateDir: string,
|
|
693
|
+
env: NodeJS.ProcessEnv,
|
|
694
|
+
options: DoctorOptions,
|
|
695
|
+
): Promise<DoctorReport> {
|
|
696
|
+
options.signal?.throwIfAborted();
|
|
697
|
+
const initial = await inspect(stateDir, env, options);
|
|
698
|
+
let report = initial.report;
|
|
699
|
+
const release = initial.release;
|
|
700
|
+
const verification = initial.verification;
|
|
701
|
+
if (!options.fix) return report;
|
|
702
|
+
const state = report.checks.find((item) => item.id === "state")!;
|
|
703
|
+
const kubo = report.checks.find((item) => item.id === "kubo")!;
|
|
704
|
+
const unverifiedInstall = kubo.repairable && !verification && !release;
|
|
705
|
+
if (unverifiedInstall) {
|
|
706
|
+
options.diagnostic?.(
|
|
707
|
+
"Kubo repair is blocked: no verified latest compatible target. Retry doctor when official metadata is available.",
|
|
708
|
+
);
|
|
709
|
+
kubo.status = "blocked";
|
|
710
|
+
kubo.repairable = false;
|
|
711
|
+
kubo.message =
|
|
712
|
+
"Managed Kubo repair is blocked because the latest compatible official target is unverified.";
|
|
713
|
+
kubo.guidance =
|
|
714
|
+
"Retry when official release metadata is available; no installation was attempted.";
|
|
715
|
+
}
|
|
716
|
+
const blockedRepairs: DoctorReport["repairs"] = [];
|
|
717
|
+
const update = report.checks.find((item) => item.id === "kubo-update")!;
|
|
718
|
+
if (update.status === "blocked") {
|
|
719
|
+
blockedRepairs.push({
|
|
720
|
+
id: "kubo-update",
|
|
721
|
+
action: `Upgrade managed Kubo blocked: ${update.message}`,
|
|
722
|
+
status: "skipped",
|
|
723
|
+
});
|
|
724
|
+
options.diagnostic?.(`Repair blocked: ${update.message}`);
|
|
725
|
+
}
|
|
726
|
+
const identity = report.checks.find((item) => item.id === "identity")!;
|
|
727
|
+
const blockedIdentity =
|
|
728
|
+
identity.status === "missing" &&
|
|
729
|
+
kubo.status === "not-checked" &&
|
|
730
|
+
!verification;
|
|
731
|
+
if (blockedIdentity) {
|
|
732
|
+
identity.status = "blocked";
|
|
733
|
+
identity.repairable = false;
|
|
734
|
+
identity.message =
|
|
735
|
+
"Missing HOME identity repair is blocked by unverified managed Kubo provenance.";
|
|
736
|
+
identity.guidance =
|
|
737
|
+
"Restore verified Kubo provenance before creating the dependent identity; no identity was created.";
|
|
738
|
+
blockedRepairs.push({
|
|
739
|
+
id: "identity",
|
|
740
|
+
action: identity.message,
|
|
741
|
+
status: "skipped",
|
|
742
|
+
});
|
|
743
|
+
options.diagnostic?.(`Repair blocked: ${identity.message}`);
|
|
744
|
+
}
|
|
745
|
+
const actions = report.checks
|
|
746
|
+
.filter((item) => item.repairable)
|
|
747
|
+
.filter(
|
|
748
|
+
(item) =>
|
|
749
|
+
(item.id === "state" || state.status === "ok" || state.repairable) &&
|
|
750
|
+
(item.id !== "kubo" || verification || release) &&
|
|
751
|
+
(item.id !== "identity" ||
|
|
752
|
+
kubo.status === "ok" ||
|
|
753
|
+
(kubo.repairable && (verification || release))),
|
|
754
|
+
)
|
|
755
|
+
.map((item) => ({
|
|
756
|
+
id: item.id,
|
|
757
|
+
action:
|
|
758
|
+
item.id === "kubo-update"
|
|
759
|
+
? `Upgrade managed Kubo to ${release!.version}`
|
|
760
|
+
: item.id === "kubo"
|
|
761
|
+
? kubo.status === "not-checked" && verification
|
|
762
|
+
? `Download/cache the official Kubo ${verification.version} archive to verify the existing executable (no reinstall or node stopping)`
|
|
763
|
+
: `${kubo.status === "blocked" ? "Recover journaled installation using verified managed Kubo" : "Install verified managed Kubo"} ${release!.version}`
|
|
764
|
+
: item.id === "identity"
|
|
765
|
+
? "Create missing protected HOME account identity"
|
|
766
|
+
: "Create missing protected local state",
|
|
767
|
+
}));
|
|
768
|
+
if (!actions.length) {
|
|
769
|
+
report.repairs = blockedRepairs;
|
|
770
|
+
if (unverifiedInstall || blockedRepairs.length) report.ready = false;
|
|
771
|
+
return report;
|
|
772
|
+
}
|
|
773
|
+
for (const item of actions)
|
|
774
|
+
options.diagnostic?.(`Planned repair: ${item.action}.`);
|
|
775
|
+
if (
|
|
776
|
+
!options.yes &&
|
|
777
|
+
(!options.tty ||
|
|
778
|
+
!(await authorize(
|
|
779
|
+
options,
|
|
780
|
+
actions.map((item) => item.action),
|
|
781
|
+
)))
|
|
782
|
+
) {
|
|
783
|
+
options.diagnostic?.(
|
|
784
|
+
"Repairs were not authorized; use ipab doctor --fix --yes outside an interactive terminal.",
|
|
785
|
+
);
|
|
786
|
+
report.repairs = [
|
|
787
|
+
...blockedRepairs,
|
|
788
|
+
...actions.map((item) => ({ ...item, status: "skipped" as const })),
|
|
789
|
+
];
|
|
790
|
+
report.ready = false;
|
|
791
|
+
return report;
|
|
792
|
+
}
|
|
793
|
+
const repairs: DoctorReport["repairs"] = [];
|
|
794
|
+
let installationFailed = false;
|
|
795
|
+
for (const action of actions) {
|
|
796
|
+
options.signal?.throwIfAborted();
|
|
797
|
+
if (
|
|
798
|
+
(action.id === "identity" || action.id === "kubo-update") &&
|
|
799
|
+
installationFailed
|
|
800
|
+
) {
|
|
801
|
+
repairs.push({ ...action, status: "skipped" });
|
|
802
|
+
continue;
|
|
803
|
+
}
|
|
804
|
+
try {
|
|
805
|
+
// Inspect again immediately before each action; concurrent actors may
|
|
806
|
+
// have filled a missing resource or made its path unsafe.
|
|
807
|
+
const current = await inspect(
|
|
808
|
+
stateDir,
|
|
809
|
+
env,
|
|
810
|
+
{
|
|
811
|
+
...options,
|
|
812
|
+
...(release ? { release } : {}),
|
|
813
|
+
},
|
|
814
|
+
verification,
|
|
815
|
+
);
|
|
816
|
+
const item = current.report.checks.find((item) => item.id === action.id)!;
|
|
817
|
+
if (item.status === "ok") {
|
|
818
|
+
repairs.push({ ...action, status: "skipped" });
|
|
819
|
+
continue;
|
|
820
|
+
}
|
|
821
|
+
if (!item.repairable) throw new Error("Repair is no longer safe.");
|
|
822
|
+
if (
|
|
823
|
+
action.id !== "state" &&
|
|
824
|
+
current.report.checks.find((item) => item.id === "state")?.status !==
|
|
825
|
+
"ok"
|
|
826
|
+
)
|
|
827
|
+
throw new Error("State dependency is invalid.");
|
|
828
|
+
if (action.id === "state") prepareStateStorage(stateDir, env);
|
|
829
|
+
else if (action.id === "identity") {
|
|
830
|
+
if (
|
|
831
|
+
current.report.checks.find((item) => item.id === "kubo")?.status !==
|
|
832
|
+
"ok"
|
|
833
|
+
)
|
|
834
|
+
throw new Error("Kubo dependency is unavailable.");
|
|
835
|
+
await accountIdentity(env, true, true);
|
|
836
|
+
} else if (action.id === "kubo" && verification)
|
|
837
|
+
await verifyExistingKuboArchive(stateDir, verification, {
|
|
838
|
+
...options,
|
|
839
|
+
...(release ? { release } : {}),
|
|
840
|
+
});
|
|
841
|
+
else
|
|
842
|
+
await kuboBinary(stateDir, {
|
|
843
|
+
...options,
|
|
844
|
+
...(release ? { release } : {}),
|
|
845
|
+
upgrade: action.id === "kubo-update",
|
|
846
|
+
});
|
|
847
|
+
repairs.push({ ...action, status: "completed" });
|
|
848
|
+
} catch (cause) {
|
|
849
|
+
options.signal?.throwIfAborted();
|
|
850
|
+
options.diagnostic?.(
|
|
851
|
+
`Repair failed: ${action.action}. ${cause instanceof HostError && cause.code === "KUBO_SETUP_FAILED" ? cause.message : "Existing resources were not replaced; inspect the protected installation/cache and retry."}`,
|
|
852
|
+
);
|
|
853
|
+
repairs.push({ ...action, status: "failed" });
|
|
854
|
+
if (action.id === "kubo" || action.id === "kubo-update")
|
|
855
|
+
installationFailed = true;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
({ report } = await inspect(
|
|
859
|
+
stateDir,
|
|
860
|
+
env,
|
|
861
|
+
{
|
|
862
|
+
...options,
|
|
863
|
+
...(release ? { release } : {}),
|
|
864
|
+
},
|
|
865
|
+
verification,
|
|
866
|
+
));
|
|
867
|
+
report.repairs = [...blockedRepairs, ...repairs];
|
|
868
|
+
if (unverifiedInstall) {
|
|
869
|
+
const item = report.checks.find((item) => item.id === "kubo")!;
|
|
870
|
+
item.status = kubo.status;
|
|
871
|
+
item.repairable = false;
|
|
872
|
+
item.message = kubo.message;
|
|
873
|
+
item.guidance = kubo.guidance;
|
|
874
|
+
}
|
|
875
|
+
if (blockedIdentity) {
|
|
876
|
+
const item = report.checks.find((item) => item.id === "identity")!;
|
|
877
|
+
if (item.status === "missing") Object.assign(item, identity);
|
|
878
|
+
}
|
|
879
|
+
report.ready =
|
|
880
|
+
ready(report) &&
|
|
881
|
+
!unverifiedInstall &&
|
|
882
|
+
blockedRepairs.length === 0 &&
|
|
883
|
+
!report.checks.some(
|
|
884
|
+
(item) => item.id === "kubo-update" && item.status === "blocked",
|
|
885
|
+
);
|
|
886
|
+
options.signal?.throwIfAborted();
|
|
887
|
+
return report;
|
|
888
|
+
}
|
|
889
|
+
export function doctorText(report: DoctorReport): string {
|
|
890
|
+
return [
|
|
891
|
+
...report.checks.map(
|
|
892
|
+
(item) =>
|
|
893
|
+
`${item.status.toUpperCase().padEnd(17)} ${item.message}${item.guidance ? `\n ${item.guidance}` : ""}`,
|
|
894
|
+
),
|
|
895
|
+
...report.repairs.map(
|
|
896
|
+
(item) => `${item.status.toUpperCase()} ${item.action}`,
|
|
897
|
+
),
|
|
898
|
+
report.ready
|
|
899
|
+
? "Local operations are ready. Optional Swarm readiness is shown above."
|
|
900
|
+
: "Not ready; resolve the reported issues.",
|
|
901
|
+
].join("\n");
|
|
902
|
+
}
|