@moberg_hr/work-tree 1.8.5 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +18 -0
- package/README.md +7 -5
- package/dist/bin.js +422 -55
- package/dist/bin.js.map +1 -1
- package/dist/wd-bin.js +416 -49
- package/dist/wd-bin.js.map +1 -1
- package/dist/web/assets/{index-uJQw1Itb.css → index-BYfxyhDx.css} +1 -1
- package/dist/web/assets/index-BaT8rhHI.js +105 -0
- package/dist/web/assets/index-BaT8rhHI.js.map +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +7 -3
- package/plugins/work-tree/.claude-plugin/plugin.json +11 -0
- package/plugins/work-tree/skills/wd-review/SKILL.md +145 -0
- package/scripts/postinstall.mjs +57 -0
- package/dist/web/assets/index-BV5-pKcI.js +0 -106
- package/dist/web/assets/index-BV5-pKcI.js.map +0 -1
package/dist/bin.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/bin.ts
|
|
4
|
-
import
|
|
5
|
-
import
|
|
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
|
|
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
|
|
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);
|
|
@@ -8952,6 +8984,14 @@ function getCommentFileStore(sessionId) {
|
|
|
8952
8984
|
},
|
|
8953
8985
|
reload() {
|
|
8954
8986
|
reloadInner();
|
|
8987
|
+
},
|
|
8988
|
+
clearAll() {
|
|
8989
|
+
return lockedMutate(() => {
|
|
8990
|
+
const list = inner.list();
|
|
8991
|
+
const n = list.length;
|
|
8992
|
+
list.length = 0;
|
|
8993
|
+
return { value: n, persisted: n > 0 };
|
|
8994
|
+
});
|
|
8955
8995
|
}
|
|
8956
8996
|
};
|
|
8957
8997
|
cache.set(sessionId, store);
|
|
@@ -9171,6 +9211,21 @@ function mountSessionCommentRoutes(app, opts) {
|
|
|
9171
9211
|
if (removed) opts.broadcast("comments-changed", { sessionId: id, deleted: cid });
|
|
9172
9212
|
return c.json({ comments: store.snapshot() });
|
|
9173
9213
|
});
|
|
9214
|
+
app.post(
|
|
9215
|
+
"/api/sessions/:id/comments/:cid/resolve",
|
|
9216
|
+
zValidator2("json", resolveSchema),
|
|
9217
|
+
(c) => {
|
|
9218
|
+
const id = c.req.param("id");
|
|
9219
|
+
if (!requireSession(id)) return c.json({ error: "unknown session" }, 404);
|
|
9220
|
+
const store = getCommentFileStore(id);
|
|
9221
|
+
const updated = store.setResolved(
|
|
9222
|
+
c.req.param("cid"),
|
|
9223
|
+
c.req.valid("json").resolved
|
|
9224
|
+
);
|
|
9225
|
+
if (updated) opts.broadcast("comments-changed", { sessionId: id, id: updated.id });
|
|
9226
|
+
return c.json({ comments: store.snapshot() });
|
|
9227
|
+
}
|
|
9228
|
+
);
|
|
9174
9229
|
app.post(
|
|
9175
9230
|
"/api/sessions/:id/submit-review",
|
|
9176
9231
|
zValidator2("json", submitReviewSchema),
|
|
@@ -9482,8 +9537,8 @@ function mountWorktreeRoutes(app, opts) {
|
|
|
9482
9537
|
import { zValidator as zValidator5 } from "@hono/zod-validator";
|
|
9483
9538
|
import { z as z4 } from "zod";
|
|
9484
9539
|
import { EventEmitter } from "events";
|
|
9485
|
-
import
|
|
9486
|
-
import
|
|
9540
|
+
import path39 from "path";
|
|
9541
|
+
import spawn14 from "cross-spawn";
|
|
9487
9542
|
|
|
9488
9543
|
// src/core/checkpoint.ts
|
|
9489
9544
|
import fs39 from "fs";
|
|
@@ -9612,6 +9667,17 @@ async function takeCheckpoint(scopeHash, repos, opts = {}) {
|
|
|
9612
9667
|
return entry;
|
|
9613
9668
|
});
|
|
9614
9669
|
}
|
|
9670
|
+
async function setCheckpointLabel(scopeHash, id, label2) {
|
|
9671
|
+
const file = manifestPath(scopeHash);
|
|
9672
|
+
ensureFile(file, JSON.stringify(emptyManifest(scopeHash), null, 2));
|
|
9673
|
+
await withFileLock(file, () => {
|
|
9674
|
+
const manifest = loadManifest(scopeHash);
|
|
9675
|
+
const entry = manifest.entries.find((e) => e.id === id);
|
|
9676
|
+
if (!entry || entry.label === label2) return;
|
|
9677
|
+
entry.label = label2;
|
|
9678
|
+
atomicWriteFile(file, JSON.stringify(manifest, null, 2));
|
|
9679
|
+
});
|
|
9680
|
+
}
|
|
9615
9681
|
function clearCheckpoints(scopeHash, repoRoots) {
|
|
9616
9682
|
const manifest = loadManifest(scopeHash);
|
|
9617
9683
|
for (const root of repoRoots) {
|
|
@@ -9633,8 +9699,130 @@ function clearCheckpoints(scopeHash, repoRoots) {
|
|
|
9633
9699
|
}
|
|
9634
9700
|
}
|
|
9635
9701
|
|
|
9636
|
-
// src/core/
|
|
9702
|
+
// src/core/checkpoint-summary.ts
|
|
9703
|
+
import spawn13 from "cross-spawn";
|
|
9637
9704
|
import path37 from "path";
|
|
9705
|
+
var MAX_DIFF_CHARS = 6e3;
|
|
9706
|
+
var MAX_LABEL_CHARS = 80;
|
|
9707
|
+
function buildDelta(scopeHash, repos, id) {
|
|
9708
|
+
const manifest = loadManifest(scopeHash);
|
|
9709
|
+
const entry = manifest.entries.find((e) => e.id === id);
|
|
9710
|
+
const prev = manifest.entries.find((e) => e.id === id - 1);
|
|
9711
|
+
const all = [];
|
|
9712
|
+
for (const repo of repos) {
|
|
9713
|
+
const toRef = entry?.repos[repo.name];
|
|
9714
|
+
if (!toRef) continue;
|
|
9715
|
+
const fromRef = prev?.repos[repo.name] ?? "HEAD";
|
|
9716
|
+
try {
|
|
9717
|
+
all.push(...computeRangeDiff({ root: repo.root, fromRef, toRef }));
|
|
9718
|
+
} catch {
|
|
9719
|
+
}
|
|
9720
|
+
}
|
|
9721
|
+
let added = 0;
|
|
9722
|
+
let deleted = 0;
|
|
9723
|
+
for (const f of all) {
|
|
9724
|
+
added += f.added;
|
|
9725
|
+
deleted += f.deleted;
|
|
9726
|
+
}
|
|
9727
|
+
const parts = [];
|
|
9728
|
+
let budget = MAX_DIFF_CHARS;
|
|
9729
|
+
for (const f of all) {
|
|
9730
|
+
const head = `### ${f.status} ${f.path} (+${f.added} -${f.deleted})
|
|
9731
|
+
`;
|
|
9732
|
+
if (budget - head.length < 0) break;
|
|
9733
|
+
parts.push(head);
|
|
9734
|
+
budget -= head.length;
|
|
9735
|
+
for (const h of f.hunks) {
|
|
9736
|
+
for (const ln of h.lines) {
|
|
9737
|
+
if (ln.kind !== "add" && ln.kind !== "delete") continue;
|
|
9738
|
+
const prefix = ln.kind === "add" ? "+" : "-";
|
|
9739
|
+
const line = `${prefix}${ln.content}
|
|
9740
|
+
`;
|
|
9741
|
+
if (budget - line.length < 0) {
|
|
9742
|
+
budget = -1;
|
|
9743
|
+
break;
|
|
9744
|
+
}
|
|
9745
|
+
parts.push(line);
|
|
9746
|
+
budget -= line.length;
|
|
9747
|
+
}
|
|
9748
|
+
if (budget < 0) break;
|
|
9749
|
+
}
|
|
9750
|
+
if (budget < 0) break;
|
|
9751
|
+
}
|
|
9752
|
+
return { files: all, added, deleted, text: parts.join("") };
|
|
9753
|
+
}
|
|
9754
|
+
function heuristicLabel(files, added, deleted) {
|
|
9755
|
+
if (files.length === 0) return "no changes";
|
|
9756
|
+
if (files.length === 1) {
|
|
9757
|
+
return `${path37.basename(files[0].path)} +${added} \u2212${deleted}`;
|
|
9758
|
+
}
|
|
9759
|
+
return `${files.length} files \xB7 +${added} \u2212${deleted}`;
|
|
9760
|
+
}
|
|
9761
|
+
function runClaude(prompt, timeoutMs = 25e3) {
|
|
9762
|
+
return new Promise((resolve) => {
|
|
9763
|
+
let settled = false;
|
|
9764
|
+
const finish = (v) => {
|
|
9765
|
+
if (settled) return;
|
|
9766
|
+
settled = true;
|
|
9767
|
+
resolve(v);
|
|
9768
|
+
};
|
|
9769
|
+
let out = "";
|
|
9770
|
+
let child;
|
|
9771
|
+
try {
|
|
9772
|
+
child = spawn13("claude", ["-p"], {
|
|
9773
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
9774
|
+
windowsHide: true
|
|
9775
|
+
});
|
|
9776
|
+
} catch {
|
|
9777
|
+
finish(null);
|
|
9778
|
+
return;
|
|
9779
|
+
}
|
|
9780
|
+
const timer = setTimeout(() => {
|
|
9781
|
+
try {
|
|
9782
|
+
child.kill();
|
|
9783
|
+
} catch {
|
|
9784
|
+
}
|
|
9785
|
+
finish(null);
|
|
9786
|
+
}, timeoutMs);
|
|
9787
|
+
child.stdout?.on("data", (d) => {
|
|
9788
|
+
out += d.toString();
|
|
9789
|
+
});
|
|
9790
|
+
child.on("error", () => {
|
|
9791
|
+
clearTimeout(timer);
|
|
9792
|
+
finish(null);
|
|
9793
|
+
});
|
|
9794
|
+
child.on("close", (code) => {
|
|
9795
|
+
clearTimeout(timer);
|
|
9796
|
+
finish(code === 0 && out.trim() ? out.trim() : null);
|
|
9797
|
+
});
|
|
9798
|
+
try {
|
|
9799
|
+
child.stdin?.write(prompt);
|
|
9800
|
+
child.stdin?.end();
|
|
9801
|
+
} catch {
|
|
9802
|
+
clearTimeout(timer);
|
|
9803
|
+
finish(null);
|
|
9804
|
+
}
|
|
9805
|
+
});
|
|
9806
|
+
}
|
|
9807
|
+
function cleanLabel(raw) {
|
|
9808
|
+
const firstLine = raw.split("\n").map((l) => l.trim()).find(Boolean) ?? "";
|
|
9809
|
+
const cleaned = firstLine.replace(/^["'`]+|["'`]+$/g, "").replace(/\s+/g, " ").replace(/[.;]+$/, "").trim();
|
|
9810
|
+
return cleaned.slice(0, MAX_LABEL_CHARS);
|
|
9811
|
+
}
|
|
9812
|
+
async function summarizeCheckpoint(scopeHash, repos, id) {
|
|
9813
|
+
const { files, added, deleted, text } = buildDelta(scopeHash, repos, id);
|
|
9814
|
+
if (files.length === 0) return "no changes";
|
|
9815
|
+
const fallback = heuristicLabel(files, added, deleted);
|
|
9816
|
+
if (!text.trim()) return fallback;
|
|
9817
|
+
const prompt = "Summarise this code change in 8 words or fewer, imperative mood, no trailing punctuation. Output ONLY the summary line.\n\n" + text;
|
|
9818
|
+
const reply = await runClaude(prompt);
|
|
9819
|
+
if (!reply) return fallback;
|
|
9820
|
+
const label2 = cleanLabel(reply);
|
|
9821
|
+
return label2 || fallback;
|
|
9822
|
+
}
|
|
9823
|
+
|
|
9824
|
+
// src/core/scope-manager.ts
|
|
9825
|
+
import path38 from "path";
|
|
9638
9826
|
import crypto5 from "crypto";
|
|
9639
9827
|
var scopes = /* @__PURE__ */ new Map();
|
|
9640
9828
|
function hashFor(paths) {
|
|
@@ -9651,7 +9839,7 @@ var ScopePathRejectedError = class extends Error {
|
|
|
9651
9839
|
}
|
|
9652
9840
|
};
|
|
9653
9841
|
function normaliseForCompare(p) {
|
|
9654
|
-
return
|
|
9842
|
+
return path38.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
9655
9843
|
}
|
|
9656
9844
|
function rejectedPaths(normalised) {
|
|
9657
9845
|
const config = loadConfig();
|
|
@@ -9669,7 +9857,7 @@ function rejectedPaths(normalised) {
|
|
|
9669
9857
|
});
|
|
9670
9858
|
}
|
|
9671
9859
|
function registerScope(paths, label2) {
|
|
9672
|
-
const normalised = paths.map((p) =>
|
|
9860
|
+
const normalised = paths.map((p) => path38.resolve(p));
|
|
9673
9861
|
const rejected = rejectedPaths(normalised);
|
|
9674
9862
|
if (rejected.length > 0) throw new ScopePathRejectedError(rejected);
|
|
9675
9863
|
const hash = hashFor(normalised);
|
|
@@ -9683,11 +9871,16 @@ function registerScope(paths, label2) {
|
|
|
9683
9871
|
const scope = {
|
|
9684
9872
|
hash,
|
|
9685
9873
|
paths: normalised,
|
|
9686
|
-
label: label2 ??
|
|
9874
|
+
label: label2 ?? path38.basename(normalised[0]),
|
|
9687
9875
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9688
9876
|
ended: false
|
|
9689
9877
|
};
|
|
9690
|
-
scopes.set(hash, {
|
|
9878
|
+
scopes.set(hash, {
|
|
9879
|
+
scope,
|
|
9880
|
+
watcher: null,
|
|
9881
|
+
subscribers: /* @__PURE__ */ new Set(),
|
|
9882
|
+
suppressWatchUntil: 0
|
|
9883
|
+
});
|
|
9691
9884
|
return scope;
|
|
9692
9885
|
}
|
|
9693
9886
|
function markScopeEnded(hash) {
|
|
@@ -9697,9 +9890,29 @@ function markScopeEnded(hash) {
|
|
|
9697
9890
|
entry.scope.ended = true;
|
|
9698
9891
|
return true;
|
|
9699
9892
|
}
|
|
9893
|
+
function reviveScope(hash) {
|
|
9894
|
+
const entry = scopes.get(hash);
|
|
9895
|
+
if (!entry || !entry.scope.ended) return false;
|
|
9896
|
+
entry.scope.ended = false;
|
|
9897
|
+
return true;
|
|
9898
|
+
}
|
|
9700
9899
|
function getScope(hash) {
|
|
9701
9900
|
return scopes.get(hash)?.scope ?? null;
|
|
9702
9901
|
}
|
|
9902
|
+
function suppressScopeWatch(hash, ms) {
|
|
9903
|
+
const entry = scopes.get(hash);
|
|
9904
|
+
if (entry) entry.suppressWatchUntil = Date.now() + ms;
|
|
9905
|
+
}
|
|
9906
|
+
function scopeCoversCwd(paths, cwd) {
|
|
9907
|
+
const nc = normaliseForCompare(cwd);
|
|
9908
|
+
return paths.some((p) => {
|
|
9909
|
+
const np = normaliseForCompare(p);
|
|
9910
|
+
return np === nc || np.startsWith(nc + "/") || nc.startsWith(np + "/");
|
|
9911
|
+
});
|
|
9912
|
+
}
|
|
9913
|
+
function scopesForCwd(cwd) {
|
|
9914
|
+
return Array.from(scopes.values()).map((e) => e.scope).filter((s) => scopeCoversCwd(s.paths, cwd));
|
|
9915
|
+
}
|
|
9703
9916
|
function listScopes() {
|
|
9704
9917
|
return Array.from(scopes.values()).map((e) => e.scope);
|
|
9705
9918
|
}
|
|
@@ -9720,6 +9933,7 @@ function subscribeScope(hash, cb) {
|
|
|
9720
9933
|
roots: entry.scope.paths,
|
|
9721
9934
|
debounceMs: 150,
|
|
9722
9935
|
onChange: () => {
|
|
9936
|
+
if (Date.now() < entry.suppressWatchUntil) return;
|
|
9723
9937
|
for (const sub of entry.subscribers) {
|
|
9724
9938
|
try {
|
|
9725
9939
|
sub();
|
|
@@ -9753,10 +9967,13 @@ import { streamSSE as streamSSE2 } from "hono/streaming";
|
|
|
9753
9967
|
function mountScopeRoutes(app, opts) {
|
|
9754
9968
|
const checkpointWatched = /* @__PURE__ */ new Set();
|
|
9755
9969
|
const lastStatus = /* @__PURE__ */ new Map();
|
|
9970
|
+
const snapshotTimers = /* @__PURE__ */ new Map();
|
|
9971
|
+
const CHECKPOINT_SETTLE_MS = 4e3;
|
|
9972
|
+
const CLAUDE_SESSION_MS = 5 * 6e4;
|
|
9756
9973
|
function workingTreeFingerprint(paths) {
|
|
9757
9974
|
const parts = [];
|
|
9758
9975
|
for (const p of paths) {
|
|
9759
|
-
const r =
|
|
9976
|
+
const r = spawn14.sync(
|
|
9760
9977
|
"git",
|
|
9761
9978
|
["status", "--porcelain", "--no-renames", "-z"],
|
|
9762
9979
|
{ cwd: p, encoding: "utf-8", windowsHide: true }
|
|
@@ -9767,6 +9984,10 @@ function mountScopeRoutes(app, opts) {
|
|
|
9767
9984
|
}
|
|
9768
9985
|
const scopeBus = new EventEmitter();
|
|
9769
9986
|
scopeBus.setMaxListeners(0);
|
|
9987
|
+
function emitCommentsChanged(payload) {
|
|
9988
|
+
opts.broadcast("comments-changed", payload);
|
|
9989
|
+
scopeBus.emit("comments-changed", payload);
|
|
9990
|
+
}
|
|
9770
9991
|
function scopeRepos(scopePaths) {
|
|
9771
9992
|
return scopePaths.map((p) => ({ name: p, root: p }));
|
|
9772
9993
|
}
|
|
@@ -9783,6 +10004,12 @@ function mountScopeRoutes(app, opts) {
|
|
|
9783
10004
|
const { paths, label: label2 } = c.req.valid("json");
|
|
9784
10005
|
try {
|
|
9785
10006
|
const scope = registerScope(paths, label2);
|
|
10007
|
+
if (reviveScope(scope.hash)) {
|
|
10008
|
+
const cleared = commentStore(scope.hash).clearAll();
|
|
10009
|
+
if (cleared > 0) {
|
|
10010
|
+
emitCommentsChanged({ scopeHash: scope.hash });
|
|
10011
|
+
}
|
|
10012
|
+
}
|
|
9786
10013
|
opts.broadcast("scopes-changed", { hash: scope.hash });
|
|
9787
10014
|
const announceCheckpoint = (entry) => {
|
|
9788
10015
|
const payload = { scopeHash: scope.hash, id: entry.id };
|
|
@@ -9798,18 +10025,32 @@ function mountScopeRoutes(app, opts) {
|
|
|
9798
10025
|
}
|
|
9799
10026
|
if (!checkpointWatched.has(scope.hash)) {
|
|
9800
10027
|
checkpointWatched.add(scope.hash);
|
|
9801
|
-
|
|
10028
|
+
const hash = scope.hash;
|
|
10029
|
+
const runSnapshot = () => {
|
|
10030
|
+
snapshotTimers.delete(hash);
|
|
10031
|
+
const claudeMs = scope.paths.reduce(
|
|
10032
|
+
(m, p) => Math.max(m, getClaudeActivityMs(p)),
|
|
10033
|
+
0
|
|
10034
|
+
);
|
|
10035
|
+
if (claudeActiveWithin(claudeMs, Date.now(), CLAUDE_SESSION_MS)) {
|
|
10036
|
+
return;
|
|
10037
|
+
}
|
|
9802
10038
|
try {
|
|
9803
10039
|
const fp = workingTreeFingerprint(scope.paths);
|
|
9804
|
-
if (lastStatus.get(
|
|
9805
|
-
lastStatus.set(
|
|
10040
|
+
if (lastStatus.get(hash) === fp) return;
|
|
10041
|
+
lastStatus.set(hash, fp);
|
|
9806
10042
|
} catch {
|
|
9807
10043
|
}
|
|
9808
|
-
takeCheckpoint(
|
|
10044
|
+
takeCheckpoint(hash, scopeRepos(scope.paths)).then((entry) => {
|
|
9809
10045
|
if (entry) announceCheckpoint(entry);
|
|
9810
10046
|
}).catch((err) => {
|
|
9811
10047
|
console.error("[checkpoint] auto-snapshot failed:", err);
|
|
9812
10048
|
});
|
|
10049
|
+
};
|
|
10050
|
+
subscribeScope(hash, () => {
|
|
10051
|
+
const pending = snapshotTimers.get(hash);
|
|
10052
|
+
if (pending) clearTimeout(pending);
|
|
10053
|
+
snapshotTimers.set(hash, setTimeout(runSnapshot, CHECKPOINT_SETTLE_MS));
|
|
9813
10054
|
});
|
|
9814
10055
|
}
|
|
9815
10056
|
return c.json({
|
|
@@ -9826,6 +10067,27 @@ function mountScopeRoutes(app, opts) {
|
|
|
9826
10067
|
}
|
|
9827
10068
|
);
|
|
9828
10069
|
app.get("/api/scopes", (c) => c.json({ scopes: listScopes() }));
|
|
10070
|
+
app.post(
|
|
10071
|
+
"/api/checkpoint",
|
|
10072
|
+
zValidator5("json", z4.object({ cwd: z4.string().min(1) })),
|
|
10073
|
+
async (c) => {
|
|
10074
|
+
const { cwd } = c.req.valid("json");
|
|
10075
|
+
const matched = scopesForCwd(cwd);
|
|
10076
|
+
let snapshotted = 0;
|
|
10077
|
+
for (const s of matched) {
|
|
10078
|
+
const entry = await takeCheckpoint(s.hash, scopeRepos(s.paths)).catch(
|
|
10079
|
+
() => null
|
|
10080
|
+
);
|
|
10081
|
+
if (entry) {
|
|
10082
|
+
const payload = { scopeHash: s.hash, id: entry.id };
|
|
10083
|
+
opts.broadcast("checkpoints-changed", payload);
|
|
10084
|
+
scopeBus.emit("checkpoints-changed", payload);
|
|
10085
|
+
snapshotted++;
|
|
10086
|
+
}
|
|
10087
|
+
}
|
|
10088
|
+
return c.json({ ok: true, scopes: matched.length, snapshotted });
|
|
10089
|
+
}
|
|
10090
|
+
);
|
|
9829
10091
|
app.delete("/api/scopes/:hash", (c) => {
|
|
9830
10092
|
const hash = c.req.param("hash");
|
|
9831
10093
|
const scope = getScope(hash);
|
|
@@ -9833,6 +10095,11 @@ function mountScopeRoutes(app, opts) {
|
|
|
9833
10095
|
const ok = removeScope(hash);
|
|
9834
10096
|
checkpointWatched.delete(hash);
|
|
9835
10097
|
lastStatus.delete(hash);
|
|
10098
|
+
const pendingTimer = snapshotTimers.get(hash);
|
|
10099
|
+
if (pendingTimer) {
|
|
10100
|
+
clearTimeout(pendingTimer);
|
|
10101
|
+
snapshotTimers.delete(hash);
|
|
10102
|
+
}
|
|
9836
10103
|
if (repoPaths.length > 0) clearCheckpoints(hash, repoPaths);
|
|
9837
10104
|
if (ok) opts.broadcast("scopes-changed", { hash });
|
|
9838
10105
|
return c.json({ ok });
|
|
@@ -9880,11 +10147,12 @@ function mountScopeRoutes(app, opts) {
|
|
|
9880
10147
|
const fromSha = fromEntry.repos[p] ?? "HEAD";
|
|
9881
10148
|
const toSha = toEntry === void 0 ? "working" : toEntry.repos[p] ?? "HEAD";
|
|
9882
10149
|
return {
|
|
9883
|
-
name:
|
|
10150
|
+
name: path39.basename(p),
|
|
9884
10151
|
root: p,
|
|
9885
10152
|
files: computeRangeDiff({ root: p, fromRef: fromSha, toRef: toSha })
|
|
9886
10153
|
};
|
|
9887
10154
|
});
|
|
10155
|
+
suppressScopeWatch(scope.hash, 800);
|
|
9888
10156
|
return c.json({
|
|
9889
10157
|
scopeHash: scope.hash,
|
|
9890
10158
|
base: "uncommitted",
|
|
@@ -9898,7 +10166,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
9898
10166
|
(p) => resolveRepoDiff(p, base, sessionBaseForPath(p))
|
|
9899
10167
|
);
|
|
9900
10168
|
const repos = scope.paths.map((p, i) => ({
|
|
9901
|
-
name:
|
|
10169
|
+
name: path39.basename(p),
|
|
9902
10170
|
root: p,
|
|
9903
10171
|
resolvedBase: resolved[i].resolvedBase,
|
|
9904
10172
|
files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
|
|
@@ -9906,6 +10174,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
9906
10174
|
const resolvedBase = resolved[0]?.resolvedBase ?? "HEAD";
|
|
9907
10175
|
const head = git(["rev-parse", "--abbrev-ref", "HEAD"], scope.paths[0]);
|
|
9908
10176
|
const headBranch = head.exitCode === 0 && head.stdout && head.stdout !== "HEAD" ? head.stdout : void 0;
|
|
10177
|
+
suppressScopeWatch(scope.hash, 800);
|
|
9909
10178
|
return c.json({
|
|
9910
10179
|
scopeHash: scope.hash,
|
|
9911
10180
|
base,
|
|
@@ -9928,7 +10197,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
9928
10197
|
if (!relPath || !Number.isInteger(start) || !Number.isInteger(end)) {
|
|
9929
10198
|
return c.json({ error: "bad path/start/end" }, 400);
|
|
9930
10199
|
}
|
|
9931
|
-
const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) =>
|
|
10200
|
+
const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path39.basename(p) === repoName);
|
|
9932
10201
|
if (!root) return c.json({ error: "unknown repo" }, 404);
|
|
9933
10202
|
const result = readContextLines({ root, relPath, start, end, ref });
|
|
9934
10203
|
if (!result) return c.json({ error: "cannot read file" }, 400);
|
|
@@ -9943,6 +10212,22 @@ function mountScopeRoutes(app, opts) {
|
|
|
9943
10212
|
entries: manifest.entries
|
|
9944
10213
|
});
|
|
9945
10214
|
});
|
|
10215
|
+
app.post("/api/scopes/:hash/checkpoints/:id/summary", async (c) => {
|
|
10216
|
+
const scope = getScope(c.req.param("hash"));
|
|
10217
|
+
if (!scope) return c.json({ error: "unknown scope" }, 404);
|
|
10218
|
+
const id = Number(c.req.param("id"));
|
|
10219
|
+
if (!Number.isInteger(id) || id < 0) {
|
|
10220
|
+
return c.json({ error: "bad checkpoint id" }, 400);
|
|
10221
|
+
}
|
|
10222
|
+
const entry = loadManifest(scope.hash).entries.find((e) => e.id === id);
|
|
10223
|
+
if (!entry) return c.json({ error: "unknown checkpoint" }, 404);
|
|
10224
|
+
if (entry.label && entry.label.trim()) return c.json({ label: entry.label });
|
|
10225
|
+
if (id === 0) return c.json({ label: "Initial" });
|
|
10226
|
+
const label2 = await summarizeCheckpoint(scope.hash, scopeRepos(scope.paths), id);
|
|
10227
|
+
await setCheckpointLabel(scope.hash, id, label2);
|
|
10228
|
+
opts.broadcast("checkpoints-changed", { scopeHash: scope.hash, id });
|
|
10229
|
+
return c.json({ label: label2 });
|
|
10230
|
+
});
|
|
9946
10231
|
function commentStore(hash) {
|
|
9947
10232
|
return getCommentFileStore(commentStoreIdForScope(hash));
|
|
9948
10233
|
}
|
|
@@ -9963,7 +10248,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
9963
10248
|
const store = commentStore(scope.hash);
|
|
9964
10249
|
try {
|
|
9965
10250
|
const comment = store.post(c.req.valid("json"));
|
|
9966
|
-
|
|
10251
|
+
emitCommentsChanged({
|
|
9967
10252
|
scopeHash: scope.hash,
|
|
9968
10253
|
id: comment.id
|
|
9969
10254
|
});
|
|
@@ -9979,13 +10264,33 @@ function mountScopeRoutes(app, opts) {
|
|
|
9979
10264
|
const store = commentStore(scope.hash);
|
|
9980
10265
|
const removed = store.remove(c.req.param("cid"));
|
|
9981
10266
|
if (removed) {
|
|
9982
|
-
|
|
10267
|
+
emitCommentsChanged({
|
|
9983
10268
|
scopeHash: scope.hash,
|
|
9984
10269
|
deleted: c.req.param("cid")
|
|
9985
10270
|
});
|
|
9986
10271
|
}
|
|
9987
10272
|
return c.json({ comments: store.snapshot() });
|
|
9988
10273
|
});
|
|
10274
|
+
app.post(
|
|
10275
|
+
"/api/scopes/:hash/comments/:cid/resolve",
|
|
10276
|
+
zValidator5("json", resolveSchema),
|
|
10277
|
+
(c) => {
|
|
10278
|
+
const scope = getScope(c.req.param("hash"));
|
|
10279
|
+
if (!scope) return c.json({ error: "unknown scope" }, 404);
|
|
10280
|
+
const store = commentStore(scope.hash);
|
|
10281
|
+
const updated = store.setResolved(
|
|
10282
|
+
c.req.param("cid"),
|
|
10283
|
+
c.req.valid("json").resolved
|
|
10284
|
+
);
|
|
10285
|
+
if (updated) {
|
|
10286
|
+
emitCommentsChanged({
|
|
10287
|
+
scopeHash: scope.hash,
|
|
10288
|
+
id: updated.id
|
|
10289
|
+
});
|
|
10290
|
+
}
|
|
10291
|
+
return c.json({ comments: store.snapshot() });
|
|
10292
|
+
}
|
|
10293
|
+
);
|
|
9989
10294
|
app.post(
|
|
9990
10295
|
"/api/scopes/:hash/submit-review",
|
|
9991
10296
|
zValidator5("json", submitReviewSchema),
|
|
@@ -9994,7 +10299,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
9994
10299
|
if (!scope) return c.json({ error: "unknown scope" }, 404);
|
|
9995
10300
|
const store = commentStore(scope.hash);
|
|
9996
10301
|
const result = store.submit(c.req.valid("json").summary);
|
|
9997
|
-
|
|
10302
|
+
emitCommentsChanged({
|
|
9998
10303
|
scopeHash: scope.hash,
|
|
9999
10304
|
submittedCount: result.drafts.length
|
|
10000
10305
|
});
|
|
@@ -10010,7 +10315,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
10010
10315
|
const store = commentStore(scope.hash);
|
|
10011
10316
|
const discarded = store.discardDrafts();
|
|
10012
10317
|
if (discarded > 0) {
|
|
10013
|
-
|
|
10318
|
+
emitCommentsChanged({ scopeHash: scope.hash });
|
|
10014
10319
|
}
|
|
10015
10320
|
return c.json({ discarded, comments: store.snapshot() });
|
|
10016
10321
|
});
|
|
@@ -10020,7 +10325,9 @@ function mountScopeRoutes(app, opts) {
|
|
|
10020
10325
|
const store = commentStore(scope.hash);
|
|
10021
10326
|
const count = store.list().length;
|
|
10022
10327
|
markScopeEnded(scope.hash);
|
|
10023
|
-
|
|
10328
|
+
const payload = { scopeHash: scope.hash, count };
|
|
10329
|
+
opts.broadcast("review-done", payload);
|
|
10330
|
+
scopeBus.emit("review-done", payload);
|
|
10024
10331
|
return c.json({ ok: true, count });
|
|
10025
10332
|
});
|
|
10026
10333
|
app.get("/api/scopes/:hash/events", (c) => {
|
|
@@ -10043,11 +10350,31 @@ function mountScopeRoutes(app, opts) {
|
|
|
10043
10350
|
});
|
|
10044
10351
|
};
|
|
10045
10352
|
scopeBus.on("checkpoints-changed", onCheckpoint);
|
|
10353
|
+
const onComments = (payload) => {
|
|
10354
|
+
if (payload.scopeHash !== scope.hash) return;
|
|
10355
|
+
stream.writeSSE({
|
|
10356
|
+
event: "comments-changed",
|
|
10357
|
+
data: JSON.stringify(payload)
|
|
10358
|
+
}).catch(() => {
|
|
10359
|
+
});
|
|
10360
|
+
};
|
|
10361
|
+
scopeBus.on("comments-changed", onComments);
|
|
10362
|
+
const onDone = (payload) => {
|
|
10363
|
+
if (payload.scopeHash !== scope.hash) return;
|
|
10364
|
+
stream.writeSSE({
|
|
10365
|
+
event: "review-done",
|
|
10366
|
+
data: JSON.stringify(payload)
|
|
10367
|
+
}).catch(() => {
|
|
10368
|
+
});
|
|
10369
|
+
};
|
|
10370
|
+
scopeBus.on("review-done", onDone);
|
|
10046
10371
|
await stream.writeSSE({ event: "connected", data: "" });
|
|
10047
10372
|
await new Promise((resolve) => {
|
|
10048
10373
|
stream.onAbort(() => {
|
|
10049
10374
|
unsubscribe?.();
|
|
10050
10375
|
scopeBus.off("checkpoints-changed", onCheckpoint);
|
|
10376
|
+
scopeBus.off("comments-changed", onComments);
|
|
10377
|
+
scopeBus.off("review-done", onDone);
|
|
10051
10378
|
resolve();
|
|
10052
10379
|
});
|
|
10053
10380
|
});
|
|
@@ -10166,7 +10493,7 @@ function computeSessionDiff(s, base) {
|
|
|
10166
10493
|
(p) => resolveRepoDiff(p, base, s.baseBranches?.[p] ?? s.baseBranch)
|
|
10167
10494
|
);
|
|
10168
10495
|
const repos = s.paths.map((p, i) => ({
|
|
10169
|
-
name:
|
|
10496
|
+
name: path40.basename(p),
|
|
10170
10497
|
root: p,
|
|
10171
10498
|
resolvedBase: resolved[i].resolvedBase,
|
|
10172
10499
|
files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
|
|
@@ -10186,10 +10513,10 @@ async function startWebServer(opts = {}) {
|
|
|
10186
10513
|
for (const cb of sseListeners) cb({ event, data });
|
|
10187
10514
|
};
|
|
10188
10515
|
const home = os12.homedir();
|
|
10189
|
-
const historyPath =
|
|
10516
|
+
const historyPath = path40.join(home, ".work", "history.json");
|
|
10190
10517
|
const onHistoryChange = () => broadcast("sessions-changed", { ts: Date.now() });
|
|
10191
10518
|
fs40.watchFile(historyPath, { interval: 1e3 }, onHistoryChange);
|
|
10192
|
-
const tasksPath =
|
|
10519
|
+
const tasksPath = path40.join(home, ".work", "tasks.json");
|
|
10193
10520
|
const onTasksChange = () => broadcast("tasks-changed", { ts: Date.now() });
|
|
10194
10521
|
fs40.watchFile(tasksPath, { interval: 1e3 }, onTasksChange);
|
|
10195
10522
|
const projectsRoot = claudeProjectsRoot();
|
|
@@ -10334,10 +10661,10 @@ function info2(message) {
|
|
|
10334
10661
|
process.stderr.write(message + "\n");
|
|
10335
10662
|
}
|
|
10336
10663
|
function urlFilePath() {
|
|
10337
|
-
return
|
|
10664
|
+
return path41.join(os13.homedir(), ".work", "web.url");
|
|
10338
10665
|
}
|
|
10339
10666
|
function pidFilePath() {
|
|
10340
|
-
return
|
|
10667
|
+
return path41.join(os13.homedir(), ".work", "web.pid");
|
|
10341
10668
|
}
|
|
10342
10669
|
function isPidAlive(pid) {
|
|
10343
10670
|
try {
|
|
@@ -10462,7 +10789,7 @@ var webCommand = {
|
|
|
10462
10789
|
const lean = !!argv.lean || process.env.WORK_WEB_LEAN === "1";
|
|
10463
10790
|
const handle = await startWebServer({ lean });
|
|
10464
10791
|
try {
|
|
10465
|
-
fs41.mkdirSync(
|
|
10792
|
+
fs41.mkdirSync(path41.dirname(urlFilePath()), { recursive: true });
|
|
10466
10793
|
fs41.writeFileSync(urlFilePath(), handle.url);
|
|
10467
10794
|
fs41.writeFileSync(pidFilePath(), String(process.pid));
|
|
10468
10795
|
} catch {
|
|
@@ -10491,6 +10818,13 @@ var webCommand = {
|
|
|
10491
10818
|
]).catch(() => {
|
|
10492
10819
|
});
|
|
10493
10820
|
}
|
|
10821
|
+
await installCommandHook({
|
|
10822
|
+
owner: "web-checkpoint",
|
|
10823
|
+
event: "Stop",
|
|
10824
|
+
command: "work hook checkpoint",
|
|
10825
|
+
timeoutSec: 5
|
|
10826
|
+
}).catch(() => {
|
|
10827
|
+
});
|
|
10494
10828
|
const shutdown = () => {
|
|
10495
10829
|
info2(chalk23.gray("\nStopping work web."));
|
|
10496
10830
|
try {
|
|
@@ -10511,6 +10845,10 @@ var webCommand = {
|
|
|
10511
10845
|
} catch {
|
|
10512
10846
|
}
|
|
10513
10847
|
}
|
|
10848
|
+
try {
|
|
10849
|
+
removeCommandHookSync("web-checkpoint", "Stop");
|
|
10850
|
+
} catch {
|
|
10851
|
+
}
|
|
10514
10852
|
handle.stop();
|
|
10515
10853
|
process.exit(0);
|
|
10516
10854
|
};
|
|
@@ -10532,6 +10870,31 @@ var webCommand = {
|
|
|
10532
10870
|
};
|
|
10533
10871
|
|
|
10534
10872
|
// src/commands/hook.ts
|
|
10873
|
+
import fs42 from "fs";
|
|
10874
|
+
import os14 from "os";
|
|
10875
|
+
import path42 from "path";
|
|
10876
|
+
async function triggerCheckpoint(cwd) {
|
|
10877
|
+
let base;
|
|
10878
|
+
try {
|
|
10879
|
+
base = fs42.readFileSync(path42.join(os14.homedir(), ".work", "web.url"), "utf-8").trim();
|
|
10880
|
+
} catch {
|
|
10881
|
+
return;
|
|
10882
|
+
}
|
|
10883
|
+
if (!base) return;
|
|
10884
|
+
const controller = new AbortController();
|
|
10885
|
+
const timer = setTimeout(() => controller.abort(), 3e3);
|
|
10886
|
+
try {
|
|
10887
|
+
await fetch(`${base}api/checkpoint`, {
|
|
10888
|
+
method: "POST",
|
|
10889
|
+
headers: { "Content-Type": "application/json" },
|
|
10890
|
+
body: JSON.stringify({ cwd }),
|
|
10891
|
+
signal: controller.signal
|
|
10892
|
+
});
|
|
10893
|
+
} catch {
|
|
10894
|
+
} finally {
|
|
10895
|
+
clearTimeout(timer);
|
|
10896
|
+
}
|
|
10897
|
+
}
|
|
10535
10898
|
function computeHookOutput(input2) {
|
|
10536
10899
|
const session = findSessionForCwd(input2.cwd);
|
|
10537
10900
|
if (!session) return null;
|
|
@@ -10581,13 +10944,17 @@ var hookCommand = {
|
|
|
10581
10944
|
// hidden — humans don't call this directly
|
|
10582
10945
|
builder: (y) => y.positional("event", {
|
|
10583
10946
|
type: "string",
|
|
10584
|
-
choices: ["prompt-submit", "stop"],
|
|
10947
|
+
choices: ["prompt-submit", "stop", "checkpoint"],
|
|
10585
10948
|
describe: "Hook event name"
|
|
10586
10949
|
}),
|
|
10587
10950
|
handler: async (argv) => {
|
|
10588
10951
|
const event = argv.event;
|
|
10589
10952
|
const payload = await readStdinJson();
|
|
10590
10953
|
const cwd = payload.cwd ?? process.cwd();
|
|
10954
|
+
if (event === "checkpoint") {
|
|
10955
|
+
await triggerCheckpoint(cwd);
|
|
10956
|
+
return;
|
|
10957
|
+
}
|
|
10591
10958
|
const result = computeHookOutput({ event, cwd });
|
|
10592
10959
|
if (!result || !result.sessionId) return;
|
|
10593
10960
|
process.stdout.write(result.stdout);
|
|
@@ -10597,7 +10964,7 @@ var hookCommand = {
|
|
|
10597
10964
|
|
|
10598
10965
|
// src/commands/run.ts
|
|
10599
10966
|
import chalk24 from "chalk";
|
|
10600
|
-
import
|
|
10967
|
+
import spawn15 from "cross-spawn";
|
|
10601
10968
|
|
|
10602
10969
|
// src/core/fleet.ts
|
|
10603
10970
|
function selectSessions(sessions, filter) {
|
|
@@ -10639,7 +11006,7 @@ function killAllChildren(signal = "SIGTERM") {
|
|
|
10639
11006
|
function runInPath(unit, cmd, prefix) {
|
|
10640
11007
|
const { bin, args } = shellInvocation(cmd);
|
|
10641
11008
|
return new Promise((resolve) => {
|
|
10642
|
-
const child =
|
|
11009
|
+
const child = spawn15(bin, args, {
|
|
10643
11010
|
cwd: unit.path,
|
|
10644
11011
|
stdio: prefix ? ["ignore", "pipe", "pipe"] : "inherit",
|
|
10645
11012
|
shell: false
|
|
@@ -10871,15 +11238,15 @@ var runCommand = {
|
|
|
10871
11238
|
};
|
|
10872
11239
|
|
|
10873
11240
|
// src/commands/broadcast.ts
|
|
10874
|
-
import
|
|
11241
|
+
import fs44 from "fs";
|
|
10875
11242
|
import chalk25 from "chalk";
|
|
10876
11243
|
|
|
10877
11244
|
// src/core/broadcast.ts
|
|
10878
11245
|
import crypto6 from "crypto";
|
|
10879
|
-
import
|
|
11246
|
+
import fs43 from "fs";
|
|
10880
11247
|
function readComments(file) {
|
|
10881
11248
|
try {
|
|
10882
|
-
const parsed = JSON.parse(
|
|
11249
|
+
const parsed = JSON.parse(fs43.readFileSync(file, "utf-8"));
|
|
10883
11250
|
return Array.isArray(parsed) ? parsed : [];
|
|
10884
11251
|
} catch {
|
|
10885
11252
|
return [];
|
|
@@ -10887,7 +11254,7 @@ function readComments(file) {
|
|
|
10887
11254
|
}
|
|
10888
11255
|
async function appendLocked(sessionId, body) {
|
|
10889
11256
|
const file = commentsFileFor(sessionId);
|
|
10890
|
-
|
|
11257
|
+
fs43.mkdirSync(commentsDir(), { recursive: true });
|
|
10891
11258
|
ensureFile(file, "[]");
|
|
10892
11259
|
const comment = {
|
|
10893
11260
|
id: crypto6.randomBytes(8).toString("hex"),
|
|
@@ -10924,7 +11291,7 @@ async function broadcastPrompt(sessions, filter, prompt) {
|
|
|
10924
11291
|
// src/commands/broadcast.ts
|
|
10925
11292
|
function readStdin() {
|
|
10926
11293
|
try {
|
|
10927
|
-
return
|
|
11294
|
+
return fs44.readFileSync(0, "utf-8");
|
|
10928
11295
|
} catch {
|
|
10929
11296
|
return "";
|
|
10930
11297
|
}
|
|
@@ -10999,8 +11366,8 @@ var broadcastCommand = {
|
|
|
10999
11366
|
};
|
|
11000
11367
|
|
|
11001
11368
|
// src/completions/index.ts
|
|
11002
|
-
import
|
|
11003
|
-
import
|
|
11369
|
+
import fs45 from "fs";
|
|
11370
|
+
import path43 from "path";
|
|
11004
11371
|
function completionHandler(current, argv, done) {
|
|
11005
11372
|
const rawArgs = argv._;
|
|
11006
11373
|
const args = rawArgs.slice(1, -1);
|
|
@@ -11104,7 +11471,7 @@ function completeTreeRemoveList(command, args, current, config, done) {
|
|
|
11104
11471
|
}
|
|
11105
11472
|
function completeRepoBranches(alias, current, config, done) {
|
|
11106
11473
|
const repoPath = config.repos[alias];
|
|
11107
|
-
if (!repoPath || !
|
|
11474
|
+
if (!repoPath || !fs45.existsSync(repoPath)) {
|
|
11108
11475
|
done([]);
|
|
11109
11476
|
return;
|
|
11110
11477
|
}
|
|
@@ -11113,19 +11480,19 @@ function completeRepoBranches(alias, current, config, done) {
|
|
|
11113
11480
|
done(branches);
|
|
11114
11481
|
}
|
|
11115
11482
|
function completeGroupBranches(groupName, repoAliases, current, config, done) {
|
|
11116
|
-
const groupDir =
|
|
11117
|
-
if (!
|
|
11483
|
+
const groupDir = path43.join(config.worktreesRoot, groupName);
|
|
11484
|
+
if (!fs45.existsSync(groupDir)) {
|
|
11118
11485
|
done([]);
|
|
11119
11486
|
return;
|
|
11120
11487
|
}
|
|
11121
11488
|
try {
|
|
11122
|
-
const branchDirs =
|
|
11123
|
-
const bdPath =
|
|
11489
|
+
const branchDirs = fs45.readdirSync(groupDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => {
|
|
11490
|
+
const bdPath = path43.join(groupDir, d.name);
|
|
11124
11491
|
for (const alias of repoAliases) {
|
|
11125
11492
|
const repoPath = config.repos[alias];
|
|
11126
11493
|
if (!repoPath) continue;
|
|
11127
|
-
const subPath =
|
|
11128
|
-
if (
|
|
11494
|
+
const subPath = path43.join(bdPath, path43.basename(repoPath));
|
|
11495
|
+
if (fs45.existsSync(subPath)) {
|
|
11129
11496
|
const branch = getCurrentBranch(subPath);
|
|
11130
11497
|
if (branch) return branch;
|
|
11131
11498
|
}
|
|
@@ -11139,7 +11506,7 @@ function completeGroupBranches(groupName, repoAliases, current, config, done) {
|
|
|
11139
11506
|
}
|
|
11140
11507
|
|
|
11141
11508
|
// src/version.ts
|
|
11142
|
-
var VERSION = true ? "1.
|
|
11509
|
+
var VERSION = true ? "1.9.1" : "dev";
|
|
11143
11510
|
|
|
11144
11511
|
// src/cli.ts
|
|
11145
11512
|
function showHelp() {
|
|
@@ -11236,8 +11603,8 @@ function handleFatalError(err) {
|
|
|
11236
11603
|
}
|
|
11237
11604
|
if (err instanceof Error && err.message?.includes("pty that has already exited")) {
|
|
11238
11605
|
try {
|
|
11239
|
-
|
|
11240
|
-
|
|
11606
|
+
fs46.appendFileSync(
|
|
11607
|
+
path44.join(getConfigDir(), "debug.log"),
|
|
11241
11608
|
`${(/* @__PURE__ */ new Date()).toISOString()} [WARN] Ignored async node-pty error: ${err.message}
|
|
11242
11609
|
`
|
|
11243
11610
|
);
|
|
@@ -11247,8 +11614,8 @@ function handleFatalError(err) {
|
|
|
11247
11614
|
}
|
|
11248
11615
|
try {
|
|
11249
11616
|
const msg = err instanceof Error ? err.stack || err.message : String(err);
|
|
11250
|
-
|
|
11251
|
-
|
|
11617
|
+
fs46.appendFileSync(
|
|
11618
|
+
path44.join(getConfigDir(), "debug.log"),
|
|
11252
11619
|
`${(/* @__PURE__ */ new Date()).toISOString()} [FATAL] handleFatalError: ${msg}
|
|
11253
11620
|
`
|
|
11254
11621
|
);
|