@moberg_hr/work-tree 1.8.5 → 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(),
@@ -7683,7 +7686,7 @@ function createCommentStore() {
7683
7686
  }
7684
7687
  const parent = findParent2(input2.parentId);
7685
7688
  const side = input2.side ?? parent?.side ?? "general";
7686
- if (side !== "left" && side !== "right" && side !== "general") {
7689
+ if (side !== "left" && side !== "right" && side !== "general" && side !== "file") {
7687
7690
  throw new Error("invalid side");
7688
7691
  }
7689
7692
  const c = {
@@ -7708,6 +7711,14 @@ function createCommentStore() {
7708
7711
  comments.splice(idx, 1);
7709
7712
  return true;
7710
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
+ },
7711
7722
  submit(summary) {
7712
7723
  const drafts = comments.filter((c) => c.status === "draft").sort((a, b) => a.createdAt.localeCompare(b.createdAt));
7713
7724
  let summaryComment = null;
@@ -8096,7 +8107,7 @@ var commentInputSchema = z.object({
8096
8107
  repo: z.string().optional(),
8097
8108
  file: z.string().optional(),
8098
8109
  line: z.number().int().optional(),
8099
- side: z.enum(["left", "right", "general"]).optional(),
8110
+ side: z.enum(["left", "right", "general", "file"]).optional(),
8100
8111
  body: z.string().min(1),
8101
8112
  status: z.enum(["published", "draft"]).optional(),
8102
8113
  lineContent: z.string().optional(),
@@ -8106,6 +8117,9 @@ var commentInputSchema = z.object({
8106
8117
  var submitReviewSchema = z.object({
8107
8118
  summary: z.string().optional()
8108
8119
  });
8120
+ var resolveSchema = z.object({
8121
+ resolved: z.boolean()
8122
+ });
8109
8123
 
8110
8124
  // src/core/comment-server.ts
8111
8125
  async function startCommentServer(opts) {
@@ -8142,6 +8156,18 @@ async function startCommentServer(opts) {
8142
8156
  if (removed && opts.onCommentDeleted) opts.onCommentDeleted(id);
8143
8157
  return c.json({ comments: store.snapshot() });
8144
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
+ );
8145
8171
  routes.post(
8146
8172
  "/api/submit-review",
8147
8173
  zValidator("json", submitReviewSchema),
@@ -8196,7 +8222,7 @@ async function startCommentServer(opts) {
8196
8222
  }
8197
8223
  function formatSingleComment(c) {
8198
8224
  const bodyLines = c.body.split("\n").map((l) => `> ${l}`).join("\n");
8199
- 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})`;
8200
8226
  const meta = [];
8201
8227
  if (c.author === "claude") meta.push("author: claude");
8202
8228
  if (c.parentId) meta.push(`reply-to: ${c.parentId}`);
@@ -8724,13 +8750,13 @@ var diffCommand = {
8724
8750
  // src/commands/web.ts
8725
8751
  import fs41 from "fs";
8726
8752
  import os13 from "os";
8727
- import path40 from "path";
8753
+ import path41 from "path";
8728
8754
  import chalk23 from "chalk";
8729
8755
 
8730
8756
  // src/core/web-server.ts
8731
8757
  import fs40 from "fs";
8732
8758
  import os12 from "os";
8733
- import path39 from "path";
8759
+ import path40 from "path";
8734
8760
  import chalk22 from "chalk";
8735
8761
  import { Hono as Hono3 } from "hono";
8736
8762
  import { streamSSE as streamSSE3 } from "hono/streaming";
@@ -8936,6 +8962,12 @@ function getCommentFileStore(sessionId) {
8936
8962
  return { value: r, persisted: r };
8937
8963
  });
8938
8964
  },
8965
+ setResolved(id, resolved) {
8966
+ return lockedMutate(() => {
8967
+ const c = inner.setResolved(id, resolved);
8968
+ return { value: c, persisted: c !== null };
8969
+ });
8970
+ },
8939
8971
  submit(summary) {
8940
8972
  return lockedMutate(() => {
8941
8973
  const result = inner.submit(summary);
@@ -9169,6 +9201,21 @@ function mountSessionCommentRoutes(app, opts) {
9169
9201
  if (removed) opts.broadcast("comments-changed", { sessionId: id, deleted: cid });
9170
9202
  return c.json({ comments: store.snapshot() });
9171
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
+ );
9172
9219
  app.post(
9173
9220
  "/api/sessions/:id/submit-review",
9174
9221
  zValidator2("json", submitReviewSchema),
@@ -9480,8 +9527,8 @@ function mountWorktreeRoutes(app, opts) {
9480
9527
  import { zValidator as zValidator5 } from "@hono/zod-validator";
9481
9528
  import { z as z4 } from "zod";
9482
9529
  import { EventEmitter } from "events";
9483
- import path38 from "path";
9484
- import spawn13 from "cross-spawn";
9530
+ import path39 from "path";
9531
+ import spawn14 from "cross-spawn";
9485
9532
 
9486
9533
  // src/core/checkpoint.ts
9487
9534
  import fs39 from "fs";
@@ -9610,6 +9657,17 @@ async function takeCheckpoint(scopeHash, repos, opts = {}) {
9610
9657
  return entry;
9611
9658
  });
9612
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
+ }
9613
9671
  function clearCheckpoints(scopeHash, repoRoots) {
9614
9672
  const manifest = loadManifest(scopeHash);
9615
9673
  for (const root of repoRoots) {
@@ -9631,8 +9689,130 @@ function clearCheckpoints(scopeHash, repoRoots) {
9631
9689
  }
9632
9690
  }
9633
9691
 
9634
- // src/core/scope-manager.ts
9692
+ // src/core/checkpoint-summary.ts
9693
+ import spawn13 from "cross-spawn";
9635
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
+
9814
+ // src/core/scope-manager.ts
9815
+ import path38 from "path";
9636
9816
  import crypto5 from "crypto";
9637
9817
  var scopes = /* @__PURE__ */ new Map();
9638
9818
  function hashFor(paths) {
@@ -9649,7 +9829,7 @@ var ScopePathRejectedError = class extends Error {
9649
9829
  }
9650
9830
  };
9651
9831
  function normaliseForCompare(p) {
9652
- return path37.resolve(p).replace(/\\/g, "/").toLowerCase();
9832
+ return path38.resolve(p).replace(/\\/g, "/").toLowerCase();
9653
9833
  }
9654
9834
  function rejectedPaths(normalised) {
9655
9835
  const config = loadConfig();
@@ -9667,7 +9847,7 @@ function rejectedPaths(normalised) {
9667
9847
  });
9668
9848
  }
9669
9849
  function registerScope(paths, label2) {
9670
- const normalised = paths.map((p) => path37.resolve(p));
9850
+ const normalised = paths.map((p) => path38.resolve(p));
9671
9851
  const rejected = rejectedPaths(normalised);
9672
9852
  if (rejected.length > 0) throw new ScopePathRejectedError(rejected);
9673
9853
  const hash = hashFor(normalised);
@@ -9681,11 +9861,16 @@ function registerScope(paths, label2) {
9681
9861
  const scope = {
9682
9862
  hash,
9683
9863
  paths: normalised,
9684
- label: label2 ?? path37.basename(normalised[0]),
9864
+ label: label2 ?? path38.basename(normalised[0]),
9685
9865
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
9686
9866
  ended: false
9687
9867
  };
9688
- 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
+ });
9689
9874
  return scope;
9690
9875
  }
9691
9876
  function markScopeEnded(hash) {
@@ -9698,6 +9883,20 @@ function markScopeEnded(hash) {
9698
9883
  function getScope(hash) {
9699
9884
  return scopes.get(hash)?.scope ?? null;
9700
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
+ }
9701
9900
  function listScopes() {
9702
9901
  return Array.from(scopes.values()).map((e) => e.scope);
9703
9902
  }
@@ -9718,6 +9917,7 @@ function subscribeScope(hash, cb) {
9718
9917
  roots: entry.scope.paths,
9719
9918
  debounceMs: 150,
9720
9919
  onChange: () => {
9920
+ if (Date.now() < entry.suppressWatchUntil) return;
9721
9921
  for (const sub of entry.subscribers) {
9722
9922
  try {
9723
9923
  sub();
@@ -9751,10 +9951,13 @@ import { streamSSE as streamSSE2 } from "hono/streaming";
9751
9951
  function mountScopeRoutes(app, opts) {
9752
9952
  const checkpointWatched = /* @__PURE__ */ new Set();
9753
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;
9754
9957
  function workingTreeFingerprint(paths) {
9755
9958
  const parts = [];
9756
9959
  for (const p of paths) {
9757
- const r = spawn13.sync(
9960
+ const r = spawn14.sync(
9758
9961
  "git",
9759
9962
  ["status", "--porcelain", "--no-renames", "-z"],
9760
9963
  { cwd: p, encoding: "utf-8", windowsHide: true }
@@ -9796,18 +9999,32 @@ function mountScopeRoutes(app, opts) {
9796
9999
  }
9797
10000
  if (!checkpointWatched.has(scope.hash)) {
9798
10001
  checkpointWatched.add(scope.hash);
9799
- 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
+ }
9800
10012
  try {
9801
10013
  const fp = workingTreeFingerprint(scope.paths);
9802
- if (lastStatus.get(scope.hash) === fp) return;
9803
- lastStatus.set(scope.hash, fp);
10014
+ if (lastStatus.get(hash) === fp) return;
10015
+ lastStatus.set(hash, fp);
9804
10016
  } catch {
9805
10017
  }
9806
- takeCheckpoint(scope.hash, scopeRepos(scope.paths)).then((entry) => {
10018
+ takeCheckpoint(hash, scopeRepos(scope.paths)).then((entry) => {
9807
10019
  if (entry) announceCheckpoint(entry);
9808
10020
  }).catch((err) => {
9809
10021
  console.error("[checkpoint] auto-snapshot failed:", err);
9810
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));
9811
10028
  });
9812
10029
  }
9813
10030
  return c.json({
@@ -9824,6 +10041,27 @@ function mountScopeRoutes(app, opts) {
9824
10041
  }
9825
10042
  );
9826
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
+ );
9827
10065
  app.delete("/api/scopes/:hash", (c) => {
9828
10066
  const hash = c.req.param("hash");
9829
10067
  const scope = getScope(hash);
@@ -9831,6 +10069,11 @@ function mountScopeRoutes(app, opts) {
9831
10069
  const ok = removeScope(hash);
9832
10070
  checkpointWatched.delete(hash);
9833
10071
  lastStatus.delete(hash);
10072
+ const pendingTimer = snapshotTimers.get(hash);
10073
+ if (pendingTimer) {
10074
+ clearTimeout(pendingTimer);
10075
+ snapshotTimers.delete(hash);
10076
+ }
9834
10077
  if (repoPaths.length > 0) clearCheckpoints(hash, repoPaths);
9835
10078
  if (ok) opts.broadcast("scopes-changed", { hash });
9836
10079
  return c.json({ ok });
@@ -9878,11 +10121,12 @@ function mountScopeRoutes(app, opts) {
9878
10121
  const fromSha = fromEntry.repos[p] ?? "HEAD";
9879
10122
  const toSha = toEntry === void 0 ? "working" : toEntry.repos[p] ?? "HEAD";
9880
10123
  return {
9881
- name: path38.basename(p),
10124
+ name: path39.basename(p),
9882
10125
  root: p,
9883
10126
  files: computeRangeDiff({ root: p, fromRef: fromSha, toRef: toSha })
9884
10127
  };
9885
10128
  });
10129
+ suppressScopeWatch(scope.hash, 800);
9886
10130
  return c.json({
9887
10131
  scopeHash: scope.hash,
9888
10132
  base: "uncommitted",
@@ -9896,7 +10140,7 @@ function mountScopeRoutes(app, opts) {
9896
10140
  (p) => resolveRepoDiff(p, base, sessionBaseForPath(p))
9897
10141
  );
9898
10142
  const repos = scope.paths.map((p, i) => ({
9899
- name: path38.basename(p),
10143
+ name: path39.basename(p),
9900
10144
  root: p,
9901
10145
  resolvedBase: resolved[i].resolvedBase,
9902
10146
  files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
@@ -9904,6 +10148,7 @@ function mountScopeRoutes(app, opts) {
9904
10148
  const resolvedBase = resolved[0]?.resolvedBase ?? "HEAD";
9905
10149
  const head = git(["rev-parse", "--abbrev-ref", "HEAD"], scope.paths[0]);
9906
10150
  const headBranch = head.exitCode === 0 && head.stdout && head.stdout !== "HEAD" ? head.stdout : void 0;
10151
+ suppressScopeWatch(scope.hash, 800);
9907
10152
  return c.json({
9908
10153
  scopeHash: scope.hash,
9909
10154
  base,
@@ -9926,7 +10171,7 @@ function mountScopeRoutes(app, opts) {
9926
10171
  if (!relPath || !Number.isInteger(start) || !Number.isInteger(end)) {
9927
10172
  return c.json({ error: "bad path/start/end" }, 400);
9928
10173
  }
9929
- const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path38.basename(p) === repoName);
10174
+ const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path39.basename(p) === repoName);
9930
10175
  if (!root) return c.json({ error: "unknown repo" }, 404);
9931
10176
  const result = readContextLines({ root, relPath, start, end, ref });
9932
10177
  if (!result) return c.json({ error: "cannot read file" }, 400);
@@ -9941,6 +10186,22 @@ function mountScopeRoutes(app, opts) {
9941
10186
  entries: manifest.entries
9942
10187
  });
9943
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
+ });
9944
10205
  function commentStore(hash) {
9945
10206
  return getCommentFileStore(commentStoreIdForScope(hash));
9946
10207
  }
@@ -9984,6 +10245,26 @@ function mountScopeRoutes(app, opts) {
9984
10245
  }
9985
10246
  return c.json({ comments: store.snapshot() });
9986
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
+ );
9987
10268
  app.post(
9988
10269
  "/api/scopes/:hash/submit-review",
9989
10270
  zValidator5("json", submitReviewSchema),
@@ -10164,7 +10445,7 @@ function computeSessionDiff(s, base) {
10164
10445
  (p) => resolveRepoDiff(p, base, s.baseBranches?.[p] ?? s.baseBranch)
10165
10446
  );
10166
10447
  const repos = s.paths.map((p, i) => ({
10167
- name: path39.basename(p),
10448
+ name: path40.basename(p),
10168
10449
  root: p,
10169
10450
  resolvedBase: resolved[i].resolvedBase,
10170
10451
  files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
@@ -10184,10 +10465,10 @@ async function startWebServer(opts = {}) {
10184
10465
  for (const cb of sseListeners) cb({ event, data });
10185
10466
  };
10186
10467
  const home = os12.homedir();
10187
- const historyPath = path39.join(home, ".work", "history.json");
10468
+ const historyPath = path40.join(home, ".work", "history.json");
10188
10469
  const onHistoryChange = () => broadcast("sessions-changed", { ts: Date.now() });
10189
10470
  fs40.watchFile(historyPath, { interval: 1e3 }, onHistoryChange);
10190
- const tasksPath = path39.join(home, ".work", "tasks.json");
10471
+ const tasksPath = path40.join(home, ".work", "tasks.json");
10191
10472
  const onTasksChange = () => broadcast("tasks-changed", { ts: Date.now() });
10192
10473
  fs40.watchFile(tasksPath, { interval: 1e3 }, onTasksChange);
10193
10474
  const projectsRoot = claudeProjectsRoot();
@@ -10332,10 +10613,10 @@ function info2(message) {
10332
10613
  process.stderr.write(message + "\n");
10333
10614
  }
10334
10615
  function urlFilePath() {
10335
- return path40.join(os13.homedir(), ".work", "web.url");
10616
+ return path41.join(os13.homedir(), ".work", "web.url");
10336
10617
  }
10337
10618
  function pidFilePath() {
10338
- return path40.join(os13.homedir(), ".work", "web.pid");
10619
+ return path41.join(os13.homedir(), ".work", "web.pid");
10339
10620
  }
10340
10621
  function isPidAlive(pid) {
10341
10622
  try {
@@ -10460,7 +10741,7 @@ var webCommand = {
10460
10741
  const lean = !!argv.lean || process.env.WORK_WEB_LEAN === "1";
10461
10742
  const handle = await startWebServer({ lean });
10462
10743
  try {
10463
- fs41.mkdirSync(path40.dirname(urlFilePath()), { recursive: true });
10744
+ fs41.mkdirSync(path41.dirname(urlFilePath()), { recursive: true });
10464
10745
  fs41.writeFileSync(urlFilePath(), handle.url);
10465
10746
  fs41.writeFileSync(pidFilePath(), String(process.pid));
10466
10747
  } catch {
@@ -10489,6 +10770,13 @@ var webCommand = {
10489
10770
  ]).catch(() => {
10490
10771
  });
10491
10772
  }
10773
+ await installCommandHook({
10774
+ owner: "web-checkpoint",
10775
+ event: "Stop",
10776
+ command: "work hook checkpoint",
10777
+ timeoutSec: 5
10778
+ }).catch(() => {
10779
+ });
10492
10780
  const shutdown = () => {
10493
10781
  info2(chalk23.gray("\nStopping work web."));
10494
10782
  try {
@@ -10509,6 +10797,10 @@ var webCommand = {
10509
10797
  } catch {
10510
10798
  }
10511
10799
  }
10800
+ try {
10801
+ removeCommandHookSync("web-checkpoint", "Stop");
10802
+ } catch {
10803
+ }
10512
10804
  handle.stop();
10513
10805
  process.exit(0);
10514
10806
  };
@@ -10530,6 +10822,31 @@ var webCommand = {
10530
10822
  };
10531
10823
 
10532
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
+ }
10533
10850
  function computeHookOutput(input2) {
10534
10851
  const session = findSessionForCwd(input2.cwd);
10535
10852
  if (!session) return null;
@@ -10579,13 +10896,17 @@ var hookCommand = {
10579
10896
  // hidden — humans don't call this directly
10580
10897
  builder: (y) => y.positional("event", {
10581
10898
  type: "string",
10582
- choices: ["prompt-submit", "stop"],
10899
+ choices: ["prompt-submit", "stop", "checkpoint"],
10583
10900
  describe: "Hook event name"
10584
10901
  }),
10585
10902
  handler: async (argv) => {
10586
10903
  const event = argv.event;
10587
10904
  const payload = await readStdinJson();
10588
10905
  const cwd = payload.cwd ?? process.cwd();
10906
+ if (event === "checkpoint") {
10907
+ await triggerCheckpoint(cwd);
10908
+ return;
10909
+ }
10589
10910
  const result = computeHookOutput({ event, cwd });
10590
10911
  if (!result || !result.sessionId) return;
10591
10912
  process.stdout.write(result.stdout);
@@ -10595,7 +10916,7 @@ var hookCommand = {
10595
10916
 
10596
10917
  // src/commands/run.ts
10597
10918
  import chalk24 from "chalk";
10598
- import spawn14 from "cross-spawn";
10919
+ import spawn15 from "cross-spawn";
10599
10920
 
10600
10921
  // src/core/fleet.ts
10601
10922
  function selectSessions(sessions, filter) {
@@ -10637,7 +10958,7 @@ function killAllChildren(signal = "SIGTERM") {
10637
10958
  function runInPath(unit, cmd, prefix) {
10638
10959
  const { bin, args } = shellInvocation(cmd);
10639
10960
  return new Promise((resolve) => {
10640
- const child = spawn14(bin, args, {
10961
+ const child = spawn15(bin, args, {
10641
10962
  cwd: unit.path,
10642
10963
  stdio: prefix ? ["ignore", "pipe", "pipe"] : "inherit",
10643
10964
  shell: false
@@ -10869,15 +11190,15 @@ var runCommand = {
10869
11190
  };
10870
11191
 
10871
11192
  // src/commands/broadcast.ts
10872
- import fs43 from "fs";
11193
+ import fs44 from "fs";
10873
11194
  import chalk25 from "chalk";
10874
11195
 
10875
11196
  // src/core/broadcast.ts
10876
11197
  import crypto6 from "crypto";
10877
- import fs42 from "fs";
11198
+ import fs43 from "fs";
10878
11199
  function readComments(file) {
10879
11200
  try {
10880
- const parsed = JSON.parse(fs42.readFileSync(file, "utf-8"));
11201
+ const parsed = JSON.parse(fs43.readFileSync(file, "utf-8"));
10881
11202
  return Array.isArray(parsed) ? parsed : [];
10882
11203
  } catch {
10883
11204
  return [];
@@ -10885,7 +11206,7 @@ function readComments(file) {
10885
11206
  }
10886
11207
  async function appendLocked(sessionId, body) {
10887
11208
  const file = commentsFileFor(sessionId);
10888
- fs42.mkdirSync(commentsDir(), { recursive: true });
11209
+ fs43.mkdirSync(commentsDir(), { recursive: true });
10889
11210
  ensureFile(file, "[]");
10890
11211
  const comment = {
10891
11212
  id: crypto6.randomBytes(8).toString("hex"),
@@ -10922,7 +11243,7 @@ async function broadcastPrompt(sessions, filter, prompt) {
10922
11243
  // src/commands/broadcast.ts
10923
11244
  function readStdin() {
10924
11245
  try {
10925
- return fs43.readFileSync(0, "utf-8");
11246
+ return fs44.readFileSync(0, "utf-8");
10926
11247
  } catch {
10927
11248
  return "";
10928
11249
  }
@@ -10997,8 +11318,8 @@ var broadcastCommand = {
10997
11318
  };
10998
11319
 
10999
11320
  // src/completions/index.ts
11000
- import fs44 from "fs";
11001
- import path41 from "path";
11321
+ import fs45 from "fs";
11322
+ import path43 from "path";
11002
11323
  function completionHandler(current, argv, done) {
11003
11324
  const rawArgs = argv._;
11004
11325
  const args = rawArgs.slice(1, -1);
@@ -11102,7 +11423,7 @@ function completeTreeRemoveList(command, args, current, config, done) {
11102
11423
  }
11103
11424
  function completeRepoBranches(alias, current, config, done) {
11104
11425
  const repoPath = config.repos[alias];
11105
- if (!repoPath || !fs44.existsSync(repoPath)) {
11426
+ if (!repoPath || !fs45.existsSync(repoPath)) {
11106
11427
  done([]);
11107
11428
  return;
11108
11429
  }
@@ -11111,19 +11432,19 @@ function completeRepoBranches(alias, current, config, done) {
11111
11432
  done(branches);
11112
11433
  }
11113
11434
  function completeGroupBranches(groupName, repoAliases, current, config, done) {
11114
- const groupDir = path41.join(config.worktreesRoot, groupName);
11115
- if (!fs44.existsSync(groupDir)) {
11435
+ const groupDir = path43.join(config.worktreesRoot, groupName);
11436
+ if (!fs45.existsSync(groupDir)) {
11116
11437
  done([]);
11117
11438
  return;
11118
11439
  }
11119
11440
  try {
11120
- const branchDirs = fs44.readdirSync(groupDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => {
11121
- const bdPath = path41.join(groupDir, d.name);
11441
+ const branchDirs = fs45.readdirSync(groupDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => {
11442
+ const bdPath = path43.join(groupDir, d.name);
11122
11443
  for (const alias of repoAliases) {
11123
11444
  const repoPath = config.repos[alias];
11124
11445
  if (!repoPath) continue;
11125
- const subPath = path41.join(bdPath, path41.basename(repoPath));
11126
- if (fs44.existsSync(subPath)) {
11446
+ const subPath = path43.join(bdPath, path43.basename(repoPath));
11447
+ if (fs45.existsSync(subPath)) {
11127
11448
  const branch = getCurrentBranch(subPath);
11128
11449
  if (branch) return branch;
11129
11450
  }
@@ -11137,7 +11458,7 @@ function completeGroupBranches(groupName, repoAliases, current, config, done) {
11137
11458
  }
11138
11459
 
11139
11460
  // src/version.ts
11140
- var VERSION = true ? "1.8.5" : "dev";
11461
+ var VERSION = true ? "1.9.0" : "dev";
11141
11462
 
11142
11463
  // src/cli.ts
11143
11464
  function showHelp() {