@moberg_hr/work-tree 1.8.0 → 1.9.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/wd-bin.js CHANGED
@@ -1462,6 +1462,9 @@ function latestJsonlMtimeMs(projectDir) {
1462
1462
  }
1463
1463
  return latest;
1464
1464
  }
1465
+ function claudeActiveWithin(activityMs, nowMs, windowMs) {
1466
+ return activityMs > 0 && nowMs - activityMs < windowMs;
1467
+ }
1465
1468
  function getClaudeActivityMs(launchPath) {
1466
1469
  const dir = path9.join(
1467
1470
  os4.homedir(),
@@ -1486,6 +1489,28 @@ function effectiveLastAccessedAt(session) {
1486
1489
  }
1487
1490
  return new Date(bestMs).toISOString();
1488
1491
  }
1492
+ function resolveResumeLaunch(session) {
1493
+ const existing = session.paths.filter((p) => fs9.existsSync(p));
1494
+ const first = existing[0] ?? session.paths[0];
1495
+ const defaultPath = session.isGroup ? path9.dirname(first) : first;
1496
+ const candidates = /* @__PURE__ */ new Set();
1497
+ if (session.isGroup) {
1498
+ for (const p of existing) candidates.add(path9.dirname(p));
1499
+ for (const p of existing) candidates.add(p);
1500
+ } else {
1501
+ for (const p of existing) candidates.add(p);
1502
+ }
1503
+ let launchPath = defaultPath;
1504
+ let bestMs = 0;
1505
+ for (const c of candidates) {
1506
+ const ms = getClaudeActivityMs(c);
1507
+ if (ms > bestMs) {
1508
+ bestMs = ms;
1509
+ launchPath = c;
1510
+ }
1511
+ }
1512
+ return { launchPath, hasConversation: bestMs > 0 };
1513
+ }
1489
1514
  var ACTIVE_MS = 3e4;
1490
1515
  var OPEN_MS = 5 * 6e4;
1491
1516
  function readSessionActivity(session) {
@@ -2745,7 +2770,6 @@ function printSessionStatus(session) {
2745
2770
 
2746
2771
  // src/commands/recent.ts
2747
2772
  import fs17 from "fs";
2748
- import path14 from "path";
2749
2773
  import chalk10 from "chalk";
2750
2774
  import { select as select2 } from "@inquirer/prompts";
2751
2775
  var recentCommand = {
@@ -2803,12 +2827,19 @@ var recentCommand = {
2803
2827
  process.exitCode = 1;
2804
2828
  return;
2805
2829
  }
2806
- const launchPath = choice.isGroup ? path14.dirname(firstExisting) : firstExisting;
2830
+ const { launchPath, hasConversation } = resolveResumeLaunch(choice);
2807
2831
  await upsertSession(choice.target, choice.isGroup, choice.branch, choice.paths);
2808
2832
  const tool = getAiTool(config);
2809
2833
  console.log(chalk10.cyan(`Resuming in: ${launchPath}`));
2834
+ if (!hasConversation) {
2835
+ console.log(
2836
+ chalk10.yellow(
2837
+ `No prior ${tool.cmd} conversation found for this worktree \u2014 starting a fresh session.`
2838
+ )
2839
+ );
2840
+ }
2810
2841
  console.log(`Starting ${tool.cmd}...`);
2811
- launchAi(launchPath, tool, { unsafe, resume: true }, choice.port);
2842
+ launchAi(launchPath, tool, { unsafe, resume: hasConversation }, choice.port);
2812
2843
  return;
2813
2844
  }
2814
2845
  console.log("");
@@ -2835,7 +2866,6 @@ var recentCommand = {
2835
2866
 
2836
2867
  // src/commands/resume.ts
2837
2868
  import fs18 from "fs";
2838
- import path15 from "path";
2839
2869
  import chalk11 from "chalk";
2840
2870
  import { select as select3 } from "@inquirer/prompts";
2841
2871
  var resumeCommand = {
@@ -2878,12 +2908,19 @@ var resumeCommand = {
2878
2908
  process.exitCode = 1;
2879
2909
  return;
2880
2910
  }
2881
- const launchPath = choice.isGroup ? path15.dirname(firstExisting) : firstExisting;
2911
+ const { launchPath, hasConversation } = resolveResumeLaunch(choice);
2882
2912
  await upsertSession(choice.target, choice.isGroup, choice.branch, choice.paths);
2883
2913
  const tool = getAiTool(config);
2884
2914
  console.log(chalk11.cyan(`Resuming in: ${launchPath}`));
2915
+ if (!hasConversation) {
2916
+ console.log(
2917
+ chalk11.yellow(
2918
+ `No prior ${tool.cmd} conversation found for this worktree \u2014 starting a fresh session.`
2919
+ )
2920
+ );
2921
+ }
2885
2922
  console.log(`Starting ${tool.cmd}...`);
2886
- launchAi(launchPath, tool, { unsafe, resume: true }, choice.port);
2923
+ launchAi(launchPath, tool, { unsafe, resume: hasConversation }, choice.port);
2887
2924
  }
2888
2925
  };
2889
2926
 
@@ -2893,7 +2930,7 @@ import { checkbox } from "@inquirer/prompts";
2893
2930
 
2894
2931
  // src/core/prunable-scan.ts
2895
2932
  import fs19 from "fs";
2896
- import path16 from "path";
2933
+ import path14 from "path";
2897
2934
  import chalk12 from "chalk";
2898
2935
  function collectPrunable(config, options = {}) {
2899
2936
  const { fetch: fetch2 = true, print = true, includeSquash = false } = options;
@@ -2910,7 +2947,7 @@ function collectPrunable(config, options = {}) {
2910
2947
  }
2911
2948
  const groupCoveredKeys = /* @__PURE__ */ new Set();
2912
2949
  for (const [groupName, aliases] of Object.entries(config.groups)) {
2913
- const groupDir = path16.join(config.worktreesRoot, groupName);
2950
+ const groupDir = path14.join(config.worktreesRoot, groupName);
2914
2951
  if (!fs19.existsSync(groupDir)) continue;
2915
2952
  let branchDirs;
2916
2953
  try {
@@ -2919,7 +2956,7 @@ function collectPrunable(config, options = {}) {
2919
2956
  continue;
2920
2957
  }
2921
2958
  for (const branchDir of branchDirs) {
2922
- const branchDirPath = path16.join(groupDir, branchDir);
2959
+ const branchDirPath = path14.join(groupDir, branchDir);
2923
2960
  let branch;
2924
2961
  let allMerged = true;
2925
2962
  let groupHasChanges = false;
@@ -2933,8 +2970,8 @@ function collectPrunable(config, options = {}) {
2933
2970
  skipped = true;
2934
2971
  continue;
2935
2972
  }
2936
- const repoName = path16.basename(repoPath);
2937
- const subWorktreePath = path16.join(branchDirPath, repoName);
2973
+ const repoName = path14.basename(repoPath);
2974
+ const subWorktreePath = path14.join(branchDirPath, repoName);
2938
2975
  if (!fs19.existsSync(subWorktreePath)) {
2939
2976
  continue;
2940
2977
  }
@@ -3051,7 +3088,7 @@ async function removeSingleEntry(entry, force = true) {
3051
3088
  }
3052
3089
  async function removeGroupEntry(entry, config, force = true) {
3053
3090
  const workTreeDirName = entry.branch.replace(/\//g, "-");
3054
- const groupWorktreePath = path16.join(
3091
+ const groupWorktreePath = path14.join(
3055
3092
  config.worktreesRoot,
3056
3093
  entry.target,
3057
3094
  workTreeDirName
@@ -3061,7 +3098,7 @@ async function removeGroupEntry(entry, config, force = true) {
3061
3098
  );
3062
3099
  let allRemoved = true;
3063
3100
  for (const { alias, repoPath, worktreePath } of entry.repos) {
3064
- const repoName = path16.basename(repoPath);
3101
+ const repoName = path14.basename(repoPath);
3065
3102
  console.log(chalk12.cyan(` [${alias}] (${repoName}):`));
3066
3103
  const removed = removeSingleWorktree(repoPath, worktreePath, entry.branch, force);
3067
3104
  if (!removed) {
@@ -3071,7 +3108,7 @@ async function removeGroupEntry(entry, config, force = true) {
3071
3108
  if (allRemoved) {
3072
3109
  await removeSession(entry.target, entry.branch);
3073
3110
  }
3074
- const claudeMdInWorktree = path16.join(groupWorktreePath, "CLAUDE.md");
3111
+ const claudeMdInWorktree = path14.join(groupWorktreePath, "CLAUDE.md");
3075
3112
  if (fs19.existsSync(claudeMdInWorktree)) {
3076
3113
  fs19.unlinkSync(claudeMdInWorktree);
3077
3114
  }
@@ -3297,7 +3334,7 @@ var syncCommand = {
3297
3334
 
3298
3335
  // src/tui-ink/index.tsx
3299
3336
  import fs24 from "fs";
3300
- import path21 from "path";
3337
+ import path19 from "path";
3301
3338
  import { render } from "ink";
3302
3339
 
3303
3340
  // src/tui-ink/App.tsx
@@ -3305,7 +3342,7 @@ import { useState, useEffect, useRef, useCallback, useMemo } from "react";
3305
3342
  import { Box as Box5 } from "ink";
3306
3343
  import fs23 from "fs";
3307
3344
  import os6 from "os";
3308
- import path20 from "path";
3345
+ import path18 from "path";
3309
3346
  import { execFile as execFile4 } from "child_process";
3310
3347
  import spawn7 from "cross-spawn";
3311
3348
 
@@ -3519,10 +3556,10 @@ async function fetchJiraPane() {
3519
3556
 
3520
3557
  // src/core/tasks.ts
3521
3558
  import fs21 from "fs";
3522
- import path17 from "path";
3559
+ import path15 from "path";
3523
3560
  var EMPTY_STORE = { nextId: 1, tasks: [] };
3524
3561
  function getTasksPath() {
3525
- return path17.join(getConfigDir(), "tasks.json");
3562
+ return path15.join(getConfigDir(), "tasks.json");
3526
3563
  }
3527
3564
  function loadStore() {
3528
3565
  const p = getTasksPath();
@@ -3771,13 +3808,13 @@ var PtySession = class {
3771
3808
 
3772
3809
  // src/core/hook-server.ts
3773
3810
  import http from "http";
3774
- import path19 from "path";
3811
+ import path17 from "path";
3775
3812
 
3776
3813
  // src/core/settings-editor.ts
3777
3814
  import fs22 from "fs";
3778
- import path18 from "path";
3815
+ import path16 from "path";
3779
3816
  import os5 from "os";
3780
- var SETTINGS_PATH = path18.join(os5.homedir(), ".claude", "settings.json");
3817
+ var SETTINGS_PATH = path16.join(os5.homedir(), ".claude", "settings.json");
3781
3818
  var OWNER_TAG = "_workHookOwner";
3782
3819
  var PID_TAG = "_workHookPid";
3783
3820
  var LEGACY_TAGS = ["_workDash", "_work2Dash"];
@@ -3791,7 +3828,7 @@ function readSettings() {
3791
3828
  }
3792
3829
  function writeAtomic(s) {
3793
3830
  try {
3794
- fs22.mkdirSync(path18.dirname(SETTINGS_PATH), { recursive: true });
3831
+ fs22.mkdirSync(path16.dirname(SETTINGS_PATH), { recursive: true });
3795
3832
  const tmp = `${SETTINGS_PATH}.tmp-${process.pid}-${Date.now()}`;
3796
3833
  fs22.writeFileSync(tmp, JSON.stringify(s, null, 2), "utf-8");
3797
3834
  fs22.renameSync(tmp, SETTINGS_PATH);
@@ -3966,7 +4003,7 @@ function removeHttpHooksSync(owner) {
3966
4003
  editSettingsSync(mutateRemove(owner));
3967
4004
  }
3968
4005
  function normalizePath(p) {
3969
- return path19.resolve(p).toLowerCase();
4006
+ return path17.resolve(p).toLowerCase();
3970
4007
  }
3971
4008
 
3972
4009
  // src/core/notifier.ts
@@ -5045,9 +5082,9 @@ var RENDER_INTERVAL_MS = 50;
5045
5082
  var MOUSE_SGR_RE = /\x1b\[<(\d+);(\d+);(\d+)[Mm]/;
5046
5083
  function hasClaudeConversation(dir) {
5047
5084
  try {
5048
- const resolved = path20.resolve(dir);
5085
+ const resolved = path18.resolve(dir);
5049
5086
  const projectDir = resolved.replace(/[^a-zA-Z0-9-]/g, "-");
5050
- const claudeProjectPath = path20.join(os6.homedir(), ".claude", "projects", projectDir);
5087
+ const claudeProjectPath = path18.join(os6.homedir(), ".claude", "projects", projectDir);
5051
5088
  if (!fs23.existsSync(claudeProjectPath)) return false;
5052
5089
  const files = fs23.readdirSync(claudeProjectPath);
5053
5090
  return files.some((f) => f.endsWith(".jsonl"));
@@ -5056,7 +5093,7 @@ function hasClaudeConversation(dir) {
5056
5093
  }
5057
5094
  }
5058
5095
  function ptyDedupKey(pty2) {
5059
- return path20.resolve(pty2.cwd).toLowerCase();
5096
+ return path18.resolve(pty2.cwd).toLowerCase();
5060
5097
  }
5061
5098
  function loadSessions() {
5062
5099
  const all = loadHistory();
@@ -5350,10 +5387,10 @@ function App({ unsafe, onExit }) {
5350
5387
  }
5351
5388
  }, [setScrollBack, renderTermAtScroll]);
5352
5389
  const findPtyByCwd = useCallback((cwd) => {
5353
- const normalized = path20.resolve(cwd).toLowerCase();
5390
+ const normalized = path18.resolve(cwd).toLowerCase();
5354
5391
  for (const pty2 of ptySessions.current.values()) {
5355
5392
  if (pty2.exited) continue;
5356
- if (normalized.startsWith(path20.resolve(pty2.cwd).toLowerCase())) return pty2;
5393
+ if (normalized.startsWith(path18.resolve(pty2.cwd).toLowerCase())) return pty2;
5357
5394
  }
5358
5395
  return void 0;
5359
5396
  }, []);
@@ -5429,13 +5466,13 @@ function App({ unsafe, onExit }) {
5429
5466
  notifiedSessionsRef.current
5430
5467
  );
5431
5468
  if (kind) {
5432
- notifyDesktop(path20.basename(pty2.cwd), kind, {
5469
+ notifyDesktop(path18.basename(pty2.cwd), kind, {
5433
5470
  enabled: config?.notifications === true
5434
5471
  });
5435
5472
  runStatusHooks(
5436
5473
  kind,
5437
5474
  pty2.cwd,
5438
- path20.basename(pty2.cwd),
5475
+ path18.basename(pty2.cwd),
5439
5476
  config?.statusHooks
5440
5477
  );
5441
5478
  }
@@ -5568,7 +5605,7 @@ function App({ unsafe, onExit }) {
5568
5605
  refreshSessions();
5569
5606
  return;
5570
5607
  }
5571
- const dir = s.isGroup ? path20.dirname(existing) : existing;
5608
+ const dir = s.isGroup ? path18.dirname(existing) : existing;
5572
5609
  const resume = hasClaudeConversation(dir);
5573
5610
  const tool = getAiTool(config ?? {});
5574
5611
  const pty2 = new PtySession(dir, termInner, contentHeight - 2, void 0, { tool, unsafe, resume, port: s.port });
@@ -5666,7 +5703,7 @@ function App({ unsafe, onExit }) {
5666
5703
  "",
5667
5704
  " - Ask if I want to proceed with the recommended approach, choose a different one, get more details, or make adjustments."
5668
5705
  ].join("\n");
5669
- promptFile = path20.join(os6.tmpdir(), `work-prompt-${Date.now()}.txt`);
5706
+ promptFile = path18.join(os6.tmpdir(), `work-prompt-${Date.now()}.txt`);
5670
5707
  fs23.writeFileSync(promptFile, prompt, "utf-8");
5671
5708
  }
5672
5709
  const setupArgs = ["tree", projectName, branchName, "--setup-only"];
@@ -5706,7 +5743,7 @@ function App({ unsafe, onExit }) {
5706
5743
  setStatusVersion((v) => v + 1);
5707
5744
  return;
5708
5745
  }
5709
- const launchDir = session.isGroup ? path20.dirname(existing) : existing;
5746
+ const launchDir = session.isGroup ? path18.dirname(existing) : existing;
5710
5747
  const tool = getAiTool(config);
5711
5748
  const aiPty = new PtySession(
5712
5749
  launchDir,
@@ -6281,7 +6318,7 @@ function App({ unsafe, onExit }) {
6281
6318
  setMessage("Session path no longer exists");
6282
6319
  return;
6283
6320
  }
6284
- const dir = s.isGroup ? path20.dirname(existing) : existing;
6321
+ const dir = s.isGroup ? path18.dirname(existing) : existing;
6285
6322
  const editor = config?.editor ?? "code";
6286
6323
  spawn7(editor, [dir], { detached: true, stdio: "ignore" }).unref();
6287
6324
  setMessage(`Opened in ${editor}: ${s.branch}`);
@@ -6466,7 +6503,7 @@ function crashLog(label2, err) {
6466
6503
  const msg = err instanceof Error ? err.stack || err.message : String(err);
6467
6504
  const line = `${(/* @__PURE__ */ new Date()).toISOString()} [CRASH] ${label2}: ${msg}
6468
6505
  `;
6469
- fs24.appendFileSync(path21.join(getConfigDir(), "debug.log"), line);
6506
+ fs24.appendFileSync(path19.join(getConfigDir(), "debug.log"), line);
6470
6507
  } catch {
6471
6508
  }
6472
6509
  }
@@ -6790,22 +6827,22 @@ import chalk17 from "chalk";
6790
6827
 
6791
6828
  // src/core/hydrate.ts
6792
6829
  import fs25 from "fs";
6793
- import path22 from "path";
6830
+ import path20 from "path";
6794
6831
  async function hydrateHistoryFromDisk(config) {
6795
- const worktreesRoot = path22.resolve(config.worktreesRoot);
6832
+ const worktreesRoot = path20.resolve(config.worktreesRoot);
6796
6833
  const folderNameToAlias = /* @__PURE__ */ new Map();
6797
6834
  for (const [alias, repoPath] of Object.entries(config.repos)) {
6798
- folderNameToAlias.set(path22.basename(repoPath), alias);
6835
+ folderNameToAlias.set(path20.basename(repoPath), alias);
6799
6836
  }
6800
6837
  const discovered = /* @__PURE__ */ new Map();
6801
6838
  for (const [alias, repoPath] of Object.entries(config.repos)) {
6802
6839
  if (!fs25.existsSync(repoPath)) continue;
6803
6840
  for (const entry of parseWorktreeList(repoPath)) {
6804
6841
  if (!entry.branch) continue;
6805
- if (path22.resolve(entry.path) === path22.resolve(repoPath)) continue;
6806
- const rel = path22.relative(worktreesRoot, entry.path);
6807
- if (!rel || rel.startsWith("..") || path22.isAbsolute(rel)) continue;
6808
- const parts = rel.split(path22.sep).filter(Boolean);
6842
+ if (path20.resolve(entry.path) === path20.resolve(repoPath)) continue;
6843
+ const rel = path20.relative(worktreesRoot, entry.path);
6844
+ if (!rel || rel.startsWith("..") || path20.isAbsolute(rel)) continue;
6845
+ const parts = rel.split(path20.sep).filter(Boolean);
6809
6846
  if (parts.length < 2) continue;
6810
6847
  const [first, second] = parts;
6811
6848
  const isGroup = Object.prototype.hasOwnProperty.call(config.groups, first);
@@ -6890,13 +6927,13 @@ var hydrateCommand = {
6890
6927
  // src/commands/diff.ts
6891
6928
  import fs36 from "fs";
6892
6929
  import os9 from "os";
6893
- import path33 from "path";
6930
+ import path31 from "path";
6894
6931
  import { spawn as childSpawn } from "child_process";
6895
6932
  import chalk21 from "chalk";
6896
6933
 
6897
6934
  // src/core/diff-pipeline.ts
6898
6935
  import fs28 from "fs";
6899
- import path25 from "path";
6936
+ import path23 from "path";
6900
6937
  import spawn9 from "cross-spawn";
6901
6938
 
6902
6939
  // src/core/diff-parse.ts
@@ -7045,7 +7082,7 @@ function stripPathPrefix(p) {
7045
7082
 
7046
7083
  // src/core/lcov.ts
7047
7084
  import fs26 from "fs";
7048
- import path23 from "path";
7085
+ import path21 from "path";
7049
7086
  function parseLcov(content) {
7050
7087
  const result = /* @__PURE__ */ new Map();
7051
7088
  let sf = null;
@@ -7104,8 +7141,8 @@ function parseLcov(content) {
7104
7141
  }
7105
7142
  function findLcov(root) {
7106
7143
  const candidates = [
7107
- path23.join(root, "coverage", "lcov.info"),
7108
- path23.join(root, "lcov.info")
7144
+ path21.join(root, "coverage", "lcov.info"),
7145
+ path21.join(root, "lcov.info")
7109
7146
  ];
7110
7147
  for (const c of candidates) {
7111
7148
  try {
@@ -7140,33 +7177,33 @@ function readParsedLcov(lcovPath) {
7140
7177
  return { parsed, mtimeMs };
7141
7178
  }
7142
7179
  function normRel(p) {
7143
- return path23.normalize(p).replace(/\\/g, "/").replace(/^\.\//, "");
7180
+ return path21.normalize(p).replace(/\\/g, "/").replace(/^\.\//, "");
7144
7181
  }
7145
7182
  function realRoot(root) {
7146
7183
  try {
7147
- return fs26.realpathSync(path23.resolve(root));
7184
+ return fs26.realpathSync(path21.resolve(root));
7148
7185
  } catch {
7149
- return path23.resolve(root);
7186
+ return path21.resolve(root);
7150
7187
  }
7151
7188
  }
7152
7189
  function canonicalize(absPath) {
7153
- const resolved = path23.resolve(absPath);
7190
+ const resolved = path21.resolve(absPath);
7154
7191
  let dir = resolved;
7155
7192
  const tail = [];
7156
7193
  for (; ; ) {
7157
7194
  try {
7158
7195
  const realDir = fs26.realpathSync(dir);
7159
- return tail.length ? path23.join(realDir, ...tail.reverse()) : realDir;
7196
+ return tail.length ? path21.join(realDir, ...tail.reverse()) : realDir;
7160
7197
  } catch {
7161
- const parent = path23.dirname(dir);
7198
+ const parent = path21.dirname(dir);
7162
7199
  if (parent === dir) return resolved;
7163
- tail.push(path23.basename(dir));
7200
+ tail.push(path21.basename(dir));
7164
7201
  dir = parent;
7165
7202
  }
7166
7203
  }
7167
7204
  }
7168
7205
  function relForAbsSf(absSf, canonRoot) {
7169
- return path23.relative(canonRoot, canonicalize(absSf));
7206
+ return path21.relative(canonRoot, canonicalize(absSf));
7170
7207
  }
7171
7208
  function coverageLookup(root, relPaths) {
7172
7209
  const out = /* @__PURE__ */ new Map();
@@ -7179,7 +7216,7 @@ function coverageLookup(root, relPaths) {
7179
7216
  const canonRoot = realRoot(root);
7180
7217
  const byRel = /* @__PURE__ */ new Map();
7181
7218
  for (const [sf, pct] of read.parsed) {
7182
- const rel = path23.isAbsolute(sf) ? relForAbsSf(sf, canonRoot) : sf;
7219
+ const rel = path21.isAbsolute(sf) ? relForAbsSf(sf, canonRoot) : sf;
7183
7220
  byRel.set(normRel(rel), pct);
7184
7221
  }
7185
7222
  for (const rp of relPaths) {
@@ -7192,12 +7229,12 @@ function coverageLookup(root, relPaths) {
7192
7229
  // src/core/git-tree-snapshot.ts
7193
7230
  import fs27 from "fs";
7194
7231
  import os7 from "os";
7195
- import path24 from "path";
7232
+ import path22 from "path";
7196
7233
  import crypto from "crypto";
7197
7234
  import spawn8 from "cross-spawn";
7198
7235
  function writeTempTree(repoRoot, opts = {}) {
7199
7236
  const includeWorkingTree = opts.includeWorkingTree ?? true;
7200
- const tmpIndex = path24.join(
7237
+ const tmpIndex = path22.join(
7201
7238
  os7.tmpdir(),
7202
7239
  `wd-tree-${process.pid}-${crypto.randomBytes(6).toString("hex")}.idx`
7203
7240
  );
@@ -7242,12 +7279,12 @@ function isMarkdownPath(p) {
7242
7279
  return p !== "/dev/null" && MARKDOWN_EXT_RE.test(p);
7243
7280
  }
7244
7281
  function isInsideRoot(root, rel) {
7245
- const resolvedRoot = path25.resolve(root);
7246
- const resolvedTarget = path25.resolve(resolvedRoot, rel);
7247
- const r = path25.relative(resolvedRoot, resolvedTarget);
7282
+ const resolvedRoot = path23.resolve(root);
7283
+ const resolvedTarget = path23.resolve(resolvedRoot, rel);
7284
+ const r = path23.relative(resolvedRoot, resolvedTarget);
7248
7285
  if (r === "") return true;
7249
7286
  if (r.startsWith("..")) return false;
7250
- if (path25.isAbsolute(r)) return false;
7287
+ if (path23.isAbsolute(r)) return false;
7251
7288
  return true;
7252
7289
  }
7253
7290
  function readMarkdownContent(root, file, fromRef, toRef) {
@@ -7272,10 +7309,10 @@ function readMarkdownContent(root, file, fromRef, toRef) {
7272
7309
  if (file.status !== "deleted" && isMarkdownPath(file.newPath) && isInsideRoot(root, file.newPath)) {
7273
7310
  if (toRef === "working") {
7274
7311
  try {
7275
- const absPath = path25.join(root, file.newPath);
7276
- const realRoot2 = fs28.realpathSync(path25.resolve(root));
7312
+ const absPath = path23.join(root, file.newPath);
7313
+ const realRoot2 = fs28.realpathSync(path23.resolve(root));
7277
7314
  const realPath = fs28.realpathSync(absPath);
7278
- const sep = path25.sep;
7315
+ const sep = path23.sep;
7279
7316
  if (realPath === realRoot2 || realPath.startsWith(realRoot2 + sep)) {
7280
7317
  result.after = fs28.readFileSync(absPath, "utf-8");
7281
7318
  }
@@ -7305,7 +7342,7 @@ function isBinaryContent(buffer) {
7305
7342
  return false;
7306
7343
  }
7307
7344
  function synthesizeUntrackedDiff(root, relPath) {
7308
- const absPath = path25.join(root, relPath);
7345
+ const absPath = path23.join(root, relPath);
7309
7346
  let buffer;
7310
7347
  try {
7311
7348
  buffer = fs28.readFileSync(absPath);
@@ -7396,7 +7433,7 @@ function attachCoverage(root, files) {
7396
7433
  f.coverageMtimeMs = lcovMtimeMs;
7397
7434
  let srcMtimeMs = null;
7398
7435
  try {
7399
- srcMtimeMs = fs28.statSync(path25.join(root, f.path)).mtimeMs;
7436
+ srcMtimeMs = fs28.statSync(path23.join(root, f.path)).mtimeMs;
7400
7437
  } catch {
7401
7438
  srcMtimeMs = null;
7402
7439
  }
@@ -7464,7 +7501,7 @@ function computeRangeDiff(opts) {
7464
7501
 
7465
7502
  // src/core/repo-spec.ts
7466
7503
  import fs29 from "fs";
7467
- import path26 from "path";
7504
+ import path24 from "path";
7468
7505
  import os8 from "os";
7469
7506
  import crypto2 from "crypto";
7470
7507
  function scopeHashFor(keyPaths) {
@@ -7472,21 +7509,21 @@ function scopeHashFor(keyPaths) {
7472
7509
  return crypto2.createHash("sha1").update(key).digest("hex").slice(0, 12);
7473
7510
  }
7474
7511
  function stableDiffPath(keyPaths) {
7475
- const dir = path26.join(os8.homedir(), ".work", "diffs");
7512
+ const dir = path24.join(os8.homedir(), ".work", "diffs");
7476
7513
  fs29.mkdirSync(dir, { recursive: true });
7477
- return path26.join(dir, scopeHashFor(keyPaths));
7514
+ return path24.join(dir, scopeHashFor(keyPaths));
7478
7515
  }
7479
7516
 
7480
7517
  // src/core/diff-scope.ts
7481
7518
  import fs30 from "fs";
7482
- import path27 from "path";
7519
+ import path25 from "path";
7483
7520
  import chalk18 from "chalk";
7484
7521
  function normPath(p) {
7485
- return path27.resolve(p).replace(/\\/g, "/").toLowerCase();
7522
+ return path25.resolve(p).replace(/\\/g, "/").toLowerCase();
7486
7523
  }
7487
7524
  function realNorm(p) {
7488
7525
  try {
7489
- return normPath(fs30.realpathSync(p));
7526
+ return normPath(fs30.realpathSync.native(p));
7490
7527
  } catch {
7491
7528
  return normPath(p);
7492
7529
  }
@@ -7506,29 +7543,29 @@ function resolveScope(cwd) {
7506
7543
  return {
7507
7544
  isGroup: true,
7508
7545
  session: s,
7509
- repos: s.paths.map((rp) => ({ name: path27.basename(rp), root: rp })),
7510
- activeRepoName: path27.basename(p)
7546
+ repos: s.paths.map((rp) => ({ name: path25.basename(rp), root: rp })),
7547
+ activeRepoName: path25.basename(p)
7511
7548
  };
7512
7549
  }
7513
7550
  return {
7514
7551
  isGroup: false,
7515
7552
  session: s,
7516
- repos: [{ name: path27.basename(p), root: p }],
7517
- activeRepoName: path27.basename(p)
7553
+ repos: [{ name: path25.basename(p), root: p }],
7554
+ activeRepoName: path25.basename(p)
7518
7555
  };
7519
7556
  }
7520
7557
  }
7521
7558
  }
7522
7559
  for (const s of sessions) {
7523
7560
  if (!s.isGroup || s.paths.length === 0) continue;
7524
- const parents = s.paths.map((p) => normPath(path27.dirname(p)));
7561
+ const parents = s.paths.map((p) => normPath(path25.dirname(p)));
7525
7562
  const groupRoot = parents[0];
7526
7563
  if (!parents.every((par) => par === groupRoot)) continue;
7527
7564
  if (normCwd === groupRoot || normCwd.startsWith(groupRoot + "/")) {
7528
7565
  return {
7529
7566
  isGroup: true,
7530
7567
  session: s,
7531
- repos: s.paths.map((rp) => ({ name: path27.basename(rp), root: rp })),
7568
+ repos: s.paths.map((rp) => ({ name: path25.basename(rp), root: rp })),
7532
7569
  activeRepoName: null
7533
7570
  };
7534
7571
  }
@@ -7537,8 +7574,8 @@ function resolveScope(cwd) {
7537
7574
  return {
7538
7575
  isGroup: false,
7539
7576
  session: null,
7540
- repos: [{ name: path27.basename(toplevel), root: toplevel }],
7541
- activeRepoName: path27.basename(toplevel)
7577
+ repos: [{ name: path25.basename(toplevel), root: toplevel }],
7578
+ activeRepoName: path25.basename(toplevel)
7542
7579
  };
7543
7580
  }
7544
7581
  function findAnyParentBranch(cwd) {
@@ -7649,7 +7686,7 @@ function createCommentStore() {
7649
7686
  }
7650
7687
  const parent = findParent2(input2.parentId);
7651
7688
  const side = input2.side ?? parent?.side ?? "general";
7652
- if (side !== "left" && side !== "right" && side !== "general") {
7689
+ if (side !== "left" && side !== "right" && side !== "general" && side !== "file") {
7653
7690
  throw new Error("invalid side");
7654
7691
  }
7655
7692
  const c = {
@@ -7674,6 +7711,14 @@ function createCommentStore() {
7674
7711
  comments.splice(idx, 1);
7675
7712
  return true;
7676
7713
  },
7714
+ setResolved(id, resolved) {
7715
+ const c = comments.find((x) => x.id === id);
7716
+ if (!c) return null;
7717
+ const next = resolved || void 0;
7718
+ if (c.resolved === next) return null;
7719
+ c.resolved = next;
7720
+ return c;
7721
+ },
7677
7722
  submit(summary) {
7678
7723
  const drafts = comments.filter((c) => c.status === "draft").sort((a, b) => a.createdAt.localeCompare(b.createdAt));
7679
7724
  let summaryComment = null;
@@ -7714,7 +7759,7 @@ import { streamSSE } from "hono/streaming";
7714
7759
 
7715
7760
  // src/core/file-context.ts
7716
7761
  import fs31 from "fs";
7717
- import path28 from "path";
7762
+ import path26 from "path";
7718
7763
  import spawn10 from "cross-spawn";
7719
7764
  function readContextLines(opts) {
7720
7765
  const { root, relPath, ref } = opts;
@@ -7736,10 +7781,10 @@ function readContextLines(opts) {
7736
7781
  }
7737
7782
  function readWorkingTree(root, relPath) {
7738
7783
  try {
7739
- const absPath = path28.join(root, relPath);
7740
- const realRoot2 = fs31.realpathSync(path28.resolve(root));
7784
+ const absPath = path26.join(root, relPath);
7785
+ const realRoot2 = fs31.realpathSync(path26.resolve(root));
7741
7786
  const realPath = fs31.realpathSync(absPath);
7742
- const sep = path28.sep;
7787
+ const sep = path26.sep;
7743
7788
  if (realPath !== realRoot2 && !realPath.startsWith(realRoot2 + sep)) {
7744
7789
  return null;
7745
7790
  }
@@ -7761,7 +7806,7 @@ function readAtRef(root, ref, relPath) {
7761
7806
 
7762
7807
  // src/core/fs-watcher.ts
7763
7808
  import fs32 from "fs";
7764
- import path29 from "path";
7809
+ import path27 from "path";
7765
7810
  import chalk19 from "chalk";
7766
7811
  import chokidar from "chokidar";
7767
7812
  var IGNORED_DIRS = /* @__PURE__ */ new Set([
@@ -7787,7 +7832,7 @@ var IGNORED_DIRS = /* @__PURE__ */ new Set([
7787
7832
  ]);
7788
7833
  function isIgnoredWatchPath(roots, filePath) {
7789
7834
  for (const root of roots) {
7790
- const rel = path29.relative(root, filePath).replace(/\\/g, "/");
7835
+ const rel = path27.relative(root, filePath).replace(/\\/g, "/");
7791
7836
  if (rel === "" || rel.startsWith("../")) continue;
7792
7837
  if (rel.split("/").some((seg) => IGNORED_DIRS.has(seg))) return true;
7793
7838
  }
@@ -7812,7 +7857,7 @@ function createFsWatcher(opts) {
7812
7857
  if (SUPPORTS_RECURSIVE_WATCH) {
7813
7858
  const watchers = opts.roots.map((root) => {
7814
7859
  const w = fs32.watch(root, { recursive: true }, (_event, filename) => {
7815
- if (filename && isIgnoredWatchPath([root], path29.join(root, filename.toString()))) {
7860
+ if (filename && isIgnoredWatchPath([root], path27.join(root, filename.toString()))) {
7816
7861
  return;
7817
7862
  }
7818
7863
  fire();
@@ -7851,29 +7896,29 @@ function createFsWatcher(opts) {
7851
7896
 
7852
7897
  // src/core/web-static.ts
7853
7898
  import fs33 from "fs";
7854
- import path30 from "path";
7899
+ import path28 from "path";
7855
7900
  import { fileURLToPath } from "url";
7856
7901
  function resolveWebRoot() {
7857
- const entryDir = path30.dirname(process.argv[1] ?? "");
7858
- const moduleDir = path30.dirname(fileURLToPath(import.meta.url));
7902
+ const entryDir = path28.dirname(process.argv[1] ?? "");
7903
+ const moduleDir = path28.dirname(fileURLToPath(import.meta.url));
7859
7904
  const candidates = [
7860
- path30.join(entryDir, "web"),
7905
+ path28.join(entryDir, "web"),
7861
7906
  // bundled: this module is inlined into dist/<bin>.js, so dist/web is a
7862
7907
  // sibling of the bundle. Works even when argv[1] is an npm bin symlink
7863
7908
  // (which is not realpath'd, so the entryDir candidate above misses).
7864
- path30.join(moduleDir, "web"),
7909
+ path28.join(moduleDir, "web"),
7865
7910
  // dev/tsx fallback: walk up from src/core to repo root then into dist/web.
7866
- path30.resolve(moduleDir, "../../dist/web")
7911
+ path28.resolve(moduleDir, "../../dist/web")
7867
7912
  ];
7868
7913
  for (const c of candidates) {
7869
- if (fs33.existsSync(path30.join(c, "index.html"))) return c;
7914
+ if (fs33.existsSync(path28.join(c, "index.html"))) return c;
7870
7915
  }
7871
7916
  return null;
7872
7917
  }
7873
7918
 
7874
7919
  // src/core/spa-handler.ts
7875
7920
  import fs34 from "fs";
7876
- import path31 from "path";
7921
+ import path29 from "path";
7877
7922
  var MIME = {
7878
7923
  ".html": "text/html; charset=utf-8",
7879
7924
  ".js": "application/javascript; charset=utf-8",
@@ -7887,9 +7932,9 @@ var MIME = {
7887
7932
  function readFile(root, relPath) {
7888
7933
  const clean = relPath.split("?")[0];
7889
7934
  const requested = clean === "/" ? "/index.html" : clean;
7890
- const filePath = path31.join(root, requested);
7891
- const norm = path31.normalize(filePath);
7892
- if (!norm.startsWith(path31.normalize(root))) return null;
7935
+ const filePath = path29.join(root, requested);
7936
+ const norm = path29.normalize(filePath);
7937
+ if (!norm.startsWith(path29.normalize(root))) return null;
7893
7938
  let stat;
7894
7939
  try {
7895
7940
  stat = fs34.statSync(norm);
@@ -7897,7 +7942,7 @@ function readFile(root, relPath) {
7897
7942
  return null;
7898
7943
  }
7899
7944
  if (!stat.isFile()) return null;
7900
- const ext = path31.extname(norm).toLowerCase();
7945
+ const ext = path29.extname(norm).toLowerCase();
7901
7946
  return { body: fs34.readFileSync(norm), ext };
7902
7947
  }
7903
7948
  function serveSpa(c, webRoot) {
@@ -8062,7 +8107,7 @@ var commentInputSchema = z.object({
8062
8107
  repo: z.string().optional(),
8063
8108
  file: z.string().optional(),
8064
8109
  line: z.number().int().optional(),
8065
- side: z.enum(["left", "right", "general"]).optional(),
8110
+ side: z.enum(["left", "right", "general", "file"]).optional(),
8066
8111
  body: z.string().min(1),
8067
8112
  status: z.enum(["published", "draft"]).optional(),
8068
8113
  lineContent: z.string().optional(),
@@ -8072,6 +8117,9 @@ var commentInputSchema = z.object({
8072
8117
  var submitReviewSchema = z.object({
8073
8118
  summary: z.string().optional()
8074
8119
  });
8120
+ var resolveSchema = z.object({
8121
+ resolved: z.boolean()
8122
+ });
8075
8123
 
8076
8124
  // src/core/comment-server.ts
8077
8125
  async function startCommentServer(opts) {
@@ -8108,6 +8156,18 @@ async function startCommentServer(opts) {
8108
8156
  if (removed && opts.onCommentDeleted) opts.onCommentDeleted(id);
8109
8157
  return c.json({ comments: store.snapshot() });
8110
8158
  });
8159
+ routes.post(
8160
+ "/api/comments/:id/resolve",
8161
+ zValidator("json", resolveSchema),
8162
+ (c) => {
8163
+ const updated = store.setResolved(
8164
+ c.req.param("id"),
8165
+ c.req.valid("json").resolved
8166
+ );
8167
+ if (updated) api.broadcast("comments-changed", { id: updated.id });
8168
+ return c.json({ comments: store.snapshot() });
8169
+ }
8170
+ );
8111
8171
  routes.post(
8112
8172
  "/api/submit-review",
8113
8173
  zValidator("json", submitReviewSchema),
@@ -8162,7 +8222,7 @@ async function startCommentServer(opts) {
8162
8222
  }
8163
8223
  function formatSingleComment(c) {
8164
8224
  const bodyLines = c.body.split("\n").map((l) => `> ${l}`).join("\n");
8165
- const header = c.side === "general" ? `**General review comment**` : `**${c.repo}/${c.file}** : line ${c.line} (${c.side})`;
8225
+ const header = c.side === "general" ? `**General review comment**` : c.side === "file" ? `**${c.repo}/${c.file}** : whole file` : `**${c.repo}/${c.file}** : line ${c.line} (${c.side})`;
8166
8226
  const meta = [];
8167
8227
  if (c.author === "claude") meta.push("author: claude");
8168
8228
  if (c.parentId) meta.push(`reply-to: ${c.parentId}`);
@@ -8192,7 +8252,7 @@ function diffReviewSnapshot(snapshot, seen) {
8192
8252
 
8193
8253
  // src/core/static-renderer.ts
8194
8254
  import fs35 from "fs";
8195
- import path32 from "path";
8255
+ import path30 from "path";
8196
8256
  function buildDiff(specs, resolvedBase) {
8197
8257
  return {
8198
8258
  repos: specs.map((r) => ({
@@ -8208,7 +8268,7 @@ function renderStatic(opts) {
8208
8268
  if (!webRoot) {
8209
8269
  throw new Error("Could not find dist/web/. Run `npm run build` first.");
8210
8270
  }
8211
- const shellPath = path32.join(webRoot, "index.html");
8271
+ const shellPath = path30.join(webRoot, "index.html");
8212
8272
  let shell = fs35.readFileSync(shellPath, "utf-8");
8213
8273
  const uncommitted = buildDiff(opts.uncommitted, "HEAD");
8214
8274
  const branch = opts.branch ? buildDiff(opts.branch.specs, opts.branch.resolvedBase) : void 0;
@@ -8258,8 +8318,8 @@ function escapeForScriptTag(json) {
8258
8318
  }
8259
8319
  function readAsset(webRoot, urlPath) {
8260
8320
  const clean = urlPath.split("?")[0].replace(/^\//, "");
8261
- const full = path32.join(webRoot, clean);
8262
- if (!path32.normalize(full).startsWith(path32.normalize(webRoot))) return null;
8321
+ const full = path30.join(webRoot, clean);
8322
+ if (!path30.normalize(full).startsWith(path30.normalize(webRoot))) return null;
8263
8323
  try {
8264
8324
  return fs35.readFileSync(full, "utf-8");
8265
8325
  } catch {
@@ -8302,7 +8362,7 @@ async function runStop(repoSpecs) {
8302
8362
  }
8303
8363
  }
8304
8364
  function webUrlFilePath() {
8305
- return path33.join(os9.homedir(), ".work", "web.url");
8365
+ return path31.join(os9.homedir(), ".work", "web.url");
8306
8366
  }
8307
8367
  function resolveWorkBinPath(selfArgv1) {
8308
8368
  let real = selfArgv1;
@@ -8311,7 +8371,7 @@ function resolveWorkBinPath(selfArgv1) {
8311
8371
  } catch {
8312
8372
  }
8313
8373
  if (real.endsWith("wd-bin.js")) {
8314
- return path33.join(path33.dirname(real), "bin.js");
8374
+ return path31.join(path31.dirname(real), "bin.js");
8315
8375
  }
8316
8376
  return real;
8317
8377
  }
@@ -8323,12 +8383,32 @@ function readWebUrl() {
8323
8383
  return null;
8324
8384
  }
8325
8385
  }
8386
+ async function webServerResponds(url, timeoutMs = 1500) {
8387
+ try {
8388
+ const ctrl = new AbortController();
8389
+ const timer = setTimeout(() => ctrl.abort(), timeoutMs);
8390
+ try {
8391
+ const res = await fetch(`${url}api/context`, { signal: ctrl.signal });
8392
+ return res.ok;
8393
+ } finally {
8394
+ clearTimeout(timer);
8395
+ }
8396
+ } catch {
8397
+ return false;
8398
+ }
8399
+ }
8326
8400
  async function ensureWorkWebRunning() {
8327
8401
  const existing = readWebUrl();
8328
- if (existing) return existing;
8402
+ if (existing) {
8403
+ if (await webServerResponds(existing)) return existing;
8404
+ try {
8405
+ fs36.unlinkSync(webUrlFilePath());
8406
+ } catch {
8407
+ }
8408
+ }
8329
8409
  const workBin = resolveWorkBinPath(process.argv[1]);
8330
8410
  const out = fs36.openSync(
8331
- path33.join(os9.homedir(), ".work", "web-autostart.log"),
8411
+ path31.join(os9.homedir(), ".work", "web-autostart.log"),
8332
8412
  "a"
8333
8413
  );
8334
8414
  const child = childSpawn(
@@ -8670,19 +8750,19 @@ var diffCommand = {
8670
8750
  // src/commands/web.ts
8671
8751
  import fs41 from "fs";
8672
8752
  import os13 from "os";
8673
- import path42 from "path";
8753
+ import path41 from "path";
8674
8754
  import chalk23 from "chalk";
8675
8755
 
8676
8756
  // src/core/web-server.ts
8677
8757
  import fs40 from "fs";
8678
8758
  import os12 from "os";
8679
- import path41 from "path";
8759
+ import path40 from "path";
8680
8760
  import chalk22 from "chalk";
8681
8761
  import { Hono as Hono3 } from "hono";
8682
8762
  import { streamSSE as streamSSE3 } from "hono/streaming";
8683
8763
 
8684
8764
  // src/core/web-state.ts
8685
- import path34 from "path";
8765
+ import path32 from "path";
8686
8766
  import crypto4 from "crypto";
8687
8767
  import chokidar2 from "chokidar";
8688
8768
  function sessionIdFor(s) {
@@ -8703,7 +8783,7 @@ function subscribeSession(sessionId, onChange) {
8703
8783
  const watcher = chokidar2.watch(roots, {
8704
8784
  ignored: (filePath) => {
8705
8785
  for (const r of roots) {
8706
- const rel = path34.relative(r, filePath).replace(/\\/g, "/");
8786
+ const rel = path32.relative(r, filePath).replace(/\\/g, "/");
8707
8787
  if (rel === ".git" || rel.startsWith(".git/")) return true;
8708
8788
  }
8709
8789
  return false;
@@ -8818,16 +8898,16 @@ function disposeAllPtys() {
8818
8898
 
8819
8899
  // src/core/comment-file-store.ts
8820
8900
  import fs37 from "fs";
8821
- import path35 from "path";
8901
+ import path33 from "path";
8822
8902
  import os10 from "os";
8823
8903
  function commentsDir() {
8824
- return path35.join(os10.homedir(), ".work", "comments");
8904
+ return path33.join(os10.homedir(), ".work", "comments");
8825
8905
  }
8826
8906
  function ensureDir() {
8827
8907
  fs37.mkdirSync(commentsDir(), { recursive: true });
8828
8908
  }
8829
8909
  function commentsFileFor(sessionId) {
8830
- return path35.join(commentsDir(), `${sessionId}.json`);
8910
+ return path33.join(commentsDir(), `${sessionId}.json`);
8831
8911
  }
8832
8912
  function pathFor(sessionId) {
8833
8913
  return commentsFileFor(sessionId);
@@ -8882,6 +8962,12 @@ function getCommentFileStore(sessionId) {
8882
8962
  return { value: r, persisted: r };
8883
8963
  });
8884
8964
  },
8965
+ setResolved(id, resolved) {
8966
+ return lockedMutate(() => {
8967
+ const c = inner.setResolved(id, resolved);
8968
+ return { value: c, persisted: c !== null };
8969
+ });
8970
+ },
8885
8971
  submit(summary) {
8886
8972
  return lockedMutate(() => {
8887
8973
  const result = inner.submit(summary);
@@ -8907,11 +8993,11 @@ function clearCommentStoreCache() {
8907
8993
 
8908
8994
  // src/core/pending-delivery.ts
8909
8995
  import fs38 from "fs";
8910
- import path36 from "path";
8996
+ import path34 from "path";
8911
8997
  function pathFor2(sessionId) {
8912
8998
  return {
8913
8999
  comments: commentsFileFor(sessionId),
8914
- delivered: path36.join(commentsDir(), `${sessionId}.delivered.json`)
9000
+ delivered: path34.join(commentsDir(), `${sessionId}.delivered.json`)
8915
9001
  };
8916
9002
  }
8917
9003
  function readJson(filePath, fallback) {
@@ -8922,13 +9008,13 @@ function readJson(filePath, fallback) {
8922
9008
  }
8923
9009
  }
8924
9010
  function writeAtomic2(filePath, content) {
8925
- fs38.mkdirSync(path36.dirname(filePath), { recursive: true });
9011
+ fs38.mkdirSync(path34.dirname(filePath), { recursive: true });
8926
9012
  const tmp = `${filePath}.tmp-${process.pid}-${Date.now()}`;
8927
9013
  fs38.writeFileSync(tmp, content, "utf-8");
8928
9014
  fs38.renameSync(tmp, filePath);
8929
9015
  }
8930
9016
  function normalize(p) {
8931
- return path36.resolve(p).replace(/\\/g, "/").toLowerCase();
9017
+ return path34.resolve(p).replace(/\\/g, "/").toLowerCase();
8932
9018
  }
8933
9019
  function findSessionForCwd(cwd) {
8934
9020
  const norm = normalize(cwd);
@@ -8959,7 +9045,7 @@ function readPendingForSession(sessionId) {
8959
9045
  return comments.filter(isPendingFor(delivered));
8960
9046
  }
8961
9047
  function scopeStoreIdsForPaths(paths) {
8962
- const resolved = paths.map((p) => path36.resolve(p));
9048
+ const resolved = paths.map((p) => path34.resolve(p));
8963
9049
  const ids = /* @__PURE__ */ new Set();
8964
9050
  ids.add(`scope-${scopeHashFor(resolved)}`);
8965
9051
  for (const p of resolved) ids.add(`scope-${scopeHashFor([p])}`);
@@ -9115,6 +9201,21 @@ function mountSessionCommentRoutes(app, opts) {
9115
9201
  if (removed) opts.broadcast("comments-changed", { sessionId: id, deleted: cid });
9116
9202
  return c.json({ comments: store.snapshot() });
9117
9203
  });
9204
+ app.post(
9205
+ "/api/sessions/:id/comments/:cid/resolve",
9206
+ zValidator2("json", resolveSchema),
9207
+ (c) => {
9208
+ const id = c.req.param("id");
9209
+ if (!requireSession(id)) return c.json({ error: "unknown session" }, 404);
9210
+ const store = getCommentFileStore(id);
9211
+ const updated = store.setResolved(
9212
+ c.req.param("cid"),
9213
+ c.req.valid("json").resolved
9214
+ );
9215
+ if (updated) opts.broadcast("comments-changed", { sessionId: id, id: updated.id });
9216
+ return c.json({ comments: store.snapshot() });
9217
+ }
9218
+ );
9118
9219
  app.post(
9119
9220
  "/api/sessions/:id/submit-review",
9120
9221
  zValidator2("json", submitReviewSchema),
@@ -9282,7 +9383,7 @@ function mountPanesRoutes(app, opts) {
9282
9383
  }
9283
9384
 
9284
9385
  // src/core/worktree-routes.ts
9285
- import path37 from "path";
9386
+ import path35 from "path";
9286
9387
  import { spawn as spawn11 } from "child_process";
9287
9388
  import { zValidator as zValidator4 } from "@hono/zod-validator";
9288
9389
  import { z as z3 } from "zod";
@@ -9406,7 +9507,7 @@ function mountWorktreeRoutes(app, opts) {
9406
9507
  const id = c.req.param("id");
9407
9508
  const session = findSession2(id);
9408
9509
  if (!session) return c.json({ error: "unknown session" }, 404);
9409
- const target = session.isGroup ? path37.dirname(session.paths[0]) : session.paths[0];
9510
+ const target = session.isGroup ? path35.dirname(session.paths[0]) : session.paths[0];
9410
9511
  try {
9411
9512
  const cmd = process.platform === "win32" ? "code.cmd" : "code";
9412
9513
  const child = spawn11(cmd, [target], {
@@ -9426,18 +9527,18 @@ function mountWorktreeRoutes(app, opts) {
9426
9527
  import { zValidator as zValidator5 } from "@hono/zod-validator";
9427
9528
  import { z as z4 } from "zod";
9428
9529
  import { EventEmitter } from "events";
9429
- import path40 from "path";
9430
- import spawn13 from "cross-spawn";
9530
+ import path39 from "path";
9531
+ import spawn14 from "cross-spawn";
9431
9532
 
9432
9533
  // src/core/checkpoint.ts
9433
9534
  import fs39 from "fs";
9434
9535
  import os11 from "os";
9435
- import path38 from "path";
9536
+ import path36 from "path";
9436
9537
  import spawn12 from "cross-spawn";
9437
9538
  function manifestPath(scopeHash) {
9438
- const dir = path38.join(os11.homedir(), ".work", "diffs");
9539
+ const dir = path36.join(os11.homedir(), ".work", "diffs");
9439
9540
  fs39.mkdirSync(dir, { recursive: true });
9440
- return path38.join(dir, `${scopeHash}.checkpoints.json`);
9541
+ return path36.join(dir, `${scopeHash}.checkpoints.json`);
9441
9542
  }
9442
9543
  function emptyManifest(scopeHash) {
9443
9544
  return { version: 1, scopeHash, entries: [] };
@@ -9556,6 +9657,17 @@ async function takeCheckpoint(scopeHash, repos, opts = {}) {
9556
9657
  return entry;
9557
9658
  });
9558
9659
  }
9660
+ async function setCheckpointLabel(scopeHash, id, label2) {
9661
+ const file = manifestPath(scopeHash);
9662
+ ensureFile(file, JSON.stringify(emptyManifest(scopeHash), null, 2));
9663
+ await withFileLock(file, () => {
9664
+ const manifest = loadManifest(scopeHash);
9665
+ const entry = manifest.entries.find((e) => e.id === id);
9666
+ if (!entry || entry.label === label2) return;
9667
+ entry.label = label2;
9668
+ atomicWriteFile(file, JSON.stringify(manifest, null, 2));
9669
+ });
9670
+ }
9559
9671
  function clearCheckpoints(scopeHash, repoRoots) {
9560
9672
  const manifest = loadManifest(scopeHash);
9561
9673
  for (const root of repoRoots) {
@@ -9577,8 +9689,130 @@ function clearCheckpoints(scopeHash, repoRoots) {
9577
9689
  }
9578
9690
  }
9579
9691
 
9692
+ // src/core/checkpoint-summary.ts
9693
+ import spawn13 from "cross-spawn";
9694
+ import path37 from "path";
9695
+ var MAX_DIFF_CHARS = 6e3;
9696
+ var MAX_LABEL_CHARS = 80;
9697
+ function buildDelta(scopeHash, repos, id) {
9698
+ const manifest = loadManifest(scopeHash);
9699
+ const entry = manifest.entries.find((e) => e.id === id);
9700
+ const prev = manifest.entries.find((e) => e.id === id - 1);
9701
+ const all = [];
9702
+ for (const repo of repos) {
9703
+ const toRef = entry?.repos[repo.name];
9704
+ if (!toRef) continue;
9705
+ const fromRef = prev?.repos[repo.name] ?? "HEAD";
9706
+ try {
9707
+ all.push(...computeRangeDiff({ root: repo.root, fromRef, toRef }));
9708
+ } catch {
9709
+ }
9710
+ }
9711
+ let added = 0;
9712
+ let deleted = 0;
9713
+ for (const f of all) {
9714
+ added += f.added;
9715
+ deleted += f.deleted;
9716
+ }
9717
+ const parts = [];
9718
+ let budget = MAX_DIFF_CHARS;
9719
+ for (const f of all) {
9720
+ const head = `### ${f.status} ${f.path} (+${f.added} -${f.deleted})
9721
+ `;
9722
+ if (budget - head.length < 0) break;
9723
+ parts.push(head);
9724
+ budget -= head.length;
9725
+ for (const h of f.hunks) {
9726
+ for (const ln of h.lines) {
9727
+ if (ln.kind !== "add" && ln.kind !== "delete") continue;
9728
+ const prefix = ln.kind === "add" ? "+" : "-";
9729
+ const line = `${prefix}${ln.content}
9730
+ `;
9731
+ if (budget - line.length < 0) {
9732
+ budget = -1;
9733
+ break;
9734
+ }
9735
+ parts.push(line);
9736
+ budget -= line.length;
9737
+ }
9738
+ if (budget < 0) break;
9739
+ }
9740
+ if (budget < 0) break;
9741
+ }
9742
+ return { files: all, added, deleted, text: parts.join("") };
9743
+ }
9744
+ function heuristicLabel(files, added, deleted) {
9745
+ if (files.length === 0) return "no changes";
9746
+ if (files.length === 1) {
9747
+ return `${path37.basename(files[0].path)} +${added} \u2212${deleted}`;
9748
+ }
9749
+ return `${files.length} files \xB7 +${added} \u2212${deleted}`;
9750
+ }
9751
+ function runClaude(prompt, timeoutMs = 25e3) {
9752
+ return new Promise((resolve) => {
9753
+ let settled = false;
9754
+ const finish = (v) => {
9755
+ if (settled) return;
9756
+ settled = true;
9757
+ resolve(v);
9758
+ };
9759
+ let out = "";
9760
+ let child;
9761
+ try {
9762
+ child = spawn13("claude", ["-p"], {
9763
+ stdio: ["pipe", "pipe", "ignore"],
9764
+ windowsHide: true
9765
+ });
9766
+ } catch {
9767
+ finish(null);
9768
+ return;
9769
+ }
9770
+ const timer = setTimeout(() => {
9771
+ try {
9772
+ child.kill();
9773
+ } catch {
9774
+ }
9775
+ finish(null);
9776
+ }, timeoutMs);
9777
+ child.stdout?.on("data", (d) => {
9778
+ out += d.toString();
9779
+ });
9780
+ child.on("error", () => {
9781
+ clearTimeout(timer);
9782
+ finish(null);
9783
+ });
9784
+ child.on("close", (code) => {
9785
+ clearTimeout(timer);
9786
+ finish(code === 0 && out.trim() ? out.trim() : null);
9787
+ });
9788
+ try {
9789
+ child.stdin?.write(prompt);
9790
+ child.stdin?.end();
9791
+ } catch {
9792
+ clearTimeout(timer);
9793
+ finish(null);
9794
+ }
9795
+ });
9796
+ }
9797
+ function cleanLabel(raw) {
9798
+ const firstLine = raw.split("\n").map((l) => l.trim()).find(Boolean) ?? "";
9799
+ const cleaned = firstLine.replace(/^["'`]+|["'`]+$/g, "").replace(/\s+/g, " ").replace(/[.;]+$/, "").trim();
9800
+ return cleaned.slice(0, MAX_LABEL_CHARS);
9801
+ }
9802
+ async function summarizeCheckpoint(scopeHash, repos, id) {
9803
+ const { files, added, deleted, text } = buildDelta(scopeHash, repos, id);
9804
+ if (files.length === 0) return "no changes";
9805
+ const fallback = heuristicLabel(files, added, deleted);
9806
+ if (!text.trim()) return fallback;
9807
+ const prompt = "Summarise this code change in 8 words or fewer, imperative mood, no trailing punctuation. Output ONLY the summary line.\n\n" + text;
9808
+ const reply = await runClaude(prompt);
9809
+ if (!reply) return fallback;
9810
+ const label2 = cleanLabel(reply);
9811
+ return label2 || fallback;
9812
+ }
9813
+
9580
9814
  // src/core/scope-manager.ts
9581
- import path39 from "path";
9815
+ import path38 from "path";
9582
9816
  import crypto5 from "crypto";
9583
9817
  var scopes = /* @__PURE__ */ new Map();
9584
9818
  function hashFor(paths) {
@@ -9595,7 +9829,7 @@ var ScopePathRejectedError = class extends Error {
9595
9829
  }
9596
9830
  };
9597
9831
  function normaliseForCompare(p) {
9598
- return path39.resolve(p).replace(/\\/g, "/").toLowerCase();
9832
+ return path38.resolve(p).replace(/\\/g, "/").toLowerCase();
9599
9833
  }
9600
9834
  function rejectedPaths(normalised) {
9601
9835
  const config = loadConfig();
@@ -9613,7 +9847,7 @@ function rejectedPaths(normalised) {
9613
9847
  });
9614
9848
  }
9615
9849
  function registerScope(paths, label2) {
9616
- const normalised = paths.map((p) => path39.resolve(p));
9850
+ const normalised = paths.map((p) => path38.resolve(p));
9617
9851
  const rejected = rejectedPaths(normalised);
9618
9852
  if (rejected.length > 0) throw new ScopePathRejectedError(rejected);
9619
9853
  const hash = hashFor(normalised);
@@ -9627,11 +9861,16 @@ function registerScope(paths, label2) {
9627
9861
  const scope = {
9628
9862
  hash,
9629
9863
  paths: normalised,
9630
- label: label2 ?? path39.basename(normalised[0]),
9864
+ label: label2 ?? path38.basename(normalised[0]),
9631
9865
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
9632
9866
  ended: false
9633
9867
  };
9634
- scopes.set(hash, { scope, watcher: null, subscribers: /* @__PURE__ */ new Set() });
9868
+ scopes.set(hash, {
9869
+ scope,
9870
+ watcher: null,
9871
+ subscribers: /* @__PURE__ */ new Set(),
9872
+ suppressWatchUntil: 0
9873
+ });
9635
9874
  return scope;
9636
9875
  }
9637
9876
  function markScopeEnded(hash) {
@@ -9644,6 +9883,20 @@ function markScopeEnded(hash) {
9644
9883
  function getScope(hash) {
9645
9884
  return scopes.get(hash)?.scope ?? null;
9646
9885
  }
9886
+ function suppressScopeWatch(hash, ms) {
9887
+ const entry = scopes.get(hash);
9888
+ if (entry) entry.suppressWatchUntil = Date.now() + ms;
9889
+ }
9890
+ function scopeCoversCwd(paths, cwd) {
9891
+ const nc = normaliseForCompare(cwd);
9892
+ return paths.some((p) => {
9893
+ const np = normaliseForCompare(p);
9894
+ return np === nc || np.startsWith(nc + "/") || nc.startsWith(np + "/");
9895
+ });
9896
+ }
9897
+ function scopesForCwd(cwd) {
9898
+ return Array.from(scopes.values()).map((e) => e.scope).filter((s) => scopeCoversCwd(s.paths, cwd));
9899
+ }
9647
9900
  function listScopes() {
9648
9901
  return Array.from(scopes.values()).map((e) => e.scope);
9649
9902
  }
@@ -9664,6 +9917,7 @@ function subscribeScope(hash, cb) {
9664
9917
  roots: entry.scope.paths,
9665
9918
  debounceMs: 150,
9666
9919
  onChange: () => {
9920
+ if (Date.now() < entry.suppressWatchUntil) return;
9667
9921
  for (const sub of entry.subscribers) {
9668
9922
  try {
9669
9923
  sub();
@@ -9697,10 +9951,13 @@ import { streamSSE as streamSSE2 } from "hono/streaming";
9697
9951
  function mountScopeRoutes(app, opts) {
9698
9952
  const checkpointWatched = /* @__PURE__ */ new Set();
9699
9953
  const lastStatus = /* @__PURE__ */ new Map();
9954
+ const snapshotTimers = /* @__PURE__ */ new Map();
9955
+ const CHECKPOINT_SETTLE_MS = 4e3;
9956
+ const CLAUDE_SESSION_MS = 5 * 6e4;
9700
9957
  function workingTreeFingerprint(paths) {
9701
9958
  const parts = [];
9702
9959
  for (const p of paths) {
9703
- const r = spawn13.sync(
9960
+ const r = spawn14.sync(
9704
9961
  "git",
9705
9962
  ["status", "--porcelain", "--no-renames", "-z"],
9706
9963
  { cwd: p, encoding: "utf-8", windowsHide: true }
@@ -9742,18 +9999,32 @@ function mountScopeRoutes(app, opts) {
9742
9999
  }
9743
10000
  if (!checkpointWatched.has(scope.hash)) {
9744
10001
  checkpointWatched.add(scope.hash);
9745
- subscribeScope(scope.hash, () => {
10002
+ const hash = scope.hash;
10003
+ const runSnapshot = () => {
10004
+ snapshotTimers.delete(hash);
10005
+ const claudeMs = scope.paths.reduce(
10006
+ (m, p) => Math.max(m, getClaudeActivityMs(p)),
10007
+ 0
10008
+ );
10009
+ if (claudeActiveWithin(claudeMs, Date.now(), CLAUDE_SESSION_MS)) {
10010
+ return;
10011
+ }
9746
10012
  try {
9747
10013
  const fp = workingTreeFingerprint(scope.paths);
9748
- if (lastStatus.get(scope.hash) === fp) return;
9749
- lastStatus.set(scope.hash, fp);
10014
+ if (lastStatus.get(hash) === fp) return;
10015
+ lastStatus.set(hash, fp);
9750
10016
  } catch {
9751
10017
  }
9752
- takeCheckpoint(scope.hash, scopeRepos(scope.paths)).then((entry) => {
10018
+ takeCheckpoint(hash, scopeRepos(scope.paths)).then((entry) => {
9753
10019
  if (entry) announceCheckpoint(entry);
9754
10020
  }).catch((err) => {
9755
10021
  console.error("[checkpoint] auto-snapshot failed:", err);
9756
10022
  });
10023
+ };
10024
+ subscribeScope(hash, () => {
10025
+ const pending = snapshotTimers.get(hash);
10026
+ if (pending) clearTimeout(pending);
10027
+ snapshotTimers.set(hash, setTimeout(runSnapshot, CHECKPOINT_SETTLE_MS));
9757
10028
  });
9758
10029
  }
9759
10030
  return c.json({
@@ -9770,6 +10041,27 @@ function mountScopeRoutes(app, opts) {
9770
10041
  }
9771
10042
  );
9772
10043
  app.get("/api/scopes", (c) => c.json({ scopes: listScopes() }));
10044
+ app.post(
10045
+ "/api/checkpoint",
10046
+ zValidator5("json", z4.object({ cwd: z4.string().min(1) })),
10047
+ async (c) => {
10048
+ const { cwd } = c.req.valid("json");
10049
+ const matched = scopesForCwd(cwd);
10050
+ let snapshotted = 0;
10051
+ for (const s of matched) {
10052
+ const entry = await takeCheckpoint(s.hash, scopeRepos(s.paths)).catch(
10053
+ () => null
10054
+ );
10055
+ if (entry) {
10056
+ const payload = { scopeHash: s.hash, id: entry.id };
10057
+ opts.broadcast("checkpoints-changed", payload);
10058
+ scopeBus.emit("checkpoints-changed", payload);
10059
+ snapshotted++;
10060
+ }
10061
+ }
10062
+ return c.json({ ok: true, scopes: matched.length, snapshotted });
10063
+ }
10064
+ );
9773
10065
  app.delete("/api/scopes/:hash", (c) => {
9774
10066
  const hash = c.req.param("hash");
9775
10067
  const scope = getScope(hash);
@@ -9777,6 +10069,11 @@ function mountScopeRoutes(app, opts) {
9777
10069
  const ok = removeScope(hash);
9778
10070
  checkpointWatched.delete(hash);
9779
10071
  lastStatus.delete(hash);
10072
+ const pendingTimer = snapshotTimers.get(hash);
10073
+ if (pendingTimer) {
10074
+ clearTimeout(pendingTimer);
10075
+ snapshotTimers.delete(hash);
10076
+ }
9780
10077
  if (repoPaths.length > 0) clearCheckpoints(hash, repoPaths);
9781
10078
  if (ok) opts.broadcast("scopes-changed", { hash });
9782
10079
  return c.json({ ok });
@@ -9824,11 +10121,12 @@ function mountScopeRoutes(app, opts) {
9824
10121
  const fromSha = fromEntry.repos[p] ?? "HEAD";
9825
10122
  const toSha = toEntry === void 0 ? "working" : toEntry.repos[p] ?? "HEAD";
9826
10123
  return {
9827
- name: path40.basename(p),
10124
+ name: path39.basename(p),
9828
10125
  root: p,
9829
10126
  files: computeRangeDiff({ root: p, fromRef: fromSha, toRef: toSha })
9830
10127
  };
9831
10128
  });
10129
+ suppressScopeWatch(scope.hash, 800);
9832
10130
  return c.json({
9833
10131
  scopeHash: scope.hash,
9834
10132
  base: "uncommitted",
@@ -9842,7 +10140,7 @@ function mountScopeRoutes(app, opts) {
9842
10140
  (p) => resolveRepoDiff(p, base, sessionBaseForPath(p))
9843
10141
  );
9844
10142
  const repos = scope.paths.map((p, i) => ({
9845
- name: path40.basename(p),
10143
+ name: path39.basename(p),
9846
10144
  root: p,
9847
10145
  resolvedBase: resolved[i].resolvedBase,
9848
10146
  files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
@@ -9850,6 +10148,7 @@ function mountScopeRoutes(app, opts) {
9850
10148
  const resolvedBase = resolved[0]?.resolvedBase ?? "HEAD";
9851
10149
  const head = git(["rev-parse", "--abbrev-ref", "HEAD"], scope.paths[0]);
9852
10150
  const headBranch = head.exitCode === 0 && head.stdout && head.stdout !== "HEAD" ? head.stdout : void 0;
10151
+ suppressScopeWatch(scope.hash, 800);
9853
10152
  return c.json({
9854
10153
  scopeHash: scope.hash,
9855
10154
  base,
@@ -9872,7 +10171,7 @@ function mountScopeRoutes(app, opts) {
9872
10171
  if (!relPath || !Number.isInteger(start) || !Number.isInteger(end)) {
9873
10172
  return c.json({ error: "bad path/start/end" }, 400);
9874
10173
  }
9875
- const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path40.basename(p) === repoName);
10174
+ const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path39.basename(p) === repoName);
9876
10175
  if (!root) return c.json({ error: "unknown repo" }, 404);
9877
10176
  const result = readContextLines({ root, relPath, start, end, ref });
9878
10177
  if (!result) return c.json({ error: "cannot read file" }, 400);
@@ -9887,6 +10186,22 @@ function mountScopeRoutes(app, opts) {
9887
10186
  entries: manifest.entries
9888
10187
  });
9889
10188
  });
10189
+ app.post("/api/scopes/:hash/checkpoints/:id/summary", async (c) => {
10190
+ const scope = getScope(c.req.param("hash"));
10191
+ if (!scope) return c.json({ error: "unknown scope" }, 404);
10192
+ const id = Number(c.req.param("id"));
10193
+ if (!Number.isInteger(id) || id < 0) {
10194
+ return c.json({ error: "bad checkpoint id" }, 400);
10195
+ }
10196
+ const entry = loadManifest(scope.hash).entries.find((e) => e.id === id);
10197
+ if (!entry) return c.json({ error: "unknown checkpoint" }, 404);
10198
+ if (entry.label && entry.label.trim()) return c.json({ label: entry.label });
10199
+ if (id === 0) return c.json({ label: "Initial" });
10200
+ const label2 = await summarizeCheckpoint(scope.hash, scopeRepos(scope.paths), id);
10201
+ await setCheckpointLabel(scope.hash, id, label2);
10202
+ opts.broadcast("checkpoints-changed", { scopeHash: scope.hash, id });
10203
+ return c.json({ label: label2 });
10204
+ });
9890
10205
  function commentStore(hash) {
9891
10206
  return getCommentFileStore(commentStoreIdForScope(hash));
9892
10207
  }
@@ -9930,6 +10245,26 @@ function mountScopeRoutes(app, opts) {
9930
10245
  }
9931
10246
  return c.json({ comments: store.snapshot() });
9932
10247
  });
10248
+ app.post(
10249
+ "/api/scopes/:hash/comments/:cid/resolve",
10250
+ zValidator5("json", resolveSchema),
10251
+ (c) => {
10252
+ const scope = getScope(c.req.param("hash"));
10253
+ if (!scope) return c.json({ error: "unknown scope" }, 404);
10254
+ const store = commentStore(scope.hash);
10255
+ const updated = store.setResolved(
10256
+ c.req.param("cid"),
10257
+ c.req.valid("json").resolved
10258
+ );
10259
+ if (updated) {
10260
+ opts.broadcast("comments-changed", {
10261
+ scopeHash: scope.hash,
10262
+ id: updated.id
10263
+ });
10264
+ }
10265
+ return c.json({ comments: store.snapshot() });
10266
+ }
10267
+ );
9933
10268
  app.post(
9934
10269
  "/api/scopes/:hash/submit-review",
9935
10270
  zValidator5("json", submitReviewSchema),
@@ -10110,7 +10445,7 @@ function computeSessionDiff(s, base) {
10110
10445
  (p) => resolveRepoDiff(p, base, s.baseBranches?.[p] ?? s.baseBranch)
10111
10446
  );
10112
10447
  const repos = s.paths.map((p, i) => ({
10113
- name: path41.basename(p),
10448
+ name: path40.basename(p),
10114
10449
  root: p,
10115
10450
  resolvedBase: resolved[i].resolvedBase,
10116
10451
  files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
@@ -10130,10 +10465,10 @@ async function startWebServer(opts = {}) {
10130
10465
  for (const cb of sseListeners) cb({ event, data });
10131
10466
  };
10132
10467
  const home = os12.homedir();
10133
- const historyPath = path41.join(home, ".work", "history.json");
10468
+ const historyPath = path40.join(home, ".work", "history.json");
10134
10469
  const onHistoryChange = () => broadcast("sessions-changed", { ts: Date.now() });
10135
10470
  fs40.watchFile(historyPath, { interval: 1e3 }, onHistoryChange);
10136
- const tasksPath = path41.join(home, ".work", "tasks.json");
10471
+ const tasksPath = path40.join(home, ".work", "tasks.json");
10137
10472
  const onTasksChange = () => broadcast("tasks-changed", { ts: Date.now() });
10138
10473
  fs40.watchFile(tasksPath, { interval: 1e3 }, onTasksChange);
10139
10474
  const projectsRoot = claudeProjectsRoot();
@@ -10278,10 +10613,10 @@ function info2(message) {
10278
10613
  process.stderr.write(message + "\n");
10279
10614
  }
10280
10615
  function urlFilePath() {
10281
- return path42.join(os13.homedir(), ".work", "web.url");
10616
+ return path41.join(os13.homedir(), ".work", "web.url");
10282
10617
  }
10283
10618
  function pidFilePath() {
10284
- return path42.join(os13.homedir(), ".work", "web.pid");
10619
+ return path41.join(os13.homedir(), ".work", "web.pid");
10285
10620
  }
10286
10621
  function isPidAlive(pid) {
10287
10622
  try {
@@ -10406,7 +10741,7 @@ var webCommand = {
10406
10741
  const lean = !!argv.lean || process.env.WORK_WEB_LEAN === "1";
10407
10742
  const handle = await startWebServer({ lean });
10408
10743
  try {
10409
- fs41.mkdirSync(path42.dirname(urlFilePath()), { recursive: true });
10744
+ fs41.mkdirSync(path41.dirname(urlFilePath()), { recursive: true });
10410
10745
  fs41.writeFileSync(urlFilePath(), handle.url);
10411
10746
  fs41.writeFileSync(pidFilePath(), String(process.pid));
10412
10747
  } catch {
@@ -10435,6 +10770,13 @@ var webCommand = {
10435
10770
  ]).catch(() => {
10436
10771
  });
10437
10772
  }
10773
+ await installCommandHook({
10774
+ owner: "web-checkpoint",
10775
+ event: "Stop",
10776
+ command: "work hook checkpoint",
10777
+ timeoutSec: 5
10778
+ }).catch(() => {
10779
+ });
10438
10780
  const shutdown = () => {
10439
10781
  info2(chalk23.gray("\nStopping work web."));
10440
10782
  try {
@@ -10455,6 +10797,10 @@ var webCommand = {
10455
10797
  } catch {
10456
10798
  }
10457
10799
  }
10800
+ try {
10801
+ removeCommandHookSync("web-checkpoint", "Stop");
10802
+ } catch {
10803
+ }
10458
10804
  handle.stop();
10459
10805
  process.exit(0);
10460
10806
  };
@@ -10476,6 +10822,31 @@ var webCommand = {
10476
10822
  };
10477
10823
 
10478
10824
  // src/commands/hook.ts
10825
+ import fs42 from "fs";
10826
+ import os14 from "os";
10827
+ import path42 from "path";
10828
+ async function triggerCheckpoint(cwd) {
10829
+ let base;
10830
+ try {
10831
+ base = fs42.readFileSync(path42.join(os14.homedir(), ".work", "web.url"), "utf-8").trim();
10832
+ } catch {
10833
+ return;
10834
+ }
10835
+ if (!base) return;
10836
+ const controller = new AbortController();
10837
+ const timer = setTimeout(() => controller.abort(), 3e3);
10838
+ try {
10839
+ await fetch(`${base}api/checkpoint`, {
10840
+ method: "POST",
10841
+ headers: { "Content-Type": "application/json" },
10842
+ body: JSON.stringify({ cwd }),
10843
+ signal: controller.signal
10844
+ });
10845
+ } catch {
10846
+ } finally {
10847
+ clearTimeout(timer);
10848
+ }
10849
+ }
10479
10850
  function computeHookOutput(input2) {
10480
10851
  const session = findSessionForCwd(input2.cwd);
10481
10852
  if (!session) return null;
@@ -10525,13 +10896,17 @@ var hookCommand = {
10525
10896
  // hidden — humans don't call this directly
10526
10897
  builder: (y) => y.positional("event", {
10527
10898
  type: "string",
10528
- choices: ["prompt-submit", "stop"],
10899
+ choices: ["prompt-submit", "stop", "checkpoint"],
10529
10900
  describe: "Hook event name"
10530
10901
  }),
10531
10902
  handler: async (argv) => {
10532
10903
  const event = argv.event;
10533
10904
  const payload = await readStdinJson();
10534
10905
  const cwd = payload.cwd ?? process.cwd();
10906
+ if (event === "checkpoint") {
10907
+ await triggerCheckpoint(cwd);
10908
+ return;
10909
+ }
10535
10910
  const result = computeHookOutput({ event, cwd });
10536
10911
  if (!result || !result.sessionId) return;
10537
10912
  process.stdout.write(result.stdout);
@@ -10541,7 +10916,7 @@ var hookCommand = {
10541
10916
 
10542
10917
  // src/commands/run.ts
10543
10918
  import chalk24 from "chalk";
10544
- import spawn14 from "cross-spawn";
10919
+ import spawn15 from "cross-spawn";
10545
10920
 
10546
10921
  // src/core/fleet.ts
10547
10922
  function selectSessions(sessions, filter) {
@@ -10583,7 +10958,7 @@ function killAllChildren(signal = "SIGTERM") {
10583
10958
  function runInPath(unit, cmd, prefix) {
10584
10959
  const { bin, args } = shellInvocation(cmd);
10585
10960
  return new Promise((resolve) => {
10586
- const child = spawn14(bin, args, {
10961
+ const child = spawn15(bin, args, {
10587
10962
  cwd: unit.path,
10588
10963
  stdio: prefix ? ["ignore", "pipe", "pipe"] : "inherit",
10589
10964
  shell: false
@@ -10815,15 +11190,15 @@ var runCommand = {
10815
11190
  };
10816
11191
 
10817
11192
  // src/commands/broadcast.ts
10818
- import fs43 from "fs";
11193
+ import fs44 from "fs";
10819
11194
  import chalk25 from "chalk";
10820
11195
 
10821
11196
  // src/core/broadcast.ts
10822
11197
  import crypto6 from "crypto";
10823
- import fs42 from "fs";
11198
+ import fs43 from "fs";
10824
11199
  function readComments(file) {
10825
11200
  try {
10826
- const parsed = JSON.parse(fs42.readFileSync(file, "utf-8"));
11201
+ const parsed = JSON.parse(fs43.readFileSync(file, "utf-8"));
10827
11202
  return Array.isArray(parsed) ? parsed : [];
10828
11203
  } catch {
10829
11204
  return [];
@@ -10831,7 +11206,7 @@ function readComments(file) {
10831
11206
  }
10832
11207
  async function appendLocked(sessionId, body) {
10833
11208
  const file = commentsFileFor(sessionId);
10834
- fs42.mkdirSync(commentsDir(), { recursive: true });
11209
+ fs43.mkdirSync(commentsDir(), { recursive: true });
10835
11210
  ensureFile(file, "[]");
10836
11211
  const comment = {
10837
11212
  id: crypto6.randomBytes(8).toString("hex"),
@@ -10868,7 +11243,7 @@ async function broadcastPrompt(sessions, filter, prompt) {
10868
11243
  // src/commands/broadcast.ts
10869
11244
  function readStdin() {
10870
11245
  try {
10871
- return fs43.readFileSync(0, "utf-8");
11246
+ return fs44.readFileSync(0, "utf-8");
10872
11247
  } catch {
10873
11248
  return "";
10874
11249
  }
@@ -10943,7 +11318,7 @@ var broadcastCommand = {
10943
11318
  };
10944
11319
 
10945
11320
  // src/completions/index.ts
10946
- import fs44 from "fs";
11321
+ import fs45 from "fs";
10947
11322
  import path43 from "path";
10948
11323
  function completionHandler(current, argv, done) {
10949
11324
  const rawArgs = argv._;
@@ -11048,7 +11423,7 @@ function completeTreeRemoveList(command, args, current, config, done) {
11048
11423
  }
11049
11424
  function completeRepoBranches(alias, current, config, done) {
11050
11425
  const repoPath = config.repos[alias];
11051
- if (!repoPath || !fs44.existsSync(repoPath)) {
11426
+ if (!repoPath || !fs45.existsSync(repoPath)) {
11052
11427
  done([]);
11053
11428
  return;
11054
11429
  }
@@ -11058,18 +11433,18 @@ function completeRepoBranches(alias, current, config, done) {
11058
11433
  }
11059
11434
  function completeGroupBranches(groupName, repoAliases, current, config, done) {
11060
11435
  const groupDir = path43.join(config.worktreesRoot, groupName);
11061
- if (!fs44.existsSync(groupDir)) {
11436
+ if (!fs45.existsSync(groupDir)) {
11062
11437
  done([]);
11063
11438
  return;
11064
11439
  }
11065
11440
  try {
11066
- const branchDirs = fs44.readdirSync(groupDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => {
11441
+ const branchDirs = fs45.readdirSync(groupDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => {
11067
11442
  const bdPath = path43.join(groupDir, d.name);
11068
11443
  for (const alias of repoAliases) {
11069
11444
  const repoPath = config.repos[alias];
11070
11445
  if (!repoPath) continue;
11071
11446
  const subPath = path43.join(bdPath, path43.basename(repoPath));
11072
- if (fs44.existsSync(subPath)) {
11447
+ if (fs45.existsSync(subPath)) {
11073
11448
  const branch = getCurrentBranch(subPath);
11074
11449
  if (branch) return branch;
11075
11450
  }
@@ -11083,7 +11458,7 @@ function completeGroupBranches(groupName, repoAliases, current, config, done) {
11083
11458
  }
11084
11459
 
11085
11460
  // src/version.ts
11086
- var VERSION = true ? "1.8.0" : "dev";
11461
+ var VERSION = true ? "1.9.0" : "dev";
11087
11462
 
11088
11463
  // src/cli.ts
11089
11464
  function showHelp() {