@mstar-harness/cli 3.9.0 → 3.9.1

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.
@@ -18666,16 +18666,31 @@ function cleanupWorktreeClaims(worktreePath, snapshots) {
18666
18666
  }
18667
18667
  return claims;
18668
18668
  }
18669
- function cleanupReadSnapshotDir(dir) {
18670
- try {
18671
- return readWorkflowSnapshot(dir);
18672
- } catch (error) {
18673
- if (error instanceof WorkflowSnapshotValidationError) {
18674
- const detail = error.violations.map((violation16) => `${violation16.code}: ${violation16.message}`).join("; ");
18675
- throw new Error(`${path15.join(dir, WORKFLOW_SNAPSHOT_FILE)}: ${detail}`);
18669
+ function cleanupDegradeSiblingSnapshot(doc, id) {
18670
+ const text = (value) => typeof value === "string" && value !== "" ? value : undefined;
18671
+ const branch = {};
18672
+ const rawBranch = doc.branch;
18673
+ if (cleanupIsPlainRow(rawBranch)) {
18674
+ for (const key of ["base", "integration", "target"]) {
18675
+ const value = text(rawBranch[key]);
18676
+ if (value !== undefined)
18677
+ branch[key] = value;
18676
18678
  }
18677
- throw error;
18678
18679
  }
18680
+ const integrationWorktreePath = text(doc.integration_worktree_path) ?? text(doc.control_worktree_path);
18681
+ const plans = (Array.isArray(doc.plans) ? doc.plans : []).filter(cleanupIsPlainRow).map((row) => ({ ...row, status: "InProgress" }));
18682
+ return {
18683
+ schema_version: 1,
18684
+ id,
18685
+ type: doc.type === "iteration" || doc.type === "plan" ? doc.type : "plan",
18686
+ status: "running",
18687
+ started_at: text(doc.started_at) ?? "",
18688
+ updated_at: text(doc.updated_at) ?? "",
18689
+ ...Object.keys(branch).length > 0 ? { branch } : {},
18690
+ ...integrationWorktreePath !== undefined ? { integration_worktree_path: integrationWorktreePath } : {},
18691
+ ...cleanupIsPlainRow(doc.integration_merge_lease) ? { integration_merge_lease: doc.integration_merge_lease } : {},
18692
+ plans
18693
+ };
18679
18694
  }
18680
18695
  function cleanupPrintDiagnostics(diagnostics) {
18681
18696
  for (const diagnostic of diagnostics) {
@@ -18777,17 +18792,33 @@ function cleanupProbeRemoteEvidence(mainRoot, remoteBranches, bases) {
18777
18792
  return evidence;
18778
18793
  }
18779
18794
  function cleanupProbe(input) {
18780
- const selectedRead = cleanupReadSnapshotDir(input.snapshotDir);
18795
+ const selectedRead = readWorkflowSnapshot(input.snapshotDir);
18781
18796
  cleanupPrintDiagnostics(selectedRead.diagnostics);
18782
18797
  const selected = selectedRead.snapshot;
18783
18798
  const snapshots = [];
18799
+ const unreadableSiblings = [];
18784
18800
  for (const entry of fs12.readdirSync(input.workflowRoot, { withFileTypes: true })) {
18785
18801
  if (!entry.isDirectory())
18786
18802
  continue;
18787
18803
  const dir = path15.join(input.workflowRoot, entry.name);
18788
- if (!fs12.existsSync(path15.join(dir, WORKFLOW_SNAPSHOT_FILE)))
18804
+ const snapshotPath = path15.join(dir, WORKFLOW_SNAPSHOT_FILE);
18805
+ if (!fs12.existsSync(snapshotPath))
18789
18806
  continue;
18790
- const read = cleanupReadSnapshotDir(dir);
18807
+ let read;
18808
+ try {
18809
+ read = readWorkflowSnapshot(dir);
18810
+ } catch (error) {
18811
+ if (error instanceof WorkflowSnapshotValidationError) {
18812
+ const detail = error.violations.map((violation16) => `${violation16.code}: ${violation16.message}`).join("; ");
18813
+ const doc = JSON.parse(fs12.readFileSync(snapshotPath, "utf8"));
18814
+ snapshots.push(cleanupDegradeSiblingSnapshot(doc, entry.name));
18815
+ console.error(import_picocolors3.default.yellow(`worktree cleanup: note: sibling snapshot ${snapshotPath} is invalid (${detail}) \u2014 its protective declarations are kept in degraded form`));
18816
+ continue;
18817
+ }
18818
+ unreadableSiblings.push(snapshotPath);
18819
+ console.error(import_picocolors3.default.yellow(`worktree cleanup: note: sibling snapshot ${snapshotPath} cannot be parsed (${error.message}) \u2014 its declarations are unknown, so removals are withheld`));
18820
+ continue;
18821
+ }
18791
18822
  cleanupPrintDiagnostics(read.diagnostics);
18792
18823
  snapshots.push(read.snapshot);
18793
18824
  }
@@ -18803,6 +18834,7 @@ function cleanupProbe(input) {
18803
18834
  return {
18804
18835
  selected,
18805
18836
  snapshots,
18837
+ unreadableSiblings,
18806
18838
  worktrees,
18807
18839
  defaultBranch: cleanupProbeDefaultBranch(input.mainRoot, worktrees[0]?.branch ?? null),
18808
18840
  localBranches,
@@ -18879,16 +18911,21 @@ function cleanupPrintPlan(title, decisions) {
18879
18911
  console.log(`${decision.verdict} | ${decision.kind} | ${decision.ref} | ${decision.reason}`);
18880
18912
  }
18881
18913
  }
18914
+ function cleanupGuardUnreadableSiblings(decisions, probe, ignoreUnreadableSiblings) {
18915
+ if (ignoreUnreadableSiblings || probe.unreadableSiblings.length === 0)
18916
+ return [...decisions];
18917
+ return decisions.map((decision) => decision.verdict === "remove" ? { ...decision, verdict: "refuse", reason: "cleanup.refuse.unreadable-snapshot" } : decision);
18918
+ }
18882
18919
  function cleanupBranchDeletionCwd(base, probe, mainRoot) {
18883
18920
  if (base === undefined)
18884
18921
  return mainRoot;
18885
18922
  const host = probe.worktrees.find((worktree) => worktree.branch === base);
18886
18923
  return host?.path ?? mainRoot;
18887
18924
  }
18888
- worktreeCommand.command("cleanup").description("Plan (and with --apply execute) guarded worktree/branch cleanup for a workflow: merged-evidence-only branch deletion with " + "active-lease / checked-out / foreign / dirty / non-terminal refusals; dry-run by default (no fetch/prune/write), prints " + "`verdict | kind | ref | reason` (exit 0 valid dry-run / successful removals, 1 probe/mutation failure, 2 usage)").option("--workflow <id>", "Workflow id whose snapshot drives ownership and protected refs (required)").option("--harness <path>", "Harness dir override (default: process-harness discovery from the verified main worktree)").option("--apply", "Execute current remove rows: git worktree remove (never force; evidence-base hosts deferred) \u2192 re-probe/re-plan \u2192 git branch -d (never -D) from the evidence-base checkout \u2192 remote compare-and-delete \u2192 deferred integration worktree removal \u2192 re-probe/re-plan newly released local branches").option("--remote", "Include remote-branch candidates (refs/remotes/origin) with expected-OID compare-and-delete").option("--worktree <path>", "Limit worktree candidates to this path (repeatable); also asserts ownership for a released-lease worktree matched to its recorded branch", (value, previous) => [...previous, value], []).action((options) => {
18925
+ worktreeCommand.command("cleanup").description("Plan (and with --apply execute) guarded worktree/branch cleanup for a workflow: merged-evidence-only branch deletion with " + "active-lease / checked-out / foreign / dirty / non-terminal refusals; dry-run by default (no fetch/prune/write), prints " + "`verdict | kind | ref | reason` (exit 0 valid dry-run / successful removals, 1 probe/mutation failure, 2 usage)").option("--workflow <id>", "Workflow id whose snapshot drives ownership and protected refs (required)").option("--harness <path>", "Harness dir override (default: process-harness discovery from the verified main worktree)").option("--apply", "Execute current remove rows: git worktree remove (never force; evidence-base hosts deferred) \u2192 re-probe/re-plan \u2192 git branch -d (never -D) from the evidence-base checkout \u2192 remote compare-and-delete \u2192 deferred integration worktree removal \u2192 re-probe/re-plan newly released local branches").option("--remote", "Include remote-branch candidates (refs/remotes/origin) with expected-OID compare-and-delete").option("--worktree <path>", "Limit worktree candidates to this path (repeatable); also asserts ownership for a released-lease worktree matched to its recorded branch", (value, previous) => [...previous, value], []).option("--ignore-unreadable-snapshots", "Operator assertion: judge candidates against the readable snapshots only even when a sibling snapshot cannot be parsed at all (its declarations are unknown, so removals are otherwise withheld as cleanup.refuse.unreadable-snapshot)").action((options) => {
18889
18926
  try {
18890
18927
  if (!options.workflow) {
18891
- throw new SddScriptError("usage: worktree cleanup --workflow <id> [--harness <path>] [--apply] [--remote] [--worktree <path>]", 2);
18928
+ throw new SddScriptError("usage: worktree cleanup --workflow <id> [--harness <path>] [--apply] [--remote] [--worktree <path>] [--ignore-unreadable-snapshots]", 2);
18892
18929
  }
18893
18930
  const main = readMainWorktree();
18894
18931
  if (main === null)
@@ -18908,9 +18945,10 @@ worktreeCommand.command("cleanup").description("Plan (and with --apply execute)
18908
18945
  workflowRoot,
18909
18946
  workflowId: options.workflow
18910
18947
  };
18948
+ const ignoreUnreadableSiblings = options.ignoreUnreadableSnapshots === true;
18911
18949
  const probe1 = cleanupProbe(probeInput);
18912
18950
  const built1 = cleanupBuildFacts(probe1, scope, options.remote === true);
18913
- const plan1 = planWorktreeCleanup(probe1.selected, built1.facts);
18951
+ const plan1 = cleanupGuardUnreadableSiblings(planWorktreeCleanup(probe1.selected, built1.facts), probe1, ignoreUnreadableSiblings);
18914
18952
  cleanupPrintPlan(`worktree cleanup (workflow ${options.workflow}): plan`, plan1);
18915
18953
  if (options.apply !== true)
18916
18954
  return;
@@ -18943,7 +18981,7 @@ worktreeCommand.command("cleanup").description("Plan (and with --apply execute)
18943
18981
  }
18944
18982
  const probe2 = cleanupProbe(probeInput);
18945
18983
  const built2 = cleanupBuildFacts(probe2, scope, options.remote === true);
18946
- const plan2 = planWorktreeCleanup(probe2.selected, built2.facts);
18984
+ const plan2 = cleanupGuardUnreadableSiblings(planWorktreeCleanup(probe2.selected, built2.facts), probe2, ignoreUnreadableSiblings);
18947
18985
  cleanupPrintPlan(`worktree cleanup (workflow ${options.workflow}): post-removal re-plan`, plan2);
18948
18986
  for (const decision of plan2) {
18949
18987
  if (decision.verdict !== "remove")
@@ -18993,7 +19031,7 @@ worktreeCommand.command("cleanup").description("Plan (and with --apply execute)
18993
19031
  if (releasedBranches.size > 0) {
18994
19032
  const probe3 = cleanupProbe(probeInput);
18995
19033
  const built3 = cleanupBuildFacts(probe3, scope, options.remote === true);
18996
- const plan3 = planWorktreeCleanup(probe3.selected, built3.facts).filter((decision) => decision.kind === "local-branch" && releasedBranches.has(decision.ref));
19034
+ const plan3 = cleanupGuardUnreadableSiblings(planWorktreeCleanup(probe3.selected, built3.facts), probe3, ignoreUnreadableSiblings).filter((decision) => decision.kind === "local-branch" && releasedBranches.has(decision.ref));
18997
19035
  cleanupPrintPlan(`worktree cleanup (workflow ${options.workflow}): post-deferred-removal re-plan`, plan3);
18998
19036
  for (const decision of plan3) {
18999
19037
  if (decision.verdict !== "remove")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mstar-harness/cli",
3
- "version": "3.9.0",
3
+ "version": "3.9.1",
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": {