@moberg_hr/work-tree 1.5.1 → 1.8.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 +2 -2
- package/dist/bin.js +992 -337
- package/dist/bin.js.map +1 -1
- package/dist/wd-bin.js +986 -331
- package/dist/wd-bin.js.map +1 -1
- package/dist/web/assets/index-BV5-pKcI.js +106 -0
- package/dist/web/assets/index-BV5-pKcI.js.map +1 -0
- package/dist/web/assets/{index-8WP9kHU6.css → index-uJQw1Itb.css} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +3 -3
- package/dist/web/assets/index-C5ddmssO.js +0 -106
- package/dist/web/assets/index-C5ddmssO.js.map +0 -1
package/dist/wd-bin.js
CHANGED
|
@@ -321,26 +321,110 @@ async function fetchRemoteAsync(cwd) {
|
|
|
321
321
|
git(["remote", "set-head", "origin", "--auto"], cwd);
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
|
-
function
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
324
|
+
function gitAsync(args, cwd) {
|
|
325
|
+
debug("gitAsync", args.join(" "), `cwd=${cwd}`);
|
|
326
|
+
return new Promise((resolve) => {
|
|
327
|
+
execFile(
|
|
328
|
+
"git",
|
|
329
|
+
args,
|
|
330
|
+
{ cwd, encoding: "utf-8", timeout: 6e4, windowsHide: true },
|
|
331
|
+
(err, stdout, stderr) => {
|
|
332
|
+
const r = {
|
|
333
|
+
stdout: (stdout ?? "").toString().trim(),
|
|
334
|
+
stderr: (stderr ?? "").toString().trim(),
|
|
335
|
+
exitCode: err ? err.code ?? 1 : 0
|
|
336
|
+
};
|
|
337
|
+
if (typeof r.exitCode !== "number") r.exitCode = 1;
|
|
338
|
+
if (r.exitCode !== 0) {
|
|
339
|
+
debug("gitAsync failed", { args, exitCode: r.exitCode, stderr: r.stderr });
|
|
340
|
+
}
|
|
341
|
+
resolve(r);
|
|
342
|
+
}
|
|
343
|
+
);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
async function getDefaultBranchAsync(cwd) {
|
|
347
|
+
const result = await gitAsync(["symbolic-ref", "refs/remotes/origin/HEAD"], cwd);
|
|
348
|
+
if (result.exitCode === 0 && result.stdout) {
|
|
349
|
+
return result.stdout.replace(/^refs\/remotes\/origin\//, "");
|
|
332
350
|
}
|
|
333
351
|
return null;
|
|
334
352
|
}
|
|
335
|
-
function
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
353
|
+
async function refExistsAsync(ref, cwd) {
|
|
354
|
+
return (await gitAsync(["rev-parse", "--verify", ref], cwd)).exitCode === 0;
|
|
355
|
+
}
|
|
356
|
+
async function checkSquashMergedAsync(branch, baseRef, cwd) {
|
|
357
|
+
const mb = await gitAsync(["merge-base", baseRef, branch], cwd);
|
|
358
|
+
if (mb.exitCode !== 0) return false;
|
|
359
|
+
const tree = await gitAsync(["rev-parse", `${branch}^{tree}`], cwd);
|
|
360
|
+
if (tree.exitCode !== 0) return false;
|
|
361
|
+
const dangling = await gitAsync(["commit-tree", tree.stdout, "-p", mb.stdout, "-m", ""], cwd);
|
|
362
|
+
if (dangling.exitCode !== 0) return false;
|
|
363
|
+
const cherry = await gitAsync(["cherry", baseRef, dangling.stdout], cwd);
|
|
364
|
+
if (cherry.exitCode !== 0) return false;
|
|
365
|
+
return cherry.stdout.startsWith("-");
|
|
366
|
+
}
|
|
367
|
+
async function checkMergeStatusAsync(branch, baseRef, cwd) {
|
|
368
|
+
const branchInBase = await gitAsync(["merge-base", "--is-ancestor", branch, baseRef], cwd);
|
|
369
|
+
if (branchInBase.exitCode !== 0) {
|
|
370
|
+
if (await checkSquashMergedAsync(branch, baseRef, cwd)) return "squash-merged";
|
|
371
|
+
return "unrelated";
|
|
372
|
+
}
|
|
373
|
+
const baseInBranch = await gitAsync(["merge-base", "--is-ancestor", baseRef, branch], cwd);
|
|
374
|
+
if (baseInBranch.exitCode === 0) return "merged";
|
|
375
|
+
const tip = await gitAsync(["rev-parse", branch], cwd);
|
|
376
|
+
if (tip.exitCode !== 0) return "unrelated";
|
|
377
|
+
const mainLine = await gitAsync(["rev-list", "--first-parent", "-n", "500", baseRef], cwd);
|
|
378
|
+
if (mainLine.exitCode === 0 && mainLine.stdout.includes(tip.stdout)) {
|
|
379
|
+
return "stale";
|
|
380
|
+
}
|
|
381
|
+
return "merged";
|
|
382
|
+
}
|
|
383
|
+
async function isBranchMergedAsync(branch, cwd, baseBranch) {
|
|
384
|
+
const defaultBranch = await getDefaultBranchAsync(cwd);
|
|
385
|
+
const bases = baseBranch ? [baseBranch] : [defaultBranch, "main", "master"].filter(
|
|
386
|
+
(b) => b !== null
|
|
387
|
+
);
|
|
388
|
+
const uniqueBases = [...new Set(bases)];
|
|
389
|
+
for (const base of uniqueBases) {
|
|
390
|
+
if (await refExistsAsync(`origin/${base}`, cwd)) {
|
|
391
|
+
const baseRef = `origin/${base}`;
|
|
392
|
+
const status = await checkMergeStatusAsync(branch, baseRef, cwd);
|
|
393
|
+
if (status === "merged") return { merged: true, into: baseRef, confidence: "merged" };
|
|
394
|
+
if (status === "squash-merged")
|
|
395
|
+
return { merged: true, into: baseRef, confidence: "squash-merged" };
|
|
396
|
+
if (status === "stale") return { merged: false, into: null, confidence: null };
|
|
397
|
+
}
|
|
398
|
+
if (await refExistsAsync(base, cwd)) {
|
|
399
|
+
const status = await checkMergeStatusAsync(branch, base, cwd);
|
|
400
|
+
if (status === "merged") return { merged: true, into: base, confidence: "merged" };
|
|
401
|
+
if (status === "squash-merged")
|
|
402
|
+
return { merged: true, into: base, confidence: "squash-merged" };
|
|
403
|
+
if (status === "stale") return { merged: false, into: null, confidence: null };
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return { merged: false, into: null, confidence: null };
|
|
407
|
+
}
|
|
408
|
+
async function countConflictsAsync(branch, cwd) {
|
|
409
|
+
const defaultBranch = await getDefaultBranchAsync(cwd) ?? "main";
|
|
410
|
+
const base = await refExistsAsync(`origin/${defaultBranch}`, cwd) ? `origin/${defaultBranch}` : defaultBranch;
|
|
411
|
+
const mergeBase = await gitAsync(["merge-base", base, branch], cwd);
|
|
339
412
|
if (mergeBase.exitCode !== 0) return 0;
|
|
340
|
-
const result =
|
|
413
|
+
const result = await gitAsync(["merge-tree", mergeBase.stdout, base, branch], cwd);
|
|
341
414
|
const conflicts = (result.stdout.match(/^<<<<<<< /gm) || []).length;
|
|
342
415
|
return conflicts;
|
|
343
416
|
}
|
|
417
|
+
async function rebaseOntoMainAsync(branch, cwd) {
|
|
418
|
+
const defaultBranch = await getDefaultBranchAsync(cwd) ?? "main";
|
|
419
|
+
await gitAsync(["fetch", "--quiet"], cwd);
|
|
420
|
+
const base = await refExistsAsync(`origin/${defaultBranch}`, cwd) ? `origin/${defaultBranch}` : defaultBranch;
|
|
421
|
+
const result = await gitAsync(["rebase", base, branch], cwd);
|
|
422
|
+
if (result.exitCode !== 0) {
|
|
423
|
+
await gitAsync(["rebase", "--abort"], cwd);
|
|
424
|
+
return result.stderr || "Rebase failed";
|
|
425
|
+
}
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
344
428
|
function getUnpushedCommits(cwd) {
|
|
345
429
|
const branch = getCurrentBranch(cwd);
|
|
346
430
|
if (!branch) return "";
|
|
@@ -1573,11 +1657,12 @@ async function upsertSession(target, isGroup, branch, paths, jiraKey, baseBranch
|
|
|
1573
1657
|
saveHistory(sessions);
|
|
1574
1658
|
});
|
|
1575
1659
|
}
|
|
1576
|
-
async function upsertSessionWithPort(target, isGroup, branch, paths, config, jiraKey, baseBranch) {
|
|
1660
|
+
async function upsertSessionWithPort(target, isGroup, branch, paths, config, jiraKey, baseBranch, baseBranches) {
|
|
1577
1661
|
return withHistoryLock(async () => {
|
|
1578
1662
|
const sessions = loadHistory();
|
|
1579
1663
|
const existing = findSession(sessions, target, branch);
|
|
1580
1664
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1665
|
+
const hasPerRepo = baseBranches && Object.keys(baseBranches).length > 0;
|
|
1581
1666
|
let port = existing?.port;
|
|
1582
1667
|
if (port === void 0) {
|
|
1583
1668
|
const seedKey = sessionKey(target, branch);
|
|
@@ -1592,6 +1677,7 @@ async function upsertSessionWithPort(target, isGroup, branch, paths, config, jir
|
|
|
1592
1677
|
existing.lastAccessedAt = now;
|
|
1593
1678
|
if (jiraKey) existing.jiraKey = jiraKey;
|
|
1594
1679
|
if (baseBranch && !existing.baseBranch) existing.baseBranch = baseBranch;
|
|
1680
|
+
if (hasPerRepo && !existing.baseBranches) existing.baseBranches = baseBranches;
|
|
1595
1681
|
if (port !== void 0) existing.port = port;
|
|
1596
1682
|
} else {
|
|
1597
1683
|
const session = {
|
|
@@ -1604,6 +1690,7 @@ async function upsertSessionWithPort(target, isGroup, branch, paths, config, jir
|
|
|
1604
1690
|
};
|
|
1605
1691
|
if (jiraKey) session.jiraKey = jiraKey;
|
|
1606
1692
|
if (baseBranch) session.baseBranch = baseBranch;
|
|
1693
|
+
if (hasPerRepo) session.baseBranches = baseBranches;
|
|
1607
1694
|
if (port !== void 0) session.port = port;
|
|
1608
1695
|
sessions.push(session);
|
|
1609
1696
|
}
|
|
@@ -1719,6 +1806,62 @@ function copyConfigFiles(repoPath, worktreePath, patterns) {
|
|
|
1719
1806
|
}
|
|
1720
1807
|
}
|
|
1721
1808
|
|
|
1809
|
+
// src/core/base-spec.ts
|
|
1810
|
+
var BaseSpecError = class extends Error {
|
|
1811
|
+
constructor(message) {
|
|
1812
|
+
super(message);
|
|
1813
|
+
this.name = "BaseSpecError";
|
|
1814
|
+
}
|
|
1815
|
+
};
|
|
1816
|
+
function parseBaseSpec(raw) {
|
|
1817
|
+
const spec = { perRepo: {} };
|
|
1818
|
+
if (raw === void 0) return spec;
|
|
1819
|
+
const values = Array.isArray(raw) ? raw : [raw];
|
|
1820
|
+
for (const value of values) {
|
|
1821
|
+
const v = value.trim();
|
|
1822
|
+
if (!v) continue;
|
|
1823
|
+
const eq = v.indexOf("=");
|
|
1824
|
+
if (eq === -1) {
|
|
1825
|
+
if (spec.default !== void 0 && spec.default !== v) {
|
|
1826
|
+
throw new BaseSpecError(
|
|
1827
|
+
`Conflicting default --base values: '${spec.default}' and '${v}'`
|
|
1828
|
+
);
|
|
1829
|
+
}
|
|
1830
|
+
spec.default = v;
|
|
1831
|
+
} else {
|
|
1832
|
+
const alias = v.slice(0, eq).trim();
|
|
1833
|
+
const branch = v.slice(eq + 1).trim();
|
|
1834
|
+
if (!alias || !branch) {
|
|
1835
|
+
throw new BaseSpecError(
|
|
1836
|
+
`Invalid --base '${value}'. Use 'alias=branch' or a bare 'branch'.`
|
|
1837
|
+
);
|
|
1838
|
+
}
|
|
1839
|
+
const prior = spec.perRepo[alias];
|
|
1840
|
+
if (prior !== void 0 && prior !== branch) {
|
|
1841
|
+
throw new BaseSpecError(
|
|
1842
|
+
`Conflicting --base for '${alias}': '${prior}' and '${branch}'`
|
|
1843
|
+
);
|
|
1844
|
+
}
|
|
1845
|
+
spec.perRepo[alias] = branch;
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
return spec;
|
|
1849
|
+
}
|
|
1850
|
+
function baseForAlias(spec, alias) {
|
|
1851
|
+
return spec.perRepo[alias] ?? spec.default;
|
|
1852
|
+
}
|
|
1853
|
+
function isEmptyBaseSpec(spec) {
|
|
1854
|
+
return spec.default === void 0 && Object.keys(spec.perRepo).length === 0;
|
|
1855
|
+
}
|
|
1856
|
+
function baseSpecOverrideAliases(spec) {
|
|
1857
|
+
return Object.keys(spec.perRepo);
|
|
1858
|
+
}
|
|
1859
|
+
function toBaseSpec(base) {
|
|
1860
|
+
if (base === void 0) return { perRepo: {} };
|
|
1861
|
+
if (typeof base === "string") return { default: base, perRepo: {} };
|
|
1862
|
+
return base;
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1722
1865
|
// src/core/worktree.ts
|
|
1723
1866
|
function createSingleWorktree(repoPath, worktreePath, branchName, config, baseBranch) {
|
|
1724
1867
|
debug("createSingleWorktree", { repoPath, worktreePath, branchName, baseBranch });
|
|
@@ -1924,8 +2067,9 @@ function removeSingleWorktree(repoPath, worktreePath, branchName, force) {
|
|
|
1924
2067
|
return false;
|
|
1925
2068
|
}
|
|
1926
2069
|
}
|
|
1927
|
-
async function setupWorktree(targetName, branchName, config,
|
|
1928
|
-
|
|
2070
|
+
async function setupWorktree(targetName, branchName, config, base, jiraKey) {
|
|
2071
|
+
const spec = toBaseSpec(base);
|
|
2072
|
+
debug("setupWorktree", { targetName, branchName, spec, jiraKey });
|
|
1929
2073
|
const target = resolveProjectTarget(targetName, config);
|
|
1930
2074
|
if (!target) {
|
|
1931
2075
|
debug("setupWorktree: target not found", targetName);
|
|
@@ -1933,27 +2077,38 @@ async function setupWorktree(targetName, branchName, config, baseBranch, jiraKey
|
|
|
1933
2077
|
}
|
|
1934
2078
|
const workTreeDirName = branchName.replace(/\//g, "-");
|
|
1935
2079
|
if (target.isGroup) {
|
|
1936
|
-
return setupGroupWorktree(target.name, target.repoAliases, branchName, workTreeDirName, config,
|
|
2080
|
+
return setupGroupWorktree(target.name, target.repoAliases, branchName, workTreeDirName, config, spec, jiraKey);
|
|
1937
2081
|
} else {
|
|
1938
|
-
return setupSingleWorktree(targetName, branchName, workTreeDirName, config,
|
|
2082
|
+
return setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey);
|
|
1939
2083
|
}
|
|
1940
2084
|
}
|
|
1941
|
-
async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDirName, config,
|
|
2085
|
+
async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDirName, config, spec, jiraKey) {
|
|
1942
2086
|
const groupWorktreePath = path12.join(config.worktreesRoot, groupName, workTreeDirName);
|
|
1943
|
-
if (
|
|
2087
|
+
if (!isEmptyBaseSpec(spec)) {
|
|
2088
|
+
const unknownAliases = baseSpecOverrideAliases(spec).filter(
|
|
2089
|
+
(a) => !repoAliases.includes(a)
|
|
2090
|
+
);
|
|
2091
|
+
if (unknownAliases.length > 0) {
|
|
2092
|
+
console.error(
|
|
2093
|
+
`--base names repo(s) not in group '${groupName}': ${unknownAliases.join(", ")}. Group repos: ${repoAliases.join(", ")}`
|
|
2094
|
+
);
|
|
2095
|
+
return null;
|
|
2096
|
+
}
|
|
1944
2097
|
const missingBase = [];
|
|
1945
2098
|
const branchExists = [];
|
|
1946
2099
|
for (const alias of repoAliases) {
|
|
1947
2100
|
const repoPath = config.repos[alias];
|
|
1948
|
-
|
|
1949
|
-
|
|
2101
|
+
const repoBase = baseForAlias(spec, alias);
|
|
2102
|
+
if (!repoBase) continue;
|
|
2103
|
+
if (!localBranchExists(repoBase, repoPath) && !remoteBranchExists(repoBase, repoPath)) {
|
|
2104
|
+
missingBase.push(`${alias} (${repoBase})`);
|
|
1950
2105
|
}
|
|
1951
2106
|
if (localBranchExists(branchName, repoPath) || remoteBranchExists(branchName, repoPath)) {
|
|
1952
2107
|
branchExists.push(alias);
|
|
1953
2108
|
}
|
|
1954
2109
|
}
|
|
1955
2110
|
if (missingBase.length > 0) {
|
|
1956
|
-
console.error(`Base branch
|
|
2111
|
+
console.error(`Base branch not found in: ${missingBase.join(", ")}`);
|
|
1957
2112
|
return null;
|
|
1958
2113
|
}
|
|
1959
2114
|
if (branchExists.length > 0) {
|
|
@@ -1966,14 +2121,17 @@ async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDi
|
|
|
1966
2121
|
console.log("");
|
|
1967
2122
|
fs13.mkdirSync(groupWorktreePath, { recursive: true });
|
|
1968
2123
|
const createdWorktrees = [];
|
|
2124
|
+
const baseBranches = {};
|
|
1969
2125
|
for (const alias of repoAliases) {
|
|
1970
2126
|
const repoPath = config.repos[alias];
|
|
1971
2127
|
const repoName = path12.basename(repoPath);
|
|
1972
2128
|
const subWorktreePath = path12.join(groupWorktreePath, repoName);
|
|
2129
|
+
const repoBase = baseForAlias(spec, alias);
|
|
1973
2130
|
console.log(chalk5.cyan(`[${alias}] (${repoName}):`));
|
|
1974
|
-
const success = createSingleWorktree(repoPath, subWorktreePath, branchName, config,
|
|
2131
|
+
const success = createSingleWorktree(repoPath, subWorktreePath, branchName, config, repoBase);
|
|
1975
2132
|
if (success) {
|
|
1976
2133
|
createdWorktrees.push({ repoPath, worktreePath: subWorktreePath });
|
|
2134
|
+
if (repoBase) baseBranches[subWorktreePath] = repoBase;
|
|
1977
2135
|
} else {
|
|
1978
2136
|
console.log("");
|
|
1979
2137
|
console.log(chalk5.yellow("Rolling back created worktrees due to failure..."));
|
|
@@ -2003,6 +2161,8 @@ async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDi
|
|
|
2003
2161
|
console.log(chalk5.yellow(`Run 'work config regengroup ${groupName}' to generate it.`));
|
|
2004
2162
|
}
|
|
2005
2163
|
const allPaths = createdWorktrees.map((wt) => wt.worktreePath);
|
|
2164
|
+
const distinctBases = [...new Set(Object.values(baseBranches))];
|
|
2165
|
+
const representativeBase = spec.default ?? (distinctBases.length === 1 ? distinctBases[0] : void 0);
|
|
2006
2166
|
const { port } = await upsertSessionWithPort(
|
|
2007
2167
|
groupName,
|
|
2008
2168
|
true,
|
|
@@ -2010,17 +2170,26 @@ async function setupGroupWorktree(groupName, repoAliases, branchName, workTreeDi
|
|
|
2010
2170
|
allPaths,
|
|
2011
2171
|
config,
|
|
2012
2172
|
jiraKey,
|
|
2013
|
-
|
|
2173
|
+
representativeBase,
|
|
2174
|
+
baseBranches
|
|
2014
2175
|
);
|
|
2015
2176
|
console.log("");
|
|
2016
2177
|
console.log(`Branch: ${branchName}`);
|
|
2017
2178
|
if (port !== void 0) console.log(chalk5.gray(`Dev-server port: ${port}`));
|
|
2018
2179
|
return { launchDir: groupWorktreePath, paths: allPaths, isGroup: true, port };
|
|
2019
2180
|
}
|
|
2020
|
-
async function setupSingleWorktree(targetName, branchName, workTreeDirName, config,
|
|
2181
|
+
async function setupSingleWorktree(targetName, branchName, workTreeDirName, config, spec, jiraKey) {
|
|
2021
2182
|
const repoPath = config.repos[targetName];
|
|
2022
2183
|
const repoName = path12.basename(repoPath);
|
|
2023
2184
|
let workTreePath = path12.join(config.worktreesRoot, repoName, workTreeDirName);
|
|
2185
|
+
const unknownAliases = baseSpecOverrideAliases(spec).filter((a) => a !== targetName);
|
|
2186
|
+
if (unknownAliases.length > 0) {
|
|
2187
|
+
console.error(
|
|
2188
|
+
`--base names repo(s) other than '${targetName}': ${unknownAliases.join(", ")}`
|
|
2189
|
+
);
|
|
2190
|
+
return null;
|
|
2191
|
+
}
|
|
2192
|
+
const baseBranch = baseForAlias(spec, targetName);
|
|
2024
2193
|
if (!fs13.existsSync(repoPath)) {
|
|
2025
2194
|
console.error(`Repository path does not exist: ${repoPath}`);
|
|
2026
2195
|
return null;
|
|
@@ -2047,7 +2216,8 @@ async function setupSingleWorktree(targetName, branchName, workTreeDirName, conf
|
|
|
2047
2216
|
[workTreePath],
|
|
2048
2217
|
config,
|
|
2049
2218
|
jiraKey,
|
|
2050
|
-
baseBranch
|
|
2219
|
+
baseBranch,
|
|
2220
|
+
baseBranch ? { [workTreePath]: baseBranch } : void 0
|
|
2051
2221
|
);
|
|
2052
2222
|
console.log(`Branch: ${branchName}`);
|
|
2053
2223
|
if (port !== void 0) console.log(chalk5.gray(`Dev-server port: ${port}`));
|
|
@@ -2119,7 +2289,7 @@ var treeCommand = {
|
|
|
2119
2289
|
type: "boolean",
|
|
2120
2290
|
default: false
|
|
2121
2291
|
}).option("base", {
|
|
2122
|
-
describe: "
|
|
2292
|
+
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.",
|
|
2123
2293
|
type: "string"
|
|
2124
2294
|
}).option("prompt", {
|
|
2125
2295
|
describe: "Initial prompt to send to the AI tool on startup",
|
|
@@ -2144,7 +2314,17 @@ var treeCommand = {
|
|
|
2144
2314
|
const open = argv.open;
|
|
2145
2315
|
const unsafe = argv.unsafe;
|
|
2146
2316
|
const setupOnly = argv["setup-only"];
|
|
2147
|
-
|
|
2317
|
+
let baseSpec;
|
|
2318
|
+
try {
|
|
2319
|
+
baseSpec = parseBaseSpec(argv.base);
|
|
2320
|
+
} catch (err) {
|
|
2321
|
+
if (err instanceof BaseSpecError) {
|
|
2322
|
+
console.error(err.message);
|
|
2323
|
+
process.exitCode = 1;
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
throw err;
|
|
2327
|
+
}
|
|
2148
2328
|
const jiraKey = argv["jira-key"];
|
|
2149
2329
|
const promptFile = argv["prompt-file"];
|
|
2150
2330
|
let initialPrompt = argv.prompt;
|
|
@@ -2182,12 +2362,10 @@ var treeCommand = {
|
|
|
2182
2362
|
process.exitCode = 1;
|
|
2183
2363
|
return;
|
|
2184
2364
|
}
|
|
2185
|
-
if (
|
|
2365
|
+
if (!isEmptyBaseSpec(baseSpec) && !branchName) {
|
|
2186
2366
|
console.error("--base requires a branch name");
|
|
2187
2367
|
console.log(
|
|
2188
|
-
chalk6.yellow(
|
|
2189
|
-
`Usage: work tree ${targetName} <branch> --base ${baseBranch}`
|
|
2190
|
-
)
|
|
2368
|
+
chalk6.yellow(`Usage: work tree ${targetName} <branch> --base <base>`)
|
|
2191
2369
|
);
|
|
2192
2370
|
process.exitCode = 1;
|
|
2193
2371
|
return;
|
|
@@ -2235,7 +2413,7 @@ var treeCommand = {
|
|
|
2235
2413
|
}
|
|
2236
2414
|
return;
|
|
2237
2415
|
}
|
|
2238
|
-
const result = await setupWorktree(targetName, branchName, config,
|
|
2416
|
+
const result = await setupWorktree(targetName, branchName, config, baseSpec, jiraKey);
|
|
2239
2417
|
if (!result) {
|
|
2240
2418
|
process.exitCode = 1;
|
|
2241
2419
|
return;
|
|
@@ -3124,7 +3302,7 @@ import { render } from "ink";
|
|
|
3124
3302
|
|
|
3125
3303
|
// src/tui-ink/App.tsx
|
|
3126
3304
|
import { useState, useEffect, useRef, useCallback, useMemo } from "react";
|
|
3127
|
-
import { Box as
|
|
3305
|
+
import { Box as Box5 } from "ink";
|
|
3128
3306
|
import fs23 from "fs";
|
|
3129
3307
|
import os6 from "os";
|
|
3130
3308
|
import path20 from "path";
|
|
@@ -3441,7 +3619,7 @@ var PtySession = class {
|
|
|
3441
3619
|
cwd;
|
|
3442
3620
|
outputHandler;
|
|
3443
3621
|
_exited = false;
|
|
3444
|
-
|
|
3622
|
+
_status = "idle";
|
|
3445
3623
|
_outputBuffer = "";
|
|
3446
3624
|
_loggedOutput = false;
|
|
3447
3625
|
onExit;
|
|
@@ -3511,13 +3689,18 @@ var PtySession = class {
|
|
|
3511
3689
|
get exited() {
|
|
3512
3690
|
return this._exited;
|
|
3513
3691
|
}
|
|
3692
|
+
/** True when the session is not actively working (idle or needs input). */
|
|
3514
3693
|
get idle() {
|
|
3515
|
-
return this.
|
|
3694
|
+
return this._status !== "running";
|
|
3695
|
+
}
|
|
3696
|
+
/** Live status: 'running', 'idle' (turn finished) or 'attention' (needs input). */
|
|
3697
|
+
get status() {
|
|
3698
|
+
return this._status;
|
|
3516
3699
|
}
|
|
3517
|
-
/** Called by the dashboard when a hook event indicates
|
|
3518
|
-
|
|
3519
|
-
if (this._exited || this.
|
|
3520
|
-
this.
|
|
3700
|
+
/** Called by the dashboard when a hook event indicates a state change. */
|
|
3701
|
+
setStatus(status) {
|
|
3702
|
+
if (this._exited || this._status === status) return;
|
|
3703
|
+
this._status = status;
|
|
3521
3704
|
this.onStatusChange?.();
|
|
3522
3705
|
}
|
|
3523
3706
|
write(data) {
|
|
@@ -3984,7 +4167,7 @@ function renderBufferLines(buffer, cols, rows, scrollBack = 0) {
|
|
|
3984
4167
|
// src/tui-ink/Sidebar.tsx
|
|
3985
4168
|
import React from "react";
|
|
3986
4169
|
import { Box, Text } from "ink";
|
|
3987
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4170
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3988
4171
|
function buildSessionRows(sessions, statusMap) {
|
|
3989
4172
|
if (sessions.length === 0) return [];
|
|
3990
4173
|
const rows = [];
|
|
@@ -3993,7 +4176,7 @@ function buildSessionRows(sessions, statusMap) {
|
|
|
3993
4176
|
for (const s of sessions) {
|
|
3994
4177
|
const key = `${s.target}:${s.branch}`;
|
|
3995
4178
|
const status = statusMap?.get(key);
|
|
3996
|
-
if (status
|
|
4179
|
+
if (status !== void 0 && status !== "stopped") {
|
|
3997
4180
|
active.push(s);
|
|
3998
4181
|
} else {
|
|
3999
4182
|
inactive.push(s);
|
|
@@ -4117,6 +4300,47 @@ function cursorToRow(rows, cursor) {
|
|
|
4117
4300
|
function sessionKey2(s) {
|
|
4118
4301
|
return `${s.target}:${s.branch}`;
|
|
4119
4302
|
}
|
|
4303
|
+
function computeScrollOffset(rows, cursor, contentHeight) {
|
|
4304
|
+
let cursorRowIdx = 0;
|
|
4305
|
+
let selectableCount = 0;
|
|
4306
|
+
for (let i = 0; i < rows.length; i++) {
|
|
4307
|
+
if (rows[i].type !== "header") {
|
|
4308
|
+
if (selectableCount === cursor) {
|
|
4309
|
+
cursorRowIdx = i;
|
|
4310
|
+
break;
|
|
4311
|
+
}
|
|
4312
|
+
selectableCount++;
|
|
4313
|
+
}
|
|
4314
|
+
}
|
|
4315
|
+
if (rows.length > contentHeight && cursorRowIdx >= contentHeight - 1) {
|
|
4316
|
+
return Math.min(
|
|
4317
|
+
cursorRowIdx - contentHeight + 2,
|
|
4318
|
+
rows.length - contentHeight
|
|
4319
|
+
);
|
|
4320
|
+
}
|
|
4321
|
+
return 0;
|
|
4322
|
+
}
|
|
4323
|
+
function InputText({ value, pos, budget }) {
|
|
4324
|
+
let v = value;
|
|
4325
|
+
let p = pos;
|
|
4326
|
+
if (budget !== void 0 && value.length + 1 > budget) {
|
|
4327
|
+
const windowLen = Math.max(1, budget - 1);
|
|
4328
|
+
const start = Math.max(0, p - windowLen);
|
|
4329
|
+
v = value.slice(start, start + windowLen);
|
|
4330
|
+
p = pos - start;
|
|
4331
|
+
}
|
|
4332
|
+
if (p >= v.length) {
|
|
4333
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4334
|
+
/* @__PURE__ */ jsx(Text, { children: v }),
|
|
4335
|
+
/* @__PURE__ */ jsx(Text, { dimColor: true, children: "\u2588" })
|
|
4336
|
+
] });
|
|
4337
|
+
}
|
|
4338
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4339
|
+
/* @__PURE__ */ jsx(Text, { children: v.slice(0, p) }),
|
|
4340
|
+
/* @__PURE__ */ jsx(Text, { inverse: true, children: v[p] }),
|
|
4341
|
+
/* @__PURE__ */ jsx(Text, { children: v.slice(p + 1) })
|
|
4342
|
+
] });
|
|
4343
|
+
}
|
|
4120
4344
|
function truncate(str, max) {
|
|
4121
4345
|
if (max <= 1) return "";
|
|
4122
4346
|
return str.length > max ? str.slice(0, max - 1) + "\u2026" : str;
|
|
@@ -4161,8 +4385,8 @@ function SessionRow({
|
|
|
4161
4385
|
active,
|
|
4162
4386
|
width
|
|
4163
4387
|
}) {
|
|
4164
|
-
const dotChar = status === "
|
|
4165
|
-
const dotColor = status === "
|
|
4388
|
+
const dotChar = status === "attention" ? "\u25C6" : status === "idle" ? "\u25C7" : status === "running" ? "\u25CF" : "\u25CB";
|
|
4389
|
+
const dotColor = status === "attention" ? "yellow" : status === "idle" ? "cyan" : status === "running" ? "green" : "gray";
|
|
4166
4390
|
const agoStr = timeAgo(effectiveLastAccessedAt(s));
|
|
4167
4391
|
const mergedLen = merged ? 8 : 0;
|
|
4168
4392
|
const conflictLen = conflicts > 0 ? 2 + String(conflicts).length : 0;
|
|
@@ -4207,11 +4431,8 @@ function ProjectRow({
|
|
|
4207
4431
|
/* @__PURE__ */ jsx(Text, { color: "magenta", children: truncate(name, width - 15) }),
|
|
4208
4432
|
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
4209
4433
|
/* @__PURE__ */ jsx(Text, { color: "cyan", children: "branch:" }),
|
|
4210
|
-
/* @__PURE__ */
|
|
4211
|
-
|
|
4212
|
-
branchInput.value
|
|
4213
|
-
] }),
|
|
4214
|
-
/* @__PURE__ */ jsx(Text, { dimColor: true, children: "\u2588" })
|
|
4434
|
+
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
4435
|
+
/* @__PURE__ */ jsx(InputText, { value: branchInput.value, pos: branchInput.pos })
|
|
4215
4436
|
] });
|
|
4216
4437
|
}
|
|
4217
4438
|
return /* @__PURE__ */ jsxs(Box, { width, children: [
|
|
@@ -4269,26 +4490,7 @@ function BorderedPane({
|
|
|
4269
4490
|
}) {
|
|
4270
4491
|
const innerWidth = width - 2;
|
|
4271
4492
|
const contentHeight = height - 2;
|
|
4272
|
-
|
|
4273
|
-
let selectableCount = 0;
|
|
4274
|
-
for (let i = 0; i < sidebarRows.length; i++) {
|
|
4275
|
-
if (sidebarRows[i].type !== "header") {
|
|
4276
|
-
if (selectableCount === cursor) {
|
|
4277
|
-
cursorRowIdx = i;
|
|
4278
|
-
break;
|
|
4279
|
-
}
|
|
4280
|
-
selectableCount++;
|
|
4281
|
-
}
|
|
4282
|
-
}
|
|
4283
|
-
let scrollOffset = 0;
|
|
4284
|
-
if (sidebarRows.length > contentHeight) {
|
|
4285
|
-
if (cursorRowIdx >= contentHeight - 1) {
|
|
4286
|
-
scrollOffset = Math.min(
|
|
4287
|
-
cursorRowIdx - contentHeight + 2,
|
|
4288
|
-
sidebarRows.length - contentHeight
|
|
4289
|
-
);
|
|
4290
|
-
}
|
|
4291
|
-
}
|
|
4493
|
+
const scrollOffset = computeScrollOffset(sidebarRows, cursor, contentHeight);
|
|
4292
4494
|
const rendered = [];
|
|
4293
4495
|
let selectableIdx = 0;
|
|
4294
4496
|
for (let i = 0; i < scrollOffset; i++) {
|
|
@@ -4309,7 +4511,14 @@ function BorderedPane({
|
|
|
4309
4511
|
rendered.push(renderRow(row, rowIdx, sel));
|
|
4310
4512
|
}
|
|
4311
4513
|
}
|
|
4312
|
-
const
|
|
4514
|
+
const hiddenAbove = scrollOffset;
|
|
4515
|
+
const hiddenBelow = Math.max(0, sidebarRows.length - (scrollOffset + contentHeight));
|
|
4516
|
+
const upText = hiddenAbove > 0 ? ` \u2191${hiddenAbove} ` : "";
|
|
4517
|
+
const downText = hiddenBelow > 0 ? ` \u2193${hiddenBelow} ` : "";
|
|
4518
|
+
const titlePart = title ? "\u2500 " + title + " " : "";
|
|
4519
|
+
const topFill = Math.max(0, innerWidth - titlePart.length - upText.length);
|
|
4520
|
+
const topBorder = "\u250C" + titlePart + "\u2500".repeat(topFill) + upText + "\u2510";
|
|
4521
|
+
const bottomBorder = "\u2514" + "\u2500".repeat(Math.max(0, innerWidth - downText.length)) + downText + "\u2518";
|
|
4313
4522
|
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", width, children: [
|
|
4314
4523
|
/* @__PURE__ */ jsx(Text, { color: borderColor, children: topBorder }),
|
|
4315
4524
|
rendered.map((row, i) => /* @__PURE__ */ jsxs(Box, { children: [
|
|
@@ -4317,12 +4526,13 @@ function BorderedPane({
|
|
|
4317
4526
|
row,
|
|
4318
4527
|
/* @__PURE__ */ jsx(Text, { color: borderColor, children: "\u2502" })
|
|
4319
4528
|
] }, i)),
|
|
4320
|
-
/* @__PURE__ */ jsx(Text, { color: borderColor, children:
|
|
4529
|
+
/* @__PURE__ */ jsx(Text, { color: borderColor, children: bottomBorder })
|
|
4321
4530
|
] });
|
|
4322
4531
|
}
|
|
4323
|
-
|
|
4532
|
+
var Sidebar = React.memo(function Sidebar2({ sidebarRows, cursor, focused, statusMap, conflictCounts, mergedSet, prMap, activeKey, width, height, branchInput, filter }) {
|
|
4324
4533
|
const borderColor = focused ? "cyan" : "gray";
|
|
4325
4534
|
const innerWidth = width - 2;
|
|
4535
|
+
const title = filter ? `Worktrees /${filter.value}${filter.editing ? "\u2588" : ""}` : "Worktrees";
|
|
4326
4536
|
return /* @__PURE__ */ jsx(
|
|
4327
4537
|
BorderedPane,
|
|
4328
4538
|
{
|
|
@@ -4330,7 +4540,7 @@ function Sidebar({ sidebarRows, cursor, focused, statusMap, conflictCounts, merg
|
|
|
4330
4540
|
cursor,
|
|
4331
4541
|
focused,
|
|
4332
4542
|
borderColor,
|
|
4333
|
-
title
|
|
4543
|
+
title,
|
|
4334
4544
|
width,
|
|
4335
4545
|
height,
|
|
4336
4546
|
renderRow: (row, i, sel) => {
|
|
@@ -4371,7 +4581,7 @@ function Sidebar({ sidebarRows, cursor, focused, statusMap, conflictCounts, merg
|
|
|
4371
4581
|
}
|
|
4372
4582
|
}
|
|
4373
4583
|
);
|
|
4374
|
-
}
|
|
4584
|
+
});
|
|
4375
4585
|
function statusColor(status) {
|
|
4376
4586
|
const lower = status.toLowerCase();
|
|
4377
4587
|
if (lower.includes("progress") || lower.includes("review")) return "cyan";
|
|
@@ -4396,7 +4606,7 @@ function JiraListRow({
|
|
|
4396
4606
|
/* @__PURE__ */ jsx(Text, { children: truncate(issue.summary, summaryBudget) })
|
|
4397
4607
|
] });
|
|
4398
4608
|
}
|
|
4399
|
-
|
|
4609
|
+
var PrPane = React.memo(function PrPane2({ prRows, cursor, focused, localBranches, width, height }) {
|
|
4400
4610
|
const borderColor = focused ? "cyan" : "gray";
|
|
4401
4611
|
const innerWidth = width - 2;
|
|
4402
4612
|
return /* @__PURE__ */ jsx(
|
|
@@ -4427,7 +4637,7 @@ function PrPane({ prRows, cursor, focused, localBranches, width, height }) {
|
|
|
4427
4637
|
}
|
|
4428
4638
|
}
|
|
4429
4639
|
);
|
|
4430
|
-
}
|
|
4640
|
+
});
|
|
4431
4641
|
function TaskListRow({
|
|
4432
4642
|
task,
|
|
4433
4643
|
selected,
|
|
@@ -4449,22 +4659,21 @@ function TaskListRow({
|
|
|
4449
4659
|
/* @__PURE__ */ jsx(Text, { dimColor: true, children: idStr })
|
|
4450
4660
|
] });
|
|
4451
4661
|
}
|
|
4452
|
-
function TaskInputRow({ value, width }) {
|
|
4662
|
+
function TaskInputRow({ value, pos, width }) {
|
|
4453
4663
|
const budget = Math.max(4, width - 8);
|
|
4454
4664
|
return /* @__PURE__ */ jsxs(Box, { width, children: [
|
|
4455
4665
|
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
4456
4666
|
/* @__PURE__ */ jsx(Text, { color: "cyan", children: "+ " }),
|
|
4457
|
-
/* @__PURE__ */ jsx(
|
|
4458
|
-
/* @__PURE__ */ jsx(Text, { dimColor: true, children: "\u2588" })
|
|
4667
|
+
/* @__PURE__ */ jsx(InputText, { value, pos, budget })
|
|
4459
4668
|
] });
|
|
4460
4669
|
}
|
|
4461
|
-
|
|
4670
|
+
var TaskPane = React.memo(function TaskPane2({ taskRows, cursor, focused, width, height, taskInput }) {
|
|
4462
4671
|
const borderColor = focused ? "cyan" : "gray";
|
|
4463
4672
|
const innerWidth = width - 2;
|
|
4464
4673
|
const contentHeight = height - 2;
|
|
4465
4674
|
if (taskInput !== null && taskInput !== void 0) {
|
|
4466
4675
|
const rendered = [];
|
|
4467
|
-
rendered.push(/* @__PURE__ */ jsx(TaskInputRow, { value: taskInput, width: innerWidth }, "input"));
|
|
4676
|
+
rendered.push(/* @__PURE__ */ jsx(TaskInputRow, { value: taskInput.value, pos: taskInput.pos, width: innerWidth }, "input"));
|
|
4468
4677
|
let selectableIdx = 0;
|
|
4469
4678
|
for (let i = 0; i < contentHeight - 1 && i < taskRows.length; i++) {
|
|
4470
4679
|
const row = taskRows[i];
|
|
@@ -4519,8 +4728,8 @@ function TaskPane({ taskRows, cursor, focused, width, height, taskInput }) {
|
|
|
4519
4728
|
}
|
|
4520
4729
|
}
|
|
4521
4730
|
);
|
|
4522
|
-
}
|
|
4523
|
-
|
|
4731
|
+
});
|
|
4732
|
+
var JiraPane = React.memo(function JiraPane2({ jiraRows, cursor, focused, width, height }) {
|
|
4524
4733
|
const borderColor = focused ? "cyan" : "gray";
|
|
4525
4734
|
const innerWidth = width - 2;
|
|
4526
4735
|
return /* @__PURE__ */ jsx(
|
|
@@ -4550,12 +4759,13 @@ function JiraPane({ jiraRows, cursor, focused, width, height }) {
|
|
|
4550
4759
|
}
|
|
4551
4760
|
}
|
|
4552
4761
|
);
|
|
4553
|
-
}
|
|
4762
|
+
});
|
|
4554
4763
|
|
|
4555
4764
|
// src/tui-ink/TerminalPane.tsx
|
|
4765
|
+
import React2 from "react";
|
|
4556
4766
|
import { Box as Box2, Text as Text2 } from "ink";
|
|
4557
4767
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
4558
|
-
|
|
4768
|
+
var TerminalPane = React2.memo(function TerminalPane2({ lines, width, height, focused, placeholder, title, scrollback }) {
|
|
4559
4769
|
const borderColor = focused ? "cyan" : "gray";
|
|
4560
4770
|
const innerWidth = width - 2;
|
|
4561
4771
|
const contentHeight = height - 2;
|
|
@@ -4581,8 +4791,10 @@ function TerminalPane({ lines, width, height, focused, placeholder, title }) {
|
|
|
4581
4791
|
}
|
|
4582
4792
|
}
|
|
4583
4793
|
}
|
|
4794
|
+
const scrolledTitle = scrollback && scrollback > 0 ? `${title ?? "Terminal"} \u2500 \u2191${scrollback} paused (pgdn/type to resume)` : title;
|
|
4795
|
+
const topBorder = scrolledTitle ? "\u250C\u2500 " + scrolledTitle + " " + "\u2500".repeat(Math.max(0, innerWidth - scrolledTitle.length - 3)) + "\u2510" : "\u250C" + "\u2500".repeat(innerWidth) + "\u2510";
|
|
4584
4796
|
return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", width, children: [
|
|
4585
|
-
/* @__PURE__ */ jsx2(Text2, { color:
|
|
4797
|
+
/* @__PURE__ */ jsx2(Text2, { color: scrollback && scrollback > 0 ? "yellow" : borderColor, children: topBorder }),
|
|
4586
4798
|
content.map((row, i) => /* @__PURE__ */ jsxs2(Box2, { children: [
|
|
4587
4799
|
/* @__PURE__ */ jsx2(Text2, { color: borderColor, children: "\u2502" }),
|
|
4588
4800
|
/* @__PURE__ */ jsx2(Box2, { width: innerWidth, children: row }),
|
|
@@ -4590,19 +4802,20 @@ function TerminalPane({ lines, width, height, focused, placeholder, title }) {
|
|
|
4590
4802
|
] }, i)),
|
|
4591
4803
|
/* @__PURE__ */ jsx2(Text2, { color: borderColor, children: "\u2514" + "\u2500".repeat(innerWidth) + "\u2518" })
|
|
4592
4804
|
] });
|
|
4593
|
-
}
|
|
4805
|
+
});
|
|
4594
4806
|
|
|
4595
4807
|
// src/tui-ink/StatusBar.tsx
|
|
4808
|
+
import React3 from "react";
|
|
4596
4809
|
import { Box as Box3, Text as Text3 } from "ink";
|
|
4597
|
-
import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
4810
|
+
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
4598
4811
|
var PANE_HINTS = {
|
|
4599
|
-
sessions: " tab pane j/k nav enter start n new d remove
|
|
4600
|
-
tasks: " tab pane j/k nav enter toggle a add e edit w worktree d remove
|
|
4601
|
-
prs: " tab pane j/k nav enter checkout g sync
|
|
4602
|
-
jira: " tab pane j/k nav enter worktree o open g sync
|
|
4603
|
-
terminal: " tab pane ctrl+] detach "
|
|
4812
|
+
sessions: " tab pane j/k nav / filter enter start n new d remove u rebase g sync ? help q quit ",
|
|
4813
|
+
tasks: " tab pane j/k nav enter toggle a add e edit w worktree d remove ? help q quit ",
|
|
4814
|
+
prs: " tab pane j/k nav enter checkout o open g sync ? help q quit ",
|
|
4815
|
+
jira: " tab pane j/k nav enter worktree o open g sync ? help q quit ",
|
|
4816
|
+
terminal: " tab pane ctrl+] detach pgup/pgdn scroll "
|
|
4604
4817
|
};
|
|
4605
|
-
|
|
4818
|
+
var StatusBar = React3.memo(function StatusBar2({ message, pane, syncing }) {
|
|
4606
4819
|
if (message) {
|
|
4607
4820
|
return /* @__PURE__ */ jsxs3(Box3, { children: [
|
|
4608
4821
|
/* @__PURE__ */ jsxs3(Text3, { color: "yellow", children: [
|
|
@@ -4615,21 +4828,217 @@ function StatusBar({ message, pane, syncing }) {
|
|
|
4615
4828
|
}
|
|
4616
4829
|
return /* @__PURE__ */ jsxs3(Box3, { children: [
|
|
4617
4830
|
/* @__PURE__ */ jsx3(Text3, { dimColor: true, children: PANE_HINTS[pane] }),
|
|
4618
|
-
pane === "sessions" && /* @__PURE__ */ jsxs3(
|
|
4831
|
+
pane === "sessions" && /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
4619
4832
|
/* @__PURE__ */ jsx3(Text3, { dimColor: true, children: "[" }),
|
|
4620
4833
|
/* @__PURE__ */ jsx3(Text3, { color: "green", children: "\u25CF" }),
|
|
4621
4834
|
/* @__PURE__ */ jsx3(Text3, { dimColor: true, children: " working " }),
|
|
4622
4835
|
/* @__PURE__ */ jsx3(Text3, { color: "yellow", children: "\u25C6" }),
|
|
4623
4836
|
/* @__PURE__ */ jsx3(Text3, { dimColor: true, children: " needs input " }),
|
|
4837
|
+
/* @__PURE__ */ jsx3(Text3, { color: "cyan", children: "\u25C7" }),
|
|
4838
|
+
/* @__PURE__ */ jsx3(Text3, { dimColor: true, children: " done " }),
|
|
4624
4839
|
/* @__PURE__ */ jsx3(Text3, { dimColor: true, children: "\u25CB stopped]" })
|
|
4625
4840
|
] }),
|
|
4626
4841
|
syncing && /* @__PURE__ */ jsx3(Box3, { flexGrow: 1 }),
|
|
4627
4842
|
syncing && /* @__PURE__ */ jsx3(Text3, { color: "cyan", children: " syncing" })
|
|
4628
4843
|
] });
|
|
4844
|
+
});
|
|
4845
|
+
|
|
4846
|
+
// src/tui-ink/HelpOverlay.tsx
|
|
4847
|
+
import React4 from "react";
|
|
4848
|
+
import { Box as Box4, Text as Text4 } from "ink";
|
|
4849
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
4850
|
+
var HELP = [
|
|
4851
|
+
{ type: "section", label: "Navigation" },
|
|
4852
|
+
{ type: "key", keys: "tab", desc: "cycle pane focus" },
|
|
4853
|
+
{ type: "key", keys: "j/k or \u2191/\u2193", desc: "move cursor" },
|
|
4854
|
+
{ type: "key", keys: "ctrl+d / ctrl+u", desc: "half-page down / up" },
|
|
4855
|
+
{ type: "key", keys: "pgup / pgdn", desc: "page up / down" },
|
|
4856
|
+
{ type: "key", keys: "mouse", desc: "wheel scrolls, click focuses + selects" },
|
|
4857
|
+
{ type: "blank" },
|
|
4858
|
+
{ type: "section", label: "Worktrees pane" },
|
|
4859
|
+
{ type: "key", keys: "enter", desc: "start / show session" },
|
|
4860
|
+
{ type: "key", keys: "/", desc: "filter sessions (enter keeps, esc clears)" },
|
|
4861
|
+
{ type: "key", keys: "n", desc: "new worktree" },
|
|
4862
|
+
{ type: "key", keys: "d", desc: "remove worktree (press d again to confirm)" },
|
|
4863
|
+
{ type: "key", keys: ".", desc: "open in editor" },
|
|
4864
|
+
{ type: "key", keys: "u", desc: "rebase onto main" },
|
|
4865
|
+
{ type: "blank" },
|
|
4866
|
+
{ type: "section", label: "Pull Requests / Jira panes" },
|
|
4867
|
+
{ type: "key", keys: "enter", desc: "checkout PR / create worktree for issue" },
|
|
4868
|
+
{ type: "key", keys: "o", desc: "open in browser" },
|
|
4869
|
+
{ type: "blank" },
|
|
4870
|
+
{ type: "section", label: "Tasks pane" },
|
|
4871
|
+
{ type: "key", keys: "enter or x", desc: "toggle done" },
|
|
4872
|
+
{ type: "key", keys: "a / e / d", desc: "add / edit / remove task" },
|
|
4873
|
+
{ type: "key", keys: "w", desc: "create worktree from task" },
|
|
4874
|
+
{ type: "blank" },
|
|
4875
|
+
{ type: "section", label: "Terminal" },
|
|
4876
|
+
{ type: "key", keys: "ctrl+]", desc: "detach back to sidebar" },
|
|
4877
|
+
{ type: "key", keys: "pgup / pgdn", desc: "scroll history (typing resumes live)" },
|
|
4878
|
+
{ type: "blank" },
|
|
4879
|
+
{ type: "section", label: "Global" },
|
|
4880
|
+
{ type: "key", keys: "g / G", desc: "sync focused pane / sync everything" },
|
|
4881
|
+
{ type: "key", keys: "r", desc: "refresh all panes" },
|
|
4882
|
+
{ type: "key", keys: "?", desc: "toggle this help" },
|
|
4883
|
+
{ type: "key", keys: "q or ctrl+c", desc: "quit" }
|
|
4884
|
+
];
|
|
4885
|
+
var HelpOverlay = React4.memo(function HelpOverlay2({ width, height }) {
|
|
4886
|
+
const innerWidth = width - 2;
|
|
4887
|
+
const contentHeight = height - 2;
|
|
4888
|
+
const title = "Help \u2014 press ? or esc to close";
|
|
4889
|
+
const topBorder = "\u250C\u2500 " + title + " " + "\u2500".repeat(Math.max(0, innerWidth - title.length - 3)) + "\u2510";
|
|
4890
|
+
const rows = [];
|
|
4891
|
+
for (let i = 0; i < contentHeight; i++) {
|
|
4892
|
+
const line = HELP[i];
|
|
4893
|
+
if (!line || line.type === "blank") {
|
|
4894
|
+
rows.push(/* @__PURE__ */ jsx4(Text4, { children: " ".repeat(innerWidth) }, i));
|
|
4895
|
+
continue;
|
|
4896
|
+
}
|
|
4897
|
+
if (line.type === "section") {
|
|
4898
|
+
rows.push(
|
|
4899
|
+
/* @__PURE__ */ jsx4(Box4, { width: innerWidth, children: /* @__PURE__ */ jsx4(Text4, { color: "yellow", bold: true, children: " " + line.label }) }, i)
|
|
4900
|
+
);
|
|
4901
|
+
continue;
|
|
4902
|
+
}
|
|
4903
|
+
rows.push(
|
|
4904
|
+
/* @__PURE__ */ jsxs4(Box4, { width: innerWidth, children: [
|
|
4905
|
+
/* @__PURE__ */ jsx4(Text4, { color: "cyan", children: " " + line.keys.padEnd(18) }),
|
|
4906
|
+
/* @__PURE__ */ jsx4(Text4, { children: line.desc })
|
|
4907
|
+
] }, i)
|
|
4908
|
+
);
|
|
4909
|
+
}
|
|
4910
|
+
return /* @__PURE__ */ jsxs4(Box4, { flexDirection: "column", width, children: [
|
|
4911
|
+
/* @__PURE__ */ jsx4(Text4, { color: "cyan", children: topBorder }),
|
|
4912
|
+
rows.map((row, i) => /* @__PURE__ */ jsxs4(Box4, { children: [
|
|
4913
|
+
/* @__PURE__ */ jsx4(Text4, { color: "cyan", children: "\u2502" }),
|
|
4914
|
+
row,
|
|
4915
|
+
/* @__PURE__ */ jsx4(Text4, { color: "cyan", children: "\u2502" })
|
|
4916
|
+
] }, i)),
|
|
4917
|
+
/* @__PURE__ */ jsx4(Text4, { color: "cyan", children: "\u2514" + "\u2500".repeat(innerWidth) + "\u2518" })
|
|
4918
|
+
] });
|
|
4919
|
+
});
|
|
4920
|
+
|
|
4921
|
+
// src/tui-ink/line-editor.ts
|
|
4922
|
+
var KEYS = {
|
|
4923
|
+
UP: "\x1B[A",
|
|
4924
|
+
DOWN: "\x1B[B",
|
|
4925
|
+
RIGHT: "\x1B[C",
|
|
4926
|
+
LEFT: "\x1B[D",
|
|
4927
|
+
HOME: "\x1B[H",
|
|
4928
|
+
END: "\x1B[F",
|
|
4929
|
+
HOME_ALT: "\x1B[1~",
|
|
4930
|
+
END_ALT: "\x1B[4~",
|
|
4931
|
+
PAGE_UP: "\x1B[5~",
|
|
4932
|
+
PAGE_DOWN: "\x1B[6~",
|
|
4933
|
+
DELETE: "\x1B[3~",
|
|
4934
|
+
ESC: "\x1B",
|
|
4935
|
+
ENTER: "\r",
|
|
4936
|
+
BACKSPACE: "\x7F",
|
|
4937
|
+
BACKSPACE_ALT: "\b",
|
|
4938
|
+
CTRL_C: "",
|
|
4939
|
+
CTRL_D: "",
|
|
4940
|
+
CTRL_U: "",
|
|
4941
|
+
TAB: " "
|
|
4942
|
+
};
|
|
4943
|
+
function splitInputChunks(data) {
|
|
4944
|
+
const tokens = [];
|
|
4945
|
+
let i = 0;
|
|
4946
|
+
let run2 = "";
|
|
4947
|
+
const flushRun = () => {
|
|
4948
|
+
if (run2) {
|
|
4949
|
+
tokens.push(run2);
|
|
4950
|
+
run2 = "";
|
|
4951
|
+
}
|
|
4952
|
+
};
|
|
4953
|
+
while (i < data.length) {
|
|
4954
|
+
const ch = data[i];
|
|
4955
|
+
if (ch === "\x1B") {
|
|
4956
|
+
flushRun();
|
|
4957
|
+
const next = data[i + 1];
|
|
4958
|
+
if (next === "[") {
|
|
4959
|
+
let j = i + 2;
|
|
4960
|
+
while (j < data.length) {
|
|
4961
|
+
const code2 = data.charCodeAt(j);
|
|
4962
|
+
if (code2 >= 64 && code2 <= 126) break;
|
|
4963
|
+
j++;
|
|
4964
|
+
}
|
|
4965
|
+
tokens.push(data.slice(i, Math.min(j + 1, data.length)));
|
|
4966
|
+
i = j + 1;
|
|
4967
|
+
continue;
|
|
4968
|
+
}
|
|
4969
|
+
if (next === "O" && i + 2 < data.length) {
|
|
4970
|
+
tokens.push(data.slice(i, i + 3));
|
|
4971
|
+
i += 3;
|
|
4972
|
+
continue;
|
|
4973
|
+
}
|
|
4974
|
+
tokens.push("\x1B");
|
|
4975
|
+
i++;
|
|
4976
|
+
continue;
|
|
4977
|
+
}
|
|
4978
|
+
const code = data.charCodeAt(i);
|
|
4979
|
+
if (code < 32 || code === 127) {
|
|
4980
|
+
flushRun();
|
|
4981
|
+
tokens.push(ch);
|
|
4982
|
+
i++;
|
|
4983
|
+
continue;
|
|
4984
|
+
}
|
|
4985
|
+
run2 += ch;
|
|
4986
|
+
i++;
|
|
4987
|
+
}
|
|
4988
|
+
flushRun();
|
|
4989
|
+
return tokens;
|
|
4990
|
+
}
|
|
4991
|
+
function sanitizePaste(text) {
|
|
4992
|
+
const firstLine = text.split(/\r|\n/, 1)[0] ?? "";
|
|
4993
|
+
return firstLine.replace(/[\u0000-\u001f\u007f]/g, "");
|
|
4994
|
+
}
|
|
4995
|
+
function editLine(state, token) {
|
|
4996
|
+
const { value, pos } = state;
|
|
4997
|
+
switch (token) {
|
|
4998
|
+
case KEYS.ESC:
|
|
4999
|
+
case KEYS.CTRL_C:
|
|
5000
|
+
return { state, action: "cancel" };
|
|
5001
|
+
case KEYS.ENTER:
|
|
5002
|
+
return { state, action: "submit" };
|
|
5003
|
+
case KEYS.BACKSPACE:
|
|
5004
|
+
case KEYS.BACKSPACE_ALT:
|
|
5005
|
+
if (pos === 0) return { state, action: null };
|
|
5006
|
+
return {
|
|
5007
|
+
state: { value: value.slice(0, pos - 1) + value.slice(pos), pos: pos - 1 },
|
|
5008
|
+
action: null
|
|
5009
|
+
};
|
|
5010
|
+
case KEYS.DELETE:
|
|
5011
|
+
if (pos >= value.length) return { state, action: null };
|
|
5012
|
+
return {
|
|
5013
|
+
state: { value: value.slice(0, pos) + value.slice(pos + 1), pos },
|
|
5014
|
+
action: null
|
|
5015
|
+
};
|
|
5016
|
+
case KEYS.LEFT:
|
|
5017
|
+
return { state: { value, pos: Math.max(0, pos - 1) }, action: null };
|
|
5018
|
+
case KEYS.RIGHT:
|
|
5019
|
+
return { state: { value, pos: Math.min(value.length, pos + 1) }, action: null };
|
|
5020
|
+
case KEYS.HOME:
|
|
5021
|
+
case KEYS.HOME_ALT:
|
|
5022
|
+
return { state: { value, pos: 0 }, action: null };
|
|
5023
|
+
case KEYS.END:
|
|
5024
|
+
case KEYS.END_ALT:
|
|
5025
|
+
return { state: { value, pos: value.length }, action: null };
|
|
5026
|
+
case KEYS.CTRL_U:
|
|
5027
|
+
return { state: { value: value.slice(pos), pos: 0 }, action: null };
|
|
5028
|
+
}
|
|
5029
|
+
if (token.startsWith("\x1B") || token.charCodeAt(0) < 32 || token === "\x7F") {
|
|
5030
|
+
return { state, action: null };
|
|
5031
|
+
}
|
|
5032
|
+
const insert = sanitizePaste(token);
|
|
5033
|
+
if (!insert) return { state, action: null };
|
|
5034
|
+
return {
|
|
5035
|
+
state: { value: value.slice(0, pos) + insert + value.slice(pos), pos: pos + insert.length },
|
|
5036
|
+
action: null
|
|
5037
|
+
};
|
|
4629
5038
|
}
|
|
4630
5039
|
|
|
4631
5040
|
// src/tui-ink/App.tsx
|
|
4632
|
-
import { jsx as
|
|
5041
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
4633
5042
|
var DETACH_KEY = "";
|
|
4634
5043
|
var TAB_KEY = " ";
|
|
4635
5044
|
var RENDER_INTERVAL_MS = 50;
|
|
@@ -4637,7 +5046,7 @@ var MOUSE_SGR_RE = /\x1b\[<(\d+);(\d+);(\d+)[Mm]/;
|
|
|
4637
5046
|
function hasClaudeConversation(dir) {
|
|
4638
5047
|
try {
|
|
4639
5048
|
const resolved = path20.resolve(dir);
|
|
4640
|
-
const projectDir = resolved.replace(/[
|
|
5049
|
+
const projectDir = resolved.replace(/[^a-zA-Z0-9-]/g, "-");
|
|
4641
5050
|
const claudeProjectPath = path20.join(os6.homedir(), ".claude", "projects", projectDir);
|
|
4642
5051
|
if (!fs23.existsSync(claudeProjectPath)) return false;
|
|
4643
5052
|
const files = fs23.readdirSync(claudeProjectPath);
|
|
@@ -4732,20 +5141,35 @@ function App({ unsafe, onExit }) {
|
|
|
4732
5141
|
const [pendingJiraIssue, setPendingJiraIssue] = useState(null);
|
|
4733
5142
|
const [pendingTask, setPendingTask] = useState(null);
|
|
4734
5143
|
const [savedSessionCursor, setSavedSessionCursor] = useState(0);
|
|
5144
|
+
const [showHelp2, setShowHelp] = useState(false);
|
|
5145
|
+
const [filter, setFilter] = useState(null);
|
|
5146
|
+
const [pendingRemoveKey, setPendingRemoveKey] = useState(null);
|
|
5147
|
+
const [termScroll, setTermScroll] = useState(0);
|
|
5148
|
+
const setScrollBack = useCallback((n) => {
|
|
5149
|
+
termScrollBack.current = n;
|
|
5150
|
+
setTermScroll(n);
|
|
5151
|
+
}, []);
|
|
4735
5152
|
const localBranches = useMemo(() => new Set(sessions.map((s) => s.branch)), [sessions]);
|
|
4736
5153
|
const projectRows = useMemo(() => buildProjectRows(projects), [projects]);
|
|
4737
5154
|
const prRows = useMemo(() => buildPrRows(prMap), [prMap]);
|
|
4738
5155
|
const jiraRows = useMemo(() => buildJiraRows(jiraIssues), [jiraIssues]);
|
|
4739
5156
|
const taskRows = useMemo(() => buildTaskRows(tasks), [tasks]);
|
|
5157
|
+
const filteredSessions = useMemo(() => {
|
|
5158
|
+
const q = filter?.value.trim().toLowerCase();
|
|
5159
|
+
if (!q) return sessions;
|
|
5160
|
+
return sessions.filter(
|
|
5161
|
+
(s) => s.branch.toLowerCase().includes(q) || s.target.toLowerCase().includes(q)
|
|
5162
|
+
);
|
|
5163
|
+
}, [sessions, filter]);
|
|
4740
5164
|
const ptySessions = useRef(/* @__PURE__ */ new Map());
|
|
4741
5165
|
const sessionRows = useMemo(() => {
|
|
4742
5166
|
const sMap = /* @__PURE__ */ new Map();
|
|
4743
5167
|
for (const [key, pty2] of ptySessions.current) {
|
|
4744
5168
|
if (pty2.exited) continue;
|
|
4745
|
-
sMap.set(key, pty2.
|
|
5169
|
+
sMap.set(key, pty2.status);
|
|
4746
5170
|
}
|
|
4747
|
-
return buildSessionRows(
|
|
4748
|
-
}, [
|
|
5171
|
+
return buildSessionRows(filteredSessions, sMap);
|
|
5172
|
+
}, [filteredSessions, statusVersion]);
|
|
4749
5173
|
const topRows = topPaneMode === 0 /* SESSIONS */ ? sessionRows : projectRows;
|
|
4750
5174
|
const renderPending = useRef(false);
|
|
4751
5175
|
const focusRef = useRef(focus);
|
|
@@ -4785,6 +5209,13 @@ function App({ unsafe, onExit }) {
|
|
|
4785
5209
|
prRowsRef.current = prRows;
|
|
4786
5210
|
const acliAvailableRef = useRef(acliAvailable);
|
|
4787
5211
|
acliAvailableRef.current = acliAvailable;
|
|
5212
|
+
const showHelpRef = useRef(showHelp2);
|
|
5213
|
+
showHelpRef.current = showHelp2;
|
|
5214
|
+
const filterRef = useRef(filter);
|
|
5215
|
+
filterRef.current = filter;
|
|
5216
|
+
const pendingRemoveRef = useRef(pendingRemoveKey);
|
|
5217
|
+
pendingRemoveRef.current = pendingRemoveKey;
|
|
5218
|
+
const rebasingRef = useRef(false);
|
|
4788
5219
|
const hookServerRef = useRef(null);
|
|
4789
5220
|
const notifiedSessionsRef = useRef(/* @__PURE__ */ new Set());
|
|
4790
5221
|
const [dims, setDims] = useState(() => ({
|
|
@@ -4801,16 +5232,21 @@ function App({ unsafe, onExit }) {
|
|
|
4801
5232
|
const taskPaneHeight = Math.max(5, Math.floor(contentHeight * 0.2));
|
|
4802
5233
|
const prPaneHeight = Math.max(5, Math.floor((contentHeight - jiraPaneHeight - taskPaneHeight) * 0.45));
|
|
4803
5234
|
const sessionPaneHeight = contentHeight - prPaneHeight - taskPaneHeight - jiraPaneHeight;
|
|
5235
|
+
const layoutRef = useRef({ sidebarWidth, termInner, contentHeight, sessionPaneHeight, prPaneHeight, jiraPaneHeight, taskPaneHeight });
|
|
5236
|
+
layoutRef.current = { sidebarWidth, termInner, contentHeight, sessionPaneHeight, prPaneHeight, jiraPaneHeight, taskPaneHeight };
|
|
4804
5237
|
useEffect(() => {
|
|
5238
|
+
let attentionCount = 0;
|
|
4805
5239
|
let idleCount = 0;
|
|
4806
5240
|
let runningCount = 0;
|
|
4807
5241
|
for (const pty2 of ptySessions.current.values()) {
|
|
4808
5242
|
if (pty2.exited) continue;
|
|
4809
|
-
if (pty2.
|
|
5243
|
+
if (pty2.status === "attention") attentionCount++;
|
|
5244
|
+
else if (pty2.status === "idle") idleCount++;
|
|
4810
5245
|
else runningCount++;
|
|
4811
5246
|
}
|
|
4812
5247
|
const parts = [];
|
|
4813
|
-
if (
|
|
5248
|
+
if (attentionCount > 0) parts.push(`\u{1F7E1} ${attentionCount}`);
|
|
5249
|
+
if (idleCount > 0) parts.push(`\u{1F535} ${idleCount}`);
|
|
4814
5250
|
if (runningCount > 0) parts.push(`\u{1F7E2} ${runningCount}`);
|
|
4815
5251
|
const title = parts.length > 0 ? parts.join(" ") : "work dash";
|
|
4816
5252
|
process.stdout.write(`\x1B]0;${title}\x07`);
|
|
@@ -4818,23 +5254,21 @@ function App({ unsafe, onExit }) {
|
|
|
4818
5254
|
const computeGeneration = useRef(0);
|
|
4819
5255
|
const computeConflictsAndMerged = useCallback((sessionList) => {
|
|
4820
5256
|
const generation = ++computeGeneration.current;
|
|
4821
|
-
const tick = () => new Promise((r) => setTimeout(r, 0));
|
|
4822
5257
|
(async () => {
|
|
4823
5258
|
const counts = /* @__PURE__ */ new Map();
|
|
4824
5259
|
const merged = /* @__PURE__ */ new Set();
|
|
4825
5260
|
for (const s of sessionList) {
|
|
4826
5261
|
if (computeGeneration.current !== generation) return;
|
|
4827
|
-
await tick();
|
|
4828
5262
|
const existing = s.paths.find((p) => fs23.existsSync(p));
|
|
4829
5263
|
if (!existing || !s.branch) continue;
|
|
4830
5264
|
const key = sessionKey2(s);
|
|
4831
5265
|
try {
|
|
4832
|
-
const c =
|
|
5266
|
+
const c = await countConflictsAsync(s.branch, existing);
|
|
4833
5267
|
if (c > 0) counts.set(key, c);
|
|
4834
5268
|
} catch {
|
|
4835
5269
|
}
|
|
4836
5270
|
try {
|
|
4837
|
-
const { merged: isMerged } =
|
|
5271
|
+
const { merged: isMerged } = await isBranchMergedAsync(s.branch, existing);
|
|
4838
5272
|
if (isMerged) merged.add(key);
|
|
4839
5273
|
} catch {
|
|
4840
5274
|
}
|
|
@@ -4846,10 +5280,10 @@ function App({ unsafe, onExit }) {
|
|
|
4846
5280
|
})();
|
|
4847
5281
|
}, []);
|
|
4848
5282
|
const refreshPrs = useCallback(() => {
|
|
4849
|
-
if (!ghAvailable || !config || prFetching.current) return;
|
|
5283
|
+
if (!ghAvailable || !config || prFetching.current) return Promise.resolve();
|
|
4850
5284
|
prFetching.current = true;
|
|
4851
5285
|
setMessage("Loading PRs...");
|
|
4852
|
-
fetchAllPullRequests(config.repos).then((prs) => {
|
|
5286
|
+
return fetchAllPullRequests(config.repos).then((prs) => {
|
|
4853
5287
|
setPrMap(prs);
|
|
4854
5288
|
setMessage("");
|
|
4855
5289
|
}).catch(() => {
|
|
@@ -4858,9 +5292,9 @@ function App({ unsafe, onExit }) {
|
|
|
4858
5292
|
});
|
|
4859
5293
|
}, [ghAvailable, config]);
|
|
4860
5294
|
const refreshJira = useCallback(() => {
|
|
4861
|
-
if (!acliAvailable || jiraFetching.current) return;
|
|
5295
|
+
if (!acliAvailable || jiraFetching.current) return Promise.resolve();
|
|
4862
5296
|
jiraFetching.current = true;
|
|
4863
|
-
fetchMyJiraIssues().then((issues) => setJiraIssues(issues)).catch(() => {
|
|
5297
|
+
return fetchMyJiraIssues().then((issues) => setJiraIssues(issues)).catch(() => {
|
|
4864
5298
|
}).finally(() => {
|
|
4865
5299
|
jiraFetching.current = false;
|
|
4866
5300
|
});
|
|
@@ -4873,11 +5307,11 @@ function App({ unsafe, onExit }) {
|
|
|
4873
5307
|
setSessions(updated);
|
|
4874
5308
|
computeConflictsAndMerged(updated);
|
|
4875
5309
|
}, [computeConflictsAndMerged]);
|
|
4876
|
-
const
|
|
5310
|
+
const statusMap = useMemo(() => {
|
|
4877
5311
|
const map = /* @__PURE__ */ new Map();
|
|
4878
5312
|
for (const [key, pty2] of ptySessions.current) {
|
|
4879
5313
|
if (pty2.exited) continue;
|
|
4880
|
-
map.set(key, pty2.
|
|
5314
|
+
map.set(key, pty2.status);
|
|
4881
5315
|
}
|
|
4882
5316
|
return map;
|
|
4883
5317
|
}, [statusVersion]);
|
|
@@ -4887,6 +5321,8 @@ function App({ unsafe, onExit }) {
|
|
|
4887
5321
|
setTimeout(() => {
|
|
4888
5322
|
renderPending.current = false;
|
|
4889
5323
|
try {
|
|
5324
|
+
const activeKey2 = activeKeyRef.current;
|
|
5325
|
+
if (!activeKey2 || ptySessions.current.get(activeKey2) !== pty2) return;
|
|
4890
5326
|
if (termScrollBack.current > 0) return;
|
|
4891
5327
|
const lines = renderBufferLines(pty2.terminal.buffer.active, termInner, contentHeight - 2);
|
|
4892
5328
|
setTermLines(lines);
|
|
@@ -4903,6 +5339,16 @@ function App({ unsafe, onExit }) {
|
|
|
4903
5339
|
} catch {
|
|
4904
5340
|
}
|
|
4905
5341
|
}, [termInner, contentHeight]);
|
|
5342
|
+
const scrollTerminal = useCallback((linesUp) => {
|
|
5343
|
+
const pty2 = activeKeyRef.current ? ptySessions.current.get(activeKeyRef.current) : void 0;
|
|
5344
|
+
if (!pty2 || pty2.exited) return;
|
|
5345
|
+
const maxScroll = pty2.terminal.buffer.active.baseY;
|
|
5346
|
+
const next = Math.max(0, Math.min(maxScroll, termScrollBack.current + linesUp));
|
|
5347
|
+
if (next !== termScrollBack.current) {
|
|
5348
|
+
setScrollBack(next);
|
|
5349
|
+
renderTermAtScroll();
|
|
5350
|
+
}
|
|
5351
|
+
}, [setScrollBack, renderTermAtScroll]);
|
|
4906
5352
|
const findPtyByCwd = useCallback((cwd) => {
|
|
4907
5353
|
const normalized = path20.resolve(cwd).toLowerCase();
|
|
4908
5354
|
for (const pty2 of ptySessions.current.values()) {
|
|
@@ -4969,10 +5415,12 @@ function App({ unsafe, onExit }) {
|
|
|
4969
5415
|
callback: (cwd, event) => {
|
|
4970
5416
|
const pty2 = findPtyByCwd(cwd);
|
|
4971
5417
|
if (!pty2) return;
|
|
4972
|
-
if (event === "
|
|
4973
|
-
pty2.
|
|
5418
|
+
if (event === "notification") {
|
|
5419
|
+
pty2.setStatus("attention");
|
|
5420
|
+
} else if (event === "stop") {
|
|
5421
|
+
pty2.setStatus("idle");
|
|
4974
5422
|
} else if (event === "prompt_submit") {
|
|
4975
|
-
pty2.
|
|
5423
|
+
pty2.setStatus("running");
|
|
4976
5424
|
}
|
|
4977
5425
|
const dedupKey = ptyDedupKey(pty2);
|
|
4978
5426
|
const kind = notifyKindForEvent(
|
|
@@ -5033,7 +5481,7 @@ function App({ unsafe, onExit }) {
|
|
|
5033
5481
|
const switchDisplay = useCallback((s) => {
|
|
5034
5482
|
const k = sessionKey2(s);
|
|
5035
5483
|
if (activeKeyRef.current === k) return;
|
|
5036
|
-
|
|
5484
|
+
setScrollBack(0);
|
|
5037
5485
|
if (activeKeyRef.current) {
|
|
5038
5486
|
ptySessions.current.get(activeKeyRef.current)?.setOutputHandler(void 0);
|
|
5039
5487
|
}
|
|
@@ -5084,6 +5532,7 @@ function App({ unsafe, onExit }) {
|
|
|
5084
5532
|
if (activeKeyRef.current && activeKeyRef.current !== key) {
|
|
5085
5533
|
ptySessions.current.get(activeKeyRef.current)?.setOutputHandler(void 0);
|
|
5086
5534
|
}
|
|
5535
|
+
setScrollBack(0);
|
|
5087
5536
|
setActiveKey(key);
|
|
5088
5537
|
setFocus(4 /* TERMINAL */);
|
|
5089
5538
|
pty2.resize(termInner, contentHeight - 2);
|
|
@@ -5274,8 +5723,8 @@ function App({ unsafe, onExit }) {
|
|
|
5274
5723
|
connectPty(key, setupPty);
|
|
5275
5724
|
}, [unsafe, termInner, contentHeight, refreshSessions, connectPty, registerPty, savedSessionCursor, config]);
|
|
5276
5725
|
useEffect(() => {
|
|
5277
|
-
const
|
|
5278
|
-
const
|
|
5726
|
+
const handleKey = (key) => {
|
|
5727
|
+
const layout = layoutRef.current;
|
|
5279
5728
|
const mouseMatch = MOUSE_SGR_RE.exec(key);
|
|
5280
5729
|
if (mouseMatch) {
|
|
5281
5730
|
const button = parseInt(mouseMatch[1], 10);
|
|
@@ -5283,48 +5732,52 @@ function App({ unsafe, onExit }) {
|
|
|
5283
5732
|
const row = parseInt(mouseMatch[3], 10);
|
|
5284
5733
|
if (button === 64 || button === 65) {
|
|
5285
5734
|
const delta = button === 64 ? -1 : 1;
|
|
5286
|
-
if (col <= sidebarWidth) {
|
|
5287
|
-
if (row <= sessionPaneHeight) {
|
|
5735
|
+
if (col <= layout.sidebarWidth) {
|
|
5736
|
+
if (row <= layout.sessionPaneHeight) {
|
|
5288
5737
|
moveSessionCursor(delta);
|
|
5289
|
-
} else if (row <= sessionPaneHeight + prPaneHeight) {
|
|
5738
|
+
} else if (row <= layout.sessionPaneHeight + layout.prPaneHeight) {
|
|
5290
5739
|
movePrCursor(delta);
|
|
5291
|
-
} else if (jiraPaneHeight > 0 && row <= sessionPaneHeight + prPaneHeight + jiraPaneHeight) {
|
|
5740
|
+
} else if (layout.jiraPaneHeight > 0 && row <= layout.sessionPaneHeight + layout.prPaneHeight + layout.jiraPaneHeight) {
|
|
5292
5741
|
moveJiraCursor(delta);
|
|
5293
5742
|
} else {
|
|
5294
5743
|
moveTaskCursor(delta);
|
|
5295
5744
|
}
|
|
5296
5745
|
} else {
|
|
5297
|
-
|
|
5298
|
-
if (pty2 && !pty2.exited) {
|
|
5299
|
-
const maxScroll = pty2.terminal.buffer.active.baseY;
|
|
5300
|
-
const newScroll = Math.max(0, Math.min(maxScroll, termScrollBack.current - delta * 3));
|
|
5301
|
-
if (newScroll !== termScrollBack.current) {
|
|
5302
|
-
termScrollBack.current = newScroll;
|
|
5303
|
-
renderTermAtScroll();
|
|
5304
|
-
}
|
|
5305
|
-
}
|
|
5746
|
+
scrollTerminal(-delta * 3);
|
|
5306
5747
|
}
|
|
5307
5748
|
return;
|
|
5308
5749
|
}
|
|
5309
5750
|
if (button === 0) {
|
|
5310
|
-
if (col <= sidebarWidth) {
|
|
5311
|
-
if (row <= sessionPaneHeight) {
|
|
5751
|
+
if (col <= layout.sidebarWidth) {
|
|
5752
|
+
if (row <= layout.sessionPaneHeight) {
|
|
5312
5753
|
setFocus(0 /* SESSIONS */);
|
|
5313
5754
|
const visualIdx = row - 2;
|
|
5314
|
-
if (visualIdx >= 0)
|
|
5315
|
-
|
|
5755
|
+
if (visualIdx >= 0) {
|
|
5756
|
+
const offset = computeScrollOffset(topRowsRef.current, sessionCursorRef.current, layout.sessionPaneHeight - 2);
|
|
5757
|
+
setSessionCursor(visualRowToCursor(topRowsRef.current, visualIdx + offset));
|
|
5758
|
+
}
|
|
5759
|
+
} else if (row <= layout.sessionPaneHeight + layout.prPaneHeight) {
|
|
5316
5760
|
setFocus(2 /* PRS */);
|
|
5317
|
-
const visualIdx = row - sessionPaneHeight - 2;
|
|
5318
|
-
if (visualIdx >= 0)
|
|
5319
|
-
|
|
5761
|
+
const visualIdx = row - layout.sessionPaneHeight - 2;
|
|
5762
|
+
if (visualIdx >= 0) {
|
|
5763
|
+
const offset = computeScrollOffset(prRowsRef.current, prCursorRef.current, layout.prPaneHeight - 2);
|
|
5764
|
+
setPrCursor(visualRowToCursor(prRowsRef.current, visualIdx + offset));
|
|
5765
|
+
}
|
|
5766
|
+
} else if (layout.jiraPaneHeight > 0 && row <= layout.sessionPaneHeight + layout.prPaneHeight + layout.jiraPaneHeight) {
|
|
5320
5767
|
setFocus(3 /* JIRA */);
|
|
5321
|
-
const visualIdx = row - sessionPaneHeight - prPaneHeight - 2;
|
|
5322
|
-
if (visualIdx >= 0)
|
|
5768
|
+
const visualIdx = row - layout.sessionPaneHeight - layout.prPaneHeight - 2;
|
|
5769
|
+
if (visualIdx >= 0) {
|
|
5770
|
+
const offset = computeScrollOffset(jiraRowsRef.current, jiraCursorRef.current, layout.jiraPaneHeight - 2);
|
|
5771
|
+
setJiraCursor(visualRowToCursor(jiraRowsRef.current, visualIdx + offset));
|
|
5772
|
+
}
|
|
5323
5773
|
} else {
|
|
5324
5774
|
setFocus(1 /* TASKS */);
|
|
5325
|
-
const taskStart = sessionPaneHeight + prPaneHeight + jiraPaneHeight;
|
|
5775
|
+
const taskStart = layout.sessionPaneHeight + layout.prPaneHeight + layout.jiraPaneHeight;
|
|
5326
5776
|
const visualIdx = row - taskStart - 2;
|
|
5327
|
-
if (visualIdx >= 0)
|
|
5777
|
+
if (visualIdx >= 0) {
|
|
5778
|
+
const offset = computeScrollOffset(taskRowsRef.current, taskCursorRef.current, layout.taskPaneHeight - 2);
|
|
5779
|
+
setTaskCursor(visualRowToCursor(taskRowsRef.current, visualIdx + offset));
|
|
5780
|
+
}
|
|
5328
5781
|
}
|
|
5329
5782
|
} else {
|
|
5330
5783
|
const activePty = activeKeyRef.current ? ptySessions.current.get(activeKeyRef.current) : void 0;
|
|
@@ -5335,18 +5788,25 @@ function App({ unsafe, onExit }) {
|
|
|
5335
5788
|
}
|
|
5336
5789
|
return;
|
|
5337
5790
|
}
|
|
5791
|
+
if (showHelpRef.current) {
|
|
5792
|
+
if (key === "?" || key === KEYS.ESC || key === "q" || key === KEYS.CTRL_C) {
|
|
5793
|
+
setShowHelp(false);
|
|
5794
|
+
}
|
|
5795
|
+
return;
|
|
5796
|
+
}
|
|
5338
5797
|
if (branchInputRef.current) {
|
|
5339
|
-
|
|
5798
|
+
const { projectName, isGroup, value, pos } = branchInputRef.current;
|
|
5799
|
+
const { state, action } = editLine({ value, pos }, key);
|
|
5800
|
+
if (action === "cancel") {
|
|
5340
5801
|
setBranchInput(null);
|
|
5341
5802
|
setTopPaneMode(1 /* PROJECTS */);
|
|
5342
5803
|
setMessage("Esc to go back");
|
|
5343
5804
|
return;
|
|
5344
5805
|
}
|
|
5345
|
-
if (
|
|
5346
|
-
const { projectName, value, isGroup } = branchInputRef.current;
|
|
5806
|
+
if (action === "submit") {
|
|
5347
5807
|
setBranchInput(null);
|
|
5348
|
-
if (value.trim()) {
|
|
5349
|
-
handleCreateWorktree(projectName, value.trim());
|
|
5808
|
+
if (state.value.trim()) {
|
|
5809
|
+
handleCreateWorktree(projectName, state.value.trim());
|
|
5350
5810
|
} else if (!isGroup) {
|
|
5351
5811
|
handleLaunchBaseRepo(projectName);
|
|
5352
5812
|
} else {
|
|
@@ -5354,12 +5814,36 @@ function App({ unsafe, onExit }) {
|
|
|
5354
5814
|
}
|
|
5355
5815
|
return;
|
|
5356
5816
|
}
|
|
5357
|
-
|
|
5358
|
-
|
|
5817
|
+
setBranchInput({ projectName, isGroup, ...state });
|
|
5818
|
+
return;
|
|
5819
|
+
}
|
|
5820
|
+
if (filterRef.current?.editing) {
|
|
5821
|
+
if (key === KEYS.UP) {
|
|
5822
|
+
moveSessionCursor(-1);
|
|
5359
5823
|
return;
|
|
5360
5824
|
}
|
|
5361
|
-
if (key
|
|
5362
|
-
|
|
5825
|
+
if (key === KEYS.DOWN) {
|
|
5826
|
+
moveSessionCursor(1);
|
|
5827
|
+
return;
|
|
5828
|
+
}
|
|
5829
|
+
const current = filterRef.current.value;
|
|
5830
|
+
const { state, action } = editLine({ value: current, pos: current.length }, key);
|
|
5831
|
+
if (action === "cancel") {
|
|
5832
|
+
setFilter(null);
|
|
5833
|
+
setSessionCursor(0);
|
|
5834
|
+
setMessage("");
|
|
5835
|
+
return;
|
|
5836
|
+
}
|
|
5837
|
+
if (action === "submit" || key === TAB_KEY) {
|
|
5838
|
+
const value = current.trim();
|
|
5839
|
+
setFilter(value ? { value, editing: false } : null);
|
|
5840
|
+
setMessage(value ? `Filtering: ${value} (esc clears)` : "");
|
|
5841
|
+
return;
|
|
5842
|
+
}
|
|
5843
|
+
if (state.value !== current) {
|
|
5844
|
+
setFilter({ value: state.value, editing: true });
|
|
5845
|
+
setSessionCursor(0);
|
|
5846
|
+
}
|
|
5363
5847
|
return;
|
|
5364
5848
|
}
|
|
5365
5849
|
if (key === TAB_KEY) {
|
|
@@ -5392,11 +5876,24 @@ function App({ unsafe, onExit }) {
|
|
|
5392
5876
|
setMessage("");
|
|
5393
5877
|
return;
|
|
5394
5878
|
}
|
|
5395
|
-
|
|
5879
|
+
if (key === KEYS.PAGE_UP) {
|
|
5880
|
+
scrollTerminal(Math.max(1, layout.contentHeight - 3));
|
|
5881
|
+
return;
|
|
5882
|
+
}
|
|
5883
|
+
if (key === KEYS.PAGE_DOWN) {
|
|
5884
|
+
scrollTerminal(-Math.max(1, layout.contentHeight - 3));
|
|
5885
|
+
return;
|
|
5886
|
+
}
|
|
5887
|
+
if (termScrollBack.current > 0) setScrollBack(0);
|
|
5396
5888
|
ptySessions.current.get(activeKeyRef.current)?.write(key);
|
|
5397
5889
|
return;
|
|
5398
5890
|
}
|
|
5399
5891
|
setMessage("");
|
|
5892
|
+
if (pendingRemoveRef.current && key !== "d") setPendingRemoveKey(null);
|
|
5893
|
+
if (key === "?") {
|
|
5894
|
+
setShowHelp(true);
|
|
5895
|
+
return;
|
|
5896
|
+
}
|
|
5400
5897
|
if (key === "G") {
|
|
5401
5898
|
if (syncing) return;
|
|
5402
5899
|
setSyncing(true);
|
|
@@ -5411,8 +5908,7 @@ function App({ unsafe, onExit }) {
|
|
|
5411
5908
|
);
|
|
5412
5909
|
}
|
|
5413
5910
|
refreshSessions();
|
|
5414
|
-
refreshPrs();
|
|
5415
|
-
refreshJira();
|
|
5911
|
+
await Promise.all([refreshPrs(), refreshJira()]);
|
|
5416
5912
|
refreshTasks();
|
|
5417
5913
|
computeConflictsAndMerged(sessionsRef.current);
|
|
5418
5914
|
setSyncing(false);
|
|
@@ -5420,6 +5916,33 @@ function App({ unsafe, onExit }) {
|
|
|
5420
5916
|
})();
|
|
5421
5917
|
return;
|
|
5422
5918
|
}
|
|
5919
|
+
if (taskInputRef.current === null) {
|
|
5920
|
+
const pageJump = (dir, full) => {
|
|
5921
|
+
const heightFor = focusRef.current === 2 /* PRS */ ? layout.prPaneHeight : focusRef.current === 3 /* JIRA */ ? layout.jiraPaneHeight : focusRef.current === 1 /* TASKS */ ? layout.taskPaneHeight : layout.sessionPaneHeight;
|
|
5922
|
+
const page = Math.max(1, full ? heightFor - 2 : Math.floor((heightFor - 2) / 2));
|
|
5923
|
+
const delta = page * dir;
|
|
5924
|
+
if (focusRef.current === 2 /* PRS */) movePrCursor(delta);
|
|
5925
|
+
else if (focusRef.current === 3 /* JIRA */) moveJiraCursor(delta);
|
|
5926
|
+
else if (focusRef.current === 1 /* TASKS */) moveTaskCursor(delta);
|
|
5927
|
+
else moveSessionCursor(delta);
|
|
5928
|
+
};
|
|
5929
|
+
if (key === KEYS.PAGE_UP) {
|
|
5930
|
+
pageJump(-1, true);
|
|
5931
|
+
return;
|
|
5932
|
+
}
|
|
5933
|
+
if (key === KEYS.PAGE_DOWN) {
|
|
5934
|
+
pageJump(1, true);
|
|
5935
|
+
return;
|
|
5936
|
+
}
|
|
5937
|
+
if (key === KEYS.CTRL_U) {
|
|
5938
|
+
pageJump(-1, false);
|
|
5939
|
+
return;
|
|
5940
|
+
}
|
|
5941
|
+
if (key === KEYS.CTRL_D) {
|
|
5942
|
+
pageJump(1, false);
|
|
5943
|
+
return;
|
|
5944
|
+
}
|
|
5945
|
+
}
|
|
5423
5946
|
if (topPaneModeRef.current === 1 /* PROJECTS */) {
|
|
5424
5947
|
if (key === "\x1B" || key === "" || key === "q") {
|
|
5425
5948
|
setTopPaneMode(0 /* SESSIONS */);
|
|
@@ -5464,7 +5987,7 @@ function App({ unsafe, onExit }) {
|
|
|
5464
5987
|
handleCreateWorktree(row.name, branch);
|
|
5465
5988
|
} else {
|
|
5466
5989
|
setTopPaneMode(2 /* BRANCH_INPUT */);
|
|
5467
|
-
setBranchInput({ projectName: row.name, value: "", isGroup: row.isGroup });
|
|
5990
|
+
setBranchInput({ projectName: row.name, value: "", pos: 0, isGroup: row.isGroup });
|
|
5468
5991
|
setMessage(row.isGroup ? "Type branch name, Enter to create, Esc to cancel" : "Type branch name (empty for base repo), Enter to create, Esc to cancel");
|
|
5469
5992
|
}
|
|
5470
5993
|
}
|
|
@@ -5474,14 +5997,15 @@ function App({ unsafe, onExit }) {
|
|
|
5474
5997
|
}
|
|
5475
5998
|
if (focusRef.current === 1 /* TASKS */) {
|
|
5476
5999
|
if (taskInputRef.current !== null) {
|
|
5477
|
-
|
|
6000
|
+
const { state, action } = editLine(taskInputRef.current, key);
|
|
6001
|
+
if (action === "cancel") {
|
|
5478
6002
|
setTaskInput(null);
|
|
5479
6003
|
setTaskEditId(null);
|
|
5480
6004
|
setMessage("");
|
|
5481
6005
|
return;
|
|
5482
6006
|
}
|
|
5483
|
-
if (
|
|
5484
|
-
const text = taskInputRef.current.trim();
|
|
6007
|
+
if (action === "submit") {
|
|
6008
|
+
const text = taskInputRef.current.value.trim();
|
|
5485
6009
|
const editId = taskEditIdRef.current;
|
|
5486
6010
|
setTaskInput(null);
|
|
5487
6011
|
setTaskEditId(null);
|
|
@@ -5496,12 +6020,7 @@ function App({ unsafe, onExit }) {
|
|
|
5496
6020
|
}
|
|
5497
6021
|
return;
|
|
5498
6022
|
}
|
|
5499
|
-
|
|
5500
|
-
setTaskInput((prev) => prev !== null ? prev.slice(0, -1) : null);
|
|
5501
|
-
return;
|
|
5502
|
-
}
|
|
5503
|
-
if (key.charCodeAt(0) < 32) return;
|
|
5504
|
-
setTaskInput((prev) => prev !== null ? prev + key : null);
|
|
6023
|
+
setTaskInput(state);
|
|
5505
6024
|
return;
|
|
5506
6025
|
}
|
|
5507
6026
|
if (key === "\x1B[A" || key === "k") {
|
|
@@ -5521,7 +6040,7 @@ function App({ unsafe, onExit }) {
|
|
|
5521
6040
|
return;
|
|
5522
6041
|
}
|
|
5523
6042
|
if (key === "a") {
|
|
5524
|
-
setTaskInput("");
|
|
6043
|
+
setTaskInput({ value: "", pos: 0 });
|
|
5525
6044
|
setMessage("Type task, Enter to add, Esc to cancel");
|
|
5526
6045
|
return;
|
|
5527
6046
|
}
|
|
@@ -5529,7 +6048,7 @@ function App({ unsafe, onExit }) {
|
|
|
5529
6048
|
const row = cursorToRow(taskRowsRef.current, taskCursorRef.current);
|
|
5530
6049
|
if (row?.type === "task") {
|
|
5531
6050
|
setTaskEditId(row.task.id);
|
|
5532
|
-
setTaskInput(row.task.text);
|
|
6051
|
+
setTaskInput({ value: row.task.text, pos: row.task.text.length });
|
|
5533
6052
|
setMessage("Edit task, Enter to save, Esc to cancel");
|
|
5534
6053
|
}
|
|
5535
6054
|
return;
|
|
@@ -5685,6 +6204,16 @@ function App({ unsafe, onExit }) {
|
|
|
5685
6204
|
onExit();
|
|
5686
6205
|
return;
|
|
5687
6206
|
}
|
|
6207
|
+
if (key === KEYS.ESC && filterRef.current) {
|
|
6208
|
+
setFilter(null);
|
|
6209
|
+
setSessionCursor(0);
|
|
6210
|
+
return;
|
|
6211
|
+
}
|
|
6212
|
+
if (key === "/" && topPaneModeRef.current === 0 /* SESSIONS */) {
|
|
6213
|
+
setFilter({ value: filterRef.current?.value ?? "", editing: true });
|
|
6214
|
+
setMessage("Type to filter, Enter to keep, Esc to clear");
|
|
6215
|
+
return;
|
|
6216
|
+
}
|
|
5688
6217
|
if (key === "\x1B[A" || key === "k") {
|
|
5689
6218
|
moveSessionCursor(-1);
|
|
5690
6219
|
return;
|
|
@@ -5705,6 +6234,12 @@ function App({ unsafe, onExit }) {
|
|
|
5705
6234
|
if (row?.type !== "session") return;
|
|
5706
6235
|
const s = row.session;
|
|
5707
6236
|
const k = sessionKey2(s);
|
|
6237
|
+
if (pendingRemoveRef.current !== k) {
|
|
6238
|
+
setPendingRemoveKey(k);
|
|
6239
|
+
setMessage(`Remove ${s.target}/${s.branch}? Press d again to confirm, any other key cancels`);
|
|
6240
|
+
return;
|
|
6241
|
+
}
|
|
6242
|
+
setPendingRemoveKey(null);
|
|
5708
6243
|
const pty2 = ptySessions.current.get(k);
|
|
5709
6244
|
if (pty2) {
|
|
5710
6245
|
notifiedSessionsRef.current.delete(ptyDedupKey(pty2));
|
|
@@ -5761,14 +6296,22 @@ function App({ unsafe, onExit }) {
|
|
|
5761
6296
|
setMessage("Session path no longer exists");
|
|
5762
6297
|
return;
|
|
5763
6298
|
}
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
setMessage(`Rebase failed: ${err}`);
|
|
5768
|
-
} else {
|
|
5769
|
-
setMessage(`Rebased ${s.branch} onto main`);
|
|
5770
|
-
computeConflictsAndMerged(sessionsRef.current);
|
|
6299
|
+
if (rebasingRef.current) {
|
|
6300
|
+
setMessage("A rebase is already running");
|
|
6301
|
+
return;
|
|
5771
6302
|
}
|
|
6303
|
+
rebasingRef.current = true;
|
|
6304
|
+
setMessage(`Rebasing ${s.branch}...`);
|
|
6305
|
+
void rebaseOntoMainAsync(s.branch, existing).then((err) => {
|
|
6306
|
+
if (err) {
|
|
6307
|
+
setMessage(`Rebase failed: ${err}`);
|
|
6308
|
+
} else {
|
|
6309
|
+
setMessage(`Rebased ${s.branch} onto main`);
|
|
6310
|
+
computeConflictsAndMerged(sessionsRef.current);
|
|
6311
|
+
}
|
|
6312
|
+
}).catch((e) => setMessage(`Rebase failed: ${e.message}`)).finally(() => {
|
|
6313
|
+
rebasingRef.current = false;
|
|
6314
|
+
});
|
|
5772
6315
|
return;
|
|
5773
6316
|
}
|
|
5774
6317
|
if (key === "g") {
|
|
@@ -5785,7 +6328,7 @@ function App({ unsafe, onExit }) {
|
|
|
5785
6328
|
);
|
|
5786
6329
|
}
|
|
5787
6330
|
refreshSessions();
|
|
5788
|
-
refreshPrs();
|
|
6331
|
+
await refreshPrs();
|
|
5789
6332
|
computeConflictsAndMerged(sessionsRef.current);
|
|
5790
6333
|
setSyncing(false);
|
|
5791
6334
|
setMessage("Sessions synced");
|
|
@@ -5794,18 +6337,23 @@ function App({ unsafe, onExit }) {
|
|
|
5794
6337
|
}
|
|
5795
6338
|
if (key === "r") {
|
|
5796
6339
|
refreshSessions();
|
|
5797
|
-
refreshPrs();
|
|
5798
|
-
refreshJira();
|
|
6340
|
+
void refreshPrs();
|
|
6341
|
+
void refreshJira();
|
|
5799
6342
|
refreshTasks();
|
|
5800
6343
|
if (!ghAvailable) setMessage("Refreshed");
|
|
5801
6344
|
return;
|
|
5802
6345
|
}
|
|
5803
6346
|
};
|
|
6347
|
+
const handler = (data) => {
|
|
6348
|
+
for (const key of splitInputChunks(data.toString("utf8"))) {
|
|
6349
|
+
handleKey(key);
|
|
6350
|
+
}
|
|
6351
|
+
};
|
|
5804
6352
|
process.stdin.on("data", handler);
|
|
5805
6353
|
return () => {
|
|
5806
6354
|
process.stdin.removeListener("data", handler);
|
|
5807
6355
|
};
|
|
5808
|
-
}, [onExit, activateSession, refreshSessions, refreshPrs, refreshJira, refreshTasks, moveSessionCursor, movePrCursor, moveJiraCursor, moveTaskCursor, syncSessionCursorToActive, handleCreateWorktree, savedSessionCursor, config, computeConflictsAndMerged, syncing, ghAvailable, prMap]);
|
|
6356
|
+
}, [onExit, activateSession, refreshSessions, refreshPrs, refreshJira, refreshTasks, moveSessionCursor, movePrCursor, moveJiraCursor, moveTaskCursor, syncSessionCursorToActive, handleCreateWorktree, handleLaunchBaseRepo, savedSessionCursor, config, computeConflictsAndMerged, syncing, ghAvailable, prMap, scrollTerminal, setScrollBack]);
|
|
5809
6357
|
useEffect(() => {
|
|
5810
6358
|
const handler = () => {
|
|
5811
6359
|
const newCols = process.stdout.columns || 80;
|
|
@@ -5817,6 +6365,10 @@ function App({ unsafe, onExit }) {
|
|
|
5817
6365
|
const newTermInner = newCols - Math.min(60, Math.floor(newCols * 0.525)) - 2;
|
|
5818
6366
|
const newContentHeight = newRows - 3;
|
|
5819
6367
|
pty2.resize(newTermInner, newContentHeight);
|
|
6368
|
+
try {
|
|
6369
|
+
setTermLines(renderBufferLines(pty2.terminal.buffer.active, newTermInner, newContentHeight, termScrollBack.current));
|
|
6370
|
+
} catch {
|
|
6371
|
+
}
|
|
5820
6372
|
}
|
|
5821
6373
|
}
|
|
5822
6374
|
};
|
|
@@ -5836,12 +6388,11 @@ function App({ unsafe, onExit }) {
|
|
|
5836
6388
|
}, 5 * 60 * 1e3);
|
|
5837
6389
|
return () => clearInterval(interval);
|
|
5838
6390
|
}, []);
|
|
5839
|
-
const statusMap = buildStatusMap();
|
|
5840
6391
|
const placeholder = !activeKey ? "Select a session and press Enter" : "Press Enter to start session";
|
|
5841
|
-
return /* @__PURE__ */
|
|
5842
|
-
/* @__PURE__ */
|
|
5843
|
-
/* @__PURE__ */
|
|
5844
|
-
/* @__PURE__ */
|
|
6392
|
+
return /* @__PURE__ */ jsxs5(Box5, { flexDirection: "column", width: cols, height: rows, children: [
|
|
6393
|
+
showHelp2 ? /* @__PURE__ */ jsx5(HelpOverlay, { width: cols, height: contentHeight }) : /* @__PURE__ */ jsxs5(Box5, { flexDirection: "row", height: contentHeight, children: [
|
|
6394
|
+
/* @__PURE__ */ jsxs5(Box5, { flexDirection: "column", width: sidebarWidth, children: [
|
|
6395
|
+
/* @__PURE__ */ jsx5(
|
|
5845
6396
|
Sidebar,
|
|
5846
6397
|
{
|
|
5847
6398
|
sidebarRows: topRows,
|
|
@@ -5854,10 +6405,11 @@ function App({ unsafe, onExit }) {
|
|
|
5854
6405
|
activeKey,
|
|
5855
6406
|
width: sidebarWidth,
|
|
5856
6407
|
height: sessionPaneHeight,
|
|
5857
|
-
branchInput
|
|
6408
|
+
branchInput,
|
|
6409
|
+
filter
|
|
5858
6410
|
}
|
|
5859
6411
|
),
|
|
5860
|
-
/* @__PURE__ */
|
|
6412
|
+
/* @__PURE__ */ jsx5(
|
|
5861
6413
|
PrPane,
|
|
5862
6414
|
{
|
|
5863
6415
|
prRows,
|
|
@@ -5868,7 +6420,7 @@ function App({ unsafe, onExit }) {
|
|
|
5868
6420
|
height: prPaneHeight
|
|
5869
6421
|
}
|
|
5870
6422
|
),
|
|
5871
|
-
jiraPaneHeight > 0 && /* @__PURE__ */
|
|
6423
|
+
jiraPaneHeight > 0 && /* @__PURE__ */ jsx5(
|
|
5872
6424
|
JiraPane,
|
|
5873
6425
|
{
|
|
5874
6426
|
jiraRows,
|
|
@@ -5878,7 +6430,7 @@ function App({ unsafe, onExit }) {
|
|
|
5878
6430
|
height: jiraPaneHeight
|
|
5879
6431
|
}
|
|
5880
6432
|
),
|
|
5881
|
-
/* @__PURE__ */
|
|
6433
|
+
/* @__PURE__ */ jsx5(
|
|
5882
6434
|
TaskPane,
|
|
5883
6435
|
{
|
|
5884
6436
|
taskRows,
|
|
@@ -5890,7 +6442,7 @@ function App({ unsafe, onExit }) {
|
|
|
5890
6442
|
}
|
|
5891
6443
|
)
|
|
5892
6444
|
] }),
|
|
5893
|
-
/* @__PURE__ */
|
|
6445
|
+
/* @__PURE__ */ jsx5(
|
|
5894
6446
|
TerminalPane,
|
|
5895
6447
|
{
|
|
5896
6448
|
lines: termLines,
|
|
@@ -5898,16 +6450,17 @@ function App({ unsafe, onExit }) {
|
|
|
5898
6450
|
height: contentHeight,
|
|
5899
6451
|
focused: focus === 4 /* TERMINAL */,
|
|
5900
6452
|
placeholder,
|
|
5901
|
-
title: "Terminal"
|
|
6453
|
+
title: "Terminal",
|
|
6454
|
+
scrollback: termScroll
|
|
5902
6455
|
}
|
|
5903
6456
|
)
|
|
5904
6457
|
] }),
|
|
5905
|
-
/* @__PURE__ */
|
|
6458
|
+
/* @__PURE__ */ jsx5(StatusBar, { message, pane: focus === 4 /* TERMINAL */ ? "terminal" : focus === 2 /* PRS */ ? "prs" : focus === 3 /* JIRA */ ? "jira" : focus === 1 /* TASKS */ ? "tasks" : "sessions", syncing })
|
|
5906
6459
|
] });
|
|
5907
6460
|
}
|
|
5908
6461
|
|
|
5909
6462
|
// src/tui-ink/index.tsx
|
|
5910
|
-
import { jsx as
|
|
6463
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
5911
6464
|
function crashLog(label2, err) {
|
|
5912
6465
|
try {
|
|
5913
6466
|
const msg = err instanceof Error ? err.stack || err.message : String(err);
|
|
@@ -5926,11 +6479,11 @@ async function startDashboard(unsafe) {
|
|
|
5926
6479
|
process.stdin.setRawMode(true);
|
|
5927
6480
|
process.stdin.resume();
|
|
5928
6481
|
const restore = () => {
|
|
5929
|
-
process.stdout.write("\x1B]0;\x07\x1B[?25h\x1B[?1049l");
|
|
6482
|
+
process.stdout.write("\x1B]0;\x07\x1B[?1000l\x1B[?1006l\x1B[?25h\x1B[?1049l");
|
|
5930
6483
|
};
|
|
5931
6484
|
try {
|
|
5932
6485
|
const { waitUntilExit, unmount } = render(
|
|
5933
|
-
/* @__PURE__ */
|
|
6486
|
+
/* @__PURE__ */ jsx6(App, { unsafe, onExit: () => {
|
|
5934
6487
|
unmount();
|
|
5935
6488
|
restore();
|
|
5936
6489
|
process.exit(0);
|
|
@@ -6335,9 +6888,9 @@ var hydrateCommand = {
|
|
|
6335
6888
|
};
|
|
6336
6889
|
|
|
6337
6890
|
// src/commands/diff.ts
|
|
6338
|
-
import
|
|
6891
|
+
import fs36 from "fs";
|
|
6339
6892
|
import os9 from "os";
|
|
6340
|
-
import
|
|
6893
|
+
import path33 from "path";
|
|
6341
6894
|
import { spawn as childSpawn } from "child_process";
|
|
6342
6895
|
import chalk21 from "chalk";
|
|
6343
6896
|
|
|
@@ -7039,11 +7592,12 @@ function resolveBase(scope, argv) {
|
|
|
7039
7592
|
}
|
|
7040
7593
|
return { base: "HEAD", source: "default" };
|
|
7041
7594
|
}
|
|
7042
|
-
function buildRepoSpecs(scope, base) {
|
|
7595
|
+
function buildRepoSpecs(scope, base, perRepoBase) {
|
|
7043
7596
|
return scope.repos.map((r) => {
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7597
|
+
const repoBase = perRepoBase?.[r.root] ?? base;
|
|
7598
|
+
let diffArg = repoBase;
|
|
7599
|
+
if (repoBase !== "HEAD") {
|
|
7600
|
+
const mb = git(["merge-base", repoBase, "HEAD"], r.root);
|
|
7047
7601
|
if (mb.exitCode === 0 && mb.stdout) diffArg = mb.stdout;
|
|
7048
7602
|
}
|
|
7049
7603
|
return { name: r.name, root: r.root, diffArg };
|
|
@@ -7060,6 +7614,17 @@ function resolveRepoDiff(root, base, sessionBaseBranch) {
|
|
|
7060
7614
|
if (mb.exitCode === 0 && mb.stdout) diffArg = mb.stdout;
|
|
7061
7615
|
return { resolvedBase: parent, diffArg };
|
|
7062
7616
|
}
|
|
7617
|
+
function sessionBaseForPath(root) {
|
|
7618
|
+
const norm = normPath(root);
|
|
7619
|
+
for (const s of loadHistory()) {
|
|
7620
|
+
for (const p of s.paths) {
|
|
7621
|
+
if (normPath(p) === norm) {
|
|
7622
|
+
return s.baseBranches?.[p] ?? s.baseBranch;
|
|
7623
|
+
}
|
|
7624
|
+
}
|
|
7625
|
+
}
|
|
7626
|
+
return void 0;
|
|
7627
|
+
}
|
|
7063
7628
|
|
|
7064
7629
|
// src/core/comment-server.ts
|
|
7065
7630
|
import { Hono as Hono2 } from "hono";
|
|
@@ -7147,9 +7712,56 @@ import { Hono } from "hono";
|
|
|
7147
7712
|
import { serve } from "@hono/node-server";
|
|
7148
7713
|
import { streamSSE } from "hono/streaming";
|
|
7149
7714
|
|
|
7150
|
-
// src/core/
|
|
7715
|
+
// src/core/file-context.ts
|
|
7151
7716
|
import fs31 from "fs";
|
|
7152
7717
|
import path28 from "path";
|
|
7718
|
+
import spawn10 from "cross-spawn";
|
|
7719
|
+
function readContextLines(opts) {
|
|
7720
|
+
const { root, relPath, ref } = opts;
|
|
7721
|
+
if (!relPath || !isInsideRoot(root, relPath)) return null;
|
|
7722
|
+
const start = Math.max(1, Math.floor(opts.start));
|
|
7723
|
+
const end = Math.max(start, Math.floor(opts.end));
|
|
7724
|
+
const content = !ref || ref === "working" ? readWorkingTree(root, relPath) : readAtRef(root, ref, relPath);
|
|
7725
|
+
if (content === null) return null;
|
|
7726
|
+
const all = content.split(/\r?\n/);
|
|
7727
|
+
if (all.length > 0 && all[all.length - 1] === "") all.pop();
|
|
7728
|
+
const totalLines = all.length;
|
|
7729
|
+
const slice = all.slice(start - 1, end);
|
|
7730
|
+
return {
|
|
7731
|
+
lines: slice,
|
|
7732
|
+
start,
|
|
7733
|
+
totalLines,
|
|
7734
|
+
eof: end >= totalLines
|
|
7735
|
+
};
|
|
7736
|
+
}
|
|
7737
|
+
function readWorkingTree(root, relPath) {
|
|
7738
|
+
try {
|
|
7739
|
+
const absPath = path28.join(root, relPath);
|
|
7740
|
+
const realRoot2 = fs31.realpathSync(path28.resolve(root));
|
|
7741
|
+
const realPath = fs31.realpathSync(absPath);
|
|
7742
|
+
const sep = path28.sep;
|
|
7743
|
+
if (realPath !== realRoot2 && !realPath.startsWith(realRoot2 + sep)) {
|
|
7744
|
+
return null;
|
|
7745
|
+
}
|
|
7746
|
+
return fs31.readFileSync(absPath, "utf-8");
|
|
7747
|
+
} catch {
|
|
7748
|
+
return null;
|
|
7749
|
+
}
|
|
7750
|
+
}
|
|
7751
|
+
function readAtRef(root, ref, relPath) {
|
|
7752
|
+
const r = spawn10.sync("git", ["show", `${ref}:${relPath}`], {
|
|
7753
|
+
cwd: root,
|
|
7754
|
+
encoding: "utf-8",
|
|
7755
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
7756
|
+
windowsHide: true
|
|
7757
|
+
});
|
|
7758
|
+
if (r.status === 0 && typeof r.stdout === "string") return r.stdout;
|
|
7759
|
+
return null;
|
|
7760
|
+
}
|
|
7761
|
+
|
|
7762
|
+
// src/core/fs-watcher.ts
|
|
7763
|
+
import fs32 from "fs";
|
|
7764
|
+
import path29 from "path";
|
|
7153
7765
|
import chalk19 from "chalk";
|
|
7154
7766
|
import chokidar from "chokidar";
|
|
7155
7767
|
var IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
@@ -7175,7 +7787,7 @@ var IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
|
7175
7787
|
]);
|
|
7176
7788
|
function isIgnoredWatchPath(roots, filePath) {
|
|
7177
7789
|
for (const root of roots) {
|
|
7178
|
-
const rel =
|
|
7790
|
+
const rel = path29.relative(root, filePath).replace(/\\/g, "/");
|
|
7179
7791
|
if (rel === "" || rel.startsWith("../")) continue;
|
|
7180
7792
|
if (rel.split("/").some((seg) => IGNORED_DIRS.has(seg))) return true;
|
|
7181
7793
|
}
|
|
@@ -7199,8 +7811,8 @@ function createFsWatcher(opts) {
|
|
|
7199
7811
|
};
|
|
7200
7812
|
if (SUPPORTS_RECURSIVE_WATCH) {
|
|
7201
7813
|
const watchers = opts.roots.map((root) => {
|
|
7202
|
-
const w =
|
|
7203
|
-
if (filename && isIgnoredWatchPath([root],
|
|
7814
|
+
const w = fs32.watch(root, { recursive: true }, (_event, filename) => {
|
|
7815
|
+
if (filename && isIgnoredWatchPath([root], path29.join(root, filename.toString()))) {
|
|
7204
7816
|
return;
|
|
7205
7817
|
}
|
|
7206
7818
|
fire();
|
|
@@ -7238,30 +7850,30 @@ function createFsWatcher(opts) {
|
|
|
7238
7850
|
}
|
|
7239
7851
|
|
|
7240
7852
|
// src/core/web-static.ts
|
|
7241
|
-
import
|
|
7242
|
-
import
|
|
7853
|
+
import fs33 from "fs";
|
|
7854
|
+
import path30 from "path";
|
|
7243
7855
|
import { fileURLToPath } from "url";
|
|
7244
7856
|
function resolveWebRoot() {
|
|
7245
|
-
const entryDir =
|
|
7246
|
-
const moduleDir =
|
|
7857
|
+
const entryDir = path30.dirname(process.argv[1] ?? "");
|
|
7858
|
+
const moduleDir = path30.dirname(fileURLToPath(import.meta.url));
|
|
7247
7859
|
const candidates = [
|
|
7248
|
-
|
|
7860
|
+
path30.join(entryDir, "web"),
|
|
7249
7861
|
// bundled: this module is inlined into dist/<bin>.js, so dist/web is a
|
|
7250
7862
|
// sibling of the bundle. Works even when argv[1] is an npm bin symlink
|
|
7251
7863
|
// (which is not realpath'd, so the entryDir candidate above misses).
|
|
7252
|
-
|
|
7864
|
+
path30.join(moduleDir, "web"),
|
|
7253
7865
|
// dev/tsx fallback: walk up from src/core to repo root then into dist/web.
|
|
7254
|
-
|
|
7866
|
+
path30.resolve(moduleDir, "../../dist/web")
|
|
7255
7867
|
];
|
|
7256
7868
|
for (const c of candidates) {
|
|
7257
|
-
if (
|
|
7869
|
+
if (fs33.existsSync(path30.join(c, "index.html"))) return c;
|
|
7258
7870
|
}
|
|
7259
7871
|
return null;
|
|
7260
7872
|
}
|
|
7261
7873
|
|
|
7262
7874
|
// src/core/spa-handler.ts
|
|
7263
|
-
import
|
|
7264
|
-
import
|
|
7875
|
+
import fs34 from "fs";
|
|
7876
|
+
import path31 from "path";
|
|
7265
7877
|
var MIME = {
|
|
7266
7878
|
".html": "text/html; charset=utf-8",
|
|
7267
7879
|
".js": "application/javascript; charset=utf-8",
|
|
@@ -7275,18 +7887,18 @@ var MIME = {
|
|
|
7275
7887
|
function readFile(root, relPath) {
|
|
7276
7888
|
const clean = relPath.split("?")[0];
|
|
7277
7889
|
const requested = clean === "/" ? "/index.html" : clean;
|
|
7278
|
-
const filePath =
|
|
7279
|
-
const norm =
|
|
7280
|
-
if (!norm.startsWith(
|
|
7890
|
+
const filePath = path31.join(root, requested);
|
|
7891
|
+
const norm = path31.normalize(filePath);
|
|
7892
|
+
if (!norm.startsWith(path31.normalize(root))) return null;
|
|
7281
7893
|
let stat;
|
|
7282
7894
|
try {
|
|
7283
|
-
stat =
|
|
7895
|
+
stat = fs34.statSync(norm);
|
|
7284
7896
|
} catch {
|
|
7285
7897
|
return null;
|
|
7286
7898
|
}
|
|
7287
7899
|
if (!stat.isFile()) return null;
|
|
7288
|
-
const ext =
|
|
7289
|
-
return { body:
|
|
7900
|
+
const ext = path31.extname(norm).toLowerCase();
|
|
7901
|
+
return { body: fs34.readFileSync(norm), ext };
|
|
7290
7902
|
}
|
|
7291
7903
|
function serveSpa(c, webRoot) {
|
|
7292
7904
|
const url = new URL(c.req.url);
|
|
@@ -7342,7 +7954,11 @@ async function startDiffServer(opts) {
|
|
|
7342
7954
|
const base = c.req.query("base") === "branch" ? "branch" : "uncommitted";
|
|
7343
7955
|
try {
|
|
7344
7956
|
const resolved = opts.repos.map(
|
|
7345
|
-
(r) => base === "uncommitted" ? { resolvedBase: "HEAD", diffArg: r.diffArg } : resolveRepoDiff(
|
|
7957
|
+
(r) => base === "uncommitted" ? { resolvedBase: "HEAD", diffArg: r.diffArg } : resolveRepoDiff(
|
|
7958
|
+
r.root,
|
|
7959
|
+
"branch",
|
|
7960
|
+
opts.sessionBaseBranches?.[r.root] ?? opts.sessionBaseBranch
|
|
7961
|
+
)
|
|
7346
7962
|
);
|
|
7347
7963
|
const repos = opts.repos.map((r, i) => ({
|
|
7348
7964
|
name: r.name,
|
|
@@ -7356,6 +7972,21 @@ async function startDiffServer(opts) {
|
|
|
7356
7972
|
return c.json({ error: err.message }, 500);
|
|
7357
7973
|
}
|
|
7358
7974
|
});
|
|
7975
|
+
app.get("/api/file-lines", (c) => {
|
|
7976
|
+
const repoName = c.req.query("repo") ?? "";
|
|
7977
|
+
const relPath = c.req.query("path") ?? "";
|
|
7978
|
+
const start = Number(c.req.query("start"));
|
|
7979
|
+
const end = Number(c.req.query("end"));
|
|
7980
|
+
const ref = c.req.query("ref") || void 0;
|
|
7981
|
+
if (!relPath || !Number.isInteger(start) || !Number.isInteger(end)) {
|
|
7982
|
+
return c.json({ error: "bad path/start/end" }, 400);
|
|
7983
|
+
}
|
|
7984
|
+
const root = opts.repos.length === 1 ? opts.repos[0].root : opts.repos.find((r) => r.name === repoName)?.root;
|
|
7985
|
+
if (!root) return c.json({ error: "unknown repo" }, 404);
|
|
7986
|
+
const result = readContextLines({ root, relPath, start, end, ref });
|
|
7987
|
+
if (!result) return c.json({ error: "cannot read file" }, 400);
|
|
7988
|
+
return c.json(result);
|
|
7989
|
+
});
|
|
7359
7990
|
app.get(
|
|
7360
7991
|
"/events",
|
|
7361
7992
|
(c) => streamSSE(c, async (stream) => {
|
|
@@ -7518,6 +8149,7 @@ async function startCommentServer(opts) {
|
|
|
7518
8149
|
repos: opts.repos,
|
|
7519
8150
|
scopeLabel: opts.scopeLabel,
|
|
7520
8151
|
sessionBaseBranch: opts.sessionBaseBranch,
|
|
8152
|
+
sessionBaseBranches: opts.sessionBaseBranches,
|
|
7521
8153
|
watchDebounceMs: opts.watchDebounceMs,
|
|
7522
8154
|
attachRoutes
|
|
7523
8155
|
});
|
|
@@ -7559,8 +8191,8 @@ function diffReviewSnapshot(snapshot, seen) {
|
|
|
7559
8191
|
}
|
|
7560
8192
|
|
|
7561
8193
|
// src/core/static-renderer.ts
|
|
7562
|
-
import
|
|
7563
|
-
import
|
|
8194
|
+
import fs35 from "fs";
|
|
8195
|
+
import path32 from "path";
|
|
7564
8196
|
function buildDiff(specs, resolvedBase) {
|
|
7565
8197
|
return {
|
|
7566
8198
|
repos: specs.map((r) => ({
|
|
@@ -7576,8 +8208,8 @@ function renderStatic(opts) {
|
|
|
7576
8208
|
if (!webRoot) {
|
|
7577
8209
|
throw new Error("Could not find dist/web/. Run `npm run build` first.");
|
|
7578
8210
|
}
|
|
7579
|
-
const shellPath =
|
|
7580
|
-
let shell =
|
|
8211
|
+
const shellPath = path32.join(webRoot, "index.html");
|
|
8212
|
+
let shell = fs35.readFileSync(shellPath, "utf-8");
|
|
7581
8213
|
const uncommitted = buildDiff(opts.uncommitted, "HEAD");
|
|
7582
8214
|
const branch = opts.branch ? buildDiff(opts.branch.specs, opts.branch.resolvedBase) : void 0;
|
|
7583
8215
|
const initialBase = opts.initialBase ?? "uncommitted";
|
|
@@ -7626,10 +8258,10 @@ function escapeForScriptTag(json) {
|
|
|
7626
8258
|
}
|
|
7627
8259
|
function readAsset(webRoot, urlPath) {
|
|
7628
8260
|
const clean = urlPath.split("?")[0].replace(/^\//, "");
|
|
7629
|
-
const full =
|
|
7630
|
-
if (!
|
|
8261
|
+
const full = path32.join(webRoot, clean);
|
|
8262
|
+
if (!path32.normalize(full).startsWith(path32.normalize(webRoot))) return null;
|
|
7631
8263
|
try {
|
|
7632
|
-
return
|
|
8264
|
+
return fs35.readFileSync(full, "utf-8");
|
|
7633
8265
|
} catch {
|
|
7634
8266
|
return null;
|
|
7635
8267
|
}
|
|
@@ -7670,22 +8302,22 @@ async function runStop(repoSpecs) {
|
|
|
7670
8302
|
}
|
|
7671
8303
|
}
|
|
7672
8304
|
function webUrlFilePath() {
|
|
7673
|
-
return
|
|
8305
|
+
return path33.join(os9.homedir(), ".work", "web.url");
|
|
7674
8306
|
}
|
|
7675
8307
|
function resolveWorkBinPath(selfArgv1) {
|
|
7676
8308
|
let real = selfArgv1;
|
|
7677
8309
|
try {
|
|
7678
|
-
real =
|
|
8310
|
+
real = fs36.realpathSync(selfArgv1);
|
|
7679
8311
|
} catch {
|
|
7680
8312
|
}
|
|
7681
8313
|
if (real.endsWith("wd-bin.js")) {
|
|
7682
|
-
return
|
|
8314
|
+
return path33.join(path33.dirname(real), "bin.js");
|
|
7683
8315
|
}
|
|
7684
8316
|
return real;
|
|
7685
8317
|
}
|
|
7686
8318
|
function readWebUrl() {
|
|
7687
8319
|
try {
|
|
7688
|
-
const v =
|
|
8320
|
+
const v = fs36.readFileSync(webUrlFilePath(), "utf-8").trim();
|
|
7689
8321
|
return v || null;
|
|
7690
8322
|
} catch {
|
|
7691
8323
|
return null;
|
|
@@ -7695,8 +8327,8 @@ async function ensureWorkWebRunning() {
|
|
|
7695
8327
|
const existing = readWebUrl();
|
|
7696
8328
|
if (existing) return existing;
|
|
7697
8329
|
const workBin = resolveWorkBinPath(process.argv[1]);
|
|
7698
|
-
const out =
|
|
7699
|
-
|
|
8330
|
+
const out = fs36.openSync(
|
|
8331
|
+
path33.join(os9.homedir(), ".work", "web-autostart.log"),
|
|
7700
8332
|
"a"
|
|
7701
8333
|
);
|
|
7702
8334
|
const child = childSpawn(
|
|
@@ -7711,7 +8343,7 @@ async function ensureWorkWebRunning() {
|
|
|
7711
8343
|
}
|
|
7712
8344
|
);
|
|
7713
8345
|
child.unref();
|
|
7714
|
-
|
|
8346
|
+
fs36.closeSync(out);
|
|
7715
8347
|
const url = await waitForUrlFile(webUrlFilePath(), 5e3);
|
|
7716
8348
|
return url;
|
|
7717
8349
|
}
|
|
@@ -7755,9 +8387,10 @@ async function runLauncher(ctx) {
|
|
|
7755
8387
|
function runStatic(ctx, initialBranch) {
|
|
7756
8388
|
const uncommitted = buildRepoSpecs(ctx.scope, "HEAD");
|
|
7757
8389
|
const primaryRoot = ctx.scope.repos.find((r) => r.name === ctx.scope.activeRepoName)?.root ?? ctx.scope.repos[0].root;
|
|
7758
|
-
const
|
|
8390
|
+
const perRepoBase = ctx.scope.session?.baseBranches;
|
|
8391
|
+
const parent = perRepoBase?.[primaryRoot] ?? ctx.scope.session?.baseBranch ?? findAnyParentBranch(primaryRoot);
|
|
7759
8392
|
const branch = parent === null ? void 0 : {
|
|
7760
|
-
specs: buildRepoSpecs(ctx.scope, parent),
|
|
8393
|
+
specs: buildRepoSpecs(ctx.scope, parent, perRepoBase),
|
|
7761
8394
|
resolvedBase: parent
|
|
7762
8395
|
};
|
|
7763
8396
|
const uncommittedTotal = uncommitted.reduce(
|
|
@@ -7779,7 +8412,7 @@ function runStatic(ctx, initialBranch) {
|
|
|
7779
8412
|
initialBase: initialBranch && branch ? "branch" : "uncommitted"
|
|
7780
8413
|
});
|
|
7781
8414
|
const filePath = `${ctx.scopeStem}.html`;
|
|
7782
|
-
|
|
8415
|
+
fs36.writeFileSync(filePath, html, "utf-8");
|
|
7783
8416
|
info(chalk21.gray(`Wrote ${filePath}`));
|
|
7784
8417
|
openUrl(`file:///${filePath.replace(/\\/g, "/")}`);
|
|
7785
8418
|
}
|
|
@@ -7788,7 +8421,7 @@ function waitForUrlFile(filePath, timeoutMs) {
|
|
|
7788
8421
|
const start = Date.now();
|
|
7789
8422
|
const tick = () => {
|
|
7790
8423
|
try {
|
|
7791
|
-
const v =
|
|
8424
|
+
const v = fs36.readFileSync(filePath, "utf-8").trim();
|
|
7792
8425
|
if (v) return resolve(v);
|
|
7793
8426
|
} catch {
|
|
7794
8427
|
}
|
|
@@ -7928,6 +8561,7 @@ summary-id: ${info3.summary.id}` : ""}
|
|
|
7928
8561
|
repos: ctx.repoSpecs,
|
|
7929
8562
|
scopeLabel: ctx.scopeLabel,
|
|
7930
8563
|
sessionBaseBranch: ctx.scope.session?.baseBranch,
|
|
8564
|
+
sessionBaseBranches: ctx.scope.session?.baseBranches,
|
|
7931
8565
|
onComment,
|
|
7932
8566
|
onCommentDeleted,
|
|
7933
8567
|
onSubmitReviewStart,
|
|
@@ -8034,21 +8668,21 @@ var diffCommand = {
|
|
|
8034
8668
|
};
|
|
8035
8669
|
|
|
8036
8670
|
// src/commands/web.ts
|
|
8037
|
-
import
|
|
8671
|
+
import fs41 from "fs";
|
|
8038
8672
|
import os13 from "os";
|
|
8039
|
-
import
|
|
8673
|
+
import path42 from "path";
|
|
8040
8674
|
import chalk23 from "chalk";
|
|
8041
8675
|
|
|
8042
8676
|
// src/core/web-server.ts
|
|
8043
|
-
import
|
|
8677
|
+
import fs40 from "fs";
|
|
8044
8678
|
import os12 from "os";
|
|
8045
|
-
import
|
|
8679
|
+
import path41 from "path";
|
|
8046
8680
|
import chalk22 from "chalk";
|
|
8047
8681
|
import { Hono as Hono3 } from "hono";
|
|
8048
8682
|
import { streamSSE as streamSSE3 } from "hono/streaming";
|
|
8049
8683
|
|
|
8050
8684
|
// src/core/web-state.ts
|
|
8051
|
-
import
|
|
8685
|
+
import path34 from "path";
|
|
8052
8686
|
import crypto4 from "crypto";
|
|
8053
8687
|
import chokidar2 from "chokidar";
|
|
8054
8688
|
function sessionIdFor(s) {
|
|
@@ -8069,7 +8703,7 @@ function subscribeSession(sessionId, onChange) {
|
|
|
8069
8703
|
const watcher = chokidar2.watch(roots, {
|
|
8070
8704
|
ignored: (filePath) => {
|
|
8071
8705
|
for (const r of roots) {
|
|
8072
|
-
const rel =
|
|
8706
|
+
const rel = path34.relative(r, filePath).replace(/\\/g, "/");
|
|
8073
8707
|
if (rel === ".git" || rel.startsWith(".git/")) return true;
|
|
8074
8708
|
}
|
|
8075
8709
|
return false;
|
|
@@ -8183,24 +8817,24 @@ function disposeAllPtys() {
|
|
|
8183
8817
|
}
|
|
8184
8818
|
|
|
8185
8819
|
// src/core/comment-file-store.ts
|
|
8186
|
-
import
|
|
8187
|
-
import
|
|
8820
|
+
import fs37 from "fs";
|
|
8821
|
+
import path35 from "path";
|
|
8188
8822
|
import os10 from "os";
|
|
8189
8823
|
function commentsDir() {
|
|
8190
|
-
return
|
|
8824
|
+
return path35.join(os10.homedir(), ".work", "comments");
|
|
8191
8825
|
}
|
|
8192
8826
|
function ensureDir() {
|
|
8193
|
-
|
|
8827
|
+
fs37.mkdirSync(commentsDir(), { recursive: true });
|
|
8194
8828
|
}
|
|
8195
8829
|
function commentsFileFor(sessionId) {
|
|
8196
|
-
return
|
|
8830
|
+
return path35.join(commentsDir(), `${sessionId}.json`);
|
|
8197
8831
|
}
|
|
8198
8832
|
function pathFor(sessionId) {
|
|
8199
8833
|
return commentsFileFor(sessionId);
|
|
8200
8834
|
}
|
|
8201
8835
|
function readDisk(sessionId) {
|
|
8202
8836
|
try {
|
|
8203
|
-
const raw =
|
|
8837
|
+
const raw = fs37.readFileSync(pathFor(sessionId), "utf-8");
|
|
8204
8838
|
const parsed = JSON.parse(raw);
|
|
8205
8839
|
return Array.isArray(parsed) ? parsed : [];
|
|
8206
8840
|
} catch {
|
|
@@ -8272,29 +8906,29 @@ function clearCommentStoreCache() {
|
|
|
8272
8906
|
}
|
|
8273
8907
|
|
|
8274
8908
|
// src/core/pending-delivery.ts
|
|
8275
|
-
import
|
|
8276
|
-
import
|
|
8909
|
+
import fs38 from "fs";
|
|
8910
|
+
import path36 from "path";
|
|
8277
8911
|
function pathFor2(sessionId) {
|
|
8278
8912
|
return {
|
|
8279
8913
|
comments: commentsFileFor(sessionId),
|
|
8280
|
-
delivered:
|
|
8914
|
+
delivered: path36.join(commentsDir(), `${sessionId}.delivered.json`)
|
|
8281
8915
|
};
|
|
8282
8916
|
}
|
|
8283
8917
|
function readJson(filePath, fallback) {
|
|
8284
8918
|
try {
|
|
8285
|
-
return JSON.parse(
|
|
8919
|
+
return JSON.parse(fs38.readFileSync(filePath, "utf8"));
|
|
8286
8920
|
} catch {
|
|
8287
8921
|
return fallback;
|
|
8288
8922
|
}
|
|
8289
8923
|
}
|
|
8290
8924
|
function writeAtomic2(filePath, content) {
|
|
8291
|
-
|
|
8925
|
+
fs38.mkdirSync(path36.dirname(filePath), { recursive: true });
|
|
8292
8926
|
const tmp = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
8293
|
-
|
|
8294
|
-
|
|
8927
|
+
fs38.writeFileSync(tmp, content, "utf-8");
|
|
8928
|
+
fs38.renameSync(tmp, filePath);
|
|
8295
8929
|
}
|
|
8296
8930
|
function normalize(p) {
|
|
8297
|
-
return
|
|
8931
|
+
return path36.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
8298
8932
|
}
|
|
8299
8933
|
function findSessionForCwd(cwd) {
|
|
8300
8934
|
const norm = normalize(cwd);
|
|
@@ -8325,7 +8959,7 @@ function readPendingForSession(sessionId) {
|
|
|
8325
8959
|
return comments.filter(isPendingFor(delivered));
|
|
8326
8960
|
}
|
|
8327
8961
|
function scopeStoreIdsForPaths(paths) {
|
|
8328
|
-
const resolved = paths.map((p) =>
|
|
8962
|
+
const resolved = paths.map((p) => path36.resolve(p));
|
|
8329
8963
|
const ids = /* @__PURE__ */ new Set();
|
|
8330
8964
|
ids.add(`scope-${scopeHashFor(resolved)}`);
|
|
8331
8965
|
for (const p of resolved) ids.add(`scope-${scopeHashFor([p])}`);
|
|
@@ -8648,8 +9282,8 @@ function mountPanesRoutes(app, opts) {
|
|
|
8648
9282
|
}
|
|
8649
9283
|
|
|
8650
9284
|
// src/core/worktree-routes.ts
|
|
8651
|
-
import
|
|
8652
|
-
import { spawn as
|
|
9285
|
+
import path37 from "path";
|
|
9286
|
+
import { spawn as spawn11 } from "child_process";
|
|
8653
9287
|
import { zValidator as zValidator4 } from "@hono/zod-validator";
|
|
8654
9288
|
import { z as z3 } from "zod";
|
|
8655
9289
|
function mountWorktreeRoutes(app, opts) {
|
|
@@ -8772,10 +9406,10 @@ function mountWorktreeRoutes(app, opts) {
|
|
|
8772
9406
|
const id = c.req.param("id");
|
|
8773
9407
|
const session = findSession2(id);
|
|
8774
9408
|
if (!session) return c.json({ error: "unknown session" }, 404);
|
|
8775
|
-
const target = session.isGroup ?
|
|
9409
|
+
const target = session.isGroup ? path37.dirname(session.paths[0]) : session.paths[0];
|
|
8776
9410
|
try {
|
|
8777
9411
|
const cmd = process.platform === "win32" ? "code.cmd" : "code";
|
|
8778
|
-
const child =
|
|
9412
|
+
const child = spawn11(cmd, [target], {
|
|
8779
9413
|
detached: true,
|
|
8780
9414
|
stdio: "ignore",
|
|
8781
9415
|
shell: false
|
|
@@ -8792,27 +9426,27 @@ function mountWorktreeRoutes(app, opts) {
|
|
|
8792
9426
|
import { zValidator as zValidator5 } from "@hono/zod-validator";
|
|
8793
9427
|
import { z as z4 } from "zod";
|
|
8794
9428
|
import { EventEmitter } from "events";
|
|
8795
|
-
import
|
|
8796
|
-
import
|
|
9429
|
+
import path40 from "path";
|
|
9430
|
+
import spawn13 from "cross-spawn";
|
|
8797
9431
|
|
|
8798
9432
|
// src/core/checkpoint.ts
|
|
8799
|
-
import
|
|
9433
|
+
import fs39 from "fs";
|
|
8800
9434
|
import os11 from "os";
|
|
8801
|
-
import
|
|
8802
|
-
import
|
|
9435
|
+
import path38 from "path";
|
|
9436
|
+
import spawn12 from "cross-spawn";
|
|
8803
9437
|
function manifestPath(scopeHash) {
|
|
8804
|
-
const dir =
|
|
8805
|
-
|
|
8806
|
-
return
|
|
9438
|
+
const dir = path38.join(os11.homedir(), ".work", "diffs");
|
|
9439
|
+
fs39.mkdirSync(dir, { recursive: true });
|
|
9440
|
+
return path38.join(dir, `${scopeHash}.checkpoints.json`);
|
|
8807
9441
|
}
|
|
8808
9442
|
function emptyManifest(scopeHash) {
|
|
8809
9443
|
return { version: 1, scopeHash, entries: [] };
|
|
8810
9444
|
}
|
|
8811
9445
|
function loadManifest(scopeHash) {
|
|
8812
9446
|
const file = manifestPath(scopeHash);
|
|
8813
|
-
if (!
|
|
9447
|
+
if (!fs39.existsSync(file)) return emptyManifest(scopeHash);
|
|
8814
9448
|
try {
|
|
8815
|
-
const raw =
|
|
9449
|
+
const raw = fs39.readFileSync(file, "utf-8");
|
|
8816
9450
|
const parsed = JSON.parse(raw);
|
|
8817
9451
|
if (parsed.version !== 1 || !Array.isArray(parsed.entries)) {
|
|
8818
9452
|
return emptyManifest(scopeHash);
|
|
@@ -8841,7 +9475,7 @@ function snapshotRepo(repoRoot, scopeHash, id, includeWorkingTree = true) {
|
|
|
8841
9475
|
GIT_COMMITTER_EMAIL: "wd@local",
|
|
8842
9476
|
GIT_COMMITTER_DATE: "2000-01-01T00:00:00Z"
|
|
8843
9477
|
};
|
|
8844
|
-
const commit =
|
|
9478
|
+
const commit = spawn12.sync("git", commitArgs, {
|
|
8845
9479
|
cwd: repoRoot,
|
|
8846
9480
|
encoding: "utf-8",
|
|
8847
9481
|
env: commitEnv,
|
|
@@ -8850,7 +9484,7 @@ function snapshotRepo(repoRoot, scopeHash, id, includeWorkingTree = true) {
|
|
|
8850
9484
|
if (commit.status !== 0 || !commit.stdout) return null;
|
|
8851
9485
|
const commitSha = commit.stdout.trim();
|
|
8852
9486
|
const refName = `refs/wd/${scopeHash}/${id}`;
|
|
8853
|
-
const updateRef =
|
|
9487
|
+
const updateRef = spawn12.sync("git", ["update-ref", refName, commitSha], {
|
|
8854
9488
|
cwd: repoRoot,
|
|
8855
9489
|
encoding: "utf-8",
|
|
8856
9490
|
windowsHide: true
|
|
@@ -8877,7 +9511,7 @@ async function takeCheckpoint(scopeHash, repos, opts = {}) {
|
|
|
8877
9511
|
const rollbackRefs = () => {
|
|
8878
9512
|
const refName = `refs/wd/${scopeHash}/${nextId}`;
|
|
8879
9513
|
for (const repo of repos) {
|
|
8880
|
-
|
|
9514
|
+
spawn12.sync("git", ["update-ref", "-d", refName], {
|
|
8881
9515
|
cwd: repo.root,
|
|
8882
9516
|
encoding: "utf-8",
|
|
8883
9517
|
windowsHide: true
|
|
@@ -8892,7 +9526,7 @@ async function takeCheckpoint(scopeHash, repos, opts = {}) {
|
|
|
8892
9526
|
const prev = manifest.entries[manifest.entries.length - 1];
|
|
8893
9527
|
const treeOf = (root, commitSha) => {
|
|
8894
9528
|
if (!commitSha) return null;
|
|
8895
|
-
const r =
|
|
9529
|
+
const r = spawn12.sync(
|
|
8896
9530
|
"git",
|
|
8897
9531
|
["rev-parse", `${commitSha}^{tree}`],
|
|
8898
9532
|
{ cwd: root, encoding: "utf-8", windowsHide: true }
|
|
@@ -8927,7 +9561,7 @@ function clearCheckpoints(scopeHash, repoRoots) {
|
|
|
8927
9561
|
for (const root of repoRoots) {
|
|
8928
9562
|
for (const entry of manifest.entries) {
|
|
8929
9563
|
const refName = `refs/wd/${scopeHash}/${entry.id}`;
|
|
8930
|
-
|
|
9564
|
+
spawn12.sync("git", ["update-ref", "-d", refName], {
|
|
8931
9565
|
cwd: root,
|
|
8932
9566
|
encoding: "utf-8",
|
|
8933
9567
|
windowsHide: true
|
|
@@ -8935,16 +9569,16 @@ function clearCheckpoints(scopeHash, repoRoots) {
|
|
|
8935
9569
|
}
|
|
8936
9570
|
}
|
|
8937
9571
|
const file = manifestPath(scopeHash);
|
|
8938
|
-
if (
|
|
9572
|
+
if (fs39.existsSync(file)) {
|
|
8939
9573
|
try {
|
|
8940
|
-
|
|
9574
|
+
fs39.unlinkSync(file);
|
|
8941
9575
|
} catch {
|
|
8942
9576
|
}
|
|
8943
9577
|
}
|
|
8944
9578
|
}
|
|
8945
9579
|
|
|
8946
9580
|
// src/core/scope-manager.ts
|
|
8947
|
-
import
|
|
9581
|
+
import path39 from "path";
|
|
8948
9582
|
import crypto5 from "crypto";
|
|
8949
9583
|
var scopes = /* @__PURE__ */ new Map();
|
|
8950
9584
|
function hashFor(paths) {
|
|
@@ -8961,7 +9595,7 @@ var ScopePathRejectedError = class extends Error {
|
|
|
8961
9595
|
}
|
|
8962
9596
|
};
|
|
8963
9597
|
function normaliseForCompare(p) {
|
|
8964
|
-
return
|
|
9598
|
+
return path39.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
8965
9599
|
}
|
|
8966
9600
|
function rejectedPaths(normalised) {
|
|
8967
9601
|
const config = loadConfig();
|
|
@@ -8979,7 +9613,7 @@ function rejectedPaths(normalised) {
|
|
|
8979
9613
|
});
|
|
8980
9614
|
}
|
|
8981
9615
|
function registerScope(paths, label2) {
|
|
8982
|
-
const normalised = paths.map((p) =>
|
|
9616
|
+
const normalised = paths.map((p) => path39.resolve(p));
|
|
8983
9617
|
const rejected = rejectedPaths(normalised);
|
|
8984
9618
|
if (rejected.length > 0) throw new ScopePathRejectedError(rejected);
|
|
8985
9619
|
const hash = hashFor(normalised);
|
|
@@ -8993,7 +9627,7 @@ function registerScope(paths, label2) {
|
|
|
8993
9627
|
const scope = {
|
|
8994
9628
|
hash,
|
|
8995
9629
|
paths: normalised,
|
|
8996
|
-
label: label2 ??
|
|
9630
|
+
label: label2 ?? path39.basename(normalised[0]),
|
|
8997
9631
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8998
9632
|
ended: false
|
|
8999
9633
|
};
|
|
@@ -9066,7 +9700,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
9066
9700
|
function workingTreeFingerprint(paths) {
|
|
9067
9701
|
const parts = [];
|
|
9068
9702
|
for (const p of paths) {
|
|
9069
|
-
const r =
|
|
9703
|
+
const r = spawn13.sync(
|
|
9070
9704
|
"git",
|
|
9071
9705
|
["status", "--porcelain", "--no-renames", "-z"],
|
|
9072
9706
|
{ cwd: p, encoding: "utf-8", windowsHide: true }
|
|
@@ -9190,7 +9824,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
9190
9824
|
const fromSha = fromEntry.repos[p] ?? "HEAD";
|
|
9191
9825
|
const toSha = toEntry === void 0 ? "working" : toEntry.repos[p] ?? "HEAD";
|
|
9192
9826
|
return {
|
|
9193
|
-
name:
|
|
9827
|
+
name: path40.basename(p),
|
|
9194
9828
|
root: p,
|
|
9195
9829
|
files: computeRangeDiff({ root: p, fromRef: fromSha, toRef: toSha })
|
|
9196
9830
|
};
|
|
@@ -9204,9 +9838,11 @@ function mountScopeRoutes(app, opts) {
|
|
|
9204
9838
|
repos: repos2
|
|
9205
9839
|
});
|
|
9206
9840
|
}
|
|
9207
|
-
const resolved = scope.paths.map(
|
|
9841
|
+
const resolved = scope.paths.map(
|
|
9842
|
+
(p) => resolveRepoDiff(p, base, sessionBaseForPath(p))
|
|
9843
|
+
);
|
|
9208
9844
|
const repos = scope.paths.map((p, i) => ({
|
|
9209
|
-
name:
|
|
9845
|
+
name: path40.basename(p),
|
|
9210
9846
|
root: p,
|
|
9211
9847
|
resolvedBase: resolved[i].resolvedBase,
|
|
9212
9848
|
files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
|
|
@@ -9225,6 +9861,23 @@ function mountScopeRoutes(app, opts) {
|
|
|
9225
9861
|
return c.json({ error: err.message }, 500);
|
|
9226
9862
|
}
|
|
9227
9863
|
});
|
|
9864
|
+
app.get("/api/scopes/:hash/file-lines", (c) => {
|
|
9865
|
+
const scope = getScope(c.req.param("hash"));
|
|
9866
|
+
if (!scope) return c.json({ error: "unknown scope" }, 404);
|
|
9867
|
+
const repoName = c.req.query("repo") ?? "";
|
|
9868
|
+
const relPath = c.req.query("path") ?? "";
|
|
9869
|
+
const start = Number(c.req.query("start"));
|
|
9870
|
+
const end = Number(c.req.query("end"));
|
|
9871
|
+
const ref = c.req.query("ref") || void 0;
|
|
9872
|
+
if (!relPath || !Number.isInteger(start) || !Number.isInteger(end)) {
|
|
9873
|
+
return c.json({ error: "bad path/start/end" }, 400);
|
|
9874
|
+
}
|
|
9875
|
+
const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path40.basename(p) === repoName);
|
|
9876
|
+
if (!root) return c.json({ error: "unknown repo" }, 404);
|
|
9877
|
+
const result = readContextLines({ root, relPath, start, end, ref });
|
|
9878
|
+
if (!result) return c.json({ error: "cannot read file" }, 400);
|
|
9879
|
+
return c.json(result);
|
|
9880
|
+
});
|
|
9228
9881
|
app.get("/api/scopes/:hash/checkpoints", (c) => {
|
|
9229
9882
|
const scope = getScope(c.req.param("hash"));
|
|
9230
9883
|
if (!scope) return c.json({ error: "unknown scope" }, 404);
|
|
@@ -9453,9 +10106,11 @@ function sessionToWire(s) {
|
|
|
9453
10106
|
};
|
|
9454
10107
|
}
|
|
9455
10108
|
function computeSessionDiff(s, base) {
|
|
9456
|
-
const resolved = s.paths.map(
|
|
10109
|
+
const resolved = s.paths.map(
|
|
10110
|
+
(p) => resolveRepoDiff(p, base, s.baseBranches?.[p] ?? s.baseBranch)
|
|
10111
|
+
);
|
|
9457
10112
|
const repos = s.paths.map((p, i) => ({
|
|
9458
|
-
name:
|
|
10113
|
+
name: path41.basename(p),
|
|
9459
10114
|
root: p,
|
|
9460
10115
|
resolvedBase: resolved[i].resolvedBase,
|
|
9461
10116
|
files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
|
|
@@ -9475,17 +10130,17 @@ async function startWebServer(opts = {}) {
|
|
|
9475
10130
|
for (const cb of sseListeners) cb({ event, data });
|
|
9476
10131
|
};
|
|
9477
10132
|
const home = os12.homedir();
|
|
9478
|
-
const historyPath =
|
|
10133
|
+
const historyPath = path41.join(home, ".work", "history.json");
|
|
9479
10134
|
const onHistoryChange = () => broadcast("sessions-changed", { ts: Date.now() });
|
|
9480
|
-
|
|
9481
|
-
const tasksPath =
|
|
10135
|
+
fs40.watchFile(historyPath, { interval: 1e3 }, onHistoryChange);
|
|
10136
|
+
const tasksPath = path41.join(home, ".work", "tasks.json");
|
|
9482
10137
|
const onTasksChange = () => broadcast("tasks-changed", { ts: Date.now() });
|
|
9483
|
-
|
|
10138
|
+
fs40.watchFile(tasksPath, { interval: 1e3 }, onTasksChange);
|
|
9484
10139
|
const projectsRoot = claudeProjectsRoot();
|
|
9485
10140
|
let activityWatcher = null;
|
|
9486
10141
|
if (!lean) {
|
|
9487
10142
|
try {
|
|
9488
|
-
if (
|
|
10143
|
+
if (fs40.existsSync(projectsRoot)) {
|
|
9489
10144
|
activityWatcher = createFsWatcher({
|
|
9490
10145
|
roots: [projectsRoot],
|
|
9491
10146
|
debounceMs: 250,
|
|
@@ -9560,8 +10215,8 @@ async function startWebServer(opts = {}) {
|
|
|
9560
10215
|
url: handle.url,
|
|
9561
10216
|
port: handle.port,
|
|
9562
10217
|
stop: async () => {
|
|
9563
|
-
|
|
9564
|
-
|
|
10218
|
+
fs40.unwatchFile(historyPath, onHistoryChange);
|
|
10219
|
+
fs40.unwatchFile(tasksPath, onTasksChange);
|
|
9565
10220
|
if (decayTick) clearInterval(decayTick);
|
|
9566
10221
|
activityWatcher?.stop();
|
|
9567
10222
|
disposeAllWatchers();
|
|
@@ -9623,10 +10278,10 @@ function info2(message) {
|
|
|
9623
10278
|
process.stderr.write(message + "\n");
|
|
9624
10279
|
}
|
|
9625
10280
|
function urlFilePath() {
|
|
9626
|
-
return
|
|
10281
|
+
return path42.join(os13.homedir(), ".work", "web.url");
|
|
9627
10282
|
}
|
|
9628
10283
|
function pidFilePath() {
|
|
9629
|
-
return
|
|
10284
|
+
return path42.join(os13.homedir(), ".work", "web.pid");
|
|
9630
10285
|
}
|
|
9631
10286
|
function isPidAlive(pid) {
|
|
9632
10287
|
try {
|
|
@@ -9638,7 +10293,7 @@ function isPidAlive(pid) {
|
|
|
9638
10293
|
}
|
|
9639
10294
|
function readPid() {
|
|
9640
10295
|
try {
|
|
9641
|
-
const raw =
|
|
10296
|
+
const raw = fs41.readFileSync(pidFilePath(), "utf-8").trim();
|
|
9642
10297
|
const n = Number(raw);
|
|
9643
10298
|
return Number.isFinite(n) && n > 0 ? n : null;
|
|
9644
10299
|
} catch {
|
|
@@ -9647,7 +10302,7 @@ function readPid() {
|
|
|
9647
10302
|
}
|
|
9648
10303
|
function readUrl() {
|
|
9649
10304
|
try {
|
|
9650
|
-
const v =
|
|
10305
|
+
const v = fs41.readFileSync(urlFilePath(), "utf-8").trim();
|
|
9651
10306
|
return v || null;
|
|
9652
10307
|
} catch {
|
|
9653
10308
|
return null;
|
|
@@ -9673,11 +10328,11 @@ function stopExisting() {
|
|
|
9673
10328
|
if (!isPidAlive(pid)) {
|
|
9674
10329
|
info2(chalk23.gray(`Stale PID ${pid} \u2014 cleaning up.`));
|
|
9675
10330
|
try {
|
|
9676
|
-
|
|
10331
|
+
fs41.unlinkSync(pidFilePath());
|
|
9677
10332
|
} catch {
|
|
9678
10333
|
}
|
|
9679
10334
|
try {
|
|
9680
|
-
|
|
10335
|
+
fs41.unlinkSync(urlFilePath());
|
|
9681
10336
|
} catch {
|
|
9682
10337
|
}
|
|
9683
10338
|
return false;
|
|
@@ -9686,11 +10341,11 @@ function stopExisting() {
|
|
|
9686
10341
|
process.kill(pid);
|
|
9687
10342
|
info2(chalk23.gray(`Stopped work web (PID ${pid}).`));
|
|
9688
10343
|
try {
|
|
9689
|
-
|
|
10344
|
+
fs41.unlinkSync(pidFilePath());
|
|
9690
10345
|
} catch {
|
|
9691
10346
|
}
|
|
9692
10347
|
try {
|
|
9693
|
-
|
|
10348
|
+
fs41.unlinkSync(urlFilePath());
|
|
9694
10349
|
} catch {
|
|
9695
10350
|
}
|
|
9696
10351
|
return true;
|
|
@@ -9741,19 +10396,19 @@ var webCommand = {
|
|
|
9741
10396
|
process.exit(1);
|
|
9742
10397
|
}
|
|
9743
10398
|
try {
|
|
9744
|
-
|
|
10399
|
+
fs41.unlinkSync(pidFilePath());
|
|
9745
10400
|
} catch {
|
|
9746
10401
|
}
|
|
9747
10402
|
try {
|
|
9748
|
-
|
|
10403
|
+
fs41.unlinkSync(urlFilePath());
|
|
9749
10404
|
} catch {
|
|
9750
10405
|
}
|
|
9751
10406
|
const lean = !!argv.lean || process.env.WORK_WEB_LEAN === "1";
|
|
9752
10407
|
const handle = await startWebServer({ lean });
|
|
9753
10408
|
try {
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
10409
|
+
fs41.mkdirSync(path42.dirname(urlFilePath()), { recursive: true });
|
|
10410
|
+
fs41.writeFileSync(urlFilePath(), handle.url);
|
|
10411
|
+
fs41.writeFileSync(pidFilePath(), String(process.pid));
|
|
9757
10412
|
} catch {
|
|
9758
10413
|
}
|
|
9759
10414
|
info2(
|
|
@@ -9783,11 +10438,11 @@ var webCommand = {
|
|
|
9783
10438
|
const shutdown = () => {
|
|
9784
10439
|
info2(chalk23.gray("\nStopping work web."));
|
|
9785
10440
|
try {
|
|
9786
|
-
|
|
10441
|
+
fs41.unlinkSync(urlFilePath());
|
|
9787
10442
|
} catch {
|
|
9788
10443
|
}
|
|
9789
10444
|
try {
|
|
9790
|
-
|
|
10445
|
+
fs41.unlinkSync(pidFilePath());
|
|
9791
10446
|
} catch {
|
|
9792
10447
|
}
|
|
9793
10448
|
if (!lean) {
|
|
@@ -9807,11 +10462,11 @@ var webCommand = {
|
|
|
9807
10462
|
process.on("SIGTERM", shutdown);
|
|
9808
10463
|
process.on("exit", () => {
|
|
9809
10464
|
try {
|
|
9810
|
-
|
|
10465
|
+
fs41.unlinkSync(pidFilePath());
|
|
9811
10466
|
} catch {
|
|
9812
10467
|
}
|
|
9813
10468
|
try {
|
|
9814
|
-
|
|
10469
|
+
fs41.unlinkSync(urlFilePath());
|
|
9815
10470
|
} catch {
|
|
9816
10471
|
}
|
|
9817
10472
|
});
|
|
@@ -9886,7 +10541,7 @@ var hookCommand = {
|
|
|
9886
10541
|
|
|
9887
10542
|
// src/commands/run.ts
|
|
9888
10543
|
import chalk24 from "chalk";
|
|
9889
|
-
import
|
|
10544
|
+
import spawn14 from "cross-spawn";
|
|
9890
10545
|
|
|
9891
10546
|
// src/core/fleet.ts
|
|
9892
10547
|
function selectSessions(sessions, filter) {
|
|
@@ -9928,7 +10583,7 @@ function killAllChildren(signal = "SIGTERM") {
|
|
|
9928
10583
|
function runInPath(unit, cmd, prefix) {
|
|
9929
10584
|
const { bin, args } = shellInvocation(cmd);
|
|
9930
10585
|
return new Promise((resolve) => {
|
|
9931
|
-
const child =
|
|
10586
|
+
const child = spawn14(bin, args, {
|
|
9932
10587
|
cwd: unit.path,
|
|
9933
10588
|
stdio: prefix ? ["ignore", "pipe", "pipe"] : "inherit",
|
|
9934
10589
|
shell: false
|
|
@@ -10160,15 +10815,15 @@ var runCommand = {
|
|
|
10160
10815
|
};
|
|
10161
10816
|
|
|
10162
10817
|
// src/commands/broadcast.ts
|
|
10163
|
-
import
|
|
10818
|
+
import fs43 from "fs";
|
|
10164
10819
|
import chalk25 from "chalk";
|
|
10165
10820
|
|
|
10166
10821
|
// src/core/broadcast.ts
|
|
10167
10822
|
import crypto6 from "crypto";
|
|
10168
|
-
import
|
|
10823
|
+
import fs42 from "fs";
|
|
10169
10824
|
function readComments(file) {
|
|
10170
10825
|
try {
|
|
10171
|
-
const parsed = JSON.parse(
|
|
10826
|
+
const parsed = JSON.parse(fs42.readFileSync(file, "utf-8"));
|
|
10172
10827
|
return Array.isArray(parsed) ? parsed : [];
|
|
10173
10828
|
} catch {
|
|
10174
10829
|
return [];
|
|
@@ -10176,7 +10831,7 @@ function readComments(file) {
|
|
|
10176
10831
|
}
|
|
10177
10832
|
async function appendLocked(sessionId, body) {
|
|
10178
10833
|
const file = commentsFileFor(sessionId);
|
|
10179
|
-
|
|
10834
|
+
fs42.mkdirSync(commentsDir(), { recursive: true });
|
|
10180
10835
|
ensureFile(file, "[]");
|
|
10181
10836
|
const comment = {
|
|
10182
10837
|
id: crypto6.randomBytes(8).toString("hex"),
|
|
@@ -10213,7 +10868,7 @@ async function broadcastPrompt(sessions, filter, prompt) {
|
|
|
10213
10868
|
// src/commands/broadcast.ts
|
|
10214
10869
|
function readStdin() {
|
|
10215
10870
|
try {
|
|
10216
|
-
return
|
|
10871
|
+
return fs43.readFileSync(0, "utf-8");
|
|
10217
10872
|
} catch {
|
|
10218
10873
|
return "";
|
|
10219
10874
|
}
|
|
@@ -10288,8 +10943,8 @@ var broadcastCommand = {
|
|
|
10288
10943
|
};
|
|
10289
10944
|
|
|
10290
10945
|
// src/completions/index.ts
|
|
10291
|
-
import
|
|
10292
|
-
import
|
|
10946
|
+
import fs44 from "fs";
|
|
10947
|
+
import path43 from "path";
|
|
10293
10948
|
function completionHandler(current, argv, done) {
|
|
10294
10949
|
const rawArgs = argv._;
|
|
10295
10950
|
const args = rawArgs.slice(1, -1);
|
|
@@ -10393,7 +11048,7 @@ function completeTreeRemoveList(command, args, current, config, done) {
|
|
|
10393
11048
|
}
|
|
10394
11049
|
function completeRepoBranches(alias, current, config, done) {
|
|
10395
11050
|
const repoPath = config.repos[alias];
|
|
10396
|
-
if (!repoPath || !
|
|
11051
|
+
if (!repoPath || !fs44.existsSync(repoPath)) {
|
|
10397
11052
|
done([]);
|
|
10398
11053
|
return;
|
|
10399
11054
|
}
|
|
@@ -10402,19 +11057,19 @@ function completeRepoBranches(alias, current, config, done) {
|
|
|
10402
11057
|
done(branches);
|
|
10403
11058
|
}
|
|
10404
11059
|
function completeGroupBranches(groupName, repoAliases, current, config, done) {
|
|
10405
|
-
const groupDir =
|
|
10406
|
-
if (!
|
|
11060
|
+
const groupDir = path43.join(config.worktreesRoot, groupName);
|
|
11061
|
+
if (!fs44.existsSync(groupDir)) {
|
|
10407
11062
|
done([]);
|
|
10408
11063
|
return;
|
|
10409
11064
|
}
|
|
10410
11065
|
try {
|
|
10411
|
-
const branchDirs =
|
|
10412
|
-
const bdPath =
|
|
11066
|
+
const branchDirs = fs44.readdirSync(groupDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => {
|
|
11067
|
+
const bdPath = path43.join(groupDir, d.name);
|
|
10413
11068
|
for (const alias of repoAliases) {
|
|
10414
11069
|
const repoPath = config.repos[alias];
|
|
10415
11070
|
if (!repoPath) continue;
|
|
10416
|
-
const subPath =
|
|
10417
|
-
if (
|
|
11071
|
+
const subPath = path43.join(bdPath, path43.basename(repoPath));
|
|
11072
|
+
if (fs44.existsSync(subPath)) {
|
|
10418
11073
|
const branch = getCurrentBranch(subPath);
|
|
10419
11074
|
if (branch) return branch;
|
|
10420
11075
|
}
|
|
@@ -10428,7 +11083,7 @@ function completeGroupBranches(groupName, repoAliases, current, config, done) {
|
|
|
10428
11083
|
}
|
|
10429
11084
|
|
|
10430
11085
|
// src/version.ts
|
|
10431
|
-
var VERSION = true ? "1.
|
|
11086
|
+
var VERSION = true ? "1.8.0" : "dev";
|
|
10432
11087
|
|
|
10433
11088
|
// src/cli.ts
|
|
10434
11089
|
function showHelp() {
|