@moberg_hr/work-tree 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/bin.js +541 -166
- package/dist/bin.js.map +1 -1
- package/dist/wd-bin.js +538 -163
- package/dist/wd-bin.js.map +1 -1
- package/dist/web/assets/{index-BV5-pKcI.js → index-B-iWIQnC.js} +57 -58
- package/dist/web/assets/index-B-iWIQnC.js.map +1 -0
- package/dist/web/assets/{index-uJQw1Itb.css → index-BYfxyhDx.css} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/index-BV5-pKcI.js.map +0 -1
package/dist/bin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/bin.ts
|
|
4
|
-
import
|
|
4
|
+
import fs46 from "fs";
|
|
5
5
|
import path44 from "path";
|
|
6
6
|
import chalk27 from "chalk";
|
|
7
7
|
|
|
@@ -1464,6 +1464,9 @@ function latestJsonlMtimeMs(projectDir) {
|
|
|
1464
1464
|
}
|
|
1465
1465
|
return latest;
|
|
1466
1466
|
}
|
|
1467
|
+
function claudeActiveWithin(activityMs, nowMs, windowMs) {
|
|
1468
|
+
return activityMs > 0 && nowMs - activityMs < windowMs;
|
|
1469
|
+
}
|
|
1467
1470
|
function getClaudeActivityMs(launchPath) {
|
|
1468
1471
|
const dir = path9.join(
|
|
1469
1472
|
os4.homedir(),
|
|
@@ -1488,6 +1491,28 @@ function effectiveLastAccessedAt(session) {
|
|
|
1488
1491
|
}
|
|
1489
1492
|
return new Date(bestMs).toISOString();
|
|
1490
1493
|
}
|
|
1494
|
+
function resolveResumeLaunch(session) {
|
|
1495
|
+
const existing = session.paths.filter((p) => fs9.existsSync(p));
|
|
1496
|
+
const first = existing[0] ?? session.paths[0];
|
|
1497
|
+
const defaultPath = session.isGroup ? path9.dirname(first) : first;
|
|
1498
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
1499
|
+
if (session.isGroup) {
|
|
1500
|
+
for (const p of existing) candidates.add(path9.dirname(p));
|
|
1501
|
+
for (const p of existing) candidates.add(p);
|
|
1502
|
+
} else {
|
|
1503
|
+
for (const p of existing) candidates.add(p);
|
|
1504
|
+
}
|
|
1505
|
+
let launchPath = defaultPath;
|
|
1506
|
+
let bestMs = 0;
|
|
1507
|
+
for (const c of candidates) {
|
|
1508
|
+
const ms = getClaudeActivityMs(c);
|
|
1509
|
+
if (ms > bestMs) {
|
|
1510
|
+
bestMs = ms;
|
|
1511
|
+
launchPath = c;
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
return { launchPath, hasConversation: bestMs > 0 };
|
|
1515
|
+
}
|
|
1491
1516
|
var ACTIVE_MS = 3e4;
|
|
1492
1517
|
var OPEN_MS = 5 * 6e4;
|
|
1493
1518
|
function readSessionActivity(session) {
|
|
@@ -2747,7 +2772,6 @@ function printSessionStatus(session) {
|
|
|
2747
2772
|
|
|
2748
2773
|
// src/commands/recent.ts
|
|
2749
2774
|
import fs17 from "fs";
|
|
2750
|
-
import path14 from "path";
|
|
2751
2775
|
import chalk10 from "chalk";
|
|
2752
2776
|
import { select as select2 } from "@inquirer/prompts";
|
|
2753
2777
|
var recentCommand = {
|
|
@@ -2805,12 +2829,19 @@ var recentCommand = {
|
|
|
2805
2829
|
process.exitCode = 1;
|
|
2806
2830
|
return;
|
|
2807
2831
|
}
|
|
2808
|
-
const launchPath
|
|
2832
|
+
const { launchPath, hasConversation } = resolveResumeLaunch(choice);
|
|
2809
2833
|
await upsertSession(choice.target, choice.isGroup, choice.branch, choice.paths);
|
|
2810
2834
|
const tool = getAiTool(config);
|
|
2811
2835
|
console.log(chalk10.cyan(`Resuming in: ${launchPath}`));
|
|
2836
|
+
if (!hasConversation) {
|
|
2837
|
+
console.log(
|
|
2838
|
+
chalk10.yellow(
|
|
2839
|
+
`No prior ${tool.cmd} conversation found for this worktree \u2014 starting a fresh session.`
|
|
2840
|
+
)
|
|
2841
|
+
);
|
|
2842
|
+
}
|
|
2812
2843
|
console.log(`Starting ${tool.cmd}...`);
|
|
2813
|
-
launchAi(launchPath, tool, { unsafe, resume:
|
|
2844
|
+
launchAi(launchPath, tool, { unsafe, resume: hasConversation }, choice.port);
|
|
2814
2845
|
return;
|
|
2815
2846
|
}
|
|
2816
2847
|
console.log("");
|
|
@@ -2837,7 +2868,6 @@ var recentCommand = {
|
|
|
2837
2868
|
|
|
2838
2869
|
// src/commands/resume.ts
|
|
2839
2870
|
import fs18 from "fs";
|
|
2840
|
-
import path15 from "path";
|
|
2841
2871
|
import chalk11 from "chalk";
|
|
2842
2872
|
import { select as select3 } from "@inquirer/prompts";
|
|
2843
2873
|
var resumeCommand = {
|
|
@@ -2880,12 +2910,19 @@ var resumeCommand = {
|
|
|
2880
2910
|
process.exitCode = 1;
|
|
2881
2911
|
return;
|
|
2882
2912
|
}
|
|
2883
|
-
const launchPath
|
|
2913
|
+
const { launchPath, hasConversation } = resolveResumeLaunch(choice);
|
|
2884
2914
|
await upsertSession(choice.target, choice.isGroup, choice.branch, choice.paths);
|
|
2885
2915
|
const tool = getAiTool(config);
|
|
2886
2916
|
console.log(chalk11.cyan(`Resuming in: ${launchPath}`));
|
|
2917
|
+
if (!hasConversation) {
|
|
2918
|
+
console.log(
|
|
2919
|
+
chalk11.yellow(
|
|
2920
|
+
`No prior ${tool.cmd} conversation found for this worktree \u2014 starting a fresh session.`
|
|
2921
|
+
)
|
|
2922
|
+
);
|
|
2923
|
+
}
|
|
2887
2924
|
console.log(`Starting ${tool.cmd}...`);
|
|
2888
|
-
launchAi(launchPath, tool, { unsafe, resume:
|
|
2925
|
+
launchAi(launchPath, tool, { unsafe, resume: hasConversation }, choice.port);
|
|
2889
2926
|
}
|
|
2890
2927
|
};
|
|
2891
2928
|
|
|
@@ -2895,7 +2932,7 @@ import { checkbox } from "@inquirer/prompts";
|
|
|
2895
2932
|
|
|
2896
2933
|
// src/core/prunable-scan.ts
|
|
2897
2934
|
import fs19 from "fs";
|
|
2898
|
-
import
|
|
2935
|
+
import path14 from "path";
|
|
2899
2936
|
import chalk12 from "chalk";
|
|
2900
2937
|
function collectPrunable(config, options = {}) {
|
|
2901
2938
|
const { fetch: fetch2 = true, print = true, includeSquash = false } = options;
|
|
@@ -2912,7 +2949,7 @@ function collectPrunable(config, options = {}) {
|
|
|
2912
2949
|
}
|
|
2913
2950
|
const groupCoveredKeys = /* @__PURE__ */ new Set();
|
|
2914
2951
|
for (const [groupName, aliases] of Object.entries(config.groups)) {
|
|
2915
|
-
const groupDir =
|
|
2952
|
+
const groupDir = path14.join(config.worktreesRoot, groupName);
|
|
2916
2953
|
if (!fs19.existsSync(groupDir)) continue;
|
|
2917
2954
|
let branchDirs;
|
|
2918
2955
|
try {
|
|
@@ -2921,7 +2958,7 @@ function collectPrunable(config, options = {}) {
|
|
|
2921
2958
|
continue;
|
|
2922
2959
|
}
|
|
2923
2960
|
for (const branchDir of branchDirs) {
|
|
2924
|
-
const branchDirPath =
|
|
2961
|
+
const branchDirPath = path14.join(groupDir, branchDir);
|
|
2925
2962
|
let branch;
|
|
2926
2963
|
let allMerged = true;
|
|
2927
2964
|
let groupHasChanges = false;
|
|
@@ -2935,8 +2972,8 @@ function collectPrunable(config, options = {}) {
|
|
|
2935
2972
|
skipped = true;
|
|
2936
2973
|
continue;
|
|
2937
2974
|
}
|
|
2938
|
-
const repoName =
|
|
2939
|
-
const subWorktreePath =
|
|
2975
|
+
const repoName = path14.basename(repoPath);
|
|
2976
|
+
const subWorktreePath = path14.join(branchDirPath, repoName);
|
|
2940
2977
|
if (!fs19.existsSync(subWorktreePath)) {
|
|
2941
2978
|
continue;
|
|
2942
2979
|
}
|
|
@@ -3053,7 +3090,7 @@ async function removeSingleEntry(entry, force = true) {
|
|
|
3053
3090
|
}
|
|
3054
3091
|
async function removeGroupEntry(entry, config, force = true) {
|
|
3055
3092
|
const workTreeDirName = entry.branch.replace(/\//g, "-");
|
|
3056
|
-
const groupWorktreePath =
|
|
3093
|
+
const groupWorktreePath = path14.join(
|
|
3057
3094
|
config.worktreesRoot,
|
|
3058
3095
|
entry.target,
|
|
3059
3096
|
workTreeDirName
|
|
@@ -3063,7 +3100,7 @@ async function removeGroupEntry(entry, config, force = true) {
|
|
|
3063
3100
|
);
|
|
3064
3101
|
let allRemoved = true;
|
|
3065
3102
|
for (const { alias, repoPath, worktreePath } of entry.repos) {
|
|
3066
|
-
const repoName =
|
|
3103
|
+
const repoName = path14.basename(repoPath);
|
|
3067
3104
|
console.log(chalk12.cyan(` [${alias}] (${repoName}):`));
|
|
3068
3105
|
const removed = removeSingleWorktree(repoPath, worktreePath, entry.branch, force);
|
|
3069
3106
|
if (!removed) {
|
|
@@ -3073,7 +3110,7 @@ async function removeGroupEntry(entry, config, force = true) {
|
|
|
3073
3110
|
if (allRemoved) {
|
|
3074
3111
|
await removeSession(entry.target, entry.branch);
|
|
3075
3112
|
}
|
|
3076
|
-
const claudeMdInWorktree =
|
|
3113
|
+
const claudeMdInWorktree = path14.join(groupWorktreePath, "CLAUDE.md");
|
|
3077
3114
|
if (fs19.existsSync(claudeMdInWorktree)) {
|
|
3078
3115
|
fs19.unlinkSync(claudeMdInWorktree);
|
|
3079
3116
|
}
|
|
@@ -3299,7 +3336,7 @@ var syncCommand = {
|
|
|
3299
3336
|
|
|
3300
3337
|
// src/tui-ink/index.tsx
|
|
3301
3338
|
import fs24 from "fs";
|
|
3302
|
-
import
|
|
3339
|
+
import path19 from "path";
|
|
3303
3340
|
import { render } from "ink";
|
|
3304
3341
|
|
|
3305
3342
|
// src/tui-ink/App.tsx
|
|
@@ -3307,7 +3344,7 @@ import { useState, useEffect, useRef, useCallback, useMemo } from "react";
|
|
|
3307
3344
|
import { Box as Box5 } from "ink";
|
|
3308
3345
|
import fs23 from "fs";
|
|
3309
3346
|
import os6 from "os";
|
|
3310
|
-
import
|
|
3347
|
+
import path18 from "path";
|
|
3311
3348
|
import { execFile as execFile4 } from "child_process";
|
|
3312
3349
|
import spawn7 from "cross-spawn";
|
|
3313
3350
|
|
|
@@ -3521,10 +3558,10 @@ async function fetchJiraPane() {
|
|
|
3521
3558
|
|
|
3522
3559
|
// src/core/tasks.ts
|
|
3523
3560
|
import fs21 from "fs";
|
|
3524
|
-
import
|
|
3561
|
+
import path15 from "path";
|
|
3525
3562
|
var EMPTY_STORE = { nextId: 1, tasks: [] };
|
|
3526
3563
|
function getTasksPath() {
|
|
3527
|
-
return
|
|
3564
|
+
return path15.join(getConfigDir(), "tasks.json");
|
|
3528
3565
|
}
|
|
3529
3566
|
function loadStore() {
|
|
3530
3567
|
const p = getTasksPath();
|
|
@@ -3773,13 +3810,13 @@ var PtySession = class {
|
|
|
3773
3810
|
|
|
3774
3811
|
// src/core/hook-server.ts
|
|
3775
3812
|
import http from "http";
|
|
3776
|
-
import
|
|
3813
|
+
import path17 from "path";
|
|
3777
3814
|
|
|
3778
3815
|
// src/core/settings-editor.ts
|
|
3779
3816
|
import fs22 from "fs";
|
|
3780
|
-
import
|
|
3817
|
+
import path16 from "path";
|
|
3781
3818
|
import os5 from "os";
|
|
3782
|
-
var SETTINGS_PATH =
|
|
3819
|
+
var SETTINGS_PATH = path16.join(os5.homedir(), ".claude", "settings.json");
|
|
3783
3820
|
var OWNER_TAG = "_workHookOwner";
|
|
3784
3821
|
var PID_TAG = "_workHookPid";
|
|
3785
3822
|
var LEGACY_TAGS = ["_workDash", "_work2Dash"];
|
|
@@ -3793,7 +3830,7 @@ function readSettings() {
|
|
|
3793
3830
|
}
|
|
3794
3831
|
function writeAtomic(s) {
|
|
3795
3832
|
try {
|
|
3796
|
-
fs22.mkdirSync(
|
|
3833
|
+
fs22.mkdirSync(path16.dirname(SETTINGS_PATH), { recursive: true });
|
|
3797
3834
|
const tmp = `${SETTINGS_PATH}.tmp-${process.pid}-${Date.now()}`;
|
|
3798
3835
|
fs22.writeFileSync(tmp, JSON.stringify(s, null, 2), "utf-8");
|
|
3799
3836
|
fs22.renameSync(tmp, SETTINGS_PATH);
|
|
@@ -3968,7 +4005,7 @@ function removeHttpHooksSync(owner) {
|
|
|
3968
4005
|
editSettingsSync(mutateRemove(owner));
|
|
3969
4006
|
}
|
|
3970
4007
|
function normalizePath(p) {
|
|
3971
|
-
return
|
|
4008
|
+
return path17.resolve(p).toLowerCase();
|
|
3972
4009
|
}
|
|
3973
4010
|
|
|
3974
4011
|
// src/core/notifier.ts
|
|
@@ -5047,9 +5084,9 @@ var RENDER_INTERVAL_MS = 50;
|
|
|
5047
5084
|
var MOUSE_SGR_RE = /\x1b\[<(\d+);(\d+);(\d+)[Mm]/;
|
|
5048
5085
|
function hasClaudeConversation(dir) {
|
|
5049
5086
|
try {
|
|
5050
|
-
const resolved =
|
|
5087
|
+
const resolved = path18.resolve(dir);
|
|
5051
5088
|
const projectDir = resolved.replace(/[^a-zA-Z0-9-]/g, "-");
|
|
5052
|
-
const claudeProjectPath =
|
|
5089
|
+
const claudeProjectPath = path18.join(os6.homedir(), ".claude", "projects", projectDir);
|
|
5053
5090
|
if (!fs23.existsSync(claudeProjectPath)) return false;
|
|
5054
5091
|
const files = fs23.readdirSync(claudeProjectPath);
|
|
5055
5092
|
return files.some((f) => f.endsWith(".jsonl"));
|
|
@@ -5058,7 +5095,7 @@ function hasClaudeConversation(dir) {
|
|
|
5058
5095
|
}
|
|
5059
5096
|
}
|
|
5060
5097
|
function ptyDedupKey(pty2) {
|
|
5061
|
-
return
|
|
5098
|
+
return path18.resolve(pty2.cwd).toLowerCase();
|
|
5062
5099
|
}
|
|
5063
5100
|
function loadSessions() {
|
|
5064
5101
|
const all = loadHistory();
|
|
@@ -5352,10 +5389,10 @@ function App({ unsafe, onExit }) {
|
|
|
5352
5389
|
}
|
|
5353
5390
|
}, [setScrollBack, renderTermAtScroll]);
|
|
5354
5391
|
const findPtyByCwd = useCallback((cwd) => {
|
|
5355
|
-
const normalized =
|
|
5392
|
+
const normalized = path18.resolve(cwd).toLowerCase();
|
|
5356
5393
|
for (const pty2 of ptySessions.current.values()) {
|
|
5357
5394
|
if (pty2.exited) continue;
|
|
5358
|
-
if (normalized.startsWith(
|
|
5395
|
+
if (normalized.startsWith(path18.resolve(pty2.cwd).toLowerCase())) return pty2;
|
|
5359
5396
|
}
|
|
5360
5397
|
return void 0;
|
|
5361
5398
|
}, []);
|
|
@@ -5431,13 +5468,13 @@ function App({ unsafe, onExit }) {
|
|
|
5431
5468
|
notifiedSessionsRef.current
|
|
5432
5469
|
);
|
|
5433
5470
|
if (kind) {
|
|
5434
|
-
notifyDesktop(
|
|
5471
|
+
notifyDesktop(path18.basename(pty2.cwd), kind, {
|
|
5435
5472
|
enabled: config?.notifications === true
|
|
5436
5473
|
});
|
|
5437
5474
|
runStatusHooks(
|
|
5438
5475
|
kind,
|
|
5439
5476
|
pty2.cwd,
|
|
5440
|
-
|
|
5477
|
+
path18.basename(pty2.cwd),
|
|
5441
5478
|
config?.statusHooks
|
|
5442
5479
|
);
|
|
5443
5480
|
}
|
|
@@ -5570,7 +5607,7 @@ function App({ unsafe, onExit }) {
|
|
|
5570
5607
|
refreshSessions();
|
|
5571
5608
|
return;
|
|
5572
5609
|
}
|
|
5573
|
-
const dir = s.isGroup ?
|
|
5610
|
+
const dir = s.isGroup ? path18.dirname(existing) : existing;
|
|
5574
5611
|
const resume = hasClaudeConversation(dir);
|
|
5575
5612
|
const tool = getAiTool(config ?? {});
|
|
5576
5613
|
const pty2 = new PtySession(dir, termInner, contentHeight - 2, void 0, { tool, unsafe, resume, port: s.port });
|
|
@@ -5668,7 +5705,7 @@ function App({ unsafe, onExit }) {
|
|
|
5668
5705
|
"",
|
|
5669
5706
|
" - Ask if I want to proceed with the recommended approach, choose a different one, get more details, or make adjustments."
|
|
5670
5707
|
].join("\n");
|
|
5671
|
-
promptFile =
|
|
5708
|
+
promptFile = path18.join(os6.tmpdir(), `work-prompt-${Date.now()}.txt`);
|
|
5672
5709
|
fs23.writeFileSync(promptFile, prompt, "utf-8");
|
|
5673
5710
|
}
|
|
5674
5711
|
const setupArgs = ["tree", projectName, branchName, "--setup-only"];
|
|
@@ -5708,7 +5745,7 @@ function App({ unsafe, onExit }) {
|
|
|
5708
5745
|
setStatusVersion((v) => v + 1);
|
|
5709
5746
|
return;
|
|
5710
5747
|
}
|
|
5711
|
-
const launchDir = session.isGroup ?
|
|
5748
|
+
const launchDir = session.isGroup ? path18.dirname(existing) : existing;
|
|
5712
5749
|
const tool = getAiTool(config);
|
|
5713
5750
|
const aiPty = new PtySession(
|
|
5714
5751
|
launchDir,
|
|
@@ -6283,7 +6320,7 @@ function App({ unsafe, onExit }) {
|
|
|
6283
6320
|
setMessage("Session path no longer exists");
|
|
6284
6321
|
return;
|
|
6285
6322
|
}
|
|
6286
|
-
const dir = s.isGroup ?
|
|
6323
|
+
const dir = s.isGroup ? path18.dirname(existing) : existing;
|
|
6287
6324
|
const editor = config?.editor ?? "code";
|
|
6288
6325
|
spawn7(editor, [dir], { detached: true, stdio: "ignore" }).unref();
|
|
6289
6326
|
setMessage(`Opened in ${editor}: ${s.branch}`);
|
|
@@ -6468,7 +6505,7 @@ function crashLog(label2, err) {
|
|
|
6468
6505
|
const msg = err instanceof Error ? err.stack || err.message : String(err);
|
|
6469
6506
|
const line = `${(/* @__PURE__ */ new Date()).toISOString()} [CRASH] ${label2}: ${msg}
|
|
6470
6507
|
`;
|
|
6471
|
-
fs24.appendFileSync(
|
|
6508
|
+
fs24.appendFileSync(path19.join(getConfigDir(), "debug.log"), line);
|
|
6472
6509
|
} catch {
|
|
6473
6510
|
}
|
|
6474
6511
|
}
|
|
@@ -6792,22 +6829,22 @@ import chalk17 from "chalk";
|
|
|
6792
6829
|
|
|
6793
6830
|
// src/core/hydrate.ts
|
|
6794
6831
|
import fs25 from "fs";
|
|
6795
|
-
import
|
|
6832
|
+
import path20 from "path";
|
|
6796
6833
|
async function hydrateHistoryFromDisk(config) {
|
|
6797
|
-
const worktreesRoot =
|
|
6834
|
+
const worktreesRoot = path20.resolve(config.worktreesRoot);
|
|
6798
6835
|
const folderNameToAlias = /* @__PURE__ */ new Map();
|
|
6799
6836
|
for (const [alias, repoPath] of Object.entries(config.repos)) {
|
|
6800
|
-
folderNameToAlias.set(
|
|
6837
|
+
folderNameToAlias.set(path20.basename(repoPath), alias);
|
|
6801
6838
|
}
|
|
6802
6839
|
const discovered = /* @__PURE__ */ new Map();
|
|
6803
6840
|
for (const [alias, repoPath] of Object.entries(config.repos)) {
|
|
6804
6841
|
if (!fs25.existsSync(repoPath)) continue;
|
|
6805
6842
|
for (const entry of parseWorktreeList(repoPath)) {
|
|
6806
6843
|
if (!entry.branch) continue;
|
|
6807
|
-
if (
|
|
6808
|
-
const rel =
|
|
6809
|
-
if (!rel || rel.startsWith("..") ||
|
|
6810
|
-
const parts = rel.split(
|
|
6844
|
+
if (path20.resolve(entry.path) === path20.resolve(repoPath)) continue;
|
|
6845
|
+
const rel = path20.relative(worktreesRoot, entry.path);
|
|
6846
|
+
if (!rel || rel.startsWith("..") || path20.isAbsolute(rel)) continue;
|
|
6847
|
+
const parts = rel.split(path20.sep).filter(Boolean);
|
|
6811
6848
|
if (parts.length < 2) continue;
|
|
6812
6849
|
const [first, second] = parts;
|
|
6813
6850
|
const isGroup = Object.prototype.hasOwnProperty.call(config.groups, first);
|
|
@@ -6892,13 +6929,13 @@ var hydrateCommand = {
|
|
|
6892
6929
|
// src/commands/diff.ts
|
|
6893
6930
|
import fs36 from "fs";
|
|
6894
6931
|
import os9 from "os";
|
|
6895
|
-
import
|
|
6932
|
+
import path31 from "path";
|
|
6896
6933
|
import { spawn as childSpawn } from "child_process";
|
|
6897
6934
|
import chalk21 from "chalk";
|
|
6898
6935
|
|
|
6899
6936
|
// src/core/diff-pipeline.ts
|
|
6900
6937
|
import fs28 from "fs";
|
|
6901
|
-
import
|
|
6938
|
+
import path23 from "path";
|
|
6902
6939
|
import spawn9 from "cross-spawn";
|
|
6903
6940
|
|
|
6904
6941
|
// src/core/diff-parse.ts
|
|
@@ -7047,7 +7084,7 @@ function stripPathPrefix(p) {
|
|
|
7047
7084
|
|
|
7048
7085
|
// src/core/lcov.ts
|
|
7049
7086
|
import fs26 from "fs";
|
|
7050
|
-
import
|
|
7087
|
+
import path21 from "path";
|
|
7051
7088
|
function parseLcov(content) {
|
|
7052
7089
|
const result = /* @__PURE__ */ new Map();
|
|
7053
7090
|
let sf = null;
|
|
@@ -7106,8 +7143,8 @@ function parseLcov(content) {
|
|
|
7106
7143
|
}
|
|
7107
7144
|
function findLcov(root) {
|
|
7108
7145
|
const candidates = [
|
|
7109
|
-
|
|
7110
|
-
|
|
7146
|
+
path21.join(root, "coverage", "lcov.info"),
|
|
7147
|
+
path21.join(root, "lcov.info")
|
|
7111
7148
|
];
|
|
7112
7149
|
for (const c of candidates) {
|
|
7113
7150
|
try {
|
|
@@ -7142,33 +7179,33 @@ function readParsedLcov(lcovPath) {
|
|
|
7142
7179
|
return { parsed, mtimeMs };
|
|
7143
7180
|
}
|
|
7144
7181
|
function normRel(p) {
|
|
7145
|
-
return
|
|
7182
|
+
return path21.normalize(p).replace(/\\/g, "/").replace(/^\.\//, "");
|
|
7146
7183
|
}
|
|
7147
7184
|
function realRoot(root) {
|
|
7148
7185
|
try {
|
|
7149
|
-
return fs26.realpathSync(
|
|
7186
|
+
return fs26.realpathSync(path21.resolve(root));
|
|
7150
7187
|
} catch {
|
|
7151
|
-
return
|
|
7188
|
+
return path21.resolve(root);
|
|
7152
7189
|
}
|
|
7153
7190
|
}
|
|
7154
7191
|
function canonicalize(absPath) {
|
|
7155
|
-
const resolved =
|
|
7192
|
+
const resolved = path21.resolve(absPath);
|
|
7156
7193
|
let dir = resolved;
|
|
7157
7194
|
const tail = [];
|
|
7158
7195
|
for (; ; ) {
|
|
7159
7196
|
try {
|
|
7160
7197
|
const realDir = fs26.realpathSync(dir);
|
|
7161
|
-
return tail.length ?
|
|
7198
|
+
return tail.length ? path21.join(realDir, ...tail.reverse()) : realDir;
|
|
7162
7199
|
} catch {
|
|
7163
|
-
const parent =
|
|
7200
|
+
const parent = path21.dirname(dir);
|
|
7164
7201
|
if (parent === dir) return resolved;
|
|
7165
|
-
tail.push(
|
|
7202
|
+
tail.push(path21.basename(dir));
|
|
7166
7203
|
dir = parent;
|
|
7167
7204
|
}
|
|
7168
7205
|
}
|
|
7169
7206
|
}
|
|
7170
7207
|
function relForAbsSf(absSf, canonRoot) {
|
|
7171
|
-
return
|
|
7208
|
+
return path21.relative(canonRoot, canonicalize(absSf));
|
|
7172
7209
|
}
|
|
7173
7210
|
function coverageLookup(root, relPaths) {
|
|
7174
7211
|
const out = /* @__PURE__ */ new Map();
|
|
@@ -7181,7 +7218,7 @@ function coverageLookup(root, relPaths) {
|
|
|
7181
7218
|
const canonRoot = realRoot(root);
|
|
7182
7219
|
const byRel = /* @__PURE__ */ new Map();
|
|
7183
7220
|
for (const [sf, pct] of read.parsed) {
|
|
7184
|
-
const rel =
|
|
7221
|
+
const rel = path21.isAbsolute(sf) ? relForAbsSf(sf, canonRoot) : sf;
|
|
7185
7222
|
byRel.set(normRel(rel), pct);
|
|
7186
7223
|
}
|
|
7187
7224
|
for (const rp of relPaths) {
|
|
@@ -7194,12 +7231,12 @@ function coverageLookup(root, relPaths) {
|
|
|
7194
7231
|
// src/core/git-tree-snapshot.ts
|
|
7195
7232
|
import fs27 from "fs";
|
|
7196
7233
|
import os7 from "os";
|
|
7197
|
-
import
|
|
7234
|
+
import path22 from "path";
|
|
7198
7235
|
import crypto from "crypto";
|
|
7199
7236
|
import spawn8 from "cross-spawn";
|
|
7200
7237
|
function writeTempTree(repoRoot, opts = {}) {
|
|
7201
7238
|
const includeWorkingTree = opts.includeWorkingTree ?? true;
|
|
7202
|
-
const tmpIndex =
|
|
7239
|
+
const tmpIndex = path22.join(
|
|
7203
7240
|
os7.tmpdir(),
|
|
7204
7241
|
`wd-tree-${process.pid}-${crypto.randomBytes(6).toString("hex")}.idx`
|
|
7205
7242
|
);
|
|
@@ -7244,12 +7281,12 @@ function isMarkdownPath(p) {
|
|
|
7244
7281
|
return p !== "/dev/null" && MARKDOWN_EXT_RE.test(p);
|
|
7245
7282
|
}
|
|
7246
7283
|
function isInsideRoot(root, rel) {
|
|
7247
|
-
const resolvedRoot =
|
|
7248
|
-
const resolvedTarget =
|
|
7249
|
-
const r =
|
|
7284
|
+
const resolvedRoot = path23.resolve(root);
|
|
7285
|
+
const resolvedTarget = path23.resolve(resolvedRoot, rel);
|
|
7286
|
+
const r = path23.relative(resolvedRoot, resolvedTarget);
|
|
7250
7287
|
if (r === "") return true;
|
|
7251
7288
|
if (r.startsWith("..")) return false;
|
|
7252
|
-
if (
|
|
7289
|
+
if (path23.isAbsolute(r)) return false;
|
|
7253
7290
|
return true;
|
|
7254
7291
|
}
|
|
7255
7292
|
function readMarkdownContent(root, file, fromRef, toRef) {
|
|
@@ -7274,10 +7311,10 @@ function readMarkdownContent(root, file, fromRef, toRef) {
|
|
|
7274
7311
|
if (file.status !== "deleted" && isMarkdownPath(file.newPath) && isInsideRoot(root, file.newPath)) {
|
|
7275
7312
|
if (toRef === "working") {
|
|
7276
7313
|
try {
|
|
7277
|
-
const absPath =
|
|
7278
|
-
const realRoot2 = fs28.realpathSync(
|
|
7314
|
+
const absPath = path23.join(root, file.newPath);
|
|
7315
|
+
const realRoot2 = fs28.realpathSync(path23.resolve(root));
|
|
7279
7316
|
const realPath = fs28.realpathSync(absPath);
|
|
7280
|
-
const sep =
|
|
7317
|
+
const sep = path23.sep;
|
|
7281
7318
|
if (realPath === realRoot2 || realPath.startsWith(realRoot2 + sep)) {
|
|
7282
7319
|
result.after = fs28.readFileSync(absPath, "utf-8");
|
|
7283
7320
|
}
|
|
@@ -7307,7 +7344,7 @@ function isBinaryContent(buffer) {
|
|
|
7307
7344
|
return false;
|
|
7308
7345
|
}
|
|
7309
7346
|
function synthesizeUntrackedDiff(root, relPath) {
|
|
7310
|
-
const absPath =
|
|
7347
|
+
const absPath = path23.join(root, relPath);
|
|
7311
7348
|
let buffer;
|
|
7312
7349
|
try {
|
|
7313
7350
|
buffer = fs28.readFileSync(absPath);
|
|
@@ -7398,7 +7435,7 @@ function attachCoverage(root, files) {
|
|
|
7398
7435
|
f.coverageMtimeMs = lcovMtimeMs;
|
|
7399
7436
|
let srcMtimeMs = null;
|
|
7400
7437
|
try {
|
|
7401
|
-
srcMtimeMs = fs28.statSync(
|
|
7438
|
+
srcMtimeMs = fs28.statSync(path23.join(root, f.path)).mtimeMs;
|
|
7402
7439
|
} catch {
|
|
7403
7440
|
srcMtimeMs = null;
|
|
7404
7441
|
}
|
|
@@ -7466,7 +7503,7 @@ function computeRangeDiff(opts) {
|
|
|
7466
7503
|
|
|
7467
7504
|
// src/core/repo-spec.ts
|
|
7468
7505
|
import fs29 from "fs";
|
|
7469
|
-
import
|
|
7506
|
+
import path24 from "path";
|
|
7470
7507
|
import os8 from "os";
|
|
7471
7508
|
import crypto2 from "crypto";
|
|
7472
7509
|
function scopeHashFor(keyPaths) {
|
|
@@ -7474,21 +7511,21 @@ function scopeHashFor(keyPaths) {
|
|
|
7474
7511
|
return crypto2.createHash("sha1").update(key).digest("hex").slice(0, 12);
|
|
7475
7512
|
}
|
|
7476
7513
|
function stableDiffPath(keyPaths) {
|
|
7477
|
-
const dir =
|
|
7514
|
+
const dir = path24.join(os8.homedir(), ".work", "diffs");
|
|
7478
7515
|
fs29.mkdirSync(dir, { recursive: true });
|
|
7479
|
-
return
|
|
7516
|
+
return path24.join(dir, scopeHashFor(keyPaths));
|
|
7480
7517
|
}
|
|
7481
7518
|
|
|
7482
7519
|
// src/core/diff-scope.ts
|
|
7483
7520
|
import fs30 from "fs";
|
|
7484
|
-
import
|
|
7521
|
+
import path25 from "path";
|
|
7485
7522
|
import chalk18 from "chalk";
|
|
7486
7523
|
function normPath(p) {
|
|
7487
|
-
return
|
|
7524
|
+
return path25.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
7488
7525
|
}
|
|
7489
7526
|
function realNorm(p) {
|
|
7490
7527
|
try {
|
|
7491
|
-
return normPath(fs30.realpathSync(p));
|
|
7528
|
+
return normPath(fs30.realpathSync.native(p));
|
|
7492
7529
|
} catch {
|
|
7493
7530
|
return normPath(p);
|
|
7494
7531
|
}
|
|
@@ -7508,29 +7545,29 @@ function resolveScope(cwd) {
|
|
|
7508
7545
|
return {
|
|
7509
7546
|
isGroup: true,
|
|
7510
7547
|
session: s,
|
|
7511
|
-
repos: s.paths.map((rp) => ({ name:
|
|
7512
|
-
activeRepoName:
|
|
7548
|
+
repos: s.paths.map((rp) => ({ name: path25.basename(rp), root: rp })),
|
|
7549
|
+
activeRepoName: path25.basename(p)
|
|
7513
7550
|
};
|
|
7514
7551
|
}
|
|
7515
7552
|
return {
|
|
7516
7553
|
isGroup: false,
|
|
7517
7554
|
session: s,
|
|
7518
|
-
repos: [{ name:
|
|
7519
|
-
activeRepoName:
|
|
7555
|
+
repos: [{ name: path25.basename(p), root: p }],
|
|
7556
|
+
activeRepoName: path25.basename(p)
|
|
7520
7557
|
};
|
|
7521
7558
|
}
|
|
7522
7559
|
}
|
|
7523
7560
|
}
|
|
7524
7561
|
for (const s of sessions) {
|
|
7525
7562
|
if (!s.isGroup || s.paths.length === 0) continue;
|
|
7526
|
-
const parents = s.paths.map((p) => normPath(
|
|
7563
|
+
const parents = s.paths.map((p) => normPath(path25.dirname(p)));
|
|
7527
7564
|
const groupRoot = parents[0];
|
|
7528
7565
|
if (!parents.every((par) => par === groupRoot)) continue;
|
|
7529
7566
|
if (normCwd === groupRoot || normCwd.startsWith(groupRoot + "/")) {
|
|
7530
7567
|
return {
|
|
7531
7568
|
isGroup: true,
|
|
7532
7569
|
session: s,
|
|
7533
|
-
repos: s.paths.map((rp) => ({ name:
|
|
7570
|
+
repos: s.paths.map((rp) => ({ name: path25.basename(rp), root: rp })),
|
|
7534
7571
|
activeRepoName: null
|
|
7535
7572
|
};
|
|
7536
7573
|
}
|
|
@@ -7539,8 +7576,8 @@ function resolveScope(cwd) {
|
|
|
7539
7576
|
return {
|
|
7540
7577
|
isGroup: false,
|
|
7541
7578
|
session: null,
|
|
7542
|
-
repos: [{ name:
|
|
7543
|
-
activeRepoName:
|
|
7579
|
+
repos: [{ name: path25.basename(toplevel), root: toplevel }],
|
|
7580
|
+
activeRepoName: path25.basename(toplevel)
|
|
7544
7581
|
};
|
|
7545
7582
|
}
|
|
7546
7583
|
function findAnyParentBranch(cwd) {
|
|
@@ -7651,7 +7688,7 @@ function createCommentStore() {
|
|
|
7651
7688
|
}
|
|
7652
7689
|
const parent = findParent2(input2.parentId);
|
|
7653
7690
|
const side = input2.side ?? parent?.side ?? "general";
|
|
7654
|
-
if (side !== "left" && side !== "right" && side !== "general") {
|
|
7691
|
+
if (side !== "left" && side !== "right" && side !== "general" && side !== "file") {
|
|
7655
7692
|
throw new Error("invalid side");
|
|
7656
7693
|
}
|
|
7657
7694
|
const c = {
|
|
@@ -7676,6 +7713,14 @@ function createCommentStore() {
|
|
|
7676
7713
|
comments.splice(idx, 1);
|
|
7677
7714
|
return true;
|
|
7678
7715
|
},
|
|
7716
|
+
setResolved(id, resolved) {
|
|
7717
|
+
const c = comments.find((x) => x.id === id);
|
|
7718
|
+
if (!c) return null;
|
|
7719
|
+
const next = resolved || void 0;
|
|
7720
|
+
if (c.resolved === next) return null;
|
|
7721
|
+
c.resolved = next;
|
|
7722
|
+
return c;
|
|
7723
|
+
},
|
|
7679
7724
|
submit(summary) {
|
|
7680
7725
|
const drafts = comments.filter((c) => c.status === "draft").sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
7681
7726
|
let summaryComment = null;
|
|
@@ -7716,7 +7761,7 @@ import { streamSSE } from "hono/streaming";
|
|
|
7716
7761
|
|
|
7717
7762
|
// src/core/file-context.ts
|
|
7718
7763
|
import fs31 from "fs";
|
|
7719
|
-
import
|
|
7764
|
+
import path26 from "path";
|
|
7720
7765
|
import spawn10 from "cross-spawn";
|
|
7721
7766
|
function readContextLines(opts) {
|
|
7722
7767
|
const { root, relPath, ref } = opts;
|
|
@@ -7738,10 +7783,10 @@ function readContextLines(opts) {
|
|
|
7738
7783
|
}
|
|
7739
7784
|
function readWorkingTree(root, relPath) {
|
|
7740
7785
|
try {
|
|
7741
|
-
const absPath =
|
|
7742
|
-
const realRoot2 = fs31.realpathSync(
|
|
7786
|
+
const absPath = path26.join(root, relPath);
|
|
7787
|
+
const realRoot2 = fs31.realpathSync(path26.resolve(root));
|
|
7743
7788
|
const realPath = fs31.realpathSync(absPath);
|
|
7744
|
-
const sep =
|
|
7789
|
+
const sep = path26.sep;
|
|
7745
7790
|
if (realPath !== realRoot2 && !realPath.startsWith(realRoot2 + sep)) {
|
|
7746
7791
|
return null;
|
|
7747
7792
|
}
|
|
@@ -7763,7 +7808,7 @@ function readAtRef(root, ref, relPath) {
|
|
|
7763
7808
|
|
|
7764
7809
|
// src/core/fs-watcher.ts
|
|
7765
7810
|
import fs32 from "fs";
|
|
7766
|
-
import
|
|
7811
|
+
import path27 from "path";
|
|
7767
7812
|
import chalk19 from "chalk";
|
|
7768
7813
|
import chokidar from "chokidar";
|
|
7769
7814
|
var IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
@@ -7789,7 +7834,7 @@ var IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
|
7789
7834
|
]);
|
|
7790
7835
|
function isIgnoredWatchPath(roots, filePath) {
|
|
7791
7836
|
for (const root of roots) {
|
|
7792
|
-
const rel =
|
|
7837
|
+
const rel = path27.relative(root, filePath).replace(/\\/g, "/");
|
|
7793
7838
|
if (rel === "" || rel.startsWith("../")) continue;
|
|
7794
7839
|
if (rel.split("/").some((seg) => IGNORED_DIRS.has(seg))) return true;
|
|
7795
7840
|
}
|
|
@@ -7814,7 +7859,7 @@ function createFsWatcher(opts) {
|
|
|
7814
7859
|
if (SUPPORTS_RECURSIVE_WATCH) {
|
|
7815
7860
|
const watchers = opts.roots.map((root) => {
|
|
7816
7861
|
const w = fs32.watch(root, { recursive: true }, (_event, filename) => {
|
|
7817
|
-
if (filename && isIgnoredWatchPath([root],
|
|
7862
|
+
if (filename && isIgnoredWatchPath([root], path27.join(root, filename.toString()))) {
|
|
7818
7863
|
return;
|
|
7819
7864
|
}
|
|
7820
7865
|
fire();
|
|
@@ -7853,29 +7898,29 @@ function createFsWatcher(opts) {
|
|
|
7853
7898
|
|
|
7854
7899
|
// src/core/web-static.ts
|
|
7855
7900
|
import fs33 from "fs";
|
|
7856
|
-
import
|
|
7901
|
+
import path28 from "path";
|
|
7857
7902
|
import { fileURLToPath } from "url";
|
|
7858
7903
|
function resolveWebRoot() {
|
|
7859
|
-
const entryDir =
|
|
7860
|
-
const moduleDir =
|
|
7904
|
+
const entryDir = path28.dirname(process.argv[1] ?? "");
|
|
7905
|
+
const moduleDir = path28.dirname(fileURLToPath(import.meta.url));
|
|
7861
7906
|
const candidates = [
|
|
7862
|
-
|
|
7907
|
+
path28.join(entryDir, "web"),
|
|
7863
7908
|
// bundled: this module is inlined into dist/<bin>.js, so dist/web is a
|
|
7864
7909
|
// sibling of the bundle. Works even when argv[1] is an npm bin symlink
|
|
7865
7910
|
// (which is not realpath'd, so the entryDir candidate above misses).
|
|
7866
|
-
|
|
7911
|
+
path28.join(moduleDir, "web"),
|
|
7867
7912
|
// dev/tsx fallback: walk up from src/core to repo root then into dist/web.
|
|
7868
|
-
|
|
7913
|
+
path28.resolve(moduleDir, "../../dist/web")
|
|
7869
7914
|
];
|
|
7870
7915
|
for (const c of candidates) {
|
|
7871
|
-
if (fs33.existsSync(
|
|
7916
|
+
if (fs33.existsSync(path28.join(c, "index.html"))) return c;
|
|
7872
7917
|
}
|
|
7873
7918
|
return null;
|
|
7874
7919
|
}
|
|
7875
7920
|
|
|
7876
7921
|
// src/core/spa-handler.ts
|
|
7877
7922
|
import fs34 from "fs";
|
|
7878
|
-
import
|
|
7923
|
+
import path29 from "path";
|
|
7879
7924
|
var MIME = {
|
|
7880
7925
|
".html": "text/html; charset=utf-8",
|
|
7881
7926
|
".js": "application/javascript; charset=utf-8",
|
|
@@ -7889,9 +7934,9 @@ var MIME = {
|
|
|
7889
7934
|
function readFile(root, relPath) {
|
|
7890
7935
|
const clean = relPath.split("?")[0];
|
|
7891
7936
|
const requested = clean === "/" ? "/index.html" : clean;
|
|
7892
|
-
const filePath =
|
|
7893
|
-
const norm =
|
|
7894
|
-
if (!norm.startsWith(
|
|
7937
|
+
const filePath = path29.join(root, requested);
|
|
7938
|
+
const norm = path29.normalize(filePath);
|
|
7939
|
+
if (!norm.startsWith(path29.normalize(root))) return null;
|
|
7895
7940
|
let stat;
|
|
7896
7941
|
try {
|
|
7897
7942
|
stat = fs34.statSync(norm);
|
|
@@ -7899,7 +7944,7 @@ function readFile(root, relPath) {
|
|
|
7899
7944
|
return null;
|
|
7900
7945
|
}
|
|
7901
7946
|
if (!stat.isFile()) return null;
|
|
7902
|
-
const ext =
|
|
7947
|
+
const ext = path29.extname(norm).toLowerCase();
|
|
7903
7948
|
return { body: fs34.readFileSync(norm), ext };
|
|
7904
7949
|
}
|
|
7905
7950
|
function serveSpa(c, webRoot) {
|
|
@@ -8064,7 +8109,7 @@ var commentInputSchema = z.object({
|
|
|
8064
8109
|
repo: z.string().optional(),
|
|
8065
8110
|
file: z.string().optional(),
|
|
8066
8111
|
line: z.number().int().optional(),
|
|
8067
|
-
side: z.enum(["left", "right", "general"]).optional(),
|
|
8112
|
+
side: z.enum(["left", "right", "general", "file"]).optional(),
|
|
8068
8113
|
body: z.string().min(1),
|
|
8069
8114
|
status: z.enum(["published", "draft"]).optional(),
|
|
8070
8115
|
lineContent: z.string().optional(),
|
|
@@ -8074,6 +8119,9 @@ var commentInputSchema = z.object({
|
|
|
8074
8119
|
var submitReviewSchema = z.object({
|
|
8075
8120
|
summary: z.string().optional()
|
|
8076
8121
|
});
|
|
8122
|
+
var resolveSchema = z.object({
|
|
8123
|
+
resolved: z.boolean()
|
|
8124
|
+
});
|
|
8077
8125
|
|
|
8078
8126
|
// src/core/comment-server.ts
|
|
8079
8127
|
async function startCommentServer(opts) {
|
|
@@ -8110,6 +8158,18 @@ async function startCommentServer(opts) {
|
|
|
8110
8158
|
if (removed && opts.onCommentDeleted) opts.onCommentDeleted(id);
|
|
8111
8159
|
return c.json({ comments: store.snapshot() });
|
|
8112
8160
|
});
|
|
8161
|
+
routes.post(
|
|
8162
|
+
"/api/comments/:id/resolve",
|
|
8163
|
+
zValidator("json", resolveSchema),
|
|
8164
|
+
(c) => {
|
|
8165
|
+
const updated = store.setResolved(
|
|
8166
|
+
c.req.param("id"),
|
|
8167
|
+
c.req.valid("json").resolved
|
|
8168
|
+
);
|
|
8169
|
+
if (updated) api.broadcast("comments-changed", { id: updated.id });
|
|
8170
|
+
return c.json({ comments: store.snapshot() });
|
|
8171
|
+
}
|
|
8172
|
+
);
|
|
8113
8173
|
routes.post(
|
|
8114
8174
|
"/api/submit-review",
|
|
8115
8175
|
zValidator("json", submitReviewSchema),
|
|
@@ -8164,7 +8224,7 @@ async function startCommentServer(opts) {
|
|
|
8164
8224
|
}
|
|
8165
8225
|
function formatSingleComment(c) {
|
|
8166
8226
|
const bodyLines = c.body.split("\n").map((l) => `> ${l}`).join("\n");
|
|
8167
|
-
const header = c.side === "general" ? `**General review comment**` : `**${c.repo}/${c.file}** : line ${c.line} (${c.side})`;
|
|
8227
|
+
const header = c.side === "general" ? `**General review comment**` : c.side === "file" ? `**${c.repo}/${c.file}** : whole file` : `**${c.repo}/${c.file}** : line ${c.line} (${c.side})`;
|
|
8168
8228
|
const meta = [];
|
|
8169
8229
|
if (c.author === "claude") meta.push("author: claude");
|
|
8170
8230
|
if (c.parentId) meta.push(`reply-to: ${c.parentId}`);
|
|
@@ -8194,7 +8254,7 @@ function diffReviewSnapshot(snapshot, seen) {
|
|
|
8194
8254
|
|
|
8195
8255
|
// src/core/static-renderer.ts
|
|
8196
8256
|
import fs35 from "fs";
|
|
8197
|
-
import
|
|
8257
|
+
import path30 from "path";
|
|
8198
8258
|
function buildDiff(specs, resolvedBase) {
|
|
8199
8259
|
return {
|
|
8200
8260
|
repos: specs.map((r) => ({
|
|
@@ -8210,7 +8270,7 @@ function renderStatic(opts) {
|
|
|
8210
8270
|
if (!webRoot) {
|
|
8211
8271
|
throw new Error("Could not find dist/web/. Run `npm run build` first.");
|
|
8212
8272
|
}
|
|
8213
|
-
const shellPath =
|
|
8273
|
+
const shellPath = path30.join(webRoot, "index.html");
|
|
8214
8274
|
let shell = fs35.readFileSync(shellPath, "utf-8");
|
|
8215
8275
|
const uncommitted = buildDiff(opts.uncommitted, "HEAD");
|
|
8216
8276
|
const branch = opts.branch ? buildDiff(opts.branch.specs, opts.branch.resolvedBase) : void 0;
|
|
@@ -8260,8 +8320,8 @@ function escapeForScriptTag(json) {
|
|
|
8260
8320
|
}
|
|
8261
8321
|
function readAsset(webRoot, urlPath) {
|
|
8262
8322
|
const clean = urlPath.split("?")[0].replace(/^\//, "");
|
|
8263
|
-
const full =
|
|
8264
|
-
if (!
|
|
8323
|
+
const full = path30.join(webRoot, clean);
|
|
8324
|
+
if (!path30.normalize(full).startsWith(path30.normalize(webRoot))) return null;
|
|
8265
8325
|
try {
|
|
8266
8326
|
return fs35.readFileSync(full, "utf-8");
|
|
8267
8327
|
} catch {
|
|
@@ -8304,7 +8364,7 @@ async function runStop(repoSpecs) {
|
|
|
8304
8364
|
}
|
|
8305
8365
|
}
|
|
8306
8366
|
function webUrlFilePath() {
|
|
8307
|
-
return
|
|
8367
|
+
return path31.join(os9.homedir(), ".work", "web.url");
|
|
8308
8368
|
}
|
|
8309
8369
|
function resolveWorkBinPath(selfArgv1) {
|
|
8310
8370
|
let real = selfArgv1;
|
|
@@ -8313,7 +8373,7 @@ function resolveWorkBinPath(selfArgv1) {
|
|
|
8313
8373
|
} catch {
|
|
8314
8374
|
}
|
|
8315
8375
|
if (real.endsWith("wd-bin.js")) {
|
|
8316
|
-
return
|
|
8376
|
+
return path31.join(path31.dirname(real), "bin.js");
|
|
8317
8377
|
}
|
|
8318
8378
|
return real;
|
|
8319
8379
|
}
|
|
@@ -8325,12 +8385,32 @@ function readWebUrl() {
|
|
|
8325
8385
|
return null;
|
|
8326
8386
|
}
|
|
8327
8387
|
}
|
|
8388
|
+
async function webServerResponds(url, timeoutMs = 1500) {
|
|
8389
|
+
try {
|
|
8390
|
+
const ctrl = new AbortController();
|
|
8391
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
8392
|
+
try {
|
|
8393
|
+
const res = await fetch(`${url}api/context`, { signal: ctrl.signal });
|
|
8394
|
+
return res.ok;
|
|
8395
|
+
} finally {
|
|
8396
|
+
clearTimeout(timer);
|
|
8397
|
+
}
|
|
8398
|
+
} catch {
|
|
8399
|
+
return false;
|
|
8400
|
+
}
|
|
8401
|
+
}
|
|
8328
8402
|
async function ensureWorkWebRunning() {
|
|
8329
8403
|
const existing = readWebUrl();
|
|
8330
|
-
if (existing)
|
|
8404
|
+
if (existing) {
|
|
8405
|
+
if (await webServerResponds(existing)) return existing;
|
|
8406
|
+
try {
|
|
8407
|
+
fs36.unlinkSync(webUrlFilePath());
|
|
8408
|
+
} catch {
|
|
8409
|
+
}
|
|
8410
|
+
}
|
|
8331
8411
|
const workBin = resolveWorkBinPath(process.argv[1]);
|
|
8332
8412
|
const out = fs36.openSync(
|
|
8333
|
-
|
|
8413
|
+
path31.join(os9.homedir(), ".work", "web-autostart.log"),
|
|
8334
8414
|
"a"
|
|
8335
8415
|
);
|
|
8336
8416
|
const child = childSpawn(
|
|
@@ -8672,19 +8752,19 @@ var diffCommand = {
|
|
|
8672
8752
|
// src/commands/web.ts
|
|
8673
8753
|
import fs41 from "fs";
|
|
8674
8754
|
import os13 from "os";
|
|
8675
|
-
import
|
|
8755
|
+
import path41 from "path";
|
|
8676
8756
|
import chalk23 from "chalk";
|
|
8677
8757
|
|
|
8678
8758
|
// src/core/web-server.ts
|
|
8679
8759
|
import fs40 from "fs";
|
|
8680
8760
|
import os12 from "os";
|
|
8681
|
-
import
|
|
8761
|
+
import path40 from "path";
|
|
8682
8762
|
import chalk22 from "chalk";
|
|
8683
8763
|
import { Hono as Hono3 } from "hono";
|
|
8684
8764
|
import { streamSSE as streamSSE3 } from "hono/streaming";
|
|
8685
8765
|
|
|
8686
8766
|
// src/core/web-state.ts
|
|
8687
|
-
import
|
|
8767
|
+
import path32 from "path";
|
|
8688
8768
|
import crypto4 from "crypto";
|
|
8689
8769
|
import chokidar2 from "chokidar";
|
|
8690
8770
|
function sessionIdFor(s) {
|
|
@@ -8705,7 +8785,7 @@ function subscribeSession(sessionId, onChange) {
|
|
|
8705
8785
|
const watcher = chokidar2.watch(roots, {
|
|
8706
8786
|
ignored: (filePath) => {
|
|
8707
8787
|
for (const r of roots) {
|
|
8708
|
-
const rel =
|
|
8788
|
+
const rel = path32.relative(r, filePath).replace(/\\/g, "/");
|
|
8709
8789
|
if (rel === ".git" || rel.startsWith(".git/")) return true;
|
|
8710
8790
|
}
|
|
8711
8791
|
return false;
|
|
@@ -8820,16 +8900,16 @@ function disposeAllPtys() {
|
|
|
8820
8900
|
|
|
8821
8901
|
// src/core/comment-file-store.ts
|
|
8822
8902
|
import fs37 from "fs";
|
|
8823
|
-
import
|
|
8903
|
+
import path33 from "path";
|
|
8824
8904
|
import os10 from "os";
|
|
8825
8905
|
function commentsDir() {
|
|
8826
|
-
return
|
|
8906
|
+
return path33.join(os10.homedir(), ".work", "comments");
|
|
8827
8907
|
}
|
|
8828
8908
|
function ensureDir() {
|
|
8829
8909
|
fs37.mkdirSync(commentsDir(), { recursive: true });
|
|
8830
8910
|
}
|
|
8831
8911
|
function commentsFileFor(sessionId) {
|
|
8832
|
-
return
|
|
8912
|
+
return path33.join(commentsDir(), `${sessionId}.json`);
|
|
8833
8913
|
}
|
|
8834
8914
|
function pathFor(sessionId) {
|
|
8835
8915
|
return commentsFileFor(sessionId);
|
|
@@ -8884,6 +8964,12 @@ function getCommentFileStore(sessionId) {
|
|
|
8884
8964
|
return { value: r, persisted: r };
|
|
8885
8965
|
});
|
|
8886
8966
|
},
|
|
8967
|
+
setResolved(id, resolved) {
|
|
8968
|
+
return lockedMutate(() => {
|
|
8969
|
+
const c = inner.setResolved(id, resolved);
|
|
8970
|
+
return { value: c, persisted: c !== null };
|
|
8971
|
+
});
|
|
8972
|
+
},
|
|
8887
8973
|
submit(summary) {
|
|
8888
8974
|
return lockedMutate(() => {
|
|
8889
8975
|
const result = inner.submit(summary);
|
|
@@ -8909,11 +8995,11 @@ function clearCommentStoreCache() {
|
|
|
8909
8995
|
|
|
8910
8996
|
// src/core/pending-delivery.ts
|
|
8911
8997
|
import fs38 from "fs";
|
|
8912
|
-
import
|
|
8998
|
+
import path34 from "path";
|
|
8913
8999
|
function pathFor2(sessionId) {
|
|
8914
9000
|
return {
|
|
8915
9001
|
comments: commentsFileFor(sessionId),
|
|
8916
|
-
delivered:
|
|
9002
|
+
delivered: path34.join(commentsDir(), `${sessionId}.delivered.json`)
|
|
8917
9003
|
};
|
|
8918
9004
|
}
|
|
8919
9005
|
function readJson(filePath, fallback) {
|
|
@@ -8924,13 +9010,13 @@ function readJson(filePath, fallback) {
|
|
|
8924
9010
|
}
|
|
8925
9011
|
}
|
|
8926
9012
|
function writeAtomic2(filePath, content) {
|
|
8927
|
-
fs38.mkdirSync(
|
|
9013
|
+
fs38.mkdirSync(path34.dirname(filePath), { recursive: true });
|
|
8928
9014
|
const tmp = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
8929
9015
|
fs38.writeFileSync(tmp, content, "utf-8");
|
|
8930
9016
|
fs38.renameSync(tmp, filePath);
|
|
8931
9017
|
}
|
|
8932
9018
|
function normalize(p) {
|
|
8933
|
-
return
|
|
9019
|
+
return path34.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
8934
9020
|
}
|
|
8935
9021
|
function findSessionForCwd(cwd) {
|
|
8936
9022
|
const norm = normalize(cwd);
|
|
@@ -8961,7 +9047,7 @@ function readPendingForSession(sessionId) {
|
|
|
8961
9047
|
return comments.filter(isPendingFor(delivered));
|
|
8962
9048
|
}
|
|
8963
9049
|
function scopeStoreIdsForPaths(paths) {
|
|
8964
|
-
const resolved = paths.map((p) =>
|
|
9050
|
+
const resolved = paths.map((p) => path34.resolve(p));
|
|
8965
9051
|
const ids = /* @__PURE__ */ new Set();
|
|
8966
9052
|
ids.add(`scope-${scopeHashFor(resolved)}`);
|
|
8967
9053
|
for (const p of resolved) ids.add(`scope-${scopeHashFor([p])}`);
|
|
@@ -9117,6 +9203,21 @@ function mountSessionCommentRoutes(app, opts) {
|
|
|
9117
9203
|
if (removed) opts.broadcast("comments-changed", { sessionId: id, deleted: cid });
|
|
9118
9204
|
return c.json({ comments: store.snapshot() });
|
|
9119
9205
|
});
|
|
9206
|
+
app.post(
|
|
9207
|
+
"/api/sessions/:id/comments/:cid/resolve",
|
|
9208
|
+
zValidator2("json", resolveSchema),
|
|
9209
|
+
(c) => {
|
|
9210
|
+
const id = c.req.param("id");
|
|
9211
|
+
if (!requireSession(id)) return c.json({ error: "unknown session" }, 404);
|
|
9212
|
+
const store = getCommentFileStore(id);
|
|
9213
|
+
const updated = store.setResolved(
|
|
9214
|
+
c.req.param("cid"),
|
|
9215
|
+
c.req.valid("json").resolved
|
|
9216
|
+
);
|
|
9217
|
+
if (updated) opts.broadcast("comments-changed", { sessionId: id, id: updated.id });
|
|
9218
|
+
return c.json({ comments: store.snapshot() });
|
|
9219
|
+
}
|
|
9220
|
+
);
|
|
9120
9221
|
app.post(
|
|
9121
9222
|
"/api/sessions/:id/submit-review",
|
|
9122
9223
|
zValidator2("json", submitReviewSchema),
|
|
@@ -9284,7 +9385,7 @@ function mountPanesRoutes(app, opts) {
|
|
|
9284
9385
|
}
|
|
9285
9386
|
|
|
9286
9387
|
// src/core/worktree-routes.ts
|
|
9287
|
-
import
|
|
9388
|
+
import path35 from "path";
|
|
9288
9389
|
import { spawn as spawn11 } from "child_process";
|
|
9289
9390
|
import { zValidator as zValidator4 } from "@hono/zod-validator";
|
|
9290
9391
|
import { z as z3 } from "zod";
|
|
@@ -9408,7 +9509,7 @@ function mountWorktreeRoutes(app, opts) {
|
|
|
9408
9509
|
const id = c.req.param("id");
|
|
9409
9510
|
const session = findSession2(id);
|
|
9410
9511
|
if (!session) return c.json({ error: "unknown session" }, 404);
|
|
9411
|
-
const target = session.isGroup ?
|
|
9512
|
+
const target = session.isGroup ? path35.dirname(session.paths[0]) : session.paths[0];
|
|
9412
9513
|
try {
|
|
9413
9514
|
const cmd = process.platform === "win32" ? "code.cmd" : "code";
|
|
9414
9515
|
const child = spawn11(cmd, [target], {
|
|
@@ -9428,18 +9529,18 @@ function mountWorktreeRoutes(app, opts) {
|
|
|
9428
9529
|
import { zValidator as zValidator5 } from "@hono/zod-validator";
|
|
9429
9530
|
import { z as z4 } from "zod";
|
|
9430
9531
|
import { EventEmitter } from "events";
|
|
9431
|
-
import
|
|
9432
|
-
import
|
|
9532
|
+
import path39 from "path";
|
|
9533
|
+
import spawn14 from "cross-spawn";
|
|
9433
9534
|
|
|
9434
9535
|
// src/core/checkpoint.ts
|
|
9435
9536
|
import fs39 from "fs";
|
|
9436
9537
|
import os11 from "os";
|
|
9437
|
-
import
|
|
9538
|
+
import path36 from "path";
|
|
9438
9539
|
import spawn12 from "cross-spawn";
|
|
9439
9540
|
function manifestPath(scopeHash) {
|
|
9440
|
-
const dir =
|
|
9541
|
+
const dir = path36.join(os11.homedir(), ".work", "diffs");
|
|
9441
9542
|
fs39.mkdirSync(dir, { recursive: true });
|
|
9442
|
-
return
|
|
9543
|
+
return path36.join(dir, `${scopeHash}.checkpoints.json`);
|
|
9443
9544
|
}
|
|
9444
9545
|
function emptyManifest(scopeHash) {
|
|
9445
9546
|
return { version: 1, scopeHash, entries: [] };
|
|
@@ -9558,6 +9659,17 @@ async function takeCheckpoint(scopeHash, repos, opts = {}) {
|
|
|
9558
9659
|
return entry;
|
|
9559
9660
|
});
|
|
9560
9661
|
}
|
|
9662
|
+
async function setCheckpointLabel(scopeHash, id, label2) {
|
|
9663
|
+
const file = manifestPath(scopeHash);
|
|
9664
|
+
ensureFile(file, JSON.stringify(emptyManifest(scopeHash), null, 2));
|
|
9665
|
+
await withFileLock(file, () => {
|
|
9666
|
+
const manifest = loadManifest(scopeHash);
|
|
9667
|
+
const entry = manifest.entries.find((e) => e.id === id);
|
|
9668
|
+
if (!entry || entry.label === label2) return;
|
|
9669
|
+
entry.label = label2;
|
|
9670
|
+
atomicWriteFile(file, JSON.stringify(manifest, null, 2));
|
|
9671
|
+
});
|
|
9672
|
+
}
|
|
9561
9673
|
function clearCheckpoints(scopeHash, repoRoots) {
|
|
9562
9674
|
const manifest = loadManifest(scopeHash);
|
|
9563
9675
|
for (const root of repoRoots) {
|
|
@@ -9579,8 +9691,130 @@ function clearCheckpoints(scopeHash, repoRoots) {
|
|
|
9579
9691
|
}
|
|
9580
9692
|
}
|
|
9581
9693
|
|
|
9694
|
+
// src/core/checkpoint-summary.ts
|
|
9695
|
+
import spawn13 from "cross-spawn";
|
|
9696
|
+
import path37 from "path";
|
|
9697
|
+
var MAX_DIFF_CHARS = 6e3;
|
|
9698
|
+
var MAX_LABEL_CHARS = 80;
|
|
9699
|
+
function buildDelta(scopeHash, repos, id) {
|
|
9700
|
+
const manifest = loadManifest(scopeHash);
|
|
9701
|
+
const entry = manifest.entries.find((e) => e.id === id);
|
|
9702
|
+
const prev = manifest.entries.find((e) => e.id === id - 1);
|
|
9703
|
+
const all = [];
|
|
9704
|
+
for (const repo of repos) {
|
|
9705
|
+
const toRef = entry?.repos[repo.name];
|
|
9706
|
+
if (!toRef) continue;
|
|
9707
|
+
const fromRef = prev?.repos[repo.name] ?? "HEAD";
|
|
9708
|
+
try {
|
|
9709
|
+
all.push(...computeRangeDiff({ root: repo.root, fromRef, toRef }));
|
|
9710
|
+
} catch {
|
|
9711
|
+
}
|
|
9712
|
+
}
|
|
9713
|
+
let added = 0;
|
|
9714
|
+
let deleted = 0;
|
|
9715
|
+
for (const f of all) {
|
|
9716
|
+
added += f.added;
|
|
9717
|
+
deleted += f.deleted;
|
|
9718
|
+
}
|
|
9719
|
+
const parts = [];
|
|
9720
|
+
let budget = MAX_DIFF_CHARS;
|
|
9721
|
+
for (const f of all) {
|
|
9722
|
+
const head = `### ${f.status} ${f.path} (+${f.added} -${f.deleted})
|
|
9723
|
+
`;
|
|
9724
|
+
if (budget - head.length < 0) break;
|
|
9725
|
+
parts.push(head);
|
|
9726
|
+
budget -= head.length;
|
|
9727
|
+
for (const h of f.hunks) {
|
|
9728
|
+
for (const ln of h.lines) {
|
|
9729
|
+
if (ln.kind !== "add" && ln.kind !== "delete") continue;
|
|
9730
|
+
const prefix = ln.kind === "add" ? "+" : "-";
|
|
9731
|
+
const line = `${prefix}${ln.content}
|
|
9732
|
+
`;
|
|
9733
|
+
if (budget - line.length < 0) {
|
|
9734
|
+
budget = -1;
|
|
9735
|
+
break;
|
|
9736
|
+
}
|
|
9737
|
+
parts.push(line);
|
|
9738
|
+
budget -= line.length;
|
|
9739
|
+
}
|
|
9740
|
+
if (budget < 0) break;
|
|
9741
|
+
}
|
|
9742
|
+
if (budget < 0) break;
|
|
9743
|
+
}
|
|
9744
|
+
return { files: all, added, deleted, text: parts.join("") };
|
|
9745
|
+
}
|
|
9746
|
+
function heuristicLabel(files, added, deleted) {
|
|
9747
|
+
if (files.length === 0) return "no changes";
|
|
9748
|
+
if (files.length === 1) {
|
|
9749
|
+
return `${path37.basename(files[0].path)} +${added} \u2212${deleted}`;
|
|
9750
|
+
}
|
|
9751
|
+
return `${files.length} files \xB7 +${added} \u2212${deleted}`;
|
|
9752
|
+
}
|
|
9753
|
+
function runClaude(prompt, timeoutMs = 25e3) {
|
|
9754
|
+
return new Promise((resolve) => {
|
|
9755
|
+
let settled = false;
|
|
9756
|
+
const finish = (v) => {
|
|
9757
|
+
if (settled) return;
|
|
9758
|
+
settled = true;
|
|
9759
|
+
resolve(v);
|
|
9760
|
+
};
|
|
9761
|
+
let out = "";
|
|
9762
|
+
let child;
|
|
9763
|
+
try {
|
|
9764
|
+
child = spawn13("claude", ["-p"], {
|
|
9765
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
9766
|
+
windowsHide: true
|
|
9767
|
+
});
|
|
9768
|
+
} catch {
|
|
9769
|
+
finish(null);
|
|
9770
|
+
return;
|
|
9771
|
+
}
|
|
9772
|
+
const timer = setTimeout(() => {
|
|
9773
|
+
try {
|
|
9774
|
+
child.kill();
|
|
9775
|
+
} catch {
|
|
9776
|
+
}
|
|
9777
|
+
finish(null);
|
|
9778
|
+
}, timeoutMs);
|
|
9779
|
+
child.stdout?.on("data", (d) => {
|
|
9780
|
+
out += d.toString();
|
|
9781
|
+
});
|
|
9782
|
+
child.on("error", () => {
|
|
9783
|
+
clearTimeout(timer);
|
|
9784
|
+
finish(null);
|
|
9785
|
+
});
|
|
9786
|
+
child.on("close", (code) => {
|
|
9787
|
+
clearTimeout(timer);
|
|
9788
|
+
finish(code === 0 && out.trim() ? out.trim() : null);
|
|
9789
|
+
});
|
|
9790
|
+
try {
|
|
9791
|
+
child.stdin?.write(prompt);
|
|
9792
|
+
child.stdin?.end();
|
|
9793
|
+
} catch {
|
|
9794
|
+
clearTimeout(timer);
|
|
9795
|
+
finish(null);
|
|
9796
|
+
}
|
|
9797
|
+
});
|
|
9798
|
+
}
|
|
9799
|
+
function cleanLabel(raw) {
|
|
9800
|
+
const firstLine = raw.split("\n").map((l) => l.trim()).find(Boolean) ?? "";
|
|
9801
|
+
const cleaned = firstLine.replace(/^["'`]+|["'`]+$/g, "").replace(/\s+/g, " ").replace(/[.;]+$/, "").trim();
|
|
9802
|
+
return cleaned.slice(0, MAX_LABEL_CHARS);
|
|
9803
|
+
}
|
|
9804
|
+
async function summarizeCheckpoint(scopeHash, repos, id) {
|
|
9805
|
+
const { files, added, deleted, text } = buildDelta(scopeHash, repos, id);
|
|
9806
|
+
if (files.length === 0) return "no changes";
|
|
9807
|
+
const fallback = heuristicLabel(files, added, deleted);
|
|
9808
|
+
if (!text.trim()) return fallback;
|
|
9809
|
+
const prompt = "Summarise this code change in 8 words or fewer, imperative mood, no trailing punctuation. Output ONLY the summary line.\n\n" + text;
|
|
9810
|
+
const reply = await runClaude(prompt);
|
|
9811
|
+
if (!reply) return fallback;
|
|
9812
|
+
const label2 = cleanLabel(reply);
|
|
9813
|
+
return label2 || fallback;
|
|
9814
|
+
}
|
|
9815
|
+
|
|
9582
9816
|
// src/core/scope-manager.ts
|
|
9583
|
-
import
|
|
9817
|
+
import path38 from "path";
|
|
9584
9818
|
import crypto5 from "crypto";
|
|
9585
9819
|
var scopes = /* @__PURE__ */ new Map();
|
|
9586
9820
|
function hashFor(paths) {
|
|
@@ -9597,7 +9831,7 @@ var ScopePathRejectedError = class extends Error {
|
|
|
9597
9831
|
}
|
|
9598
9832
|
};
|
|
9599
9833
|
function normaliseForCompare(p) {
|
|
9600
|
-
return
|
|
9834
|
+
return path38.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
9601
9835
|
}
|
|
9602
9836
|
function rejectedPaths(normalised) {
|
|
9603
9837
|
const config = loadConfig();
|
|
@@ -9615,7 +9849,7 @@ function rejectedPaths(normalised) {
|
|
|
9615
9849
|
});
|
|
9616
9850
|
}
|
|
9617
9851
|
function registerScope(paths, label2) {
|
|
9618
|
-
const normalised = paths.map((p) =>
|
|
9852
|
+
const normalised = paths.map((p) => path38.resolve(p));
|
|
9619
9853
|
const rejected = rejectedPaths(normalised);
|
|
9620
9854
|
if (rejected.length > 0) throw new ScopePathRejectedError(rejected);
|
|
9621
9855
|
const hash = hashFor(normalised);
|
|
@@ -9629,11 +9863,16 @@ function registerScope(paths, label2) {
|
|
|
9629
9863
|
const scope = {
|
|
9630
9864
|
hash,
|
|
9631
9865
|
paths: normalised,
|
|
9632
|
-
label: label2 ??
|
|
9866
|
+
label: label2 ?? path38.basename(normalised[0]),
|
|
9633
9867
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9634
9868
|
ended: false
|
|
9635
9869
|
};
|
|
9636
|
-
scopes.set(hash, {
|
|
9870
|
+
scopes.set(hash, {
|
|
9871
|
+
scope,
|
|
9872
|
+
watcher: null,
|
|
9873
|
+
subscribers: /* @__PURE__ */ new Set(),
|
|
9874
|
+
suppressWatchUntil: 0
|
|
9875
|
+
});
|
|
9637
9876
|
return scope;
|
|
9638
9877
|
}
|
|
9639
9878
|
function markScopeEnded(hash) {
|
|
@@ -9646,6 +9885,20 @@ function markScopeEnded(hash) {
|
|
|
9646
9885
|
function getScope(hash) {
|
|
9647
9886
|
return scopes.get(hash)?.scope ?? null;
|
|
9648
9887
|
}
|
|
9888
|
+
function suppressScopeWatch(hash, ms) {
|
|
9889
|
+
const entry = scopes.get(hash);
|
|
9890
|
+
if (entry) entry.suppressWatchUntil = Date.now() + ms;
|
|
9891
|
+
}
|
|
9892
|
+
function scopeCoversCwd(paths, cwd) {
|
|
9893
|
+
const nc = normaliseForCompare(cwd);
|
|
9894
|
+
return paths.some((p) => {
|
|
9895
|
+
const np = normaliseForCompare(p);
|
|
9896
|
+
return np === nc || np.startsWith(nc + "/") || nc.startsWith(np + "/");
|
|
9897
|
+
});
|
|
9898
|
+
}
|
|
9899
|
+
function scopesForCwd(cwd) {
|
|
9900
|
+
return Array.from(scopes.values()).map((e) => e.scope).filter((s) => scopeCoversCwd(s.paths, cwd));
|
|
9901
|
+
}
|
|
9649
9902
|
function listScopes() {
|
|
9650
9903
|
return Array.from(scopes.values()).map((e) => e.scope);
|
|
9651
9904
|
}
|
|
@@ -9666,6 +9919,7 @@ function subscribeScope(hash, cb) {
|
|
|
9666
9919
|
roots: entry.scope.paths,
|
|
9667
9920
|
debounceMs: 150,
|
|
9668
9921
|
onChange: () => {
|
|
9922
|
+
if (Date.now() < entry.suppressWatchUntil) return;
|
|
9669
9923
|
for (const sub of entry.subscribers) {
|
|
9670
9924
|
try {
|
|
9671
9925
|
sub();
|
|
@@ -9699,10 +9953,13 @@ import { streamSSE as streamSSE2 } from "hono/streaming";
|
|
|
9699
9953
|
function mountScopeRoutes(app, opts) {
|
|
9700
9954
|
const checkpointWatched = /* @__PURE__ */ new Set();
|
|
9701
9955
|
const lastStatus = /* @__PURE__ */ new Map();
|
|
9956
|
+
const snapshotTimers = /* @__PURE__ */ new Map();
|
|
9957
|
+
const CHECKPOINT_SETTLE_MS = 4e3;
|
|
9958
|
+
const CLAUDE_SESSION_MS = 5 * 6e4;
|
|
9702
9959
|
function workingTreeFingerprint(paths) {
|
|
9703
9960
|
const parts = [];
|
|
9704
9961
|
for (const p of paths) {
|
|
9705
|
-
const r =
|
|
9962
|
+
const r = spawn14.sync(
|
|
9706
9963
|
"git",
|
|
9707
9964
|
["status", "--porcelain", "--no-renames", "-z"],
|
|
9708
9965
|
{ cwd: p, encoding: "utf-8", windowsHide: true }
|
|
@@ -9744,18 +10001,32 @@ function mountScopeRoutes(app, opts) {
|
|
|
9744
10001
|
}
|
|
9745
10002
|
if (!checkpointWatched.has(scope.hash)) {
|
|
9746
10003
|
checkpointWatched.add(scope.hash);
|
|
9747
|
-
|
|
10004
|
+
const hash = scope.hash;
|
|
10005
|
+
const runSnapshot = () => {
|
|
10006
|
+
snapshotTimers.delete(hash);
|
|
10007
|
+
const claudeMs = scope.paths.reduce(
|
|
10008
|
+
(m, p) => Math.max(m, getClaudeActivityMs(p)),
|
|
10009
|
+
0
|
|
10010
|
+
);
|
|
10011
|
+
if (claudeActiveWithin(claudeMs, Date.now(), CLAUDE_SESSION_MS)) {
|
|
10012
|
+
return;
|
|
10013
|
+
}
|
|
9748
10014
|
try {
|
|
9749
10015
|
const fp = workingTreeFingerprint(scope.paths);
|
|
9750
|
-
if (lastStatus.get(
|
|
9751
|
-
lastStatus.set(
|
|
10016
|
+
if (lastStatus.get(hash) === fp) return;
|
|
10017
|
+
lastStatus.set(hash, fp);
|
|
9752
10018
|
} catch {
|
|
9753
10019
|
}
|
|
9754
|
-
takeCheckpoint(
|
|
10020
|
+
takeCheckpoint(hash, scopeRepos(scope.paths)).then((entry) => {
|
|
9755
10021
|
if (entry) announceCheckpoint(entry);
|
|
9756
10022
|
}).catch((err) => {
|
|
9757
10023
|
console.error("[checkpoint] auto-snapshot failed:", err);
|
|
9758
10024
|
});
|
|
10025
|
+
};
|
|
10026
|
+
subscribeScope(hash, () => {
|
|
10027
|
+
const pending = snapshotTimers.get(hash);
|
|
10028
|
+
if (pending) clearTimeout(pending);
|
|
10029
|
+
snapshotTimers.set(hash, setTimeout(runSnapshot, CHECKPOINT_SETTLE_MS));
|
|
9759
10030
|
});
|
|
9760
10031
|
}
|
|
9761
10032
|
return c.json({
|
|
@@ -9772,6 +10043,27 @@ function mountScopeRoutes(app, opts) {
|
|
|
9772
10043
|
}
|
|
9773
10044
|
);
|
|
9774
10045
|
app.get("/api/scopes", (c) => c.json({ scopes: listScopes() }));
|
|
10046
|
+
app.post(
|
|
10047
|
+
"/api/checkpoint",
|
|
10048
|
+
zValidator5("json", z4.object({ cwd: z4.string().min(1) })),
|
|
10049
|
+
async (c) => {
|
|
10050
|
+
const { cwd } = c.req.valid("json");
|
|
10051
|
+
const matched = scopesForCwd(cwd);
|
|
10052
|
+
let snapshotted = 0;
|
|
10053
|
+
for (const s of matched) {
|
|
10054
|
+
const entry = await takeCheckpoint(s.hash, scopeRepos(s.paths)).catch(
|
|
10055
|
+
() => null
|
|
10056
|
+
);
|
|
10057
|
+
if (entry) {
|
|
10058
|
+
const payload = { scopeHash: s.hash, id: entry.id };
|
|
10059
|
+
opts.broadcast("checkpoints-changed", payload);
|
|
10060
|
+
scopeBus.emit("checkpoints-changed", payload);
|
|
10061
|
+
snapshotted++;
|
|
10062
|
+
}
|
|
10063
|
+
}
|
|
10064
|
+
return c.json({ ok: true, scopes: matched.length, snapshotted });
|
|
10065
|
+
}
|
|
10066
|
+
);
|
|
9775
10067
|
app.delete("/api/scopes/:hash", (c) => {
|
|
9776
10068
|
const hash = c.req.param("hash");
|
|
9777
10069
|
const scope = getScope(hash);
|
|
@@ -9779,6 +10071,11 @@ function mountScopeRoutes(app, opts) {
|
|
|
9779
10071
|
const ok = removeScope(hash);
|
|
9780
10072
|
checkpointWatched.delete(hash);
|
|
9781
10073
|
lastStatus.delete(hash);
|
|
10074
|
+
const pendingTimer = snapshotTimers.get(hash);
|
|
10075
|
+
if (pendingTimer) {
|
|
10076
|
+
clearTimeout(pendingTimer);
|
|
10077
|
+
snapshotTimers.delete(hash);
|
|
10078
|
+
}
|
|
9782
10079
|
if (repoPaths.length > 0) clearCheckpoints(hash, repoPaths);
|
|
9783
10080
|
if (ok) opts.broadcast("scopes-changed", { hash });
|
|
9784
10081
|
return c.json({ ok });
|
|
@@ -9826,11 +10123,12 @@ function mountScopeRoutes(app, opts) {
|
|
|
9826
10123
|
const fromSha = fromEntry.repos[p] ?? "HEAD";
|
|
9827
10124
|
const toSha = toEntry === void 0 ? "working" : toEntry.repos[p] ?? "HEAD";
|
|
9828
10125
|
return {
|
|
9829
|
-
name:
|
|
10126
|
+
name: path39.basename(p),
|
|
9830
10127
|
root: p,
|
|
9831
10128
|
files: computeRangeDiff({ root: p, fromRef: fromSha, toRef: toSha })
|
|
9832
10129
|
};
|
|
9833
10130
|
});
|
|
10131
|
+
suppressScopeWatch(scope.hash, 800);
|
|
9834
10132
|
return c.json({
|
|
9835
10133
|
scopeHash: scope.hash,
|
|
9836
10134
|
base: "uncommitted",
|
|
@@ -9844,7 +10142,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
9844
10142
|
(p) => resolveRepoDiff(p, base, sessionBaseForPath(p))
|
|
9845
10143
|
);
|
|
9846
10144
|
const repos = scope.paths.map((p, i) => ({
|
|
9847
|
-
name:
|
|
10145
|
+
name: path39.basename(p),
|
|
9848
10146
|
root: p,
|
|
9849
10147
|
resolvedBase: resolved[i].resolvedBase,
|
|
9850
10148
|
files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
|
|
@@ -9852,6 +10150,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
9852
10150
|
const resolvedBase = resolved[0]?.resolvedBase ?? "HEAD";
|
|
9853
10151
|
const head = git(["rev-parse", "--abbrev-ref", "HEAD"], scope.paths[0]);
|
|
9854
10152
|
const headBranch = head.exitCode === 0 && head.stdout && head.stdout !== "HEAD" ? head.stdout : void 0;
|
|
10153
|
+
suppressScopeWatch(scope.hash, 800);
|
|
9855
10154
|
return c.json({
|
|
9856
10155
|
scopeHash: scope.hash,
|
|
9857
10156
|
base,
|
|
@@ -9874,7 +10173,7 @@ function mountScopeRoutes(app, opts) {
|
|
|
9874
10173
|
if (!relPath || !Number.isInteger(start) || !Number.isInteger(end)) {
|
|
9875
10174
|
return c.json({ error: "bad path/start/end" }, 400);
|
|
9876
10175
|
}
|
|
9877
|
-
const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) =>
|
|
10176
|
+
const root = scope.paths.length === 1 ? scope.paths[0] : scope.paths.find((p) => path39.basename(p) === repoName);
|
|
9878
10177
|
if (!root) return c.json({ error: "unknown repo" }, 404);
|
|
9879
10178
|
const result = readContextLines({ root, relPath, start, end, ref });
|
|
9880
10179
|
if (!result) return c.json({ error: "cannot read file" }, 400);
|
|
@@ -9889,6 +10188,22 @@ function mountScopeRoutes(app, opts) {
|
|
|
9889
10188
|
entries: manifest.entries
|
|
9890
10189
|
});
|
|
9891
10190
|
});
|
|
10191
|
+
app.post("/api/scopes/:hash/checkpoints/:id/summary", async (c) => {
|
|
10192
|
+
const scope = getScope(c.req.param("hash"));
|
|
10193
|
+
if (!scope) return c.json({ error: "unknown scope" }, 404);
|
|
10194
|
+
const id = Number(c.req.param("id"));
|
|
10195
|
+
if (!Number.isInteger(id) || id < 0) {
|
|
10196
|
+
return c.json({ error: "bad checkpoint id" }, 400);
|
|
10197
|
+
}
|
|
10198
|
+
const entry = loadManifest(scope.hash).entries.find((e) => e.id === id);
|
|
10199
|
+
if (!entry) return c.json({ error: "unknown checkpoint" }, 404);
|
|
10200
|
+
if (entry.label && entry.label.trim()) return c.json({ label: entry.label });
|
|
10201
|
+
if (id === 0) return c.json({ label: "Initial" });
|
|
10202
|
+
const label2 = await summarizeCheckpoint(scope.hash, scopeRepos(scope.paths), id);
|
|
10203
|
+
await setCheckpointLabel(scope.hash, id, label2);
|
|
10204
|
+
opts.broadcast("checkpoints-changed", { scopeHash: scope.hash, id });
|
|
10205
|
+
return c.json({ label: label2 });
|
|
10206
|
+
});
|
|
9892
10207
|
function commentStore(hash) {
|
|
9893
10208
|
return getCommentFileStore(commentStoreIdForScope(hash));
|
|
9894
10209
|
}
|
|
@@ -9932,6 +10247,26 @@ function mountScopeRoutes(app, opts) {
|
|
|
9932
10247
|
}
|
|
9933
10248
|
return c.json({ comments: store.snapshot() });
|
|
9934
10249
|
});
|
|
10250
|
+
app.post(
|
|
10251
|
+
"/api/scopes/:hash/comments/:cid/resolve",
|
|
10252
|
+
zValidator5("json", resolveSchema),
|
|
10253
|
+
(c) => {
|
|
10254
|
+
const scope = getScope(c.req.param("hash"));
|
|
10255
|
+
if (!scope) return c.json({ error: "unknown scope" }, 404);
|
|
10256
|
+
const store = commentStore(scope.hash);
|
|
10257
|
+
const updated = store.setResolved(
|
|
10258
|
+
c.req.param("cid"),
|
|
10259
|
+
c.req.valid("json").resolved
|
|
10260
|
+
);
|
|
10261
|
+
if (updated) {
|
|
10262
|
+
opts.broadcast("comments-changed", {
|
|
10263
|
+
scopeHash: scope.hash,
|
|
10264
|
+
id: updated.id
|
|
10265
|
+
});
|
|
10266
|
+
}
|
|
10267
|
+
return c.json({ comments: store.snapshot() });
|
|
10268
|
+
}
|
|
10269
|
+
);
|
|
9935
10270
|
app.post(
|
|
9936
10271
|
"/api/scopes/:hash/submit-review",
|
|
9937
10272
|
zValidator5("json", submitReviewSchema),
|
|
@@ -10112,7 +10447,7 @@ function computeSessionDiff(s, base) {
|
|
|
10112
10447
|
(p) => resolveRepoDiff(p, base, s.baseBranches?.[p] ?? s.baseBranch)
|
|
10113
10448
|
);
|
|
10114
10449
|
const repos = s.paths.map((p, i) => ({
|
|
10115
|
-
name:
|
|
10450
|
+
name: path40.basename(p),
|
|
10116
10451
|
root: p,
|
|
10117
10452
|
resolvedBase: resolved[i].resolvedBase,
|
|
10118
10453
|
files: computeDiff({ root: p, diffArg: resolved[i].diffArg })
|
|
@@ -10132,10 +10467,10 @@ async function startWebServer(opts = {}) {
|
|
|
10132
10467
|
for (const cb of sseListeners) cb({ event, data });
|
|
10133
10468
|
};
|
|
10134
10469
|
const home = os12.homedir();
|
|
10135
|
-
const historyPath =
|
|
10470
|
+
const historyPath = path40.join(home, ".work", "history.json");
|
|
10136
10471
|
const onHistoryChange = () => broadcast("sessions-changed", { ts: Date.now() });
|
|
10137
10472
|
fs40.watchFile(historyPath, { interval: 1e3 }, onHistoryChange);
|
|
10138
|
-
const tasksPath =
|
|
10473
|
+
const tasksPath = path40.join(home, ".work", "tasks.json");
|
|
10139
10474
|
const onTasksChange = () => broadcast("tasks-changed", { ts: Date.now() });
|
|
10140
10475
|
fs40.watchFile(tasksPath, { interval: 1e3 }, onTasksChange);
|
|
10141
10476
|
const projectsRoot = claudeProjectsRoot();
|
|
@@ -10280,10 +10615,10 @@ function info2(message) {
|
|
|
10280
10615
|
process.stderr.write(message + "\n");
|
|
10281
10616
|
}
|
|
10282
10617
|
function urlFilePath() {
|
|
10283
|
-
return
|
|
10618
|
+
return path41.join(os13.homedir(), ".work", "web.url");
|
|
10284
10619
|
}
|
|
10285
10620
|
function pidFilePath() {
|
|
10286
|
-
return
|
|
10621
|
+
return path41.join(os13.homedir(), ".work", "web.pid");
|
|
10287
10622
|
}
|
|
10288
10623
|
function isPidAlive(pid) {
|
|
10289
10624
|
try {
|
|
@@ -10408,7 +10743,7 @@ var webCommand = {
|
|
|
10408
10743
|
const lean = !!argv.lean || process.env.WORK_WEB_LEAN === "1";
|
|
10409
10744
|
const handle = await startWebServer({ lean });
|
|
10410
10745
|
try {
|
|
10411
|
-
fs41.mkdirSync(
|
|
10746
|
+
fs41.mkdirSync(path41.dirname(urlFilePath()), { recursive: true });
|
|
10412
10747
|
fs41.writeFileSync(urlFilePath(), handle.url);
|
|
10413
10748
|
fs41.writeFileSync(pidFilePath(), String(process.pid));
|
|
10414
10749
|
} catch {
|
|
@@ -10437,6 +10772,13 @@ var webCommand = {
|
|
|
10437
10772
|
]).catch(() => {
|
|
10438
10773
|
});
|
|
10439
10774
|
}
|
|
10775
|
+
await installCommandHook({
|
|
10776
|
+
owner: "web-checkpoint",
|
|
10777
|
+
event: "Stop",
|
|
10778
|
+
command: "work hook checkpoint",
|
|
10779
|
+
timeoutSec: 5
|
|
10780
|
+
}).catch(() => {
|
|
10781
|
+
});
|
|
10440
10782
|
const shutdown = () => {
|
|
10441
10783
|
info2(chalk23.gray("\nStopping work web."));
|
|
10442
10784
|
try {
|
|
@@ -10457,6 +10799,10 @@ var webCommand = {
|
|
|
10457
10799
|
} catch {
|
|
10458
10800
|
}
|
|
10459
10801
|
}
|
|
10802
|
+
try {
|
|
10803
|
+
removeCommandHookSync("web-checkpoint", "Stop");
|
|
10804
|
+
} catch {
|
|
10805
|
+
}
|
|
10460
10806
|
handle.stop();
|
|
10461
10807
|
process.exit(0);
|
|
10462
10808
|
};
|
|
@@ -10478,6 +10824,31 @@ var webCommand = {
|
|
|
10478
10824
|
};
|
|
10479
10825
|
|
|
10480
10826
|
// src/commands/hook.ts
|
|
10827
|
+
import fs42 from "fs";
|
|
10828
|
+
import os14 from "os";
|
|
10829
|
+
import path42 from "path";
|
|
10830
|
+
async function triggerCheckpoint(cwd) {
|
|
10831
|
+
let base;
|
|
10832
|
+
try {
|
|
10833
|
+
base = fs42.readFileSync(path42.join(os14.homedir(), ".work", "web.url"), "utf-8").trim();
|
|
10834
|
+
} catch {
|
|
10835
|
+
return;
|
|
10836
|
+
}
|
|
10837
|
+
if (!base) return;
|
|
10838
|
+
const controller = new AbortController();
|
|
10839
|
+
const timer = setTimeout(() => controller.abort(), 3e3);
|
|
10840
|
+
try {
|
|
10841
|
+
await fetch(`${base}api/checkpoint`, {
|
|
10842
|
+
method: "POST",
|
|
10843
|
+
headers: { "Content-Type": "application/json" },
|
|
10844
|
+
body: JSON.stringify({ cwd }),
|
|
10845
|
+
signal: controller.signal
|
|
10846
|
+
});
|
|
10847
|
+
} catch {
|
|
10848
|
+
} finally {
|
|
10849
|
+
clearTimeout(timer);
|
|
10850
|
+
}
|
|
10851
|
+
}
|
|
10481
10852
|
function computeHookOutput(input2) {
|
|
10482
10853
|
const session = findSessionForCwd(input2.cwd);
|
|
10483
10854
|
if (!session) return null;
|
|
@@ -10527,13 +10898,17 @@ var hookCommand = {
|
|
|
10527
10898
|
// hidden — humans don't call this directly
|
|
10528
10899
|
builder: (y) => y.positional("event", {
|
|
10529
10900
|
type: "string",
|
|
10530
|
-
choices: ["prompt-submit", "stop"],
|
|
10901
|
+
choices: ["prompt-submit", "stop", "checkpoint"],
|
|
10531
10902
|
describe: "Hook event name"
|
|
10532
10903
|
}),
|
|
10533
10904
|
handler: async (argv) => {
|
|
10534
10905
|
const event = argv.event;
|
|
10535
10906
|
const payload = await readStdinJson();
|
|
10536
10907
|
const cwd = payload.cwd ?? process.cwd();
|
|
10908
|
+
if (event === "checkpoint") {
|
|
10909
|
+
await triggerCheckpoint(cwd);
|
|
10910
|
+
return;
|
|
10911
|
+
}
|
|
10537
10912
|
const result = computeHookOutput({ event, cwd });
|
|
10538
10913
|
if (!result || !result.sessionId) return;
|
|
10539
10914
|
process.stdout.write(result.stdout);
|
|
@@ -10543,7 +10918,7 @@ var hookCommand = {
|
|
|
10543
10918
|
|
|
10544
10919
|
// src/commands/run.ts
|
|
10545
10920
|
import chalk24 from "chalk";
|
|
10546
|
-
import
|
|
10921
|
+
import spawn15 from "cross-spawn";
|
|
10547
10922
|
|
|
10548
10923
|
// src/core/fleet.ts
|
|
10549
10924
|
function selectSessions(sessions, filter) {
|
|
@@ -10585,7 +10960,7 @@ function killAllChildren(signal = "SIGTERM") {
|
|
|
10585
10960
|
function runInPath(unit, cmd, prefix) {
|
|
10586
10961
|
const { bin, args } = shellInvocation(cmd);
|
|
10587
10962
|
return new Promise((resolve) => {
|
|
10588
|
-
const child =
|
|
10963
|
+
const child = spawn15(bin, args, {
|
|
10589
10964
|
cwd: unit.path,
|
|
10590
10965
|
stdio: prefix ? ["ignore", "pipe", "pipe"] : "inherit",
|
|
10591
10966
|
shell: false
|
|
@@ -10817,15 +11192,15 @@ var runCommand = {
|
|
|
10817
11192
|
};
|
|
10818
11193
|
|
|
10819
11194
|
// src/commands/broadcast.ts
|
|
10820
|
-
import
|
|
11195
|
+
import fs44 from "fs";
|
|
10821
11196
|
import chalk25 from "chalk";
|
|
10822
11197
|
|
|
10823
11198
|
// src/core/broadcast.ts
|
|
10824
11199
|
import crypto6 from "crypto";
|
|
10825
|
-
import
|
|
11200
|
+
import fs43 from "fs";
|
|
10826
11201
|
function readComments(file) {
|
|
10827
11202
|
try {
|
|
10828
|
-
const parsed = JSON.parse(
|
|
11203
|
+
const parsed = JSON.parse(fs43.readFileSync(file, "utf-8"));
|
|
10829
11204
|
return Array.isArray(parsed) ? parsed : [];
|
|
10830
11205
|
} catch {
|
|
10831
11206
|
return [];
|
|
@@ -10833,7 +11208,7 @@ function readComments(file) {
|
|
|
10833
11208
|
}
|
|
10834
11209
|
async function appendLocked(sessionId, body) {
|
|
10835
11210
|
const file = commentsFileFor(sessionId);
|
|
10836
|
-
|
|
11211
|
+
fs43.mkdirSync(commentsDir(), { recursive: true });
|
|
10837
11212
|
ensureFile(file, "[]");
|
|
10838
11213
|
const comment = {
|
|
10839
11214
|
id: crypto6.randomBytes(8).toString("hex"),
|
|
@@ -10870,7 +11245,7 @@ async function broadcastPrompt(sessions, filter, prompt) {
|
|
|
10870
11245
|
// src/commands/broadcast.ts
|
|
10871
11246
|
function readStdin() {
|
|
10872
11247
|
try {
|
|
10873
|
-
return
|
|
11248
|
+
return fs44.readFileSync(0, "utf-8");
|
|
10874
11249
|
} catch {
|
|
10875
11250
|
return "";
|
|
10876
11251
|
}
|
|
@@ -10945,7 +11320,7 @@ var broadcastCommand = {
|
|
|
10945
11320
|
};
|
|
10946
11321
|
|
|
10947
11322
|
// src/completions/index.ts
|
|
10948
|
-
import
|
|
11323
|
+
import fs45 from "fs";
|
|
10949
11324
|
import path43 from "path";
|
|
10950
11325
|
function completionHandler(current, argv, done) {
|
|
10951
11326
|
const rawArgs = argv._;
|
|
@@ -11050,7 +11425,7 @@ function completeTreeRemoveList(command, args, current, config, done) {
|
|
|
11050
11425
|
}
|
|
11051
11426
|
function completeRepoBranches(alias, current, config, done) {
|
|
11052
11427
|
const repoPath = config.repos[alias];
|
|
11053
|
-
if (!repoPath || !
|
|
11428
|
+
if (!repoPath || !fs45.existsSync(repoPath)) {
|
|
11054
11429
|
done([]);
|
|
11055
11430
|
return;
|
|
11056
11431
|
}
|
|
@@ -11060,18 +11435,18 @@ function completeRepoBranches(alias, current, config, done) {
|
|
|
11060
11435
|
}
|
|
11061
11436
|
function completeGroupBranches(groupName, repoAliases, current, config, done) {
|
|
11062
11437
|
const groupDir = path43.join(config.worktreesRoot, groupName);
|
|
11063
|
-
if (!
|
|
11438
|
+
if (!fs45.existsSync(groupDir)) {
|
|
11064
11439
|
done([]);
|
|
11065
11440
|
return;
|
|
11066
11441
|
}
|
|
11067
11442
|
try {
|
|
11068
|
-
const branchDirs =
|
|
11443
|
+
const branchDirs = fs45.readdirSync(groupDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => {
|
|
11069
11444
|
const bdPath = path43.join(groupDir, d.name);
|
|
11070
11445
|
for (const alias of repoAliases) {
|
|
11071
11446
|
const repoPath = config.repos[alias];
|
|
11072
11447
|
if (!repoPath) continue;
|
|
11073
11448
|
const subPath = path43.join(bdPath, path43.basename(repoPath));
|
|
11074
|
-
if (
|
|
11449
|
+
if (fs45.existsSync(subPath)) {
|
|
11075
11450
|
const branch = getCurrentBranch(subPath);
|
|
11076
11451
|
if (branch) return branch;
|
|
11077
11452
|
}
|
|
@@ -11085,7 +11460,7 @@ function completeGroupBranches(groupName, repoAliases, current, config, done) {
|
|
|
11085
11460
|
}
|
|
11086
11461
|
|
|
11087
11462
|
// src/version.ts
|
|
11088
|
-
var VERSION = true ? "1.
|
|
11463
|
+
var VERSION = true ? "1.9.0" : "dev";
|
|
11089
11464
|
|
|
11090
11465
|
// src/cli.ts
|
|
11091
11466
|
function showHelp() {
|
|
@@ -11182,7 +11557,7 @@ function handleFatalError(err) {
|
|
|
11182
11557
|
}
|
|
11183
11558
|
if (err instanceof Error && err.message?.includes("pty that has already exited")) {
|
|
11184
11559
|
try {
|
|
11185
|
-
|
|
11560
|
+
fs46.appendFileSync(
|
|
11186
11561
|
path44.join(getConfigDir(), "debug.log"),
|
|
11187
11562
|
`${(/* @__PURE__ */ new Date()).toISOString()} [WARN] Ignored async node-pty error: ${err.message}
|
|
11188
11563
|
`
|
|
@@ -11193,7 +11568,7 @@ function handleFatalError(err) {
|
|
|
11193
11568
|
}
|
|
11194
11569
|
try {
|
|
11195
11570
|
const msg = err instanceof Error ? err.stack || err.message : String(err);
|
|
11196
|
-
|
|
11571
|
+
fs46.appendFileSync(
|
|
11197
11572
|
path44.join(getConfigDir(), "debug.log"),
|
|
11198
11573
|
`${(/* @__PURE__ */ new Date()).toISOString()} [FATAL] handleFatalError: ${msg}
|
|
11199
11574
|
`
|