@feigi/fleet-ctl 3.30.16 → 3.30.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.30.16",
3
+ "version": "3.30.18",
4
4
  "description": "Agent fleet: run-team controller, merge bot, PR reviewer, and the ticket pipeline they share",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -692,10 +692,11 @@ fi
692
692
  # `wt_counts` establishes the listing is complete before its absences are
693
693
  # trusted — the registry entries on disk counted against the linked worktrees
694
694
  # git listed, recounted before refusing, the direction of a standing
695
- # disagreement named — and leaves that listing in `$wt_list` for the filter
696
- # below. Every refusal is this probe's unknown, never a `die`: probes 1 and 2
697
- # may already have established a verdict. A listing git could not produce at
698
- # all is named as one, with git's own cause.
695
+ # disagreement named, and every unlisted `.worktrees/*` pointer checked to
696
+ # name an admin dir the registry still holds — and leaves that listing in
697
+ # `$wt_list` for the filter below. Every refusal is this probe's unknown,
698
+ # never a `die`: probes 1 and 2 may already have established a verdict. A
699
+ # listing git could not produce at all is named as one, with git's own cause.
699
700
  if wt_counts; then :; else
700
701
  case $? in
701
702
  2) add_unknown "local" "could not read the worktree list for #$n: $wt_why" ;;
@@ -112,11 +112,13 @@ export function resolveMainCheckout(cwd = process.cwd(), env = process.env) {
112
112
 
113
113
  export const baselinePath = (root) => join(root, ".fleet", BASELINE_FILE);
114
114
 
115
- // A content hash of one path porcelain named, relative to the main checkout.
116
- // Gone is an answer (a deleted tracked file is a ` D` entry), and so is a
117
- // directory (an untracked nested repository is listed as `dir/`); anything
118
- // else that fails to read throws, and the caller's answer is `unknown`.
119
- function hashPath(root, rel) {
115
+ // A content hash of one path porcelain named, relative to `root`. Gone is an
116
+ // answer (a deleted tracked file is a ` D` entry); anything else that fails
117
+ // to read throws, and the caller's answer is `unknown`. A directory holding
118
+ // `.git` is a nested repository (an untracked one is listed as `dir/`, a
119
+ // submodule by its own path), hashed as `nestedHash` below; any other
120
+ // directory hashes as `dir`.
121
+ function hashPath(root, rel, env) {
120
122
  const abs = join(root, rel);
121
123
  let st;
122
124
  try {
@@ -125,13 +127,38 @@ function hashPath(root, rel) {
125
127
  if (e?.code === "ENOENT" || e?.code === "ENOTDIR") return "absent";
126
128
  throw e;
127
129
  }
128
- const sha = (buf) => createHash("sha256").update(buf).digest("hex");
129
130
  if (st.isSymbolicLink()) return `link:${sha(readlinkSync(abs))}`;
130
- if (st.isDirectory()) return "dir";
131
+ if (st.isDirectory()) {
132
+ try {
133
+ lstatSync(join(abs, ".git"));
134
+ } catch (e) {
135
+ if (e?.code === "ENOENT") return "dir";
136
+ throw e;
137
+ }
138
+ return nestedHash(abs, env);
139
+ }
131
140
  if (st.isFile()) return `sha256:${sha(readFileSync(abs))}`;
132
141
  return "other";
133
142
  }
134
143
 
144
+ const sha = (buf) => createHash("sha256").update(buf).digest("hex");
145
+
146
+ // A nested repository's own snapshot — its porcelain entries and the hash of
147
+ // every path they name, so a further edit to a file already dirty in it moves
148
+ // the hash where its status line would not — folded with its HEAD, so a
149
+ // commit in it moves the hash too. A commitless repository's HEAD is the
150
+ // branch it names. Nothing is left out: the run's bookkeeping is the main
151
+ // checkout's two paths, not a nested repository's. Any git that fails
152
+ // throws: `unknown`, never a hash that reads clean.
153
+ function nestedHash(abs, env) {
154
+ const now = entriesAt(abs, env, new Set());
155
+ if (!now.ok) throw new Error(now.why);
156
+ let head = git("git rev-parse HEAD", ["rev-parse", "-q", "--verify", "HEAD^{commit}"], abs, env);
157
+ if (!head.ok) head = git("git symbolic-ref HEAD", ["symbolic-ref", "-q", "HEAD"], abs, env);
158
+ if (!head.ok) throw new Error(head.why);
159
+ return `repo:${sha(`${head.stdout}${formatBaseline(now.entries)}`)}`;
160
+ }
161
+
135
162
  /**
136
163
  * The main checkout as it stands: `{ok, entries}` — a Map from each porcelain
137
164
  * entry (`XY path`) to its path's hash, the run's own bookkeeping left out
@@ -141,6 +168,11 @@ function hashPath(root, rel) {
141
168
  * `--no-renames` so every entry names exactly one path.
142
169
  */
143
170
  export function snapshot(root, env = process.env) {
171
+ return entriesAt(root, env, RUN_BOOKKEEPING);
172
+ }
173
+
174
+ // `snapshot` of the repository at `root`, leaving out the paths in `skip`.
175
+ function entriesAt(root, env, skip) {
144
176
  const r = git("git status --porcelain -uall", ["--no-optional-locks", "status", "--porcelain", "-uall", "-z", "--no-renames"], root, env);
145
177
  if (!r.ok) return r;
146
178
  const entries = new Map();
@@ -148,9 +180,9 @@ export function snapshot(root, env = process.env) {
148
180
  if (!line) continue;
149
181
  if (line.length < 4 || line[2] !== " ") return { ok: false, why: `git status printed an entry it does not document: ${JSON.stringify(line)}` };
150
182
  const rel = line.slice(3);
151
- if (RUN_BOOKKEEPING.has(rel)) continue;
183
+ if (skip.has(rel)) continue;
152
184
  try {
153
- entries.set(line, hashPath(root, rel));
185
+ entries.set(line, hashPath(root, rel, env));
154
186
  } catch (e) {
155
187
  return { ok: false, why: `cannot hash ${rel}: ${e?.code ?? e?.message ?? e}` };
156
188
  }
package/scripts/net.sh CHANGED
@@ -388,9 +388,12 @@ net_git() {
388
388
  # reap.sh's registry recount (worktree.sh's `wt_counts`) reads the very
389
389
  # corruption this detached run erases:
390
390
  # with the entry gone, the registry count drops to match the listing's
391
- # linked count, in lockstep, and the guard a stray `git worktree add`
392
- # mid-run is built to catch sees no mismatch to refuse on — both branches
393
- # in that fixture's pass were wrongly reaped. A bare foreground fetch
391
+ # linked count, in lockstep, and the COUNT comparison a stray `git worktree
392
+ # add` mid-run is built to catch sees no mismatch to refuse on — both
393
+ # branches in that fixture's pass were wrongly reaped. (The pointer
394
+ # cross-check `wt_counts` now ends in refuses that state for a worktree
395
+ # under `.worktrees/`, on its own `.git` file, which this run does not
396
+ # touch.) A bare foreground fetch
394
397
  # usually wins this race (the detached child has not run yet by the time
395
398
  # the caller reads the registry); this function's own extra fork/wait
396
399
  # overhead was measured to flip the outcome reliably. `maintenance.auto`
package/scripts/reap.sh CHANGED
@@ -627,7 +627,10 @@ wt_reg_state() {
627
627
  # (a) COUNT. The `gitdir`/admin-dir/registry-file faults DROP the entry, so
628
628
  # fewer linked worktrees are listed than are registered under
629
629
  # `<git-common-dir>/worktrees/`. worktree.sh's `wt_counts` answers that,
630
- # with its recount and the measurements behind both.
630
+ # with its recount and the measurements behind both. It also answers the
631
+ # registry or an entry removed OUTRIGHT, which drops both counts in step and
632
+ # so agrees: the `.git` pointer of the worktree it orphans still names the
633
+ # missing admin dir, and `wt_counts` refuses on that.
631
634
  #
632
635
  # (b) NULL HEAD. The `HEAD` faults keep the entry, so the counts AGREE and
633
636
  # (a) sees nothing: git lists it with the null object id and no `branch`
@@ -819,7 +822,8 @@ for b in $gone_branches; do
819
822
  fi
820
823
 
821
824
  # The listing is read per branch, through worktree.sh's `wt_counts`, which
822
- # counts the registry, reads the listing, checks the two agree, and leaves
825
+ # counts the registry, reads the listing, checks the two agree and that no
826
+ # `.worktrees/*` pointer names an admin dir the registry lacks, and leaves
823
827
  # that listing in `$wt_list` for the lookup below — so the lookup scans the
824
828
  # very listing the counts validated.
825
829
  #
@@ -294,9 +294,10 @@ git rev-parse --verify "$base_rev" >/dev/null || die "$base does not resolve"
294
294
  # disk against the linked worktrees git listed, recounts before refusing, and
295
295
  # names the direction a standing disagreement runs. Each refusal is this
296
296
  # script's precondition `die`; a listing git could not produce at all names
297
- # git's own cause. Absent entirely is fine and answers nothing: zero registry
298
- # entries against the main worktree alone is a match, so the release goes
299
- # through. The listing it validated is the `$wt_list` every lookup below scans.
297
+ # git's own cause. Absent entirely is fine and answers nothing while no
298
+ # `.worktrees/*` pointer names an entry in it: zero registry entries against
299
+ # the main worktree alone is a match, so the release goes through. The listing
300
+ # it validated is the `$wt_list` every lookup below scans.
300
301
  if wt_counts; then :; else
301
302
  case $? in
302
303
  2) die "could not read the worktree list for #$issue: $wt_why" ;;
@@ -50,6 +50,8 @@
50
50
  # only thing any caller needs: this is a path the reader cannot hand back to the
51
51
  # filesystem byte for byte.
52
52
  wt_nl=$(printf '\001')
53
+ # A carriage return, which git drops from the end of a `.git` pointer.
54
+ wt_cret=$(printf '\r')
53
55
 
54
56
  # Does $1 carry the byte `wt_listing` substituted for a newline?
55
57
  #
@@ -664,9 +666,11 @@ wt_registry_root() {
664
666
  # listing — measured. So count instead: one registry entry on disk per linked
665
667
  # worktree, against what git reported.
666
668
  #
667
- # Absent entirely answers nothing: a repo whose worktrees were removed and
669
+ # Absent entirely answers nothing here: a repo whose worktrees were removed and
668
670
  # pruned (or never existed) has no `worktrees` dir, and zero entries against
669
- # the main worktree alone is a match. Present but unreadable is a refusal, and
671
+ # the main worktree alone is a match. A registry or entry removed OUTRIGHT
672
+ # under a live worktree drops both counts in step, so they agree over it too;
673
+ # `wt_count_pointers` is what refuses that. Present but unreadable is a refusal, and
670
674
  # not redundant with the count: unreadable, the glob below expands to nothing,
671
675
  # and zero-on-disk would AGREE with the empty listing git returns for the same
672
676
  # reason. `-d` joins `-r` and `-x` there because a registry replaced by a
@@ -744,6 +748,128 @@ wt_count_pair() {
744
748
  wt_count_linked || return 1
745
749
  }
746
750
 
751
+ # Is any fleet worktree standing with its registration removed under it? 0
752
+ # when none is; 1 with `$wt_why` naming the first `.worktrees/*` pointer git
753
+ # does not list that names an admin dir the registry does not hold, or that
754
+ # could not be read. Reads `$wt_list` for the main checkout and the listed
755
+ # paths, and `$wt_root` for the registry, both as `wt_count_pair` left them.
756
+ #
757
+ # The counts cannot see this: git lists a linked worktree only from its admin
758
+ # dir, so a registry `rm -rf`'d whole, or one entry removed, drops the entry
759
+ # from the registry count AND the listing in step. They agree, the worktree's
760
+ # branch reads as held by nothing, and `git branch -D` deletes it too — git's
761
+ # own "used by worktree" refusal reads the same admin state (measured, git
762
+ # 2.50.1, for both shapes and for an entry emptied to a bare directory, which
763
+ # the registry count skips and git ignores). Nothing in the registry names the
764
+ # orphan any more, so the cross-check reads the other end of the link: the
765
+ # `.git` file in each `.worktrees/*` directory, the layout claim-ticket.sh
766
+ # creates every fleet worktree in.
767
+ #
768
+ # A directory git LISTS is skipped first: its admin dir exists, since that is
769
+ # where git read it from, so its branch is already held in the listing, and
770
+ # whatever else is wrong with it is the caller's per-worktree guards' to
771
+ # answer. Its path is matched byte for byte against the listing's, under the
772
+ # main checkout path the listing itself spells. Of the rest, only a pointer
773
+ # into THIS registry is answered for: its admin dir's parent is named
774
+ # `worktrees` and sits in the same directory (`-ef`) as `$wt_root`'s. Anything
775
+ # else under `.worktrees/` — a directory with no `.git`, a `.git` DIRECTORY (a
776
+ # clone, not a linked worktree), a pointer into another repo — is not a linked
777
+ # worktree of this repo and is skipped. A pointer is read the way git reads it
778
+ # (git 2.50.1): `gitdir: <path>` on its first line, a trailing CR dropped, a
779
+ # relative path resolved against the worktree directory. An unlisted
780
+ # directory, pointer or named admin dir that cannot be read is a refusal: what
781
+ # it names is unknown, and unknown is never "registered".
782
+ #
783
+ # Ceilings, left open on purpose. A `.worktrees` directory that cannot be
784
+ # listed is skipped, not refused: every worktree in it that git still lists is
785
+ # answered by the caller's own guards, each with its own remedy, and an
786
+ # unlisted one behind it needs that fault and a removed registry entry at once.
787
+ # And only `.worktrees/*` itself is read, the depth claim-ticket.sh creates
788
+ # worktrees at: one nested deeper (`.worktrees/feature/x`) is not, since
789
+ # reaching it means walking every directory under `.worktrees/` that holds no
790
+ # `.git` — operators' scratch trees included — on every count.
791
+ # shellcheck disable=SC2034
792
+ wt_count_pointers() {
793
+ wt_cp_main=${wt_list%%"
794
+ "*}
795
+ case $wt_cp_main in
796
+ "worktree "?*) wt_cp_main=${wt_cp_main#worktree } ;;
797
+ *)
798
+ wt_why="git's listing does not open with the main checkout's path"
799
+ return 1
800
+ ;;
801
+ esac
802
+ if nl_path "$wt_cp_main"; then
803
+ wt_why="the main checkout's path carries a newline, so its .worktrees directory cannot be named"
804
+ return 1
805
+ fi
806
+ wt_cp_dir=$wt_cp_main/.worktrees
807
+ [ -d "$wt_cp_dir" ] && [ -r "$wt_cp_dir" ] && [ -x "$wt_cp_dir" ] || return 0
808
+ for wt_cp_wt in "$wt_cp_dir"/*; do
809
+ [ -d "$wt_cp_wt" ] || continue
810
+ case "
811
+ $wt_list
812
+ " in
813
+ *"
814
+ worktree $wt_cp_wt
815
+ "*) continue ;;
816
+ esac
817
+ [ -x "$wt_cp_wt" ] || {
818
+ wt_why="worktree directory $wt_cp_wt is not in git's listing and could not be searched, so whether it has lost its registration is unknown"
819
+ return 1
820
+ }
821
+ wt_cp_ptr=$wt_cp_wt/.git
822
+ [ -f "$wt_cp_ptr" ] || continue
823
+ wt_cp_line=
824
+ # `|| :` because a last line with no newline fails `read` with the line read.
825
+ if ! [ -r "$wt_cp_ptr" ] || ! { IFS= read -r wt_cp_line || :; } 2>/dev/null <"$wt_cp_ptr"; then
826
+ wt_why="worktree pointer $wt_cp_ptr could not be read, and git does not list its worktree, so whether its admin dir is registered is unknown"
827
+ return 1
828
+ fi
829
+ wt_cp_line=${wt_cp_line%"$wt_cret"}
830
+ case $wt_cp_line in
831
+ "gitdir: "?*) wt_cp_admin=${wt_cp_line#gitdir: } ;;
832
+ *)
833
+ wt_why="worktree pointer $wt_cp_ptr names no admin dir (no gitdir: line), and git does not list its worktree, so whether it is registered is unknown"
834
+ return 1
835
+ ;;
836
+ esac
837
+ case $wt_cp_admin in
838
+ /*) ;;
839
+ *) wt_cp_admin=$wt_cp_wt/$wt_cp_admin ;;
840
+ esac
841
+ while :; do
842
+ case $wt_cp_admin in
843
+ ?*/) wt_cp_admin=${wt_cp_admin%/} ;;
844
+ *) break ;;
845
+ esac
846
+ done
847
+ wt_cp_reg=${wt_cp_admin%/*}
848
+ [ "${wt_cp_reg##*/}" = worktrees ] || continue
849
+ # shellcheck disable=SC3013,SC2319 # -ef as in wt_linkage; the else's $? is the `[ -ef ]` test's own rc, read before anything else runs, to fail closed on rc>=2
850
+ if [ "${wt_cp_reg%/*}/" -ef "${wt_root%/*}/" ]; then :; else
851
+ wt_cp_rc=$?
852
+ [ "$wt_cp_rc" -ge 2 ] || continue
853
+ wt_why="could not compare the repo $wt_cp_ptr points into with ${wt_root%/*} (test -ef exited $wt_cp_rc), so whether it names this registry is unknown"
854
+ return 1
855
+ fi
856
+ if ! [ -d "$wt_cp_admin" ]; then
857
+ wt_why="worktree pointer $wt_cp_ptr names admin dir $wt_cp_admin, which is missing from the worktree registry $wt_root — git lists no worktree there, so no absence it reports can be trusted; inspect the directory and, once its work is saved, remove it by hand"
858
+ return 1
859
+ fi
860
+ # `ls`'s STATUS, not just its output: an admin dir that cannot be listed is
861
+ # not an empty one, and `2>/dev/null` alone reads both as "nothing to say".
862
+ if ! wt_cp_ls=$(ls -A "$wt_cp_admin" 2>/dev/null); then
863
+ wt_why="worktree pointer $wt_cp_ptr names admin dir $wt_cp_admin, which could not be listed, and git does not list its worktree, so whether it is registered is unknown"
864
+ return 1
865
+ elif [ -z "$wt_cp_ls" ]; then
866
+ wt_why="worktree pointer $wt_cp_ptr names admin dir $wt_cp_admin, an empty directory git does not list — git lists no worktree there, so no absence it reports can be trusted; inspect the directory and, once its work is saved, remove it by hand"
867
+ return 1
868
+ fi
869
+ done
870
+ return 0
871
+ }
872
+
747
873
  # Is the listing COMPLETE — does git list exactly as many linked worktrees as
748
874
  # the registry holds entries? A listing that silently dropped an entry hands
749
875
  # every lookup over it "no worktree" for a branch a live worktree holds, at
@@ -753,15 +879,18 @@ wt_count_pair() {
753
879
  # the caller's lookups then scan the very listing the counts validated. Sets
754
880
  # `$wt_registered`, `$wt_linked` and `$wt_root`.
755
881
  #
756
- # 0: the counts agree.
882
+ # 0: the counts agree, and every fleet worktree's pointer names a registered
883
+ # admin dir.
757
884
  # 1: refused — `$wt_why` names the cause: the common directory or the
758
- # registry could not be read, the listing could not be counted, or the
759
- # counts still disagree, named by the DIRECTION observed. FEWER listed than
760
- # registered is git dropping an entry it could not read — the fault this
761
- # check exists to catch. MORE listed than registered is the reverse, the
762
- # registry read missing entries, which under a parallel fleet is a
763
- # sibling's `git worktree add` landing between the two reads. One message
764
- # cannot serve both: they send the reader to opposite places.
885
+ # registry could not be read, the listing could not be counted, the
886
+ # counts still disagree, or a `.worktrees/*` pointer names an admin dir the
887
+ # registry does not hold (`wt_count_pointers`). A standing disagreement is
888
+ # named by the DIRECTION observed. FEWER listed than registered is git
889
+ # dropping an entry it could not read — the fault this check exists to
890
+ # catch. MORE listed than registered is the reverse, the registry read
891
+ # missing entries, which under a parallel fleet is a sibling's `git
892
+ # worktree add` landing between the two reads. One message cannot serve
893
+ # both: they send the reader to opposite places.
765
894
  # 2: the listing itself could not be read — `$wt_why` is `wt_listing`'s cause,
766
895
  # flattened to one line, and `$wt_err` holds it as read.
767
896
  #
@@ -805,7 +934,7 @@ wt_counts() {
805
934
  wt_why="git listed $wt_linked worktrees but only $wt_registered registry entries were counted in $wt_root — the registry read missed entries git can see, so no absence it reports can be trusted"
806
935
  return 1
807
936
  fi
808
- return 0
937
+ wt_count_pointers
809
938
  }
810
939
 
811
940
  # Does $1's `.git` linkage answer for $1 itself? 0 when it does; 1 with