@moberg_hr/work-tree 1.9.1 → 1.15.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/README.md +26 -4
- package/dist/bin.js +520 -230
- package/dist/bin.js.map +1 -1
- package/dist/wd-bin.js +517 -227
- package/dist/wd-bin.js.map +1 -1
- package/dist/web/assets/index-BgVq8Uj_.js +107 -0
- package/dist/web/assets/index-BgVq8Uj_.js.map +1 -0
- package/dist/web/assets/index-ubbitWeW.css +1 -0
- package/dist/web/index.html +20 -2
- package/package.json +2 -1
- package/plugins/work-tree/skills/wd-review/SKILL.md +23 -2
- package/scripts/postinstall.mjs +4 -4
- package/dist/web/assets/index-BYfxyhDx.css +0 -1
- package/dist/web/assets/index-BaT8rhHI.js +0 -105
- package/dist/web/assets/index-BaT8rhHI.js.map +0 -1
package/dist/bin.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/bin.ts
|
|
4
4
|
import fs46 from "fs";
|
|
5
|
-
import
|
|
5
|
+
import path45 from "path";
|
|
6
6
|
import chalk27 from "chalk";
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
@@ -445,6 +445,17 @@ import fs3 from "fs";
|
|
|
445
445
|
import path4 from "path";
|
|
446
446
|
import spawn2 from "cross-spawn";
|
|
447
447
|
import chalk from "chalk";
|
|
448
|
+
|
|
449
|
+
// src/core/internal-claude.ts
|
|
450
|
+
var INTERNAL_CLAUDE_ENV = "WORK_INTERNAL_CLAUDE";
|
|
451
|
+
function internalClaudeEnv() {
|
|
452
|
+
return { [INTERNAL_CLAUDE_ENV]: "1" };
|
|
453
|
+
}
|
|
454
|
+
function isInternalClaude() {
|
|
455
|
+
return process.env[INTERNAL_CLAUDE_ENV] === "1";
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// src/core/claude-md.ts
|
|
448
459
|
function generateGroupClaudeMd(groupName, repoAliases, config) {
|
|
449
460
|
const outputPath = path4.join(getConfigDir(), `${groupName}.claude.md`);
|
|
450
461
|
const promptParts = [];
|
|
@@ -501,7 +512,9 @@ function generateGroupClaudeMd(groupName, repoAliases, config) {
|
|
|
501
512
|
input: prompt,
|
|
502
513
|
encoding: "utf-8",
|
|
503
514
|
stdio: ["pipe", "pipe", "pipe"],
|
|
504
|
-
windowsHide: true
|
|
515
|
+
windowsHide: true,
|
|
516
|
+
// Internal call — don't trip work's checkpoint hooks (see internal-claude.ts).
|
|
517
|
+
env: { ...process.env, ...internalClaudeEnv() }
|
|
505
518
|
});
|
|
506
519
|
let content;
|
|
507
520
|
if (result.status !== 0 || !result.stdout?.trim()) {
|
|
@@ -1384,20 +1397,44 @@ function resolveFromCwd(config, cwd) {
|
|
|
1384
1397
|
|
|
1385
1398
|
// src/core/worktree.ts
|
|
1386
1399
|
import fs13 from "fs";
|
|
1387
|
-
import
|
|
1400
|
+
import path13 from "path";
|
|
1388
1401
|
import chalk5 from "chalk";
|
|
1389
1402
|
|
|
1390
1403
|
// src/core/history.ts
|
|
1391
1404
|
import fs11 from "fs";
|
|
1392
|
-
import
|
|
1405
|
+
import path11 from "path";
|
|
1393
1406
|
|
|
1394
1407
|
// src/core/fs-safe.ts
|
|
1395
1408
|
import fs8 from "fs";
|
|
1409
|
+
import path9 from "path";
|
|
1396
1410
|
import lockfile from "proper-lockfile";
|
|
1411
|
+
function resolveLinkTarget(filePath) {
|
|
1412
|
+
let current = filePath;
|
|
1413
|
+
const seen = /* @__PURE__ */ new Set([current]);
|
|
1414
|
+
for (let i = 0; i < 32; i++) {
|
|
1415
|
+
let stat;
|
|
1416
|
+
try {
|
|
1417
|
+
stat = fs8.lstatSync(current);
|
|
1418
|
+
} catch {
|
|
1419
|
+
return current;
|
|
1420
|
+
}
|
|
1421
|
+
if (!stat.isSymbolicLink()) return current;
|
|
1422
|
+
const next = path9.resolve(path9.dirname(current), fs8.readlinkSync(current));
|
|
1423
|
+
if (seen.has(next)) return filePath;
|
|
1424
|
+
seen.add(next);
|
|
1425
|
+
current = next;
|
|
1426
|
+
}
|
|
1427
|
+
return filePath;
|
|
1428
|
+
}
|
|
1397
1429
|
function atomicWriteFile(filePath, content) {
|
|
1398
|
-
const
|
|
1430
|
+
const target = resolveLinkTarget(filePath);
|
|
1431
|
+
const tmpPath = `${target}.tmp-${process.pid}`;
|
|
1399
1432
|
fs8.writeFileSync(tmpPath, content, "utf-8");
|
|
1400
|
-
|
|
1433
|
+
try {
|
|
1434
|
+
fs8.chmodSync(tmpPath, fs8.statSync(target).mode & 511);
|
|
1435
|
+
} catch {
|
|
1436
|
+
}
|
|
1437
|
+
fs8.renameSync(tmpPath, target);
|
|
1401
1438
|
}
|
|
1402
1439
|
function ensureFile(filePath, initialContent) {
|
|
1403
1440
|
if (!fs8.existsSync(filePath)) {
|
|
@@ -1442,9 +1479,9 @@ function sleepSync(ms) {
|
|
|
1442
1479
|
// src/core/claude-activity.ts
|
|
1443
1480
|
import fs9 from "fs";
|
|
1444
1481
|
import os4 from "os";
|
|
1445
|
-
import
|
|
1482
|
+
import path10 from "path";
|
|
1446
1483
|
function encodeProjectDir(p) {
|
|
1447
|
-
return
|
|
1484
|
+
return path10.resolve(p).replace(/[^A-Za-z0-9]/g, "-");
|
|
1448
1485
|
}
|
|
1449
1486
|
function latestJsonlMtimeMs(projectDir) {
|
|
1450
1487
|
let entries;
|
|
@@ -1457,7 +1494,7 @@ function latestJsonlMtimeMs(projectDir) {
|
|
|
1457
1494
|
for (const name of entries) {
|
|
1458
1495
|
if (!name.endsWith(".jsonl")) continue;
|
|
1459
1496
|
try {
|
|
1460
|
-
const stat = fs9.statSync(
|
|
1497
|
+
const stat = fs9.statSync(path10.join(projectDir, name));
|
|
1461
1498
|
if (stat.mtimeMs > latest) latest = stat.mtimeMs;
|
|
1462
1499
|
} catch {
|
|
1463
1500
|
}
|
|
@@ -1468,7 +1505,7 @@ function claudeActiveWithin(activityMs, nowMs, windowMs) {
|
|
|
1468
1505
|
return activityMs > 0 && nowMs - activityMs < windowMs;
|
|
1469
1506
|
}
|
|
1470
1507
|
function getClaudeActivityMs(launchPath) {
|
|
1471
|
-
const dir =
|
|
1508
|
+
const dir = path10.join(
|
|
1472
1509
|
os4.homedir(),
|
|
1473
1510
|
".claude",
|
|
1474
1511
|
"projects",
|
|
@@ -1476,10 +1513,13 @@ function getClaudeActivityMs(launchPath) {
|
|
|
1476
1513
|
);
|
|
1477
1514
|
return latestJsonlMtimeMs(dir);
|
|
1478
1515
|
}
|
|
1516
|
+
function hasClaudeConversation(dir) {
|
|
1517
|
+
return getClaudeActivityMs(dir) > 0;
|
|
1518
|
+
}
|
|
1479
1519
|
function getLaunchPaths(session) {
|
|
1480
1520
|
if (!session.isGroup) return [...session.paths];
|
|
1481
1521
|
const parents = /* @__PURE__ */ new Set();
|
|
1482
|
-
for (const p of session.paths) parents.add(
|
|
1522
|
+
for (const p of session.paths) parents.add(path10.dirname(p));
|
|
1483
1523
|
return [...parents];
|
|
1484
1524
|
}
|
|
1485
1525
|
function effectiveLastAccessedAt(session) {
|
|
@@ -1494,10 +1534,10 @@ function effectiveLastAccessedAt(session) {
|
|
|
1494
1534
|
function resolveResumeLaunch(session) {
|
|
1495
1535
|
const existing = session.paths.filter((p) => fs9.existsSync(p));
|
|
1496
1536
|
const first = existing[0] ?? session.paths[0];
|
|
1497
|
-
const defaultPath = session.isGroup ?
|
|
1537
|
+
const defaultPath = session.isGroup ? path10.dirname(first) : first;
|
|
1498
1538
|
const candidates = /* @__PURE__ */ new Set();
|
|
1499
1539
|
if (session.isGroup) {
|
|
1500
|
-
for (const p of existing) candidates.add(
|
|
1540
|
+
for (const p of existing) candidates.add(path10.dirname(p));
|
|
1501
1541
|
for (const p of existing) candidates.add(p);
|
|
1502
1542
|
} else {
|
|
1503
1543
|
for (const p of existing) candidates.add(p);
|
|
@@ -1527,7 +1567,7 @@ function readSessionActivity(session) {
|
|
|
1527
1567
|
return { lastActivity: latest, state };
|
|
1528
1568
|
}
|
|
1529
1569
|
function claudeProjectsRoot() {
|
|
1530
|
-
return
|
|
1570
|
+
return path10.join(os4.homedir(), ".claude", "projects");
|
|
1531
1571
|
}
|
|
1532
1572
|
|
|
1533
1573
|
// src/core/port-allocator.ts
|
|
@@ -1601,7 +1641,7 @@ async function allocateFreePort(seedKey, config, sessions, probe = isPortFree) {
|
|
|
1601
1641
|
|
|
1602
1642
|
// src/core/history.ts
|
|
1603
1643
|
function getHistoryPath() {
|
|
1604
|
-
return
|
|
1644
|
+
return path11.join(getConfigDir(), "history.json");
|
|
1605
1645
|
}
|
|
1606
1646
|
function backupCorruptFile(historyPath, reason) {
|
|
1607
1647
|
try {
|
|
@@ -1794,7 +1834,7 @@ async function mergeHydratedSessions(incoming) {
|
|
|
1794
1834
|
|
|
1795
1835
|
// src/core/copy-files.ts
|
|
1796
1836
|
import fs12 from "fs";
|
|
1797
|
-
import
|
|
1837
|
+
import path12 from "path";
|
|
1798
1838
|
import { globSync } from "glob";
|
|
1799
1839
|
var EXCLUDED_DIRS = ["bin", "obj", "node_modules", ".git"];
|
|
1800
1840
|
function copyConfigFiles(repoPath, worktreePath, patterns) {
|
|
@@ -1802,10 +1842,10 @@ function copyConfigFiles(repoPath, worktreePath, patterns) {
|
|
|
1802
1842
|
const normalized = pattern.replace(/\\/g, "/");
|
|
1803
1843
|
if (normalized.startsWith(".claude/")) {
|
|
1804
1844
|
const relativePath = normalized;
|
|
1805
|
-
const sourcePath =
|
|
1845
|
+
const sourcePath = path12.join(repoPath, relativePath);
|
|
1806
1846
|
if (fs12.existsSync(sourcePath)) {
|
|
1807
|
-
const destPath =
|
|
1808
|
-
const destDir =
|
|
1847
|
+
const destPath = path12.join(worktreePath, relativePath);
|
|
1848
|
+
const destDir = path12.dirname(destPath);
|
|
1809
1849
|
fs12.mkdirSync(destDir, { recursive: true });
|
|
1810
1850
|
fs12.copyFileSync(sourcePath, destPath);
|
|
1811
1851
|
console.log(` Copied: ${relativePath}`);
|
|
@@ -1823,9 +1863,9 @@ function copyConfigFiles(repoPath, worktreePath, patterns) {
|
|
|
1823
1863
|
if (parts.some((p) => EXCLUDED_DIRS.includes(p))) {
|
|
1824
1864
|
continue;
|
|
1825
1865
|
}
|
|
1826
|
-
const sourcePath =
|
|
1827
|
-
const destPath =
|
|
1828
|
-
const destDir =
|
|
1866
|
+
const sourcePath = path12.join(repoPath, match);
|
|
1867
|
+
const destPath = path12.join(worktreePath, match);
|
|
1868
|
+
const destDir = path12.dirname(destPath);
|
|
1829
1869
|
fs12.mkdirSync(destDir, { recursive: true });
|
|
1830
1870
|
fs12.copyFileSync(sourcePath, destPath);
|
|
1831
1871
|
console.log(` Copied: ${match}`);
|
|
@@ -1890,7 +1930,26 @@ function toBaseSpec(base) {
|
|
|
1890
1930
|
}
|
|
1891
1931
|
|
|
1892
1932
|
// src/core/worktree.ts
|
|
1893
|
-
function
|
|
1933
|
+
function pullLatestForBranch(worktreePath, branchName) {
|
|
1934
|
+
const upstream = git(
|
|
1935
|
+
["rev-parse", "--abbrev-ref", `${branchName}@{upstream}`],
|
|
1936
|
+
worktreePath
|
|
1937
|
+
);
|
|
1938
|
+
if (upstream.exitCode !== 0) return;
|
|
1939
|
+
console.log(` Pulling latest changes for ${branchName}...`);
|
|
1940
|
+
git(["fetch", "--quiet"], worktreePath);
|
|
1941
|
+
const pull = git(["pull", "--quiet"], worktreePath);
|
|
1942
|
+
if (pull.exitCode !== 0) {
|
|
1943
|
+
console.log(
|
|
1944
|
+
chalk5.yellow(
|
|
1945
|
+
` \u26A0 Could not pull '${branchName}' (uncommitted changes or conflicts). Worktree may be behind origin.`
|
|
1946
|
+
)
|
|
1947
|
+
);
|
|
1948
|
+
const firstErrLine = pull.stderr.split("\n")[0];
|
|
1949
|
+
if (firstErrLine) console.log(chalk5.gray(` ${firstErrLine}`));
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
function createSingleWorktree(repoPath, worktreePath, branchName, config, baseBranch, pull = true) {
|
|
1894
1953
|
debug("createSingleWorktree", { repoPath, worktreePath, branchName, baseBranch });
|
|
1895
1954
|
if (fs13.existsSync(worktreePath)) {
|
|
1896
1955
|
if (isGitRepo(worktreePath)) {
|
|
@@ -1899,6 +1958,7 @@ function createSingleWorktree(repoPath, worktreePath, branchName, config, baseBr
|
|
|
1899
1958
|
console.log(
|
|
1900
1959
|
chalk5.yellow(` Worktree already exists at: ${worktreePath}`)
|
|
1901
1960
|
);
|
|
1961
|
+
if (pull) pullLatestForBranch(worktreePath, branchName);
|
|
1902
1962
|
return true;
|
|
1903
1963
|
}
|
|
1904
1964
|
}
|
|
@@ -1918,7 +1978,7 @@ function createSingleWorktree(repoPath, worktreePath, branchName, config, baseBr
|
|
|
1918
1978
|
);
|
|
1919
1979
|
return false;
|
|
1920
1980
|
}
|
|
1921
|
-
const parentDir =
|
|
1981
|
+
const parentDir = path13.dirname(worktreePath);
|
|
1922
1982
|
fs13.mkdirSync(parentDir, { recursive: true });
|
|
1923
1983
|
git(["fetch", "--quiet"], repoPath);
|
|
1924
1984
|
const baseRepoBranch = getCurrentBranch(repoPath);
|
|
@@ -2094,9 +2154,9 @@ function removeSingleWorktree(repoPath, worktreePath, branchName, force) {
|
|
|
2094
2154
|
return false;
|
|
2095
2155
|
}
|
|
2096
2156
|
}
|
|
2097
|
-
async function setupWorktree(targetName, branchName, config, base, jiraKey) {
|
|
2157
|
+
async function setupWorktree(targetName, branchName, config, base, jiraKey, opts = {}) {
|
|
2098
2158
|
const spec = toBaseSpec(base);
|
|
2099
|
-
debug("setupWorktree", { targetName, branchName, spec, jiraKey });
|
|
2159
|
+
debug("setupWorktree", { targetName, branchName, spec, jiraKey, opts });
|
|
2100
2160
|
const target = resolveProjectTarget(targetName, config);
|
|
2101
2161
|
if (!target) {
|
|
2102
2162
|
debug("setupWorktree: target not found", targetName);
|
|
@@ -2104,13 +2164,13 @@ async function setupWorktree(targetName, branchName, config, base, jiraKey) {
|
|
|
2104
2164
|
}
|
|
2105
2165
|
const workTreeDirName = branchName.replace(/\//g, "-");
|
|
2106
2166
|
if (target.isGroup) {
|
|
2107
|
-
return setupGroupWorktree(target.name, target.repoAliases, branchName, workTreeDirName, config, spec, jiraKey);
|
|
2167
|
+
return setupGroupWorktree(target.name, target.repoAliases, branchName, workTreeDirName, config, spec, jiraKey, opts);
|
|
2108
2168
|
} else {
|
|
2109
|
-
return setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey);
|
|
2169
|
+
return setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey, opts);
|
|
2110
2170
|
}
|
|
2111
2171
|
}
|
|
2112
|
-
async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDirName, config, spec, jiraKey) {
|
|
2113
|
-
const groupWorktreePath =
|
|
2172
|
+
async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDirName, config, spec, jiraKey, opts = {}) {
|
|
2173
|
+
const groupWorktreePath = path13.join(config.worktreesRoot, groupName, workTreeDirName);
|
|
2114
2174
|
if (!isEmptyBaseSpec(spec)) {
|
|
2115
2175
|
const unknownAliases = baseSpecOverrideAliases(spec).filter(
|
|
2116
2176
|
(a) => !repoAliases.includes(a)
|
|
@@ -2151,11 +2211,11 @@ async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDi
|
|
|
2151
2211
|
const baseBranches = {};
|
|
2152
2212
|
for (const alias of repoAliases) {
|
|
2153
2213
|
const repoPath = config.repos[alias];
|
|
2154
|
-
const repoName =
|
|
2155
|
-
const subWorktreePath =
|
|
2214
|
+
const repoName = path13.basename(repoPath);
|
|
2215
|
+
const subWorktreePath = path13.join(groupWorktreePath, repoName);
|
|
2156
2216
|
const repoBase = baseForAlias(spec, alias);
|
|
2157
2217
|
console.log(chalk5.cyan(`[${alias}] (${repoName}):`));
|
|
2158
|
-
const success = createSingleWorktree(repoPath, subWorktreePath, branchName, config, repoBase);
|
|
2218
|
+
const success = createSingleWorktree(repoPath, subWorktreePath, branchName, config, repoBase, opts.pull !== false);
|
|
2159
2219
|
if (success) {
|
|
2160
2220
|
createdWorktrees.push({ repoPath, worktreePath: subWorktreePath });
|
|
2161
2221
|
if (repoBase) baseBranches[subWorktreePath] = repoBase;
|
|
@@ -2176,8 +2236,8 @@ async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDi
|
|
|
2176
2236
|
}
|
|
2177
2237
|
}
|
|
2178
2238
|
const configDir = getConfigDir();
|
|
2179
|
-
const claudeMdSrc =
|
|
2180
|
-
const claudeMdDest =
|
|
2239
|
+
const claudeMdSrc = path13.join(configDir, `${groupName}.claude.md`);
|
|
2240
|
+
const claudeMdDest = path13.join(groupWorktreePath, "CLAUDE.md");
|
|
2181
2241
|
if (fs13.existsSync(claudeMdSrc)) {
|
|
2182
2242
|
fs13.copyFileSync(claudeMdSrc, claudeMdDest);
|
|
2183
2243
|
console.log("");
|
|
@@ -2205,10 +2265,10 @@ async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDi
|
|
|
2205
2265
|
if (port !== void 0) console.log(chalk5.gray(`Dev-server port: ${port}`));
|
|
2206
2266
|
return { launchDir: groupWorktreePath, paths: allPaths, isGroup: true, port };
|
|
2207
2267
|
}
|
|
2208
|
-
async function setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey) {
|
|
2268
|
+
async function setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey, opts = {}) {
|
|
2209
2269
|
const repoPath = config.repos[targetName];
|
|
2210
|
-
const repoName =
|
|
2211
|
-
let workTreePath =
|
|
2270
|
+
const repoName = path13.basename(repoPath);
|
|
2271
|
+
let workTreePath = path13.join(config.worktreesRoot, repoName, workTreeDirName);
|
|
2212
2272
|
const unknownAliases = baseSpecOverrideAliases(spec).filter((a) => a !== targetName);
|
|
2213
2273
|
if (unknownAliases.length > 0) {
|
|
2214
2274
|
console.error(
|
|
@@ -2223,7 +2283,7 @@ async function setupSingleWorktree(targetName, branchName, workTreeDirName, conf
|
|
|
2223
2283
|
}
|
|
2224
2284
|
const worktrees = parseWorktreeList(repoPath);
|
|
2225
2285
|
const existing = worktrees.find(
|
|
2226
|
-
(wt) => wt.branch === branchName &&
|
|
2286
|
+
(wt) => wt.branch === branchName && path13.resolve(wt.path) !== path13.resolve(repoPath)
|
|
2227
2287
|
);
|
|
2228
2288
|
if (existing) {
|
|
2229
2289
|
if (baseBranch) {
|
|
@@ -2232,8 +2292,9 @@ async function setupSingleWorktree(targetName, branchName, workTreeDirName, conf
|
|
|
2232
2292
|
}
|
|
2233
2293
|
console.log(`Worktree already exists at: ${existing.path}`);
|
|
2234
2294
|
workTreePath = existing.path;
|
|
2295
|
+
if (opts.pull !== false) pullLatestForBranch(workTreePath, branchName);
|
|
2235
2296
|
} else {
|
|
2236
|
-
const success = createSingleWorktree(repoPath, workTreePath, branchName, config, baseBranch);
|
|
2297
|
+
const success = createSingleWorktree(repoPath, workTreePath, branchName, config, baseBranch, opts.pull !== false);
|
|
2237
2298
|
if (!success) return null;
|
|
2238
2299
|
}
|
|
2239
2300
|
const { port } = await upsertSessionWithPort(
|
|
@@ -2254,19 +2315,19 @@ function teardownWorktree(target, isGroup, branch, config, force = true) {
|
|
|
2254
2315
|
const workTreeDirName = branch.replace(/\//g, "-");
|
|
2255
2316
|
if (isGroup && config.groups[target]) {
|
|
2256
2317
|
const aliases = config.groups[target];
|
|
2257
|
-
const groupWorktreePath =
|
|
2318
|
+
const groupWorktreePath = path13.join(config.worktreesRoot, target, workTreeDirName);
|
|
2258
2319
|
let allRemoved = true;
|
|
2259
2320
|
for (const alias of aliases) {
|
|
2260
2321
|
const repoPath = config.repos[alias];
|
|
2261
2322
|
if (!repoPath) continue;
|
|
2262
|
-
const repoName =
|
|
2263
|
-
const subWorktreePath =
|
|
2323
|
+
const repoName = path13.basename(repoPath);
|
|
2324
|
+
const subWorktreePath = path13.join(groupWorktreePath, repoName);
|
|
2264
2325
|
console.log(chalk5.cyan(`[${alias}] (${repoName}):`));
|
|
2265
2326
|
if (!removeSingleWorktree(repoPath, subWorktreePath, branch, force)) {
|
|
2266
2327
|
allRemoved = false;
|
|
2267
2328
|
}
|
|
2268
2329
|
}
|
|
2269
|
-
const claudeMd =
|
|
2330
|
+
const claudeMd = path13.join(groupWorktreePath, "CLAUDE.md");
|
|
2270
2331
|
try {
|
|
2271
2332
|
if (fs13.existsSync(claudeMd)) fs13.unlinkSync(claudeMd);
|
|
2272
2333
|
} catch {
|
|
@@ -2315,6 +2376,14 @@ var treeCommand = {
|
|
|
2315
2376
|
describe: "Launch the AI tool with its skip-permissions flag (default: --dangerously-skip-permissions)",
|
|
2316
2377
|
type: "boolean",
|
|
2317
2378
|
default: false
|
|
2379
|
+
}).option("pull", {
|
|
2380
|
+
describe: "Pull latest changes when switching into an existing worktree or the base repo. Use --no-pull to skip.",
|
|
2381
|
+
type: "boolean",
|
|
2382
|
+
default: true
|
|
2383
|
+
}).option("fresh", {
|
|
2384
|
+
describe: "Start a new AI conversation instead of continuing the previous one for this directory",
|
|
2385
|
+
type: "boolean",
|
|
2386
|
+
default: false
|
|
2318
2387
|
}).option("base", {
|
|
2319
2388
|
describe: "Base branch to fork from instead of HEAD. Repeatable. Use a bare branch (--base dev) for all repos, or alias=branch (--base backend=dev --base frontend=feat/x) for per-repo bases in a group.",
|
|
2320
2389
|
type: "string"
|
|
@@ -2340,6 +2409,8 @@ var treeCommand = {
|
|
|
2340
2409
|
const here = argv.here;
|
|
2341
2410
|
const open = argv.open;
|
|
2342
2411
|
const unsafe = argv.unsafe;
|
|
2412
|
+
const pull = argv.pull;
|
|
2413
|
+
const fresh = argv.fresh;
|
|
2343
2414
|
const setupOnly = argv["setup-only"];
|
|
2344
2415
|
let baseSpec;
|
|
2345
2416
|
try {
|
|
@@ -2363,6 +2434,19 @@ var treeCommand = {
|
|
|
2363
2434
|
}
|
|
2364
2435
|
}
|
|
2365
2436
|
const config = ensureConfig();
|
|
2437
|
+
const launchTool = (dir, port) => {
|
|
2438
|
+
const tool = getAiTool(config);
|
|
2439
|
+
const resume = !fresh && hasClaudeConversation(dir);
|
|
2440
|
+
if (resume) {
|
|
2441
|
+
console.log(
|
|
2442
|
+
chalk6.gray(
|
|
2443
|
+
`Continuing the previous ${tool.cmd} conversation (--fresh starts a new one).`
|
|
2444
|
+
)
|
|
2445
|
+
);
|
|
2446
|
+
}
|
|
2447
|
+
console.log(`Starting ${tool.cmd}...`);
|
|
2448
|
+
launchAi(dir, tool, { unsafe, initialPrompt, resume }, port);
|
|
2449
|
+
};
|
|
2366
2450
|
if (here) {
|
|
2367
2451
|
if (targetName) {
|
|
2368
2452
|
console.error("Cannot combine --here with an explicit target.");
|
|
@@ -2431,16 +2515,15 @@ var treeCommand = {
|
|
|
2431
2515
|
console.log(chalk6.cyan(`Working on base repo: ${targetName}`));
|
|
2432
2516
|
console.log(`Repo path: ${repoPath}`);
|
|
2433
2517
|
const currentBranch = getCurrentBranch(repoPath) ?? "(detached)";
|
|
2518
|
+
if (pull && currentBranch && currentBranch !== "(detached)") {
|
|
2519
|
+
pullLatestForBranch(repoPath, currentBranch);
|
|
2520
|
+
}
|
|
2434
2521
|
await upsertSession(targetName, false, currentBranch, [repoPath], jiraKey);
|
|
2435
2522
|
if (open) openVSCode(repoPath);
|
|
2436
|
-
if (!setupOnly)
|
|
2437
|
-
const tool = getAiTool(config);
|
|
2438
|
-
console.log(`Starting ${tool.cmd}...`);
|
|
2439
|
-
launchAi(repoPath, tool, { unsafe, initialPrompt });
|
|
2440
|
-
}
|
|
2523
|
+
if (!setupOnly) launchTool(repoPath);
|
|
2441
2524
|
return;
|
|
2442
2525
|
}
|
|
2443
|
-
const result = await setupWorktree(targetName, branchName, config, baseSpec, jiraKey);
|
|
2526
|
+
const result = await setupWorktree(targetName, branchName, config, baseSpec, jiraKey, { pull });
|
|
2444
2527
|
if (!result) {
|
|
2445
2528
|
process.exitCode = 1;
|
|
2446
2529
|
return;
|
|
@@ -2451,11 +2534,7 @@ var treeCommand = {
|
|
|
2451
2534
|
}
|
|
2452
2535
|
}
|
|
2453
2536
|
console.log(`Worktree path: ${result.launchDir}`);
|
|
2454
|
-
if (!setupOnly)
|
|
2455
|
-
const tool = getAiTool(config);
|
|
2456
|
-
console.log(`Starting ${tool.cmd}...`);
|
|
2457
|
-
launchAi(result.launchDir, tool, { unsafe, initialPrompt }, result.port);
|
|
2458
|
-
}
|
|
2537
|
+
if (!setupOnly) launchTool(result.launchDir, result.port);
|
|
2459
2538
|
}
|
|
2460
2539
|
};
|
|
2461
2540
|
|
|
@@ -2514,7 +2593,7 @@ var removeCommand = {
|
|
|
2514
2593
|
|
|
2515
2594
|
// src/commands/list.ts
|
|
2516
2595
|
import fs15 from "fs";
|
|
2517
|
-
import
|
|
2596
|
+
import path14 from "path";
|
|
2518
2597
|
import chalk8 from "chalk";
|
|
2519
2598
|
var listCommand = {
|
|
2520
2599
|
command: "list [target]",
|
|
@@ -2582,7 +2661,7 @@ var listCommand = {
|
|
|
2582
2661
|
}
|
|
2583
2662
|
}
|
|
2584
2663
|
for (const groupName of showGroups) {
|
|
2585
|
-
const groupDir =
|
|
2664
|
+
const groupDir = path14.join(worktreesRoot, groupName);
|
|
2586
2665
|
if (!fs15.existsSync(groupDir)) continue;
|
|
2587
2666
|
let branchDirs;
|
|
2588
2667
|
try {
|
|
@@ -2600,12 +2679,12 @@ var listCommand = {
|
|
|
2600
2679
|
);
|
|
2601
2680
|
const repoAliases = config.groups[groupName] ?? [];
|
|
2602
2681
|
for (const bdName of branchDirs) {
|
|
2603
|
-
const bdPath =
|
|
2682
|
+
const bdPath = path14.join(groupDir, bdName);
|
|
2604
2683
|
let actualBranch = null;
|
|
2605
2684
|
for (const alias of repoAliases) {
|
|
2606
2685
|
const repoPath = config.repos[alias];
|
|
2607
2686
|
if (!repoPath) continue;
|
|
2608
|
-
const rdPath =
|
|
2687
|
+
const rdPath = path14.join(bdPath, path14.basename(repoPath));
|
|
2609
2688
|
if (fs15.existsSync(rdPath)) {
|
|
2610
2689
|
const branch = getCurrentBranch(rdPath);
|
|
2611
2690
|
if (branch) {
|
|
@@ -2932,7 +3011,7 @@ import { checkbox } from "@inquirer/prompts";
|
|
|
2932
3011
|
|
|
2933
3012
|
// src/core/prunable-scan.ts
|
|
2934
3013
|
import fs19 from "fs";
|
|
2935
|
-
import
|
|
3014
|
+
import path15 from "path";
|
|
2936
3015
|
import chalk12 from "chalk";
|
|
2937
3016
|
function collectPrunable(config, options = {}) {
|
|
2938
3017
|
const { fetch: fetch2 = true, print = true, includeSquash = false } = options;
|
|
@@ -2949,7 +3028,7 @@ function collectPrunable(config, options = {}) {
|
|
|
2949
3028
|
}
|
|
2950
3029
|
const groupCoveredKeys = /* @__PURE__ */ new Set();
|
|
2951
3030
|
for (const [groupName, aliases] of Object.entries(config.groups)) {
|
|
2952
|
-
const groupDir =
|
|
3031
|
+
const groupDir = path15.join(config.worktreesRoot, groupName);
|
|
2953
3032
|
if (!fs19.existsSync(groupDir)) continue;
|
|
2954
3033
|
let branchDirs;
|
|
2955
3034
|
try {
|
|
@@ -2958,7 +3037,7 @@ function collectPrunable(config, options = {}) {
|
|
|
2958
3037
|
continue;
|
|
2959
3038
|
}
|
|
2960
3039
|
for (const branchDir of branchDirs) {
|
|
2961
|
-
const branchDirPath =
|
|
3040
|
+
const branchDirPath = path15.join(groupDir, branchDir);
|
|
2962
3041
|
let branch;
|
|
2963
3042
|
let allMerged = true;
|
|
2964
3043
|
let groupHasChanges = false;
|
|
@@ -2972,8 +3051,8 @@ function collectPrunable(config, options = {}) {
|
|
|
2972
3051
|
skipped = true;
|
|
2973
3052
|
continue;
|
|
2974
3053
|
}
|
|
2975
|
-
const repoName =
|
|
2976
|
-
const subWorktreePath =
|
|
3054
|
+
const repoName = path15.basename(repoPath);
|
|
3055
|
+
const subWorktreePath = path15.join(branchDirPath, repoName);
|
|
2977
3056
|
if (!fs19.existsSync(subWorktreePath)) {
|
|
2978
3057
|
continue;
|
|
2979
3058
|
}
|
|
@@ -3090,7 +3169,7 @@ async function removeSingleEntry(entry, force = true) {
|
|
|
3090
3169
|
}
|
|
3091
3170
|
async function removeGroupEntry(entry, config, force = true) {
|
|
3092
3171
|
const workTreeDirName = entry.branch.replace(/\//g, "-");
|
|
3093
|
-
const groupWorktreePath =
|
|
3172
|
+
const groupWorktreePath = path15.join(
|
|
3094
3173
|
config.worktreesRoot,
|
|
3095
3174
|
entry.target,
|
|
3096
3175
|
workTreeDirName
|
|
@@ -3100,7 +3179,7 @@ async function removeGroupEntry(entry, config, force = true) {
|
|
|
3100
3179
|
);
|
|
3101
3180
|
let allRemoved = true;
|
|
3102
3181
|
for (const { alias, repoPath, worktreePath } of entry.repos) {
|
|
3103
|
-
const repoName =
|
|
3182
|
+
const repoName = path15.basename(repoPath);
|
|
3104
3183
|
console.log(chalk12.cyan(` [${alias}] (${repoName}):`));
|
|
3105
3184
|
const removed = removeSingleWorktree(repoPath, worktreePath, entry.branch, force);
|
|
3106
3185
|
if (!removed) {
|
|
@@ -3110,7 +3189,7 @@ async function removeGroupEntry(entry, config, force = true) {
|
|
|
3110
3189
|
if (allRemoved) {
|
|
3111
3190
|
await removeSession(entry.target, entry.branch);
|
|
3112
3191
|
}
|
|
3113
|
-
const claudeMdInWorktree =
|
|
3192
|
+
const claudeMdInWorktree = path15.join(groupWorktreePath, "CLAUDE.md");
|
|
3114
3193
|
if (fs19.existsSync(claudeMdInWorktree)) {
|
|
3115
3194
|
fs19.unlinkSync(claudeMdInWorktree);
|
|
3116
3195
|
}
|
|
@@ -3336,7 +3415,7 @@ var syncCommand = {
|
|
|
3336
3415
|
|
|
3337
3416
|
// src/tui-ink/index.tsx
|
|
3338
3417
|
import fs24 from "fs";
|
|
3339
|
-
import
|
|
3418
|
+
import path20 from "path";
|
|
3340
3419
|
import { render } from "ink";
|
|
3341
3420
|
|
|
3342
3421
|
// src/tui-ink/App.tsx
|
|
@@ -3344,7 +3423,7 @@ import { useState, useEffect, useRef, useCallback, useMemo } from "react";
|
|
|
3344
3423
|
import { Box as Box5 } from "ink";
|
|
3345
3424
|
import fs23 from "fs";
|
|
3346
3425
|
import os6 from "os";
|
|
3347
|
-
import
|
|
3426
|
+
import path19 from "path";
|
|
3348
3427
|
import { execFile as execFile4 } from "child_process";
|
|
3349
3428
|
import spawn7 from "cross-spawn";
|
|
3350
3429
|
|
|
@@ -3558,10 +3637,10 @@ async function fetchJiraPane() {
|
|
|
3558
3637
|
|
|
3559
3638
|
// src/core/tasks.ts
|
|
3560
3639
|
import fs21 from "fs";
|
|
3561
|
-
import
|
|
3640
|
+
import path16 from "path";
|
|
3562
3641
|
var EMPTY_STORE = { nextId: 1, tasks: [] };
|
|
3563
3642
|
function getTasksPath() {
|
|
3564
|
-
return
|
|
3643
|
+
return path16.join(getConfigDir(), "tasks.json");
|
|
3565
3644
|
}
|
|
3566
3645
|
function loadStore() {
|
|
3567
3646
|
const p = getTasksPath();
|
|
@@ -3810,30 +3889,33 @@ var PtySession = class {
|
|
|
3810
3889
|
|
|
3811
3890
|
// src/core/hook-server.ts
|
|
3812
3891
|
import http from "http";
|
|
3813
|
-
import
|
|
3892
|
+
import path18 from "path";
|
|
3814
3893
|
|
|
3815
3894
|
// src/core/settings-editor.ts
|
|
3816
3895
|
import fs22 from "fs";
|
|
3817
|
-
import
|
|
3896
|
+
import path17 from "path";
|
|
3818
3897
|
import os5 from "os";
|
|
3819
|
-
|
|
3898
|
+
function settingsPath() {
|
|
3899
|
+
return path17.join(os5.homedir(), ".claude", "settings.json");
|
|
3900
|
+
}
|
|
3820
3901
|
var OWNER_TAG = "_workHookOwner";
|
|
3821
3902
|
var PID_TAG = "_workHookPid";
|
|
3822
3903
|
var LEGACY_TAGS = ["_workDash", "_work2Dash"];
|
|
3823
3904
|
function readSettings() {
|
|
3824
3905
|
try {
|
|
3825
|
-
|
|
3826
|
-
|
|
3906
|
+
const p = settingsPath();
|
|
3907
|
+
if (!fs22.existsSync(p)) return {};
|
|
3908
|
+
return JSON.parse(fs22.readFileSync(p, "utf8"));
|
|
3827
3909
|
} catch {
|
|
3828
3910
|
return {};
|
|
3829
3911
|
}
|
|
3830
3912
|
}
|
|
3831
3913
|
function writeAtomic(s) {
|
|
3832
3914
|
try {
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3915
|
+
const target = resolveLinkTarget(settingsPath());
|
|
3916
|
+
fs22.mkdirSync(path17.dirname(target), { recursive: true });
|
|
3917
|
+
atomicWriteFile(target, `${JSON.stringify(s, null, 2)}
|
|
3918
|
+
`);
|
|
3837
3919
|
} catch {
|
|
3838
3920
|
}
|
|
3839
3921
|
}
|
|
@@ -4005,7 +4087,7 @@ function removeHttpHooksSync(owner) {
|
|
|
4005
4087
|
editSettingsSync(mutateRemove(owner));
|
|
4006
4088
|
}
|
|
4007
4089
|
function normalizePath(p) {
|
|
4008
|
-
return
|
|
4090
|
+
return path18.resolve(p).toLowerCase();
|
|
4009
4091
|
}
|
|
4010
4092
|
|
|
4011
4093
|
// src/core/notifier.ts
|
|
@@ -5082,20 +5164,8 @@ var DETACH_KEY = "";
|
|
|
5082
5164
|
var TAB_KEY = " ";
|
|
5083
5165
|
var RENDER_INTERVAL_MS = 50;
|
|
5084
5166
|
var MOUSE_SGR_RE = /\x1b\[<(\d+);(\d+);(\d+)[Mm]/;
|
|
5085
|
-
function hasClaudeConversation(dir) {
|
|
5086
|
-
try {
|
|
5087
|
-
const resolved = path18.resolve(dir);
|
|
5088
|
-
const projectDir = resolved.replace(/[^a-zA-Z0-9-]/g, "-");
|
|
5089
|
-
const claudeProjectPath = path18.join(os6.homedir(), ".claude", "projects", projectDir);
|
|
5090
|
-
if (!fs23.existsSync(claudeProjectPath)) return false;
|
|
5091
|
-
const files = fs23.readdirSync(claudeProjectPath);
|
|
5092
|
-
return files.some((f) => f.endsWith(".jsonl"));
|
|
5093
|
-
} catch {
|
|
5094
|
-
return false;
|
|
5095
|
-
}
|
|
5096
|
-
}
|
|
5097
5167
|
function ptyDedupKey(pty2) {
|
|
5098
|
-
return
|
|
5168
|
+
return path19.resolve(pty2.cwd).toLowerCase();
|
|
5099
5169
|
}
|
|
5100
5170
|
function loadSessions() {
|
|
5101
5171
|
const all = loadHistory();
|
|
@@ -5130,7 +5200,13 @@ function generateSlug(summary) {
|
|
|
5130
5200
|
const child = execFile4(
|
|
5131
5201
|
"claude",
|
|
5132
5202
|
["-p", "--model", "haiku"],
|
|
5133
|
-
{
|
|
5203
|
+
{
|
|
5204
|
+
encoding: "utf-8",
|
|
5205
|
+
timeout: 1e4,
|
|
5206
|
+
windowsHide: true,
|
|
5207
|
+
// Internal call — don't trip work's checkpoint hooks (see internal-claude.ts).
|
|
5208
|
+
env: { ...process.env, ...internalClaudeEnv() }
|
|
5209
|
+
},
|
|
5134
5210
|
(err, stdout) => {
|
|
5135
5211
|
const result = stdout?.trim().toLowerCase().replace(/[^a-z0-9-]/g, "").replace(/^-|-$/g, "");
|
|
5136
5212
|
resolve(result || fallback);
|
|
@@ -5389,10 +5465,10 @@ function App({ unsafe, onExit }) {
|
|
|
5389
5465
|
}
|
|
5390
5466
|
}, [setScrollBack, renderTermAtScroll]);
|
|
5391
5467
|
const findPtyByCwd = useCallback((cwd) => {
|
|
5392
|
-
const normalized =
|
|
5468
|
+
const normalized = path19.resolve(cwd).toLowerCase();
|
|
5393
5469
|
for (const pty2 of ptySessions.current.values()) {
|
|
5394
5470
|
if (pty2.exited) continue;
|
|
5395
|
-
if (normalized.startsWith(
|
|
5471
|
+
if (normalized.startsWith(path19.resolve(pty2.cwd).toLowerCase())) return pty2;
|
|
5396
5472
|
}
|
|
5397
5473
|
return void 0;
|
|
5398
5474
|
}, []);
|
|
@@ -5468,13 +5544,13 @@ function App({ unsafe, onExit }) {
|
|
|
5468
5544
|
notifiedSessionsRef.current
|
|
5469
5545
|
);
|
|
5470
5546
|
if (kind) {
|
|
5471
|
-
notifyDesktop(
|
|
5547
|
+
notifyDesktop(path19.basename(pty2.cwd), kind, {
|
|
5472
5548
|
enabled: config?.notifications === true
|
|
5473
5549
|
});
|
|
5474
5550
|
runStatusHooks(
|
|
5475
5551
|
kind,
|
|
5476
5552
|
pty2.cwd,
|
|
5477
|
-
|
|
5553
|
+
path19.basename(pty2.cwd),
|
|
5478
5554
|
config?.statusHooks
|
|
5479
5555
|
);
|
|
5480
5556
|
}
|
|
@@ -5607,7 +5683,7 @@ function App({ unsafe, onExit }) {
|
|
|
5607
5683
|
refreshSessions();
|
|
5608
5684
|
return;
|
|
5609
5685
|
}
|
|
5610
|
-
const dir = s.isGroup ?
|
|
5686
|
+
const dir = s.isGroup ? path19.dirname(existing) : existing;
|
|
5611
5687
|
const resume = hasClaudeConversation(dir);
|
|
5612
5688
|
const tool = getAiTool(config ?? {});
|
|
5613
5689
|
const pty2 = new PtySession(dir, termInner, contentHeight - 2, void 0, { tool, unsafe, resume, port: s.port });
|
|
@@ -5705,7 +5781,7 @@ function App({ unsafe, onExit }) {
|
|
|
5705
5781
|
"",
|
|
5706
5782
|
" - Ask if I want to proceed with the recommended approach, choose a different one, get more details, or make adjustments."
|
|
5707
5783
|
].join("\n");
|
|
5708
|
-
promptFile =
|
|
5784
|
+
promptFile = path19.join(os6.tmpdir(), `work-prompt-${Date.now()}.txt`);
|
|
5709
5785
|
fs23.writeFileSync(promptFile, prompt, "utf-8");
|
|
5710
5786
|
}
|
|
5711
5787
|
const setupArgs = ["tree", projectName, branchName, "--setup-only"];
|
|
@@ -5745,7 +5821,7 @@ function App({ unsafe, onExit }) {
|
|
|
5745
5821
|
setStatusVersion((v) => v + 1);
|
|
5746
5822
|
return;
|
|
5747
5823
|
}
|
|
5748
|
-
const launchDir = session.isGroup ?
|
|
5824
|
+
const launchDir = session.isGroup ? path19.dirname(existing) : existing;
|
|
5749
5825
|
const tool = getAiTool(config);
|
|
5750
5826
|
const aiPty = new PtySession(
|
|
5751
5827
|
launchDir,
|
|
@@ -6320,7 +6396,7 @@ function App({ unsafe, onExit }) {
|
|
|
6320
6396
|
setMessage("Session path no longer exists");
|
|
6321
6397
|
return;
|
|
6322
6398
|
}
|
|
6323
|
-
const dir = s.isGroup ?
|
|
6399
|
+
const dir = s.isGroup ? path19.dirname(existing) : existing;
|
|
6324
6400
|
const editor = config?.editor ?? "code";
|
|
6325
6401
|
spawn7(editor, [dir], { detached: true, stdio: "ignore" }).unref();
|
|
6326
6402
|
setMessage(`Opened in ${editor}: ${s.branch}`);
|
|
@@ -6505,7 +6581,7 @@ function crashLog(label2, err) {
|
|
|
6505
6581
|
const msg = err instanceof Error ? err.stack || err.message : String(err);
|
|
6506
6582
|
const line = `${(/* @__PURE__ */ new Date()).toISOString()} [CRASH] ${label2}: ${msg}
|
|
6507
6583
|
`;
|
|
6508
|
-
fs24.appendFileSync(
|
|
6584
|
+
fs24.appendFileSync(path20.join(getConfigDir(), "debug.log"), line);
|
|
6509
6585
|
} catch {
|
|
6510
6586
|
}
|
|
6511
6587
|
}
|
|
@@ -6829,22 +6905,22 @@ import chalk17 from "chalk";
|
|
|
6829
6905
|
|
|
6830
6906
|
// src/core/hydrate.ts
|
|
6831
6907
|
import fs25 from "fs";
|
|
6832
|
-
import
|
|
6908
|
+
import path21 from "path";
|
|
6833
6909
|
async function hydrateHistoryFromDisk(config) {
|
|
6834
|
-
const worktreesRoot =
|
|
6910
|
+
const worktreesRoot = path21.resolve(config.worktreesRoot);
|
|
6835
6911
|
const folderNameToAlias = /* @__PURE__ */ new Map();
|
|
6836
6912
|
for (const [alias, repoPath] of Object.entries(config.repos)) {
|
|
6837
|
-
folderNameToAlias.set(
|
|
6913
|
+
folderNameToAlias.set(path21.basename(repoPath), alias);
|
|
6838
6914
|
}
|
|
6839
6915
|
const discovered = /* @__PURE__ */ new Map();
|
|
6840
6916
|
for (const [alias, repoPath] of Object.entries(config.repos)) {
|
|
6841
6917
|
if (!fs25.existsSync(repoPath)) continue;
|
|
6842
6918
|
for (const entry of parseWorktreeList(repoPath)) {
|
|
6843
6919
|
if (!entry.branch) continue;
|
|
6844
|
-
if (
|
|
6845
|
-
const rel =
|
|
6846
|
-
if (!rel || rel.startsWith("..") ||
|
|
6847
|
-
const parts = rel.split(
|
|
6920
|
+
if (path21.resolve(entry.path) === path21.resolve(repoPath)) continue;
|
|
6921
|
+
const rel = path21.relative(worktreesRoot, entry.path);
|
|
6922
|
+
if (!rel || rel.startsWith("..") || path21.isAbsolute(rel)) continue;
|
|
6923
|
+
const parts = rel.split(path21.sep).filter(Boolean);
|
|
6848
6924
|
if (parts.length < 2) continue;
|
|
6849
6925
|
const [first, second] = parts;
|
|
6850
6926
|
const isGroup = Object.prototype.hasOwnProperty.call(config.groups, first);
|
|
@@ -6929,13 +7005,13 @@ var hydrateCommand = {
|
|
|
6929
7005
|
// src/commands/diff.ts
|
|
6930
7006
|
import fs36 from "fs";
|
|
6931
7007
|
import os9 from "os";
|
|
6932
|
-
import
|
|
7008
|
+
import path32 from "path";
|
|
6933
7009
|
import { spawn as childSpawn } from "child_process";
|
|
6934
7010
|
import chalk21 from "chalk";
|
|
6935
7011
|
|
|
6936
7012
|
// src/core/diff-pipeline.ts
|
|
6937
7013
|
import fs28 from "fs";
|
|
6938
|
-
import
|
|
7014
|
+
import path24 from "path";
|
|
6939
7015
|
import spawn9 from "cross-spawn";
|
|
6940
7016
|
|
|
6941
7017
|
// src/core/diff-parse.ts
|
|
@@ -7084,7 +7160,7 @@ function stripPathPrefix(p) {
|
|
|
7084
7160
|
|
|
7085
7161
|
// src/core/lcov.ts
|
|
7086
7162
|
import fs26 from "fs";
|
|
7087
|
-
import
|
|
7163
|
+
import path22 from "path";
|
|
7088
7164
|
function parseLcov(content) {
|
|
7089
7165
|
const result = /* @__PURE__ */ new Map();
|
|
7090
7166
|
let sf = null;
|
|
@@ -7143,8 +7219,8 @@ function parseLcov(content) {
|
|
|
7143
7219
|
}
|
|
7144
7220
|
function findLcov(root) {
|
|
7145
7221
|
const candidates = [
|
|
7146
|
-
|
|
7147
|
-
|
|
7222
|
+
path22.join(root, "coverage", "lcov.info"),
|
|
7223
|
+
path22.join(root, "lcov.info")
|
|
7148
7224
|
];
|
|
7149
7225
|
for (const c of candidates) {
|
|
7150
7226
|
try {
|
|
@@ -7179,33 +7255,33 @@ function readParsedLcov(lcovPath) {
|
|
|
7179
7255
|
return { parsed, mtimeMs };
|
|
7180
7256
|
}
|
|
7181
7257
|
function normRel(p) {
|
|
7182
|
-
return
|
|
7258
|
+
return path22.normalize(p).replace(/\\/g, "/").replace(/^\.\//, "");
|
|
7183
7259
|
}
|
|
7184
7260
|
function realRoot(root) {
|
|
7185
7261
|
try {
|
|
7186
|
-
return fs26.realpathSync(
|
|
7262
|
+
return fs26.realpathSync(path22.resolve(root));
|
|
7187
7263
|
} catch {
|
|
7188
|
-
return
|
|
7264
|
+
return path22.resolve(root);
|
|
7189
7265
|
}
|
|
7190
7266
|
}
|
|
7191
7267
|
function canonicalize(absPath) {
|
|
7192
|
-
const resolved =
|
|
7268
|
+
const resolved = path22.resolve(absPath);
|
|
7193
7269
|
let dir = resolved;
|
|
7194
7270
|
const tail = [];
|
|
7195
7271
|
for (; ; ) {
|
|
7196
7272
|
try {
|
|
7197
7273
|
const realDir = fs26.realpathSync(dir);
|
|
7198
|
-
return tail.length ?
|
|
7274
|
+
return tail.length ? path22.join(realDir, ...tail.reverse()) : realDir;
|
|
7199
7275
|
} catch {
|
|
7200
|
-
const parent =
|
|
7276
|
+
const parent = path22.dirname(dir);
|
|
7201
7277
|
if (parent === dir) return resolved;
|
|
7202
|
-
tail.push(
|
|
7278
|
+
tail.push(path22.basename(dir));
|
|
7203
7279
|
dir = parent;
|
|
7204
7280
|
}
|
|
7205
7281
|
}
|
|
7206
7282
|
}
|
|
7207
7283
|
function relForAbsSf(absSf, canonRoot) {
|
|
7208
|
-
return
|
|
7284
|
+
return path22.relative(canonRoot, canonicalize(absSf));
|
|
7209
7285
|
}
|
|
7210
7286
|
function coverageLookup(root, relPaths) {
|
|
7211
7287
|
const out = /* @__PURE__ */ new Map();
|
|
@@ -7218,7 +7294,7 @@ function coverageLookup(root, relPaths) {
|
|
|
7218
7294
|
const canonRoot = realRoot(root);
|
|
7219
7295
|
const byRel = /* @__PURE__ */ new Map();
|
|
7220
7296
|
for (const [sf, pct] of read.parsed) {
|
|
7221
|
-
const rel =
|
|
7297
|
+
const rel = path22.isAbsolute(sf) ? relForAbsSf(sf, canonRoot) : sf;
|
|
7222
7298
|
byRel.set(normRel(rel), pct);
|
|
7223
7299
|
}
|
|
7224
7300
|
for (const rp of relPaths) {
|
|
@@ -7231,12 +7307,12 @@ function coverageLookup(root, relPaths) {
|
|
|
7231
7307
|
// src/core/git-tree-snapshot.ts
|
|
7232
7308
|
import fs27 from "fs";
|
|
7233
7309
|
import os7 from "os";
|
|
7234
|
-
import
|
|
7310
|
+
import path23 from "path";
|
|
7235
7311
|
import crypto from "crypto";
|
|
7236
7312
|
import spawn8 from "cross-spawn";
|
|
7237
7313
|
function writeTempTree(repoRoot, opts = {}) {
|
|
7238
7314
|
const includeWorkingTree = opts.includeWorkingTree ?? true;
|
|
7239
|
-
const tmpIndex =
|
|
7315
|
+
const tmpIndex = path23.join(
|
|
7240
7316
|
os7.tmpdir(),
|
|
7241
7317
|
`wd-tree-${process.pid}-${crypto.randomBytes(6).toString("hex")}.idx`
|
|
7242
7318
|
);
|
|
@@ -7281,12 +7357,12 @@ function isMarkdownPath(p) {
|
|
|
7281
7357
|
return p !== "/dev/null" && MARKDOWN_EXT_RE.test(p);
|
|
7282
7358
|
}
|
|
7283
7359
|
function isInsideRoot(root, rel) {
|
|
7284
|
-
const resolvedRoot =
|
|
7285
|
-
const resolvedTarget =
|
|
7286
|
-
const r =
|
|
7360
|
+
const resolvedRoot = path24.resolve(root);
|
|
7361
|
+
const resolvedTarget = path24.resolve(resolvedRoot, rel);
|
|
7362
|
+
const r = path24.relative(resolvedRoot, resolvedTarget);
|
|
7287
7363
|
if (r === "") return true;
|
|
7288
7364
|
if (r.startsWith("..")) return false;
|
|
7289
|
-
if (
|
|
7365
|
+
if (path24.isAbsolute(r)) return false;
|
|
7290
7366
|
return true;
|
|
7291
7367
|
}
|
|
7292
7368
|
function readMarkdownContent(root, file, fromRef, toRef) {
|
|
@@ -7311,10 +7387,10 @@ function readMarkdownContent(root, file, fromRef, toRef) {
|
|
|
7311
7387
|
if (file.status !== "deleted" && isMarkdownPath(file.newPath) && isInsideRoot(root, file.newPath)) {
|
|
7312
7388
|
if (toRef === "working") {
|
|
7313
7389
|
try {
|
|
7314
|
-
const absPath =
|
|
7315
|
-
const realRoot2 = fs28.realpathSync(
|
|
7390
|
+
const absPath = path24.join(root, file.newPath);
|
|
7391
|
+
const realRoot2 = fs28.realpathSync(path24.resolve(root));
|
|
7316
7392
|
const realPath = fs28.realpathSync(absPath);
|
|
7317
|
-
const sep =
|
|
7393
|
+
const sep = path24.sep;
|
|
7318
7394
|
if (realPath === realRoot2 || realPath.startsWith(realRoot2 + sep)) {
|
|
7319
7395
|
result.after = fs28.readFileSync(absPath, "utf-8");
|
|
7320
7396
|
}
|
|
@@ -7344,7 +7420,7 @@ function isBinaryContent(buffer) {
|
|
|
7344
7420
|
return false;
|
|
7345
7421
|
}
|
|
7346
7422
|
function synthesizeUntrackedDiff(root, relPath) {
|
|
7347
|
-
const absPath =
|
|
7423
|
+
const absPath = path24.join(root, relPath);
|
|
7348
7424
|
let buffer;
|
|
7349
7425
|
try {
|
|
7350
7426
|
buffer = fs28.readFileSync(absPath);
|
|
@@ -7435,7 +7511,7 @@ function attachCoverage(root, files) {
|
|
|
7435
7511
|
f.coverageMtimeMs = lcovMtimeMs;
|
|
7436
7512
|
let srcMtimeMs = null;
|
|
7437
7513
|
try {
|
|
7438
|
-
srcMtimeMs = fs28.statSync(
|
|
7514
|
+
srcMtimeMs = fs28.statSync(path24.join(root, f.path)).mtimeMs;
|
|
7439
7515
|
} catch {
|
|
7440
7516
|
srcMtimeMs = null;
|
|
7441
7517
|
}
|
|
@@ -7503,7 +7579,7 @@ function computeRangeDiff(opts) {
|
|
|
7503
7579
|
|
|
7504
7580
|
// src/core/repo-spec.ts
|
|
7505
7581
|
import fs29 from "fs";
|
|
7506
|
-
import
|
|
7582
|
+
import path25 from "path";
|
|
7507
7583
|
import os8 from "os";
|
|
7508
7584
|
import crypto2 from "crypto";
|
|
7509
7585
|
function scopeHashFor(keyPaths) {
|
|
@@ -7511,17 +7587,17 @@ function scopeHashFor(keyPaths) {
|
|
|
7511
7587
|
return crypto2.createHash("sha1").update(key).digest("hex").slice(0, 12);
|
|
7512
7588
|
}
|
|
7513
7589
|
function stableDiffPath(keyPaths) {
|
|
7514
|
-
const dir =
|
|
7590
|
+
const dir = path25.join(os8.homedir(), ".work", "diffs");
|
|
7515
7591
|
fs29.mkdirSync(dir, { recursive: true });
|
|
7516
|
-
return
|
|
7592
|
+
return path25.join(dir, scopeHashFor(keyPaths));
|
|
7517
7593
|
}
|
|
7518
7594
|
|
|
7519
7595
|
// src/core/diff-scope.ts
|
|
7520
7596
|
import fs30 from "fs";
|
|
7521
|
-
import
|
|
7597
|
+
import path26 from "path";
|
|
7522
7598
|
import chalk18 from "chalk";
|
|
7523
7599
|
function normPath(p) {
|
|
7524
|
-
return
|
|
7600
|
+
return path26.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
7525
7601
|
}
|
|
7526
7602
|
function realNorm(p) {
|
|
7527
7603
|
try {
|
|
@@ -7545,29 +7621,29 @@ function resolveScope(cwd) {
|
|
|
7545
7621
|
return {
|
|
7546
7622
|
isGroup: true,
|
|
7547
7623
|
session: s,
|
|
7548
|
-
repos: s.paths.map((rp) => ({ name:
|
|
7549
|
-
activeRepoName:
|
|
7624
|
+
repos: s.paths.map((rp) => ({ name: path26.basename(rp), root: rp })),
|
|
7625
|
+
activeRepoName: path26.basename(p)
|
|
7550
7626
|
};
|
|
7551
7627
|
}
|
|
7552
7628
|
return {
|
|
7553
7629
|
isGroup: false,
|
|
7554
7630
|
session: s,
|
|
7555
|
-
repos: [{ name:
|
|
7556
|
-
activeRepoName:
|
|
7631
|
+
repos: [{ name: path26.basename(p), root: p }],
|
|
7632
|
+
activeRepoName: path26.basename(p)
|
|
7557
7633
|
};
|
|
7558
7634
|
}
|
|
7559
7635
|
}
|
|
7560
7636
|
}
|
|
7561
7637
|
for (const s of sessions) {
|
|
7562
7638
|
if (!s.isGroup || s.paths.length === 0) continue;
|
|
7563
|
-
const parents = s.paths.map((p) => normPath(
|
|
7639
|
+
const parents = s.paths.map((p) => normPath(path26.dirname(p)));
|
|
7564
7640
|
const groupRoot = parents[0];
|
|
7565
7641
|
if (!parents.every((par) => par === groupRoot)) continue;
|
|
7566
7642
|
if (normCwd === groupRoot || normCwd.startsWith(groupRoot + "/")) {
|
|
7567
7643
|
return {
|
|
7568
7644
|
isGroup: true,
|
|
7569
7645
|
session: s,
|
|
7570
|
-
repos: s.paths.map((rp) => ({ name:
|
|
7646
|
+
repos: s.paths.map((rp) => ({ name: path26.basename(rp), root: rp })),
|
|
7571
7647
|
activeRepoName: null
|
|
7572
7648
|
};
|
|
7573
7649
|
}
|
|
@@ -7576,8 +7652,8 @@ function resolveScope(cwd) {
|
|
|
7576
7652
|
return {
|
|
7577
7653
|
isGroup: false,
|
|
7578
7654
|
session: null,
|
|
7579
|
-
repos: [{ name:
|
|
7580
|
-
activeRepoName:
|
|
7655
|
+
repos: [{ name: path26.basename(toplevel), root: toplevel }],
|
|
7656
|
+
activeRepoName: path26.basename(toplevel)
|
|
7581
7657
|
};
|
|
7582
7658
|
}
|
|
7583
7659
|
function findAnyParentBranch(cwd) {
|
|
@@ -7761,7 +7837,7 @@ import { streamSSE } from "hono/streaming";
|
|
|
7761
7837
|
|
|
7762
7838
|
// src/core/file-context.ts
|
|
7763
7839
|
import fs31 from "fs";
|
|
7764
|
-
import
|
|
7840
|
+
import path27 from "path";
|
|
7765
7841
|
import spawn10 from "cross-spawn";
|
|
7766
7842
|
function readContextLines(opts) {
|
|
7767
7843
|
const { root, relPath, ref } = opts;
|
|
@@ -7783,10 +7859,10 @@ function readContextLines(opts) {
|
|
|
7783
7859
|
}
|
|
7784
7860
|
function readWorkingTree(root, relPath) {
|
|
7785
7861
|
try {
|
|
7786
|
-
const absPath =
|
|
7787
|
-
const realRoot2 = fs31.realpathSync(
|
|
7862
|
+
const absPath = path27.join(root, relPath);
|
|
7863
|
+
const realRoot2 = fs31.realpathSync(path27.resolve(root));
|
|
7788
7864
|
const realPath = fs31.realpathSync(absPath);
|
|
7789
|
-
const sep =
|
|
7865
|
+
const sep = path27.sep;
|
|
7790
7866
|
if (realPath !== realRoot2 && !realPath.startsWith(realRoot2 + sep)) {
|
|
7791
7867
|
return null;
|
|
7792
7868
|
}
|
|
@@ -7808,7 +7884,7 @@ function readAtRef(root, ref, relPath) {
|
|
|
7808
7884
|
|
|
7809
7885
|
// src/core/fs-watcher.ts
|
|
7810
7886
|
import fs32 from "fs";
|
|
7811
|
-
import
|
|
7887
|
+
import path28 from "path";
|
|
7812
7888
|
import chalk19 from "chalk";
|
|
7813
7889
|
import chokidar from "chokidar";
|
|
7814
7890
|
var IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
@@ -7834,7 +7910,7 @@ var IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
|
7834
7910
|
]);
|
|
7835
7911
|
function isIgnoredWatchPath(roots, filePath) {
|
|
7836
7912
|
for (const root of roots) {
|
|
7837
|
-
const rel =
|
|
7913
|
+
const rel = path28.relative(root, filePath).replace(/\\/g, "/");
|
|
7838
7914
|
if (rel === "" || rel.startsWith("../")) continue;
|
|
7839
7915
|
if (rel.split("/").some((seg) => IGNORED_DIRS.has(seg))) return true;
|
|
7840
7916
|
}
|
|
@@ -7859,7 +7935,7 @@ function createFsWatcher(opts) {
|
|
|
7859
7935
|
if (SUPPORTS_RECURSIVE_WATCH) {
|
|
7860
7936
|
const watchers = opts.roots.map((root) => {
|
|
7861
7937
|
const w = fs32.watch(root, { recursive: true }, (_event, filename) => {
|
|
7862
|
-
if (filename && isIgnoredWatchPath([root],
|
|
7938
|
+
if (filename && isIgnoredWatchPath([root], path28.join(root, filename.toString()))) {
|
|
7863
7939
|
return;
|
|
7864
7940
|
}
|
|
7865
7941
|
fire();
|
|
@@ -7898,29 +7974,29 @@ function createFsWatcher(opts) {
|
|
|
7898
7974
|
|
|
7899
7975
|
// src/core/web-static.ts
|
|
7900
7976
|
import fs33 from "fs";
|
|
7901
|
-
import
|
|
7977
|
+
import path29 from "path";
|
|
7902
7978
|
import { fileURLToPath } from "url";
|
|
7903
7979
|
function resolveWebRoot() {
|
|
7904
|
-
const entryDir =
|
|
7905
|
-
const moduleDir =
|
|
7980
|
+
const entryDir = path29.dirname(process.argv[1] ?? "");
|
|
7981
|
+
const moduleDir = path29.dirname(fileURLToPath(import.meta.url));
|
|
7906
7982
|
const candidates = [
|
|
7907
|
-
|
|
7983
|
+
path29.join(entryDir, "web"),
|
|
7908
7984
|
// bundled: this module is inlined into dist/<bin>.js, so dist/web is a
|
|
7909
7985
|
// sibling of the bundle. Works even when argv[1] is an npm bin symlink
|
|
7910
7986
|
// (which is not realpath'd, so the entryDir candidate above misses).
|
|
7911
|
-
|
|
7987
|
+
path29.join(moduleDir, "web"),
|
|
7912
7988
|
// dev/tsx fallback: walk up from src/core to repo root then into dist/web.
|
|
7913
|
-
|
|
7989
|
+
path29.resolve(moduleDir, "../../dist/web")
|
|
7914
7990
|
];
|
|
7915
7991
|
for (const c of candidates) {
|
|
7916
|
-
if (fs33.existsSync(
|
|
7992
|
+
if (fs33.existsSync(path29.join(c, "index.html"))) return c;
|
|
7917
7993
|
}
|
|
7918
7994
|
return null;
|
|
7919
7995
|
}
|
|
7920
7996
|
|
|
7921
7997
|
// src/core/spa-handler.ts
|
|
7922
7998
|
import fs34 from "fs";
|
|
7923
|
-
import
|
|
7999
|
+
import path30 from "path";
|
|
7924
8000
|
var MIME = {
|
|
7925
8001
|
".html": "text/html; charset=utf-8",
|
|
7926
8002
|
".js": "application/javascript; charset=utf-8",
|
|
@@ -7934,9 +8010,9 @@ var MIME = {
|
|
|
7934
8010
|
function readFile(root, relPath) {
|
|
7935
8011
|
const clean = relPath.split("?")[0];
|
|
7936
8012
|
const requested = clean === "/" ? "/index.html" : clean;
|
|
7937
|
-
const filePath =
|
|
7938
|
-
const norm =
|
|
7939
|
-
if (!norm.startsWith(
|
|
8013
|
+
const filePath = path30.join(root, requested);
|
|
8014
|
+
const norm = path30.normalize(filePath);
|
|
8015
|
+
if (!norm.startsWith(path30.normalize(root))) return null;
|
|
7940
8016
|
let stat;
|
|
7941
8017
|
try {
|
|
7942
8018
|
stat = fs34.statSync(norm);
|
|
@@ -7944,7 +8020,7 @@ function readFile(root, relPath) {
|
|
|
7944
8020
|
return null;
|
|
7945
8021
|
}
|
|
7946
8022
|
if (!stat.isFile()) return null;
|
|
7947
|
-
const ext =
|
|
8023
|
+
const ext = path30.extname(norm).toLowerCase();
|
|
7948
8024
|
return { body: fs34.readFileSync(norm), ext };
|
|
7949
8025
|
}
|
|
7950
8026
|
function serveSpa(c, webRoot) {
|
|
@@ -8254,7 +8330,7 @@ function diffReviewSnapshot(snapshot, seen) {
|
|
|
8254
8330
|
|
|
8255
8331
|
// src/core/static-renderer.ts
|
|
8256
8332
|
import fs35 from "fs";
|
|
8257
|
-
import
|
|
8333
|
+
import path31 from "path";
|
|
8258
8334
|
function buildDiff(specs, resolvedBase) {
|
|
8259
8335
|
return {
|
|
8260
8336
|
repos: specs.map((r) => ({
|
|
@@ -8270,7 +8346,7 @@ function renderStatic(opts) {
|
|
|
8270
8346
|
if (!webRoot) {
|
|
8271
8347
|
throw new Error("Could not find dist/web/. Run `npm run build` first.");
|
|
8272
8348
|
}
|
|
8273
|
-
const shellPath =
|
|
8349
|
+
const shellPath = path31.join(webRoot, "index.html");
|
|
8274
8350
|
let shell = fs35.readFileSync(shellPath, "utf-8");
|
|
8275
8351
|
const uncommitted = buildDiff(opts.uncommitted, "HEAD");
|
|
8276
8352
|
const branch = opts.branch ? buildDiff(opts.branch.specs, opts.branch.resolvedBase) : void 0;
|
|
@@ -8320,8 +8396,8 @@ function escapeForScriptTag(json) {
|
|
|
8320
8396
|
}
|
|
8321
8397
|
function readAsset(webRoot, urlPath) {
|
|
8322
8398
|
const clean = urlPath.split("?")[0].replace(/^\//, "");
|
|
8323
|
-
const full =
|
|
8324
|
-
if (!
|
|
8399
|
+
const full = path31.join(webRoot, clean);
|
|
8400
|
+
if (!path31.normalize(full).startsWith(path31.normalize(webRoot))) return null;
|
|
8325
8401
|
try {
|
|
8326
8402
|
return fs35.readFileSync(full, "utf-8");
|
|
8327
8403
|
} catch {
|
|
@@ -8364,7 +8440,7 @@ async function runStop(repoSpecs) {
|
|
|
8364
8440
|
}
|
|
8365
8441
|
}
|
|
8366
8442
|
function webUrlFilePath() {
|
|
8367
|
-
return
|
|
8443
|
+
return path32.join(os9.homedir(), ".work", "web.url");
|
|
8368
8444
|
}
|
|
8369
8445
|
function resolveWorkBinPath(selfArgv1) {
|
|
8370
8446
|
let real = selfArgv1;
|
|
@@ -8373,7 +8449,7 @@ function resolveWorkBinPath(selfArgv1) {
|
|
|
8373
8449
|
} catch {
|
|
8374
8450
|
}
|
|
8375
8451
|
if (real.endsWith("wd-bin.js")) {
|
|
8376
|
-
return
|
|
8452
|
+
return path32.join(path32.dirname(real), "bin.js");
|
|
8377
8453
|
}
|
|
8378
8454
|
return real;
|
|
8379
8455
|
}
|
|
@@ -8410,7 +8486,7 @@ async function ensureWorkWebRunning() {
|
|
|
8410
8486
|
}
|
|
8411
8487
|
const workBin = resolveWorkBinPath(process.argv[1]);
|
|
8412
8488
|
const out = fs36.openSync(
|
|
8413
|
-
|
|
8489
|
+
path32.join(os9.homedir(), ".work", "web-autostart.log"),
|
|
8414
8490
|
"a"
|
|
8415
8491
|
);
|
|
8416
8492
|
const child = childSpawn(
|
|
@@ -8752,19 +8828,19 @@ var diffCommand = {
|
|
|
8752
8828
|
// src/commands/web.ts
|
|
8753
8829
|
import fs41 from "fs";
|
|
8754
8830
|
import os13 from "os";
|
|
8755
|
-
import
|
|
8831
|
+
import path42 from "path";
|
|
8756
8832
|
import chalk23 from "chalk";
|
|
8757
8833
|
|
|
8758
8834
|
// src/core/web-server.ts
|
|
8759
8835
|
import fs40 from "fs";
|
|
8760
8836
|
import os12 from "os";
|
|
8761
|
-
import
|
|
8837
|
+
import path41 from "path";
|
|
8762
8838
|
import chalk22 from "chalk";
|
|
8763
8839
|
import { Hono as Hono3 } from "hono";
|
|
8764
8840
|
import { streamSSE as streamSSE3 } from "hono/streaming";
|
|
8765
8841
|
|
|
8766
8842
|
// src/core/web-state.ts
|
|
8767
|
-
import
|
|
8843
|
+
import path33 from "path";
|
|
8768
8844
|
import crypto4 from "crypto";
|
|
8769
8845
|
import chokidar2 from "chokidar";
|
|
8770
8846
|
function sessionIdFor(s) {
|
|
@@ -8785,7 +8861,7 @@ function subscribeSession(sessionId, onChange) {
|
|
|
8785
8861
|
const watcher = chokidar2.watch(roots, {
|
|
8786
8862
|
ignored: (filePath) => {
|
|
8787
8863
|
for (const r of roots) {
|
|
8788
|
-
const rel =
|
|
8864
|
+
const rel = path33.relative(r, filePath).replace(/\\/g, "/");
|
|
8789
8865
|
if (rel === ".git" || rel.startsWith(".git/")) return true;
|
|
8790
8866
|
}
|
|
8791
8867
|
return false;
|
|
@@ -8900,16 +8976,16 @@ function disposeAllPtys() {
|
|
|
8900
8976
|
|
|
8901
8977
|
// src/core/comment-file-store.ts
|
|
8902
8978
|
import fs37 from "fs";
|
|
8903
|
-
import
|
|
8979
|
+
import path34 from "path";
|
|
8904
8980
|
import os10 from "os";
|
|
8905
8981
|
function commentsDir() {
|
|
8906
|
-
return
|
|
8982
|
+
return path34.join(os10.homedir(), ".work", "comments");
|
|
8907
8983
|
}
|
|
8908
8984
|
function ensureDir() {
|
|
8909
8985
|
fs37.mkdirSync(commentsDir(), { recursive: true });
|
|
8910
8986
|
}
|
|
8911
8987
|
function commentsFileFor(sessionId) {
|
|
8912
|
-
return
|
|
8988
|
+
return path34.join(commentsDir(), `${sessionId}.json`);
|
|
8913
8989
|
}
|
|
8914
8990
|
function pathFor(sessionId) {
|
|
8915
8991
|
return commentsFileFor(sessionId);
|
|
@@ -9003,11 +9079,11 @@ function clearCommentStoreCache() {
|
|
|
9003
9079
|
|
|
9004
9080
|
// src/core/pending-delivery.ts
|
|
9005
9081
|
import fs38 from "fs";
|
|
9006
|
-
import
|
|
9082
|
+
import path35 from "path";
|
|
9007
9083
|
function pathFor2(sessionId) {
|
|
9008
9084
|
return {
|
|
9009
9085
|
comments: commentsFileFor(sessionId),
|
|
9010
|
-
delivered:
|
|
9086
|
+
delivered: path35.join(commentsDir(), `${sessionId}.delivered.json`)
|
|
9011
9087
|
};
|
|
9012
9088
|
}
|
|
9013
9089
|
function readJson(filePath, fallback) {
|
|
@@ -9018,13 +9094,11 @@ function readJson(filePath, fallback) {
|
|
|
9018
9094
|
}
|
|
9019
9095
|
}
|
|
9020
9096
|
function writeAtomic2(filePath, content) {
|
|
9021
|
-
fs38.mkdirSync(
|
|
9022
|
-
|
|
9023
|
-
fs38.writeFileSync(tmp, content, "utf-8");
|
|
9024
|
-
fs38.renameSync(tmp, filePath);
|
|
9097
|
+
fs38.mkdirSync(path35.dirname(filePath), { recursive: true });
|
|
9098
|
+
atomicWriteFile(filePath, content);
|
|
9025
9099
|
}
|
|
9026
9100
|
function normalize(p) {
|
|
9027
|
-
return
|
|
9101
|
+
return path35.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
9028
9102
|
}
|
|
9029
9103
|
function findSessionForCwd(cwd) {
|
|
9030
9104
|
const norm = normalize(cwd);
|
|
@@ -9055,7 +9129,7 @@ function readPendingForSession(sessionId) {
|
|
|
9055
9129
|
return comments.filter(isPendingFor(delivered));
|
|
9056
9130
|
}
|
|
9057
9131
|
function scopeStoreIdsForPaths(paths) {
|
|
9058
|
-
const resolved = paths.map((p) =>
|
|
9132
|
+
const resolved = paths.map((p) => path35.resolve(p));
|
|
9059
9133
|
const ids = /* @__PURE__ */ new Set();
|
|
9060
9134
|
ids.add(`scope-${scopeHashFor(resolved)}`);
|
|
9061
9135
|
for (const p of resolved) ids.add(`scope-${scopeHashFor([p])}`);
|
|
@@ -9393,7 +9467,7 @@ function mountPanesRoutes(app, opts) {
|
|
|
9393
9467
|
}
|
|
9394
9468
|
|
|
9395
9469
|
// src/core/worktree-routes.ts
|
|
9396
|
-
import
|
|
9470
|
+
import path36 from "path";
|
|
9397
9471
|
import { spawn as spawn11 } from "child_process";
|
|
9398
9472
|
import { zValidator as zValidator4 } from "@hono/zod-validator";
|
|
9399
9473
|
import { z as z3 } from "zod";
|
|
@@ -9517,7 +9591,7 @@ function mountWorktreeRoutes(app, opts) {
|
|
|
9517
9591
|
const id = c.req.param("id");
|
|
9518
9592
|
const session = findSession2(id);
|
|
9519
9593
|
if (!session) return c.json({ error: "unknown session" }, 404);
|
|
9520
|
-
const target = session.isGroup ?
|
|
9594
|
+
const target = session.isGroup ? path36.dirname(session.paths[0]) : session.paths[0];
|
|
9521
9595
|
try {
|
|
9522
9596
|
const cmd = process.platform === "win32" ? "code.cmd" : "code";
|
|
9523
9597
|
const child = spawn11(cmd, [target], {
|
|
@@ -9537,18 +9611,18 @@ function mountWorktreeRoutes(app, opts) {
|
|
|
9537
9611
|
import { zValidator as zValidator5 } from "@hono/zod-validator";
|
|
9538
9612
|
import { z as z4 } from "zod";
|
|
9539
9613
|
import { EventEmitter } from "events";
|
|
9540
|
-
import
|
|
9614
|
+
import path40 from "path";
|
|
9541
9615
|
import spawn14 from "cross-spawn";
|
|
9542
9616
|
|
|
9543
9617
|
// src/core/checkpoint.ts
|
|
9544
9618
|
import fs39 from "fs";
|
|
9545
9619
|
import os11 from "os";
|
|
9546
|
-
import
|
|
9620
|
+
import path37 from "path";
|
|
9547
9621
|
import spawn12 from "cross-spawn";
|
|
9548
9622
|
function manifestPath(scopeHash) {
|
|
9549
|
-
const dir =
|
|
9623
|
+
const dir = path37.join(os11.homedir(), ".work", "diffs");
|
|
9550
9624
|
fs39.mkdirSync(dir, { recursive: true });
|
|
9551
|
-
return
|
|
9625
|
+
return path37.join(dir, `${scopeHash}.checkpoints.json`);
|
|
9552
9626
|
}
|
|
9553
9627
|
function emptyManifest(scopeHash) {
|
|
9554
9628
|
return { version: 1, scopeHash, entries: [] };
|
|
@@ -9667,6 +9741,106 @@ async function takeCheckpoint(scopeHash, repos, opts = {}) {
|
|
|
9667
9741
|
return entry;
|
|
9668
9742
|
});
|
|
9669
9743
|
}
|
|
9744
|
+
async function updateCheckpoint(scopeHash, repos, id) {
|
|
9745
|
+
const file = manifestPath(scopeHash);
|
|
9746
|
+
ensureFile(file, JSON.stringify(emptyManifest(scopeHash), null, 2));
|
|
9747
|
+
return withFileLock(file, () => {
|
|
9748
|
+
const manifest = loadManifest(scopeHash);
|
|
9749
|
+
const entry = manifest.entries.find((e) => e.id === id);
|
|
9750
|
+
if (!entry) return { status: "missing" };
|
|
9751
|
+
const refName = `refs/wd/${scopeHash}/${id}`;
|
|
9752
|
+
const restoreRefs = () => {
|
|
9753
|
+
for (const repo of repos) {
|
|
9754
|
+
const old = entry.repos[repo.name] ?? null;
|
|
9755
|
+
if (old) {
|
|
9756
|
+
spawn12.sync("git", ["update-ref", refName, old], {
|
|
9757
|
+
cwd: repo.root,
|
|
9758
|
+
encoding: "utf-8",
|
|
9759
|
+
windowsHide: true
|
|
9760
|
+
});
|
|
9761
|
+
} else {
|
|
9762
|
+
spawn12.sync("git", ["update-ref", "-d", refName], {
|
|
9763
|
+
cwd: repo.root,
|
|
9764
|
+
encoding: "utf-8",
|
|
9765
|
+
windowsHide: true
|
|
9766
|
+
});
|
|
9767
|
+
}
|
|
9768
|
+
}
|
|
9769
|
+
};
|
|
9770
|
+
const captured = {};
|
|
9771
|
+
for (const repo of repos) {
|
|
9772
|
+
captured[repo.name] = snapshotRepo(repo.root, scopeHash, id, true);
|
|
9773
|
+
}
|
|
9774
|
+
if (repos.some((r) => captured[r.name] === null)) {
|
|
9775
|
+
restoreRefs();
|
|
9776
|
+
return { status: "missing" };
|
|
9777
|
+
}
|
|
9778
|
+
const treeOf = (root, commitSha) => {
|
|
9779
|
+
if (!commitSha) return null;
|
|
9780
|
+
const r = spawn12.sync("git", ["rev-parse", `${commitSha}^{tree}`], {
|
|
9781
|
+
cwd: root,
|
|
9782
|
+
encoding: "utf-8",
|
|
9783
|
+
windowsHide: true
|
|
9784
|
+
});
|
|
9785
|
+
if (r.status !== 0 || typeof r.stdout !== "string") return null;
|
|
9786
|
+
return r.stdout.trim() || null;
|
|
9787
|
+
};
|
|
9788
|
+
const unchanged = repos.every((repo) => {
|
|
9789
|
+
const curTree = treeOf(repo.root, captured[repo.name]);
|
|
9790
|
+
const prevTree = treeOf(repo.root, entry.repos[repo.name] ?? null);
|
|
9791
|
+
return curTree !== null && curTree === prevTree;
|
|
9792
|
+
});
|
|
9793
|
+
if (unchanged) {
|
|
9794
|
+
restoreRefs();
|
|
9795
|
+
return { status: "unchanged" };
|
|
9796
|
+
}
|
|
9797
|
+
entry.repos = captured;
|
|
9798
|
+
entry.ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
9799
|
+
delete entry.label;
|
|
9800
|
+
atomicWriteFile(file, JSON.stringify(manifest, null, 2));
|
|
9801
|
+
return { status: "updated", entry };
|
|
9802
|
+
});
|
|
9803
|
+
}
|
|
9804
|
+
async function resetBaseline(scopeHash, repos) {
|
|
9805
|
+
const file = manifestPath(scopeHash);
|
|
9806
|
+
ensureFile(file, JSON.stringify(emptyManifest(scopeHash), null, 2));
|
|
9807
|
+
return withFileLock(file, () => {
|
|
9808
|
+
const prevIds = loadManifest(scopeHash).entries.map((e) => e.id);
|
|
9809
|
+
const captured = {};
|
|
9810
|
+
for (const repo of repos) {
|
|
9811
|
+
captured[repo.name] = snapshotRepo(repo.root, scopeHash, 0, false);
|
|
9812
|
+
}
|
|
9813
|
+
const delRef = (id) => {
|
|
9814
|
+
for (const repo of repos) {
|
|
9815
|
+
spawn12.sync("git", ["update-ref", "-d", `refs/wd/${scopeHash}/${id}`], {
|
|
9816
|
+
cwd: repo.root,
|
|
9817
|
+
encoding: "utf-8",
|
|
9818
|
+
windowsHide: true
|
|
9819
|
+
});
|
|
9820
|
+
}
|
|
9821
|
+
};
|
|
9822
|
+
if (repos.some((r) => captured[r.name] === null)) {
|
|
9823
|
+
delRef(0);
|
|
9824
|
+
return null;
|
|
9825
|
+
}
|
|
9826
|
+
for (const id of prevIds) {
|
|
9827
|
+
if (id !== 0) delRef(id);
|
|
9828
|
+
}
|
|
9829
|
+
const entry = {
|
|
9830
|
+
id: 0,
|
|
9831
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9832
|
+
label: "Initial",
|
|
9833
|
+
repos: captured
|
|
9834
|
+
};
|
|
9835
|
+
const manifest = {
|
|
9836
|
+
version: 1,
|
|
9837
|
+
scopeHash,
|
|
9838
|
+
entries: [entry]
|
|
9839
|
+
};
|
|
9840
|
+
atomicWriteFile(file, JSON.stringify(manifest, null, 2));
|
|
9841
|
+
return entry;
|
|
9842
|
+
});
|
|
9843
|
+
}
|
|
9670
9844
|
async function setCheckpointLabel(scopeHash, id, label2) {
|
|
9671
9845
|
const file = manifestPath(scopeHash);
|
|
9672
9846
|
ensureFile(file, JSON.stringify(emptyManifest(scopeHash), null, 2));
|
|
@@ -9678,6 +9852,29 @@ async function setCheckpointLabel(scopeHash, id, label2) {
|
|
|
9678
9852
|
atomicWriteFile(file, JSON.stringify(manifest, null, 2));
|
|
9679
9853
|
});
|
|
9680
9854
|
}
|
|
9855
|
+
function headAdvancedSinceInitial(scopeHash, repos) {
|
|
9856
|
+
const manifest = loadManifest(scopeHash);
|
|
9857
|
+
const initial = manifest.entries.find((e) => e.id === 0);
|
|
9858
|
+
if (!initial) return false;
|
|
9859
|
+
const treeOf = (root, rev) => {
|
|
9860
|
+
const r = spawn12.sync("git", ["rev-parse", `${rev}^{tree}`], {
|
|
9861
|
+
cwd: root,
|
|
9862
|
+
encoding: "utf-8",
|
|
9863
|
+
windowsHide: true
|
|
9864
|
+
});
|
|
9865
|
+
if (r.status !== 0 || typeof r.stdout !== "string") return null;
|
|
9866
|
+
return r.stdout.trim() || null;
|
|
9867
|
+
};
|
|
9868
|
+
return repos.some((repo) => {
|
|
9869
|
+
const headTree = treeOf(repo.root, "HEAD");
|
|
9870
|
+
if (headTree === null) return false;
|
|
9871
|
+
const baselineSha = initial.repos[repo.name];
|
|
9872
|
+
if (!baselineSha) return true;
|
|
9873
|
+
const baselineTree = treeOf(repo.root, baselineSha);
|
|
9874
|
+
if (baselineTree === null) return false;
|
|
9875
|
+
return baselineTree !== headTree;
|
|
9876
|
+
});
|
|
9877
|
+
}
|
|
9681
9878
|
function clearCheckpoints(scopeHash, repoRoots) {
|
|
9682
9879
|
const manifest = loadManifest(scopeHash);
|
|
9683
9880
|
for (const root of repoRoots) {
|
|
@@ -9701,7 +9898,7 @@ function clearCheckpoints(scopeHash, repoRoots) {
|
|
|
9701
9898
|
|
|
9702
9899
|
// src/core/checkpoint-summary.ts
|
|
9703
9900
|
import spawn13 from "cross-spawn";
|
|
9704
|
-
import
|
|
9901
|
+
import path38 from "path";
|
|
9705
9902
|
var MAX_DIFF_CHARS = 6e3;
|
|
9706
9903
|
var MAX_LABEL_CHARS = 80;
|
|
9707
9904
|
function buildDelta(scopeHash, repos, id) {
|
|
@@ -9754,7 +9951,7 @@ function buildDelta(scopeHash, repos, id) {
|
|
|
9754
9951
|
function heuristicLabel(files, added, deleted) {
|
|
9755
9952
|
if (files.length === 0) return "no changes";
|
|
9756
9953
|
if (files.length === 1) {
|
|
9757
|
-
return `${
|
|
9954
|
+
return `${path38.basename(files[0].path)} +${added} \u2212${deleted}`;
|
|
9758
9955
|
}
|
|
9759
9956
|
return `${files.length} files \xB7 +${added} \u2212${deleted}`;
|
|
9760
9957
|
}
|
|
@@ -9771,7 +9968,10 @@ function runClaude(prompt, timeoutMs = 25e3) {
|
|
|
9771
9968
|
try {
|
|
9772
9969
|
child = spawn13("claude", ["-p"], {
|
|
9773
9970
|
stdio: ["pipe", "pipe", "ignore"],
|
|
9774
|
-
windowsHide: true
|
|
9971
|
+
windowsHide: true,
|
|
9972
|
+
// Tag as internal so this naming run doesn't recursively trip work's
|
|
9973
|
+
// own UserPromptSubmit/Stop checkpoint hooks (see internal-claude.ts).
|
|
9974
|
+
env: { ...process.env, ...internalClaudeEnv() }
|
|
9775
9975
|
});
|
|
9776
9976
|
} catch {
|
|
9777
9977
|
finish(null);
|
|
@@ -9822,7 +10022,7 @@ async function summarizeCheckpoint(scopeHash, repos, id) {
|
|
|
9822
10022
|
}
|
|
9823
10023
|
|
|
9824
10024
|
// src/core/scope-manager.ts
|
|
9825
|
-
import
|
|
10025
|
+
import path39 from "path";
|
|
9826
10026
|
import crypto5 from "crypto";
|
|
9827
10027
|
var scopes = /* @__PURE__ */ new Map();
|
|
9828
10028
|
function hashFor(paths) {
|
|
@@ -9839,7 +10039,7 @@ var ScopePathRejectedError = class extends Error {
|
|
|
9839
10039
|
}
|
|
9840
10040
|
};
|
|
9841
10041
|
function normaliseForCompare(p) {
|
|
9842
|
-
return
|
|
10042
|
+
return path39.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
9843
10043
|
}
|
|
9844
10044
|
function rejectedPaths(normalised) {
|
|
9845
10045
|
const config = loadConfig();
|
|
@@ -9857,7 +10057,7 @@ function rejectedPaths(normalised) {
|
|
|
9857
10057
|
});
|
|
9858
10058
|
}
|
|
9859
10059
|
function registerScope(paths, label2) {
|
|
9860
|
-
const normalised = paths.map((p) =>
|
|
10060
|
+
const normalised = paths.map((p) => path39.resolve(p));
|
|
9861
10061
|
const rejected = rejectedPaths(normalised);
|
|
9862
10062
|
if (rejected.length > 0) throw new ScopePathRejectedError(rejected);
|
|
9863
10063
|
const hash = hashFor(normalised);
|
|
@@ -9871,7 +10071,7 @@ function registerScope(paths, label2) {
|
|
|
9871
10071
|
const scope = {
|
|
9872
10072
|
hash,
|
|
9873
10073
|
paths: normalised,
|
|
9874
|
-
label: label2 ??
|
|
10074
|
+
label: label2 ?? path39.basename(normalised[0]),
|
|
9875
10075
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9876
10076
|
ended: false
|
|
9877
10077
|
};
|
|
@@ -9967,6 +10167,8 @@ import { streamSSE as streamSSE2 } from "hono/streaming";
|
|
|
9967
10167
|
function mountScopeRoutes(app, opts) {
|
|
9968
10168
|
const checkpointWatched = /* @__PURE__ */ new Set();
|
|
9969
10169
|
const lastStatus = /* @__PURE__ */ new Map();
|
|
10170
|
+
const liveCheckpoint = /* @__PURE__ */ new Map();
|
|
10171
|
+
const summarizing = /* @__PURE__ */ new Set();
|
|
9970
10172
|
const snapshotTimers = /* @__PURE__ */ new Map();
|
|
9971
10173
|
const CHECKPOINT_SETTLE_MS = 4e3;
|
|
9972
10174
|
const CLAUDE_SESSION_MS = 5 * 6e4;
|
|
@@ -9991,6 +10193,31 @@ function mountScopeRoutes(app, opts) {
|
|
|
9991
10193
|
function scopeRepos(scopePaths) {
|
|
9992
10194
|
return scopePaths.map((p) => ({ name: p, root: p }));
|
|
9993
10195
|
}
|
|
10196
|
+
function ensureSummary(scope, id) {
|
|
10197
|
+
if (id === 0) return;
|
|
10198
|
+
const key = `${scope.hash}:${id}`;
|
|
10199
|
+
if (summarizing.has(key)) return;
|
|
10200
|
+
summarizing.add(key);
|
|
10201
|
+
summarizeCheckpoint(scope.hash, scopeRepos(scope.paths), id).then((label2) => setCheckpointLabel(scope.hash, id, label2)).then(() => {
|
|
10202
|
+
const payload = { scopeHash: scope.hash, id };
|
|
10203
|
+
opts.broadcast("checkpoints-changed", payload);
|
|
10204
|
+
scopeBus.emit("checkpoints-changed", payload);
|
|
10205
|
+
}).catch(() => {
|
|
10206
|
+
}).finally(() => summarizing.delete(key));
|
|
10207
|
+
}
|
|
10208
|
+
async function rebaselineIfHeadAdvanced(hash, paths) {
|
|
10209
|
+
const repos = scopeRepos(paths);
|
|
10210
|
+
if (!headAdvancedSinceInitial(hash, repos)) return false;
|
|
10211
|
+
liveCheckpoint.delete(hash);
|
|
10212
|
+
lastStatus.delete(hash);
|
|
10213
|
+
const entry = await resetBaseline(hash, repos).catch(() => null);
|
|
10214
|
+
if (entry) {
|
|
10215
|
+
const payload = { scopeHash: hash, id: entry.id };
|
|
10216
|
+
opts.broadcast("checkpoints-changed", payload);
|
|
10217
|
+
scopeBus.emit("checkpoints-changed", payload);
|
|
10218
|
+
}
|
|
10219
|
+
return true;
|
|
10220
|
+
}
|
|
9994
10221
|
app.post(
|
|
9995
10222
|
"/api/scopes",
|
|
9996
10223
|
zValidator5(
|
|
@@ -10022,6 +10249,10 @@ function mountScopeRoutes(app, opts) {
|
|
|
10022
10249
|
}).catch((err) => {
|
|
10023
10250
|
console.error("[checkpoint] initial snapshot failed:", err);
|
|
10024
10251
|
});
|
|
10252
|
+
} else {
|
|
10253
|
+
rebaselineIfHeadAdvanced(scope.hash, scope.paths).catch((err) => {
|
|
10254
|
+
console.error("[checkpoint] re-baseline failed:", err);
|
|
10255
|
+
});
|
|
10025
10256
|
}
|
|
10026
10257
|
if (!checkpointWatched.has(scope.hash)) {
|
|
10027
10258
|
checkpointWatched.add(scope.hash);
|
|
@@ -10041,8 +10272,11 @@ function mountScopeRoutes(app, opts) {
|
|
|
10041
10272
|
lastStatus.set(hash, fp);
|
|
10042
10273
|
} catch {
|
|
10043
10274
|
}
|
|
10044
|
-
takeCheckpoint(hash, scopeRepos(scope.paths)).then((entry) => {
|
|
10045
|
-
if (entry)
|
|
10275
|
+
rebaselineIfHeadAdvanced(hash, scope.paths).then(() => takeCheckpoint(hash, scopeRepos(scope.paths))).then((entry) => {
|
|
10276
|
+
if (entry) {
|
|
10277
|
+
announceCheckpoint(entry);
|
|
10278
|
+
ensureSummary(scope, entry.id);
|
|
10279
|
+
}
|
|
10046
10280
|
}).catch((err) => {
|
|
10047
10281
|
console.error("[checkpoint] auto-snapshot failed:", err);
|
|
10048
10282
|
});
|
|
@@ -10075,19 +10309,55 @@ function mountScopeRoutes(app, opts) {
|
|
|
10075
10309
|
const matched = scopesForCwd(cwd);
|
|
10076
10310
|
let snapshotted = 0;
|
|
10077
10311
|
for (const s of matched) {
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10312
|
+
await rebaselineIfHeadAdvanced(s.hash, s.paths);
|
|
10313
|
+
const liveId = liveCheckpoint.get(s.hash);
|
|
10314
|
+
let entry = null;
|
|
10315
|
+
if (liveId !== void 0) {
|
|
10316
|
+
const res = await updateCheckpoint(
|
|
10317
|
+
s.hash,
|
|
10318
|
+
scopeRepos(s.paths),
|
|
10319
|
+
liveId
|
|
10320
|
+
).catch(() => ({ status: "missing" }));
|
|
10321
|
+
if (res.status === "updated") {
|
|
10322
|
+
entry = res.entry;
|
|
10323
|
+
} else if (res.status === "missing") {
|
|
10324
|
+
liveCheckpoint.delete(s.hash);
|
|
10325
|
+
}
|
|
10326
|
+
}
|
|
10327
|
+
if (entry === null && !liveCheckpoint.has(s.hash)) {
|
|
10328
|
+
const appended = await takeCheckpoint(
|
|
10329
|
+
s.hash,
|
|
10330
|
+
scopeRepos(s.paths)
|
|
10331
|
+
).catch(() => null);
|
|
10332
|
+
if (appended) {
|
|
10333
|
+
entry = appended;
|
|
10334
|
+
liveCheckpoint.set(s.hash, appended.id);
|
|
10335
|
+
}
|
|
10336
|
+
}
|
|
10081
10337
|
if (entry) {
|
|
10082
10338
|
const payload = { scopeHash: s.hash, id: entry.id };
|
|
10083
10339
|
opts.broadcast("checkpoints-changed", payload);
|
|
10084
10340
|
scopeBus.emit("checkpoints-changed", payload);
|
|
10341
|
+
ensureSummary(s, entry.id);
|
|
10085
10342
|
snapshotted++;
|
|
10086
10343
|
}
|
|
10087
10344
|
}
|
|
10088
10345
|
return c.json({ ok: true, scopes: matched.length, snapshotted });
|
|
10089
10346
|
}
|
|
10090
10347
|
);
|
|
10348
|
+
app.post(
|
|
10349
|
+
"/api/checkpoint/seal",
|
|
10350
|
+
zValidator5("json", z4.object({ cwd: z4.string().min(1) })),
|
|
10351
|
+
(c) => {
|
|
10352
|
+
const { cwd } = c.req.valid("json");
|
|
10353
|
+
const matched = scopesForCwd(cwd);
|
|
10354
|
+
let sealed = 0;
|
|
10355
|
+
for (const s of matched) {
|
|
10356
|
+
if (liveCheckpoint.delete(s.hash)) sealed++;
|
|
10357
|
+
}
|
|
10358
|
+
return c.json({ ok: true, scopes: matched.length, sealed });
|
|
10359
|
+
}
|
|
10360
|
+
);
|
|
10091
10361
|
app.delete("/api/scopes/:hash", (c) => {
|
|
10092
10362
|
const hash = c.req.param("hash");
|
|
10093
10363
|
const scope = getScope(hash);
|
|
@@ -10095,6 +10365,10 @@ function mountScopeRoutes(app, opts) {
|
|
|
10095
10365
|
const ok = removeScope(hash);
|
|
10096
10366
|
checkpointWatched.delete(hash);
|
|
10097
10367
|
lastStatus.delete(hash);
|
|
10368
|
+
liveCheckpoint.delete(hash);
|
|
10369
|
+
for (const key of summarizing) {
|
|
10370
|
+
if (key.startsWith(`${hash}:`)) summarizing.delete(key);
|
|
10371
|
+
}
|
|
10098
10372
|
const pendingTimer = snapshotTimers.get(hash);
|
|
10099
10373
|
if (pendingTimer) {
|
|
10100
10374
|
clearTimeout(pendingTimer);
|
|
@@ -10147,7 +10421,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
10147
10421
|
const fromSha = fromEntry.repos[p] ?? "HEAD";
|
|
10148
10422
|
const toSha = toEntry === void 0 ? "working" : toEntry.repos[p] ?? "HEAD";
|
|
10149
10423
|
return {
|
|
10150
|
-
name:
|
|
10424
|
+
name: path40.basename(p),
|
|
10151
10425
|
root: p,
|
|
10152
10426
|
files: computeRangeDiff({ root: p, fromRef: fromSha, toRef: toSha })
|
|
10153
10427
|
};
|
|
@@ -10166,7 +10440,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
10166
10440
|
(p) => resolveRepoDiff(p, base, sessionBaseForPath(p))
|
|
10167
10441
|
);
|
|
10168
10442
|
const repos = scope.paths.map((p, i) => ({
|
|
10169
|
-
name:
|
|
10443
|
+
name: path40.basename(p),
|
|
10170
10444
|
root: p,
|
|
10171
10445
|
resolvedBase: resolved[i].resolvedBase,
|
|
10172
10446
|
files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
|
|
@@ -10197,7 +10471,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
10197
10471
|
if (!relPath || !Number.isInteger(start) || !Number.isInteger(end)) {
|
|
10198
10472
|
return c.json({ error: "bad path/start/end" }, 400);
|
|
10199
10473
|
}
|
|
10200
|
-
const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) =>
|
|
10474
|
+
const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path40.basename(p) === repoName);
|
|
10201
10475
|
if (!root) return c.json({ error: "unknown repo" }, 404);
|
|
10202
10476
|
const result = readContextLines({ root, relPath, start, end, ref });
|
|
10203
10477
|
if (!result) return c.json({ error: "cannot read file" }, 400);
|
|
@@ -10493,7 +10767,7 @@ function computeSessionDiff(s, base) {
|
|
|
10493
10767
|
(p) => resolveRepoDiff(p, base, s.baseBranches?.[p] ?? s.baseBranch)
|
|
10494
10768
|
);
|
|
10495
10769
|
const repos = s.paths.map((p, i) => ({
|
|
10496
|
-
name:
|
|
10770
|
+
name: path41.basename(p),
|
|
10497
10771
|
root: p,
|
|
10498
10772
|
resolvedBase: resolved[i].resolvedBase,
|
|
10499
10773
|
files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
|
|
@@ -10513,10 +10787,10 @@ async function startWebServer(opts = {}) {
|
|
|
10513
10787
|
for (const cb of sseListeners) cb({ event, data });
|
|
10514
10788
|
};
|
|
10515
10789
|
const home = os12.homedir();
|
|
10516
|
-
const historyPath =
|
|
10790
|
+
const historyPath = path41.join(home, ".work", "history.json");
|
|
10517
10791
|
const onHistoryChange = () => broadcast("sessions-changed", { ts: Date.now() });
|
|
10518
10792
|
fs40.watchFile(historyPath, { interval: 1e3 }, onHistoryChange);
|
|
10519
|
-
const tasksPath =
|
|
10793
|
+
const tasksPath = path41.join(home, ".work", "tasks.json");
|
|
10520
10794
|
const onTasksChange = () => broadcast("tasks-changed", { ts: Date.now() });
|
|
10521
10795
|
fs40.watchFile(tasksPath, { interval: 1e3 }, onTasksChange);
|
|
10522
10796
|
const projectsRoot = claudeProjectsRoot();
|
|
@@ -10661,10 +10935,10 @@ function info2(message) {
|
|
|
10661
10935
|
process.stderr.write(message + "\n");
|
|
10662
10936
|
}
|
|
10663
10937
|
function urlFilePath() {
|
|
10664
|
-
return
|
|
10938
|
+
return path42.join(os13.homedir(), ".work", "web.url");
|
|
10665
10939
|
}
|
|
10666
10940
|
function pidFilePath() {
|
|
10667
|
-
return
|
|
10941
|
+
return path42.join(os13.homedir(), ".work", "web.pid");
|
|
10668
10942
|
}
|
|
10669
10943
|
function isPidAlive(pid) {
|
|
10670
10944
|
try {
|
|
@@ -10789,7 +11063,7 @@ var webCommand = {
|
|
|
10789
11063
|
const lean = !!argv.lean || process.env.WORK_WEB_LEAN === "1";
|
|
10790
11064
|
const handle = await startWebServer({ lean });
|
|
10791
11065
|
try {
|
|
10792
|
-
fs41.mkdirSync(
|
|
11066
|
+
fs41.mkdirSync(path42.dirname(urlFilePath()), { recursive: true });
|
|
10793
11067
|
fs41.writeFileSync(urlFilePath(), handle.url);
|
|
10794
11068
|
fs41.writeFileSync(pidFilePath(), String(process.pid));
|
|
10795
11069
|
} catch {
|
|
@@ -10825,6 +11099,13 @@ var webCommand = {
|
|
|
10825
11099
|
timeoutSec: 5
|
|
10826
11100
|
}).catch(() => {
|
|
10827
11101
|
});
|
|
11102
|
+
await installCommandHook({
|
|
11103
|
+
owner: "web-checkpoint",
|
|
11104
|
+
event: "UserPromptSubmit",
|
|
11105
|
+
command: "work hook checkpoint-seal",
|
|
11106
|
+
timeoutSec: 5
|
|
11107
|
+
}).catch(() => {
|
|
11108
|
+
});
|
|
10828
11109
|
const shutdown = () => {
|
|
10829
11110
|
info2(chalk23.gray("\nStopping work web."));
|
|
10830
11111
|
try {
|
|
@@ -10849,6 +11130,10 @@ var webCommand = {
|
|
|
10849
11130
|
removeCommandHookSync("web-checkpoint", "Stop");
|
|
10850
11131
|
} catch {
|
|
10851
11132
|
}
|
|
11133
|
+
try {
|
|
11134
|
+
removeCommandHookSync("web-checkpoint", "UserPromptSubmit");
|
|
11135
|
+
} catch {
|
|
11136
|
+
}
|
|
10852
11137
|
handle.stop();
|
|
10853
11138
|
process.exit(0);
|
|
10854
11139
|
};
|
|
@@ -10872,11 +11157,11 @@ var webCommand = {
|
|
|
10872
11157
|
// src/commands/hook.ts
|
|
10873
11158
|
import fs42 from "fs";
|
|
10874
11159
|
import os14 from "os";
|
|
10875
|
-
import
|
|
10876
|
-
async function
|
|
11160
|
+
import path43 from "path";
|
|
11161
|
+
async function postToWeb(route, cwd) {
|
|
10877
11162
|
let base;
|
|
10878
11163
|
try {
|
|
10879
|
-
base = fs42.readFileSync(
|
|
11164
|
+
base = fs42.readFileSync(path43.join(os14.homedir(), ".work", "web.url"), "utf-8").trim();
|
|
10880
11165
|
} catch {
|
|
10881
11166
|
return;
|
|
10882
11167
|
}
|
|
@@ -10884,7 +11169,7 @@ async function triggerCheckpoint(cwd) {
|
|
|
10884
11169
|
const controller = new AbortController();
|
|
10885
11170
|
const timer = setTimeout(() => controller.abort(), 3e3);
|
|
10886
11171
|
try {
|
|
10887
|
-
await fetch(`${base}
|
|
11172
|
+
await fetch(`${base}${route}`, {
|
|
10888
11173
|
method: "POST",
|
|
10889
11174
|
headers: { "Content-Type": "application/json" },
|
|
10890
11175
|
body: JSON.stringify({ cwd }),
|
|
@@ -10944,15 +11229,20 @@ var hookCommand = {
|
|
|
10944
11229
|
// hidden — humans don't call this directly
|
|
10945
11230
|
builder: (y) => y.positional("event", {
|
|
10946
11231
|
type: "string",
|
|
10947
|
-
choices: ["prompt-submit", "stop", "checkpoint"],
|
|
11232
|
+
choices: ["prompt-submit", "stop", "checkpoint", "checkpoint-seal"],
|
|
10948
11233
|
describe: "Hook event name"
|
|
10949
11234
|
}),
|
|
10950
11235
|
handler: async (argv) => {
|
|
11236
|
+
if (isInternalClaude()) return;
|
|
10951
11237
|
const event = argv.event;
|
|
10952
11238
|
const payload = await readStdinJson();
|
|
10953
11239
|
const cwd = payload.cwd ?? process.cwd();
|
|
10954
11240
|
if (event === "checkpoint") {
|
|
10955
|
-
await
|
|
11241
|
+
await postToWeb("api/checkpoint", cwd);
|
|
11242
|
+
return;
|
|
11243
|
+
}
|
|
11244
|
+
if (event === "checkpoint-seal") {
|
|
11245
|
+
await postToWeb("api/checkpoint/seal", cwd);
|
|
10956
11246
|
return;
|
|
10957
11247
|
}
|
|
10958
11248
|
const result = computeHookOutput({ event, cwd });
|
|
@@ -11367,7 +11657,7 @@ var broadcastCommand = {
|
|
|
11367
11657
|
|
|
11368
11658
|
// src/completions/index.ts
|
|
11369
11659
|
import fs45 from "fs";
|
|
11370
|
-
import
|
|
11660
|
+
import path44 from "path";
|
|
11371
11661
|
function completionHandler(current, argv, done) {
|
|
11372
11662
|
const rawArgs = argv._;
|
|
11373
11663
|
const args = rawArgs.slice(1, -1);
|
|
@@ -11480,18 +11770,18 @@ function completeRepoBranches(alias, current, config, done) {
|
|
|
11480
11770
|
done(branches);
|
|
11481
11771
|
}
|
|
11482
11772
|
function completeGroupBranches(groupName, repoAliases, current, config, done) {
|
|
11483
|
-
const groupDir =
|
|
11773
|
+
const groupDir = path44.join(config.worktreesRoot, groupName);
|
|
11484
11774
|
if (!fs45.existsSync(groupDir)) {
|
|
11485
11775
|
done([]);
|
|
11486
11776
|
return;
|
|
11487
11777
|
}
|
|
11488
11778
|
try {
|
|
11489
11779
|
const branchDirs = fs45.readdirSync(groupDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => {
|
|
11490
|
-
const bdPath =
|
|
11780
|
+
const bdPath = path44.join(groupDir, d.name);
|
|
11491
11781
|
for (const alias of repoAliases) {
|
|
11492
11782
|
const repoPath = config.repos[alias];
|
|
11493
11783
|
if (!repoPath) continue;
|
|
11494
|
-
const subPath =
|
|
11784
|
+
const subPath = path44.join(bdPath, path44.basename(repoPath));
|
|
11495
11785
|
if (fs45.existsSync(subPath)) {
|
|
11496
11786
|
const branch = getCurrentBranch(subPath);
|
|
11497
11787
|
if (branch) return branch;
|
|
@@ -11506,7 +11796,7 @@ function completeGroupBranches(groupName, repoAliases, current, config, done) {
|
|
|
11506
11796
|
}
|
|
11507
11797
|
|
|
11508
11798
|
// src/version.ts
|
|
11509
|
-
var VERSION = true ? "1.
|
|
11799
|
+
var VERSION = true ? "1.15.0" : "dev";
|
|
11510
11800
|
|
|
11511
11801
|
// src/cli.ts
|
|
11512
11802
|
function showHelp() {
|
|
@@ -11604,7 +11894,7 @@ function handleFatalError(err) {
|
|
|
11604
11894
|
if (err instanceof Error && err.message?.includes("pty that has already exited")) {
|
|
11605
11895
|
try {
|
|
11606
11896
|
fs46.appendFileSync(
|
|
11607
|
-
|
|
11897
|
+
path45.join(getConfigDir(), "debug.log"),
|
|
11608
11898
|
`${(/* @__PURE__ */ new Date()).toISOString()} [WARN] Ignored async node-pty error: ${err.message}
|
|
11609
11899
|
`
|
|
11610
11900
|
);
|
|
@@ -11615,7 +11905,7 @@ function handleFatalError(err) {
|
|
|
11615
11905
|
try {
|
|
11616
11906
|
const msg = err instanceof Error ? err.stack || err.message : String(err);
|
|
11617
11907
|
fs46.appendFileSync(
|
|
11618
|
-
|
|
11908
|
+
path45.join(getConfigDir(), "debug.log"),
|
|
11619
11909
|
`${(/* @__PURE__ */ new Date()).toISOString()} [FATAL] handleFatalError: ${msg}
|
|
11620
11910
|
`
|
|
11621
11911
|
);
|