@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/bin.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/bin.ts
4
- import fs45 from "fs";
5
- import path42 from "path";
4
+ import fs46 from "fs";
5
+ import path44 from "path";
6
6
  import chalk27 from "chalk";
7
7
 
8
8
  // src/cli.ts
@@ -1464,6 +1464,9 @@ function latestJsonlMtimeMs(projectDir) {
1464
1464
  }
1465
1465
  return latest;
1466
1466
  }
1467
+ function claudeActiveWithin(activityMs, nowMs, windowMs) {
1468
+ return activityMs > 0 && nowMs - activityMs < windowMs;
1469
+ }
1467
1470
  function getClaudeActivityMs(launchPath) {
1468
1471
  const dir = path9.join(
1469
1472
  os4.homedir(),
@@ -7685,7 +7688,7 @@ function createCommentStore() {
7685
7688
  }
7686
7689
  const parent = findParent2(input2.parentId);
7687
7690
  const side = input2.side ?? parent?.side ?? "general";
7688
- if (side !== "left" && side !== "right" && side !== "general") {
7691
+ if (side !== "left" && side !== "right" && side !== "general" && side !== "file") {
7689
7692
  throw new Error("invalid side");
7690
7693
  }
7691
7694
  const c = {
@@ -7710,6 +7713,14 @@ function createCommentStore() {
7710
7713
  comments.splice(idx, 1);
7711
7714
  return true;
7712
7715
  },
7716
+ setResolved(id, resolved) {
7717
+ const c = comments.find((x) => x.id === id);
7718
+ if (!c) return null;
7719
+ const next = resolved || void 0;
7720
+ if (c.resolved === next) return null;
7721
+ c.resolved = next;
7722
+ return c;
7723
+ },
7713
7724
  submit(summary) {
7714
7725
  const drafts = comments.filter((c) => c.status === "draft").sort((a, b) => a.createdAt.localeCompare(b.createdAt));
7715
7726
  let summaryComment = null;
@@ -8098,7 +8109,7 @@ var commentInputSchema = z.object({
8098
8109
  repo: z.string().optional(),
8099
8110
  file: z.string().optional(),
8100
8111
  line: z.number().int().optional(),
8101
- side: z.enum(["left", "right", "general"]).optional(),
8112
+ side: z.enum(["left", "right", "general", "file"]).optional(),
8102
8113
  body: z.string().min(1),
8103
8114
  status: z.enum(["published", "draft"]).optional(),
8104
8115
  lineContent: z.string().optional(),
@@ -8108,6 +8119,9 @@ var commentInputSchema = z.object({
8108
8119
  var submitReviewSchema = z.object({
8109
8120
  summary: z.string().optional()
8110
8121
  });
8122
+ var resolveSchema = z.object({
8123
+ resolved: z.boolean()
8124
+ });
8111
8125
 
8112
8126
  // src/core/comment-server.ts
8113
8127
  async function startCommentServer(opts) {
@@ -8144,6 +8158,18 @@ async function startCommentServer(opts) {
8144
8158
  if (removed && opts.onCommentDeleted) opts.onCommentDeleted(id);
8145
8159
  return c.json({ comments: store.snapshot() });
8146
8160
  });
8161
+ routes.post(
8162
+ "/api/comments/:id/resolve",
8163
+ zValidator("json", resolveSchema),
8164
+ (c) => {
8165
+ const updated = store.setResolved(
8166
+ c.req.param("id"),
8167
+ c.req.valid("json").resolved
8168
+ );
8169
+ if (updated) api.broadcast("comments-changed", { id: updated.id });
8170
+ return c.json({ comments: store.snapshot() });
8171
+ }
8172
+ );
8147
8173
  routes.post(
8148
8174
  "/api/submit-review",
8149
8175
  zValidator("json", submitReviewSchema),
@@ -8198,7 +8224,7 @@ async function startCommentServer(opts) {
8198
8224
  }
8199
8225
  function formatSingleComment(c) {
8200
8226
  const bodyLines = c.body.split("\n").map((l) => `> ${l}`).join("\n");
8201
- const header = c.side === "general" ? `**General review comment**` : `**${c.repo}/${c.file}** : line ${c.line} (${c.side})`;
8227
+ 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})`;
8202
8228
  const meta = [];
8203
8229
  if (c.author === "claude") meta.push("author: claude");
8204
8230
  if (c.parentId) meta.push(`reply-to: ${c.parentId}`);
@@ -8726,13 +8752,13 @@ var diffCommand = {
8726
8752
  // src/commands/web.ts
8727
8753
  import fs41 from "fs";
8728
8754
  import os13 from "os";
8729
- import path40 from "path";
8755
+ import path41 from "path";
8730
8756
  import chalk23 from "chalk";
8731
8757
 
8732
8758
  // src/core/web-server.ts
8733
8759
  import fs40 from "fs";
8734
8760
  import os12 from "os";
8735
- import path39 from "path";
8761
+ import path40 from "path";
8736
8762
  import chalk22 from "chalk";
8737
8763
  import { Hono as Hono3 } from "hono";
8738
8764
  import { streamSSE as streamSSE3 } from "hono/streaming";
@@ -8938,6 +8964,12 @@ function getCommentFileStore(sessionId) {
8938
8964
  return { value: r, persisted: r };
8939
8965
  });
8940
8966
  },
8967
+ setResolved(id, resolved) {
8968
+ return lockedMutate(() => {
8969
+ const c = inner.setResolved(id, resolved);
8970
+ return { value: c, persisted: c !== null };
8971
+ });
8972
+ },
8941
8973
  submit(summary) {
8942
8974
  return lockedMutate(() => {
8943
8975
  const result = inner.submit(summary);
@@ -9171,6 +9203,21 @@ function mountSessionCommentRoutes(app, opts) {
9171
9203
  if (removed) opts.broadcast("comments-changed", { sessionId: id, deleted: cid });
9172
9204
  return c.json({ comments: store.snapshot() });
9173
9205
  });
9206
+ app.post(
9207
+ "/api/sessions/:id/comments/:cid/resolve",
9208
+ zValidator2("json", resolveSchema),
9209
+ (c) => {
9210
+ const id = c.req.param("id");
9211
+ if (!requireSession(id)) return c.json({ error: "unknown session" }, 404);
9212
+ const store = getCommentFileStore(id);
9213
+ const updated = store.setResolved(
9214
+ c.req.param("cid"),
9215
+ c.req.valid("json").resolved
9216
+ );
9217
+ if (updated) opts.broadcast("comments-changed", { sessionId: id, id: updated.id });
9218
+ return c.json({ comments: store.snapshot() });
9219
+ }
9220
+ );
9174
9221
  app.post(
9175
9222
  "/api/sessions/:id/submit-review",
9176
9223
  zValidator2("json", submitReviewSchema),
@@ -9482,8 +9529,8 @@ function mountWorktreeRoutes(app, opts) {
9482
9529
  import { zValidator as zValidator5 } from "@hono/zod-validator";
9483
9530
  import { z as z4 } from "zod";
9484
9531
  import { EventEmitter } from "events";
9485
- import path38 from "path";
9486
- import spawn13 from "cross-spawn";
9532
+ import path39 from "path";
9533
+ import spawn14 from "cross-spawn";
9487
9534
 
9488
9535
  // src/core/checkpoint.ts
9489
9536
  import fs39 from "fs";
@@ -9612,6 +9659,17 @@ async function takeCheckpoint(scopeHash, repos, opts = {}) {
9612
9659
  return entry;
9613
9660
  });
9614
9661
  }
9662
+ async function setCheckpointLabel(scopeHash, id, label2) {
9663
+ const file = manifestPath(scopeHash);
9664
+ ensureFile(file, JSON.stringify(emptyManifest(scopeHash), null, 2));
9665
+ await withFileLock(file, () => {
9666
+ const manifest = loadManifest(scopeHash);
9667
+ const entry = manifest.entries.find((e) => e.id === id);
9668
+ if (!entry || entry.label === label2) return;
9669
+ entry.label = label2;
9670
+ atomicWriteFile(file, JSON.stringify(manifest, null, 2));
9671
+ });
9672
+ }
9615
9673
  function clearCheckpoints(scopeHash, repoRoots) {
9616
9674
  const manifest = loadManifest(scopeHash);
9617
9675
  for (const root of repoRoots) {
@@ -9633,8 +9691,130 @@ function clearCheckpoints(scopeHash, repoRoots) {
9633
9691
  }
9634
9692
  }
9635
9693
 
9636
- // src/core/scope-manager.ts
9694
+ // src/core/checkpoint-summary.ts
9695
+ import spawn13 from "cross-spawn";
9637
9696
  import path37 from "path";
9697
+ var MAX_DIFF_CHARS = 6e3;
9698
+ var MAX_LABEL_CHARS = 80;
9699
+ function buildDelta(scopeHash, repos, id) {
9700
+ const manifest = loadManifest(scopeHash);
9701
+ const entry = manifest.entries.find((e) => e.id === id);
9702
+ const prev = manifest.entries.find((e) => e.id === id - 1);
9703
+ const all = [];
9704
+ for (const repo of repos) {
9705
+ const toRef = entry?.repos[repo.name];
9706
+ if (!toRef) continue;
9707
+ const fromRef = prev?.repos[repo.name] ?? "HEAD";
9708
+ try {
9709
+ all.push(...computeRangeDiff({ root: repo.root, fromRef, toRef }));
9710
+ } catch {
9711
+ }
9712
+ }
9713
+ let added = 0;
9714
+ let deleted = 0;
9715
+ for (const f of all) {
9716
+ added += f.added;
9717
+ deleted += f.deleted;
9718
+ }
9719
+ const parts = [];
9720
+ let budget = MAX_DIFF_CHARS;
9721
+ for (const f of all) {
9722
+ const head = `### ${f.status} ${f.path} (+${f.added} -${f.deleted})
9723
+ `;
9724
+ if (budget - head.length < 0) break;
9725
+ parts.push(head);
9726
+ budget -= head.length;
9727
+ for (const h of f.hunks) {
9728
+ for (const ln of h.lines) {
9729
+ if (ln.kind !== "add" && ln.kind !== "delete") continue;
9730
+ const prefix = ln.kind === "add" ? "+" : "-";
9731
+ const line = `${prefix}${ln.content}
9732
+ `;
9733
+ if (budget - line.length < 0) {
9734
+ budget = -1;
9735
+ break;
9736
+ }
9737
+ parts.push(line);
9738
+ budget -= line.length;
9739
+ }
9740
+ if (budget < 0) break;
9741
+ }
9742
+ if (budget < 0) break;
9743
+ }
9744
+ return { files: all, added, deleted, text: parts.join("") };
9745
+ }
9746
+ function heuristicLabel(files, added, deleted) {
9747
+ if (files.length === 0) return "no changes";
9748
+ if (files.length === 1) {
9749
+ return `${path37.basename(files[0].path)} +${added} \u2212${deleted}`;
9750
+ }
9751
+ return `${files.length} files \xB7 +${added} \u2212${deleted}`;
9752
+ }
9753
+ function runClaude(prompt, timeoutMs = 25e3) {
9754
+ return new Promise((resolve) => {
9755
+ let settled = false;
9756
+ const finish = (v) => {
9757
+ if (settled) return;
9758
+ settled = true;
9759
+ resolve(v);
9760
+ };
9761
+ let out = "";
9762
+ let child;
9763
+ try {
9764
+ child = spawn13("claude", ["-p"], {
9765
+ stdio: ["pipe", "pipe", "ignore"],
9766
+ windowsHide: true
9767
+ });
9768
+ } catch {
9769
+ finish(null);
9770
+ return;
9771
+ }
9772
+ const timer = setTimeout(() => {
9773
+ try {
9774
+ child.kill();
9775
+ } catch {
9776
+ }
9777
+ finish(null);
9778
+ }, timeoutMs);
9779
+ child.stdout?.on("data", (d) => {
9780
+ out += d.toString();
9781
+ });
9782
+ child.on("error", () => {
9783
+ clearTimeout(timer);
9784
+ finish(null);
9785
+ });
9786
+ child.on("close", (code) => {
9787
+ clearTimeout(timer);
9788
+ finish(code === 0 && out.trim() ? out.trim() : null);
9789
+ });
9790
+ try {
9791
+ child.stdin?.write(prompt);
9792
+ child.stdin?.end();
9793
+ } catch {
9794
+ clearTimeout(timer);
9795
+ finish(null);
9796
+ }
9797
+ });
9798
+ }
9799
+ function cleanLabel(raw) {
9800
+ const firstLine = raw.split("\n").map((l) => l.trim()).find(Boolean) ?? "";
9801
+ const cleaned = firstLine.replace(/^["'`]+|["'`]+$/g, "").replace(/\s+/g, " ").replace(/[.;]+$/, "").trim();
9802
+ return cleaned.slice(0, MAX_LABEL_CHARS);
9803
+ }
9804
+ async function summarizeCheckpoint(scopeHash, repos, id) {
9805
+ const { files, added, deleted, text } = buildDelta(scopeHash, repos, id);
9806
+ if (files.length === 0) return "no changes";
9807
+ const fallback = heuristicLabel(files, added, deleted);
9808
+ if (!text.trim()) return fallback;
9809
+ const prompt = "Summarise this code change in 8 words or fewer, imperative mood, no trailing punctuation. Output ONLY the summary line.\n\n" + text;
9810
+ const reply = await runClaude(prompt);
9811
+ if (!reply) return fallback;
9812
+ const label2 = cleanLabel(reply);
9813
+ return label2 || fallback;
9814
+ }
9815
+
9816
+ // src/core/scope-manager.ts
9817
+ import path38 from "path";
9638
9818
  import crypto5 from "crypto";
9639
9819
  var scopes = /* @__PURE__ */ new Map();
9640
9820
  function hashFor(paths) {
@@ -9651,7 +9831,7 @@ var ScopePathRejectedError = class extends Error {
9651
9831
  }
9652
9832
  };
9653
9833
  function normaliseForCompare(p) {
9654
- return path37.resolve(p).replace(/\\/g, "/").toLowerCase();
9834
+ return path38.resolve(p).replace(/\\/g, "/").toLowerCase();
9655
9835
  }
9656
9836
  function rejectedPaths(normalised) {
9657
9837
  const config = loadConfig();
@@ -9669,7 +9849,7 @@ function rejectedPaths(normalised) {
9669
9849
  });
9670
9850
  }
9671
9851
  function registerScope(paths, label2) {
9672
- const normalised = paths.map((p) => path37.resolve(p));
9852
+ const normalised = paths.map((p) => path38.resolve(p));
9673
9853
  const rejected = rejectedPaths(normalised);
9674
9854
  if (rejected.length > 0) throw new ScopePathRejectedError(rejected);
9675
9855
  const hash = hashFor(normalised);
@@ -9683,11 +9863,16 @@ function registerScope(paths, label2) {
9683
9863
  const scope = {
9684
9864
  hash,
9685
9865
  paths: normalised,
9686
- label: label2 ?? path37.basename(normalised[0]),
9866
+ label: label2 ?? path38.basename(normalised[0]),
9687
9867
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
9688
9868
  ended: false
9689
9869
  };
9690
- scopes.set(hash, { scope, watcher: null, subscribers: /* @__PURE__ */ new Set() });
9870
+ scopes.set(hash, {
9871
+ scope,
9872
+ watcher: null,
9873
+ subscribers: /* @__PURE__ */ new Set(),
9874
+ suppressWatchUntil: 0
9875
+ });
9691
9876
  return scope;
9692
9877
  }
9693
9878
  function markScopeEnded(hash) {
@@ -9700,6 +9885,20 @@ function markScopeEnded(hash) {
9700
9885
  function getScope(hash) {
9701
9886
  return scopes.get(hash)?.scope ?? null;
9702
9887
  }
9888
+ function suppressScopeWatch(hash, ms) {
9889
+ const entry = scopes.get(hash);
9890
+ if (entry) entry.suppressWatchUntil = Date.now() + ms;
9891
+ }
9892
+ function scopeCoversCwd(paths, cwd) {
9893
+ const nc = normaliseForCompare(cwd);
9894
+ return paths.some((p) => {
9895
+ const np = normaliseForCompare(p);
9896
+ return np === nc || np.startsWith(nc + "/") || nc.startsWith(np + "/");
9897
+ });
9898
+ }
9899
+ function scopesForCwd(cwd) {
9900
+ return Array.from(scopes.values()).map((e) => e.scope).filter((s) => scopeCoversCwd(s.paths, cwd));
9901
+ }
9703
9902
  function listScopes() {
9704
9903
  return Array.from(scopes.values()).map((e) => e.scope);
9705
9904
  }
@@ -9720,6 +9919,7 @@ function subscribeScope(hash, cb) {
9720
9919
  roots: entry.scope.paths,
9721
9920
  debounceMs: 150,
9722
9921
  onChange: () => {
9922
+ if (Date.now() < entry.suppressWatchUntil) return;
9723
9923
  for (const sub of entry.subscribers) {
9724
9924
  try {
9725
9925
  sub();
@@ -9753,10 +9953,13 @@ import { streamSSE as streamSSE2 } from "hono/streaming";
9753
9953
  function mountScopeRoutes(app, opts) {
9754
9954
  const checkpointWatched = /* @__PURE__ */ new Set();
9755
9955
  const lastStatus = /* @__PURE__ */ new Map();
9956
+ const snapshotTimers = /* @__PURE__ */ new Map();
9957
+ const CHECKPOINT_SETTLE_MS = 4e3;
9958
+ const CLAUDE_SESSION_MS = 5 * 6e4;
9756
9959
  function workingTreeFingerprint(paths) {
9757
9960
  const parts = [];
9758
9961
  for (const p of paths) {
9759
- const r = spawn13.sync(
9962
+ const r = spawn14.sync(
9760
9963
  "git",
9761
9964
  ["status", "--porcelain", "--no-renames", "-z"],
9762
9965
  { cwd: p, encoding: "utf-8", windowsHide: true }
@@ -9798,18 +10001,32 @@ function mountScopeRoutes(app, opts) {
9798
10001
  }
9799
10002
  if (!checkpointWatched.has(scope.hash)) {
9800
10003
  checkpointWatched.add(scope.hash);
9801
- subscribeScope(scope.hash, () => {
10004
+ const hash = scope.hash;
10005
+ const runSnapshot = () => {
10006
+ snapshotTimers.delete(hash);
10007
+ const claudeMs = scope.paths.reduce(
10008
+ (m, p) => Math.max(m, getClaudeActivityMs(p)),
10009
+ 0
10010
+ );
10011
+ if (claudeActiveWithin(claudeMs, Date.now(), CLAUDE_SESSION_MS)) {
10012
+ return;
10013
+ }
9802
10014
  try {
9803
10015
  const fp = workingTreeFingerprint(scope.paths);
9804
- if (lastStatus.get(scope.hash) === fp) return;
9805
- lastStatus.set(scope.hash, fp);
10016
+ if (lastStatus.get(hash) === fp) return;
10017
+ lastStatus.set(hash, fp);
9806
10018
  } catch {
9807
10019
  }
9808
- takeCheckpoint(scope.hash, scopeRepos(scope.paths)).then((entry) => {
10020
+ takeCheckpoint(hash, scopeRepos(scope.paths)).then((entry) => {
9809
10021
  if (entry) announceCheckpoint(entry);
9810
10022
  }).catch((err) => {
9811
10023
  console.error("[checkpoint] auto-snapshot failed:", err);
9812
10024
  });
10025
+ };
10026
+ subscribeScope(hash, () => {
10027
+ const pending = snapshotTimers.get(hash);
10028
+ if (pending) clearTimeout(pending);
10029
+ snapshotTimers.set(hash, setTimeout(runSnapshot, CHECKPOINT_SETTLE_MS));
9813
10030
  });
9814
10031
  }
9815
10032
  return c.json({
@@ -9826,6 +10043,27 @@ function mountScopeRoutes(app, opts) {
9826
10043
  }
9827
10044
  );
9828
10045
  app.get("/api/scopes", (c) => c.json({ scopes: listScopes() }));
10046
+ app.post(
10047
+ "/api/checkpoint",
10048
+ zValidator5("json", z4.object({ cwd: z4.string().min(1) })),
10049
+ async (c) => {
10050
+ const { cwd } = c.req.valid("json");
10051
+ const matched = scopesForCwd(cwd);
10052
+ let snapshotted = 0;
10053
+ for (const s of matched) {
10054
+ const entry = await takeCheckpoint(s.hash, scopeRepos(s.paths)).catch(
10055
+ () => null
10056
+ );
10057
+ if (entry) {
10058
+ const payload = { scopeHash: s.hash, id: entry.id };
10059
+ opts.broadcast("checkpoints-changed", payload);
10060
+ scopeBus.emit("checkpoints-changed", payload);
10061
+ snapshotted++;
10062
+ }
10063
+ }
10064
+ return c.json({ ok: true, scopes: matched.length, snapshotted });
10065
+ }
10066
+ );
9829
10067
  app.delete("/api/scopes/:hash", (c) => {
9830
10068
  const hash = c.req.param("hash");
9831
10069
  const scope = getScope(hash);
@@ -9833,6 +10071,11 @@ function mountScopeRoutes(app, opts) {
9833
10071
  const ok = removeScope(hash);
9834
10072
  checkpointWatched.delete(hash);
9835
10073
  lastStatus.delete(hash);
10074
+ const pendingTimer = snapshotTimers.get(hash);
10075
+ if (pendingTimer) {
10076
+ clearTimeout(pendingTimer);
10077
+ snapshotTimers.delete(hash);
10078
+ }
9836
10079
  if (repoPaths.length > 0) clearCheckpoints(hash, repoPaths);
9837
10080
  if (ok) opts.broadcast("scopes-changed", { hash });
9838
10081
  return c.json({ ok });
@@ -9880,11 +10123,12 @@ function mountScopeRoutes(app, opts) {
9880
10123
  const fromSha = fromEntry.repos[p] ?? "HEAD";
9881
10124
  const toSha = toEntry === void 0 ? "working" : toEntry.repos[p] ?? "HEAD";
9882
10125
  return {
9883
- name: path38.basename(p),
10126
+ name: path39.basename(p),
9884
10127
  root: p,
9885
10128
  files: computeRangeDiff({ root: p, fromRef: fromSha, toRef: toSha })
9886
10129
  };
9887
10130
  });
10131
+ suppressScopeWatch(scope.hash, 800);
9888
10132
  return c.json({
9889
10133
  scopeHash: scope.hash,
9890
10134
  base: "uncommitted",
@@ -9898,7 +10142,7 @@ function mountScopeRoutes(app, opts) {
9898
10142
  (p) => resolveRepoDiff(p, base, sessionBaseForPath(p))
9899
10143
  );
9900
10144
  const repos = scope.paths.map((p, i) => ({
9901
- name: path38.basename(p),
10145
+ name: path39.basename(p),
9902
10146
  root: p,
9903
10147
  resolvedBase: resolved[i].resolvedBase,
9904
10148
  files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
@@ -9906,6 +10150,7 @@ function mountScopeRoutes(app, opts) {
9906
10150
  const resolvedBase = resolved[0]?.resolvedBase ?? "HEAD";
9907
10151
  const head = git(["rev-parse", "--abbrev-ref", "HEAD"], scope.paths[0]);
9908
10152
  const headBranch = head.exitCode === 0 && head.stdout && head.stdout !== "HEAD" ? head.stdout : void 0;
10153
+ suppressScopeWatch(scope.hash, 800);
9909
10154
  return c.json({
9910
10155
  scopeHash: scope.hash,
9911
10156
  base,
@@ -9928,7 +10173,7 @@ function mountScopeRoutes(app, opts) {
9928
10173
  if (!relPath || !Number.isInteger(start) || !Number.isInteger(end)) {
9929
10174
  return c.json({ error: "bad path/start/end" }, 400);
9930
10175
  }
9931
- const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path38.basename(p) === repoName);
10176
+ const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path39.basename(p) === repoName);
9932
10177
  if (!root) return c.json({ error: "unknown repo" }, 404);
9933
10178
  const result = readContextLines({ root, relPath, start, end, ref });
9934
10179
  if (!result) return c.json({ error: "cannot read file" }, 400);
@@ -9943,6 +10188,22 @@ function mountScopeRoutes(app, opts) {
9943
10188
  entries: manifest.entries
9944
10189
  });
9945
10190
  });
10191
+ app.post("/api/scopes/:hash/checkpoints/:id/summary", async (c) => {
10192
+ const scope = getScope(c.req.param("hash"));
10193
+ if (!scope) return c.json({ error: "unknown scope" }, 404);
10194
+ const id = Number(c.req.param("id"));
10195
+ if (!Number.isInteger(id) || id < 0) {
10196
+ return c.json({ error: "bad checkpoint id" }, 400);
10197
+ }
10198
+ const entry = loadManifest(scope.hash).entries.find((e) => e.id === id);
10199
+ if (!entry) return c.json({ error: "unknown checkpoint" }, 404);
10200
+ if (entry.label && entry.label.trim()) return c.json({ label: entry.label });
10201
+ if (id === 0) return c.json({ label: "Initial" });
10202
+ const label2 = await summarizeCheckpoint(scope.hash, scopeRepos(scope.paths), id);
10203
+ await setCheckpointLabel(scope.hash, id, label2);
10204
+ opts.broadcast("checkpoints-changed", { scopeHash: scope.hash, id });
10205
+ return c.json({ label: label2 });
10206
+ });
9946
10207
  function commentStore(hash) {
9947
10208
  return getCommentFileStore(commentStoreIdForScope(hash));
9948
10209
  }
@@ -9986,6 +10247,26 @@ function mountScopeRoutes(app, opts) {
9986
10247
  }
9987
10248
  return c.json({ comments: store.snapshot() });
9988
10249
  });
10250
+ app.post(
10251
+ "/api/scopes/:hash/comments/:cid/resolve",
10252
+ zValidator5("json", resolveSchema),
10253
+ (c) => {
10254
+ const scope = getScope(c.req.param("hash"));
10255
+ if (!scope) return c.json({ error: "unknown scope" }, 404);
10256
+ const store = commentStore(scope.hash);
10257
+ const updated = store.setResolved(
10258
+ c.req.param("cid"),
10259
+ c.req.valid("json").resolved
10260
+ );
10261
+ if (updated) {
10262
+ opts.broadcast("comments-changed", {
10263
+ scopeHash: scope.hash,
10264
+ id: updated.id
10265
+ });
10266
+ }
10267
+ return c.json({ comments: store.snapshot() });
10268
+ }
10269
+ );
9989
10270
  app.post(
9990
10271
  "/api/scopes/:hash/submit-review",
9991
10272
  zValidator5("json", submitReviewSchema),
@@ -10166,7 +10447,7 @@ function computeSessionDiff(s, base) {
10166
10447
  (p) => resolveRepoDiff(p, base, s.baseBranches?.[p] ?? s.baseBranch)
10167
10448
  );
10168
10449
  const repos = s.paths.map((p, i) => ({
10169
- name: path39.basename(p),
10450
+ name: path40.basename(p),
10170
10451
  root: p,
10171
10452
  resolvedBase: resolved[i].resolvedBase,
10172
10453
  files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
@@ -10186,10 +10467,10 @@ async function startWebServer(opts = {}) {
10186
10467
  for (const cb of sseListeners) cb({ event, data });
10187
10468
  };
10188
10469
  const home = os12.homedir();
10189
- const historyPath = path39.join(home, ".work", "history.json");
10470
+ const historyPath = path40.join(home, ".work", "history.json");
10190
10471
  const onHistoryChange = () => broadcast("sessions-changed", { ts: Date.now() });
10191
10472
  fs40.watchFile(historyPath, { interval: 1e3 }, onHistoryChange);
10192
- const tasksPath = path39.join(home, ".work", "tasks.json");
10473
+ const tasksPath = path40.join(home, ".work", "tasks.json");
10193
10474
  const onTasksChange = () => broadcast("tasks-changed", { ts: Date.now() });
10194
10475
  fs40.watchFile(tasksPath, { interval: 1e3 }, onTasksChange);
10195
10476
  const projectsRoot = claudeProjectsRoot();
@@ -10334,10 +10615,10 @@ function info2(message) {
10334
10615
  process.stderr.write(message + "\n");
10335
10616
  }
10336
10617
  function urlFilePath() {
10337
- return path40.join(os13.homedir(), ".work", "web.url");
10618
+ return path41.join(os13.homedir(), ".work", "web.url");
10338
10619
  }
10339
10620
  function pidFilePath() {
10340
- return path40.join(os13.homedir(), ".work", "web.pid");
10621
+ return path41.join(os13.homedir(), ".work", "web.pid");
10341
10622
  }
10342
10623
  function isPidAlive(pid) {
10343
10624
  try {
@@ -10462,7 +10743,7 @@ var webCommand = {
10462
10743
  const lean = !!argv.lean || process.env.WORK_WEB_LEAN === "1";
10463
10744
  const handle = await startWebServer({ lean });
10464
10745
  try {
10465
- fs41.mkdirSync(path40.dirname(urlFilePath()), { recursive: true });
10746
+ fs41.mkdirSync(path41.dirname(urlFilePath()), { recursive: true });
10466
10747
  fs41.writeFileSync(urlFilePath(), handle.url);
10467
10748
  fs41.writeFileSync(pidFilePath(), String(process.pid));
10468
10749
  } catch {
@@ -10491,6 +10772,13 @@ var webCommand = {
10491
10772
  ]).catch(() => {
10492
10773
  });
10493
10774
  }
10775
+ await installCommandHook({
10776
+ owner: "web-checkpoint",
10777
+ event: "Stop",
10778
+ command: "work hook checkpoint",
10779
+ timeoutSec: 5
10780
+ }).catch(() => {
10781
+ });
10494
10782
  const shutdown = () => {
10495
10783
  info2(chalk23.gray("\nStopping work web."));
10496
10784
  try {
@@ -10511,6 +10799,10 @@ var webCommand = {
10511
10799
  } catch {
10512
10800
  }
10513
10801
  }
10802
+ try {
10803
+ removeCommandHookSync("web-checkpoint", "Stop");
10804
+ } catch {
10805
+ }
10514
10806
  handle.stop();
10515
10807
  process.exit(0);
10516
10808
  };
@@ -10532,6 +10824,31 @@ var webCommand = {
10532
10824
  };
10533
10825
 
10534
10826
  // src/commands/hook.ts
10827
+ import fs42 from "fs";
10828
+ import os14 from "os";
10829
+ import path42 from "path";
10830
+ async function triggerCheckpoint(cwd) {
10831
+ let base;
10832
+ try {
10833
+ base = fs42.readFileSync(path42.join(os14.homedir(), ".work", "web.url"), "utf-8").trim();
10834
+ } catch {
10835
+ return;
10836
+ }
10837
+ if (!base) return;
10838
+ const controller = new AbortController();
10839
+ const timer = setTimeout(() => controller.abort(), 3e3);
10840
+ try {
10841
+ await fetch(`${base}api/checkpoint`, {
10842
+ method: "POST",
10843
+ headers: { "Content-Type": "application/json" },
10844
+ body: JSON.stringify({ cwd }),
10845
+ signal: controller.signal
10846
+ });
10847
+ } catch {
10848
+ } finally {
10849
+ clearTimeout(timer);
10850
+ }
10851
+ }
10535
10852
  function computeHookOutput(input2) {
10536
10853
  const session = findSessionForCwd(input2.cwd);
10537
10854
  if (!session) return null;
@@ -10581,13 +10898,17 @@ var hookCommand = {
10581
10898
  // hidden — humans don't call this directly
10582
10899
  builder: (y) => y.positional("event", {
10583
10900
  type: "string",
10584
- choices: ["prompt-submit", "stop"],
10901
+ choices: ["prompt-submit", "stop", "checkpoint"],
10585
10902
  describe: "Hook event name"
10586
10903
  }),
10587
10904
  handler: async (argv) => {
10588
10905
  const event = argv.event;
10589
10906
  const payload = await readStdinJson();
10590
10907
  const cwd = payload.cwd ?? process.cwd();
10908
+ if (event === "checkpoint") {
10909
+ await triggerCheckpoint(cwd);
10910
+ return;
10911
+ }
10591
10912
  const result = computeHookOutput({ event, cwd });
10592
10913
  if (!result || !result.sessionId) return;
10593
10914
  process.stdout.write(result.stdout);
@@ -10597,7 +10918,7 @@ var hookCommand = {
10597
10918
 
10598
10919
  // src/commands/run.ts
10599
10920
  import chalk24 from "chalk";
10600
- import spawn14 from "cross-spawn";
10921
+ import spawn15 from "cross-spawn";
10601
10922
 
10602
10923
  // src/core/fleet.ts
10603
10924
  function selectSessions(sessions, filter) {
@@ -10639,7 +10960,7 @@ function killAllChildren(signal = "SIGTERM") {
10639
10960
  function runInPath(unit, cmd, prefix) {
10640
10961
  const { bin, args } = shellInvocation(cmd);
10641
10962
  return new Promise((resolve) => {
10642
- const child = spawn14(bin, args, {
10963
+ const child = spawn15(bin, args, {
10643
10964
  cwd: unit.path,
10644
10965
  stdio: prefix ? ["ignore", "pipe", "pipe"] : "inherit",
10645
10966
  shell: false
@@ -10871,15 +11192,15 @@ var runCommand = {
10871
11192
  };
10872
11193
 
10873
11194
  // src/commands/broadcast.ts
10874
- import fs43 from "fs";
11195
+ import fs44 from "fs";
10875
11196
  import chalk25 from "chalk";
10876
11197
 
10877
11198
  // src/core/broadcast.ts
10878
11199
  import crypto6 from "crypto";
10879
- import fs42 from "fs";
11200
+ import fs43 from "fs";
10880
11201
  function readComments(file) {
10881
11202
  try {
10882
- const parsed = JSON.parse(fs42.readFileSync(file, "utf-8"));
11203
+ const parsed = JSON.parse(fs43.readFileSync(file, "utf-8"));
10883
11204
  return Array.isArray(parsed) ? parsed : [];
10884
11205
  } catch {
10885
11206
  return [];
@@ -10887,7 +11208,7 @@ function readComments(file) {
10887
11208
  }
10888
11209
  async function appendLocked(sessionId, body) {
10889
11210
  const file = commentsFileFor(sessionId);
10890
- fs42.mkdirSync(commentsDir(), { recursive: true });
11211
+ fs43.mkdirSync(commentsDir(), { recursive: true });
10891
11212
  ensureFile(file, "[]");
10892
11213
  const comment = {
10893
11214
  id: crypto6.randomBytes(8).toString("hex"),
@@ -10924,7 +11245,7 @@ async function broadcastPrompt(sessions, filter, prompt) {
10924
11245
  // src/commands/broadcast.ts
10925
11246
  function readStdin() {
10926
11247
  try {
10927
- return fs43.readFileSync(0, "utf-8");
11248
+ return fs44.readFileSync(0, "utf-8");
10928
11249
  } catch {
10929
11250
  return "";
10930
11251
  }
@@ -10999,8 +11320,8 @@ var broadcastCommand = {
10999
11320
  };
11000
11321
 
11001
11322
  // src/completions/index.ts
11002
- import fs44 from "fs";
11003
- import path41 from "path";
11323
+ import fs45 from "fs";
11324
+ import path43 from "path";
11004
11325
  function completionHandler(current, argv, done) {
11005
11326
  const rawArgs = argv._;
11006
11327
  const args = rawArgs.slice(1, -1);
@@ -11104,7 +11425,7 @@ function completeTreeRemoveList(command, args, current, config, done) {
11104
11425
  }
11105
11426
  function completeRepoBranches(alias, current, config, done) {
11106
11427
  const repoPath = config.repos[alias];
11107
- if (!repoPath || !fs44.existsSync(repoPath)) {
11428
+ if (!repoPath || !fs45.existsSync(repoPath)) {
11108
11429
  done([]);
11109
11430
  return;
11110
11431
  }
@@ -11113,19 +11434,19 @@ function completeRepoBranches(alias, current, config, done) {
11113
11434
  done(branches);
11114
11435
  }
11115
11436
  function completeGroupBranches(groupName, repoAliases, current, config, done) {
11116
- const groupDir = path41.join(config.worktreesRoot, groupName);
11117
- if (!fs44.existsSync(groupDir)) {
11437
+ const groupDir = path43.join(config.worktreesRoot, groupName);
11438
+ if (!fs45.existsSync(groupDir)) {
11118
11439
  done([]);
11119
11440
  return;
11120
11441
  }
11121
11442
  try {
11122
- const branchDirs = fs44.readdirSync(groupDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => {
11123
- const bdPath = path41.join(groupDir, d.name);
11443
+ const branchDirs = fs45.readdirSync(groupDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => {
11444
+ const bdPath = path43.join(groupDir, d.name);
11124
11445
  for (const alias of repoAliases) {
11125
11446
  const repoPath = config.repos[alias];
11126
11447
  if (!repoPath) continue;
11127
- const subPath = path41.join(bdPath, path41.basename(repoPath));
11128
- if (fs44.existsSync(subPath)) {
11448
+ const subPath = path43.join(bdPath, path43.basename(repoPath));
11449
+ if (fs45.existsSync(subPath)) {
11129
11450
  const branch = getCurrentBranch(subPath);
11130
11451
  if (branch) return branch;
11131
11452
  }
@@ -11139,7 +11460,7 @@ function completeGroupBranches(groupName, repoAliases, current, config, done) {
11139
11460
  }
11140
11461
 
11141
11462
  // src/version.ts
11142
- var VERSION = true ? "1.8.5" : "dev";
11463
+ var VERSION = true ? "1.9.0" : "dev";
11143
11464
 
11144
11465
  // src/cli.ts
11145
11466
  function showHelp() {
@@ -11236,8 +11557,8 @@ function handleFatalError(err) {
11236
11557
  }
11237
11558
  if (err instanceof Error && err.message?.includes("pty that has already exited")) {
11238
11559
  try {
11239
- fs45.appendFileSync(
11240
- path42.join(getConfigDir(), "debug.log"),
11560
+ fs46.appendFileSync(
11561
+ path44.join(getConfigDir(), "debug.log"),
11241
11562
  `${(/* @__PURE__ */ new Date()).toISOString()} [WARN] Ignored async node-pty error: ${err.message}
11242
11563
  `
11243
11564
  );
@@ -11247,8 +11568,8 @@ function handleFatalError(err) {
11247
11568
  }
11248
11569
  try {
11249
11570
  const msg = err instanceof Error ? err.stack || err.message : String(err);
11250
- fs45.appendFileSync(
11251
- path42.join(getConfigDir(), "debug.log"),
11571
+ fs46.appendFileSync(
11572
+ path44.join(getConfigDir(), "debug.log"),
11252
11573
  `${(/* @__PURE__ */ new Date()).toISOString()} [FATAL] handleFatalError: ${msg}
11253
11574
  `
11254
11575
  );