@staff0rd/assist 0.1129.1 → 0.1130.0

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/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.1129.1",
9
+ version: "0.1130.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -4378,22 +4378,22 @@ async function postDocsRefresh(req, res) {
4378
4378
  respondJson(res, 200, await requestDocsRefresh(orm, getOrigin()));
4379
4379
  }
4380
4380
 
4381
- // src/commands/backlog/web/listNoteRepos.ts
4381
+ // src/commands/backlog/web/listCloneBaseRepos.ts
4382
4382
  import { existsSync as existsSync12, readdirSync as readdirSync2, statSync as statSync4 } from "fs";
4383
4383
  import { join as join12 } from "path";
4384
4384
  function hasGitDirectory(dir) {
4385
4385
  const gitPath = join12(dir, ".git");
4386
4386
  return existsSync12(gitPath) && statSync4(gitPath).isDirectory();
4387
4387
  }
4388
- function listNoteRepos(baseDir) {
4388
+ function listCloneBaseRepos(baseDir) {
4389
4389
  if (!existsSync12(baseDir)) return [];
4390
4390
  return readdirSync2(baseDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => ({ name: entry.name, cwd: join12(baseDir, entry.name) })).filter((repo) => hasGitDirectory(repo.cwd)).sort((a, b) => a.name.localeCompare(b.name));
4391
4391
  }
4392
4392
 
4393
- // src/commands/backlog/web/getNoteRepos.ts
4394
- function getNoteRepos(_req, res) {
4393
+ // src/commands/backlog/web/getCloneBaseRepos.ts
4394
+ function getCloneBaseRepos(_req, res) {
4395
4395
  const baseDir = expandTilde(loadConfig().clone.baseDir);
4396
- respondJson(res, 200, { repos: listNoteRepos(baseDir) });
4396
+ respondJson(res, 200, { repos: listCloneBaseRepos(baseDir) });
4397
4397
  }
4398
4398
 
4399
4399
  // src/commands/backlog/web/getRepoLocation.ts
@@ -13500,8 +13500,8 @@ function subsequenceScore(text18, query) {
13500
13500
  function scoreFilePath(path128, query) {
13501
13501
  const needle = query.trim().toLowerCase();
13502
13502
  if (!needle) return 0;
13503
- const basename38 = path128.slice(path128.lastIndexOf("/") + 1);
13504
- const inBasename = subsequenceScore(basename38, needle);
13503
+ const basename39 = path128.slice(path128.lastIndexOf("/") + 1);
13504
+ const inBasename = subsequenceScore(basename39, needle);
13505
13505
  if (inBasename !== null) return BASENAME_WEIGHT + inBasename;
13506
13506
  return subsequenceScore(path128, needle);
13507
13507
  }
@@ -18625,7 +18625,7 @@ var routes2 = {
18625
18625
  "GET /api/daemon-log": daemonLogTail,
18626
18626
  "GET /api/items": listItems,
18627
18627
  "POST /api/items": postItem,
18628
- "GET /api/note-repos": getNoteRepos,
18628
+ "GET /api/clone-base-repos": getCloneBaseRepos,
18629
18629
  "POST /api/note-session": postNoteSession,
18630
18630
  "GET /api/backlog/summary": getBacklogSummary,
18631
18631
  "GET /api/backlog/docs-refresh": getDocsRefresh,
@@ -19302,6 +19302,10 @@ function readWorktreeRegistry() {
19302
19302
  const data = loadJson(REGISTRY_FILE);
19303
19303
  return Object.entries(data).filter(([, record3]) => !record3.reaped).map(([path128, { reaped: _reaped, ...record3 }]) => ({ path: path128, ...record3 }));
19304
19304
  }
19305
+ function readReapedWorktreeRegistry() {
19306
+ const data = loadJson(REGISTRY_FILE);
19307
+ return Object.entries(data).filter(([, record3]) => record3.reaped).map(([path128, { reaped: _reaped, ...record3 }]) => ({ path: path128, ...record3 }));
19308
+ }
19305
19309
  function worktreeAttributionIncludingReaped(path128) {
19306
19310
  const record3 = loadJson(REGISTRY_FILE)[path128];
19307
19311
  return record3 ? { clone: record3.clone, origin: record3.origin } : void 0;
@@ -33848,13 +33852,13 @@ function buildTree(csprojPath, repoRoot3, visited = /* @__PURE__ */ new Set()) {
33848
33852
  }
33849
33853
  function collectAllDeps(node) {
33850
33854
  const result = /* @__PURE__ */ new Set();
33851
- function walk2(n) {
33855
+ function walk3(n) {
33852
33856
  for (const child2 of n.children) {
33853
33857
  result.add(child2.path);
33854
- walk2(child2);
33858
+ walk3(child2);
33855
33859
  }
33856
33860
  }
33857
- walk2(node);
33861
+ walk3(node);
33858
33862
  return result;
33859
33863
  }
33860
33864
 
@@ -60766,7 +60770,7 @@ function rearmStoppedSessions(sessions, notify2) {
60766
60770
 
60767
60771
  // src/commands/sessions/daemon/worktree/reconcileWorktreesOnRestore.ts
60768
60772
  import { existsSync as existsSync112 } from "fs";
60769
- import { basename as basename37 } from "path";
60773
+ import { basename as basename38 } from "path";
60770
60774
 
60771
60775
  // src/commands/sessions/daemon/worktree/accountedTrees.ts
60772
60776
  function accountedTrees(sessions) {
@@ -60838,6 +60842,96 @@ function logVanishedTree(sessions, path128) {
60838
60842
  );
60839
60843
  }
60840
60844
 
60845
+ // src/commands/sessions/daemon/worktree/leftoverContents.ts
60846
+ import { lstatSync, readdirSync as readdirSync30 } from "fs";
60847
+ import { join as join131 } from "path";
60848
+ function leftoverContents(path128) {
60849
+ const contents = { holdsFiles: false, foreignOwned: false };
60850
+ walk2(path128, contents, process.getuid?.());
60851
+ return contents;
60852
+ }
60853
+ function walk2(path128, contents, uid) {
60854
+ const stat5 = lstatSync(path128, { throwIfNoEntry: false });
60855
+ if (!stat5) return;
60856
+ if (uid !== void 0 && stat5.uid !== uid) contents.foreignOwned = true;
60857
+ if (!stat5.isDirectory()) {
60858
+ contents.holdsFiles = true;
60859
+ return;
60860
+ }
60861
+ let entries2;
60862
+ try {
60863
+ entries2 = readdirSync30(path128);
60864
+ } catch {
60865
+ contents.foreignOwned = true;
60866
+ contents.holdsFiles = true;
60867
+ return;
60868
+ }
60869
+ for (const entry of entries2) walk2(join131(path128, entry), contents, uid);
60870
+ }
60871
+
60872
+ // src/commands/sessions/daemon/worktree/surfaceUndeletableLeftover.ts
60873
+ import { basename as basename36 } from "path";
60874
+ function surfaceUndeletableLeftover(spawnWith, leftover, notify2) {
60875
+ forgetWorktree(leftover.path);
60876
+ try {
60877
+ const id = spawnWith((sid) => leftoverSession(sid, leftover));
60878
+ daemonLog(
60879
+ `worktree ${leftover.path} could not be deleted; surfaced as error card ${id} until it is removed by hand: ${leftover.reason}`
60880
+ );
60881
+ } catch (error) {
60882
+ daemonLog(
60883
+ `worktree ${leftover.path} could not be deleted and no card was available to surface it: ${error instanceof Error ? error.message : String(error)}`
60884
+ );
60885
+ return;
60886
+ }
60887
+ notify2();
60888
+ }
60889
+ function leftoverSession(id, leftover) {
60890
+ const message4 = `Leftover workspace ${leftover.path} could not be deleted: ${leftover.reason}`;
60891
+ return {
60892
+ ...sessionBase(id, "error"),
60893
+ name: `leftover ${basename36(leftover.path)}`,
60894
+ subtitle: message4,
60895
+ commandType: "claude",
60896
+ harness: leftover.harness ?? loadConfigFrom(leftover.clone).harness.engine,
60897
+ pty: null,
60898
+ cwd: leftover.path,
60899
+ error: message4,
60900
+ scrollback: [
60901
+ `\r
60902
+ \x1B[31m${message4}\x1B[0m\r
60903
+ `,
60904
+ "\r\nIts worktree is gone, but the directory is still on disk. Remove it with the command above,\r\n",
60905
+ "then dismiss this card. If it is still there on the next daemon restart, this card returns.\r\n"
60906
+ ].join("")
60907
+ };
60908
+ }
60909
+
60910
+ // src/commands/sessions/daemon/worktree/recheckReapedWorktrees.ts
60911
+ async function recheckReapedWorktrees(accounted, spawnWith, notify2) {
60912
+ for (const record3 of readReapedWorktreeRegistry()) {
60913
+ if (accounted.has(record3.path) || underTempRoot(record3.path)) continue;
60914
+ if (!holdsNoCheckout(record3.path)) continue;
60915
+ const reason4 = await clearReappearedTree(record3);
60916
+ if (reason4)
60917
+ surfaceUndeletableLeftover(spawnWith, { ...record3, reason: reason4 }, notify2);
60918
+ }
60919
+ }
60920
+ async function clearReappearedTree(record3) {
60921
+ const contents = leftoverContents(record3.path);
60922
+ if (contents.holdsFiles) return reviewFirst(record3.path, contents);
60923
+ const removal = await deleteTreeDirectly(
60924
+ record3.clone,
60925
+ record3.path,
60926
+ "it reappeared after its worktree was reaped, holding only empty directories (e.g. recreated by dockerd as a bind-mount source)"
60927
+ );
60928
+ return removal.removed ? null : removal.reason;
60929
+ }
60930
+ function reviewFirst(path128, contents) {
60931
+ const command = `${contents.foreignOwned ? "sudo " : ""}rm -rf ${path128}`;
60932
+ return `it reappeared after its worktree was reaped and holds files assist will not delete unreviewed; check them, then remove it with \`${command}\``;
60933
+ }
60934
+
60841
60935
  // src/commands/sessions/daemon/worktree/describeHeldWork.ts
60842
60936
  var MAX_ITEMS = 20;
60843
60937
  async function describeHeldWork(path128, reason4) {
@@ -60874,7 +60968,7 @@ function capped2(lines) {
60874
60968
  }
60875
60969
 
60876
60970
  // src/commands/sessions/daemon/worktree/resurfaceOrphanedWorktree.ts
60877
- import { basename as basename36 } from "path";
60971
+ import { basename as basename37 } from "path";
60878
60972
  function resurfaceOrphanedWorktree(sessions, spawnWith, recovered, notify2) {
60879
60973
  const { orphan, reason: reason4, held } = recovered;
60880
60974
  let id;
@@ -60897,7 +60991,7 @@ function orphanedSession(id, recovered) {
60897
60991
  const { orphan, reason: reason4, held } = recovered;
60898
60992
  return {
60899
60993
  ...sessionBase(id, "stopped"),
60900
- name: `recovered ${basename36(orphan.path)}`,
60994
+ name: `recovered ${basename37(orphan.path)}`,
60901
60995
  subtitle: `${held.summary} in ${orphan.path}`,
60902
60996
  commandType: "claude",
60903
60997
  harness: orphan.harness ?? loadConfigFrom(orphan.clone).harness.engine,
@@ -60927,7 +61021,13 @@ async function recoverOrphan(sessions, spawnWith, orphan, notify2) {
60927
61021
  daemonLog(`worktree ${orphan.path} orphaned across restart; reconciling`);
60928
61022
  const durability = await checkDurability(orphan.path);
60929
61023
  if (durability.durable) {
60930
- await reapWorktree(orphan.path);
61024
+ const removal = await reapWorktree(orphan.path);
61025
+ if (!removal.removed && holdsNoCheckout(orphan.path))
61026
+ surfaceUndeletableLeftover(
61027
+ spawnWith,
61028
+ { ...orphan, reason: removal.reason },
61029
+ notify2
61030
+ );
60931
61031
  return;
60932
61032
  }
60933
61033
  const held = await describeHeldWork(orphan.path, durability.reason);
@@ -60959,7 +61059,7 @@ async function recoverOrphanedWorktrees(sessions, spawnWith, notify2) {
60959
61059
  logVanishedTree(sessions, path128);
60960
61060
  vanished.set(clone, [
60961
61061
  ...vanished.get(clone) ?? [],
60962
- { path: path128, branch: basename37(path128) }
61062
+ { path: path128, branch: basename38(path128) }
60963
61063
  ]);
60964
61064
  continue;
60965
61065
  }
@@ -60968,6 +61068,7 @@ async function recoverOrphanedWorktrees(sessions, spawnWith, notify2) {
60968
61068
  }
60969
61069
  for (const [clone, paths] of vanished)
60970
61070
  await reclaimVanishedWorktrees(clone, paths);
61071
+ await recheckReapedWorktrees(accountedTrees(sessions), spawnWith, notify2);
60971
61072
  }
60972
61073
 
60973
61074
  // src/commands/sessions/daemon/startHeldInTree.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.1129.1",
3
+ "version": "0.1130.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {