automata-cli 0.7.0-develop.321 → 0.7.0-develop.324

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.
Files changed (2) hide show
  1. package/dist/index.js +77 -22
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -815,10 +815,14 @@ function listRemoteBranches() {
815
815
  function createBranchAtHead(branch) {
816
816
  return gitCommand(["checkout", "-b", branch]);
817
817
  }
818
+ function pathIsIgnored(path) {
819
+ return run2("git", ["check-ignore", "-q", "--", path]).status === 0;
820
+ }
818
821
  function stageAllExcept(excludePaths) {
822
+ const needed = excludePaths.filter((path) => !pathIsIgnored(path));
819
823
  const args = ["add", "-A"];
820
- if (excludePaths.length > 0) {
821
- args.push("--", ".", ...excludePaths.map((path) => `:(exclude)${path}`));
824
+ if (needed.length > 0) {
825
+ args.push("--", ".", ...needed.map((path) => `:(exclude)${path}`));
822
826
  }
823
827
  return gitCommand(args);
824
828
  }
@@ -3763,6 +3767,12 @@ function rescueUncommittedChanges(options, now) {
3763
3767
  );
3764
3768
  return { kind: "would-rescue", branch: target.branch, createdBranch: target.createdBranch };
3765
3769
  }
3770
+ const staged = stageAllExcept([RUN_LOCK_RELATIVE_PATH]);
3771
+ if (!staged.ok) {
3772
+ options.log(` rescue FAILED to stage the changes: ${staged.stderr}
3773
+ `);
3774
+ return { kind: "failed", step: "stage", detail: staged.stderr };
3775
+ }
3766
3776
  if (target.createdBranch) {
3767
3777
  const created = createBranchAtHead(target.branch);
3768
3778
  if (!created.ok) {
@@ -3771,17 +3781,18 @@ function rescueUncommittedChanges(options, now) {
3771
3781
  return { kind: "failed", step: "branch", detail: created.stderr };
3772
3782
  }
3773
3783
  }
3774
- const staged = stageAllExcept([RUN_LOCK_RELATIVE_PATH]);
3775
- if (!staged.ok) {
3776
- options.log(` rescue FAILED to stage the changes: ${staged.stderr}
3777
- `);
3778
- return { kind: "failed", step: "stage", detail: staged.stderr };
3779
- }
3784
+ const left = target.createdBranch ? { branch: target.branch, createdBranch: target.branch } : { branch: target.branch };
3780
3785
  const committed = commitStaged(`chore(automata): rescue uncommitted work from ${target.source}`);
3781
3786
  if (!committed.ok) {
3782
- options.log(` rescue FAILED to commit: ${committed.stderr}
3787
+ options.log(` rescue FAILED to commit on ${target.branch}: ${committed.stderr}
3783
3788
  `);
3784
- return { kind: "failed", step: "commit", detail: committed.stderr };
3789
+ if (target.createdBranch) {
3790
+ options.log(
3791
+ ` rescue ${target.branch} was created by this rescue and carries none of the work; it is left in the checkout
3792
+ `
3793
+ );
3794
+ }
3795
+ return { kind: "failed", step: "commit", detail: committed.stderr, ...left };
3785
3796
  }
3786
3797
  const pushed = pushSetUpstream(target.branch);
3787
3798
  if (!pushed.ok) {
@@ -3790,7 +3801,7 @@ function rescueUncommittedChanges(options, now) {
3790
3801
  rescue the work is committed locally on ${target.branch}; push it by hand before it is lost
3791
3802
  `
3792
3803
  );
3793
- return { kind: "failed", step: "push", detail: pushed.stderr };
3804
+ return { kind: "failed", step: "push", detail: pushed.stderr, ...left };
3794
3805
  }
3795
3806
  let existing;
3796
3807
  try {
@@ -3800,7 +3811,7 @@ function rescueUncommittedChanges(options, now) {
3800
3811
  ` rescue committed and pushed ${target.branch}, but could not check for an open PR: ${err.message}
3801
3812
  `
3802
3813
  );
3803
- return { kind: "failed", step: "pr", detail: err.message };
3814
+ return { kind: "failed", step: "pr", detail: err.message, ...left };
3804
3815
  }
3805
3816
  if (existing !== null) {
3806
3817
  options.log(
@@ -3841,7 +3852,7 @@ function rescueUncommittedChanges(options, now) {
3841
3852
  ` rescue committed and pushed ${target.branch}, but could not open a draft PR: ${err.message}
3842
3853
  `
3843
3854
  );
3844
- return { kind: "failed", step: "pr", detail: err.message };
3855
+ return { kind: "failed", step: "pr", detail: err.message, ...left };
3845
3856
  }
3846
3857
  }
3847
3858
  function prepareBase(options) {
@@ -3866,12 +3877,13 @@ function prepareBase(options) {
3866
3877
  `);
3867
3878
  return { ok: true };
3868
3879
  }
3869
- function collectCandidates(options) {
3880
+ function collectCandidates(options, rescueBranch) {
3870
3881
  const remote = listRemoteBranches();
3871
3882
  if (remote === null) return null;
3872
3883
  const remoteNames = new Set(remote);
3873
3884
  const current = getCurrentBranch();
3874
3885
  const untouchable = /* @__PURE__ */ new Set([options.baseBranch, current, ...options.protectedBranches]);
3886
+ if (rescueBranch !== null) untouchable.add(rescueBranch);
3875
3887
  return listLocalBranches().filter(
3876
3888
  (branch) => !untouchable.has(branch) && !remoteNames.has(branch)
3877
3889
  );
@@ -3967,8 +3979,8 @@ function pruneCandidate(branch, options) {
3967
3979
  return { kind: "rescued", branch, pr: null, prUrl: null };
3968
3980
  }
3969
3981
  }
3970
- function prune(options) {
3971
- const candidates = collectCandidates(options);
3982
+ function prune(options, rescueBranch) {
3983
+ const candidates = collectCandidates(options, rescueBranch);
3972
3984
  if (candidates === null) {
3973
3985
  options.log(
3974
3986
  " prune skipped: could not list origin's branches, so no branch can be shown to have no remote\n"
@@ -3988,12 +4000,46 @@ function runRepoHygiene(options, now = /* @__PURE__ */ new Date()) {
3988
4000
  options.log(options.dryRun ? "\nPre-flight (dry run):\n" : "\nPre-flight:\n");
3989
4001
  const rescue = rescueUncommittedChanges(options, now);
3990
4002
  const base = prepareBase(options);
3991
- const { outcomes, remoteUnreadable } = prune(options);
4003
+ const { outcomes, remoteUnreadable } = prune(options, rescueCreatedBranch(rescue));
3992
4004
  const degraded = rescue.kind === "failed" || !base.ok || remoteUnreadable || outcomes.some(
3993
4005
  (outcome) => outcome.kind === "kept" && outcome.reason !== "open-pr" || outcome.kind === "rescued" && outcome.pr === null
3994
4006
  );
3995
4007
  return { rescue, base, prunes: outcomes, degraded };
3996
4008
  }
4009
+ function rescueCreatedBranch(rescue) {
4010
+ switch (rescue.kind) {
4011
+ case "rescued":
4012
+ case "would-rescue":
4013
+ return rescue.createdBranch ? rescue.branch : null;
4014
+ case "failed":
4015
+ return rescue.createdBranch ?? null;
4016
+ default:
4017
+ return null;
4018
+ }
4019
+ }
4020
+ function describePreflightFailures(report) {
4021
+ const causes = [];
4022
+ if (report.rescue.kind === "failed") {
4023
+ causes.push(
4024
+ `the rescue failed at the ${report.rescue.step} step (${describeRescueRemains(report.rescue)}): ${report.rescue.detail}`
4025
+ );
4026
+ }
4027
+ if (!report.base.ok) {
4028
+ causes.push(`the base branch ${report.base.step} failed: ${report.base.detail}`);
4029
+ }
4030
+ return causes;
4031
+ }
4032
+ function describeRescueRemains(rescue) {
4033
+ if (rescue.branch === void 0) return "the tree is still dirty";
4034
+ switch (rescue.step) {
4035
+ case "push":
4036
+ return `the work is committed on ${rescue.branch} but not pushed`;
4037
+ case "pr":
4038
+ return `the work is committed and pushed on ${rescue.branch}, without a draft pull request`;
4039
+ default:
4040
+ return `the tree is still dirty and ${rescue.branch} carries none of it`;
4041
+ }
4042
+ }
3997
4043
 
3998
4044
  // src/run/operationLog.ts
3999
4045
  import {
@@ -4787,7 +4833,10 @@ function refuseBeforeRun(base, marker, detail, markerText) {
4787
4833
  }
4788
4834
  return { ...base, outcome: "failed", detail };
4789
4835
  }
4790
- async function processItem(planned, settings, silent) {
4836
+ function preflightSuffix(causes) {
4837
+ return causes.length === 0 ? "" : ` [pre-flight: ${causes.join("; ")}]`;
4838
+ }
4839
+ async function processItem(planned, settings, silent, preflightCauses) {
4791
4840
  progress(`
4792
4841
  ${itemLabel(planned)} ${planned.turn}: ${planned.reason}
4793
4842
  `);
@@ -4817,9 +4866,14 @@ ${itemLabel(planned)} ${planned.turn}: ${planned.reason}
4817
4866
  };
4818
4867
  const prepared = item.turn === "issue-discuss" ? prepareBaseBranch(item.branch) : preparePrBranch(item.branch);
4819
4868
  if (!prepared.ok) {
4820
- progress(` skipped: ${prepared.reason} \u2014 ${prepared.detail}
4869
+ const why = preflightSuffix(preflightCauses);
4870
+ progress(` skipped: ${prepared.reason} \u2014 ${prepared.detail}${why}
4821
4871
  `);
4822
- return { ...base, outcome: "skipped", detail: `${prepared.reason}: ${prepared.detail}` };
4872
+ return {
4873
+ ...base,
4874
+ outcome: "skipped",
4875
+ detail: `${prepared.reason}: ${prepared.detail}${why}`
4876
+ };
4823
4877
  }
4824
4878
  claimIssue(item, settings);
4825
4879
  if (item.turn === "pr-work" && item.pr !== null && item.prNeedsAssignment) {
@@ -5110,6 +5164,7 @@ ${describePlan(decisions)}`;
5110
5164
  }
5111
5165
  const reports = [];
5112
5166
  const deferred = [];
5167
+ const preflightCauses = describePreflightFailures(hygiene);
5113
5168
  let runsUsed = 0;
5114
5169
  for (const item of items) {
5115
5170
  if (settings.maxRuns > 0 && runsUsed >= settings.maxRuns) {
@@ -5118,7 +5173,7 @@ ${describePlan(decisions)}`;
5118
5173
  }
5119
5174
  let report;
5120
5175
  try {
5121
- report = await processItem(item, settings, options.silent === true);
5176
+ report = await processItem(item, settings, options.silent === true, preflightCauses);
5122
5177
  } catch (err) {
5123
5178
  progress(` failed: ${err.message}
5124
5179
  `);
@@ -5272,7 +5327,7 @@ function describeRescue(rescue) {
5272
5327
  case "would-rescue":
5273
5328
  return `would rescue onto ${rescue.branch}`;
5274
5329
  case "failed":
5275
- return `${rescue.step} failed \u2014 ${rescue.detail}; the tree is still dirty and nothing was discarded`;
5330
+ return `${rescue.step} failed \u2014 ${rescue.detail}; ${describeRescueRemains(rescue)}; nothing was discarded`;
5276
5331
  }
5277
5332
  }
5278
5333
  function describePrune(outcome) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "automata-cli",
3
- "version": "0.7.0-develop.321",
3
+ "version": "0.7.0-develop.324",
4
4
  "description": "Automata CLI tool",
5
5
  "type": "module",
6
6
  "engines": {