@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/wd-bin.js
CHANGED
|
@@ -443,6 +443,17 @@ import fs3 from "fs";
|
|
|
443
443
|
import path4 from "path";
|
|
444
444
|
import spawn2 from "cross-spawn";
|
|
445
445
|
import chalk from "chalk";
|
|
446
|
+
|
|
447
|
+
// src/core/internal-claude.ts
|
|
448
|
+
var INTERNAL_CLAUDE_ENV = "WORK_INTERNAL_CLAUDE";
|
|
449
|
+
function internalClaudeEnv() {
|
|
450
|
+
return { [INTERNAL_CLAUDE_ENV]: "1" };
|
|
451
|
+
}
|
|
452
|
+
function isInternalClaude() {
|
|
453
|
+
return process.env[INTERNAL_CLAUDE_ENV] === "1";
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// src/core/claude-md.ts
|
|
446
457
|
function generateGroupClaudeMd(groupName, repoAliases, config) {
|
|
447
458
|
const outputPath = path4.join(getConfigDir(), `${groupName}.claude.md`);
|
|
448
459
|
const promptParts = [];
|
|
@@ -499,7 +510,9 @@ function generateGroupClaudeMd(groupName, repoAliases, config) {
|
|
|
499
510
|
input: prompt,
|
|
500
511
|
encoding: "utf-8",
|
|
501
512
|
stdio: ["pipe", "pipe", "pipe"],
|
|
502
|
-
windowsHide: true
|
|
513
|
+
windowsHide: true,
|
|
514
|
+
// Internal call — don't trip work's checkpoint hooks (see internal-claude.ts).
|
|
515
|
+
env: { ...process.env, ...internalClaudeEnv() }
|
|
503
516
|
});
|
|
504
517
|
let content;
|
|
505
518
|
if (result.status !== 0 || !result.stdout?.trim()) {
|
|
@@ -1382,20 +1395,44 @@ function resolveFromCwd(config, cwd) {
|
|
|
1382
1395
|
|
|
1383
1396
|
// src/core/worktree.ts
|
|
1384
1397
|
import fs13 from "fs";
|
|
1385
|
-
import
|
|
1398
|
+
import path13 from "path";
|
|
1386
1399
|
import chalk5 from "chalk";
|
|
1387
1400
|
|
|
1388
1401
|
// src/core/history.ts
|
|
1389
1402
|
import fs11 from "fs";
|
|
1390
|
-
import
|
|
1403
|
+
import path11 from "path";
|
|
1391
1404
|
|
|
1392
1405
|
// src/core/fs-safe.ts
|
|
1393
1406
|
import fs8 from "fs";
|
|
1407
|
+
import path9 from "path";
|
|
1394
1408
|
import lockfile from "proper-lockfile";
|
|
1409
|
+
function resolveLinkTarget(filePath) {
|
|
1410
|
+
let current = filePath;
|
|
1411
|
+
const seen = /* @__PURE__ */ new Set([current]);
|
|
1412
|
+
for (let i = 0; i < 32; i++) {
|
|
1413
|
+
let stat;
|
|
1414
|
+
try {
|
|
1415
|
+
stat = fs8.lstatSync(current);
|
|
1416
|
+
} catch {
|
|
1417
|
+
return current;
|
|
1418
|
+
}
|
|
1419
|
+
if (!stat.isSymbolicLink()) return current;
|
|
1420
|
+
const next = path9.resolve(path9.dirname(current), fs8.readlinkSync(current));
|
|
1421
|
+
if (seen.has(next)) return filePath;
|
|
1422
|
+
seen.add(next);
|
|
1423
|
+
current = next;
|
|
1424
|
+
}
|
|
1425
|
+
return filePath;
|
|
1426
|
+
}
|
|
1395
1427
|
function atomicWriteFile(filePath, content) {
|
|
1396
|
-
const
|
|
1428
|
+
const target = resolveLinkTarget(filePath);
|
|
1429
|
+
const tmpPath = `${target}.tmp-${process.pid}`;
|
|
1397
1430
|
fs8.writeFileSync(tmpPath, content, "utf-8");
|
|
1398
|
-
|
|
1431
|
+
try {
|
|
1432
|
+
fs8.chmodSync(tmpPath, fs8.statSync(target).mode & 511);
|
|
1433
|
+
} catch {
|
|
1434
|
+
}
|
|
1435
|
+
fs8.renameSync(tmpPath, target);
|
|
1399
1436
|
}
|
|
1400
1437
|
function ensureFile(filePath, initialContent) {
|
|
1401
1438
|
if (!fs8.existsSync(filePath)) {
|
|
@@ -1440,9 +1477,9 @@ function sleepSync(ms) {
|
|
|
1440
1477
|
// src/core/claude-activity.ts
|
|
1441
1478
|
import fs9 from "fs";
|
|
1442
1479
|
import os4 from "os";
|
|
1443
|
-
import
|
|
1480
|
+
import path10 from "path";
|
|
1444
1481
|
function encodeProjectDir(p) {
|
|
1445
|
-
return
|
|
1482
|
+
return path10.resolve(p).replace(/[^A-Za-z0-9]/g, "-");
|
|
1446
1483
|
}
|
|
1447
1484
|
function latestJsonlMtimeMs(projectDir) {
|
|
1448
1485
|
let entries;
|
|
@@ -1455,7 +1492,7 @@ function latestJsonlMtimeMs(projectDir) {
|
|
|
1455
1492
|
for (const name of entries) {
|
|
1456
1493
|
if (!name.endsWith(".jsonl")) continue;
|
|
1457
1494
|
try {
|
|
1458
|
-
const stat = fs9.statSync(
|
|
1495
|
+
const stat = fs9.statSync(path10.join(projectDir, name));
|
|
1459
1496
|
if (stat.mtimeMs > latest) latest = stat.mtimeMs;
|
|
1460
1497
|
} catch {
|
|
1461
1498
|
}
|
|
@@ -1466,7 +1503,7 @@ function claudeActiveWithin(activityMs, nowMs, windowMs) {
|
|
|
1466
1503
|
return activityMs > 0 && nowMs - activityMs < windowMs;
|
|
1467
1504
|
}
|
|
1468
1505
|
function getClaudeActivityMs(launchPath) {
|
|
1469
|
-
const dir =
|
|
1506
|
+
const dir = path10.join(
|
|
1470
1507
|
os4.homedir(),
|
|
1471
1508
|
".claude",
|
|
1472
1509
|
"projects",
|
|
@@ -1474,10 +1511,13 @@ function getClaudeActivityMs(launchPath) {
|
|
|
1474
1511
|
);
|
|
1475
1512
|
return latestJsonlMtimeMs(dir);
|
|
1476
1513
|
}
|
|
1514
|
+
function hasClaudeConversation(dir) {
|
|
1515
|
+
return getClaudeActivityMs(dir) > 0;
|
|
1516
|
+
}
|
|
1477
1517
|
function getLaunchPaths(session) {
|
|
1478
1518
|
if (!session.isGroup) return [...session.paths];
|
|
1479
1519
|
const parents = /* @__PURE__ */ new Set();
|
|
1480
|
-
for (const p of session.paths) parents.add(
|
|
1520
|
+
for (const p of session.paths) parents.add(path10.dirname(p));
|
|
1481
1521
|
return [...parents];
|
|
1482
1522
|
}
|
|
1483
1523
|
function effectiveLastAccessedAt(session) {
|
|
@@ -1492,10 +1532,10 @@ function effectiveLastAccessedAt(session) {
|
|
|
1492
1532
|
function resolveResumeLaunch(session) {
|
|
1493
1533
|
const existing = session.paths.filter((p) => fs9.existsSync(p));
|
|
1494
1534
|
const first = existing[0] ?? session.paths[0];
|
|
1495
|
-
const defaultPath = session.isGroup ?
|
|
1535
|
+
const defaultPath = session.isGroup ? path10.dirname(first) : first;
|
|
1496
1536
|
const candidates = /* @__PURE__ */ new Set();
|
|
1497
1537
|
if (session.isGroup) {
|
|
1498
|
-
for (const p of existing) candidates.add(
|
|
1538
|
+
for (const p of existing) candidates.add(path10.dirname(p));
|
|
1499
1539
|
for (const p of existing) candidates.add(p);
|
|
1500
1540
|
} else {
|
|
1501
1541
|
for (const p of existing) candidates.add(p);
|
|
@@ -1525,7 +1565,7 @@ function readSessionActivity(session) {
|
|
|
1525
1565
|
return { lastActivity: latest, state };
|
|
1526
1566
|
}
|
|
1527
1567
|
function claudeProjectsRoot() {
|
|
1528
|
-
return
|
|
1568
|
+
return path10.join(os4.homedir(), ".claude", "projects");
|
|
1529
1569
|
}
|
|
1530
1570
|
|
|
1531
1571
|
// src/core/port-allocator.ts
|
|
@@ -1599,7 +1639,7 @@ async function allocateFreePort(seedKey, config, sessions, probe = isPortFree) {
|
|
|
1599
1639
|
|
|
1600
1640
|
// src/core/history.ts
|
|
1601
1641
|
function getHistoryPath() {
|
|
1602
|
-
return
|
|
1642
|
+
return path11.join(getConfigDir(), "history.json");
|
|
1603
1643
|
}
|
|
1604
1644
|
function backupCorruptFile(historyPath, reason) {
|
|
1605
1645
|
try {
|
|
@@ -1792,7 +1832,7 @@ async function mergeHydratedSessions(incoming) {
|
|
|
1792
1832
|
|
|
1793
1833
|
// src/core/copy-files.ts
|
|
1794
1834
|
import fs12 from "fs";
|
|
1795
|
-
import
|
|
1835
|
+
import path12 from "path";
|
|
1796
1836
|
import { globSync } from "glob";
|
|
1797
1837
|
var EXCLUDED_DIRS = ["bin", "obj", "node_modules", ".git"];
|
|
1798
1838
|
function copyConfigFiles(repoPath, worktreePath, patterns) {
|
|
@@ -1800,10 +1840,10 @@ function copyConfigFiles(repoPath, worktreePath, patterns) {
|
|
|
1800
1840
|
const normalized = pattern.replace(/\\/g, "/");
|
|
1801
1841
|
if (normalized.startsWith(".claude/")) {
|
|
1802
1842
|
const relativePath = normalized;
|
|
1803
|
-
const sourcePath =
|
|
1843
|
+
const sourcePath = path12.join(repoPath, relativePath);
|
|
1804
1844
|
if (fs12.existsSync(sourcePath)) {
|
|
1805
|
-
const destPath =
|
|
1806
|
-
const destDir =
|
|
1845
|
+
const destPath = path12.join(worktreePath, relativePath);
|
|
1846
|
+
const destDir = path12.dirname(destPath);
|
|
1807
1847
|
fs12.mkdirSync(destDir, { recursive: true });
|
|
1808
1848
|
fs12.copyFileSync(sourcePath, destPath);
|
|
1809
1849
|
console.log(` Copied: ${relativePath}`);
|
|
@@ -1821,9 +1861,9 @@ function copyConfigFiles(repoPath, worktreePath, patterns) {
|
|
|
1821
1861
|
if (parts.some((p) => EXCLUDED_DIRS.includes(p))) {
|
|
1822
1862
|
continue;
|
|
1823
1863
|
}
|
|
1824
|
-
const sourcePath =
|
|
1825
|
-
const destPath =
|
|
1826
|
-
const destDir =
|
|
1864
|
+
const sourcePath = path12.join(repoPath, match);
|
|
1865
|
+
const destPath = path12.join(worktreePath, match);
|
|
1866
|
+
const destDir = path12.dirname(destPath);
|
|
1827
1867
|
fs12.mkdirSync(destDir, { recursive: true });
|
|
1828
1868
|
fs12.copyFileSync(sourcePath, destPath);
|
|
1829
1869
|
console.log(` Copied: ${match}`);
|
|
@@ -1888,7 +1928,26 @@ function toBaseSpec(base) {
|
|
|
1888
1928
|
}
|
|
1889
1929
|
|
|
1890
1930
|
// src/core/worktree.ts
|
|
1891
|
-
function
|
|
1931
|
+
function pullLatestForBranch(worktreePath, branchName) {
|
|
1932
|
+
const upstream = git(
|
|
1933
|
+
["rev-parse", "--abbrev-ref", `${branchName}@{upstream}`],
|
|
1934
|
+
worktreePath
|
|
1935
|
+
);
|
|
1936
|
+
if (upstream.exitCode !== 0) return;
|
|
1937
|
+
console.log(` Pulling latest changes for ${branchName}...`);
|
|
1938
|
+
git(["fetch", "--quiet"], worktreePath);
|
|
1939
|
+
const pull = git(["pull", "--quiet"], worktreePath);
|
|
1940
|
+
if (pull.exitCode !== 0) {
|
|
1941
|
+
console.log(
|
|
1942
|
+
chalk5.yellow(
|
|
1943
|
+
` \u26A0 Could not pull '${branchName}' (uncommitted changes or conflicts). Worktree may be behind origin.`
|
|
1944
|
+
)
|
|
1945
|
+
);
|
|
1946
|
+
const firstErrLine = pull.stderr.split("\n")[0];
|
|
1947
|
+
if (firstErrLine) console.log(chalk5.gray(` ${firstErrLine}`));
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
function createSingleWorktree(repoPath, worktreePath, branchName, config, baseBranch, pull = true) {
|
|
1892
1951
|
debug("createSingleWorktree", { repoPath, worktreePath, branchName, baseBranch });
|
|
1893
1952
|
if (fs13.existsSync(worktreePath)) {
|
|
1894
1953
|
if (isGitRepo(worktreePath)) {
|
|
@@ -1897,6 +1956,7 @@ function createSingleWorktree(repoPath, worktreePath, branchName, config, baseBr
|
|
|
1897
1956
|
console.log(
|
|
1898
1957
|
chalk5.yellow(` Worktree already exists at: ${worktreePath}`)
|
|
1899
1958
|
);
|
|
1959
|
+
if (pull) pullLatestForBranch(worktreePath, branchName);
|
|
1900
1960
|
return true;
|
|
1901
1961
|
}
|
|
1902
1962
|
}
|
|
@@ -1916,7 +1976,7 @@ function createSingleWorktree(repoPath, worktreePath, branchName, config, baseBr
|
|
|
1916
1976
|
);
|
|
1917
1977
|
return false;
|
|
1918
1978
|
}
|
|
1919
|
-
const parentDir =
|
|
1979
|
+
const parentDir = path13.dirname(worktreePath);
|
|
1920
1980
|
fs13.mkdirSync(parentDir, { recursive: true });
|
|
1921
1981
|
git(["fetch", "--quiet"], repoPath);
|
|
1922
1982
|
const baseRepoBranch = getCurrentBranch(repoPath);
|
|
@@ -2092,9 +2152,9 @@ function removeSingleWorktree(repoPath, worktreePath, branchName, force) {
|
|
|
2092
2152
|
return false;
|
|
2093
2153
|
}
|
|
2094
2154
|
}
|
|
2095
|
-
async function setupWorktree(targetName, branchName, config, base, jiraKey) {
|
|
2155
|
+
async function setupWorktree(targetName, branchName, config, base, jiraKey, opts = {}) {
|
|
2096
2156
|
const spec = toBaseSpec(base);
|
|
2097
|
-
debug("setupWorktree", { targetName, branchName, spec, jiraKey });
|
|
2157
|
+
debug("setupWorktree", { targetName, branchName, spec, jiraKey, opts });
|
|
2098
2158
|
const target = resolveProjectTarget(targetName, config);
|
|
2099
2159
|
if (!target) {
|
|
2100
2160
|
debug("setupWorktree: target not found", targetName);
|
|
@@ -2102,13 +2162,13 @@ async function setupWorktree(targetName, branchName, config, base, jiraKey) {
|
|
|
2102
2162
|
}
|
|
2103
2163
|
const workTreeDirName = branchName.replace(/\//g, "-");
|
|
2104
2164
|
if (target.isGroup) {
|
|
2105
|
-
return setupGroupWorktree(target.name, target.repoAliases, branchName, workTreeDirName, config, spec, jiraKey);
|
|
2165
|
+
return setupGroupWorktree(target.name, target.repoAliases, branchName, workTreeDirName, config, spec, jiraKey, opts);
|
|
2106
2166
|
} else {
|
|
2107
|
-
return setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey);
|
|
2167
|
+
return setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey, opts);
|
|
2108
2168
|
}
|
|
2109
2169
|
}
|
|
2110
|
-
async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDirName, config, spec, jiraKey) {
|
|
2111
|
-
const groupWorktreePath =
|
|
2170
|
+
async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDirName, config, spec, jiraKey, opts = {}) {
|
|
2171
|
+
const groupWorktreePath = path13.join(config.worktreesRoot, groupName, workTreeDirName);
|
|
2112
2172
|
if (!isEmptyBaseSpec(spec)) {
|
|
2113
2173
|
const unknownAliases = baseSpecOverrideAliases(spec).filter(
|
|
2114
2174
|
(a) => !repoAliases.includes(a)
|
|
@@ -2149,11 +2209,11 @@ async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDi
|
|
|
2149
2209
|
const baseBranches = {};
|
|
2150
2210
|
for (const alias of repoAliases) {
|
|
2151
2211
|
const repoPath = config.repos[alias];
|
|
2152
|
-
const repoName =
|
|
2153
|
-
const subWorktreePath =
|
|
2212
|
+
const repoName = path13.basename(repoPath);
|
|
2213
|
+
const subWorktreePath = path13.join(groupWorktreePath, repoName);
|
|
2154
2214
|
const repoBase = baseForAlias(spec, alias);
|
|
2155
2215
|
console.log(chalk5.cyan(`[${alias}] (${repoName}):`));
|
|
2156
|
-
const success = createSingleWorktree(repoPath, subWorktreePath, branchName, config, repoBase);
|
|
2216
|
+
const success = createSingleWorktree(repoPath, subWorktreePath, branchName, config, repoBase, opts.pull !== false);
|
|
2157
2217
|
if (success) {
|
|
2158
2218
|
createdWorktrees.push({ repoPath, worktreePath: subWorktreePath });
|
|
2159
2219
|
if (repoBase) baseBranches[subWorktreePath] = repoBase;
|
|
@@ -2174,8 +2234,8 @@ async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDi
|
|
|
2174
2234
|
}
|
|
2175
2235
|
}
|
|
2176
2236
|
const configDir = getConfigDir();
|
|
2177
|
-
const claudeMdSrc =
|
|
2178
|
-
const claudeMdDest =
|
|
2237
|
+
const claudeMdSrc = path13.join(configDir, `${groupName}.claude.md`);
|
|
2238
|
+
const claudeMdDest = path13.join(groupWorktreePath, "CLAUDE.md");
|
|
2179
2239
|
if (fs13.existsSync(claudeMdSrc)) {
|
|
2180
2240
|
fs13.copyFileSync(claudeMdSrc, claudeMdDest);
|
|
2181
2241
|
console.log("");
|
|
@@ -2203,10 +2263,10 @@ async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDi
|
|
|
2203
2263
|
if (port !== void 0) console.log(chalk5.gray(`Dev-server port: ${port}`));
|
|
2204
2264
|
return { launchDir: groupWorktreePath, paths: allPaths, isGroup: true, port };
|
|
2205
2265
|
}
|
|
2206
|
-
async function setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey) {
|
|
2266
|
+
async function setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey, opts = {}) {
|
|
2207
2267
|
const repoPath = config.repos[targetName];
|
|
2208
|
-
const repoName =
|
|
2209
|
-
let workTreePath =
|
|
2268
|
+
const repoName = path13.basename(repoPath);
|
|
2269
|
+
let workTreePath = path13.join(config.worktreesRoot, repoName, workTreeDirName);
|
|
2210
2270
|
const unknownAliases = baseSpecOverrideAliases(spec).filter((a) => a !== targetName);
|
|
2211
2271
|
if (unknownAliases.length > 0) {
|
|
2212
2272
|
console.error(
|
|
@@ -2221,7 +2281,7 @@ async function setupSingleWorktree(targetName, branchName, workTreeDirName, conf
|
|
|
2221
2281
|
}
|
|
2222
2282
|
const worktrees = parseWorktreeList(repoPath);
|
|
2223
2283
|
const existing = worktrees.find(
|
|
2224
|
-
(wt) => wt.branch === branchName &&
|
|
2284
|
+
(wt) => wt.branch === branchName && path13.resolve(wt.path) !== path13.resolve(repoPath)
|
|
2225
2285
|
);
|
|
2226
2286
|
if (existing) {
|
|
2227
2287
|
if (baseBranch) {
|
|
@@ -2230,8 +2290,9 @@ async function setupSingleWorktree(targetName, branchName, workTreeDirName, conf
|
|
|
2230
2290
|
}
|
|
2231
2291
|
console.log(`Worktree already exists at: ${existing.path}`);
|
|
2232
2292
|
workTreePath = existing.path;
|
|
2293
|
+
if (opts.pull !== false) pullLatestForBranch(workTreePath, branchName);
|
|
2233
2294
|
} else {
|
|
2234
|
-
const success = createSingleWorktree(repoPath, workTreePath, branchName, config, baseBranch);
|
|
2295
|
+
const success = createSingleWorktree(repoPath, workTreePath, branchName, config, baseBranch, opts.pull !== false);
|
|
2235
2296
|
if (!success) return null;
|
|
2236
2297
|
}
|
|
2237
2298
|
const { port } = await upsertSessionWithPort(
|
|
@@ -2252,19 +2313,19 @@ function teardownWorktree(target, isGroup, branch, config, force = true) {
|
|
|
2252
2313
|
const workTreeDirName = branch.replace(/\//g, "-");
|
|
2253
2314
|
if (isGroup && config.groups[target]) {
|
|
2254
2315
|
const aliases = config.groups[target];
|
|
2255
|
-
const groupWorktreePath =
|
|
2316
|
+
const groupWorktreePath = path13.join(config.worktreesRoot, target, workTreeDirName);
|
|
2256
2317
|
let allRemoved = true;
|
|
2257
2318
|
for (const alias of aliases) {
|
|
2258
2319
|
const repoPath = config.repos[alias];
|
|
2259
2320
|
if (!repoPath) continue;
|
|
2260
|
-
const repoName =
|
|
2261
|
-
const subWorktreePath =
|
|
2321
|
+
const repoName = path13.basename(repoPath);
|
|
2322
|
+
const subWorktreePath = path13.join(groupWorktreePath, repoName);
|
|
2262
2323
|
console.log(chalk5.cyan(`[${alias}] (${repoName}):`));
|
|
2263
2324
|
if (!removeSingleWorktree(repoPath, subWorktreePath, branch, force)) {
|
|
2264
2325
|
allRemoved = false;
|
|
2265
2326
|
}
|
|
2266
2327
|
}
|
|
2267
|
-
const claudeMd =
|
|
2328
|
+
const claudeMd = path13.join(groupWorktreePath, "CLAUDE.md");
|
|
2268
2329
|
try {
|
|
2269
2330
|
if (fs13.existsSync(claudeMd)) fs13.unlinkSync(claudeMd);
|
|
2270
2331
|
} catch {
|
|
@@ -2313,6 +2374,14 @@ var treeCommand = {
|
|
|
2313
2374
|
describe: "Launch the AI tool with its skip-permissions flag (default: --dangerously-skip-permissions)",
|
|
2314
2375
|
type: "boolean",
|
|
2315
2376
|
default: false
|
|
2377
|
+
}).option("pull", {
|
|
2378
|
+
describe: "Pull latest changes when switching into an existing worktree or the base repo. Use --no-pull to skip.",
|
|
2379
|
+
type: "boolean",
|
|
2380
|
+
default: true
|
|
2381
|
+
}).option("fresh", {
|
|
2382
|
+
describe: "Start a new AI conversation instead of continuing the previous one for this directory",
|
|
2383
|
+
type: "boolean",
|
|
2384
|
+
default: false
|
|
2316
2385
|
}).option("base", {
|
|
2317
2386
|
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.",
|
|
2318
2387
|
type: "string"
|
|
@@ -2338,6 +2407,8 @@ var treeCommand = {
|
|
|
2338
2407
|
const here = argv.here;
|
|
2339
2408
|
const open = argv.open;
|
|
2340
2409
|
const unsafe = argv.unsafe;
|
|
2410
|
+
const pull = argv.pull;
|
|
2411
|
+
const fresh = argv.fresh;
|
|
2341
2412
|
const setupOnly = argv["setup-only"];
|
|
2342
2413
|
let baseSpec;
|
|
2343
2414
|
try {
|
|
@@ -2361,6 +2432,19 @@ var treeCommand = {
|
|
|
2361
2432
|
}
|
|
2362
2433
|
}
|
|
2363
2434
|
const config = ensureConfig();
|
|
2435
|
+
const launchTool = (dir, port) => {
|
|
2436
|
+
const tool = getAiTool(config);
|
|
2437
|
+
const resume = !fresh && hasClaudeConversation(dir);
|
|
2438
|
+
if (resume) {
|
|
2439
|
+
console.log(
|
|
2440
|
+
chalk6.gray(
|
|
2441
|
+
`Continuing the previous ${tool.cmd} conversation (--fresh starts a new one).`
|
|
2442
|
+
)
|
|
2443
|
+
);
|
|
2444
|
+
}
|
|
2445
|
+
console.log(`Starting ${tool.cmd}...`);
|
|
2446
|
+
launchAi(dir, tool, { unsafe, initialPrompt, resume }, port);
|
|
2447
|
+
};
|
|
2364
2448
|
if (here) {
|
|
2365
2449
|
if (targetName) {
|
|
2366
2450
|
console.error("Cannot combine --here with an explicit target.");
|
|
@@ -2429,16 +2513,15 @@ var treeCommand = {
|
|
|
2429
2513
|
console.log(chalk6.cyan(`Working on base repo: ${targetName}`));
|
|
2430
2514
|
console.log(`Repo path: ${repoPath}`);
|
|
2431
2515
|
const currentBranch = getCurrentBranch(repoPath) ?? "(detached)";
|
|
2516
|
+
if (pull && currentBranch && currentBranch !== "(detached)") {
|
|
2517
|
+
pullLatestForBranch(repoPath, currentBranch);
|
|
2518
|
+
}
|
|
2432
2519
|
await upsertSession(targetName, false, currentBranch, [repoPath], jiraKey);
|
|
2433
2520
|
if (open) openVSCode(repoPath);
|
|
2434
|
-
if (!setupOnly)
|
|
2435
|
-
const tool = getAiTool(config);
|
|
2436
|
-
console.log(`Starting ${tool.cmd}...`);
|
|
2437
|
-
launchAi(repoPath, tool, { unsafe, initialPrompt });
|
|
2438
|
-
}
|
|
2521
|
+
if (!setupOnly) launchTool(repoPath);
|
|
2439
2522
|
return;
|
|
2440
2523
|
}
|
|
2441
|
-
const result = await setupWorktree(targetName, branchName, config, baseSpec, jiraKey);
|
|
2524
|
+
const result = await setupWorktree(targetName, branchName, config, baseSpec, jiraKey, { pull });
|
|
2442
2525
|
if (!result) {
|
|
2443
2526
|
process.exitCode = 1;
|
|
2444
2527
|
return;
|
|
@@ -2449,11 +2532,7 @@ var treeCommand = {
|
|
|
2449
2532
|
}
|
|
2450
2533
|
}
|
|
2451
2534
|
console.log(`Worktree path: ${result.launchDir}`);
|
|
2452
|
-
if (!setupOnly)
|
|
2453
|
-
const tool = getAiTool(config);
|
|
2454
|
-
console.log(`Starting ${tool.cmd}...`);
|
|
2455
|
-
launchAi(result.launchDir, tool, { unsafe, initialPrompt }, result.port);
|
|
2456
|
-
}
|
|
2535
|
+
if (!setupOnly) launchTool(result.launchDir, result.port);
|
|
2457
2536
|
}
|
|
2458
2537
|
};
|
|
2459
2538
|
|
|
@@ -2512,7 +2591,7 @@ var removeCommand = {
|
|
|
2512
2591
|
|
|
2513
2592
|
// src/commands/list.ts
|
|
2514
2593
|
import fs15 from "fs";
|
|
2515
|
-
import
|
|
2594
|
+
import path14 from "path";
|
|
2516
2595
|
import chalk8 from "chalk";
|
|
2517
2596
|
var listCommand = {
|
|
2518
2597
|
command: "list [target]",
|
|
@@ -2580,7 +2659,7 @@ var listCommand = {
|
|
|
2580
2659
|
}
|
|
2581
2660
|
}
|
|
2582
2661
|
for (const groupName of showGroups) {
|
|
2583
|
-
const groupDir =
|
|
2662
|
+
const groupDir = path14.join(worktreesRoot, groupName);
|
|
2584
2663
|
if (!fs15.existsSync(groupDir)) continue;
|
|
2585
2664
|
let branchDirs;
|
|
2586
2665
|
try {
|
|
@@ -2598,12 +2677,12 @@ var listCommand = {
|
|
|
2598
2677
|
);
|
|
2599
2678
|
const repoAliases = config.groups[groupName] ?? [];
|
|
2600
2679
|
for (const bdName of branchDirs) {
|
|
2601
|
-
const bdPath =
|
|
2680
|
+
const bdPath = path14.join(groupDir, bdName);
|
|
2602
2681
|
let actualBranch = null;
|
|
2603
2682
|
for (const alias of repoAliases) {
|
|
2604
2683
|
const repoPath = config.repos[alias];
|
|
2605
2684
|
if (!repoPath) continue;
|
|
2606
|
-
const rdPath =
|
|
2685
|
+
const rdPath = path14.join(bdPath, path14.basename(repoPath));
|
|
2607
2686
|
if (fs15.existsSync(rdPath)) {
|
|
2608
2687
|
const branch = getCurrentBranch(rdPath);
|
|
2609
2688
|
if (branch) {
|
|
@@ -2930,7 +3009,7 @@ import { checkbox } from "@inquirer/prompts";
|
|
|
2930
3009
|
|
|
2931
3010
|
// src/core/prunable-scan.ts
|
|
2932
3011
|
import fs19 from "fs";
|
|
2933
|
-
import
|
|
3012
|
+
import path15 from "path";
|
|
2934
3013
|
import chalk12 from "chalk";
|
|
2935
3014
|
function collectPrunable(config, options = {}) {
|
|
2936
3015
|
const { fetch: fetch2 = true, print = true, includeSquash = false } = options;
|
|
@@ -2947,7 +3026,7 @@ function collectPrunable(config, options = {}) {
|
|
|
2947
3026
|
}
|
|
2948
3027
|
const groupCoveredKeys = /* @__PURE__ */ new Set();
|
|
2949
3028
|
for (const [groupName, aliases] of Object.entries(config.groups)) {
|
|
2950
|
-
const groupDir =
|
|
3029
|
+
const groupDir = path15.join(config.worktreesRoot, groupName);
|
|
2951
3030
|
if (!fs19.existsSync(groupDir)) continue;
|
|
2952
3031
|
let branchDirs;
|
|
2953
3032
|
try {
|
|
@@ -2956,7 +3035,7 @@ function collectPrunable(config, options = {}) {
|
|
|
2956
3035
|
continue;
|
|
2957
3036
|
}
|
|
2958
3037
|
for (const branchDir of branchDirs) {
|
|
2959
|
-
const branchDirPath =
|
|
3038
|
+
const branchDirPath = path15.join(groupDir, branchDir);
|
|
2960
3039
|
let branch;
|
|
2961
3040
|
let allMerged = true;
|
|
2962
3041
|
let groupHasChanges = false;
|
|
@@ -2970,8 +3049,8 @@ function collectPrunable(config, options = {}) {
|
|
|
2970
3049
|
skipped = true;
|
|
2971
3050
|
continue;
|
|
2972
3051
|
}
|
|
2973
|
-
const repoName =
|
|
2974
|
-
const subWorktreePath =
|
|
3052
|
+
const repoName = path15.basename(repoPath);
|
|
3053
|
+
const subWorktreePath = path15.join(branchDirPath, repoName);
|
|
2975
3054
|
if (!fs19.existsSync(subWorktreePath)) {
|
|
2976
3055
|
continue;
|
|
2977
3056
|
}
|
|
@@ -3088,7 +3167,7 @@ async function removeSingleEntry(entry, force = true) {
|
|
|
3088
3167
|
}
|
|
3089
3168
|
async function removeGroupEntry(entry, config, force = true) {
|
|
3090
3169
|
const workTreeDirName = entry.branch.replace(/\//g, "-");
|
|
3091
|
-
const groupWorktreePath =
|
|
3170
|
+
const groupWorktreePath = path15.join(
|
|
3092
3171
|
config.worktreesRoot,
|
|
3093
3172
|
entry.target,
|
|
3094
3173
|
workTreeDirName
|
|
@@ -3098,7 +3177,7 @@ async function removeGroupEntry(entry, config, force = true) {
|
|
|
3098
3177
|
);
|
|
3099
3178
|
let allRemoved = true;
|
|
3100
3179
|
for (const { alias, repoPath, worktreePath } of entry.repos) {
|
|
3101
|
-
const repoName =
|
|
3180
|
+
const repoName = path15.basename(repoPath);
|
|
3102
3181
|
console.log(chalk12.cyan(` [${alias}] (${repoName}):`));
|
|
3103
3182
|
const removed = removeSingleWorktree(repoPath, worktreePath, entry.branch, force);
|
|
3104
3183
|
if (!removed) {
|
|
@@ -3108,7 +3187,7 @@ async function removeGroupEntry(entry, config, force = true) {
|
|
|
3108
3187
|
if (allRemoved) {
|
|
3109
3188
|
await removeSession(entry.target, entry.branch);
|
|
3110
3189
|
}
|
|
3111
|
-
const claudeMdInWorktree =
|
|
3190
|
+
const claudeMdInWorktree = path15.join(groupWorktreePath, "CLAUDE.md");
|
|
3112
3191
|
if (fs19.existsSync(claudeMdInWorktree)) {
|
|
3113
3192
|
fs19.unlinkSync(claudeMdInWorktree);
|
|
3114
3193
|
}
|
|
@@ -3334,7 +3413,7 @@ var syncCommand = {
|
|
|
3334
3413
|
|
|
3335
3414
|
// src/tui-ink/index.tsx
|
|
3336
3415
|
import fs24 from "fs";
|
|
3337
|
-
import
|
|
3416
|
+
import path20 from "path";
|
|
3338
3417
|
import { render } from "ink";
|
|
3339
3418
|
|
|
3340
3419
|
// src/tui-ink/App.tsx
|
|
@@ -3342,7 +3421,7 @@ import { useState, useEffect, useRef, useCallback, useMemo } from "react";
|
|
|
3342
3421
|
import { Box as Box5 } from "ink";
|
|
3343
3422
|
import fs23 from "fs";
|
|
3344
3423
|
import os6 from "os";
|
|
3345
|
-
import
|
|
3424
|
+
import path19 from "path";
|
|
3346
3425
|
import { execFile as execFile4 } from "child_process";
|
|
3347
3426
|
import spawn7 from "cross-spawn";
|
|
3348
3427
|
|
|
@@ -3556,10 +3635,10 @@ async function fetchJiraPane() {
|
|
|
3556
3635
|
|
|
3557
3636
|
// src/core/tasks.ts
|
|
3558
3637
|
import fs21 from "fs";
|
|
3559
|
-
import
|
|
3638
|
+
import path16 from "path";
|
|
3560
3639
|
var EMPTY_STORE = { nextId: 1, tasks: [] };
|
|
3561
3640
|
function getTasksPath() {
|
|
3562
|
-
return
|
|
3641
|
+
return path16.join(getConfigDir(), "tasks.json");
|
|
3563
3642
|
}
|
|
3564
3643
|
function loadStore() {
|
|
3565
3644
|
const p = getTasksPath();
|
|
@@ -3808,30 +3887,33 @@ var PtySession = class {
|
|
|
3808
3887
|
|
|
3809
3888
|
// src/core/hook-server.ts
|
|
3810
3889
|
import http from "http";
|
|
3811
|
-
import
|
|
3890
|
+
import path18 from "path";
|
|
3812
3891
|
|
|
3813
3892
|
// src/core/settings-editor.ts
|
|
3814
3893
|
import fs22 from "fs";
|
|
3815
|
-
import
|
|
3894
|
+
import path17 from "path";
|
|
3816
3895
|
import os5 from "os";
|
|
3817
|
-
|
|
3896
|
+
function settingsPath() {
|
|
3897
|
+
return path17.join(os5.homedir(), ".claude", "settings.json");
|
|
3898
|
+
}
|
|
3818
3899
|
var OWNER_TAG = "_workHookOwner";
|
|
3819
3900
|
var PID_TAG = "_workHookPid";
|
|
3820
3901
|
var LEGACY_TAGS = ["_workDash", "_work2Dash"];
|
|
3821
3902
|
function readSettings() {
|
|
3822
3903
|
try {
|
|
3823
|
-
|
|
3824
|
-
|
|
3904
|
+
const p = settingsPath();
|
|
3905
|
+
if (!fs22.existsSync(p)) return {};
|
|
3906
|
+
return JSON.parse(fs22.readFileSync(p, "utf8"));
|
|
3825
3907
|
} catch {
|
|
3826
3908
|
return {};
|
|
3827
3909
|
}
|
|
3828
3910
|
}
|
|
3829
3911
|
function writeAtomic(s) {
|
|
3830
3912
|
try {
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3913
|
+
const target = resolveLinkTarget(settingsPath());
|
|
3914
|
+
fs22.mkdirSync(path17.dirname(target), { recursive: true });
|
|
3915
|
+
atomicWriteFile(target, `${JSON.stringify(s, null, 2)}
|
|
3916
|
+
`);
|
|
3835
3917
|
} catch {
|
|
3836
3918
|
}
|
|
3837
3919
|
}
|
|
@@ -4003,7 +4085,7 @@ function removeHttpHooksSync(owner) {
|
|
|
4003
4085
|
editSettingsSync(mutateRemove(owner));
|
|
4004
4086
|
}
|
|
4005
4087
|
function normalizePath(p) {
|
|
4006
|
-
return
|
|
4088
|
+
return path18.resolve(p).toLowerCase();
|
|
4007
4089
|
}
|
|
4008
4090
|
|
|
4009
4091
|
// src/core/notifier.ts
|
|
@@ -5080,20 +5162,8 @@ var DETACH_KEY = "";
|
|
|
5080
5162
|
var TAB_KEY = " ";
|
|
5081
5163
|
var RENDER_INTERVAL_MS = 50;
|
|
5082
5164
|
var MOUSE_SGR_RE = /\x1b\[<(\d+);(\d+);(\d+)[Mm]/;
|
|
5083
|
-
function hasClaudeConversation(dir) {
|
|
5084
|
-
try {
|
|
5085
|
-
const resolved = path18.resolve(dir);
|
|
5086
|
-
const projectDir = resolved.replace(/[^a-zA-Z0-9-]/g, "-");
|
|
5087
|
-
const claudeProjectPath = path18.join(os6.homedir(), ".claude", "projects", projectDir);
|
|
5088
|
-
if (!fs23.existsSync(claudeProjectPath)) return false;
|
|
5089
|
-
const files = fs23.readdirSync(claudeProjectPath);
|
|
5090
|
-
return files.some((f) => f.endsWith(".jsonl"));
|
|
5091
|
-
} catch {
|
|
5092
|
-
return false;
|
|
5093
|
-
}
|
|
5094
|
-
}
|
|
5095
5165
|
function ptyDedupKey(pty2) {
|
|
5096
|
-
return
|
|
5166
|
+
return path19.resolve(pty2.cwd).toLowerCase();
|
|
5097
5167
|
}
|
|
5098
5168
|
function loadSessions() {
|
|
5099
5169
|
const all = loadHistory();
|
|
@@ -5128,7 +5198,13 @@ function generateSlug(summary) {
|
|
|
5128
5198
|
const child = execFile4(
|
|
5129
5199
|
"claude",
|
|
5130
5200
|
["-p", "--model", "haiku"],
|
|
5131
|
-
{
|
|
5201
|
+
{
|
|
5202
|
+
encoding: "utf-8",
|
|
5203
|
+
timeout: 1e4,
|
|
5204
|
+
windowsHide: true,
|
|
5205
|
+
// Internal call — don't trip work's checkpoint hooks (see internal-claude.ts).
|
|
5206
|
+
env: { ...process.env, ...internalClaudeEnv() }
|
|
5207
|
+
},
|
|
5132
5208
|
(err, stdout) => {
|
|
5133
5209
|
const result = stdout?.trim().toLowerCase().replace(/[^a-z0-9-]/g, "").replace(/^-|-$/g, "");
|
|
5134
5210
|
resolve(result || fallback);
|
|
@@ -5387,10 +5463,10 @@ function App({ unsafe, onExit }) {
|
|
|
5387
5463
|
}
|
|
5388
5464
|
}, [setScrollBack, renderTermAtScroll]);
|
|
5389
5465
|
const findPtyByCwd = useCallback((cwd) => {
|
|
5390
|
-
const normalized =
|
|
5466
|
+
const normalized = path19.resolve(cwd).toLowerCase();
|
|
5391
5467
|
for (const pty2 of ptySessions.current.values()) {
|
|
5392
5468
|
if (pty2.exited) continue;
|
|
5393
|
-
if (normalized.startsWith(
|
|
5469
|
+
if (normalized.startsWith(path19.resolve(pty2.cwd).toLowerCase())) return pty2;
|
|
5394
5470
|
}
|
|
5395
5471
|
return void 0;
|
|
5396
5472
|
}, []);
|
|
@@ -5466,13 +5542,13 @@ function App({ unsafe, onExit }) {
|
|
|
5466
5542
|
notifiedSessionsRef.current
|
|
5467
5543
|
);
|
|
5468
5544
|
if (kind) {
|
|
5469
|
-
notifyDesktop(
|
|
5545
|
+
notifyDesktop(path19.basename(pty2.cwd), kind, {
|
|
5470
5546
|
enabled: config?.notifications === true
|
|
5471
5547
|
});
|
|
5472
5548
|
runStatusHooks(
|
|
5473
5549
|
kind,
|
|
5474
5550
|
pty2.cwd,
|
|
5475
|
-
|
|
5551
|
+
path19.basename(pty2.cwd),
|
|
5476
5552
|
config?.statusHooks
|
|
5477
5553
|
);
|
|
5478
5554
|
}
|
|
@@ -5605,7 +5681,7 @@ function App({ unsafe, onExit }) {
|
|
|
5605
5681
|
refreshSessions();
|
|
5606
5682
|
return;
|
|
5607
5683
|
}
|
|
5608
|
-
const dir = s.isGroup ?
|
|
5684
|
+
const dir = s.isGroup ? path19.dirname(existing) : existing;
|
|
5609
5685
|
const resume = hasClaudeConversation(dir);
|
|
5610
5686
|
const tool = getAiTool(config ?? {});
|
|
5611
5687
|
const pty2 = new PtySession(dir, termInner, contentHeight - 2, void 0, { tool, unsafe, resume, port: s.port });
|
|
@@ -5703,7 +5779,7 @@ function App({ unsafe, onExit }) {
|
|
|
5703
5779
|
"",
|
|
5704
5780
|
" - Ask if I want to proceed with the recommended approach, choose a different one, get more details, or make adjustments."
|
|
5705
5781
|
].join("\n");
|
|
5706
|
-
promptFile =
|
|
5782
|
+
promptFile = path19.join(os6.tmpdir(), `work-prompt-${Date.now()}.txt`);
|
|
5707
5783
|
fs23.writeFileSync(promptFile, prompt, "utf-8");
|
|
5708
5784
|
}
|
|
5709
5785
|
const setupArgs = ["tree", projectName, branchName, "--setup-only"];
|
|
@@ -5743,7 +5819,7 @@ function App({ unsafe, onExit }) {
|
|
|
5743
5819
|
setStatusVersion((v) => v + 1);
|
|
5744
5820
|
return;
|
|
5745
5821
|
}
|
|
5746
|
-
const launchDir = session.isGroup ?
|
|
5822
|
+
const launchDir = session.isGroup ? path19.dirname(existing) : existing;
|
|
5747
5823
|
const tool = getAiTool(config);
|
|
5748
5824
|
const aiPty = new PtySession(
|
|
5749
5825
|
launchDir,
|
|
@@ -6318,7 +6394,7 @@ function App({ unsafe, onExit }) {
|
|
|
6318
6394
|
setMessage("Session path no longer exists");
|
|
6319
6395
|
return;
|
|
6320
6396
|
}
|
|
6321
|
-
const dir = s.isGroup ?
|
|
6397
|
+
const dir = s.isGroup ? path19.dirname(existing) : existing;
|
|
6322
6398
|
const editor = config?.editor ?? "code";
|
|
6323
6399
|
spawn7(editor, [dir], { detached: true, stdio: "ignore" }).unref();
|
|
6324
6400
|
setMessage(`Opened in ${editor}: ${s.branch}`);
|
|
@@ -6503,7 +6579,7 @@ function crashLog(label2, err) {
|
|
|
6503
6579
|
const msg = err instanceof Error ? err.stack || err.message : String(err);
|
|
6504
6580
|
const line = `${(/* @__PURE__ */ new Date()).toISOString()} [CRASH] ${label2}: ${msg}
|
|
6505
6581
|
`;
|
|
6506
|
-
fs24.appendFileSync(
|
|
6582
|
+
fs24.appendFileSync(path20.join(getConfigDir(), "debug.log"), line);
|
|
6507
6583
|
} catch {
|
|
6508
6584
|
}
|
|
6509
6585
|
}
|
|
@@ -6827,22 +6903,22 @@ import chalk17 from "chalk";
|
|
|
6827
6903
|
|
|
6828
6904
|
// src/core/hydrate.ts
|
|
6829
6905
|
import fs25 from "fs";
|
|
6830
|
-
import
|
|
6906
|
+
import path21 from "path";
|
|
6831
6907
|
async function hydrateHistoryFromDisk(config) {
|
|
6832
|
-
const worktreesRoot =
|
|
6908
|
+
const worktreesRoot = path21.resolve(config.worktreesRoot);
|
|
6833
6909
|
const folderNameToAlias = /* @__PURE__ */ new Map();
|
|
6834
6910
|
for (const [alias, repoPath] of Object.entries(config.repos)) {
|
|
6835
|
-
folderNameToAlias.set(
|
|
6911
|
+
folderNameToAlias.set(path21.basename(repoPath), alias);
|
|
6836
6912
|
}
|
|
6837
6913
|
const discovered = /* @__PURE__ */ new Map();
|
|
6838
6914
|
for (const [alias, repoPath] of Object.entries(config.repos)) {
|
|
6839
6915
|
if (!fs25.existsSync(repoPath)) continue;
|
|
6840
6916
|
for (const entry of parseWorktreeList(repoPath)) {
|
|
6841
6917
|
if (!entry.branch) continue;
|
|
6842
|
-
if (
|
|
6843
|
-
const rel =
|
|
6844
|
-
if (!rel || rel.startsWith("..") ||
|
|
6845
|
-
const parts = rel.split(
|
|
6918
|
+
if (path21.resolve(entry.path) === path21.resolve(repoPath)) continue;
|
|
6919
|
+
const rel = path21.relative(worktreesRoot, entry.path);
|
|
6920
|
+
if (!rel || rel.startsWith("..") || path21.isAbsolute(rel)) continue;
|
|
6921
|
+
const parts = rel.split(path21.sep).filter(Boolean);
|
|
6846
6922
|
if (parts.length < 2) continue;
|
|
6847
6923
|
const [first, second] = parts;
|
|
6848
6924
|
const isGroup = Object.prototype.hasOwnProperty.call(config.groups, first);
|
|
@@ -6927,13 +7003,13 @@ var hydrateCommand = {
|
|
|
6927
7003
|
// src/commands/diff.ts
|
|
6928
7004
|
import fs36 from "fs";
|
|
6929
7005
|
import os9 from "os";
|
|
6930
|
-
import
|
|
7006
|
+
import path32 from "path";
|
|
6931
7007
|
import { spawn as childSpawn } from "child_process";
|
|
6932
7008
|
import chalk21 from "chalk";
|
|
6933
7009
|
|
|
6934
7010
|
// src/core/diff-pipeline.ts
|
|
6935
7011
|
import fs28 from "fs";
|
|
6936
|
-
import
|
|
7012
|
+
import path24 from "path";
|
|
6937
7013
|
import spawn9 from "cross-spawn";
|
|
6938
7014
|
|
|
6939
7015
|
// src/core/diff-parse.ts
|
|
@@ -7082,7 +7158,7 @@ function stripPathPrefix(p) {
|
|
|
7082
7158
|
|
|
7083
7159
|
// src/core/lcov.ts
|
|
7084
7160
|
import fs26 from "fs";
|
|
7085
|
-
import
|
|
7161
|
+
import path22 from "path";
|
|
7086
7162
|
function parseLcov(content) {
|
|
7087
7163
|
const result = /* @__PURE__ */ new Map();
|
|
7088
7164
|
let sf = null;
|
|
@@ -7141,8 +7217,8 @@ function parseLcov(content) {
|
|
|
7141
7217
|
}
|
|
7142
7218
|
function findLcov(root) {
|
|
7143
7219
|
const candidates = [
|
|
7144
|
-
|
|
7145
|
-
|
|
7220
|
+
path22.join(root, "coverage", "lcov.info"),
|
|
7221
|
+
path22.join(root, "lcov.info")
|
|
7146
7222
|
];
|
|
7147
7223
|
for (const c of candidates) {
|
|
7148
7224
|
try {
|
|
@@ -7177,33 +7253,33 @@ function readParsedLcov(lcovPath) {
|
|
|
7177
7253
|
return { parsed, mtimeMs };
|
|
7178
7254
|
}
|
|
7179
7255
|
function normRel(p) {
|
|
7180
|
-
return
|
|
7256
|
+
return path22.normalize(p).replace(/\\/g, "/").replace(/^\.\//, "");
|
|
7181
7257
|
}
|
|
7182
7258
|
function realRoot(root) {
|
|
7183
7259
|
try {
|
|
7184
|
-
return fs26.realpathSync(
|
|
7260
|
+
return fs26.realpathSync(path22.resolve(root));
|
|
7185
7261
|
} catch {
|
|
7186
|
-
return
|
|
7262
|
+
return path22.resolve(root);
|
|
7187
7263
|
}
|
|
7188
7264
|
}
|
|
7189
7265
|
function canonicalize(absPath) {
|
|
7190
|
-
const resolved =
|
|
7266
|
+
const resolved = path22.resolve(absPath);
|
|
7191
7267
|
let dir = resolved;
|
|
7192
7268
|
const tail = [];
|
|
7193
7269
|
for (; ; ) {
|
|
7194
7270
|
try {
|
|
7195
7271
|
const realDir = fs26.realpathSync(dir);
|
|
7196
|
-
return tail.length ?
|
|
7272
|
+
return tail.length ? path22.join(realDir, ...tail.reverse()) : realDir;
|
|
7197
7273
|
} catch {
|
|
7198
|
-
const parent =
|
|
7274
|
+
const parent = path22.dirname(dir);
|
|
7199
7275
|
if (parent === dir) return resolved;
|
|
7200
|
-
tail.push(
|
|
7276
|
+
tail.push(path22.basename(dir));
|
|
7201
7277
|
dir = parent;
|
|
7202
7278
|
}
|
|
7203
7279
|
}
|
|
7204
7280
|
}
|
|
7205
7281
|
function relForAbsSf(absSf, canonRoot) {
|
|
7206
|
-
return
|
|
7282
|
+
return path22.relative(canonRoot, canonicalize(absSf));
|
|
7207
7283
|
}
|
|
7208
7284
|
function coverageLookup(root, relPaths) {
|
|
7209
7285
|
const out = /* @__PURE__ */ new Map();
|
|
@@ -7216,7 +7292,7 @@ function coverageLookup(root, relPaths) {
|
|
|
7216
7292
|
const canonRoot = realRoot(root);
|
|
7217
7293
|
const byRel = /* @__PURE__ */ new Map();
|
|
7218
7294
|
for (const [sf, pct] of read.parsed) {
|
|
7219
|
-
const rel =
|
|
7295
|
+
const rel = path22.isAbsolute(sf) ? relForAbsSf(sf, canonRoot) : sf;
|
|
7220
7296
|
byRel.set(normRel(rel), pct);
|
|
7221
7297
|
}
|
|
7222
7298
|
for (const rp of relPaths) {
|
|
@@ -7229,12 +7305,12 @@ function coverageLookup(root, relPaths) {
|
|
|
7229
7305
|
// src/core/git-tree-snapshot.ts
|
|
7230
7306
|
import fs27 from "fs";
|
|
7231
7307
|
import os7 from "os";
|
|
7232
|
-
import
|
|
7308
|
+
import path23 from "path";
|
|
7233
7309
|
import crypto from "crypto";
|
|
7234
7310
|
import spawn8 from "cross-spawn";
|
|
7235
7311
|
function writeTempTree(repoRoot, opts = {}) {
|
|
7236
7312
|
const includeWorkingTree = opts.includeWorkingTree ?? true;
|
|
7237
|
-
const tmpIndex =
|
|
7313
|
+
const tmpIndex = path23.join(
|
|
7238
7314
|
os7.tmpdir(),
|
|
7239
7315
|
`wd-tree-${process.pid}-${crypto.randomBytes(6).toString("hex")}.idx`
|
|
7240
7316
|
);
|
|
@@ -7279,12 +7355,12 @@ function isMarkdownPath(p) {
|
|
|
7279
7355
|
return p !== "/dev/null" && MARKDOWN_EXT_RE.test(p);
|
|
7280
7356
|
}
|
|
7281
7357
|
function isInsideRoot(root, rel) {
|
|
7282
|
-
const resolvedRoot =
|
|
7283
|
-
const resolvedTarget =
|
|
7284
|
-
const r =
|
|
7358
|
+
const resolvedRoot = path24.resolve(root);
|
|
7359
|
+
const resolvedTarget = path24.resolve(resolvedRoot, rel);
|
|
7360
|
+
const r = path24.relative(resolvedRoot, resolvedTarget);
|
|
7285
7361
|
if (r === "") return true;
|
|
7286
7362
|
if (r.startsWith("..")) return false;
|
|
7287
|
-
if (
|
|
7363
|
+
if (path24.isAbsolute(r)) return false;
|
|
7288
7364
|
return true;
|
|
7289
7365
|
}
|
|
7290
7366
|
function readMarkdownContent(root, file, fromRef, toRef) {
|
|
@@ -7309,10 +7385,10 @@ function readMarkdownContent(root, file, fromRef, toRef) {
|
|
|
7309
7385
|
if (file.status !== "deleted" && isMarkdownPath(file.newPath) && isInsideRoot(root, file.newPath)) {
|
|
7310
7386
|
if (toRef === "working") {
|
|
7311
7387
|
try {
|
|
7312
|
-
const absPath =
|
|
7313
|
-
const realRoot2 = fs28.realpathSync(
|
|
7388
|
+
const absPath = path24.join(root, file.newPath);
|
|
7389
|
+
const realRoot2 = fs28.realpathSync(path24.resolve(root));
|
|
7314
7390
|
const realPath = fs28.realpathSync(absPath);
|
|
7315
|
-
const sep =
|
|
7391
|
+
const sep = path24.sep;
|
|
7316
7392
|
if (realPath === realRoot2 || realPath.startsWith(realRoot2 + sep)) {
|
|
7317
7393
|
result.after = fs28.readFileSync(absPath, "utf-8");
|
|
7318
7394
|
}
|
|
@@ -7342,7 +7418,7 @@ function isBinaryContent(buffer) {
|
|
|
7342
7418
|
return false;
|
|
7343
7419
|
}
|
|
7344
7420
|
function synthesizeUntrackedDiff(root, relPath) {
|
|
7345
|
-
const absPath =
|
|
7421
|
+
const absPath = path24.join(root, relPath);
|
|
7346
7422
|
let buffer;
|
|
7347
7423
|
try {
|
|
7348
7424
|
buffer = fs28.readFileSync(absPath);
|
|
@@ -7433,7 +7509,7 @@ function attachCoverage(root, files) {
|
|
|
7433
7509
|
f.coverageMtimeMs = lcovMtimeMs;
|
|
7434
7510
|
let srcMtimeMs = null;
|
|
7435
7511
|
try {
|
|
7436
|
-
srcMtimeMs = fs28.statSync(
|
|
7512
|
+
srcMtimeMs = fs28.statSync(path24.join(root, f.path)).mtimeMs;
|
|
7437
7513
|
} catch {
|
|
7438
7514
|
srcMtimeMs = null;
|
|
7439
7515
|
}
|
|
@@ -7501,7 +7577,7 @@ function computeRangeDiff(opts) {
|
|
|
7501
7577
|
|
|
7502
7578
|
// src/core/repo-spec.ts
|
|
7503
7579
|
import fs29 from "fs";
|
|
7504
|
-
import
|
|
7580
|
+
import path25 from "path";
|
|
7505
7581
|
import os8 from "os";
|
|
7506
7582
|
import crypto2 from "crypto";
|
|
7507
7583
|
function scopeHashFor(keyPaths) {
|
|
@@ -7509,17 +7585,17 @@ function scopeHashFor(keyPaths) {
|
|
|
7509
7585
|
return crypto2.createHash("sha1").update(key).digest("hex").slice(0, 12);
|
|
7510
7586
|
}
|
|
7511
7587
|
function stableDiffPath(keyPaths) {
|
|
7512
|
-
const dir =
|
|
7588
|
+
const dir = path25.join(os8.homedir(), ".work", "diffs");
|
|
7513
7589
|
fs29.mkdirSync(dir, { recursive: true });
|
|
7514
|
-
return
|
|
7590
|
+
return path25.join(dir, scopeHashFor(keyPaths));
|
|
7515
7591
|
}
|
|
7516
7592
|
|
|
7517
7593
|
// src/core/diff-scope.ts
|
|
7518
7594
|
import fs30 from "fs";
|
|
7519
|
-
import
|
|
7595
|
+
import path26 from "path";
|
|
7520
7596
|
import chalk18 from "chalk";
|
|
7521
7597
|
function normPath(p) {
|
|
7522
|
-
return
|
|
7598
|
+
return path26.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
7523
7599
|
}
|
|
7524
7600
|
function realNorm(p) {
|
|
7525
7601
|
try {
|
|
@@ -7543,29 +7619,29 @@ function resolveScope(cwd) {
|
|
|
7543
7619
|
return {
|
|
7544
7620
|
isGroup: true,
|
|
7545
7621
|
session: s,
|
|
7546
|
-
repos: s.paths.map((rp) => ({ name:
|
|
7547
|
-
activeRepoName:
|
|
7622
|
+
repos: s.paths.map((rp) => ({ name: path26.basename(rp), root: rp })),
|
|
7623
|
+
activeRepoName: path26.basename(p)
|
|
7548
7624
|
};
|
|
7549
7625
|
}
|
|
7550
7626
|
return {
|
|
7551
7627
|
isGroup: false,
|
|
7552
7628
|
session: s,
|
|
7553
|
-
repos: [{ name:
|
|
7554
|
-
activeRepoName:
|
|
7629
|
+
repos: [{ name: path26.basename(p), root: p }],
|
|
7630
|
+
activeRepoName: path26.basename(p)
|
|
7555
7631
|
};
|
|
7556
7632
|
}
|
|
7557
7633
|
}
|
|
7558
7634
|
}
|
|
7559
7635
|
for (const s of sessions) {
|
|
7560
7636
|
if (!s.isGroup || s.paths.length === 0) continue;
|
|
7561
|
-
const parents = s.paths.map((p) => normPath(
|
|
7637
|
+
const parents = s.paths.map((p) => normPath(path26.dirname(p)));
|
|
7562
7638
|
const groupRoot = parents[0];
|
|
7563
7639
|
if (!parents.every((par) => par === groupRoot)) continue;
|
|
7564
7640
|
if (normCwd === groupRoot || normCwd.startsWith(groupRoot + "/")) {
|
|
7565
7641
|
return {
|
|
7566
7642
|
isGroup: true,
|
|
7567
7643
|
session: s,
|
|
7568
|
-
repos: s.paths.map((rp) => ({ name:
|
|
7644
|
+
repos: s.paths.map((rp) => ({ name: path26.basename(rp), root: rp })),
|
|
7569
7645
|
activeRepoName: null
|
|
7570
7646
|
};
|
|
7571
7647
|
}
|
|
@@ -7574,8 +7650,8 @@ function resolveScope(cwd) {
|
|
|
7574
7650
|
return {
|
|
7575
7651
|
isGroup: false,
|
|
7576
7652
|
session: null,
|
|
7577
|
-
repos: [{ name:
|
|
7578
|
-
activeRepoName:
|
|
7653
|
+
repos: [{ name: path26.basename(toplevel), root: toplevel }],
|
|
7654
|
+
activeRepoName: path26.basename(toplevel)
|
|
7579
7655
|
};
|
|
7580
7656
|
}
|
|
7581
7657
|
function findAnyParentBranch(cwd) {
|
|
@@ -7759,7 +7835,7 @@ import { streamSSE } from "hono/streaming";
|
|
|
7759
7835
|
|
|
7760
7836
|
// src/core/file-context.ts
|
|
7761
7837
|
import fs31 from "fs";
|
|
7762
|
-
import
|
|
7838
|
+
import path27 from "path";
|
|
7763
7839
|
import spawn10 from "cross-spawn";
|
|
7764
7840
|
function readContextLines(opts) {
|
|
7765
7841
|
const { root, relPath, ref } = opts;
|
|
@@ -7781,10 +7857,10 @@ function readContextLines(opts) {
|
|
|
7781
7857
|
}
|
|
7782
7858
|
function readWorkingTree(root, relPath) {
|
|
7783
7859
|
try {
|
|
7784
|
-
const absPath =
|
|
7785
|
-
const realRoot2 = fs31.realpathSync(
|
|
7860
|
+
const absPath = path27.join(root, relPath);
|
|
7861
|
+
const realRoot2 = fs31.realpathSync(path27.resolve(root));
|
|
7786
7862
|
const realPath = fs31.realpathSync(absPath);
|
|
7787
|
-
const sep =
|
|
7863
|
+
const sep = path27.sep;
|
|
7788
7864
|
if (realPath !== realRoot2 && !realPath.startsWith(realRoot2 + sep)) {
|
|
7789
7865
|
return null;
|
|
7790
7866
|
}
|
|
@@ -7806,7 +7882,7 @@ function readAtRef(root, ref, relPath) {
|
|
|
7806
7882
|
|
|
7807
7883
|
// src/core/fs-watcher.ts
|
|
7808
7884
|
import fs32 from "fs";
|
|
7809
|
-
import
|
|
7885
|
+
import path28 from "path";
|
|
7810
7886
|
import chalk19 from "chalk";
|
|
7811
7887
|
import chokidar from "chokidar";
|
|
7812
7888
|
var IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
@@ -7832,7 +7908,7 @@ var IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
|
7832
7908
|
]);
|
|
7833
7909
|
function isIgnoredWatchPath(roots, filePath) {
|
|
7834
7910
|
for (const root of roots) {
|
|
7835
|
-
const rel =
|
|
7911
|
+
const rel = path28.relative(root, filePath).replace(/\\/g, "/");
|
|
7836
7912
|
if (rel === "" || rel.startsWith("../")) continue;
|
|
7837
7913
|
if (rel.split("/").some((seg) => IGNORED_DIRS.has(seg))) return true;
|
|
7838
7914
|
}
|
|
@@ -7857,7 +7933,7 @@ function createFsWatcher(opts) {
|
|
|
7857
7933
|
if (SUPPORTS_RECURSIVE_WATCH) {
|
|
7858
7934
|
const watchers = opts.roots.map((root) => {
|
|
7859
7935
|
const w = fs32.watch(root, { recursive: true }, (_event, filename) => {
|
|
7860
|
-
if (filename && isIgnoredWatchPath([root],
|
|
7936
|
+
if (filename && isIgnoredWatchPath([root], path28.join(root, filename.toString()))) {
|
|
7861
7937
|
return;
|
|
7862
7938
|
}
|
|
7863
7939
|
fire();
|
|
@@ -7896,29 +7972,29 @@ function createFsWatcher(opts) {
|
|
|
7896
7972
|
|
|
7897
7973
|
// src/core/web-static.ts
|
|
7898
7974
|
import fs33 from "fs";
|
|
7899
|
-
import
|
|
7975
|
+
import path29 from "path";
|
|
7900
7976
|
import { fileURLToPath } from "url";
|
|
7901
7977
|
function resolveWebRoot() {
|
|
7902
|
-
const entryDir =
|
|
7903
|
-
const moduleDir =
|
|
7978
|
+
const entryDir = path29.dirname(process.argv[1] ?? "");
|
|
7979
|
+
const moduleDir = path29.dirname(fileURLToPath(import.meta.url));
|
|
7904
7980
|
const candidates = [
|
|
7905
|
-
|
|
7981
|
+
path29.join(entryDir, "web"),
|
|
7906
7982
|
// bundled: this module is inlined into dist/<bin>.js, so dist/web is a
|
|
7907
7983
|
// sibling of the bundle. Works even when argv[1] is an npm bin symlink
|
|
7908
7984
|
// (which is not realpath'd, so the entryDir candidate above misses).
|
|
7909
|
-
|
|
7985
|
+
path29.join(moduleDir, "web"),
|
|
7910
7986
|
// dev/tsx fallback: walk up from src/core to repo root then into dist/web.
|
|
7911
|
-
|
|
7987
|
+
path29.resolve(moduleDir, "../../dist/web")
|
|
7912
7988
|
];
|
|
7913
7989
|
for (const c of candidates) {
|
|
7914
|
-
if (fs33.existsSync(
|
|
7990
|
+
if (fs33.existsSync(path29.join(c, "index.html"))) return c;
|
|
7915
7991
|
}
|
|
7916
7992
|
return null;
|
|
7917
7993
|
}
|
|
7918
7994
|
|
|
7919
7995
|
// src/core/spa-handler.ts
|
|
7920
7996
|
import fs34 from "fs";
|
|
7921
|
-
import
|
|
7997
|
+
import path30 from "path";
|
|
7922
7998
|
var MIME = {
|
|
7923
7999
|
".html": "text/html; charset=utf-8",
|
|
7924
8000
|
".js": "application/javascript; charset=utf-8",
|
|
@@ -7932,9 +8008,9 @@ var MIME = {
|
|
|
7932
8008
|
function readFile(root, relPath) {
|
|
7933
8009
|
const clean = relPath.split("?")[0];
|
|
7934
8010
|
const requested = clean === "/" ? "/index.html" : clean;
|
|
7935
|
-
const filePath =
|
|
7936
|
-
const norm =
|
|
7937
|
-
if (!norm.startsWith(
|
|
8011
|
+
const filePath = path30.join(root, requested);
|
|
8012
|
+
const norm = path30.normalize(filePath);
|
|
8013
|
+
if (!norm.startsWith(path30.normalize(root))) return null;
|
|
7938
8014
|
let stat;
|
|
7939
8015
|
try {
|
|
7940
8016
|
stat = fs34.statSync(norm);
|
|
@@ -7942,7 +8018,7 @@ function readFile(root, relPath) {
|
|
|
7942
8018
|
return null;
|
|
7943
8019
|
}
|
|
7944
8020
|
if (!stat.isFile()) return null;
|
|
7945
|
-
const ext =
|
|
8021
|
+
const ext = path30.extname(norm).toLowerCase();
|
|
7946
8022
|
return { body: fs34.readFileSync(norm), ext };
|
|
7947
8023
|
}
|
|
7948
8024
|
function serveSpa(c, webRoot) {
|
|
@@ -8252,7 +8328,7 @@ function diffReviewSnapshot(snapshot, seen) {
|
|
|
8252
8328
|
|
|
8253
8329
|
// src/core/static-renderer.ts
|
|
8254
8330
|
import fs35 from "fs";
|
|
8255
|
-
import
|
|
8331
|
+
import path31 from "path";
|
|
8256
8332
|
function buildDiff(specs, resolvedBase) {
|
|
8257
8333
|
return {
|
|
8258
8334
|
repos: specs.map((r) => ({
|
|
@@ -8268,7 +8344,7 @@ function renderStatic(opts) {
|
|
|
8268
8344
|
if (!webRoot) {
|
|
8269
8345
|
throw new Error("Could not find dist/web/. Run `npm run build` first.");
|
|
8270
8346
|
}
|
|
8271
|
-
const shellPath =
|
|
8347
|
+
const shellPath = path31.join(webRoot, "index.html");
|
|
8272
8348
|
let shell = fs35.readFileSync(shellPath, "utf-8");
|
|
8273
8349
|
const uncommitted = buildDiff(opts.uncommitted, "HEAD");
|
|
8274
8350
|
const branch = opts.branch ? buildDiff(opts.branch.specs, opts.branch.resolvedBase) : void 0;
|
|
@@ -8318,8 +8394,8 @@ function escapeForScriptTag(json) {
|
|
|
8318
8394
|
}
|
|
8319
8395
|
function readAsset(webRoot, urlPath) {
|
|
8320
8396
|
const clean = urlPath.split("?")[0].replace(/^\//, "");
|
|
8321
|
-
const full =
|
|
8322
|
-
if (!
|
|
8397
|
+
const full = path31.join(webRoot, clean);
|
|
8398
|
+
if (!path31.normalize(full).startsWith(path31.normalize(webRoot))) return null;
|
|
8323
8399
|
try {
|
|
8324
8400
|
return fs35.readFileSync(full, "utf-8");
|
|
8325
8401
|
} catch {
|
|
@@ -8362,7 +8438,7 @@ async function runStop(repoSpecs) {
|
|
|
8362
8438
|
}
|
|
8363
8439
|
}
|
|
8364
8440
|
function webUrlFilePath() {
|
|
8365
|
-
return
|
|
8441
|
+
return path32.join(os9.homedir(), ".work", "web.url");
|
|
8366
8442
|
}
|
|
8367
8443
|
function resolveWorkBinPath(selfArgv1) {
|
|
8368
8444
|
let real = selfArgv1;
|
|
@@ -8371,7 +8447,7 @@ function resolveWorkBinPath(selfArgv1) {
|
|
|
8371
8447
|
} catch {
|
|
8372
8448
|
}
|
|
8373
8449
|
if (real.endsWith("wd-bin.js")) {
|
|
8374
|
-
return
|
|
8450
|
+
return path32.join(path32.dirname(real), "bin.js");
|
|
8375
8451
|
}
|
|
8376
8452
|
return real;
|
|
8377
8453
|
}
|
|
@@ -8408,7 +8484,7 @@ async function ensureWorkWebRunning() {
|
|
|
8408
8484
|
}
|
|
8409
8485
|
const workBin = resolveWorkBinPath(process.argv[1]);
|
|
8410
8486
|
const out = fs36.openSync(
|
|
8411
|
-
|
|
8487
|
+
path32.join(os9.homedir(), ".work", "web-autostart.log"),
|
|
8412
8488
|
"a"
|
|
8413
8489
|
);
|
|
8414
8490
|
const child = childSpawn(
|
|
@@ -8750,19 +8826,19 @@ var diffCommand = {
|
|
|
8750
8826
|
// src/commands/web.ts
|
|
8751
8827
|
import fs41 from "fs";
|
|
8752
8828
|
import os13 from "os";
|
|
8753
|
-
import
|
|
8829
|
+
import path42 from "path";
|
|
8754
8830
|
import chalk23 from "chalk";
|
|
8755
8831
|
|
|
8756
8832
|
// src/core/web-server.ts
|
|
8757
8833
|
import fs40 from "fs";
|
|
8758
8834
|
import os12 from "os";
|
|
8759
|
-
import
|
|
8835
|
+
import path41 from "path";
|
|
8760
8836
|
import chalk22 from "chalk";
|
|
8761
8837
|
import { Hono as Hono3 } from "hono";
|
|
8762
8838
|
import { streamSSE as streamSSE3 } from "hono/streaming";
|
|
8763
8839
|
|
|
8764
8840
|
// src/core/web-state.ts
|
|
8765
|
-
import
|
|
8841
|
+
import path33 from "path";
|
|
8766
8842
|
import crypto4 from "crypto";
|
|
8767
8843
|
import chokidar2 from "chokidar";
|
|
8768
8844
|
function sessionIdFor(s) {
|
|
@@ -8783,7 +8859,7 @@ function subscribeSession(sessionId, onChange) {
|
|
|
8783
8859
|
const watcher = chokidar2.watch(roots, {
|
|
8784
8860
|
ignored: (filePath) => {
|
|
8785
8861
|
for (const r of roots) {
|
|
8786
|
-
const rel =
|
|
8862
|
+
const rel = path33.relative(r, filePath).replace(/\\/g, "/");
|
|
8787
8863
|
if (rel === ".git" || rel.startsWith(".git/")) return true;
|
|
8788
8864
|
}
|
|
8789
8865
|
return false;
|
|
@@ -8898,16 +8974,16 @@ function disposeAllPtys() {
|
|
|
8898
8974
|
|
|
8899
8975
|
// src/core/comment-file-store.ts
|
|
8900
8976
|
import fs37 from "fs";
|
|
8901
|
-
import
|
|
8977
|
+
import path34 from "path";
|
|
8902
8978
|
import os10 from "os";
|
|
8903
8979
|
function commentsDir() {
|
|
8904
|
-
return
|
|
8980
|
+
return path34.join(os10.homedir(), ".work", "comments");
|
|
8905
8981
|
}
|
|
8906
8982
|
function ensureDir() {
|
|
8907
8983
|
fs37.mkdirSync(commentsDir(), { recursive: true });
|
|
8908
8984
|
}
|
|
8909
8985
|
function commentsFileFor(sessionId) {
|
|
8910
|
-
return
|
|
8986
|
+
return path34.join(commentsDir(), `${sessionId}.json`);
|
|
8911
8987
|
}
|
|
8912
8988
|
function pathFor(sessionId) {
|
|
8913
8989
|
return commentsFileFor(sessionId);
|
|
@@ -9001,11 +9077,11 @@ function clearCommentStoreCache() {
|
|
|
9001
9077
|
|
|
9002
9078
|
// src/core/pending-delivery.ts
|
|
9003
9079
|
import fs38 from "fs";
|
|
9004
|
-
import
|
|
9080
|
+
import path35 from "path";
|
|
9005
9081
|
function pathFor2(sessionId) {
|
|
9006
9082
|
return {
|
|
9007
9083
|
comments: commentsFileFor(sessionId),
|
|
9008
|
-
delivered:
|
|
9084
|
+
delivered: path35.join(commentsDir(), `${sessionId}.delivered.json`)
|
|
9009
9085
|
};
|
|
9010
9086
|
}
|
|
9011
9087
|
function readJson(filePath, fallback) {
|
|
@@ -9016,13 +9092,11 @@ function readJson(filePath, fallback) {
|
|
|
9016
9092
|
}
|
|
9017
9093
|
}
|
|
9018
9094
|
function writeAtomic2(filePath, content) {
|
|
9019
|
-
fs38.mkdirSync(
|
|
9020
|
-
|
|
9021
|
-
fs38.writeFileSync(tmp, content, "utf-8");
|
|
9022
|
-
fs38.renameSync(tmp, filePath);
|
|
9095
|
+
fs38.mkdirSync(path35.dirname(filePath), { recursive: true });
|
|
9096
|
+
atomicWriteFile(filePath, content);
|
|
9023
9097
|
}
|
|
9024
9098
|
function normalize(p) {
|
|
9025
|
-
return
|
|
9099
|
+
return path35.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
9026
9100
|
}
|
|
9027
9101
|
function findSessionForCwd(cwd) {
|
|
9028
9102
|
const norm = normalize(cwd);
|
|
@@ -9053,7 +9127,7 @@ function readPendingForSession(sessionId) {
|
|
|
9053
9127
|
return comments.filter(isPendingFor(delivered));
|
|
9054
9128
|
}
|
|
9055
9129
|
function scopeStoreIdsForPaths(paths) {
|
|
9056
|
-
const resolved = paths.map((p) =>
|
|
9130
|
+
const resolved = paths.map((p) => path35.resolve(p));
|
|
9057
9131
|
const ids = /* @__PURE__ */ new Set();
|
|
9058
9132
|
ids.add(`scope-${scopeHashFor(resolved)}`);
|
|
9059
9133
|
for (const p of resolved) ids.add(`scope-${scopeHashFor([p])}`);
|
|
@@ -9391,7 +9465,7 @@ function mountPanesRoutes(app, opts) {
|
|
|
9391
9465
|
}
|
|
9392
9466
|
|
|
9393
9467
|
// src/core/worktree-routes.ts
|
|
9394
|
-
import
|
|
9468
|
+
import path36 from "path";
|
|
9395
9469
|
import { spawn as spawn11 } from "child_process";
|
|
9396
9470
|
import { zValidator as zValidator4 } from "@hono/zod-validator";
|
|
9397
9471
|
import { z as z3 } from "zod";
|
|
@@ -9515,7 +9589,7 @@ function mountWorktreeRoutes(app, opts) {
|
|
|
9515
9589
|
const id = c.req.param("id");
|
|
9516
9590
|
const session = findSession2(id);
|
|
9517
9591
|
if (!session) return c.json({ error: "unknown session" }, 404);
|
|
9518
|
-
const target = session.isGroup ?
|
|
9592
|
+
const target = session.isGroup ? path36.dirname(session.paths[0]) : session.paths[0];
|
|
9519
9593
|
try {
|
|
9520
9594
|
const cmd = process.platform === "win32" ? "code.cmd" : "code";
|
|
9521
9595
|
const child = spawn11(cmd, [target], {
|
|
@@ -9535,18 +9609,18 @@ function mountWorktreeRoutes(app, opts) {
|
|
|
9535
9609
|
import { zValidator as zValidator5 } from "@hono/zod-validator";
|
|
9536
9610
|
import { z as z4 } from "zod";
|
|
9537
9611
|
import { EventEmitter } from "events";
|
|
9538
|
-
import
|
|
9612
|
+
import path40 from "path";
|
|
9539
9613
|
import spawn14 from "cross-spawn";
|
|
9540
9614
|
|
|
9541
9615
|
// src/core/checkpoint.ts
|
|
9542
9616
|
import fs39 from "fs";
|
|
9543
9617
|
import os11 from "os";
|
|
9544
|
-
import
|
|
9618
|
+
import path37 from "path";
|
|
9545
9619
|
import spawn12 from "cross-spawn";
|
|
9546
9620
|
function manifestPath(scopeHash) {
|
|
9547
|
-
const dir =
|
|
9621
|
+
const dir = path37.join(os11.homedir(), ".work", "diffs");
|
|
9548
9622
|
fs39.mkdirSync(dir, { recursive: true });
|
|
9549
|
-
return
|
|
9623
|
+
return path37.join(dir, `${scopeHash}.checkpoints.json`);
|
|
9550
9624
|
}
|
|
9551
9625
|
function emptyManifest(scopeHash) {
|
|
9552
9626
|
return { version: 1, scopeHash, entries: [] };
|
|
@@ -9665,6 +9739,106 @@ async function takeCheckpoint(scopeHash, repos, opts = {}) {
|
|
|
9665
9739
|
return entry;
|
|
9666
9740
|
});
|
|
9667
9741
|
}
|
|
9742
|
+
async function updateCheckpoint(scopeHash, repos, id) {
|
|
9743
|
+
const file = manifestPath(scopeHash);
|
|
9744
|
+
ensureFile(file, JSON.stringify(emptyManifest(scopeHash), null, 2));
|
|
9745
|
+
return withFileLock(file, () => {
|
|
9746
|
+
const manifest = loadManifest(scopeHash);
|
|
9747
|
+
const entry = manifest.entries.find((e) => e.id === id);
|
|
9748
|
+
if (!entry) return { status: "missing" };
|
|
9749
|
+
const refName = `refs/wd/${scopeHash}/${id}`;
|
|
9750
|
+
const restoreRefs = () => {
|
|
9751
|
+
for (const repo of repos) {
|
|
9752
|
+
const old = entry.repos[repo.name] ?? null;
|
|
9753
|
+
if (old) {
|
|
9754
|
+
spawn12.sync("git", ["update-ref", refName, old], {
|
|
9755
|
+
cwd: repo.root,
|
|
9756
|
+
encoding: "utf-8",
|
|
9757
|
+
windowsHide: true
|
|
9758
|
+
});
|
|
9759
|
+
} else {
|
|
9760
|
+
spawn12.sync("git", ["update-ref", "-d", refName], {
|
|
9761
|
+
cwd: repo.root,
|
|
9762
|
+
encoding: "utf-8",
|
|
9763
|
+
windowsHide: true
|
|
9764
|
+
});
|
|
9765
|
+
}
|
|
9766
|
+
}
|
|
9767
|
+
};
|
|
9768
|
+
const captured = {};
|
|
9769
|
+
for (const repo of repos) {
|
|
9770
|
+
captured[repo.name] = snapshotRepo(repo.root, scopeHash, id, true);
|
|
9771
|
+
}
|
|
9772
|
+
if (repos.some((r) => captured[r.name] === null)) {
|
|
9773
|
+
restoreRefs();
|
|
9774
|
+
return { status: "missing" };
|
|
9775
|
+
}
|
|
9776
|
+
const treeOf = (root, commitSha) => {
|
|
9777
|
+
if (!commitSha) return null;
|
|
9778
|
+
const r = spawn12.sync("git", ["rev-parse", `${commitSha}^{tree}`], {
|
|
9779
|
+
cwd: root,
|
|
9780
|
+
encoding: "utf-8",
|
|
9781
|
+
windowsHide: true
|
|
9782
|
+
});
|
|
9783
|
+
if (r.status !== 0 || typeof r.stdout !== "string") return null;
|
|
9784
|
+
return r.stdout.trim() || null;
|
|
9785
|
+
};
|
|
9786
|
+
const unchanged = repos.every((repo) => {
|
|
9787
|
+
const curTree = treeOf(repo.root, captured[repo.name]);
|
|
9788
|
+
const prevTree = treeOf(repo.root, entry.repos[repo.name] ?? null);
|
|
9789
|
+
return curTree !== null && curTree === prevTree;
|
|
9790
|
+
});
|
|
9791
|
+
if (unchanged) {
|
|
9792
|
+
restoreRefs();
|
|
9793
|
+
return { status: "unchanged" };
|
|
9794
|
+
}
|
|
9795
|
+
entry.repos = captured;
|
|
9796
|
+
entry.ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
9797
|
+
delete entry.label;
|
|
9798
|
+
atomicWriteFile(file, JSON.stringify(manifest, null, 2));
|
|
9799
|
+
return { status: "updated", entry };
|
|
9800
|
+
});
|
|
9801
|
+
}
|
|
9802
|
+
async function resetBaseline(scopeHash, repos) {
|
|
9803
|
+
const file = manifestPath(scopeHash);
|
|
9804
|
+
ensureFile(file, JSON.stringify(emptyManifest(scopeHash), null, 2));
|
|
9805
|
+
return withFileLock(file, () => {
|
|
9806
|
+
const prevIds = loadManifest(scopeHash).entries.map((e) => e.id);
|
|
9807
|
+
const captured = {};
|
|
9808
|
+
for (const repo of repos) {
|
|
9809
|
+
captured[repo.name] = snapshotRepo(repo.root, scopeHash, 0, false);
|
|
9810
|
+
}
|
|
9811
|
+
const delRef = (id) => {
|
|
9812
|
+
for (const repo of repos) {
|
|
9813
|
+
spawn12.sync("git", ["update-ref", "-d", `refs/wd/${scopeHash}/${id}`], {
|
|
9814
|
+
cwd: repo.root,
|
|
9815
|
+
encoding: "utf-8",
|
|
9816
|
+
windowsHide: true
|
|
9817
|
+
});
|
|
9818
|
+
}
|
|
9819
|
+
};
|
|
9820
|
+
if (repos.some((r) => captured[r.name] === null)) {
|
|
9821
|
+
delRef(0);
|
|
9822
|
+
return null;
|
|
9823
|
+
}
|
|
9824
|
+
for (const id of prevIds) {
|
|
9825
|
+
if (id !== 0) delRef(id);
|
|
9826
|
+
}
|
|
9827
|
+
const entry = {
|
|
9828
|
+
id: 0,
|
|
9829
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9830
|
+
label: "Initial",
|
|
9831
|
+
repos: captured
|
|
9832
|
+
};
|
|
9833
|
+
const manifest = {
|
|
9834
|
+
version: 1,
|
|
9835
|
+
scopeHash,
|
|
9836
|
+
entries: [entry]
|
|
9837
|
+
};
|
|
9838
|
+
atomicWriteFile(file, JSON.stringify(manifest, null, 2));
|
|
9839
|
+
return entry;
|
|
9840
|
+
});
|
|
9841
|
+
}
|
|
9668
9842
|
async function setCheckpointLabel(scopeHash, id, label2) {
|
|
9669
9843
|
const file = manifestPath(scopeHash);
|
|
9670
9844
|
ensureFile(file, JSON.stringify(emptyManifest(scopeHash), null, 2));
|
|
@@ -9676,6 +9850,29 @@ async function setCheckpointLabel(scopeHash, id, label2) {
|
|
|
9676
9850
|
atomicWriteFile(file, JSON.stringify(manifest, null, 2));
|
|
9677
9851
|
});
|
|
9678
9852
|
}
|
|
9853
|
+
function headAdvancedSinceInitial(scopeHash, repos) {
|
|
9854
|
+
const manifest = loadManifest(scopeHash);
|
|
9855
|
+
const initial = manifest.entries.find((e) => e.id === 0);
|
|
9856
|
+
if (!initial) return false;
|
|
9857
|
+
const treeOf = (root, rev) => {
|
|
9858
|
+
const r = spawn12.sync("git", ["rev-parse", `${rev}^{tree}`], {
|
|
9859
|
+
cwd: root,
|
|
9860
|
+
encoding: "utf-8",
|
|
9861
|
+
windowsHide: true
|
|
9862
|
+
});
|
|
9863
|
+
if (r.status !== 0 || typeof r.stdout !== "string") return null;
|
|
9864
|
+
return r.stdout.trim() || null;
|
|
9865
|
+
};
|
|
9866
|
+
return repos.some((repo) => {
|
|
9867
|
+
const headTree = treeOf(repo.root, "HEAD");
|
|
9868
|
+
if (headTree === null) return false;
|
|
9869
|
+
const baselineSha = initial.repos[repo.name];
|
|
9870
|
+
if (!baselineSha) return true;
|
|
9871
|
+
const baselineTree = treeOf(repo.root, baselineSha);
|
|
9872
|
+
if (baselineTree === null) return false;
|
|
9873
|
+
return baselineTree !== headTree;
|
|
9874
|
+
});
|
|
9875
|
+
}
|
|
9679
9876
|
function clearCheckpoints(scopeHash, repoRoots) {
|
|
9680
9877
|
const manifest = loadManifest(scopeHash);
|
|
9681
9878
|
for (const root of repoRoots) {
|
|
@@ -9699,7 +9896,7 @@ function clearCheckpoints(scopeHash, repoRoots) {
|
|
|
9699
9896
|
|
|
9700
9897
|
// src/core/checkpoint-summary.ts
|
|
9701
9898
|
import spawn13 from "cross-spawn";
|
|
9702
|
-
import
|
|
9899
|
+
import path38 from "path";
|
|
9703
9900
|
var MAX_DIFF_CHARS = 6e3;
|
|
9704
9901
|
var MAX_LABEL_CHARS = 80;
|
|
9705
9902
|
function buildDelta(scopeHash, repos, id) {
|
|
@@ -9752,7 +9949,7 @@ function buildDelta(scopeHash, repos, id) {
|
|
|
9752
9949
|
function heuristicLabel(files, added, deleted) {
|
|
9753
9950
|
if (files.length === 0) return "no changes";
|
|
9754
9951
|
if (files.length === 1) {
|
|
9755
|
-
return `${
|
|
9952
|
+
return `${path38.basename(files[0].path)} +${added} \u2212${deleted}`;
|
|
9756
9953
|
}
|
|
9757
9954
|
return `${files.length} files \xB7 +${added} \u2212${deleted}`;
|
|
9758
9955
|
}
|
|
@@ -9769,7 +9966,10 @@ function runClaude(prompt, timeoutMs = 25e3) {
|
|
|
9769
9966
|
try {
|
|
9770
9967
|
child = spawn13("claude", ["-p"], {
|
|
9771
9968
|
stdio: ["pipe", "pipe", "ignore"],
|
|
9772
|
-
windowsHide: true
|
|
9969
|
+
windowsHide: true,
|
|
9970
|
+
// Tag as internal so this naming run doesn't recursively trip work's
|
|
9971
|
+
// own UserPromptSubmit/Stop checkpoint hooks (see internal-claude.ts).
|
|
9972
|
+
env: { ...process.env, ...internalClaudeEnv() }
|
|
9773
9973
|
});
|
|
9774
9974
|
} catch {
|
|
9775
9975
|
finish(null);
|
|
@@ -9820,7 +10020,7 @@ async function summarizeCheckpoint(scopeHash, repos, id) {
|
|
|
9820
10020
|
}
|
|
9821
10021
|
|
|
9822
10022
|
// src/core/scope-manager.ts
|
|
9823
|
-
import
|
|
10023
|
+
import path39 from "path";
|
|
9824
10024
|
import crypto5 from "crypto";
|
|
9825
10025
|
var scopes = /* @__PURE__ */ new Map();
|
|
9826
10026
|
function hashFor(paths) {
|
|
@@ -9837,7 +10037,7 @@ var ScopePathRejectedError = class extends Error {
|
|
|
9837
10037
|
}
|
|
9838
10038
|
};
|
|
9839
10039
|
function normaliseForCompare(p) {
|
|
9840
|
-
return
|
|
10040
|
+
return path39.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
9841
10041
|
}
|
|
9842
10042
|
function rejectedPaths(normalised) {
|
|
9843
10043
|
const config = loadConfig();
|
|
@@ -9855,7 +10055,7 @@ function rejectedPaths(normalised) {
|
|
|
9855
10055
|
});
|
|
9856
10056
|
}
|
|
9857
10057
|
function registerScope(paths, label2) {
|
|
9858
|
-
const normalised = paths.map((p) =>
|
|
10058
|
+
const normalised = paths.map((p) => path39.resolve(p));
|
|
9859
10059
|
const rejected = rejectedPaths(normalised);
|
|
9860
10060
|
if (rejected.length > 0) throw new ScopePathRejectedError(rejected);
|
|
9861
10061
|
const hash = hashFor(normalised);
|
|
@@ -9869,7 +10069,7 @@ function registerScope(paths, label2) {
|
|
|
9869
10069
|
const scope = {
|
|
9870
10070
|
hash,
|
|
9871
10071
|
paths: normalised,
|
|
9872
|
-
label: label2 ??
|
|
10072
|
+
label: label2 ?? path39.basename(normalised[0]),
|
|
9873
10073
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9874
10074
|
ended: false
|
|
9875
10075
|
};
|
|
@@ -9965,6 +10165,8 @@ import { streamSSE as streamSSE2 } from "hono/streaming";
|
|
|
9965
10165
|
function mountScopeRoutes(app, opts) {
|
|
9966
10166
|
const checkpointWatched = /* @__PURE__ */ new Set();
|
|
9967
10167
|
const lastStatus = /* @__PURE__ */ new Map();
|
|
10168
|
+
const liveCheckpoint = /* @__PURE__ */ new Map();
|
|
10169
|
+
const summarizing = /* @__PURE__ */ new Set();
|
|
9968
10170
|
const snapshotTimers = /* @__PURE__ */ new Map();
|
|
9969
10171
|
const CHECKPOINT_SETTLE_MS = 4e3;
|
|
9970
10172
|
const CLAUDE_SESSION_MS = 5 * 6e4;
|
|
@@ -9989,6 +10191,31 @@ function mountScopeRoutes(app, opts) {
|
|
|
9989
10191
|
function scopeRepos(scopePaths) {
|
|
9990
10192
|
return scopePaths.map((p) => ({ name: p, root: p }));
|
|
9991
10193
|
}
|
|
10194
|
+
function ensureSummary(scope, id) {
|
|
10195
|
+
if (id === 0) return;
|
|
10196
|
+
const key = `${scope.hash}:${id}`;
|
|
10197
|
+
if (summarizing.has(key)) return;
|
|
10198
|
+
summarizing.add(key);
|
|
10199
|
+
summarizeCheckpoint(scope.hash, scopeRepos(scope.paths), id).then((label2) => setCheckpointLabel(scope.hash, id, label2)).then(() => {
|
|
10200
|
+
const payload = { scopeHash: scope.hash, id };
|
|
10201
|
+
opts.broadcast("checkpoints-changed", payload);
|
|
10202
|
+
scopeBus.emit("checkpoints-changed", payload);
|
|
10203
|
+
}).catch(() => {
|
|
10204
|
+
}).finally(() => summarizing.delete(key));
|
|
10205
|
+
}
|
|
10206
|
+
async function rebaselineIfHeadAdvanced(hash, paths) {
|
|
10207
|
+
const repos = scopeRepos(paths);
|
|
10208
|
+
if (!headAdvancedSinceInitial(hash, repos)) return false;
|
|
10209
|
+
liveCheckpoint.delete(hash);
|
|
10210
|
+
lastStatus.delete(hash);
|
|
10211
|
+
const entry = await resetBaseline(hash, repos).catch(() => null);
|
|
10212
|
+
if (entry) {
|
|
10213
|
+
const payload = { scopeHash: hash, id: entry.id };
|
|
10214
|
+
opts.broadcast("checkpoints-changed", payload);
|
|
10215
|
+
scopeBus.emit("checkpoints-changed", payload);
|
|
10216
|
+
}
|
|
10217
|
+
return true;
|
|
10218
|
+
}
|
|
9992
10219
|
app.post(
|
|
9993
10220
|
"/api/scopes",
|
|
9994
10221
|
zValidator5(
|
|
@@ -10020,6 +10247,10 @@ function mountScopeRoutes(app, opts) {
|
|
|
10020
10247
|
}).catch((err) => {
|
|
10021
10248
|
console.error("[checkpoint] initial snapshot failed:", err);
|
|
10022
10249
|
});
|
|
10250
|
+
} else {
|
|
10251
|
+
rebaselineIfHeadAdvanced(scope.hash, scope.paths).catch((err) => {
|
|
10252
|
+
console.error("[checkpoint] re-baseline failed:", err);
|
|
10253
|
+
});
|
|
10023
10254
|
}
|
|
10024
10255
|
if (!checkpointWatched.has(scope.hash)) {
|
|
10025
10256
|
checkpointWatched.add(scope.hash);
|
|
@@ -10039,8 +10270,11 @@ function mountScopeRoutes(app, opts) {
|
|
|
10039
10270
|
lastStatus.set(hash, fp);
|
|
10040
10271
|
} catch {
|
|
10041
10272
|
}
|
|
10042
|
-
takeCheckpoint(hash, scopeRepos(scope.paths)).then((entry) => {
|
|
10043
|
-
if (entry)
|
|
10273
|
+
rebaselineIfHeadAdvanced(hash, scope.paths).then(() => takeCheckpoint(hash, scopeRepos(scope.paths))).then((entry) => {
|
|
10274
|
+
if (entry) {
|
|
10275
|
+
announceCheckpoint(entry);
|
|
10276
|
+
ensureSummary(scope, entry.id);
|
|
10277
|
+
}
|
|
10044
10278
|
}).catch((err) => {
|
|
10045
10279
|
console.error("[checkpoint] auto-snapshot failed:", err);
|
|
10046
10280
|
});
|
|
@@ -10073,19 +10307,55 @@ function mountScopeRoutes(app, opts) {
|
|
|
10073
10307
|
const matched = scopesForCwd(cwd);
|
|
10074
10308
|
let snapshotted = 0;
|
|
10075
10309
|
for (const s of matched) {
|
|
10076
|
-
|
|
10077
|
-
|
|
10078
|
-
|
|
10310
|
+
await rebaselineIfHeadAdvanced(s.hash, s.paths);
|
|
10311
|
+
const liveId = liveCheckpoint.get(s.hash);
|
|
10312
|
+
let entry = null;
|
|
10313
|
+
if (liveId !== void 0) {
|
|
10314
|
+
const res = await updateCheckpoint(
|
|
10315
|
+
s.hash,
|
|
10316
|
+
scopeRepos(s.paths),
|
|
10317
|
+
liveId
|
|
10318
|
+
).catch(() => ({ status: "missing" }));
|
|
10319
|
+
if (res.status === "updated") {
|
|
10320
|
+
entry = res.entry;
|
|
10321
|
+
} else if (res.status === "missing") {
|
|
10322
|
+
liveCheckpoint.delete(s.hash);
|
|
10323
|
+
}
|
|
10324
|
+
}
|
|
10325
|
+
if (entry === null && !liveCheckpoint.has(s.hash)) {
|
|
10326
|
+
const appended = await takeCheckpoint(
|
|
10327
|
+
s.hash,
|
|
10328
|
+
scopeRepos(s.paths)
|
|
10329
|
+
).catch(() => null);
|
|
10330
|
+
if (appended) {
|
|
10331
|
+
entry = appended;
|
|
10332
|
+
liveCheckpoint.set(s.hash, appended.id);
|
|
10333
|
+
}
|
|
10334
|
+
}
|
|
10079
10335
|
if (entry) {
|
|
10080
10336
|
const payload = { scopeHash: s.hash, id: entry.id };
|
|
10081
10337
|
opts.broadcast("checkpoints-changed", payload);
|
|
10082
10338
|
scopeBus.emit("checkpoints-changed", payload);
|
|
10339
|
+
ensureSummary(s, entry.id);
|
|
10083
10340
|
snapshotted++;
|
|
10084
10341
|
}
|
|
10085
10342
|
}
|
|
10086
10343
|
return c.json({ ok: true, scopes: matched.length, snapshotted });
|
|
10087
10344
|
}
|
|
10088
10345
|
);
|
|
10346
|
+
app.post(
|
|
10347
|
+
"/api/checkpoint/seal",
|
|
10348
|
+
zValidator5("json", z4.object({ cwd: z4.string().min(1) })),
|
|
10349
|
+
(c) => {
|
|
10350
|
+
const { cwd } = c.req.valid("json");
|
|
10351
|
+
const matched = scopesForCwd(cwd);
|
|
10352
|
+
let sealed = 0;
|
|
10353
|
+
for (const s of matched) {
|
|
10354
|
+
if (liveCheckpoint.delete(s.hash)) sealed++;
|
|
10355
|
+
}
|
|
10356
|
+
return c.json({ ok: true, scopes: matched.length, sealed });
|
|
10357
|
+
}
|
|
10358
|
+
);
|
|
10089
10359
|
app.delete("/api/scopes/:hash", (c) => {
|
|
10090
10360
|
const hash = c.req.param("hash");
|
|
10091
10361
|
const scope = getScope(hash);
|
|
@@ -10093,6 +10363,10 @@ function mountScopeRoutes(app, opts) {
|
|
|
10093
10363
|
const ok = removeScope(hash);
|
|
10094
10364
|
checkpointWatched.delete(hash);
|
|
10095
10365
|
lastStatus.delete(hash);
|
|
10366
|
+
liveCheckpoint.delete(hash);
|
|
10367
|
+
for (const key of summarizing) {
|
|
10368
|
+
if (key.startsWith(`${hash}:`)) summarizing.delete(key);
|
|
10369
|
+
}
|
|
10096
10370
|
const pendingTimer = snapshotTimers.get(hash);
|
|
10097
10371
|
if (pendingTimer) {
|
|
10098
10372
|
clearTimeout(pendingTimer);
|
|
@@ -10145,7 +10419,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
10145
10419
|
const fromSha = fromEntry.repos[p] ?? "HEAD";
|
|
10146
10420
|
const toSha = toEntry === void 0 ? "working" : toEntry.repos[p] ?? "HEAD";
|
|
10147
10421
|
return {
|
|
10148
|
-
name:
|
|
10422
|
+
name: path40.basename(p),
|
|
10149
10423
|
root: p,
|
|
10150
10424
|
files: computeRangeDiff({ root: p, fromRef: fromSha, toRef: toSha })
|
|
10151
10425
|
};
|
|
@@ -10164,7 +10438,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
10164
10438
|
(p) => resolveRepoDiff(p, base, sessionBaseForPath(p))
|
|
10165
10439
|
);
|
|
10166
10440
|
const repos = scope.paths.map((p, i) => ({
|
|
10167
|
-
name:
|
|
10441
|
+
name: path40.basename(p),
|
|
10168
10442
|
root: p,
|
|
10169
10443
|
resolvedBase: resolved[i].resolvedBase,
|
|
10170
10444
|
files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
|
|
@@ -10195,7 +10469,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
10195
10469
|
if (!relPath || !Number.isInteger(start) || !Number.isInteger(end)) {
|
|
10196
10470
|
return c.json({ error: "bad path/start/end" }, 400);
|
|
10197
10471
|
}
|
|
10198
|
-
const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) =>
|
|
10472
|
+
const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path40.basename(p) === repoName);
|
|
10199
10473
|
if (!root) return c.json({ error: "unknown repo" }, 404);
|
|
10200
10474
|
const result = readContextLines({ root, relPath, start, end, ref });
|
|
10201
10475
|
if (!result) return c.json({ error: "cannot read file" }, 400);
|
|
@@ -10491,7 +10765,7 @@ function computeSessionDiff(s, base) {
|
|
|
10491
10765
|
(p) => resolveRepoDiff(p, base, s.baseBranches?.[p] ?? s.baseBranch)
|
|
10492
10766
|
);
|
|
10493
10767
|
const repos = s.paths.map((p, i) => ({
|
|
10494
|
-
name:
|
|
10768
|
+
name: path41.basename(p),
|
|
10495
10769
|
root: p,
|
|
10496
10770
|
resolvedBase: resolved[i].resolvedBase,
|
|
10497
10771
|
files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
|
|
@@ -10511,10 +10785,10 @@ async function startWebServer(opts = {}) {
|
|
|
10511
10785
|
for (const cb of sseListeners) cb({ event, data });
|
|
10512
10786
|
};
|
|
10513
10787
|
const home = os12.homedir();
|
|
10514
|
-
const historyPath =
|
|
10788
|
+
const historyPath = path41.join(home, ".work", "history.json");
|
|
10515
10789
|
const onHistoryChange = () => broadcast("sessions-changed", { ts: Date.now() });
|
|
10516
10790
|
fs40.watchFile(historyPath, { interval: 1e3 }, onHistoryChange);
|
|
10517
|
-
const tasksPath =
|
|
10791
|
+
const tasksPath = path41.join(home, ".work", "tasks.json");
|
|
10518
10792
|
const onTasksChange = () => broadcast("tasks-changed", { ts: Date.now() });
|
|
10519
10793
|
fs40.watchFile(tasksPath, { interval: 1e3 }, onTasksChange);
|
|
10520
10794
|
const projectsRoot = claudeProjectsRoot();
|
|
@@ -10659,10 +10933,10 @@ function info2(message) {
|
|
|
10659
10933
|
process.stderr.write(message + "\n");
|
|
10660
10934
|
}
|
|
10661
10935
|
function urlFilePath() {
|
|
10662
|
-
return
|
|
10936
|
+
return path42.join(os13.homedir(), ".work", "web.url");
|
|
10663
10937
|
}
|
|
10664
10938
|
function pidFilePath() {
|
|
10665
|
-
return
|
|
10939
|
+
return path42.join(os13.homedir(), ".work", "web.pid");
|
|
10666
10940
|
}
|
|
10667
10941
|
function isPidAlive(pid) {
|
|
10668
10942
|
try {
|
|
@@ -10787,7 +11061,7 @@ var webCommand = {
|
|
|
10787
11061
|
const lean = !!argv.lean || process.env.WORK_WEB_LEAN === "1";
|
|
10788
11062
|
const handle = await startWebServer({ lean });
|
|
10789
11063
|
try {
|
|
10790
|
-
fs41.mkdirSync(
|
|
11064
|
+
fs41.mkdirSync(path42.dirname(urlFilePath()), { recursive: true });
|
|
10791
11065
|
fs41.writeFileSync(urlFilePath(), handle.url);
|
|
10792
11066
|
fs41.writeFileSync(pidFilePath(), String(process.pid));
|
|
10793
11067
|
} catch {
|
|
@@ -10823,6 +11097,13 @@ var webCommand = {
|
|
|
10823
11097
|
timeoutSec: 5
|
|
10824
11098
|
}).catch(() => {
|
|
10825
11099
|
});
|
|
11100
|
+
await installCommandHook({
|
|
11101
|
+
owner: "web-checkpoint",
|
|
11102
|
+
event: "UserPromptSubmit",
|
|
11103
|
+
command: "work hook checkpoint-seal",
|
|
11104
|
+
timeoutSec: 5
|
|
11105
|
+
}).catch(() => {
|
|
11106
|
+
});
|
|
10826
11107
|
const shutdown = () => {
|
|
10827
11108
|
info2(chalk23.gray("\nStopping work web."));
|
|
10828
11109
|
try {
|
|
@@ -10847,6 +11128,10 @@ var webCommand = {
|
|
|
10847
11128
|
removeCommandHookSync("web-checkpoint", "Stop");
|
|
10848
11129
|
} catch {
|
|
10849
11130
|
}
|
|
11131
|
+
try {
|
|
11132
|
+
removeCommandHookSync("web-checkpoint", "UserPromptSubmit");
|
|
11133
|
+
} catch {
|
|
11134
|
+
}
|
|
10850
11135
|
handle.stop();
|
|
10851
11136
|
process.exit(0);
|
|
10852
11137
|
};
|
|
@@ -10870,11 +11155,11 @@ var webCommand = {
|
|
|
10870
11155
|
// src/commands/hook.ts
|
|
10871
11156
|
import fs42 from "fs";
|
|
10872
11157
|
import os14 from "os";
|
|
10873
|
-
import
|
|
10874
|
-
async function
|
|
11158
|
+
import path43 from "path";
|
|
11159
|
+
async function postToWeb(route, cwd) {
|
|
10875
11160
|
let base;
|
|
10876
11161
|
try {
|
|
10877
|
-
base = fs42.readFileSync(
|
|
11162
|
+
base = fs42.readFileSync(path43.join(os14.homedir(), ".work", "web.url"), "utf-8").trim();
|
|
10878
11163
|
} catch {
|
|
10879
11164
|
return;
|
|
10880
11165
|
}
|
|
@@ -10882,7 +11167,7 @@ async function triggerCheckpoint(cwd) {
|
|
|
10882
11167
|
const controller = new AbortController();
|
|
10883
11168
|
const timer = setTimeout(() => controller.abort(), 3e3);
|
|
10884
11169
|
try {
|
|
10885
|
-
await fetch(`${base}
|
|
11170
|
+
await fetch(`${base}${route}`, {
|
|
10886
11171
|
method: "POST",
|
|
10887
11172
|
headers: { "Content-Type": "application/json" },
|
|
10888
11173
|
body: JSON.stringify({ cwd }),
|
|
@@ -10942,15 +11227,20 @@ var hookCommand = {
|
|
|
10942
11227
|
// hidden — humans don't call this directly
|
|
10943
11228
|
builder: (y) => y.positional("event", {
|
|
10944
11229
|
type: "string",
|
|
10945
|
-
choices: ["prompt-submit", "stop", "checkpoint"],
|
|
11230
|
+
choices: ["prompt-submit", "stop", "checkpoint", "checkpoint-seal"],
|
|
10946
11231
|
describe: "Hook event name"
|
|
10947
11232
|
}),
|
|
10948
11233
|
handler: async (argv) => {
|
|
11234
|
+
if (isInternalClaude()) return;
|
|
10949
11235
|
const event = argv.event;
|
|
10950
11236
|
const payload = await readStdinJson();
|
|
10951
11237
|
const cwd = payload.cwd ?? process.cwd();
|
|
10952
11238
|
if (event === "checkpoint") {
|
|
10953
|
-
await
|
|
11239
|
+
await postToWeb("api/checkpoint", cwd);
|
|
11240
|
+
return;
|
|
11241
|
+
}
|
|
11242
|
+
if (event === "checkpoint-seal") {
|
|
11243
|
+
await postToWeb("api/checkpoint/seal", cwd);
|
|
10954
11244
|
return;
|
|
10955
11245
|
}
|
|
10956
11246
|
const result = computeHookOutput({ event, cwd });
|
|
@@ -11365,7 +11655,7 @@ var broadcastCommand = {
|
|
|
11365
11655
|
|
|
11366
11656
|
// src/completions/index.ts
|
|
11367
11657
|
import fs45 from "fs";
|
|
11368
|
-
import
|
|
11658
|
+
import path44 from "path";
|
|
11369
11659
|
function completionHandler(current, argv, done) {
|
|
11370
11660
|
const rawArgs = argv._;
|
|
11371
11661
|
const args = rawArgs.slice(1, -1);
|
|
@@ -11478,18 +11768,18 @@ function completeRepoBranches(alias, current, config, done) {
|
|
|
11478
11768
|
done(branches);
|
|
11479
11769
|
}
|
|
11480
11770
|
function completeGroupBranches(groupName, repoAliases, current, config, done) {
|
|
11481
|
-
const groupDir =
|
|
11771
|
+
const groupDir = path44.join(config.worktreesRoot, groupName);
|
|
11482
11772
|
if (!fs45.existsSync(groupDir)) {
|
|
11483
11773
|
done([]);
|
|
11484
11774
|
return;
|
|
11485
11775
|
}
|
|
11486
11776
|
try {
|
|
11487
11777
|
const branchDirs = fs45.readdirSync(groupDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => {
|
|
11488
|
-
const bdPath =
|
|
11778
|
+
const bdPath = path44.join(groupDir, d.name);
|
|
11489
11779
|
for (const alias of repoAliases) {
|
|
11490
11780
|
const repoPath = config.repos[alias];
|
|
11491
11781
|
if (!repoPath) continue;
|
|
11492
|
-
const subPath =
|
|
11782
|
+
const subPath = path44.join(bdPath, path44.basename(repoPath));
|
|
11493
11783
|
if (fs45.existsSync(subPath)) {
|
|
11494
11784
|
const branch = getCurrentBranch(subPath);
|
|
11495
11785
|
if (branch) return branch;
|
|
@@ -11504,7 +11794,7 @@ function completeGroupBranches(groupName, repoAliases, current, config, done) {
|
|
|
11504
11794
|
}
|
|
11505
11795
|
|
|
11506
11796
|
// src/version.ts
|
|
11507
|
-
var VERSION = true ? "1.
|
|
11797
|
+
var VERSION = true ? "1.15.0" : "dev";
|
|
11508
11798
|
|
|
11509
11799
|
// src/cli.ts
|
|
11510
11800
|
function showHelp() {
|