@staff0rd/assist 0.1059.2 → 0.1060.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.
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.1059.2",
9
+ version: "0.1060.1",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -4155,7 +4155,12 @@ function applyCwdFromReq(req) {
4155
4155
  async function getDocsRefresh(req, res) {
4156
4156
  applyCwdFromReq(req);
4157
4157
  const { orm } = await getReady();
4158
- respondJson(res, 200, await loadDocsRefreshState(orm, getOrigin()));
4158
+ const state = await loadDocsRefreshState(orm, getOrigin());
4159
+ const view = {
4160
+ ...state,
4161
+ enabled: docsRefreshAfter() !== void 0
4162
+ };
4163
+ respondJson(res, 200, view);
4159
4164
  }
4160
4165
 
4161
4166
  // src/commands/backlog/requestDocsRefresh.ts
@@ -4174,6 +4179,12 @@ async function requestDocsRefresh(orm, origin) {
4174
4179
  // src/commands/backlog/web/postDocsRefresh.ts
4175
4180
  async function postDocsRefresh(req, res) {
4176
4181
  applyCwdFromReq(req);
4182
+ if (docsRefreshAfter() === void 0) {
4183
+ respondJson(res, 409, {
4184
+ error: "Refresh docs is off for this repo; run `assist config set docs.refreshAfter <n>` to turn it on"
4185
+ });
4186
+ return;
4187
+ }
4177
4188
  const { orm } = await getReady();
4178
4189
  respondJson(res, 200, await requestDocsRefresh(orm, getOrigin()));
4179
4190
  }
@@ -6291,7 +6302,7 @@ var backlogConfigHelp = [
6291
6302
  {
6292
6303
  key: "docs.refreshAfter",
6293
6304
  setter: "assist config set docs.refreshAfter 5",
6294
- note: "queue a 'Refresh docs' item once this many done stories are unswept (unset: off)"
6305
+ note: "queue a 'Refresh docs' item once this many done stories are unswept (unset: Refresh docs is off \u2014 no button, no refresh-docs, no docs locking)"
6295
6306
  }
6296
6307
  ];
6297
6308
 
@@ -20797,6 +20808,15 @@ function registerRefineCommand(cmd) {
20797
20808
  // src/commands/backlog/refreshDocs.ts
20798
20809
  import chalk88 from "chalk";
20799
20810
  async function refreshDocs() {
20811
+ if (docsRefreshAfter() === void 0) {
20812
+ console.error(
20813
+ chalk88.red(
20814
+ "Refresh docs is off for this repo; run `assist config set docs.refreshAfter <n>` to turn it on"
20815
+ )
20816
+ );
20817
+ process.exitCode = 1;
20818
+ return;
20819
+ }
20800
20820
  const { orm } = await getReady();
20801
20821
  const result = await requestDocsRefresh(orm, getOrigin());
20802
20822
  if (result.outcome === "created")
@@ -20815,7 +20835,7 @@ async function refreshDocs() {
20815
20835
  // src/commands/backlog/registerRefreshDocsCommand.ts
20816
20836
  function registerRefreshDocsCommand(cmd) {
20817
20837
  cmd.command("refresh-docs").description(
20818
- "Create a Refresh docs item now for every done story not yet swept, regardless of docs.refreshAfter"
20838
+ "Create a Refresh docs item now for every done story not yet swept, without waiting for docs.refreshAfter (refused when docs.refreshAfter is unset: Refresh docs is off)"
20819
20839
  ).action(refreshDocs);
20820
20840
  }
20821
20841
 
@@ -50789,7 +50809,16 @@ function bindResumedWorktree(session, cwd, notify2) {
50789
50809
  }
50790
50810
 
50791
50811
  // src/commands/sessions/daemon/worktree/treeDurability.ts
50812
+ import { existsSync as existsSync97 } from "fs";
50813
+
50814
+ // src/commands/sessions/daemon/worktree/holdsNoCheckout.ts
50792
50815
  import { existsSync as existsSync96 } from "fs";
50816
+ import { join as join113 } from "path";
50817
+ function holdsNoCheckout(path109) {
50818
+ return existsSync96(path109) && !existsSync96(join113(path109, ".git"));
50819
+ }
50820
+
50821
+ // src/commands/sessions/daemon/worktree/treeDurability.ts
50793
50822
  var treeIsGone = { durable: true, gone: true };
50794
50823
  function treeDurability(state) {
50795
50824
  if (state.dirty) return { durable: false, reason: "uncommitted changes" };
@@ -50797,8 +50826,9 @@ function treeDurability(state) {
50797
50826
  return { durable: false, reason: "unpushed commits" };
50798
50827
  return { durable: true };
50799
50828
  }
50800
- function* durabilityProbes() {
50829
+ function* durabilityProbes(cwd) {
50801
50830
  const status2 = yield ["status", "--porcelain"];
50831
+ if (!status2.ok && notACheckout(cwd, status2.error)) return treeIsGone;
50802
50832
  if (!status2.ok)
50803
50833
  return { durable: false, reason: `tree state unreadable: ${status2.error}` };
50804
50834
  const dirty = status2.out !== "";
@@ -50819,16 +50849,19 @@ function* durabilityProbes() {
50819
50849
  localOnlyCommits: !remoteBranches.ok || remoteBranches.out === ""
50820
50850
  });
50821
50851
  }
50852
+ function notACheckout(cwd, error) {
50853
+ return holdsNoCheckout(cwd) && /not a git repository/i.test(error);
50854
+ }
50822
50855
  async function checkDurability(cwd) {
50823
- if (!existsSync96(cwd)) return treeIsGone;
50824
- const probes = durabilityProbes();
50856
+ if (!existsSync97(cwd)) return treeIsGone;
50857
+ const probes = durabilityProbes(cwd);
50825
50858
  let step3 = probes.next();
50826
50859
  while (!step3.done) step3 = probes.next(await gitResult(cwd, step3.value));
50827
50860
  return step3.value;
50828
50861
  }
50829
50862
  function checkDurabilitySync(cwd) {
50830
- if (!existsSync96(cwd)) return treeIsGone;
50831
- const probes = durabilityProbes();
50863
+ if (!existsSync97(cwd)) return treeIsGone;
50864
+ const probes = durabilityProbes(cwd);
50832
50865
  let step3 = probes.next();
50833
50866
  while (!step3.done) step3 = probes.next(gitSyncResult(cwd, step3.value));
50834
50867
  return step3.value;
@@ -50860,7 +50893,7 @@ function releaseReason(durability, session) {
50860
50893
  if (!durability.durable)
50861
50894
  return `still held by finished session ${session.id}: ${durability.reason}`;
50862
50895
  if (durability.gone)
50863
- return `free for allocation: session ${session.id}'s directory is gone from disk \u2014 nothing to land, not landed work`;
50896
+ return `free for allocation: session ${session.id}'s directory is gone from disk or holds no git checkout \u2014 nothing to land, not landed work`;
50864
50897
  return `free for allocation: session ${session.id} finished and its work is landed`;
50865
50898
  }
50866
50899
 
@@ -51111,17 +51144,17 @@ function setStatus2(session, newStatus) {
51111
51144
  }
51112
51145
 
51113
51146
  // src/commands/sessions/daemon/worktree/reapWorktree.ts
51114
- import { existsSync as existsSync98 } from "fs";
51147
+ import { existsSync as existsSync99 } from "fs";
51115
51148
  import { basename as basename32 } from "path";
51116
51149
 
51117
51150
  // src/commands/sessions/daemon/worktree/deleteStrandedTree.ts
51118
- import { existsSync as existsSync97 } from "fs";
51119
- import { join as join114 } from "path";
51151
+ import { existsSync as existsSync98 } from "fs";
51152
+ import { join as join115 } from "path";
51120
51153
 
51121
51154
  // src/commands/sessions/daemon/worktree/deleteTreeDirectly.ts
51122
51155
  import { statSync as statSync16 } from "fs";
51123
51156
  import { rm as rm3 } from "fs/promises";
51124
- import { join as join113 } from "path";
51157
+ import { join as join114 } from "path";
51125
51158
  async function deleteTreeDirectly(clone, worktreePath, why) {
51126
51159
  if (holdsAGitDirectoryRatherThanALink(worktreePath)) {
51127
51160
  const refusal = "it is a clone of its own, not a linked worktree";
@@ -51139,17 +51172,18 @@ async function deleteTreeDirectly(clone, worktreePath, why) {
51139
51172
  retryDelay: 200
51140
51173
  });
51141
51174
  } catch (error) {
51175
+ const failure = deleteFailure(worktreePath, error);
51142
51176
  daemonLog(
51143
- `worktree ${worktreePath} directory delete failed, left in place for the next reconcile: ${reason(error)}`
51177
+ `worktree ${worktreePath} directory delete failed, left in place for the next reconcile: ${failure}`
51144
51178
  );
51145
- return { removed: false, reason: reason(error) };
51179
+ return { removed: false, reason: failure };
51146
51180
  }
51147
51181
  daemonLog(`worktree ${worktreePath} directory deleted directly`);
51148
51182
  await pruneBookkeeping(clone, worktreePath);
51149
51183
  return { removed: true };
51150
51184
  }
51151
51185
  function holdsAGitDirectoryRatherThanALink(worktreePath) {
51152
- return statSync16(join113(worktreePath, ".git"), {
51186
+ return statSync16(join114(worktreePath, ".git"), {
51153
51187
  throwIfNoEntry: false
51154
51188
  })?.isDirectory() === true;
51155
51189
  }
@@ -51165,6 +51199,11 @@ async function pruneBookkeeping(clone, worktreePath) {
51165
51199
  );
51166
51200
  }
51167
51201
  }
51202
+ function deleteFailure(worktreePath, error) {
51203
+ const code = error?.code;
51204
+ if (code !== "EACCES" && code !== "EPERM") return reason(error);
51205
+ return `${worktreePath} holds files owned by another user (e.g. root, from a Docker bind mount) that assist cannot delete; remove it with \`sudo rm -rf ${worktreePath}\` (${reason(error)})`;
51206
+ }
51168
51207
  function reason(error) {
51169
51208
  return error instanceof Error ? error.message : String(error);
51170
51209
  }
@@ -51185,7 +51224,7 @@ async function deleteStrandedTree(clone, worktreePath, cause) {
51185
51224
  );
51186
51225
  }
51187
51226
  function strandedReason(worktreePath, cause) {
51188
- if (!existsSync97(join114(worktreePath, ".git")))
51227
+ if (!existsSync98(join115(worktreePath, ".git")))
51189
51228
  return "its .git link is already gone";
51190
51229
  if (/not a working tree|not a git repository/i.test(reason2(cause)))
51191
51230
  return "git no longer recognises it as a working tree";
@@ -51237,7 +51276,7 @@ function reason3(error) {
51237
51276
 
51238
51277
  // src/commands/sessions/daemon/worktree/reapWorktree.ts
51239
51278
  async function reapWorktree(worktreePath, force = false) {
51240
- if (!existsSync98(worktreePath)) {
51279
+ if (!existsSync99(worktreePath)) {
51241
51280
  forgetWorktree(worktreePath);
51242
51281
  daemonLog(
51243
51282
  `worktree ${worktreePath} already gone; its record was forgotten`
@@ -51262,7 +51301,7 @@ async function reapWorktree(worktreePath, force = false) {
51262
51301
  }
51263
51302
  function owningClone(worktreePath) {
51264
51303
  const recorded = worktreeAttributionIncludingReaped(worktreePath)?.clone;
51265
- if (recorded && existsSync98(recorded)) return recorded;
51304
+ if (recorded && existsSync99(recorded)) return recorded;
51266
51305
  const detected = mainWorktree(worktreePath);
51267
51306
  if (detected) return detected;
51268
51307
  daemonLog(
@@ -51289,7 +51328,9 @@ async function discardTree(session, discarded, notify2) {
51289
51328
  if (session.worktree) {
51290
51329
  const removal = await reapWorktree(session.worktree.path, true);
51291
51330
  if (!removal.removed) {
51292
- holdFailedDiscard(session, removal.reason, notify2);
51331
+ if (holdsNoCheckout(session.worktree.path))
51332
+ releaseUndeletableLeftover(session, removal.reason, notify2);
51333
+ else holdFailedDiscard(session, removal.reason, notify2);
51293
51334
  return;
51294
51335
  }
51295
51336
  session.releasedFromClone = session.worktree.clone;
@@ -51309,6 +51350,24 @@ function holdFailedDiscard(session, reason4, notify2) {
51309
51350
  setStatus2(session, "stopped");
51310
51351
  notify2();
51311
51352
  }
51353
+ function releaseUndeletableLeftover(session, reason4, notify2) {
51354
+ const path109 = session.worktree?.path;
51355
+ daemonLog(
51356
+ `session ${session.id} discard could not delete ${path109}, which holds no git checkout and so no work: ${reason4}; card released to error so it can be dismissed`
51357
+ );
51358
+ const message3 = `Discard could not delete ${path109}: ${reason4}`;
51359
+ if (session.worktree) session.releasedFromClone = session.worktree.clone;
51360
+ session.worktree = void 0;
51361
+ session.closing = void 0;
51362
+ session.undurable = void 0;
51363
+ session.error = message3;
51364
+ session.subtitle = message3;
51365
+ session.scrollback += `\r
51366
+ \x1B[31m${message3}\x1B[0m\r
51367
+ `;
51368
+ setStatus2(session, "error");
51369
+ notify2();
51370
+ }
51312
51371
 
51313
51372
  // src/commands/sessions/daemon/killPtyTree.ts
51314
51373
  function killPtyTree(pty2) {
@@ -51540,7 +51599,7 @@ async function closeBlockReason(sessionId2, tree) {
51540
51599
  if (!durability.durable) return { reason: durability.reason, live: false };
51541
51600
  if (durability.gone) {
51542
51601
  daemonLog(
51543
- `session ${sessionId2} closing: worktree ${tree.path} is gone from disk \u2014 released with nothing to land, not landed work`
51602
+ `session ${sessionId2} closing: worktree ${tree.path} is gone from disk or holds no git checkout \u2014 released with nothing to land, not landed work`
51544
51603
  );
51545
51604
  return void 0;
51546
51605
  }
@@ -51549,12 +51608,12 @@ async function closeBlockReason(sessionId2, tree) {
51549
51608
  }
51550
51609
 
51551
51610
  // src/commands/sessions/daemon/worktree/watchGitState.ts
51552
- import { existsSync as existsSync99, watch } from "fs";
51611
+ import { existsSync as existsSync100, watch } from "fs";
51553
51612
  var DEBOUNCE_MS = 500;
51554
51613
  var POLL_MS5 = 3e4;
51555
51614
  function watchGitState(cwd, onChange) {
51556
51615
  const common = gitCommonDir(cwd);
51557
- if (!common || !existsSync99(common)) return void 0;
51616
+ if (!common || !existsSync100(common)) return void 0;
51558
51617
  const watchers = [
51559
51618
  watchGitDir(common, onChange),
51560
51619
  pollGitState(cwd, onChange)
@@ -52277,10 +52336,10 @@ function emitSessionOutput(session, clients, data) {
52277
52336
  }
52278
52337
 
52279
52338
  // src/commands/sessions/daemon/exitReason.ts
52280
- import { existsSync as existsSync100 } from "fs";
52339
+ import { existsSync as existsSync101 } from "fs";
52281
52340
  import { resolve as resolve33 } from "path";
52282
52341
  function exitDetail(session) {
52283
- if (session.cwd && !existsSync100(session.cwd))
52342
+ if (session.cwd && !existsSync101(session.cwd))
52284
52343
  return `working directory ${session.cwd} no longer exists`;
52285
52344
  return missingRunConfigCwd(session);
52286
52345
  }
@@ -52294,7 +52353,7 @@ function missingRunConfigCwd(session) {
52294
52353
  const config = resolveRunConfig(session.runName, dir);
52295
52354
  if (!config?.cwd) return void 0;
52296
52355
  const configured = resolve33(runConfigBaseDirFrom(dir), config.cwd);
52297
- if (existsSync100(configured)) return void 0;
52356
+ if (existsSync101(configured)) return void 0;
52298
52357
  return `run config "${config.name}": cwd ${configured} does not exist`;
52299
52358
  }
52300
52359
 
@@ -52342,7 +52401,7 @@ function handleRefusedRun(session, exitCode, onStatusChange) {
52342
52401
  }
52343
52402
 
52344
52403
  // src/commands/sessions/daemon/watchActivity.ts
52345
- import { existsSync as existsSync101, mkdirSync as mkdirSync41, watch as watch2 } from "fs";
52404
+ import { existsSync as existsSync102, mkdirSync as mkdirSync41, watch as watch2 } from "fs";
52346
52405
  import { dirname as dirname50 } from "path";
52347
52406
 
52348
52407
  // src/commands/sessions/daemon/applyActivityToSession.ts
@@ -52427,7 +52486,7 @@ function watchActivity(session, notify2, onClaudeSessionId) {
52427
52486
  if (timer) clearTimeout(timer);
52428
52487
  timer = setTimeout(read3, DEBOUNCE_MS2);
52429
52488
  });
52430
- if (existsSync101(path109)) read3();
52489
+ if (existsSync102(path109)) read3();
52431
52490
  }
52432
52491
  function refreshActivity(session) {
52433
52492
  if (session.commandType !== "assist" || !session.cwd) return;
@@ -54705,7 +54764,7 @@ function rearmStoppedSessions(sessions, notify2) {
54705
54764
  }
54706
54765
 
54707
54766
  // src/commands/sessions/daemon/worktree/reconcileWorktreesOnRestore.ts
54708
- import { existsSync as existsSync103 } from "fs";
54767
+ import { existsSync as existsSync104 } from "fs";
54709
54768
  import { basename as basename35 } from "path";
54710
54769
 
54711
54770
  // src/commands/sessions/daemon/worktree/accountedTrees.ts
@@ -54726,9 +54785,9 @@ function accountedTrees(sessions) {
54726
54785
  }
54727
54786
 
54728
54787
  // src/commands/sessions/daemon/worktree/reclaimVanishedWorktrees.ts
54729
- import { existsSync as existsSync102 } from "fs";
54788
+ import { existsSync as existsSync103 } from "fs";
54730
54789
  async function reclaimVanishedWorktrees(clone, paths) {
54731
- if (!existsSync102(clone)) {
54790
+ if (!existsSync103(clone)) {
54732
54791
  for (const { path: path109 } of paths) forgetWorktree(path109);
54733
54792
  daemonLog(
54734
54793
  `clone ${clone} is gone; forgot ${paths.length} worktree record(s) it owned`
@@ -54894,7 +54953,7 @@ async function recoverOrphanedWorktrees(sessions, spawnWith, notify2) {
54894
54953
  );
54895
54954
  continue;
54896
54955
  }
54897
- if (!existsSync103(path109)) {
54956
+ if (!existsSync104(path109)) {
54898
54957
  logVanishedTree(sessions, path109);
54899
54958
  vanished.set(clone, [
54900
54959
  ...vanished.get(clone) ?? [],
@@ -56094,7 +56153,7 @@ function spawnAssistInTree(ctx, assistArgs, cwd, meta, context) {
56094
56153
  }
56095
56154
 
56096
56155
  // src/commands/sessions/daemon/worktree/resumeInTree.ts
56097
- import { existsSync as existsSync106 } from "fs";
56156
+ import { existsSync as existsSync107 } from "fs";
56098
56157
 
56099
56158
  // src/commands/sessions/daemon/resumeSession.ts
56100
56159
  function resumeSession(id, sessionId2, cwd, name, holdPty, harness) {
@@ -56125,11 +56184,11 @@ function resumeSession(id, sessionId2, cwd, name, holdPty, harness) {
56125
56184
  }
56126
56185
 
56127
56186
  // src/commands/sessions/daemon/worktree/resumeInReplacementTree.ts
56128
- import { existsSync as existsSync105 } from "fs";
56187
+ import { existsSync as existsSync106 } from "fs";
56129
56188
 
56130
56189
  // src/commands/sessions/daemon/worktree/carryTranscriptToTree.ts
56131
- import { copyFileSync as copyFileSync4, existsSync as existsSync104, mkdirSync as mkdirSync43 } from "fs";
56132
- import { join as join115 } from "path";
56190
+ import { copyFileSync as copyFileSync4, existsSync as existsSync105, mkdirSync as mkdirSync43 } from "fs";
56191
+ import { join as join116 } from "path";
56133
56192
  function carryTranscriptToTree(claudeSessionId, fromCwd, toCwd) {
56134
56193
  const dir = projectDirForCwd(toCwd);
56135
56194
  if (dir === projectDirForCwd(fromCwd)) {
@@ -56138,8 +56197,8 @@ function carryTranscriptToTree(claudeSessionId, fromCwd, toCwd) {
56138
56197
  );
56139
56198
  return;
56140
56199
  }
56141
- const dest = join115(dir, `${claudeSessionId}.jsonl`);
56142
- if (existsSync104(dest)) {
56200
+ const dest = join116(dir, `${claudeSessionId}.jsonl`);
56201
+ if (existsSync105(dest)) {
56143
56202
  daemonLog(`transcript ${claudeSessionId} already present in ${dir}`);
56144
56203
  return;
56145
56204
  }
@@ -56190,7 +56249,7 @@ function resumeInReplacementTree(ctx, claudeSessionId, missingCwd, name, harness
56190
56249
  }
56191
56250
  function cloneForReapedTree(missingCwd) {
56192
56251
  const clone = worktreeAttributionIncludingReaped(missingCwd)?.clone;
56193
- if (!clone || !existsSync105(clone))
56252
+ if (!clone || !existsSync106(clone))
56194
56253
  throw new Error(
56195
56254
  `working directory no longer exists and no clone is recorded to re-allocate from: ${missingCwd}`
56196
56255
  );
@@ -56199,7 +56258,7 @@ function cloneForReapedTree(missingCwd) {
56199
56258
 
56200
56259
  // src/commands/sessions/daemon/worktree/resumeInTree.ts
56201
56260
  function resumeInTree(ctx, sessionId2, cwd, name, harness) {
56202
- if (!existsSync106(cwd))
56261
+ if (!existsSync107(cwd))
56203
56262
  return resumeInReplacementTree(ctx, sessionId2, cwd, name, harness);
56204
56263
  const id = ctx.spawnWith(
56205
56264
  (sid) => resumeSession(sid, sessionId2, cwd, name, void 0, harness)
@@ -57468,7 +57527,7 @@ function isPrCheckoutArgs(args) {
57468
57527
 
57469
57528
  // src/commands/sessions/daemon/worktree/prCheckoutHolder.ts
57470
57529
  import { execFile as execFile14 } from "child_process";
57471
- import { existsSync as existsSync107 } from "fs";
57530
+ import { existsSync as existsSync108 } from "fs";
57472
57531
  function prHeadBranch2(number, cwd) {
57473
57532
  const { headBranch } = prCliCommands(number, cwd);
57474
57533
  return new Promise((resolve34) => {
@@ -57482,12 +57541,12 @@ function prHeadBranch2(number, cwd) {
57482
57541
  }
57483
57542
  async function prCheckoutHolder(assistArgs, cwd) {
57484
57543
  const number = prCheckoutNumber(assistArgs);
57485
- if (!number || !cwd || !existsSync107(cwd)) return void 0;
57544
+ if (!number || !cwd || !existsSync108(cwd)) return void 0;
57486
57545
  const headRef = await prHeadBranch2(number, cwd);
57487
57546
  if (!headRef) return void 0;
57488
57547
  const listing = await gitOrNull(cwd, ["worktree", "list", "--porcelain"]);
57489
57548
  const holder = listing ? worktreeWithBranch(listing, headRef) : null;
57490
- if (!holder || !existsSync107(holder)) return void 0;
57549
+ if (!holder || !existsSync108(holder)) return void 0;
57491
57550
  daemonLog(
57492
57551
  `pr #${number} assist ${assistArgs[0]} launched in its checkout ${holder}: head branch ${headRef} is already checked out there, so no worktree is allocated`
57493
57552
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.1059.2",
3
+ "version": "0.1060.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {