@mstar-harness/cli 3.8.1 → 3.8.3
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/dist/mstar-harness.js +270 -183
- package/package.json +1 -1
package/dist/mstar-harness.js
CHANGED
|
@@ -2432,7 +2432,7 @@ var require_picocolors2 = __commonJS(function(exports, module) {
|
|
|
2432
2432
|
// src/index.ts
|
|
2433
2433
|
import { execFileSync as execFileSync10 } from "child_process";
|
|
2434
2434
|
import { createHash, randomUUID as randomUUID3 } from "crypto";
|
|
2435
|
-
import
|
|
2435
|
+
import fs10 from "fs";
|
|
2436
2436
|
import path14 from "path";
|
|
2437
2437
|
// ../../node_modules/.bun/@inquirer+core@12.0.3+72cd8510778f549e/node_modules/@inquirer/core/dist/lib/key.js
|
|
2438
2438
|
var keybindings = ["emacs", "vim"];
|
|
@@ -8216,18 +8216,62 @@ function findEphemeralCitations(skillText) {
|
|
|
8216
8216
|
return citations;
|
|
8217
8217
|
}
|
|
8218
8218
|
var TEST_FILE_PATH_RE = /[\w./-]+\.(?:test|spec)\.[a-z0-9]+/i;
|
|
8219
|
-
var TEST_FILE_PHRASE_RE = /\btest
|
|
8219
|
+
var TEST_FILE_PHRASE_RE = /\btest file(?:s|\(s\))?\s*:[ \t]*(.+)/i;
|
|
8220
8220
|
var COMMAND_PROMPT_RE = /^\s*[$>]\s*\S/;
|
|
8221
8221
|
var RUNNER_RE = /\b(?:bun|pnpm|npm|yarn|npx|bunx)\s+(?:test|run|exec)\b|\b(?:npx|bunx)\s+[\w./-]+\b|\b(?:tsc|vitest|jest|mocha|pytest)\b|\bgo\s+test\b|\bcargo\s+test\b/i;
|
|
8222
8222
|
var OUTPUT_TOKEN_RE = /[\u2713\u2714\u2717\u2718]|\b(?:PASS|FAIL)\b|\b\d+\s+(?:pass(?:es|ed)?|fail(?:s|ed|ing)?|skipped|tests?|ok)\b|\bok\s+\d+\b|\ball\s+ok\b|exit(?:ed)?\s+(?:with\s+)?(?:code\s+)?\d+/i;
|
|
8223
|
+
function hasEvidenceDetail(value) {
|
|
8224
|
+
const detail = value.trim().replace(/^`+|`+$/g, "").trim();
|
|
8225
|
+
return detail.length > 0 && !/^(?:n\/a|none|tbd|todo|tba|unknown|skipped|not[- ]run|\.\.\.|\u2026|<[^>]+>)$/i.test(detail);
|
|
8226
|
+
}
|
|
8223
8227
|
function assertSddTddTriple(reportText) {
|
|
8224
8228
|
const violations = [];
|
|
8225
|
-
const
|
|
8229
|
+
const activeRound = [...reportText.matchAll(/^## Verification round:[ \t]*(.*)$/gm)].at(-1);
|
|
8230
|
+
if (activeRound && !hasEvidenceDetail(activeRound[1])) {
|
|
8231
|
+
return {
|
|
8232
|
+
ok: false,
|
|
8233
|
+
violations: [violation11("medium", "lint.sdd-evidence.invalid-round", "Verification round requires a concrete label.")]
|
|
8234
|
+
};
|
|
8235
|
+
}
|
|
8236
|
+
const activeText = activeRound ? reportText.slice(activeRound.index + activeRound[0].length) : reportText;
|
|
8237
|
+
const lines = activeText.split(/\r?\n/);
|
|
8238
|
+
const fields = new Map;
|
|
8239
|
+
for (const line of lines) {
|
|
8240
|
+
const match = line.match(/^\s*(Verification mode|Changed files|Tests|Reason|Check command|Check result):[ \t]*(.*)$/i);
|
|
8241
|
+
if (match) {
|
|
8242
|
+
const key = match[1].toLowerCase();
|
|
8243
|
+
fields.set(key, [...fields.get(key) ?? [], match[2].trim()]);
|
|
8244
|
+
}
|
|
8245
|
+
}
|
|
8246
|
+
const modes = fields.get("verification mode");
|
|
8247
|
+
if (modes) {
|
|
8248
|
+
if (modes.length !== 1 || modes[0] !== "scoped-check") {
|
|
8249
|
+
return {
|
|
8250
|
+
ok: false,
|
|
8251
|
+
violations: [violation11("medium", "lint.sdd-evidence.invalid-mode", "Use exactly one Verification mode: scoped-check declaration in the active round; unknown or duplicate modes are invalid.")]
|
|
8252
|
+
};
|
|
8253
|
+
}
|
|
8254
|
+
for (const key of ["changed files", "tests", "reason", "check command", "check result"]) {
|
|
8255
|
+
const values = fields.get(key) ?? [];
|
|
8256
|
+
const value = values[0] ?? "";
|
|
8257
|
+
const valid = values.length === 1 && (key === "tests" ? value === "N/A" : hasEvidenceDetail(value));
|
|
8258
|
+
if (!valid) {
|
|
8259
|
+
violations.push(violation11("medium", `lint.sdd-evidence.${key.replaceAll(" ", "-")}`, `scoped-check requires one concrete ${key} field${key === "tests" ? " with value N/A" : ""}; missing, duplicate, or placeholder evidence is invalid.`));
|
|
8260
|
+
}
|
|
8261
|
+
}
|
|
8262
|
+
return { ok: violations.length === 0, violations };
|
|
8263
|
+
}
|
|
8264
|
+
if (lines.some((line) => /^\s*(?:Tests|(?:Covering )?test file(?:s|\(s\))?):\s*`?N\/A`?\s*$/i.test(line))) {
|
|
8265
|
+
return {
|
|
8266
|
+
ok: false,
|
|
8267
|
+
violations: [violation11("medium", "lint.sdd-tdd.missing-tests", "Bare N/A is not test evidence; document/policy checks need an explicit, complete scoped-check declaration.")]
|
|
8268
|
+
};
|
|
8269
|
+
}
|
|
8226
8270
|
let hasTests = false;
|
|
8227
8271
|
let hasCommand = false;
|
|
8228
8272
|
let hasOutput = false;
|
|
8229
8273
|
for (const line of lines) {
|
|
8230
|
-
if (!hasTests && (TEST_FILE_PATH_RE.test(line) ||
|
|
8274
|
+
if (!hasTests && (TEST_FILE_PATH_RE.test(line) || hasEvidenceDetail(line.match(TEST_FILE_PHRASE_RE)?.[1] ?? "")))
|
|
8231
8275
|
hasTests = true;
|
|
8232
8276
|
if (!hasCommand && (COMMAND_PROMPT_RE.test(line) || RUNNER_RE.test(line)))
|
|
8233
8277
|
hasCommand = true;
|
|
@@ -9487,6 +9531,7 @@ function harnessVersionFrom(moduleDir) {
|
|
|
9487
9531
|
function readHarnessVersion() {
|
|
9488
9532
|
return harnessVersionFrom(dirname7(fileURLToPath(import.meta.url)));
|
|
9489
9533
|
}
|
|
9534
|
+
var DSH_LLM_FALLBACKS_VERSION = "0.5.2";
|
|
9490
9535
|
var MSTARC_FILE2 = ".mstarc";
|
|
9491
9536
|
var MSTARC_SECTION2 = "config";
|
|
9492
9537
|
var MSTARC_HARNESS_DIR_KEY2 = "harness_dir";
|
|
@@ -11821,9 +11866,10 @@ var CODEX_PROJECT_COMMAND_NAMES = [
|
|
|
11821
11866
|
"iteration-drive",
|
|
11822
11867
|
"iteration-loop",
|
|
11823
11868
|
"codebase-audit",
|
|
11824
|
-
"amazing-pr-review"
|
|
11869
|
+
"amazing-pr-review",
|
|
11870
|
+
"amazing-e2e-check"
|
|
11825
11871
|
];
|
|
11826
|
-
var GLOBAL_ITERATION_SKILLS_WARNING = "Codex project-scoped commands (iteration-start / iteration-drive / iteration-loop / codebase-audit / amazing-pr-review) are installed as project-local skills under .agents/skills/ only. Global install skips them to avoid polluting other code agents. Re-run with --scope project to enable.";
|
|
11872
|
+
var GLOBAL_ITERATION_SKILLS_WARNING = "Codex project-scoped commands (iteration-start / iteration-drive / iteration-loop / codebase-audit / amazing-pr-review / amazing-e2e-check) are installed as project-local skills under .agents/skills/ only. Global install skips them to avoid polluting other code agents. Re-run with --scope project to enable.";
|
|
11827
11873
|
function runCodex(args, dryRun, timeoutMs) {
|
|
11828
11874
|
return runCliCommand([CODEX_BIN, ...args], { dryRun, timeoutMs, env: process.env });
|
|
11829
11875
|
}
|
|
@@ -11930,7 +11976,7 @@ function ensureIterationSkillLinks(dryRun) {
|
|
|
11930
11976
|
}
|
|
11931
11977
|
const gitignoreEntries = CODEX_PROJECT_COMMAND_NAMES.map(iterationSkillGitignoreEntry);
|
|
11932
11978
|
notes.push(...appendGitignore(projectRoot, gitignoreEntries, dryRun));
|
|
11933
|
-
notes.push("Installed Codex project-scoped command skills under .agents/skills/ (iteration-start, iteration-drive, iteration-loop, codebase-audit, amazing-pr-review) \u2014 symlinked to harness commands/*.md.");
|
|
11979
|
+
notes.push("Installed Codex project-scoped command skills under .agents/skills/ (iteration-start, iteration-drive, iteration-loop, codebase-audit, amazing-pr-review, amazing-e2e-check) \u2014 symlinked to harness commands/*.md.");
|
|
11934
11980
|
return notes;
|
|
11935
11981
|
}
|
|
11936
11982
|
function validateIterationSkillLinks() {
|
|
@@ -12121,7 +12167,67 @@ var cursorAdapter = {
|
|
|
12121
12167
|
};
|
|
12122
12168
|
|
|
12123
12169
|
// src/adapters/dsh.ts
|
|
12170
|
+
import fs5 from "node:fs";
|
|
12124
12171
|
import os4 from "node:os";
|
|
12172
|
+
|
|
12173
|
+
// src/version-compare.ts
|
|
12174
|
+
function splitVersion(v) {
|
|
12175
|
+
const dash = v.indexOf("-");
|
|
12176
|
+
if (dash === -1)
|
|
12177
|
+
return [v, undefined];
|
|
12178
|
+
return [v.slice(0, dash), v.slice(dash + 1)];
|
|
12179
|
+
}
|
|
12180
|
+
function compareCore(a, b) {
|
|
12181
|
+
const pa = a.split(".").map((n) => parseInt(n, 10) || 0);
|
|
12182
|
+
const pb = b.split(".").map((n) => parseInt(n, 10) || 0);
|
|
12183
|
+
for (let i = 0;i < 3; i++) {
|
|
12184
|
+
const d = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
12185
|
+
if (d !== 0)
|
|
12186
|
+
return d;
|
|
12187
|
+
}
|
|
12188
|
+
return 0;
|
|
12189
|
+
}
|
|
12190
|
+
function comparePrerelease(a, b) {
|
|
12191
|
+
if (a === undefined && b === undefined)
|
|
12192
|
+
return 0;
|
|
12193
|
+
if (a === undefined)
|
|
12194
|
+
return 1;
|
|
12195
|
+
if (b === undefined)
|
|
12196
|
+
return -1;
|
|
12197
|
+
const ia = a.split(".");
|
|
12198
|
+
const ib = b.split(".");
|
|
12199
|
+
const n = Math.min(ia.length, ib.length);
|
|
12200
|
+
for (let i = 0;i < n; i++) {
|
|
12201
|
+
const d = compareIdentifier(ia[i], ib[i]);
|
|
12202
|
+
if (d !== 0)
|
|
12203
|
+
return d;
|
|
12204
|
+
}
|
|
12205
|
+
return ia.length - ib.length;
|
|
12206
|
+
}
|
|
12207
|
+
function compareIdentifier(a, b) {
|
|
12208
|
+
const aNum = /^\d+$/.test(a);
|
|
12209
|
+
const bNum = /^\d+$/.test(b);
|
|
12210
|
+
if (aNum && bNum) {
|
|
12211
|
+
const na = BigInt(a);
|
|
12212
|
+
const nb = BigInt(b);
|
|
12213
|
+
return na < nb ? -1 : na > nb ? 1 : 0;
|
|
12214
|
+
}
|
|
12215
|
+
if (aNum)
|
|
12216
|
+
return -1;
|
|
12217
|
+
if (bNum)
|
|
12218
|
+
return 1;
|
|
12219
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
12220
|
+
}
|
|
12221
|
+
function compareSemver(a, b) {
|
|
12222
|
+
const [coreA, preA] = splitVersion(a);
|
|
12223
|
+
const [coreB, preB] = splitVersion(b);
|
|
12224
|
+
const coreDiff = compareCore(coreA, coreB);
|
|
12225
|
+
if (coreDiff !== 0)
|
|
12226
|
+
return coreDiff;
|
|
12227
|
+
return comparePrerelease(preA, preB);
|
|
12228
|
+
}
|
|
12229
|
+
|
|
12230
|
+
// src/adapters/dsh.ts
|
|
12125
12231
|
import path7 from "node:path";
|
|
12126
12232
|
var DSH_BIN = "dsh";
|
|
12127
12233
|
var DSH_PROFILE = "web";
|
|
@@ -12140,13 +12246,35 @@ function addTimeoutMs() {
|
|
|
12140
12246
|
const parsed = Number(raw);
|
|
12141
12247
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : DSH_ADD_TIMEOUT_MS;
|
|
12142
12248
|
}
|
|
12143
|
-
var
|
|
12144
|
-
var DSH_PLUGIN_SPECS = ["@mstar-harness/dsh", `dsh-llm-fallbacks@${DSH_FALLBACKS_VERSION}`];
|
|
12249
|
+
var DSH_PLUGIN_SPECS = ["@mstar-harness/dsh", `dsh-llm-fallbacks@${DSH_LLM_FALLBACKS_VERSION}`];
|
|
12145
12250
|
var DSH_FALLBACKS_SPEC = DSH_PLUGIN_SPECS[1];
|
|
12146
12251
|
function dshLoaderName(spec) {
|
|
12147
12252
|
const at = spec.lastIndexOf("@");
|
|
12148
12253
|
return at > 0 ? spec.slice(0, at) : spec;
|
|
12149
12254
|
}
|
|
12255
|
+
var DSH_FALLBACKS_LOADER_NAME = dshLoaderName(DSH_FALLBACKS_SPEC);
|
|
12256
|
+
var FALLBACKS_VERSION_SHAPE_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
12257
|
+
function readInstalledFallbacksVersion(profileDir) {
|
|
12258
|
+
const pkgJson = path7.join(profileDir, "node_modules", DSH_FALLBACKS_LOADER_NAME, "package.json");
|
|
12259
|
+
try {
|
|
12260
|
+
const raw = fs5.readFileSync(pkgJson, "utf8");
|
|
12261
|
+
const version = JSON.parse(raw).version;
|
|
12262
|
+
if (typeof version === "string") {
|
|
12263
|
+
const trimmed = version.trim();
|
|
12264
|
+
if (FALLBACKS_VERSION_SHAPE_RE.test(trimmed))
|
|
12265
|
+
return trimmed;
|
|
12266
|
+
}
|
|
12267
|
+
} catch {}
|
|
12268
|
+
return null;
|
|
12269
|
+
}
|
|
12270
|
+
function fallbacksVersionDrifted(profileDir) {
|
|
12271
|
+
if (!FALLBACKS_VERSION_SHAPE_RE.test(DSH_LLM_FALLBACKS_VERSION))
|
|
12272
|
+
return false;
|
|
12273
|
+
const installedVersion = readInstalledFallbacksVersion(profileDir);
|
|
12274
|
+
if (installedVersion === null)
|
|
12275
|
+
return true;
|
|
12276
|
+
return compareSemver(installedVersion, DSH_LLM_FALLBACKS_VERSION) !== 0;
|
|
12277
|
+
}
|
|
12150
12278
|
var DSH_INSTALL_HINT = "Install the DeepSeek Harness CLI (@deepseek-ai/dsh), e.g. `pnpm add -g @deepseek-ai/dsh` or `npm install -g @deepseek-ai/dsh`, then re-run init.";
|
|
12151
12279
|
function runDsh(args, dryRun, timeoutMs) {
|
|
12152
12280
|
return runCliCommand([DSH_BIN, ...args], { dryRun, timeoutMs, env: process.env });
|
|
@@ -12204,14 +12332,18 @@ function runInit2(scope, dryRun, initFlags) {
|
|
|
12204
12332
|
throw new Error(`${DSH_BIN} CLI not found on PATH. ${DSH_INSTALL_HINT}`);
|
|
12205
12333
|
}
|
|
12206
12334
|
const installed = new Set;
|
|
12335
|
+
const disabledLoaderNames = new Set;
|
|
12207
12336
|
if (!dryRun) {
|
|
12208
12337
|
try {
|
|
12209
12338
|
const entries = parseLoaderEntries(runDsh([DSH_PROFILE_FLAG, DSH_PROFILE, DSH_DUMP_FLAG], dryRun, DSH_LOCAL_TIMEOUT_MS));
|
|
12210
12339
|
if (entries === null) {
|
|
12211
12340
|
notes.push("Warning: could not parse installed plugins from dump (unexpected format); proceeding with add (idempotent).");
|
|
12212
12341
|
} else {
|
|
12213
|
-
for (const entry of entries)
|
|
12342
|
+
for (const entry of entries) {
|
|
12214
12343
|
installed.add(entry.name);
|
|
12344
|
+
if (!entry.enabled)
|
|
12345
|
+
disabledLoaderNames.add(entry.name);
|
|
12346
|
+
}
|
|
12215
12347
|
}
|
|
12216
12348
|
} catch (error) {
|
|
12217
12349
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -12224,8 +12356,13 @@ function runInit2(scope, dryRun, initFlags) {
|
|
|
12224
12356
|
continue;
|
|
12225
12357
|
}
|
|
12226
12358
|
if (!dryRun && (installed.has(spec) || installed.has(dshLoaderName(spec)))) {
|
|
12227
|
-
|
|
12228
|
-
|
|
12359
|
+
const isFallbacks = spec === DSH_FALLBACKS_SPEC;
|
|
12360
|
+
const disabledRow = disabledLoaderNames.has(spec) || disabledLoaderNames.has(dshLoaderName(spec));
|
|
12361
|
+
const needsVersionAlign = isFallbacks && fallbacksVersionDrifted(profileDir) && !disabledRow;
|
|
12362
|
+
if (!needsVersionAlign) {
|
|
12363
|
+
notes.push(`skipped-existing: ${spec} (already installed in profile ${DSH_PROFILE})`);
|
|
12364
|
+
continue;
|
|
12365
|
+
}
|
|
12229
12366
|
}
|
|
12230
12367
|
const addArgs = ["plugin", DSH_PROFILE_FLAG, DSH_PROFILE, "add", spec];
|
|
12231
12368
|
if (dryRun) {
|
|
@@ -12269,7 +12406,14 @@ function runDoctor2(scope) {
|
|
|
12269
12406
|
const byName = new Map(entries.map((entry) => [entry.name, entry]));
|
|
12270
12407
|
for (const spec of DSH_PLUGIN_SPECS) {
|
|
12271
12408
|
const entry = byName.get(spec) ?? byName.get(dshLoaderName(spec));
|
|
12272
|
-
|
|
12409
|
+
let state = !entry ? "uninstalled" : entry.enabled ? "mounted" : "disabled";
|
|
12410
|
+
if (spec === DSH_FALLBACKS_SPEC && state === "mounted" && fallbacksVersionDrifted(profileDir)) {
|
|
12411
|
+
const installedVersion = readInstalledFallbacksVersion(profileDir);
|
|
12412
|
+
const installedLabel = installedVersion ?? "unknown";
|
|
12413
|
+
notes.push(`${spec}: drifted (installed ${installedLabel}, pinned ${DSH_LLM_FALLBACKS_VERSION})`);
|
|
12414
|
+
errors2.push(`${spec} is drifted (profile has ${installedLabel}, harness pins ${DSH_LLM_FALLBACKS_VERSION}). Run: mstar-harness init --target dsh`);
|
|
12415
|
+
continue;
|
|
12416
|
+
}
|
|
12273
12417
|
notes.push(`${spec}: ${state}`);
|
|
12274
12418
|
if (state === "mounted")
|
|
12275
12419
|
continue;
|
|
@@ -12289,65 +12433,8 @@ var dshAdapter = {
|
|
|
12289
12433
|
import os5 from "node:os";
|
|
12290
12434
|
import path9 from "node:path";
|
|
12291
12435
|
|
|
12292
|
-
// src/version-compare.ts
|
|
12293
|
-
function splitVersion(v) {
|
|
12294
|
-
const dash = v.indexOf("-");
|
|
12295
|
-
if (dash === -1)
|
|
12296
|
-
return [v, undefined];
|
|
12297
|
-
return [v.slice(0, dash), v.slice(dash + 1)];
|
|
12298
|
-
}
|
|
12299
|
-
function compareCore(a, b) {
|
|
12300
|
-
const pa = a.split(".").map((n) => parseInt(n, 10) || 0);
|
|
12301
|
-
const pb = b.split(".").map((n) => parseInt(n, 10) || 0);
|
|
12302
|
-
for (let i = 0;i < 3; i++) {
|
|
12303
|
-
const d = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
12304
|
-
if (d !== 0)
|
|
12305
|
-
return d;
|
|
12306
|
-
}
|
|
12307
|
-
return 0;
|
|
12308
|
-
}
|
|
12309
|
-
function comparePrerelease(a, b) {
|
|
12310
|
-
if (a === undefined && b === undefined)
|
|
12311
|
-
return 0;
|
|
12312
|
-
if (a === undefined)
|
|
12313
|
-
return 1;
|
|
12314
|
-
if (b === undefined)
|
|
12315
|
-
return -1;
|
|
12316
|
-
const ia = a.split(".");
|
|
12317
|
-
const ib = b.split(".");
|
|
12318
|
-
const n = Math.min(ia.length, ib.length);
|
|
12319
|
-
for (let i = 0;i < n; i++) {
|
|
12320
|
-
const d = compareIdentifier(ia[i], ib[i]);
|
|
12321
|
-
if (d !== 0)
|
|
12322
|
-
return d;
|
|
12323
|
-
}
|
|
12324
|
-
return ia.length - ib.length;
|
|
12325
|
-
}
|
|
12326
|
-
function compareIdentifier(a, b) {
|
|
12327
|
-
const aNum = /^\d+$/.test(a);
|
|
12328
|
-
const bNum = /^\d+$/.test(b);
|
|
12329
|
-
if (aNum && bNum) {
|
|
12330
|
-
const na = BigInt(a);
|
|
12331
|
-
const nb = BigInt(b);
|
|
12332
|
-
return na < nb ? -1 : na > nb ? 1 : 0;
|
|
12333
|
-
}
|
|
12334
|
-
if (aNum)
|
|
12335
|
-
return -1;
|
|
12336
|
-
if (bNum)
|
|
12337
|
-
return 1;
|
|
12338
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
12339
|
-
}
|
|
12340
|
-
function compareSemver(a, b) {
|
|
12341
|
-
const [coreA, preA] = splitVersion(a);
|
|
12342
|
-
const [coreB, preB] = splitVersion(b);
|
|
12343
|
-
const coreDiff = compareCore(coreA, coreB);
|
|
12344
|
-
if (coreDiff !== 0)
|
|
12345
|
-
return coreDiff;
|
|
12346
|
-
return comparePrerelease(preA, preB);
|
|
12347
|
-
}
|
|
12348
|
-
|
|
12349
12436
|
// src/adapters/omp.ts
|
|
12350
|
-
import
|
|
12437
|
+
import fs6 from "node:fs";
|
|
12351
12438
|
import path8 from "node:path";
|
|
12352
12439
|
import { execFileSync as execFileSync8 } from "node:child_process";
|
|
12353
12440
|
var OMP_PACKAGE_REL = path8.join("packages", "omp");
|
|
@@ -12420,28 +12507,28 @@ function findInstalledPlugin(plugins) {
|
|
|
12420
12507
|
function validatePluginTree(pluginRoot) {
|
|
12421
12508
|
const errors2 = [];
|
|
12422
12509
|
const markerPath = path8.join(pluginRoot, "plugin.json");
|
|
12423
|
-
if (!
|
|
12510
|
+
if (!fs6.existsSync(markerPath)) {
|
|
12424
12511
|
errors2.push(`Missing omp plugin marker: ${markerPath}`);
|
|
12425
12512
|
}
|
|
12426
12513
|
for (const skill of SKILL_SMOKE) {
|
|
12427
12514
|
const skillPath = path8.join(pluginRoot, "skills", skill, "SKILL.md");
|
|
12428
|
-
if (!
|
|
12515
|
+
if (!fs6.existsSync(skillPath))
|
|
12429
12516
|
errors2.push(`Missing skill: ${skillPath}`);
|
|
12430
12517
|
}
|
|
12431
12518
|
for (const command of COMMAND_SMOKE) {
|
|
12432
12519
|
const commandPath = path8.join(pluginRoot, "commands", `${command}.md`);
|
|
12433
|
-
if (!
|
|
12520
|
+
if (!fs6.existsSync(commandPath))
|
|
12434
12521
|
errors2.push(`Missing command: ${commandPath}`);
|
|
12435
12522
|
}
|
|
12436
12523
|
const hostRef = path8.join(pluginRoot, "skills", "mstar-host", "references", "omp.md");
|
|
12437
|
-
if (!
|
|
12524
|
+
if (!fs6.existsSync(hostRef))
|
|
12438
12525
|
errors2.push(`Missing omp host reference: ${hostRef}`);
|
|
12439
12526
|
return errors2;
|
|
12440
12527
|
}
|
|
12441
12528
|
function runInit3(scope, dryRun) {
|
|
12442
12529
|
const notes = ensureLocalHarnessRepo(dryRun);
|
|
12443
12530
|
const projectRoot = resolveProjectRoot2();
|
|
12444
|
-
if (
|
|
12531
|
+
if (fs6.existsSync(path8.join(HARNESS_REPO_PATH, ".git"))) {
|
|
12445
12532
|
if (dryRun) {
|
|
12446
12533
|
notes.push(`Would update local harness repo: git -C ${HARNESS_REPO_PATH} pull --ff-only`);
|
|
12447
12534
|
} else {
|
|
@@ -12461,7 +12548,7 @@ function runInit3(scope, dryRun) {
|
|
|
12461
12548
|
notes.push("omp CLI not found on PATH. Install Oh My Pi (`omp`), then re-run init or manually: omp plugin install @mstar-harness/omp");
|
|
12462
12549
|
} else {
|
|
12463
12550
|
const ompPackagePath = path8.join(HARNESS_REPO_PATH, OMP_PACKAGE_REL);
|
|
12464
|
-
if (!dryRun && !
|
|
12551
|
+
if (!dryRun && !fs6.existsSync(path8.join(ompPackagePath, "plugin.json"))) {
|
|
12465
12552
|
try {
|
|
12466
12553
|
runCliCommand(["bun", "install"], { cwd: HARNESS_REPO_PATH, dryRun });
|
|
12467
12554
|
runCliCommand(["bun", "run", "engine:build"], { cwd: HARNESS_REPO_PATH, dryRun });
|
|
@@ -12552,7 +12639,7 @@ function runDoctor3(scope) {
|
|
|
12552
12639
|
if (scope === "project") {
|
|
12553
12640
|
const projectRoot = resolveProjectRoot2();
|
|
12554
12641
|
const gitignorePath = path8.join(projectRoot, ".gitignore");
|
|
12555
|
-
const gitignore =
|
|
12642
|
+
const gitignore = fs6.existsSync(gitignorePath) ? fs6.readFileSync(gitignorePath, "utf8") : "";
|
|
12556
12643
|
for (const entry of missingHarnessProcessGitignoreEntries(gitignore)) {
|
|
12557
12644
|
errors2.push(`Missing .gitignore entry: ${entry}`);
|
|
12558
12645
|
}
|
|
@@ -12729,7 +12816,7 @@ var opencodeAdapter = {
|
|
|
12729
12816
|
};
|
|
12730
12817
|
|
|
12731
12818
|
// src/adapters/zcode.ts
|
|
12732
|
-
import
|
|
12819
|
+
import fs7 from "node:fs";
|
|
12733
12820
|
import os7 from "node:os";
|
|
12734
12821
|
import path11 from "node:path";
|
|
12735
12822
|
var MARKETPLACE_ID = "mstar-local";
|
|
@@ -12805,7 +12892,7 @@ function findMarketplacePlugin(raw) {
|
|
|
12805
12892
|
}
|
|
12806
12893
|
function validateMarketplaceJson() {
|
|
12807
12894
|
const errors2 = [];
|
|
12808
|
-
if (!
|
|
12895
|
+
if (!fs7.existsSync(MARKETPLACE_JSON_PATH)) {
|
|
12809
12896
|
errors2.push(`Missing ZCode marketplace: ${MARKETPLACE_JSON_PATH}`);
|
|
12810
12897
|
return errors2;
|
|
12811
12898
|
}
|
|
@@ -12830,7 +12917,7 @@ function validateMarketplaceJson() {
|
|
|
12830
12917
|
}
|
|
12831
12918
|
function validateKnownMarketplaces() {
|
|
12832
12919
|
const errors2 = [];
|
|
12833
|
-
if (!
|
|
12920
|
+
if (!fs7.existsSync(KNOWN_MARKETPLACES_PATH)) {
|
|
12834
12921
|
errors2.push(`Missing ZCode known_marketplaces.json: ${KNOWN_MARKETPLACES_PATH}`);
|
|
12835
12922
|
return errors2;
|
|
12836
12923
|
}
|
|
@@ -12854,13 +12941,13 @@ function validateKnownMarketplaces() {
|
|
|
12854
12941
|
function validatePluginAgents2(pluginRoot) {
|
|
12855
12942
|
const errors2 = [];
|
|
12856
12943
|
const agentsDir = path11.join(pluginRoot, "agents");
|
|
12857
|
-
if (!
|
|
12944
|
+
if (!fs7.existsSync(agentsDir)) {
|
|
12858
12945
|
errors2.push(`Missing plugin agents directory: ${agentsDir}`);
|
|
12859
12946
|
return errors2;
|
|
12860
12947
|
}
|
|
12861
12948
|
for (const agentName of ZCODE_AGENT_SMOKE_NAMES) {
|
|
12862
12949
|
const agentPath = path11.join(agentsDir, `${agentName}.md`);
|
|
12863
|
-
if (!
|
|
12950
|
+
if (!fs7.existsSync(agentPath)) {
|
|
12864
12951
|
errors2.push(`Missing plugin agent file: ${agentPath}`);
|
|
12865
12952
|
}
|
|
12866
12953
|
}
|
|
@@ -12884,8 +12971,8 @@ function runInit5(scope, dryRun) {
|
|
|
12884
12971
|
notes.push(`Materialized local ZCode plugin checkout at ${ZCODE_PLUGIN_CHECKOUT_PROJECT} for smoke checks (the registered marketplace still points at the github repo).`);
|
|
12885
12972
|
}
|
|
12886
12973
|
if (!dryRun) {
|
|
12887
|
-
if (!
|
|
12888
|
-
|
|
12974
|
+
if (!fs7.existsSync(MARKETPLACE_DIR))
|
|
12975
|
+
fs7.mkdirSync(MARKETPLACE_DIR, { recursive: true });
|
|
12889
12976
|
writeJson2(MARKETPLACE_JSON_PATH, buildMarketplaceJson());
|
|
12890
12977
|
}
|
|
12891
12978
|
notes.push(`Wrote ZCode marketplace: ${MARKETPLACE_JSON_PATH}`);
|
|
@@ -12908,7 +12995,7 @@ function runDoctor5(scope) {
|
|
|
12908
12995
|
const checkoutPath = path11.join(projectRoot, ZCODE_PLUGIN_CHECKOUT_PROJECT);
|
|
12909
12996
|
errors2.push(...validateGitCheckout(checkoutPath, ZCODE_PLUGIN_MARKER));
|
|
12910
12997
|
const gitignorePath = path11.join(projectRoot, ".gitignore");
|
|
12911
|
-
const gitignore =
|
|
12998
|
+
const gitignore = fs7.existsSync(gitignorePath) ? fs7.readFileSync(gitignorePath, "utf8") : "";
|
|
12912
12999
|
if (!gitignore.split(/\r?\n/).includes(ZCODE_PLUGIN_CHECKOUT_PROJECT)) {
|
|
12913
13000
|
errors2.push(`Missing .gitignore entry: ${ZCODE_PLUGIN_CHECKOUT_PROJECT}`);
|
|
12914
13001
|
}
|
|
@@ -13010,7 +13097,7 @@ function formatCliDoctorNote(detected, expected) {
|
|
|
13010
13097
|
}
|
|
13011
13098
|
|
|
13012
13099
|
// src/plugin-version-alignment.ts
|
|
13013
|
-
import
|
|
13100
|
+
import fs8 from "node:fs";
|
|
13014
13101
|
import os8 from "node:os";
|
|
13015
13102
|
import path12 from "node:path";
|
|
13016
13103
|
var PLUGIN_VERSION_SHAPE_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
@@ -13024,7 +13111,7 @@ function highestVersion(current, candidate) {
|
|
|
13024
13111
|
function versionFromJsonFile(filePath) {
|
|
13025
13112
|
let raw;
|
|
13026
13113
|
try {
|
|
13027
|
-
raw =
|
|
13114
|
+
raw = fs8.readFileSync(filePath, "utf8");
|
|
13028
13115
|
} catch {
|
|
13029
13116
|
return null;
|
|
13030
13117
|
}
|
|
@@ -13049,7 +13136,7 @@ function defaultOpencodePackagesRoot() {
|
|
|
13049
13136
|
function detectOpencodePluginVersion(packagesRoot = defaultOpencodePackagesRoot()) {
|
|
13050
13137
|
let specs;
|
|
13051
13138
|
try {
|
|
13052
|
-
specs =
|
|
13139
|
+
specs = fs8.readdirSync(path12.join(packagesRoot, "@mstar-harness"), { withFileTypes: true });
|
|
13053
13140
|
} catch {
|
|
13054
13141
|
return null;
|
|
13055
13142
|
}
|
|
@@ -13082,7 +13169,7 @@ function readZcodeManifestVersion(versionDir) {
|
|
|
13082
13169
|
function detectZcodePluginVersion(cacheRoot = ZCODE_PLUGINS_CACHE_ROOT2) {
|
|
13083
13170
|
let marketplaceEntries;
|
|
13084
13171
|
try {
|
|
13085
|
-
marketplaceEntries =
|
|
13172
|
+
marketplaceEntries = fs8.readdirSync(cacheRoot, { withFileTypes: true });
|
|
13086
13173
|
} catch {
|
|
13087
13174
|
return null;
|
|
13088
13175
|
}
|
|
@@ -13093,7 +13180,7 @@ function detectZcodePluginVersion(cacheRoot = ZCODE_PLUGINS_CACHE_ROOT2) {
|
|
|
13093
13180
|
const pluginRoot = path12.join(cacheRoot, marketplace.name, PLUGIN_NAME);
|
|
13094
13181
|
let versionEntries;
|
|
13095
13182
|
try {
|
|
13096
|
-
versionEntries =
|
|
13183
|
+
versionEntries = fs8.readdirSync(pluginRoot, { withFileTypes: true });
|
|
13097
13184
|
} catch {
|
|
13098
13185
|
continue;
|
|
13099
13186
|
}
|
|
@@ -13129,7 +13216,7 @@ function listDirsToDepth(root, maxDepth) {
|
|
|
13129
13216
|
const visit = (dir, depth) => {
|
|
13130
13217
|
let entries;
|
|
13131
13218
|
try {
|
|
13132
|
-
entries =
|
|
13219
|
+
entries = fs8.readdirSync(dir, { withFileTypes: true });
|
|
13133
13220
|
} catch {
|
|
13134
13221
|
return;
|
|
13135
13222
|
}
|
|
@@ -13242,7 +13329,7 @@ function formatPluginVersionDoctorNote(target, cliVersion, installed) {
|
|
|
13242
13329
|
var SUPPORTED_TARGETS = ["opencode", "cursor", "codex", "zcode", "omp", "dsh", "kimi"];
|
|
13243
13330
|
|
|
13244
13331
|
// src/utils.ts
|
|
13245
|
-
import
|
|
13332
|
+
import fs9 from "node:fs";
|
|
13246
13333
|
import path13 from "node:path";
|
|
13247
13334
|
function parseCsv(raw) {
|
|
13248
13335
|
if (!raw)
|
|
@@ -13268,7 +13355,7 @@ function findUpPackageRoot(startDir, predicate) {
|
|
|
13268
13355
|
let dir = path13.resolve(startDir);
|
|
13269
13356
|
for (;; ) {
|
|
13270
13357
|
try {
|
|
13271
|
-
const manifest = JSON.parse(
|
|
13358
|
+
const manifest = JSON.parse(fs9.readFileSync(joinWithinRoot(dir, "package.json"), "utf8"));
|
|
13272
13359
|
if (predicate(manifest))
|
|
13273
13360
|
return dir;
|
|
13274
13361
|
} catch {}
|
|
@@ -13451,7 +13538,7 @@ function resolvePluginRoot(options) {
|
|
|
13451
13538
|
if (options.root)
|
|
13452
13539
|
return path14.resolve(options.root);
|
|
13453
13540
|
let candidate = resolveProjectRoot3();
|
|
13454
|
-
while (!
|
|
13541
|
+
while (!fs10.existsSync(path14.join(candidate, "plugin.json"))) {
|
|
13455
13542
|
const parent = path14.dirname(candidate);
|
|
13456
13543
|
if (parent === candidate)
|
|
13457
13544
|
break;
|
|
@@ -13521,7 +13608,7 @@ function runScaffold(pathArg) {
|
|
|
13521
13608
|
if (harnessKind === "mstar" && path14.resolve(harnessDir) === mstarDirAtWorkspaceRoot) {
|
|
13522
13609
|
const gitignorePath = workspaceRoot.endsWith(path14.sep) ? `${workspaceRoot}.gitignore` : `${workspaceRoot}${path14.sep}.gitignore`;
|
|
13523
13610
|
const snippet = emitGitignoreSnippet("mstar");
|
|
13524
|
-
const current =
|
|
13611
|
+
const current = fs10.existsSync(gitignorePath) ? fs10.readFileSync(gitignorePath, "utf8") : "";
|
|
13525
13612
|
const lines = new Set(current.split(/\r?\n/).map((line) => line.trim()));
|
|
13526
13613
|
const snippetLines = snippet.split(`
|
|
13527
13614
|
`).map((line) => line.trim());
|
|
@@ -13543,18 +13630,18 @@ function runScaffold(pathArg) {
|
|
|
13543
13630
|
`) ? "" : `
|
|
13544
13631
|
`}.mstarc
|
|
13545
13632
|
`;
|
|
13546
|
-
|
|
13633
|
+
fs10.writeFileSync(gitignorePath, next, "utf8");
|
|
13547
13634
|
} else {
|
|
13548
13635
|
const prefix = current && !current.endsWith(`
|
|
13549
13636
|
`) ? `
|
|
13550
13637
|
` : "";
|
|
13551
|
-
|
|
13638
|
+
fs10.appendFileSync(gitignorePath, `${prefix}${[...missingComments, ...missing].join(`
|
|
13552
13639
|
`)}
|
|
13553
13640
|
`, "utf8");
|
|
13554
13641
|
}
|
|
13555
13642
|
created.push(".gitignore (canonical harness snippet)");
|
|
13556
13643
|
}
|
|
13557
|
-
const finalLines =
|
|
13644
|
+
const finalLines = fs10.readFileSync(gitignorePath, "utf8").split(/\r?\n/);
|
|
13558
13645
|
const broadIndexes = finalLines.map((line, index) => line.trim() === ".mstar/**" ? index : -1).filter((index) => index !== -1);
|
|
13559
13646
|
const canonicalNegationIndexes = finalLines.map((line, index) => CANONICAL_NEGATIONS[line.trim()] === true ? index : -1).filter((index) => index !== -1);
|
|
13560
13647
|
const firstCanonicalNegationIndex = canonicalNegationIndexes[0] ?? -1;
|
|
@@ -13716,7 +13803,7 @@ function runScaffold(pathArg) {
|
|
|
13716
13803
|
finalLines.push("");
|
|
13717
13804
|
}
|
|
13718
13805
|
if (normalized) {
|
|
13719
|
-
|
|
13806
|
+
fs10.writeFileSync(gitignorePath, finalLines.join(`
|
|
13720
13807
|
`), "utf8");
|
|
13721
13808
|
created.push(".gitignore (canonical harness snippet reordered)");
|
|
13722
13809
|
} else if (missing.length === 0) {
|
|
@@ -13727,8 +13814,8 @@ function runScaffold(pathArg) {
|
|
|
13727
13814
|
}
|
|
13728
13815
|
const agentsPath = path14.join(harnessDir, "AGENTS.md");
|
|
13729
13816
|
const agentsLabel = `${path14.basename(harnessDir)}/AGENTS.md`;
|
|
13730
|
-
if (!
|
|
13731
|
-
|
|
13817
|
+
if (!fs10.existsSync(agentsPath)) {
|
|
13818
|
+
fs10.writeFileSync(agentsPath, HARNESS_AGENTS_TEMPLATE, "utf8");
|
|
13732
13819
|
created.push(agentsLabel);
|
|
13733
13820
|
} else {
|
|
13734
13821
|
skipped.push(`${agentsLabel} (already present)`);
|
|
@@ -13802,7 +13889,7 @@ statusCommand.command("validate").description("Validate a v2 status.json root or
|
|
|
13802
13889
|
let statusPath;
|
|
13803
13890
|
try {
|
|
13804
13891
|
statusPath = resolveStatusFilePath(pathArg);
|
|
13805
|
-
if (!
|
|
13892
|
+
if (!fs10.existsSync(statusPath)) {
|
|
13806
13893
|
throw new Error(`status file not found: ${statusPath}`);
|
|
13807
13894
|
}
|
|
13808
13895
|
const gate2 = path14.basename(statusPath) === WORKFLOW_SNAPSHOT_FILE ? validateWorkflowSnapshot(readJson2(statusPath)) : validateStatus(statusPath);
|
|
@@ -13826,7 +13913,7 @@ statusCommand.command("validate").description("Validate a v2 status.json root or
|
|
|
13826
13913
|
statusCommand.command("tech-debt").description("Print the residual tech-debt rollup aggregated over every {PROJECT_DIR}/<id>/residuals.json register " + "(total_open / by_severity / by_target / by_plan; the project register is the source of truth \u2014 " + "no stored-summary drift check, informational exit 0)").argument("[path]", "Project dir (default: resolved {PROJECT_DIR})").action((pathArg) => {
|
|
13827
13914
|
try {
|
|
13828
13915
|
const projectDir = pathArg ? path14.resolve(pathArg) : resolveProjectDir();
|
|
13829
|
-
if (!
|
|
13916
|
+
if (!fs10.existsSync(projectDir)) {
|
|
13830
13917
|
throw new Error(`project dir not found: ${projectDir}`);
|
|
13831
13918
|
}
|
|
13832
13919
|
const rollup = techDebtRollup(projectDir);
|
|
@@ -13845,7 +13932,7 @@ statusCommand.command("findings-cleanup").description("Enforce a plan's findings
|
|
|
13845
13932
|
try {
|
|
13846
13933
|
const projectDir = resolveProjectDir(process.cwd(), options.harness ? { harnessDir: options.harness } : {});
|
|
13847
13934
|
const registerPath = path14.join(projectDir, options.project ?? _DEFAULT_PROJECT, PROJECT_REGISTER_FILE);
|
|
13848
|
-
if (!
|
|
13935
|
+
if (!fs10.existsSync(registerPath)) {
|
|
13849
13936
|
throw new Error(`project register not found: ${registerPath}`);
|
|
13850
13937
|
}
|
|
13851
13938
|
const mode = options.mode === "zero-residual" || options.mode === "allow-residual" ? options.mode : undefined;
|
|
@@ -13965,12 +14052,12 @@ function readPersistPayload(options) {
|
|
|
13965
14052
|
}
|
|
13966
14053
|
if (options.file !== undefined) {
|
|
13967
14054
|
const requested = path14.isAbsolute(options.file) ? options.file : `${process.cwd()}${path14.sep}${options.file}`;
|
|
13968
|
-
if (!
|
|
14055
|
+
if (!fs10.existsSync(requested)) {
|
|
13969
14056
|
throw new Error(`persist payload file not found: ${requested}`);
|
|
13970
14057
|
}
|
|
13971
|
-
return
|
|
14058
|
+
return fs10.readFileSync(requested, "utf8");
|
|
13972
14059
|
}
|
|
13973
|
-
return
|
|
14060
|
+
return fs10.readFileSync(0, "utf8");
|
|
13974
14061
|
}
|
|
13975
14062
|
function validatePersistPayload(kind, payload) {
|
|
13976
14063
|
let gate2;
|
|
@@ -14128,7 +14215,7 @@ leaseCommand.command("verify").description("Verify a plan's execution_lease on t
|
|
|
14128
14215
|
throw new SddScriptError("usage: lease verify --workflow <id> [--plan <plan-id>] [--harness <path>]", 2);
|
|
14129
14216
|
}
|
|
14130
14217
|
const snapshotPath = resolveSnapshotPath(options.workflow, options.harness);
|
|
14131
|
-
if (!
|
|
14218
|
+
if (!fs10.existsSync(snapshotPath)) {
|
|
14132
14219
|
throw new Error(`workflow snapshot not found: ${snapshotPath}`);
|
|
14133
14220
|
}
|
|
14134
14221
|
const doc = readJson2(snapshotPath);
|
|
@@ -14166,7 +14253,7 @@ leaseCommand.command("verify-integration").description("Verify the workflow snap
|
|
|
14166
14253
|
throw new SddScriptError("usage: lease verify-integration --workflow <id> [--harness <path>]", 2);
|
|
14167
14254
|
}
|
|
14168
14255
|
const snapshotPath = resolveSnapshotPath(options.workflow, options.harness);
|
|
14169
|
-
if (!
|
|
14256
|
+
if (!fs10.existsSync(snapshotPath)) {
|
|
14170
14257
|
throw new Error(`workflow snapshot not found: ${snapshotPath}`);
|
|
14171
14258
|
}
|
|
14172
14259
|
const doc = readJson2(snapshotPath);
|
|
@@ -14201,7 +14288,7 @@ function loadSddContextFile(pathValue) {
|
|
|
14201
14288
|
}
|
|
14202
14289
|
let raw;
|
|
14203
14290
|
try {
|
|
14204
|
-
raw =
|
|
14291
|
+
raw = fs10.readFileSync(pathValue, "utf8");
|
|
14205
14292
|
} catch {
|
|
14206
14293
|
throw new SddScriptError(`no such context file: ${pathValue}`, 2);
|
|
14207
14294
|
}
|
|
@@ -14309,9 +14396,9 @@ iterationCommand.command("gate").description("Evaluate the phase-transition gate
|
|
|
14309
14396
|
try {
|
|
14310
14397
|
const snapshotPath = resolveSnapshotPath(options.workflow, options.harness);
|
|
14311
14398
|
const compassPath = path14.resolve(options.compass);
|
|
14312
|
-
if (!
|
|
14399
|
+
if (!fs10.existsSync(snapshotPath))
|
|
14313
14400
|
throw new Error(`workflow snapshot not found: ${snapshotPath}`);
|
|
14314
|
-
if (!
|
|
14401
|
+
if (!fs10.existsSync(compassPath))
|
|
14315
14402
|
throw new Error(`compass file not found: ${compassPath}`);
|
|
14316
14403
|
const result = evaluatePhaseGate(readJson2(snapshotPath), parseCompassFrontmatter(compassPath), {
|
|
14317
14404
|
currentBranch: options.branch,
|
|
@@ -14350,11 +14437,11 @@ dispatchCommand.command("validate").description("Validate an Assignment markdown
|
|
|
14350
14437
|
throw new SddScriptError("usage: dispatch validate <assignment-file> [--branch <branch>]", 2);
|
|
14351
14438
|
}
|
|
14352
14439
|
const fromCwd = path14.isAbsolute(assignmentFile) ? assignmentFile : path14.resolve(process.cwd(), assignmentFile);
|
|
14353
|
-
const file =
|
|
14354
|
-
if (!
|
|
14440
|
+
const file = fs10.existsSync(fromCwd) ? fromCwd : resolveCliPath(assignmentFile);
|
|
14441
|
+
if (!fs10.existsSync(file)) {
|
|
14355
14442
|
throw new Error(`assignment file not found: ${assignmentFile} (tried ${fromCwd} and ${resolveCliPath(assignmentFile)})`);
|
|
14356
14443
|
}
|
|
14357
|
-
const text =
|
|
14444
|
+
const text = fs10.readFileSync(file, "utf8");
|
|
14358
14445
|
const readOnly = isReadOnlyAssignmentRole(parseAssignmentFields(text).executeAs ?? "");
|
|
14359
14446
|
const violations = [...validateAssignmentFields(text, { writable: readOnly ? false : undefined }).violations];
|
|
14360
14447
|
if (!readOnly) {
|
|
@@ -14413,7 +14500,7 @@ worktreeCommand.command("check").description("L1: verify the plan's execution_le
|
|
|
14413
14500
|
throw new SddScriptError("usage: worktree check <plan-id> --workflow <id> [--harness <path>] [--control <path>] (or --plan <plan-id>)", 2);
|
|
14414
14501
|
}
|
|
14415
14502
|
const snapshotPath = resolveSnapshotPath(options.workflow, options.harness);
|
|
14416
|
-
if (!
|
|
14503
|
+
if (!fs10.existsSync(snapshotPath)) {
|
|
14417
14504
|
throw new Error(`workflow snapshot not found: ${snapshotPath}`);
|
|
14418
14505
|
}
|
|
14419
14506
|
const doc = readJson2(snapshotPath);
|
|
@@ -14471,10 +14558,10 @@ worktreeCommand.command("qc-alignment").description("Assert the QC/QA alignment
|
|
|
14471
14558
|
const assignments = [];
|
|
14472
14559
|
for (const fileArg of files) {
|
|
14473
14560
|
const file = path14.isAbsolute(fileArg) ? fileArg : `${process.cwd()}${path14.sep}${fileArg}`;
|
|
14474
|
-
if (!
|
|
14561
|
+
if (!fs10.existsSync(file)) {
|
|
14475
14562
|
throw new Error(`assignment file not found: ${file}`);
|
|
14476
14563
|
}
|
|
14477
|
-
const text =
|
|
14564
|
+
const text = fs10.readFileSync(file, "utf8");
|
|
14478
14565
|
const combinedRange = parseAssignmentHeaderField(text, "Review range / Diff basis");
|
|
14479
14566
|
const planId = parseAssignmentHeaderField(text, "plan_id");
|
|
14480
14567
|
const reviewRange = parseAssignmentHeaderField(text, "Review range") || combinedRange;
|
|
@@ -14517,10 +14604,10 @@ reviewCommand.command("seats").description("Map an Assignment's execution mode t
|
|
|
14517
14604
|
throw new SddScriptError("usage: review seats <assignment-file> [--mode sdd|inline|targeted] [--reviewers <role1,role2,...>]", 2);
|
|
14518
14605
|
}
|
|
14519
14606
|
const file = path14.isAbsolute(assignmentFile) ? assignmentFile : `${process.cwd()}${path14.sep}${assignmentFile}`;
|
|
14520
|
-
if (!
|
|
14607
|
+
if (!fs10.existsSync(file)) {
|
|
14521
14608
|
throw new Error(`assignment file not found: ${file}`);
|
|
14522
14609
|
}
|
|
14523
|
-
const text =
|
|
14610
|
+
const text = fs10.readFileSync(file, "utf8");
|
|
14524
14611
|
const mode = options.mode ?? parseAssignmentExecutionMode(text);
|
|
14525
14612
|
const reviewers = (options.reviewers ?? "").split(",").map((role) => role.trim()).filter((role) => role !== "");
|
|
14526
14613
|
const result = executionModeToN(mode, { seats: reviewers });
|
|
@@ -14596,7 +14683,7 @@ function lintTargetType(filePath) {
|
|
|
14596
14683
|
function collectLintTargets(dir) {
|
|
14597
14684
|
const targets = [];
|
|
14598
14685
|
const visit = (current) => {
|
|
14599
|
-
for (const entry of
|
|
14686
|
+
for (const entry of fs10.readdirSync(current, { withFileTypes: true })) {
|
|
14600
14687
|
if (entry.name.includes(path14.sep))
|
|
14601
14688
|
continue;
|
|
14602
14689
|
const child = current + entry.name;
|
|
@@ -14613,7 +14700,7 @@ function collectLintTargets(dir) {
|
|
|
14613
14700
|
return targets;
|
|
14614
14701
|
}
|
|
14615
14702
|
var lintIo = {
|
|
14616
|
-
readText: async (resolvedPath) =>
|
|
14703
|
+
readText: async (resolvedPath) => fs10.promises.readFile(resolvedPath, "utf8")
|
|
14617
14704
|
};
|
|
14618
14705
|
async function lintOneFile(filePath, forcedType, prVariant) {
|
|
14619
14706
|
const text = await lintIo.readText(filePath);
|
|
@@ -14668,9 +14755,9 @@ lintCommand.description("Lint <target> (file or dir) \u2014 exit 1 on violations
|
|
|
14668
14755
|
forcedType = forced;
|
|
14669
14756
|
}
|
|
14670
14757
|
const abs = resolveCliPath(target);
|
|
14671
|
-
if (!
|
|
14758
|
+
if (!fs10.existsSync(abs))
|
|
14672
14759
|
throw new Error(`lint target not found: ${abs}`);
|
|
14673
|
-
const targets =
|
|
14760
|
+
const targets = fs10.statSync(abs).isDirectory() ? collectLintTargets(abs) : [abs];
|
|
14674
14761
|
if (targets.length === 0) {
|
|
14675
14762
|
console.log(import_picocolors2.default.yellow(`lint: no lintable files under ${target}`));
|
|
14676
14763
|
return;
|
|
@@ -14716,16 +14803,16 @@ designMdCommand.command("validate").description("Validate DESIGN.md in <dir>: to
|
|
|
14716
14803
|
throw new SddScriptError("usage: design-md validate <dir>", 2);
|
|
14717
14804
|
const abs = resolveCliPath(dir);
|
|
14718
14805
|
const lightPath = `${abs}${path14.sep}DESIGN.md`;
|
|
14719
|
-
if (!
|
|
14806
|
+
if (!fs10.existsSync(lightPath))
|
|
14720
14807
|
throw new Error(`design file not found: ${lightPath}`);
|
|
14721
|
-
const light =
|
|
14808
|
+
const light = fs10.readFileSync(lightPath, "utf8");
|
|
14722
14809
|
const violations = [];
|
|
14723
14810
|
const tokens = validateDesignTokenFrontmatter(light);
|
|
14724
14811
|
printChecklist("design-md validate (tokens)", tokens);
|
|
14725
14812
|
violations.push(...tokens.violations);
|
|
14726
14813
|
const darkPath = `${abs}${path14.sep}DESIGN.dark.md`;
|
|
14727
|
-
if (
|
|
14728
|
-
const parity = assertLightDarkParity(light,
|
|
14814
|
+
if (fs10.existsSync(darkPath)) {
|
|
14815
|
+
const parity = assertLightDarkParity(light, fs10.readFileSync(darkPath, "utf8"));
|
|
14729
14816
|
printChecklist("design-md validate (light/dark parity)", parity);
|
|
14730
14817
|
violations.push(...parity.violations);
|
|
14731
14818
|
}
|
|
@@ -14873,7 +14960,7 @@ auditCommand.command("scaffold").description("Scaffold an audit-<date>/ plan dir
|
|
|
14873
14960
|
if (!findingsFile)
|
|
14874
14961
|
throw new SddScriptError("usage: audit scaffold <findings-file> [--dir <out-dir>]", 2);
|
|
14875
14962
|
const abs = resolveCliPath(findingsFile);
|
|
14876
|
-
if (!
|
|
14963
|
+
if (!fs10.existsSync(abs))
|
|
14877
14964
|
throw new Error(`findings file not found: ${abs}`);
|
|
14878
14965
|
if (options.date !== undefined && !/^\d{4}-\d{2}-\d{2}$/.test(options.date)) {
|
|
14879
14966
|
throw new SddScriptError("usage: audit scaffold \u2014 --date must be YYYY-MM-DD", 2);
|
|
@@ -14883,7 +14970,7 @@ auditCommand.command("scaffold").description("Scaffold an audit-<date>/ plan dir
|
|
|
14883
14970
|
}
|
|
14884
14971
|
const date = options.date ?? new Date().toISOString().slice(0, 10);
|
|
14885
14972
|
const outDir = options.dir !== undefined ? resolveCliPath(options.dir) : resolveCliPath(`audit-${date}`);
|
|
14886
|
-
const input = parseAuditScaffoldInput(
|
|
14973
|
+
const input = parseAuditScaffoldInput(fs10.readFileSync(abs, "utf8"));
|
|
14887
14974
|
const sha = resolveAuditShortSha(process.cwd(), options.sha);
|
|
14888
14975
|
const result = scaffoldAuditPlan(outDir, input.findings, {
|
|
14889
14976
|
date,
|
|
@@ -14910,7 +14997,7 @@ auditCommand.command("promote").description("Promote selected audit plans into t
|
|
|
14910
14997
|
throw new SddScriptError("usage: audit promote <audit-dir> --plans <ids> [--workflow <id>] [--harness <dir>]", 2);
|
|
14911
14998
|
}
|
|
14912
14999
|
const outDir = resolveCliPath(auditDir);
|
|
14913
|
-
if (!
|
|
15000
|
+
if (!fs10.existsSync(outDir)) {
|
|
14914
15001
|
throw new Error(`audit dir not found: ${outDir}`);
|
|
14915
15002
|
}
|
|
14916
15003
|
const harnessDir = resolveLeaseHarnessDir(options.harness);
|
|
@@ -14941,7 +15028,7 @@ function listTrackedFiles(root) {
|
|
|
14941
15028
|
auditCommand.command("secret-scan").description("Read-only credential-pattern scan over git-tracked files under [path] " + "(default cwd): prints {file, line, type} findings; never prints values. " + "Exit 1 on findings, 0 when clean, 2 when the tracked-file walk or reads fail").argument("[path]", "Directory to scan (default: cwd)").action((scanPath) => {
|
|
14942
15029
|
try {
|
|
14943
15030
|
const root = scanPath !== undefined ? resolveCliPath(scanPath) : process.cwd();
|
|
14944
|
-
if (!
|
|
15031
|
+
if (!fs10.existsSync(root) || !fs10.statSync(root).isDirectory()) {
|
|
14945
15032
|
throw new SddScriptError(`usage: audit secret-scan [path] \u2014 not a directory: ${root}`, 2);
|
|
14946
15033
|
}
|
|
14947
15034
|
const files = listTrackedFiles(root);
|
|
@@ -14968,7 +15055,7 @@ auditCommand.command("secret-scan").description("Read-only credential-pattern sc
|
|
|
14968
15055
|
auditCommand.command("supply-chain").description("Supply-chain checks over a repo root (read-only): root lockfile presence/duplication, " + "unpinned GitHub Actions refs, pull_request_target PR-head checkout. " + "Exit 1 on findings, 0 when clean").argument("[path]", "Repository root (default: cwd)").action((repoPath) => {
|
|
14969
15056
|
try {
|
|
14970
15057
|
const root = repoPath !== undefined ? resolveCliPath(repoPath) : process.cwd();
|
|
14971
|
-
if (!
|
|
15058
|
+
if (!fs10.existsSync(root) || !fs10.statSync(root).isDirectory()) {
|
|
14972
15059
|
throw new SddScriptError(`usage: audit supply-chain [path] \u2014 not a directory: ${root}`, 2);
|
|
14973
15060
|
}
|
|
14974
15061
|
const result = supplyChainChecks(root);
|
|
@@ -14995,9 +15082,9 @@ compoundCommand.command("validate").description("Validate a knowledge doc frontm
|
|
|
14995
15082
|
if (!docPath)
|
|
14996
15083
|
throw new SddScriptError("usage: compound validate <doc-path> [--knowledge-dir <dir>]", 2);
|
|
14997
15084
|
const abs = resolveCliPath(docPath);
|
|
14998
|
-
if (!
|
|
15085
|
+
if (!fs10.existsSync(abs))
|
|
14999
15086
|
throw new Error(`knowledge doc not found: ${abs}`);
|
|
15000
|
-
const text =
|
|
15087
|
+
const text = fs10.readFileSync(abs, "utf8");
|
|
15001
15088
|
const violations = [];
|
|
15002
15089
|
const schema = validateSchemaYaml(text);
|
|
15003
15090
|
printChecklist("compound validate (schema)", schema);
|
|
@@ -15088,9 +15175,9 @@ skillCommand.command("lint").description("Lint <skill-dir>/SKILL.md: frontmatter
|
|
|
15088
15175
|
if (!skillDir)
|
|
15089
15176
|
throw new SddScriptError("usage: skill lint <skill-dir>", 2);
|
|
15090
15177
|
const skillFile = path14.join(resolveCliPath(skillDir), "SKILL.md");
|
|
15091
|
-
if (!
|
|
15178
|
+
if (!fs10.existsSync(skillFile))
|
|
15092
15179
|
throw new Error(`SKILL.md not found: ${skillFile}`);
|
|
15093
|
-
const text =
|
|
15180
|
+
const text = fs10.readFileSync(skillFile, "utf8");
|
|
15094
15181
|
const violations = [];
|
|
15095
15182
|
const frontmatter = lintSkillFrontmatter(text);
|
|
15096
15183
|
printChecklist("skill lint (frontmatter)", frontmatter);
|
|
@@ -15132,14 +15219,14 @@ rolesCommand.command("validate").description("Validate the mstar-roles skill-dir
|
|
|
15132
15219
|
printChecklist("roles validate (mapping)", mapping);
|
|
15133
15220
|
violations.push(...mapping.violations);
|
|
15134
15221
|
const skillTexts = {};
|
|
15135
|
-
for (const entry of
|
|
15222
|
+
for (const entry of fs10.readdirSync(skillsRoot, { withFileTypes: true })) {
|
|
15136
15223
|
if (!entry.isDirectory() || !entry.name.startsWith("mstar-"))
|
|
15137
15224
|
continue;
|
|
15138
15225
|
const skillFile = path14.join(skillsRoot, entry.name, "SKILL.md");
|
|
15139
|
-
if (!
|
|
15226
|
+
if (!fs10.existsSync(skillFile))
|
|
15140
15227
|
continue;
|
|
15141
15228
|
try {
|
|
15142
|
-
skillTexts[entry.name] =
|
|
15229
|
+
skillTexts[entry.name] = fs10.readFileSync(skillFile, "utf8");
|
|
15143
15230
|
} catch {}
|
|
15144
15231
|
}
|
|
15145
15232
|
const loadOrder = lintLoadOrder(skillTexts);
|
|
@@ -15181,11 +15268,11 @@ function parsePrReviewTarget(raw) {
|
|
|
15181
15268
|
prReviewCommand.command("tally").description("Compute the locked-formula tally, verdict and score from accepted findings JSON ([{mergeClass}]) plus the " + "leftover unmet-AC / unverified counts; prints the two-line chat header + structured result (pr-review.md \xA7 Tally)").requiredOption("--findings <file.json>", "Accepted findings JSON \u2014 array of {mergeClass: must-fix|should-fix|nit}").option("--unverified <n>", "Count of residual - unverified: items (default 0)").option("--unmet-ac-unsafe <n>", "Leftover unmet ACs that are unsafe-to-ship (each \u2192 must_fix + 1)").option("--unmet-ac-safe <n>", "Leftover unmet ACs that are ship-safe (each \u2192 should_fix + 1)").action((options) => {
|
|
15182
15269
|
try {
|
|
15183
15270
|
const findingsPath = resolveCliPath(options.findings);
|
|
15184
|
-
if (!
|
|
15271
|
+
if (!fs10.existsSync(findingsPath))
|
|
15185
15272
|
throw new Error(`findings file not found: ${findingsPath}`);
|
|
15186
15273
|
let parsed;
|
|
15187
15274
|
try {
|
|
15188
|
-
parsed = JSON.parse(
|
|
15275
|
+
parsed = JSON.parse(fs10.readFileSync(findingsPath, "utf8"));
|
|
15189
15276
|
} catch (error) {
|
|
15190
15277
|
throw new Error(`--findings is not valid JSON: ${error.message}`);
|
|
15191
15278
|
}
|
|
@@ -15263,9 +15350,9 @@ prReviewCommand.command("report-path").description("Resolve the local-report (or
|
|
|
15263
15350
|
prReviewCommand.command("validate-report").description("Validate a saved local PR-review report against the machine-readable contract (frontmatter fields, verdict-from-tally, " + "locked-formula score recompute, comments tri-state; exit 1 with violations printed)").argument("<file.md>", "Saved report markdown file").action((reportFile) => {
|
|
15264
15351
|
try {
|
|
15265
15352
|
const abs = resolveCliPath(reportFile);
|
|
15266
|
-
if (!
|
|
15353
|
+
if (!fs10.existsSync(abs))
|
|
15267
15354
|
throw new Error(`report file not found: ${abs}`);
|
|
15268
|
-
const gate2 = validatePrReviewReport(
|
|
15355
|
+
const gate2 = validatePrReviewReport(fs10.readFileSync(abs, "utf8"));
|
|
15269
15356
|
printChecklist(abs, gate2);
|
|
15270
15357
|
if (!gate2.ok)
|
|
15271
15358
|
process.exitCode = 1;
|
|
@@ -15373,17 +15460,17 @@ prReviewCommand.command("post").description("Build and POST the GitHub Review pe
|
|
|
15373
15460
|
}
|
|
15374
15461
|
const prNumber = Number(options.pr);
|
|
15375
15462
|
const bodyPath = resolveCliPath(options.bodyFile);
|
|
15376
|
-
if (!
|
|
15463
|
+
if (!fs10.existsSync(bodyPath))
|
|
15377
15464
|
throw new Error(`body file not found: ${bodyPath}`);
|
|
15378
|
-
const body =
|
|
15465
|
+
const body = fs10.readFileSync(bodyPath, "utf8");
|
|
15379
15466
|
let comments = [];
|
|
15380
15467
|
if (options.findings !== undefined) {
|
|
15381
15468
|
const findingsPath = resolveCliPath(options.findings);
|
|
15382
|
-
if (!
|
|
15469
|
+
if (!fs10.existsSync(findingsPath))
|
|
15383
15470
|
throw new Error(`findings file not found: ${findingsPath}`);
|
|
15384
15471
|
let parsed;
|
|
15385
15472
|
try {
|
|
15386
|
-
parsed = JSON.parse(
|
|
15473
|
+
parsed = JSON.parse(fs10.readFileSync(findingsPath, "utf8"));
|
|
15387
15474
|
} catch (error) {
|
|
15388
15475
|
throw new Error(`--findings is not valid JSON: ${error.message}`);
|
|
15389
15476
|
}
|
|
@@ -15487,7 +15574,7 @@ prReviewCommand.command("worktree-setup").description("Create the isolated revie
|
|
|
15487
15574
|
throw new SddScriptError("usage: pr-review worktree-setup \u2014 the five input modes are mutually exclusive", 2);
|
|
15488
15575
|
}
|
|
15489
15576
|
const startDir = process.cwd();
|
|
15490
|
-
if (!
|
|
15577
|
+
if (!fs10.existsSync(path14.join(startDir, ".git")) && gitIf(["rev-parse", "--git-dir"], startDir) === "") {
|
|
15491
15578
|
throw new Error(`not a git repository: ${startDir}`);
|
|
15492
15579
|
}
|
|
15493
15580
|
const repoRoot = gitSync(["rev-parse", "--show-toplevel"], startDir);
|
|
@@ -15563,13 +15650,13 @@ prReviewCommand.command("worktree-setup").description("Create the isolated revie
|
|
|
15563
15650
|
const branchSuffix = mode === "pr" ? "" : `-${headSpec.slice(0, 8)}`;
|
|
15564
15651
|
const worktreePath = path14.resolve(options.path ?? path14.join(repoRoot, ".worktrees", `review-${reviewBranch}${branchSuffix}`));
|
|
15565
15652
|
if (options.path === undefined) {
|
|
15566
|
-
|
|
15653
|
+
fs10.mkdirSync(path14.join(repoRoot, ".worktrees"), { recursive: true });
|
|
15567
15654
|
if (gitIf(["check-ignore", ".worktrees/"], repoRoot) === "") {
|
|
15568
15655
|
const excludePath = path14.join(repoRoot, ".git", "info", "exclude");
|
|
15569
|
-
const existing2 =
|
|
15656
|
+
const existing2 = fs10.existsSync(excludePath) ? fs10.readFileSync(excludePath, "utf8") : "";
|
|
15570
15657
|
if (!existing2.split(`
|
|
15571
15658
|
`).some((line) => line.trim() === ".worktrees/")) {
|
|
15572
|
-
|
|
15659
|
+
fs10.appendFileSync(excludePath, `${existing2 === "" || existing2.endsWith(`
|
|
15573
15660
|
`) ? "" : `
|
|
15574
15661
|
`}.worktrees/
|
|
15575
15662
|
`);
|
|
@@ -15597,7 +15684,7 @@ prReviewCommand.command("worktree-setup").description("Create the isolated revie
|
|
|
15597
15684
|
let sidecarFd;
|
|
15598
15685
|
const cleanupOnFailure = (branchToDelete) => {
|
|
15599
15686
|
try {
|
|
15600
|
-
if (
|
|
15687
|
+
if (fs10.existsSync(worktreePath))
|
|
15601
15688
|
gitSync(["worktree", "remove", "--force", worktreePath], repoRoot);
|
|
15602
15689
|
gitSync(["worktree", "prune"], repoRoot);
|
|
15603
15690
|
if (branchToDelete !== "" && !existing.has(branchToDelete)) {
|
|
@@ -15688,7 +15775,7 @@ prReviewCommand.command("worktree-setup").description("Create the isolated revie
|
|
|
15688
15775
|
diffFileSha256: createHash("sha256").update(snapshot).digest("hex")
|
|
15689
15776
|
};
|
|
15690
15777
|
try {
|
|
15691
|
-
sidecarFd =
|
|
15778
|
+
sidecarFd = fs10.openSync(sidecarPath, "wx+");
|
|
15692
15779
|
} catch (error) {
|
|
15693
15780
|
if (error.code !== "EEXIST" && error.code !== "EISDIR")
|
|
15694
15781
|
throw error;
|
|
@@ -15697,21 +15784,21 @@ prReviewCommand.command("worktree-setup").description("Create the isolated revie
|
|
|
15697
15784
|
writeFdSync(sidecarFd, Buffer.from(JSON.stringify(sidecar2, null, 2), "utf8"));
|
|
15698
15785
|
wroteSidecar = true;
|
|
15699
15786
|
try {
|
|
15700
|
-
|
|
15787
|
+
fs10.writeFileSync(diffFile, snapshot, { flag: "wx" });
|
|
15701
15788
|
} catch (error) {
|
|
15702
15789
|
if (error.code !== "EEXIST" && error.code !== "EISDIR")
|
|
15703
15790
|
throw error;
|
|
15704
15791
|
throw new Error(`refusing to overwrite pre-existing non-snapshot path ${diffFile}`);
|
|
15705
15792
|
}
|
|
15706
15793
|
wroteSnapshot = true;
|
|
15707
|
-
const snapshotStat =
|
|
15794
|
+
const snapshotStat = fs10.lstatSync(diffFile);
|
|
15708
15795
|
sidecar2.diffFileDev = snapshotStat.dev;
|
|
15709
15796
|
sidecar2.diffFileIno = String(snapshotStat.ino);
|
|
15710
15797
|
sidecar2.diffFileMtimeMs = snapshotStat.mtimeMs;
|
|
15711
15798
|
pendingSidecar = sidecar2;
|
|
15712
|
-
|
|
15799
|
+
fs10.ftruncateSync(sidecarFd, 0);
|
|
15713
15800
|
writeFdSync(sidecarFd, Buffer.from(JSON.stringify(sidecar2, null, 2), "utf8"));
|
|
15714
|
-
|
|
15801
|
+
fs10.closeSync(sidecarFd);
|
|
15715
15802
|
sidecarFd = undefined;
|
|
15716
15803
|
return sidecar2;
|
|
15717
15804
|
};
|
|
@@ -15743,13 +15830,13 @@ function prReviewArtifactPathFor(worktreePath, suffix) {
|
|
|
15743
15830
|
function writeFdSync(fd, buf) {
|
|
15744
15831
|
let written = 0;
|
|
15745
15832
|
while (written < buf.length)
|
|
15746
|
-
written +=
|
|
15833
|
+
written += fs10.writeSync(fd, buf, written, buf.length - written, written);
|
|
15747
15834
|
}
|
|
15748
15835
|
function removeOwnedSnapshotFile(worktreePath, sidecar) {
|
|
15749
15836
|
const snapshotPath = prReviewArtifactPathFor(worktreePath, "diff");
|
|
15750
15837
|
let fd;
|
|
15751
15838
|
try {
|
|
15752
|
-
fd =
|
|
15839
|
+
fd = fs10.openSync(snapshotPath, "r");
|
|
15753
15840
|
} catch (error) {
|
|
15754
15841
|
if (error.code === "ENOENT")
|
|
15755
15842
|
return;
|
|
@@ -15757,7 +15844,7 @@ function removeOwnedSnapshotFile(worktreePath, sidecar) {
|
|
|
15757
15844
|
return;
|
|
15758
15845
|
}
|
|
15759
15846
|
try {
|
|
15760
|
-
const st =
|
|
15847
|
+
const st = fs10.fstatSync(fd);
|
|
15761
15848
|
if (!st.isFile())
|
|
15762
15849
|
return;
|
|
15763
15850
|
const recordedIno = sidecar.diffFileIno;
|
|
@@ -15774,28 +15861,28 @@ function removeOwnedSnapshotFile(worktreePath, sidecar) {
|
|
|
15774
15861
|
}
|
|
15775
15862
|
const tmp = `${snapshotPath}.cleanup.${process.pid}.${randomUUID3()}`;
|
|
15776
15863
|
try {
|
|
15777
|
-
|
|
15864
|
+
fs10.renameSync(snapshotPath, tmp);
|
|
15778
15865
|
} catch (error) {
|
|
15779
15866
|
console.error(import_picocolors2.default.yellow(`worktree-cleanup: snapshot at ${snapshotPath} left in place (cannot detach: ${error.message})`));
|
|
15780
15867
|
return;
|
|
15781
15868
|
}
|
|
15782
|
-
const st2 =
|
|
15869
|
+
const st2 = fs10.fstatSync(fd);
|
|
15783
15870
|
let tmpStat;
|
|
15784
15871
|
try {
|
|
15785
|
-
tmpStat =
|
|
15872
|
+
tmpStat = fs10.lstatSync(tmp);
|
|
15786
15873
|
} catch {
|
|
15787
15874
|
tmpStat = undefined;
|
|
15788
15875
|
}
|
|
15789
15876
|
if (tmpStat !== undefined && tmpStat.ino === st2.ino && tmpStat.dev === st2.dev && st2.nlink === 1 && tmpStat.nlink === 1) {
|
|
15790
|
-
|
|
15791
|
-
const st3 =
|
|
15877
|
+
fs10.unlinkSync(tmp);
|
|
15878
|
+
const st3 = fs10.fstatSync(fd);
|
|
15792
15879
|
if (st3.nlink !== 0) {
|
|
15793
15880
|
console.error(import_picocolors2.default.yellow(`worktree-cleanup: unlink at ${tmp} detached a pathname replacement, not the verified snapshot inode (${snapshotPath} still holds ${st3.nlink} link(s)) - the replacement is gone, the verified snapshot was NOT deleted`));
|
|
15794
15881
|
}
|
|
15795
15882
|
} else {
|
|
15796
15883
|
try {
|
|
15797
|
-
|
|
15798
|
-
|
|
15884
|
+
fs10.linkSync(tmp, snapshotPath);
|
|
15885
|
+
fs10.unlinkSync(tmp);
|
|
15799
15886
|
} catch (error) {
|
|
15800
15887
|
if (error.code === "EEXIST") {
|
|
15801
15888
|
console.error(import_picocolors2.default.yellow(`worktree-cleanup: snapshot replacement left at ${tmp} (snapshot path was recreated concurrently)`));
|
|
@@ -15805,41 +15892,41 @@ function removeOwnedSnapshotFile(worktreePath, sidecar) {
|
|
|
15805
15892
|
}
|
|
15806
15893
|
}
|
|
15807
15894
|
} finally {
|
|
15808
|
-
|
|
15895
|
+
fs10.closeSync(fd);
|
|
15809
15896
|
}
|
|
15810
15897
|
}
|
|
15811
15898
|
function removeOwnedFreshSidecarFile(sidecarFd, worktreePath) {
|
|
15812
15899
|
const sidecarPath = prReviewArtifactPathFor(worktreePath, "json");
|
|
15813
15900
|
try {
|
|
15814
|
-
const st =
|
|
15901
|
+
const st = fs10.fstatSync(sidecarFd);
|
|
15815
15902
|
if (!st.isFile() || st.nlink !== 1) {
|
|
15816
15903
|
console.error(import_picocolors2.default.yellow(`worktree-setup rollback: sidecar at ${sidecarPath} left in place (identity no longer held)`));
|
|
15817
15904
|
return;
|
|
15818
15905
|
}
|
|
15819
15906
|
const tmp = `${sidecarPath}.cleanup.${process.pid}.${randomUUID3()}`;
|
|
15820
15907
|
try {
|
|
15821
|
-
|
|
15908
|
+
fs10.renameSync(sidecarPath, tmp);
|
|
15822
15909
|
} catch (error) {
|
|
15823
15910
|
console.error(import_picocolors2.default.yellow(`worktree-setup rollback: sidecar at ${sidecarPath} left in place (cannot detach: ${error.message})`));
|
|
15824
15911
|
return;
|
|
15825
15912
|
}
|
|
15826
|
-
const st2 =
|
|
15913
|
+
const st2 = fs10.fstatSync(sidecarFd);
|
|
15827
15914
|
let tmpStat;
|
|
15828
15915
|
try {
|
|
15829
|
-
tmpStat =
|
|
15916
|
+
tmpStat = fs10.lstatSync(tmp);
|
|
15830
15917
|
} catch {
|
|
15831
15918
|
tmpStat = undefined;
|
|
15832
15919
|
}
|
|
15833
15920
|
if (tmpStat !== undefined && tmpStat.ino === st2.ino && tmpStat.dev === st2.dev) {
|
|
15834
|
-
|
|
15835
|
-
const st3 =
|
|
15921
|
+
fs10.unlinkSync(tmp);
|
|
15922
|
+
const st3 = fs10.fstatSync(sidecarFd);
|
|
15836
15923
|
if (st3.nlink !== 0) {
|
|
15837
15924
|
console.error(import_picocolors2.default.yellow(`worktree-setup rollback: unlink at ${tmp} detached a pathname replacement, not the verified sidecar inode (${sidecarPath} still holds ${st3.nlink} link(s)) - the replacement is gone, the verified sidecar was NOT deleted`));
|
|
15838
15925
|
}
|
|
15839
15926
|
} else {
|
|
15840
15927
|
try {
|
|
15841
|
-
|
|
15842
|
-
|
|
15928
|
+
fs10.linkSync(tmp, sidecarPath);
|
|
15929
|
+
fs10.unlinkSync(tmp);
|
|
15843
15930
|
} catch (error) {
|
|
15844
15931
|
if (error.code === "EEXIST") {
|
|
15845
15932
|
console.error(import_picocolors2.default.yellow(`worktree-setup rollback: sidecar replacement left at ${tmp} (sidecar path was recreated concurrently)`));
|
|
@@ -15850,7 +15937,7 @@ function removeOwnedFreshSidecarFile(sidecarFd, worktreePath) {
|
|
|
15850
15937
|
}
|
|
15851
15938
|
} finally {
|
|
15852
15939
|
try {
|
|
15853
|
-
|
|
15940
|
+
fs10.closeSync(sidecarFd);
|
|
15854
15941
|
} catch {}
|
|
15855
15942
|
}
|
|
15856
15943
|
}
|
|
@@ -15858,12 +15945,12 @@ prReviewCommand.command("worktree-cleanup").description("Remove the review workt
|
|
|
15858
15945
|
try {
|
|
15859
15946
|
const worktreePath = path14.resolve(resolveCliPath(options.path));
|
|
15860
15947
|
const sidecarPath = prReviewArtifactPathFor(worktreePath, "json");
|
|
15861
|
-
if (!
|
|
15948
|
+
if (!fs10.existsSync(sidecarPath)) {
|
|
15862
15949
|
throw new Error(`no setup sidecar found at ${sidecarPath} - run pr-review worktree-setup first (foreign worktrees are never cleaned here)`);
|
|
15863
15950
|
}
|
|
15864
15951
|
let sidecar;
|
|
15865
15952
|
try {
|
|
15866
|
-
sidecar = JSON.parse(
|
|
15953
|
+
sidecar = JSON.parse(fs10.readFileSync(sidecarPath, "utf8"));
|
|
15867
15954
|
} catch (error) {
|
|
15868
15955
|
throw new Error(`setup sidecar at ${sidecarPath} is not valid JSON: ${error.message}`);
|
|
15869
15956
|
}
|
|
@@ -15879,7 +15966,7 @@ prReviewCommand.command("worktree-cleanup").description("Remove the review workt
|
|
|
15879
15966
|
if (!savedOk) {
|
|
15880
15967
|
throw new Error("refusing cleanup: the local report is not saved yet - save it first or pass --report-saved (\xA7 Local report archive)");
|
|
15881
15968
|
}
|
|
15882
|
-
if (
|
|
15969
|
+
if (fs10.existsSync(worktreePath)) {
|
|
15883
15970
|
gitSync(["worktree", "remove", worktreePath], gitRoot);
|
|
15884
15971
|
}
|
|
15885
15972
|
gitSync(["worktree", "prune"], gitRoot);
|
|
@@ -15890,7 +15977,7 @@ prReviewCommand.command("worktree-cleanup").description("Remove the review workt
|
|
|
15890
15977
|
gitSync(["branch", "-D", sidecar.reviewBranch], gitRoot);
|
|
15891
15978
|
}
|
|
15892
15979
|
removeOwnedSnapshotFile(worktreePath, sidecar);
|
|
15893
|
-
|
|
15980
|
+
fs10.rmSync(sidecarPath, { force: true });
|
|
15894
15981
|
console.log(import_picocolors2.default.green(`worktree-cleanup: removed ${worktreePath}${sidecar.reviewBranch !== "" ? ` + deleted ${sidecar.reviewBranch}` : " (no local branch to delete)"}`));
|
|
15895
15982
|
} catch (error) {
|
|
15896
15983
|
failScript(error, "pr-review worktree-cleanup");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mstar-harness/cli",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.3",
|
|
4
4
|
"description": "Morning Star harness CLI — installer bootstrap + mstar workflow verbs (path/status/lease/sdd/iteration/dispatch/worktree/lint/design-md/audit/compound/host/skill).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|