opencode-agent-orchestration-kit 1.0.32 → 1.0.33
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 +33 -2
- package/SECURITY.md +7 -0
- package/docker/open-design/data/app.sqlite +0 -0
- package/docker/open-design/data/app.sqlite-shm +0 -0
- package/docker/open-design/data/app.sqlite-wal +0 -0
- package/docker/open-design/opencode-auth/log/2026-05-02T105802.log +17 -0
- package/docker/open-design/opencode-auth/log/2026-05-04T102127.log +16 -0
- package/docker/open-design/opencode-auth/opencode.db +0 -0
- package/docker/open-design/opencode-auth/opencode.db-shm +0 -0
- package/docker/open-design/opencode-auth/opencode.db-wal +0 -0
- package/docs/cli.md +72 -0
- package/docs/installation.md +25 -5
- package/docs/quickstart.md +1 -1
- package/docs/releases/v1.0.33.md +72 -0
- package/docs/security.md +4 -0
- package/docs/supply-chain.md +9 -5
- package/docs/threat-model.md +244 -0
- package/docs/use-cases/README.md +31 -0
- package/docs/use-cases/direct-label-change/README.md +76 -0
- package/docs/use-cases/direct-label-change/before/package.json +8 -0
- package/docs/use-cases/direct-label-change/before/src/settings-label.mjs +1 -0
- package/docs/use-cases/direct-label-change/before/test/settings-label.test.mjs +8 -0
- package/docs/use-cases/direct-label-change/case.json +118 -0
- package/docs/use-cases/direct-label-change/expected/package.json +8 -0
- package/docs/use-cases/direct-label-change/expected/src/settings-label.mjs +1 -0
- package/docs/use-cases/direct-label-change/expected/test/settings-label.test.mjs +8 -0
- package/docs/use-cases/feature-tag-normalizer/README.md +78 -0
- package/docs/use-cases/feature-tag-normalizer/before/package.json +8 -0
- package/docs/use-cases/feature-tag-normalizer/before/src/normalize-tags.mjs +3 -0
- package/docs/use-cases/feature-tag-normalizer/before/test/normalize-tags.test.mjs +13 -0
- package/docs/use-cases/feature-tag-normalizer/case.json +119 -0
- package/docs/use-cases/feature-tag-normalizer/expected/package.json +8 -0
- package/docs/use-cases/feature-tag-normalizer/expected/src/normalize-tags.mjs +14 -0
- package/docs/use-cases/feature-tag-normalizer/expected/test/normalize-tags.test.mjs +18 -0
- package/docs/workflows.md +6 -0
- package/opencode/docs/ai/harness/README.md +2 -0
- package/opencode/docs/ai/harness/agents.md +7 -0
- package/opencode/docs/ai/harness/checks.md +9 -0
- package/opencode/docs/ai/harness/commands.md +8 -0
- package/opencode/docs/ai/harness/orchestration-contracts.json +891 -0
- package/opencode/package-lock.json +14 -8
- package/opencode/package.json +1 -0
- package/opencode/scripts/check-harness.mjs +634 -10
- package/opencode/scripts/check-harness.test.mjs +380 -0
- package/package.json +4 -1
- package/scripts/check-supply-chain.mjs +11 -1
- package/scripts/check-supply-chain.test.mjs +47 -0
- package/scripts/check-threat-model.mjs +421 -0
- package/scripts/check-threat-model.test.mjs +304 -0
- package/scripts/check-use-cases.mjs +501 -0
- package/scripts/check-use-cases.test.mjs +225 -0
- package/scripts/check.sh +51 -1
- package/scripts/install-smoke.sh +24 -1
- package/scripts/manage-installation.mjs +567 -25
- package/scripts/manage-installation.test.mjs +418 -0
- package/scripts/oak.mjs +200 -0
- package/scripts/oak.test.mjs +277 -0
- package/scripts/package-smoke.mjs +57 -0
- package/scripts/package-smoke.test.mjs +75 -2
- package/scripts/version.mjs +1 -0
- package/scripts/version.test.mjs +3 -2
- package/supply-chain.json +1 -0
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import crypto from "node:crypto";
|
|
5
5
|
import fs from "node:fs";
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { checkCompatibility } from "./check-compatibility.mjs";
|
|
7
9
|
import { parseStableVersion, readCanonicalVersion, formatVersion, compareStableVersions } from "./version.mjs";
|
|
8
10
|
|
|
9
11
|
export const SCHEMA_VERSION = 1;
|
|
@@ -15,6 +17,120 @@ export const PROTECTED_ROOT_FILES = [
|
|
|
15
17
|
"tui.json",
|
|
16
18
|
];
|
|
17
19
|
|
|
20
|
+
const DOCTOR_CHECK_IDS = [
|
|
21
|
+
"opencode-version",
|
|
22
|
+
"node-version",
|
|
23
|
+
"dependencies",
|
|
24
|
+
"installed-files",
|
|
25
|
+
"file-drift",
|
|
26
|
+
"required-configuration",
|
|
27
|
+
"optional-plugins",
|
|
28
|
+
"permissions",
|
|
29
|
+
"executable-scripts",
|
|
30
|
+
"skill-registry",
|
|
31
|
+
"compatibility",
|
|
32
|
+
"legacy-residue",
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
function doctorCheck(id, status, summary, action = null) {
|
|
36
|
+
if (!DOCTOR_CHECK_IDS.includes(id)) throw invalid("doctor check id is invalid");
|
|
37
|
+
if (!["pass", "info", "action-required", "not-applicable"].includes(status)) {
|
|
38
|
+
throw invalid("doctor check status is invalid");
|
|
39
|
+
}
|
|
40
|
+
if (typeof summary !== "string" || summary.length === 0 || summary.includes("\n")) {
|
|
41
|
+
throw invalid("doctor check summary must be one non-empty line");
|
|
42
|
+
}
|
|
43
|
+
if (status === "action-required") {
|
|
44
|
+
if (typeof action !== "string" || action.length === 0 || action.includes("\n")) {
|
|
45
|
+
throw invalid("action-required doctor check must have one action line");
|
|
46
|
+
}
|
|
47
|
+
} else if (action !== null) {
|
|
48
|
+
throw invalid("non-actionable doctor check action must be null");
|
|
49
|
+
}
|
|
50
|
+
return { id, status, summary, action };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function summarizeDoctorChecks(checks) {
|
|
54
|
+
const summary = { pass: 0, info: 0, actionRequired: 0, notApplicable: 0 };
|
|
55
|
+
const keys = {
|
|
56
|
+
pass: "pass",
|
|
57
|
+
info: "info",
|
|
58
|
+
"action-required": "actionRequired",
|
|
59
|
+
"not-applicable": "notApplicable",
|
|
60
|
+
};
|
|
61
|
+
for (const check of checks) summary[keys[check.status]] += 1;
|
|
62
|
+
return summary;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function renderDoctorReport(report) {
|
|
66
|
+
const actions = {
|
|
67
|
+
"not-installed": "run install --dry-run",
|
|
68
|
+
current: "none",
|
|
69
|
+
"upgrade-available": "run upgrade --dry-run",
|
|
70
|
+
"source-older": "use a source checkout at least as new as the installation",
|
|
71
|
+
"same-version-different-payload": "fix the release identity mismatch",
|
|
72
|
+
"invalid-version-state": "repair the invalid version state",
|
|
73
|
+
};
|
|
74
|
+
const expectedSummary = summarizeDoctorChecks(report.checks);
|
|
75
|
+
if (JSON.stringify(expectedSummary) !== JSON.stringify(report.summary)) {
|
|
76
|
+
throw invalid("doctor report summary is inconsistent");
|
|
77
|
+
}
|
|
78
|
+
const lifecycleActionable = report.versionState !== "current"
|
|
79
|
+
|| report.blockers.length > 0
|
|
80
|
+
|| report.activeTransaction
|
|
81
|
+
|| report.activeLock
|
|
82
|
+
|| report.cleanupResidue.length > 0;
|
|
83
|
+
const actionable = lifecycleActionable
|
|
84
|
+
|| report.checks.some((check) => check.status === "action-required");
|
|
85
|
+
const lines = [
|
|
86
|
+
`doctor: ${actionable ? "action required" : "healthy"}; source=${report.sourceVersion ?? "invalid"}; installed=${report.installedVersion ?? "none"}; version=${report.versionState}; action=${actions[report.versionState]}`,
|
|
87
|
+
];
|
|
88
|
+
for (const check of report.checks) {
|
|
89
|
+
lines.push(`[${check.status}] ${check.id}: ${check.summary}`);
|
|
90
|
+
if (check.status === "action-required") lines.push(` action: ${check.action}`);
|
|
91
|
+
}
|
|
92
|
+
lines.push(
|
|
93
|
+
`summary: pass=${report.summary.pass} info=${report.summary.info} action-required=${report.summary.actionRequired} not-applicable=${report.summary.notApplicable}`,
|
|
94
|
+
);
|
|
95
|
+
return `${lines.join("\n")}\n`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function parseRuntimeVersion(value, label) {
|
|
99
|
+
if (typeof value !== "string") throw invalid(`${label} version is invalid`);
|
|
100
|
+
const canonical = value.trim().replace(/^v(?=\d)/, "");
|
|
101
|
+
try {
|
|
102
|
+
return parseStableVersion(canonical);
|
|
103
|
+
} catch {
|
|
104
|
+
throw invalid(`${label} version is invalid`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function nodeSatisfiesCanonicalEngines(versionValue, engines) {
|
|
109
|
+
const version = parseRuntimeVersion(versionValue, "Node");
|
|
110
|
+
if (typeof engines !== "string") throw invalid("Node compatibility contract is invalid");
|
|
111
|
+
const ranges = engines.split(" || ");
|
|
112
|
+
if (ranges.length === 0) throw invalid("Node compatibility contract is invalid");
|
|
113
|
+
return ranges.some((range) => {
|
|
114
|
+
if (!range.startsWith("^")) throw invalid("Node compatibility contract is invalid");
|
|
115
|
+
const floor = parseRuntimeVersion(range.slice(1), "Node compatibility");
|
|
116
|
+
return version.major === floor.major && compareStableVersions(version.canonical, floor.canonical) >= 0;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function opencodeSatisfiesCompatibility(versionValue, compatibility) {
|
|
121
|
+
const version = parseRuntimeVersion(versionValue, "OpenCode");
|
|
122
|
+
const minimum = parseRuntimeVersion(compatibility.opencode.minimum_tested, "OpenCode compatibility");
|
|
123
|
+
const range = /^>=(\d+\.\d+\.\d+) <(\d+\.\d+\.\d+)$/.exec(compatibility.opencode.supported_range);
|
|
124
|
+
if (!range) throw invalid("OpenCode compatibility contract is invalid");
|
|
125
|
+
const lower = parseRuntimeVersion(range[1], "OpenCode compatibility");
|
|
126
|
+
const upper = parseRuntimeVersion(range[2], "OpenCode compatibility");
|
|
127
|
+
if (lower.canonical !== minimum.canonical) {
|
|
128
|
+
throw invalid("OpenCode compatibility contract is invalid");
|
|
129
|
+
}
|
|
130
|
+
return compareStableVersions(version.canonical, minimum.canonical) >= 0
|
|
131
|
+
&& compareStableVersions(version.canonical, upper.canonical) < 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
18
134
|
const COMMAND_FLAGS = {
|
|
19
135
|
install: new Set(["dryRun", "force", "target", "help"]),
|
|
20
136
|
upgrade: new Set(["dryRun", "target", "help"]),
|
|
@@ -891,6 +1007,11 @@ function currentManifestDigest(targetRoot, fsOps = fs) {
|
|
|
891
1007
|
export function createInstallationManager(options) {
|
|
892
1008
|
const sourceRoot = options.sourceRoot;
|
|
893
1009
|
const fsOps = options.fsOps ?? fs;
|
|
1010
|
+
const repositoryRoot = options.repositoryRoot ?? path.dirname(sourceRoot);
|
|
1011
|
+
const commandRunner = options.commandRunner ?? spawnSync;
|
|
1012
|
+
const nodeVersionProvider = options.nodeVersionProvider ?? (() => process.version);
|
|
1013
|
+
const compatibilityProvider = options.compatibilityProvider
|
|
1014
|
+
?? (() => checkCompatibility(repositoryRoot, { fsOps, surfaces: false }));
|
|
894
1015
|
const clock = options.clock ?? (() => new Date());
|
|
895
1016
|
const newTransactionId = options.transactionId ?? (() => crypto.randomUUID());
|
|
896
1017
|
const failpoint = options.failpoint ?? (() => {});
|
|
@@ -1172,6 +1293,353 @@ export function createInstallationManager(options) {
|
|
|
1172
1293
|
return { exitCode: 0, transaction: active };
|
|
1173
1294
|
}
|
|
1174
1295
|
|
|
1296
|
+
function readTargetJson(targetRoot, relative, { required = false } = {}) {
|
|
1297
|
+
const state = inspectTargetPath(targetRoot, relative, fsOps);
|
|
1298
|
+
if (state.kind === "absent") {
|
|
1299
|
+
if (required) throw invalid(`${relative} is missing`);
|
|
1300
|
+
return null;
|
|
1301
|
+
}
|
|
1302
|
+
if (state.kind !== "file") throw invalid(`${relative} must be a regular file`);
|
|
1303
|
+
try {
|
|
1304
|
+
return JSON.parse(fsOps.readFileSync(path.join(targetRoot, relative), "utf8"));
|
|
1305
|
+
} catch {
|
|
1306
|
+
throw invalid(`${relative} is invalid JSON`);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
function dependencyDoctorCheck(targetRoot) {
|
|
1311
|
+
const packageJson = readTargetJson(targetRoot, "package.json");
|
|
1312
|
+
const packageLock = readTargetJson(targetRoot, "package-lock.json");
|
|
1313
|
+
if (!packageJson && !packageLock) {
|
|
1314
|
+
return doctorCheck("dependencies", "not-applicable", "no dependency contract is installed");
|
|
1315
|
+
}
|
|
1316
|
+
if (!packageJson || !packageLock) {
|
|
1317
|
+
return doctorCheck(
|
|
1318
|
+
"dependencies",
|
|
1319
|
+
"action-required",
|
|
1320
|
+
"the installed package and lockfile are incomplete",
|
|
1321
|
+
"review package.json and package-lock.json before installing dependencies",
|
|
1322
|
+
);
|
|
1323
|
+
}
|
|
1324
|
+
const dependencies = packageJson.dependencies;
|
|
1325
|
+
const lockRoot = packageLock.packages?.[""];
|
|
1326
|
+
if (!dependencies || typeof dependencies !== "object" || Array.isArray(dependencies)
|
|
1327
|
+
|| !lockRoot || typeof lockRoot !== "object" || Array.isArray(lockRoot)
|
|
1328
|
+
|| !lockRoot.dependencies || typeof lockRoot.dependencies !== "object") {
|
|
1329
|
+
throw invalid("installed dependency contract is invalid");
|
|
1330
|
+
}
|
|
1331
|
+
const problems = [];
|
|
1332
|
+
for (const name of Object.keys(dependencies).sort()) {
|
|
1333
|
+
const expected = dependencies[name];
|
|
1334
|
+
const locked = lockRoot.dependencies[name];
|
|
1335
|
+
const lockEntry = packageLock.packages?.[`node_modules/${name}`];
|
|
1336
|
+
const installed = readTargetJson(targetRoot, `node_modules/${name}/package.json`);
|
|
1337
|
+
if (typeof expected !== "string" || locked !== expected
|
|
1338
|
+
|| lockEntry?.version !== expected || installed?.version !== expected) {
|
|
1339
|
+
problems.push(name);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
return problems.length === 0
|
|
1343
|
+
? doctorCheck("dependencies", "pass", `${Object.keys(dependencies).length} direct dependencies are installed`)
|
|
1344
|
+
: doctorCheck(
|
|
1345
|
+
"dependencies",
|
|
1346
|
+
"action-required",
|
|
1347
|
+
`${problems.length} direct dependencies require attention`,
|
|
1348
|
+
"review package manifests, then run npm ci --ignore-scripts",
|
|
1349
|
+
);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
function configurationAndPluginDoctorChecks(targetRoot, sourceRoot) {
|
|
1353
|
+
let sourceConfig;
|
|
1354
|
+
try {
|
|
1355
|
+
sourceConfig = readTargetJson(sourceRoot, "opencode.json");
|
|
1356
|
+
} catch {
|
|
1357
|
+
sourceConfig = null;
|
|
1358
|
+
}
|
|
1359
|
+
if (typeof sourceConfig?.default_agent !== "string" || sourceConfig.default_agent.length === 0) {
|
|
1360
|
+
return {
|
|
1361
|
+
configuration: doctorCheck(
|
|
1362
|
+
"required-configuration",
|
|
1363
|
+
"not-applicable",
|
|
1364
|
+
"no semantic OpenCode configuration contract is installed",
|
|
1365
|
+
),
|
|
1366
|
+
plugins: doctorCheck("optional-plugins", "not-applicable", "no optional plugin contract is installed"),
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
const config = readTargetJson(targetRoot, "opencode.json");
|
|
1370
|
+
const tui = readTargetJson(targetRoot, "tui.json");
|
|
1371
|
+
if (!config) {
|
|
1372
|
+
return {
|
|
1373
|
+
configuration: doctorCheck(
|
|
1374
|
+
"required-configuration",
|
|
1375
|
+
"not-applicable",
|
|
1376
|
+
"no OpenCode configuration is installed",
|
|
1377
|
+
),
|
|
1378
|
+
plugins: doctorCheck("optional-plugins", "not-applicable", "no optional plugins are configured"),
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
const defaultAgent = config.default_agent;
|
|
1382
|
+
const agentState = typeof defaultAgent === "string" && defaultAgent.length > 0
|
|
1383
|
+
? inspectTargetPath(targetRoot, `agents/${defaultAgent}.md`, fsOps)
|
|
1384
|
+
: { kind: "absent" };
|
|
1385
|
+
const configuration = typeof defaultAgent === "string"
|
|
1386
|
+
&& defaultAgent.length > 0
|
|
1387
|
+
&& agentState.kind === "file"
|
|
1388
|
+
? doctorCheck("required-configuration", "pass", `default agent ${defaultAgent} is available`)
|
|
1389
|
+
: doctorCheck(
|
|
1390
|
+
"required-configuration",
|
|
1391
|
+
"action-required",
|
|
1392
|
+
"the required default agent configuration is incomplete",
|
|
1393
|
+
"set default_agent to an installed regular agent file",
|
|
1394
|
+
);
|
|
1395
|
+
const references = [];
|
|
1396
|
+
for (const value of [config.plugin, tui?.plugin]) {
|
|
1397
|
+
if (value === undefined) continue;
|
|
1398
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry.length === 0)) {
|
|
1399
|
+
throw invalid("plugin configuration must be an array of non-empty strings");
|
|
1400
|
+
}
|
|
1401
|
+
references.push(...value);
|
|
1402
|
+
}
|
|
1403
|
+
if (references.length === 0) {
|
|
1404
|
+
return {
|
|
1405
|
+
configuration,
|
|
1406
|
+
plugins: doctorCheck("optional-plugins", "not-applicable", "no optional plugins are configured"),
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
let externalPinned = 0;
|
|
1410
|
+
const broken = [];
|
|
1411
|
+
for (const reference of references) {
|
|
1412
|
+
if (reference.startsWith("./")) {
|
|
1413
|
+
try {
|
|
1414
|
+
const relative = normalizeManagedPath(reference.slice(2));
|
|
1415
|
+
if (inspectTargetPath(targetRoot, relative, fsOps).kind !== "file") broken.push(relative);
|
|
1416
|
+
} catch {
|
|
1417
|
+
broken.push("local-plugin");
|
|
1418
|
+
}
|
|
1419
|
+
} else if (/#([0-9a-f]{40})$/.test(reference)) {
|
|
1420
|
+
externalPinned += 1;
|
|
1421
|
+
} else {
|
|
1422
|
+
broken.push("external-plugin");
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
const plugins = broken.length > 0
|
|
1426
|
+
? doctorCheck(
|
|
1427
|
+
"optional-plugins",
|
|
1428
|
+
"action-required",
|
|
1429
|
+
`${broken.length} configured plugin references require attention`,
|
|
1430
|
+
"repair local plugin paths or pin external executable references",
|
|
1431
|
+
)
|
|
1432
|
+
: externalPinned > 0
|
|
1433
|
+
? doctorCheck(
|
|
1434
|
+
"optional-plugins",
|
|
1435
|
+
"info",
|
|
1436
|
+
`${externalPinned} pinned external plugin references are not verified offline`,
|
|
1437
|
+
)
|
|
1438
|
+
: doctorCheck("optional-plugins", "pass", "configured local plugins are available");
|
|
1439
|
+
return { configuration, plugins };
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
function ownershipDoctorChecks(targetRoot, inspection, plan) {
|
|
1443
|
+
const wrappers = [
|
|
1444
|
+
"install.sh",
|
|
1445
|
+
"uninstall.sh",
|
|
1446
|
+
"upgrade.sh",
|
|
1447
|
+
"doctor.sh",
|
|
1448
|
+
"rollback.sh",
|
|
1449
|
+
"scripts/check.sh",
|
|
1450
|
+
"scripts/opencode-compat-smoke.sh",
|
|
1451
|
+
"scripts/package-smoke.sh",
|
|
1452
|
+
];
|
|
1453
|
+
const rootPackage = lstatIfExists(path.join(repositoryRoot, "package.json"), fsOps);
|
|
1454
|
+
const sourceExecutablesEvaluable = rootPackage?.isFile() && !rootPackage.isSymbolicLink();
|
|
1455
|
+
const brokenWrappers = sourceExecutablesEvaluable
|
|
1456
|
+
? wrappers.filter((relative) => {
|
|
1457
|
+
const stat = lstatIfExists(path.join(repositoryRoot, relative), fsOps);
|
|
1458
|
+
return !stat?.isFile() || stat.isSymbolicLink() || (stat.mode & 0o111) === 0;
|
|
1459
|
+
})
|
|
1460
|
+
: [];
|
|
1461
|
+
if (!inspection?.manifest) {
|
|
1462
|
+
const notApplicable = (id, summary) => doctorCheck(id, "not-applicable", summary);
|
|
1463
|
+
return {
|
|
1464
|
+
installed: notApplicable("installed-files", "no ownership manifest is installed"),
|
|
1465
|
+
drift: notApplicable("file-drift", "file drift cannot be evaluated without an ownership manifest"),
|
|
1466
|
+
permissions: notApplicable("permissions", "managed permissions cannot be evaluated without an ownership manifest"),
|
|
1467
|
+
executables: sourceExecutablesEvaluable
|
|
1468
|
+
? brokenWrappers.length === 0
|
|
1469
|
+
? doctorCheck("executable-scripts", "pass", "expected source executable scripts retain approved modes")
|
|
1470
|
+
: doctorCheck(
|
|
1471
|
+
"executable-scripts",
|
|
1472
|
+
"action-required",
|
|
1473
|
+
"one or more source executable scripts require attention",
|
|
1474
|
+
`inspect ${brokenWrappers[0]}`,
|
|
1475
|
+
)
|
|
1476
|
+
: notApplicable("executable-scripts", "no executable script group is evaluable"),
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
const managedEntries = [
|
|
1480
|
+
...inspection.manifest.owned_files,
|
|
1481
|
+
...inspection.manifest.preserved_files,
|
|
1482
|
+
];
|
|
1483
|
+
const unsafe = managedEntries.filter((entry) => inspection.target[entry.path]?.kind !== "file");
|
|
1484
|
+
const installed = unsafe.length === 0
|
|
1485
|
+
? doctorCheck("installed-files", "pass", `${managedEntries.length} managed paths are regular files`)
|
|
1486
|
+
: doctorCheck(
|
|
1487
|
+
"installed-files",
|
|
1488
|
+
"action-required",
|
|
1489
|
+
`${unsafe.length} managed paths are missing or unsafe`,
|
|
1490
|
+
`inspect ${unsafe[0].path}`,
|
|
1491
|
+
);
|
|
1492
|
+
const actionableWarnings = new Set([
|
|
1493
|
+
"preserved-source-changed",
|
|
1494
|
+
"preserved-both-changed",
|
|
1495
|
+
"preserved-missing",
|
|
1496
|
+
"obsolete-preserved-present",
|
|
1497
|
+
"obsolete-preserved-missing",
|
|
1498
|
+
]);
|
|
1499
|
+
const driftActionable = plan.blockers.length > 0
|
|
1500
|
+
|| plan.warnings.some((warning) => actionableWarnings.has(warning.classification));
|
|
1501
|
+
const userOnly = !driftActionable
|
|
1502
|
+
&& plan.warnings.some((warning) => warning.classification === "preserved-user-changed");
|
|
1503
|
+
const drift = driftActionable
|
|
1504
|
+
? doctorCheck(
|
|
1505
|
+
"file-drift",
|
|
1506
|
+
"action-required",
|
|
1507
|
+
"managed file drift requires attention",
|
|
1508
|
+
"review the reported ownership conflicts before upgrade",
|
|
1509
|
+
)
|
|
1510
|
+
: userOnly
|
|
1511
|
+
? doctorCheck("file-drift", "info", "preserved user configuration changed without source drift")
|
|
1512
|
+
: doctorCheck("file-drift", "pass", "managed file hashes match their approved state");
|
|
1513
|
+
const ownedModeDrift = inspection.manifest.owned_files.filter((entry) => {
|
|
1514
|
+
const expectedMode = Object.hasOwn(entry, "mode") ? entry.mode : entry.observed_mode;
|
|
1515
|
+
return inspection.target[entry.path]?.kind === "file"
|
|
1516
|
+
&& inspection.target[entry.path].mode !== expectedMode;
|
|
1517
|
+
});
|
|
1518
|
+
const preservedModeDrift = inspection.manifest.preserved_files.filter((entry) => (
|
|
1519
|
+
inspection.target[entry.path]?.kind === "file"
|
|
1520
|
+
&& inspection.target[entry.path].mode !== entry.observed_mode
|
|
1521
|
+
));
|
|
1522
|
+
const oakStat = lstatIfExists(path.join(targetRoot, ".oak"), fsOps);
|
|
1523
|
+
const stateFiles = [
|
|
1524
|
+
".oak/manifest.json",
|
|
1525
|
+
".oak/lock.json",
|
|
1526
|
+
".oak/transaction.json",
|
|
1527
|
+
".oak/rollback/transaction.json",
|
|
1528
|
+
".oak/rollback.next/transaction.json",
|
|
1529
|
+
".oak/rollback.previous/transaction.json",
|
|
1530
|
+
];
|
|
1531
|
+
const unsafeStateFile = stateFiles.find((relative) => {
|
|
1532
|
+
const stat = lstatIfExists(path.join(targetRoot, relative), fsOps);
|
|
1533
|
+
return stat && (stat.isSymbolicLink() || !stat.isFile() || (stat.mode & 0o777) !== 0o600);
|
|
1534
|
+
});
|
|
1535
|
+
const stateModeUnsafe = !oakStat?.isDirectory()
|
|
1536
|
+
|| oakStat.isSymbolicLink()
|
|
1537
|
+
|| (oakStat.mode & 0o777) !== 0o700
|
|
1538
|
+
|| unsafeStateFile;
|
|
1539
|
+
const permissions = ownedModeDrift.length > 0 || stateModeUnsafe
|
|
1540
|
+
? doctorCheck(
|
|
1541
|
+
"permissions",
|
|
1542
|
+
"action-required",
|
|
1543
|
+
"managed or lifecycle permissions require attention",
|
|
1544
|
+
`inspect ${ownedModeDrift[0]?.path ?? unsafeStateFile ?? ".oak"}`,
|
|
1545
|
+
)
|
|
1546
|
+
: preservedModeDrift.length > 0
|
|
1547
|
+
? doctorCheck("permissions", "info", "preserved user file modes differ from their recorded baselines")
|
|
1548
|
+
: doctorCheck("permissions", "pass", "managed and lifecycle permissions match");
|
|
1549
|
+
const executableEntries = inspection.manifest.owned_files.filter((entry) => (entry.mode & 0o111) !== 0);
|
|
1550
|
+
const brokenExecutable = executableEntries.filter((entry) => {
|
|
1551
|
+
const current = inspection.target[entry.path];
|
|
1552
|
+
return current?.kind !== "file" || (current.mode & entry.mode & 0o111) !== (entry.mode & 0o111);
|
|
1553
|
+
});
|
|
1554
|
+
const executables = brokenExecutable.length === 0 && brokenWrappers.length === 0
|
|
1555
|
+
? doctorCheck("executable-scripts", "pass", "expected executable scripts retain approved modes")
|
|
1556
|
+
: doctorCheck(
|
|
1557
|
+
"executable-scripts",
|
|
1558
|
+
"action-required",
|
|
1559
|
+
"one or more executable scripts require attention",
|
|
1560
|
+
`inspect ${brokenExecutable[0]?.path ?? brokenWrappers[0]}`,
|
|
1561
|
+
);
|
|
1562
|
+
return { installed, drift, permissions, executables };
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
function skillRegistryDoctorCheck(targetRoot, inspection) {
|
|
1566
|
+
const relative = "scripts/update-skill-registry.mjs";
|
|
1567
|
+
const expected = [
|
|
1568
|
+
...(inspection?.manifest?.owned_files ?? []),
|
|
1569
|
+
...(inspection?.manifest?.preserved_files ?? []),
|
|
1570
|
+
].some((entry) => entry.path === relative);
|
|
1571
|
+
let state;
|
|
1572
|
+
try {
|
|
1573
|
+
state = inspectTargetPath(targetRoot, relative, fsOps);
|
|
1574
|
+
} catch {
|
|
1575
|
+
state = { kind: "unsafe" };
|
|
1576
|
+
}
|
|
1577
|
+
if (state.kind !== "file") {
|
|
1578
|
+
return expected
|
|
1579
|
+
? doctorCheck(
|
|
1580
|
+
"skill-registry",
|
|
1581
|
+
"action-required",
|
|
1582
|
+
"the installed skill registry checker is unavailable",
|
|
1583
|
+
"restore scripts/update-skill-registry.mjs from a reviewed kit source",
|
|
1584
|
+
)
|
|
1585
|
+
: doctorCheck("skill-registry", "not-applicable", "no portable skill registry checker is installed");
|
|
1586
|
+
}
|
|
1587
|
+
let observed;
|
|
1588
|
+
try {
|
|
1589
|
+
observed = commandRunner(process.execPath, [path.join(targetRoot, relative), "--check"], {
|
|
1590
|
+
cwd: targetRoot,
|
|
1591
|
+
encoding: "utf8",
|
|
1592
|
+
env: { ...process.env, OPENCODE_INCLUDE_USER_SKILLS: "0" },
|
|
1593
|
+
maxBuffer: 64 * 1024,
|
|
1594
|
+
shell: false,
|
|
1595
|
+
timeout: 5_000,
|
|
1596
|
+
});
|
|
1597
|
+
} catch {
|
|
1598
|
+
observed = null;
|
|
1599
|
+
}
|
|
1600
|
+
return observed?.status === 0 && !observed.error
|
|
1601
|
+
? doctorCheck("skill-registry", "pass", "the portable skill registry is current")
|
|
1602
|
+
: doctorCheck(
|
|
1603
|
+
"skill-registry",
|
|
1604
|
+
"action-required",
|
|
1605
|
+
"the portable skill registry requires attention",
|
|
1606
|
+
"run node scripts/update-skill-registry.mjs after reviewing local changes",
|
|
1607
|
+
);
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
function legacyResidueDoctorCheck(targetRoot, inspection, common, plan) {
|
|
1611
|
+
if (inspection?.manifest) {
|
|
1612
|
+
const obsolete = plan?.warnings.some((warning) => warning.classification.startsWith("obsolete-"))
|
|
1613
|
+
|| plan?.blockers.some((blocker) => blocker.classification.startsWith("obsolete-"));
|
|
1614
|
+
const actionable = common.activeTransaction
|
|
1615
|
+
|| common.activeLock === "stale"
|
|
1616
|
+
|| common.cleanupResidue.length > 0
|
|
1617
|
+
|| obsolete;
|
|
1618
|
+
return actionable
|
|
1619
|
+
? doctorCheck(
|
|
1620
|
+
"legacy-residue",
|
|
1621
|
+
"action-required",
|
|
1622
|
+
"lifecycle residue or obsolete managed state requires attention",
|
|
1623
|
+
"review rollback and recovery state before changing the installation",
|
|
1624
|
+
)
|
|
1625
|
+
: doctorCheck("legacy-residue", "pass", "no legacy or lifecycle residue was found");
|
|
1626
|
+
}
|
|
1627
|
+
const markers = [
|
|
1628
|
+
lstatIfExists(path.join(targetRoot, "AGENTS.md"), fsOps)?.isFile(),
|
|
1629
|
+
lstatIfExists(path.join(targetRoot, "opencode.json"), fsOps)?.isFile(),
|
|
1630
|
+
lstatIfExists(path.join(targetRoot, "agents"), fsOps)?.isDirectory(),
|
|
1631
|
+
lstatIfExists(path.join(targetRoot, "commands"), fsOps)?.isDirectory(),
|
|
1632
|
+
];
|
|
1633
|
+
return markers.every(Boolean)
|
|
1634
|
+
? doctorCheck(
|
|
1635
|
+
"legacy-residue",
|
|
1636
|
+
"action-required",
|
|
1637
|
+
"an unmanaged legacy harness installation was detected",
|
|
1638
|
+
"back up the target and review install --dry-run",
|
|
1639
|
+
)
|
|
1640
|
+
: doctorCheck("legacy-residue", "not-applicable", "no managed or legacy harness state was detected");
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1175
1643
|
function doctorReport(targetRoot) {
|
|
1176
1644
|
const oakPath = path.join(targetRoot, ".oak");
|
|
1177
1645
|
const manifestPath = path.join(oakPath, "manifest.json");
|
|
@@ -1188,6 +1656,82 @@ export function createInstallationManager(options) {
|
|
|
1188
1656
|
rollbackAvailable: Boolean(lstatIfExists(path.join(oakPath, "rollback", "transaction.json"), fsOps)),
|
|
1189
1657
|
cleanupResidue: residue,
|
|
1190
1658
|
};
|
|
1659
|
+
const compatibility = compatibilityProvider();
|
|
1660
|
+
const nodeVersion = nodeVersionProvider();
|
|
1661
|
+
const nodeCompatible = nodeSatisfiesCanonicalEngines(nodeVersion, compatibility.node.engines);
|
|
1662
|
+
const nodeCheck = nodeCompatible
|
|
1663
|
+
? doctorCheck("node-version", "pass", `Node ${parseRuntimeVersion(nodeVersion, "Node").canonical} is supported`)
|
|
1664
|
+
: doctorCheck(
|
|
1665
|
+
"node-version",
|
|
1666
|
+
"action-required",
|
|
1667
|
+
`Node ${parseRuntimeVersion(nodeVersion, "Node").canonical} is outside the supported range`,
|
|
1668
|
+
`use Node ${compatibility.node.engines}`,
|
|
1669
|
+
);
|
|
1670
|
+
let opencodeCheck;
|
|
1671
|
+
try {
|
|
1672
|
+
const observed = commandRunner("opencode", ["--version"], {
|
|
1673
|
+
encoding: "utf8",
|
|
1674
|
+
maxBuffer: 64 * 1024,
|
|
1675
|
+
shell: false,
|
|
1676
|
+
timeout: 5_000,
|
|
1677
|
+
});
|
|
1678
|
+
if (observed?.status !== 0 || observed?.error) {
|
|
1679
|
+
opencodeCheck = doctorCheck(
|
|
1680
|
+
"opencode-version",
|
|
1681
|
+
"action-required",
|
|
1682
|
+
"OpenCode version could not be determined",
|
|
1683
|
+
"install OpenCode or correct PATH",
|
|
1684
|
+
);
|
|
1685
|
+
} else {
|
|
1686
|
+
const parsed = parseRuntimeVersion(String(observed.stdout ?? "").split(/\r?\n/, 1)[0], "OpenCode");
|
|
1687
|
+
opencodeCheck = opencodeSatisfiesCompatibility(parsed.canonical, compatibility)
|
|
1688
|
+
? doctorCheck("opencode-version", "pass", `OpenCode ${parsed.canonical} is supported`)
|
|
1689
|
+
: doctorCheck(
|
|
1690
|
+
"opencode-version",
|
|
1691
|
+
"action-required",
|
|
1692
|
+
`OpenCode ${parsed.canonical} is outside the supported range`,
|
|
1693
|
+
`use OpenCode ${compatibility.opencode.supported_range}`,
|
|
1694
|
+
);
|
|
1695
|
+
}
|
|
1696
|
+
} catch {
|
|
1697
|
+
opencodeCheck = doctorCheck(
|
|
1698
|
+
"opencode-version",
|
|
1699
|
+
"action-required",
|
|
1700
|
+
"OpenCode version could not be determined",
|
|
1701
|
+
"install OpenCode or correct PATH",
|
|
1702
|
+
);
|
|
1703
|
+
}
|
|
1704
|
+
const attachDoctorChecks = (report, { inspection = null, plan = null } = {}) => {
|
|
1705
|
+
const dependencies = dependencyDoctorCheck(targetRoot);
|
|
1706
|
+
const configuration = configurationAndPluginDoctorChecks(targetRoot, inspection?.sourceRoot ?? sourceRoot);
|
|
1707
|
+
const ownership = ownershipDoctorChecks(targetRoot, inspection, plan);
|
|
1708
|
+
const registry = skillRegistryDoctorCheck(targetRoot, inspection);
|
|
1709
|
+
const legacy = legacyResidueDoctorCheck(targetRoot, inspection, common, plan);
|
|
1710
|
+
const checks = [
|
|
1711
|
+
opencodeCheck,
|
|
1712
|
+
nodeCheck,
|
|
1713
|
+
dependencies,
|
|
1714
|
+
ownership.installed,
|
|
1715
|
+
ownership.drift,
|
|
1716
|
+
configuration.configuration,
|
|
1717
|
+
configuration.plugins,
|
|
1718
|
+
ownership.permissions,
|
|
1719
|
+
ownership.executables,
|
|
1720
|
+
registry,
|
|
1721
|
+
nodeCheck.status === "pass"
|
|
1722
|
+
&& opencodeCheck.status === "pass"
|
|
1723
|
+
&& dependencies.status !== "action-required"
|
|
1724
|
+
? doctorCheck("compatibility", "pass", "runtime compatibility is satisfied")
|
|
1725
|
+
: doctorCheck(
|
|
1726
|
+
"compatibility",
|
|
1727
|
+
"action-required",
|
|
1728
|
+
"runtime compatibility requires action",
|
|
1729
|
+
"resolve the runtime findings above",
|
|
1730
|
+
),
|
|
1731
|
+
legacy,
|
|
1732
|
+
];
|
|
1733
|
+
return { ...report, checks, summary: summarizeDoctorChecks(checks) };
|
|
1734
|
+
};
|
|
1191
1735
|
let sourceVersion = null;
|
|
1192
1736
|
let sourceInvalid = false;
|
|
1193
1737
|
try {
|
|
@@ -1204,7 +1748,7 @@ export function createInstallationManager(options) {
|
|
|
1204
1748
|
return {
|
|
1205
1749
|
exitCode: 2,
|
|
1206
1750
|
report: {
|
|
1207
|
-
...common,
|
|
1751
|
+
...attachDoctorChecks(common),
|
|
1208
1752
|
manifest: "invalid",
|
|
1209
1753
|
blockers: [{ path: "kit_version", classification: "invalid-installed-version-state" }],
|
|
1210
1754
|
sourceVersion,
|
|
@@ -1217,7 +1761,7 @@ export function createInstallationManager(options) {
|
|
|
1217
1761
|
if (sourceInvalid) return {
|
|
1218
1762
|
exitCode: 2,
|
|
1219
1763
|
report: {
|
|
1220
|
-
...common,
|
|
1764
|
+
...attachDoctorChecks(common),
|
|
1221
1765
|
manifest: validatedManifest ? "valid" : "absent",
|
|
1222
1766
|
blockers: [{ path: "package.json", classification: "invalid-source-version-state" }],
|
|
1223
1767
|
sourceVersion: null,
|
|
@@ -1229,7 +1773,7 @@ export function createInstallationManager(options) {
|
|
|
1229
1773
|
if (!inspection.manifest) return {
|
|
1230
1774
|
exitCode: 1,
|
|
1231
1775
|
report: {
|
|
1232
|
-
...common,
|
|
1776
|
+
...attachDoctorChecks(common),
|
|
1233
1777
|
manifest: "absent",
|
|
1234
1778
|
sourceVersion,
|
|
1235
1779
|
installedVersion: null,
|
|
@@ -1246,20 +1790,22 @@ export function createInstallationManager(options) {
|
|
|
1246
1790
|
|| plan.blockers.length > 0
|
|
1247
1791
|
|| plan.warnings.some((warning) => actionableWarnings.has(warning.classification))
|
|
1248
1792
|
|| activeTransaction || activeLock || residue.length > 0;
|
|
1793
|
+
const report = {
|
|
1794
|
+
...attachDoctorChecks({}, { inspection, plan }),
|
|
1795
|
+
manifest: "valid",
|
|
1796
|
+
blockers: plan.blockers,
|
|
1797
|
+
warnings: plan.warnings,
|
|
1798
|
+
activeTransaction: Boolean(activeTransaction),
|
|
1799
|
+
activeLock: activeLock ? classifyExistingLock(activeLock) : null,
|
|
1800
|
+
rollbackAvailable: Boolean(lstatIfExists(path.join(oakPath, "rollback", "transaction.json"), fsOps)),
|
|
1801
|
+
cleanupResidue: residue,
|
|
1802
|
+
sourceVersion,
|
|
1803
|
+
installedVersion,
|
|
1804
|
+
versionState,
|
|
1805
|
+
};
|
|
1249
1806
|
return {
|
|
1250
|
-
exitCode: actionable ? 1 : 0,
|
|
1251
|
-
report
|
|
1252
|
-
manifest: "valid",
|
|
1253
|
-
blockers: plan.blockers,
|
|
1254
|
-
warnings: plan.warnings,
|
|
1255
|
-
activeTransaction: Boolean(activeTransaction),
|
|
1256
|
-
activeLock: activeLock ? classifyExistingLock(activeLock) : null,
|
|
1257
|
-
rollbackAvailable: Boolean(lstatIfExists(path.join(oakPath, "rollback", "transaction.json"), fsOps)),
|
|
1258
|
-
cleanupResidue: residue,
|
|
1259
|
-
sourceVersion,
|
|
1260
|
-
installedVersion,
|
|
1261
|
-
versionState,
|
|
1262
|
-
},
|
|
1807
|
+
exitCode: actionable || report.checks.some((check) => check.status === "action-required") ? 1 : 0,
|
|
1808
|
+
report,
|
|
1263
1809
|
};
|
|
1264
1810
|
}
|
|
1265
1811
|
|
|
@@ -1445,6 +1991,10 @@ export async function main(argv, options = {}) {
|
|
|
1445
1991
|
pidProbe: options.pidProbe,
|
|
1446
1992
|
failpoint: options.failpoint,
|
|
1447
1993
|
fsOps: options.fsOps,
|
|
1994
|
+
repositoryRoot: options.repositoryRoot ?? repositoryRoot,
|
|
1995
|
+
commandRunner: options.commandRunner,
|
|
1996
|
+
nodeVersionProvider: options.nodeVersionProvider,
|
|
1997
|
+
compatibilityProvider: options.compatibilityProvider,
|
|
1448
1998
|
stdin: input,
|
|
1449
1999
|
stdout,
|
|
1450
2000
|
stderr,
|
|
@@ -1470,15 +2020,7 @@ export async function main(argv, options = {}) {
|
|
|
1470
2020
|
else if (result.exitCode === 1 && result.plan?.blockers?.length) {
|
|
1471
2021
|
for (const blocker of result.plan.blockers) stderr.write(`Conflict: ${blocker.path} (${blocker.classification})\n`);
|
|
1472
2022
|
} else if (command === "doctor" && !parsed.acceptPreserved && result.report) {
|
|
1473
|
-
|
|
1474
|
-
"not-installed": "run install --dry-run",
|
|
1475
|
-
current: "none",
|
|
1476
|
-
"upgrade-available": "run upgrade --dry-run",
|
|
1477
|
-
"source-older": "use a source checkout at least as new as the installation",
|
|
1478
|
-
"same-version-different-payload": "fix the release identity mismatch",
|
|
1479
|
-
"invalid-version-state": "repair the invalid version state",
|
|
1480
|
-
};
|
|
1481
|
-
stdout.write(`doctor: ${result.report.versionState}; source=${result.report.sourceVersion ?? "invalid"}; installed=${result.report.installedVersion ?? "none"}; action=${actions[result.report.versionState]}\n`);
|
|
2023
|
+
stdout.write(renderDoctorReport(result.report));
|
|
1482
2024
|
} else if (command !== "doctor" || !parsed.acceptPreserved) {
|
|
1483
2025
|
const changes = result.plan?.entries?.length ?? 0;
|
|
1484
2026
|
stdout.write(`${command}: ${result.exitCode === 0 ? "ok" : "action required"}${result.plan ? ` (${changes} planned changes)` : ""}\n`);
|