@moberg_hr/work-tree 1.16.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -142
- package/dist/answer-2J4XLIP7.js +63 -0
- package/dist/answer-2J4XLIP7.js.map +1 -0
- package/dist/attach-CZKRNPAJ.js +59 -0
- package/dist/attach-CZKRNPAJ.js.map +1 -0
- package/dist/bin.js +26 -11924
- package/dist/bin.js.map +1 -1
- package/dist/block-RAIDCJ4F.js +84 -0
- package/dist/block-RAIDCJ4F.js.map +1 -0
- package/dist/broadcast-BSI5NDDB.js +104 -0
- package/dist/broadcast-BSI5NDDB.js.map +1 -0
- package/dist/catchup-VVOPL2S5.js +51 -0
- package/dist/catchup-VVOPL2S5.js.map +1 -0
- package/dist/chunk-3JWTO5VZ.js +135 -0
- package/dist/chunk-3JWTO5VZ.js.map +1 -0
- package/dist/chunk-4BOK2GXL.js +210 -0
- package/dist/chunk-4BOK2GXL.js.map +1 -0
- package/dist/chunk-5QK7GB5K.js +112 -0
- package/dist/chunk-5QK7GB5K.js.map +1 -0
- package/dist/chunk-6AQRYLOB.js +16 -0
- package/dist/chunk-6AQRYLOB.js.map +1 -0
- package/dist/chunk-6FTIY5M6.js +120 -0
- package/dist/chunk-6FTIY5M6.js.map +1 -0
- package/dist/chunk-6H3MLDGG.js +48 -0
- package/dist/chunk-6H3MLDGG.js.map +1 -0
- package/dist/chunk-77XFJQGC.js +103 -0
- package/dist/chunk-77XFJQGC.js.map +1 -0
- package/dist/chunk-7HEB6SQS.js +257 -0
- package/dist/chunk-7HEB6SQS.js.map +1 -0
- package/dist/chunk-7NAXFBFI.js +206 -0
- package/dist/chunk-7NAXFBFI.js.map +1 -0
- package/dist/chunk-7NCW3LUT.js +358 -0
- package/dist/chunk-7NCW3LUT.js.map +1 -0
- package/dist/chunk-7OLPI334.js +537 -0
- package/dist/chunk-7OLPI334.js.map +1 -0
- package/dist/chunk-ABQYKTG4.js +38 -0
- package/dist/chunk-ABQYKTG4.js.map +1 -0
- package/dist/chunk-AH5TM3NB.js +21 -0
- package/dist/chunk-AH5TM3NB.js.map +1 -0
- package/dist/chunk-AKMPF72Y.js +274 -0
- package/dist/chunk-AKMPF72Y.js.map +1 -0
- package/dist/chunk-BR6OPEE4.js +162 -0
- package/dist/chunk-BR6OPEE4.js.map +1 -0
- package/dist/chunk-C2BK6EBN.js +162 -0
- package/dist/chunk-C2BK6EBN.js.map +1 -0
- package/dist/chunk-C2THFSXA.js +37 -0
- package/dist/chunk-C2THFSXA.js.map +1 -0
- package/dist/chunk-C7W5TMFB.js +308 -0
- package/dist/chunk-C7W5TMFB.js.map +1 -0
- package/dist/chunk-CLGVSX36.js +668 -0
- package/dist/chunk-CLGVSX36.js.map +1 -0
- package/dist/chunk-CVAVYDXO.js +295 -0
- package/dist/chunk-CVAVYDXO.js.map +1 -0
- package/dist/chunk-DW4JPVXB.js +41 -0
- package/dist/chunk-DW4JPVXB.js.map +1 -0
- package/dist/chunk-FPKERDK7.js +142 -0
- package/dist/chunk-FPKERDK7.js.map +1 -0
- package/dist/chunk-FR3EWVXI.js +188 -0
- package/dist/chunk-FR3EWVXI.js.map +1 -0
- package/dist/chunk-H5LKMR45.js +117 -0
- package/dist/chunk-H5LKMR45.js.map +1 -0
- package/dist/chunk-HIZBWYPL.js +267 -0
- package/dist/chunk-HIZBWYPL.js.map +1 -0
- package/dist/chunk-HSICXDMZ.js +41 -0
- package/dist/chunk-HSICXDMZ.js.map +1 -0
- package/dist/chunk-HUXS3VAI.js +90 -0
- package/dist/chunk-HUXS3VAI.js.map +1 -0
- package/dist/chunk-HWUINPIL.js +151 -0
- package/dist/chunk-HWUINPIL.js.map +1 -0
- package/dist/chunk-IXKVCR4Y.js +487 -0
- package/dist/chunk-IXKVCR4Y.js.map +1 -0
- package/dist/chunk-JNBYNRFS.js +54 -0
- package/dist/chunk-JNBYNRFS.js.map +1 -0
- package/dist/chunk-JYTMT5DF.js +421 -0
- package/dist/chunk-JYTMT5DF.js.map +1 -0
- package/dist/chunk-KGZ6OZ2T.js +102 -0
- package/dist/chunk-KGZ6OZ2T.js.map +1 -0
- package/dist/chunk-LMIEEDDC.js +9 -0
- package/dist/chunk-LMIEEDDC.js.map +1 -0
- package/dist/chunk-LNHSBM4L.js +26 -0
- package/dist/chunk-LNHSBM4L.js.map +1 -0
- package/dist/chunk-M4FVCAT6.js +2406 -0
- package/dist/chunk-M4FVCAT6.js.map +1 -0
- package/dist/chunk-N4EYQKSM.js +104 -0
- package/dist/chunk-N4EYQKSM.js.map +1 -0
- package/dist/chunk-NDWSLQPB.js +112 -0
- package/dist/chunk-NDWSLQPB.js.map +1 -0
- package/dist/chunk-O3QTWVSK.js +323 -0
- package/dist/chunk-O3QTWVSK.js.map +1 -0
- package/dist/chunk-P3BL4EOP.js +37 -0
- package/dist/chunk-P3BL4EOP.js.map +1 -0
- package/dist/chunk-PN44M5EE.js +887 -0
- package/dist/chunk-PN44M5EE.js.map +1 -0
- package/dist/chunk-Q6WZCO45.js +47 -0
- package/dist/chunk-Q6WZCO45.js.map +1 -0
- package/dist/chunk-QBAZG4CY.js +230 -0
- package/dist/chunk-QBAZG4CY.js.map +1 -0
- package/dist/chunk-R2LN3JJJ.js +132 -0
- package/dist/chunk-R2LN3JJJ.js.map +1 -0
- package/dist/chunk-RCYI7SRA.js +15 -0
- package/dist/chunk-RCYI7SRA.js.map +1 -0
- package/dist/chunk-RYNBBSLY.js +67 -0
- package/dist/chunk-RYNBBSLY.js.map +1 -0
- package/dist/chunk-S5HJT7CM.js +30 -0
- package/dist/chunk-S5HJT7CM.js.map +1 -0
- package/dist/chunk-SNAQOHNL.js +285 -0
- package/dist/chunk-SNAQOHNL.js.map +1 -0
- package/dist/chunk-SOCPIHCS.js +181 -0
- package/dist/chunk-SOCPIHCS.js.map +1 -0
- package/dist/chunk-TUC4QY4O.js +147 -0
- package/dist/chunk-TUC4QY4O.js.map +1 -0
- package/dist/chunk-TUFQJXXO.js +19 -0
- package/dist/chunk-TUFQJXXO.js.map +1 -0
- package/dist/chunk-UFY7C5PP.js +90 -0
- package/dist/chunk-UFY7C5PP.js.map +1 -0
- package/dist/chunk-UQ35KLHH.js +34 -0
- package/dist/chunk-UQ35KLHH.js.map +1 -0
- package/dist/chunk-VJ7SVDED.js +177 -0
- package/dist/chunk-VJ7SVDED.js.map +1 -0
- package/dist/chunk-VJNSIDOA.js +23 -0
- package/dist/chunk-VJNSIDOA.js.map +1 -0
- package/dist/chunk-WF5SBVPZ.js +190 -0
- package/dist/chunk-WF5SBVPZ.js.map +1 -0
- package/dist/chunk-WMJIU3YW.js +29 -0
- package/dist/chunk-WMJIU3YW.js.map +1 -0
- package/dist/chunk-XJDEROHY.js +19 -0
- package/dist/chunk-XJDEROHY.js.map +1 -0
- package/dist/chunk-YKODIG22.js +221 -0
- package/dist/chunk-YKODIG22.js.map +1 -0
- package/dist/chunk-YNKWLC45.js +122 -0
- package/dist/chunk-YNKWLC45.js.map +1 -0
- package/dist/chunk-YZDD5YGE.js +165 -0
- package/dist/chunk-YZDD5YGE.js.map +1 -0
- package/dist/chunk-YZWADOEW.js +151 -0
- package/dist/chunk-YZWADOEW.js.map +1 -0
- package/dist/chunk-ZJN5RWZD.js +76 -0
- package/dist/chunk-ZJN5RWZD.js.map +1 -0
- package/dist/chunk-ZSHWP2VS.js +22 -0
- package/dist/chunk-ZSHWP2VS.js.map +1 -0
- package/dist/chunk-ZXPYWZL5.js +307 -0
- package/dist/chunk-ZXPYWZL5.js.map +1 -0
- package/dist/cleanup-LDBGWEKZ.js +192 -0
- package/dist/cleanup-LDBGWEKZ.js.map +1 -0
- package/dist/cli-UATB4RM2.js +18 -0
- package/dist/cli-UATB4RM2.js.map +1 -0
- package/dist/command-hook-installer-SGEJTZ2Y.js +204 -0
- package/dist/command-hook-installer-SGEJTZ2Y.js.map +1 -0
- package/dist/completion-MXX5TRIV.js +118 -0
- package/dist/completion-MXX5TRIV.js.map +1 -0
- package/dist/config-IEIU7A66.js +410 -0
- package/dist/config-IEIU7A66.js.map +1 -0
- package/dist/console-reporter-XU6VFUZE.js +10 -0
- package/dist/console-reporter-XU6VFUZE.js.map +1 -0
- package/dist/diff-K47HB6SA.js +582 -0
- package/dist/diff-K47HB6SA.js.map +1 -0
- package/dist/digest-FBZTBXQO.js +100 -0
- package/dist/digest-FBZTBXQO.js.map +1 -0
- package/dist/fork-BKI5UNNS.js +120 -0
- package/dist/fork-BKI5UNNS.js.map +1 -0
- package/dist/hook-SLMZT5OV.js +220 -0
- package/dist/hook-SLMZT5OV.js.map +1 -0
- package/dist/hydrate-Y2AAMZTA.js +121 -0
- package/dist/hydrate-Y2AAMZTA.js.map +1 -0
- package/dist/init-7ESFTYZC.js +187 -0
- package/dist/init-7ESFTYZC.js.map +1 -0
- package/dist/install-skills-O34BHFHD.js +14 -0
- package/dist/install-skills-O34BHFHD.js.map +1 -0
- package/dist/install-skills-bin.js +12 -0
- package/dist/install-skills-bin.js.map +1 -0
- package/dist/list-KEF73NLQ.js +126 -0
- package/dist/list-KEF73NLQ.js.map +1 -0
- package/dist/move-FKT2P5LY.js +313 -0
- package/dist/move-FKT2P5LY.js.map +1 -0
- package/dist/note-WGM6LCP2.js +78 -0
- package/dist/note-WGM6LCP2.js.map +1 -0
- package/dist/overlaps-FRLMMIGC.js +56 -0
- package/dist/overlaps-FRLMMIGC.js.map +1 -0
- package/dist/pin-MQ5ZE37R.js +45 -0
- package/dist/pin-MQ5ZE37R.js.map +1 -0
- package/dist/pr-527S5HXB.js +122 -0
- package/dist/pr-527S5HXB.js.map +1 -0
- package/dist/prune-AIS5YEXP.js +92 -0
- package/dist/prune-AIS5YEXP.js.map +1 -0
- package/dist/pty-host-RWIS55N4.js +826 -0
- package/dist/pty-host-RWIS55N4.js.map +1 -0
- package/dist/read-AP6T3ZGN.js +57 -0
- package/dist/read-AP6T3ZGN.js.map +1 -0
- package/dist/recent-IE3LYQ65.js +111 -0
- package/dist/recent-IE3LYQ65.js.map +1 -0
- package/dist/remove-YGUTSKZP.js +108 -0
- package/dist/remove-YGUTSKZP.js.map +1 -0
- package/dist/report-KM4OZCZB.js +16 -0
- package/dist/report-KM4OZCZB.js.map +1 -0
- package/dist/resume-UUP6R2IE.js +81 -0
- package/dist/resume-UUP6R2IE.js.map +1 -0
- package/dist/run-V4755W7C.js +263 -0
- package/dist/run-V4755W7C.js.map +1 -0
- package/dist/screen-DNX4K23V.js +58 -0
- package/dist/screen-DNX4K23V.js.map +1 -0
- package/dist/search-3JZXLCR2.js +46 -0
- package/dist/search-3JZXLCR2.js.map +1 -0
- package/dist/section-TXLC5XO3.js +79 -0
- package/dist/section-TXLC5XO3.js.map +1 -0
- package/dist/send-6X46WZLC.js +87 -0
- package/dist/send-6X46WZLC.js.map +1 -0
- package/dist/sessions-T3QDTNP7.js +135 -0
- package/dist/sessions-T3QDTNP7.js.map +1 -0
- package/dist/snooze-KYSFXLPY.js +65 -0
- package/dist/snooze-KYSFXLPY.js.map +1 -0
- package/dist/start-SQSDQK4F.js +56 -0
- package/dist/start-SQSDQK4F.js.map +1 -0
- package/dist/state-4DFV6SHG.js +147 -0
- package/dist/state-4DFV6SHG.js.map +1 -0
- package/dist/status-H5OW4LYE.js +118 -0
- package/dist/status-H5OW4LYE.js.map +1 -0
- package/dist/stop-HC7XPSSP.js +45 -0
- package/dist/stop-HC7XPSSP.js.map +1 -0
- package/dist/sync-ITK5UYGM.js +96 -0
- package/dist/sync-ITK5UYGM.js.map +1 -0
- package/dist/time-GN6B4QD6.js +111 -0
- package/dist/time-GN6B4QD6.js.map +1 -0
- package/dist/todo-LWMQY6XW.js +152 -0
- package/dist/todo-LWMQY6XW.js.map +1 -0
- package/dist/tree-7BMORJ6J.js +235 -0
- package/dist/tree-7BMORJ6J.js.map +1 -0
- package/dist/update-6LQNLRA4.js +57 -0
- package/dist/update-6LQNLRA4.js.map +1 -0
- package/dist/wait-MZOZQ3CI.js +57 -0
- package/dist/wait-MZOZQ3CI.js.map +1 -0
- package/dist/wd-bin.js +21 -11912
- package/dist/wd-bin.js.map +1 -1
- package/dist/web/assets/PtyView-BrP-ENHg.css +1 -0
- package/dist/web/assets/PtyView-DYvawzWb.js +90 -0
- package/dist/web/assets/PtyView-DYvawzWb.js.map +1 -0
- package/dist/web/assets/index-C5lJhIwK.js +116 -0
- package/dist/web/assets/index-C5lJhIwK.js.map +1 -0
- package/dist/web/assets/index-L8mjakHP.css +1 -0
- package/dist/web/index.html +3 -5
- package/dist/web-IC3P7EHZ.js +7689 -0
- package/dist/web-IC3P7EHZ.js.map +1 -0
- package/npm-shrinkwrap.json +6947 -0
- package/package.json +52 -34
- package/plugins/work-tree/.claude-plugin/plugin.json +1 -1
- package/plugins/work-tree/skills/wd-review/SKILL.md +4 -4
- package/plugins/work-tree/skills/work-sessions/SKILL.md +62 -0
- package/scripts/postinstall.mjs +15 -45
- package/dist/web/assets/index-B9H3vCtL.js +0 -107
- package/dist/web/assets/index-B9H3vCtL.js.map +0 -1
- package/dist/web/assets/index-BseMpW5i.css +0 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
BUILD_DIR_NAMES
|
|
4
|
+
} from "./chunk-NDWSLQPB.js";
|
|
5
|
+
|
|
6
|
+
// src/core/worktree/repo-rules.ts
|
|
7
|
+
var baseName = (p) => p.replace(/[\\/]+$/, "").split(/[\\/]/).pop() ?? p;
|
|
8
|
+
var dirName = (p) => p.replace(/[\\/]+$/, "").replace(/[\\/][^\\/]*$/, "");
|
|
9
|
+
function pathKey(resolved, caseless) {
|
|
10
|
+
const r = resolved.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
11
|
+
return caseless ? r.toLowerCase() : r;
|
|
12
|
+
}
|
|
13
|
+
var sameFolder = (a, b) => {
|
|
14
|
+
const caseless = /^[a-z]:/i.test(a) || /^[a-z]:/i.test(b);
|
|
15
|
+
return pathKey(a, caseless) === pathKey(b, caseless);
|
|
16
|
+
};
|
|
17
|
+
var ALIAS_RE = /^[a-z0-9][a-z0-9._-]*$/;
|
|
18
|
+
function aliasFromFolder(folder) {
|
|
19
|
+
return folder.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[-._]+|[-._]+$/g, "") || "repo";
|
|
20
|
+
}
|
|
21
|
+
function suggestAlias(repoPath, taken) {
|
|
22
|
+
const base = aliasFromFolder(baseName(repoPath));
|
|
23
|
+
if (!taken(base)) return base;
|
|
24
|
+
const withParent = `${aliasFromFolder(baseName(dirName(repoPath)))}-${base}`;
|
|
25
|
+
if (!taken(withParent)) return withParent;
|
|
26
|
+
for (let n = 2; ; n++) if (!taken(`${base}-${n}`)) return `${base}-${n}`;
|
|
27
|
+
}
|
|
28
|
+
function enrollProblem(alias, repoPath, config) {
|
|
29
|
+
if (!ALIAS_RE.test(alias)) return "an alias is lowercase letters, digits, . _ - (starting with a letter or digit)";
|
|
30
|
+
if (alias in config.repos) return `\u201C${alias}\u201D is already the alias of ${config.repos[alias]}`;
|
|
31
|
+
if (alias in config.groups) return `\u201C${alias}\u201D is a group`;
|
|
32
|
+
const same = Object.entries(config.repos).find(([, p]) => sameFolder(p, repoPath));
|
|
33
|
+
if (same) return `already enrolled as \u201C${same[0]}\u201D`;
|
|
34
|
+
const folder = baseName(repoPath).toLowerCase();
|
|
35
|
+
const clash = Object.entries(config.repos).find(([, p]) => baseName(p).toLowerCase() === folder);
|
|
36
|
+
if (clash) return `another repo has the folder name \u201C${baseName(repoPath)}\u201D (${clash[0]}): their worktrees would share a folder`;
|
|
37
|
+
if (Object.keys(config.groups).some((g) => g.toLowerCase() === folder))
|
|
38
|
+
return `a group is called \u201C${folder}\u201D: its worktrees would share a folder`;
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
function groupProblem(name, members, config, opts) {
|
|
42
|
+
if (opts.creating) {
|
|
43
|
+
if (!ALIAS_RE.test(name)) return "a group name is lowercase letters, digits, . _ - (starting with a letter or digit)";
|
|
44
|
+
if (name in config.groups) return `a group \u201C${name}\u201D already exists`;
|
|
45
|
+
if (name in config.repos) return `\u201C${name}\u201D is a repo's alias`;
|
|
46
|
+
if (Object.values(config.repos).some((p) => baseName(p).toLowerCase() === name)) return `a repo's folder is called \u201C${name}\u201D`;
|
|
47
|
+
} else if (!(name in config.groups)) {
|
|
48
|
+
return `no group \u201C${name}\u201D`;
|
|
49
|
+
}
|
|
50
|
+
if (new Set(members).size < 2) return "a group needs at least two repos";
|
|
51
|
+
const unknown = members.filter((m) => !(m in config.repos));
|
|
52
|
+
if (unknown.length) return `not enrolled: ${unknown.join(", ")}`;
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/core/worktree/repo-scan.ts
|
|
57
|
+
import fs from "fs";
|
|
58
|
+
import path from "path";
|
|
59
|
+
function samePathKey(p, platform = process.platform) {
|
|
60
|
+
return pathKey(path.resolve(p), platform === "win32");
|
|
61
|
+
}
|
|
62
|
+
function ownerRepo(url) {
|
|
63
|
+
const m = /[:/]([^/:]+)\/([^/]+?)(?:\.git)?\/?$/.exec(url.trim());
|
|
64
|
+
return m ? `${m[1]}/${m[2]}` : null;
|
|
65
|
+
}
|
|
66
|
+
function originUrl(configText) {
|
|
67
|
+
const section = /\[remote "origin"\]([\s\S]*?)(?=\n\[|$)/.exec(configText);
|
|
68
|
+
const url = section ? /^\s*url\s*=\s*(.+)$/m.exec(section[1]) : null;
|
|
69
|
+
if (!url) return null;
|
|
70
|
+
const v = url[1].trim().replace(/^"(.*)"$/, "$1");
|
|
71
|
+
return v.replace(/\\(["\\])/g, "$1");
|
|
72
|
+
}
|
|
73
|
+
function gitKind(dir) {
|
|
74
|
+
const g = path.join(dir, ".git");
|
|
75
|
+
let st;
|
|
76
|
+
try {
|
|
77
|
+
st = fs.statSync(g);
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
if (st.isDirectory()) return "repo";
|
|
82
|
+
return "linked";
|
|
83
|
+
}
|
|
84
|
+
function readOrigin(dir) {
|
|
85
|
+
try {
|
|
86
|
+
const url = originUrl(fs.readFileSync(path.join(dir, ".git", "config"), "utf-8"));
|
|
87
|
+
return url ? ownerRepo(url) : null;
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function scanForRepos(root, opts = {}) {
|
|
93
|
+
const depth = opts.depth ?? 2;
|
|
94
|
+
const skip = new Set((opts.skip ?? []).filter(Boolean).map((p) => samePathKey(p)));
|
|
95
|
+
const found = [];
|
|
96
|
+
let level = [root];
|
|
97
|
+
for (let d = 0; d <= depth && level.length; d++) {
|
|
98
|
+
const next = [];
|
|
99
|
+
for (const dir of level) {
|
|
100
|
+
if (skip.has(samePathKey(dir))) continue;
|
|
101
|
+
const kind = d === 0 ? null : gitKind(dir);
|
|
102
|
+
if (kind === "repo") {
|
|
103
|
+
found.push({ path: dir, folder: path.basename(dir), origin: readOrigin(dir) });
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (kind === "linked") continue;
|
|
107
|
+
let entries;
|
|
108
|
+
try {
|
|
109
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
110
|
+
} catch {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
for (const e of entries) {
|
|
114
|
+
if (!e.isDirectory() || e.name.startsWith(".") || BUILD_DIR_NAMES.has(e.name.toLowerCase())) continue;
|
|
115
|
+
next.push(path.join(dir, e.name));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
level = next;
|
|
119
|
+
}
|
|
120
|
+
return found.sort((a, b) => a.folder.localeCompare(b.folder));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export {
|
|
124
|
+
suggestAlias,
|
|
125
|
+
enrollProblem,
|
|
126
|
+
groupProblem,
|
|
127
|
+
samePathKey,
|
|
128
|
+
ownerRepo,
|
|
129
|
+
originUrl,
|
|
130
|
+
scanForRepos
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=chunk-R2LN3JJJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/worktree/repo-rules.ts","../src/core/worktree/repo-scan.ts"],"sourcesContent":["/**\n * The rules for enrolling repos and making groups (repo-admin.ts, the Repos\n * page, the demo): what alias a repo gets, and why one can't be used. Pure,\n * without node:path — the demo and the SPA import it.\n */\n\n/** A path's last part. */\nconst baseName = (p: string) =>\n p\n .replace(/[\\\\/]+$/, '')\n .split(/[\\\\/]/)\n .pop() ?? p;\n/** Its folder. */\nconst dirName = (p: string) => p.replace(/[\\\\/]+$/, '').replace(/[\\\\/][^\\\\/]*$/, '');\n\n/** A resolved path written one way, for comparing: `/`, no trailing separator, lowercase when `caseless` (Windows). */\nexport function pathKey(resolved: string, caseless: boolean): string {\n const r = resolved.replace(/\\\\/g, '/').replace(/\\/+$/, '');\n return caseless ? r.toLowerCase() : r;\n}\n\n/** Two paths as the same folder: separators, a trailing one and (with a drive letter) case don't matter. */\nconst sameFolder = (a: string, b: string) => {\n const caseless = /^[a-z]:/i.test(a) || /^[a-z]:/i.test(b);\n return pathKey(a, caseless) === pathKey(b, caseless);\n};\n\nconst ALIAS_RE = /^[a-z0-9][a-z0-9._-]*$/;\n\n/** A folder name as an alias: lowercase, only a-z 0-9 . _ - . Pure. */\nexport function aliasFromFolder(folder: string): string {\n return (\n folder\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, '-')\n .replace(/^[-._]+|[-._]+$/g, '') || 'repo'\n );\n}\n\n/**\n * The alias a found repo would get: its folder's, or — taken by an alias\n * or a group — its parent folder's in front (`iom-contracts`), then -2, -3….\n * Pure.\n */\nexport function suggestAlias(repoPath: string, taken: (alias: string) => boolean): string {\n const base = aliasFromFolder(baseName(repoPath));\n if (!taken(base)) return base;\n const withParent = `${aliasFromFolder(baseName(dirName(repoPath)))}-${base}`;\n if (!taken(withParent)) return withParent;\n for (let n = 2; ; n++) if (!taken(`${base}-${n}`)) return `${base}-${n}`;\n}\n\n/**\n * Why a repo can't be enrolled under `alias`; null when it can. Besides the\n * alias itself (its characters, an alias or group of that name), the\n * folder: worktrees go in `<worktreesRoot>/<folder>/`, so two repos with the\n * same folder name would share them. Pure.\n */\nexport function enrollProblem(\n alias: string,\n repoPath: string,\n config: { repos: Record<string, string>; groups: Record<string, string[]> },\n): string | null {\n if (!ALIAS_RE.test(alias)) return 'an alias is lowercase letters, digits, . _ - (starting with a letter or digit)';\n if (alias in config.repos) return `“${alias}” is already the alias of ${config.repos[alias]}`;\n if (alias in config.groups) return `“${alias}” is a group`;\n const same = Object.entries(config.repos).find(([, p]) => sameFolder(p, repoPath));\n if (same) return `already enrolled as “${same[0]}”`;\n const folder = baseName(repoPath).toLowerCase();\n const clash = Object.entries(config.repos).find(([, p]) => baseName(p).toLowerCase() === folder);\n if (clash) return `another repo has the folder name “${baseName(repoPath)}” (${clash[0]}): their worktrees would share a folder`;\n if (Object.keys(config.groups).some((g) => g.toLowerCase() === folder))\n return `a group is called “${folder}”: its worktrees would share a folder`;\n return null;\n}\n\n/** Why a group can't be called `name`, or made of `members`; null when it can. Pure. */\nexport function groupProblem(\n name: string,\n members: string[],\n config: { repos: Record<string, string>; groups: Record<string, string[]> },\n opts: { creating: boolean },\n): string | null {\n // The name is checked when it is given; an existing group keeps the one it has.\n if (opts.creating) {\n if (!ALIAS_RE.test(name)) return 'a group name is lowercase letters, digits, . _ - (starting with a letter or digit)';\n if (name in config.groups) return `a group “${name}” already exists`;\n if (name in config.repos) return `“${name}” is a repo's alias`;\n if (Object.values(config.repos).some((p) => baseName(p).toLowerCase() === name)) return `a repo's folder is called “${name}”`;\n } else if (!(name in config.groups)) {\n return `no group “${name}”`;\n }\n if (new Set(members).size < 2) return 'a group needs at least two repos';\n const unknown = members.filter((m) => !(m in config.repos));\n if (unknown.length) return `not enrolled: ${unknown.join(', ')}`;\n return null;\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport { BUILD_DIR_NAMES } from '../cleanup/build-folders.js';\nimport { pathKey } from './repo-rules.js';\nexport { aliasFromFolder, enrollProblem, groupProblem, suggestAlias } from './repo-rules.js';\n\n/**\n * Finding the git repos in a folder (the Repos page, `work config scan`):\n * a breadth-first walk, a few levels deep, that stops at each repo it finds\n * (a repo inside a repo is that repo's business), and skips what is never a\n * project of its own — build output, dot-folders, work's worktrees, a\n * worktree's or a submodule's `.git` file. Reads only: directory listings\n * and the `.git` entries.\n */\n\nexport interface FoundRepo {\n /** As found on disk. */\n path: string;\n /** Its folder name. */\n folder: string;\n /** `owner/name` from its origin URL, when it has one. */\n origin: string | null;\n}\n\n/** One way to write a path, for comparing: resolved, no trailing separator, `/`, lowercase on Windows. Pure. */\nexport function samePathKey(p: string, platform: NodeJS.Platform = process.platform): string {\n return pathKey(path.resolve(p), platform === 'win32');\n}\n\n/** `owner/name` from an origin URL (https or ssh, with or without .git); null when it isn't one. Pure. */\nexport function ownerRepo(url: string): string | null {\n const m = /[:/]([^/:]+)\\/([^/]+?)(?:\\.git)?\\/?$/.exec(url.trim());\n return m ? `${m[1]}/${m[2]}` : null;\n}\n\n/** The origin URL in a `.git/config` text. Pure. */\nexport function originUrl(configText: string): string | null {\n const section = /\\[remote \"origin\"\\]([\\s\\S]*?)(?=\\n\\[|$)/.exec(configText);\n const url = section ? /^\\s*url\\s*=\\s*(.+)$/m.exec(section[1]) : null;\n if (!url) return null;\n // As git writes a value: maybe quoted, with \\\\ and \\\" escaped (a Windows path).\n const v = url[1].trim().replace(/^\"(.*)\"$/, '$1');\n return v.replace(/\\\\([\"\\\\])/g, '$1');\n}\n\n/** What a folder's `.git` says it is: a repo, a linked worktree or a submodule (a `.git` file), or nothing. */\nfunction gitKind(dir: string): 'repo' | 'linked' | null {\n const g = path.join(dir, '.git');\n let st: fs.Stats;\n try {\n st = fs.statSync(g);\n } catch {\n return null;\n }\n if (st.isDirectory()) return 'repo';\n // A file: `gitdir: …/.git/worktrees/x` (a worktree) or `…/.git/modules/x` (a submodule) — part of another repo.\n return 'linked';\n}\n\nfunction readOrigin(dir: string): string | null {\n try {\n const url = originUrl(fs.readFileSync(path.join(dir, '.git', 'config'), 'utf-8'));\n return url ? ownerRepo(url) : null;\n } catch {\n return null;\n }\n}\n\n/**\n * The git repos under `root`, at most `depth` folders down (1 = its\n * children). `skip`: folders never walked into (work's worktrees root),\n * compared with samePathKey. A root that doesn't exist gives none.\n */\nexport function scanForRepos(root: string, opts: { depth?: number; skip?: string[] } = {}): FoundRepo[] {\n const depth = opts.depth ?? 2;\n const skip = new Set((opts.skip ?? []).filter(Boolean).map((p) => samePathKey(p)));\n const found: FoundRepo[] = [];\n let level: string[] = [root];\n for (let d = 0; d <= depth && level.length; d++) {\n const next: string[] = [];\n for (const dir of level) {\n if (skip.has(samePathKey(dir))) continue;\n const kind = d === 0 ? null : gitKind(dir);\n if (kind === 'repo') {\n found.push({ path: dir, folder: path.basename(dir), origin: readOrigin(dir) });\n continue; // a repo's insides are its own\n }\n if (kind === 'linked') continue;\n let entries: fs.Dirent[];\n try {\n entries = fs.readdirSync(dir, { withFileTypes: true });\n } catch {\n continue;\n }\n for (const e of entries) {\n if (!e.isDirectory() || e.name.startsWith('.') || BUILD_DIR_NAMES.has(e.name.toLowerCase())) continue;\n next.push(path.join(dir, e.name));\n }\n }\n level = next;\n }\n return found.sort((a, b) => a.folder.localeCompare(b.folder));\n}\n"],"mappings":";;;;;;AAOA,IAAM,WAAW,CAAC,MAChB,EACG,QAAQ,WAAW,EAAE,EACrB,MAAM,OAAO,EACb,IAAI,KAAK;AAEd,IAAM,UAAU,CAAC,MAAc,EAAE,QAAQ,WAAW,EAAE,EAAE,QAAQ,iBAAiB,EAAE;AAG5E,SAAS,QAAQ,UAAkB,UAA2B;AACnE,QAAM,IAAI,SAAS,QAAQ,OAAO,GAAG,EAAE,QAAQ,QAAQ,EAAE;AACzD,SAAO,WAAW,EAAE,YAAY,IAAI;AACtC;AAGA,IAAM,aAAa,CAAC,GAAW,MAAc;AAC3C,QAAM,WAA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N;AAAA,MACF;AACA,iBAAW,KAAK,SAAS;AACvB,YAAI,CAAC,EAAE,YAAY,KAAK,EAAE,KAAK,WAAW,GAAG,KAAK,gBAAgB,IAAI,EAAE,KAAK,YAAY,CAAC,EAAG;AAC7F,aAAK,KAAK,KAAK,KAAK,KAAK,EAAE,IAAI,CAAC;AAAA,MAClC;AAAA,IACF;AACA,YAAQ;AAAA,EACV;AACA,SAAO,MAAM,KAAK,CAAC,GAAG,MAAM,EAAE,OAAO,cAAc,EAAE,MAAM,CAAC;AAC9D;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/core/platform/spawn.ts
|
|
4
|
+
import { createRequire } from "module";
|
|
5
|
+
var loaded = null;
|
|
6
|
+
var load = () => loaded ??= createRequire(import.meta.url)("cross-spawn");
|
|
7
|
+
var spawn = Object.assign((...args) => load()(...args), {
|
|
8
|
+
sync: (...args) => load().sync(...args)
|
|
9
|
+
});
|
|
10
|
+
var spawn_default = spawn;
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
spawn_default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=chunk-RCYI7SRA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/platform/spawn.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport type CrossSpawnModule from 'cross-spawn';\n\n/**\n * cross-spawn, loaded on first use. core's modules all spawn through it, and\n * importing it up front put it (and its dependencies) on every `work hook`\n * — which runs twice per turn of every Claude — whether the hook spawned\n * anything or not. Same function, same `.sync`.\n */\ntype CrossSpawn = typeof CrossSpawnModule;\n\nlet loaded: CrossSpawn | null = null;\nconst load = (): CrossSpawn => (loaded ??= createRequire(import.meta.url)('cross-spawn') as CrossSpawn);\n\nconst spawn = Object.assign((...args: unknown[]) => (load() as unknown as (...a: unknown[]) => unknown)(...args), {\n sync: (...args: unknown[]) => (load().sync as unknown as (...a: unknown[]) => unknown)(...args),\n}) as unknown as CrossSpawn;\n\nexport default spawn;\n"],"mappings":";;;AAAA,SAAS,qBAAqB;AAW9B,IAAI,SAA4B;AAChC,IAAM,OAAO,MAAmB,WAAW,cAAc,YAAY,GAAG,EAAE,aAAa;AAEvF,IAAM,QAAQ,OAAO,OAAO,IAAI,SAAqB,KAAK,EAA8C,GAAG,IAAI,GAAG;AAAA,EAChH,MAAM,IAAI,SAAqB,KAAK,EAAE,KAAiD,GAAG,IAAI;AAChG,CAAC;AAED,IAAO,gBAAQ;","names":[]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/core/sessions/session-control.ts
|
|
4
|
+
var MAX_SEND_CHARS = 2e4;
|
|
5
|
+
async function sendToSession(id, text, deps, opts = {}) {
|
|
6
|
+
const body = text.trim();
|
|
7
|
+
if (!body) return { ok: false, status: 400, error: "the message is empty" };
|
|
8
|
+
if (body.length > MAX_SEND_CHARS) return { ok: false, status: 400, error: `the message is over ${MAX_SEND_CHARS} characters` };
|
|
9
|
+
if (deps.archived(id)) return { ok: false, status: 409, error: "it is archived: restore it first" };
|
|
10
|
+
if (deps.unsafe(id) && !opts.force) {
|
|
11
|
+
return {
|
|
12
|
+
ok: false,
|
|
13
|
+
status: 409,
|
|
14
|
+
error: "its Claude runs with permission checks off (--unsafe), so it would act on this without asking you; send with --force if you mean it"
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const sentAt = (opts.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
|
|
18
|
+
const delivered = await deps.post(id, body);
|
|
19
|
+
if (delivered) return { ok: true, how: delivered, sentAt };
|
|
20
|
+
if (deps.hostRuns(id)) return { ok: true, how: "next-turn", sentAt };
|
|
21
|
+
if (deps.runningOutside(id)) return { ok: true, how: "outside", sentAt };
|
|
22
|
+
if (!await deps.start(id))
|
|
23
|
+
return { ok: false, status: 502, error: "queued, but its Claude could not be started: it gets it when you open the session" };
|
|
24
|
+
return { ok: true, how: "started", sentAt };
|
|
25
|
+
}
|
|
26
|
+
function sendHowText(how) {
|
|
27
|
+
switch (how) {
|
|
28
|
+
case "typed":
|
|
29
|
+
return "sent: typed into its terminal";
|
|
30
|
+
case "next-turn":
|
|
31
|
+
return "queued: it is working, so it gets this when the turn ends";
|
|
32
|
+
case "outside":
|
|
33
|
+
return "queued: its Claude runs in a terminal outside work, and gets this on its next turn there";
|
|
34
|
+
case "started":
|
|
35
|
+
return "sent: its Claude was started (resuming its conversation) with this as the first message";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function waitForTurn(id, deps, opts) {
|
|
39
|
+
const deadline = deps.now() + opts.timeoutMs;
|
|
40
|
+
const after = opts.after ? Date.parse(opts.after) : null;
|
|
41
|
+
for (; ; ) {
|
|
42
|
+
const s = deps.status(id);
|
|
43
|
+
const fresh = after === null || !!s && Date.parse(s.since) > after;
|
|
44
|
+
if (s && s.state !== "working" && fresh) return { ok: true, status: s };
|
|
45
|
+
if (deps.now() >= deadline) return { ok: false, reason: "timeout", status: s };
|
|
46
|
+
await deps.sleep(opts.pollMs ?? 1e3);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function pendingRequest(status) {
|
|
50
|
+
return status?.state === "needs_input" && status.request ? status.request : null;
|
|
51
|
+
}
|
|
52
|
+
function parseDuration(text) {
|
|
53
|
+
const m = /^\s*(\d+(?:\.\d+)?)\s*(s|m|h)?\s*$/i.exec(text);
|
|
54
|
+
if (!m) return null;
|
|
55
|
+
const n = Number(m[1]);
|
|
56
|
+
const unit = (m[2] ?? "s").toLowerCase();
|
|
57
|
+
return Math.round(n * (unit === "h" ? 36e5 : unit === "m" ? 6e4 : 1e3));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
sendToSession,
|
|
62
|
+
sendHowText,
|
|
63
|
+
waitForTurn,
|
|
64
|
+
pendingRequest,
|
|
65
|
+
parseDuration
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=chunk-RYNBBSLY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/sessions/session-control.ts"],"sourcesContent":["import type { AgentState } from '../status/attention.js';\nimport type { PermissionRequest, SendHow } from '../api-types.js';\n\n/**\n * Driving a session from outside its terminal — another Claude, a script,\n * you in a shell: send it a message, wait for its turn to end, answer its\n * permission prompt. The policy is here; I/O is passed in (the routes in\n * session-control-routes.ts give the real one, tests a fake).\n *\n * A message goes the way every note to a session goes (§ saved prompts): a\n * published comment, which the dashboard types into a terminal it owns when\n * that Claude is idle, or which the prompt hook hands over on its next turn.\n * Never typed into a terminal directly.\n */\n\nexport const MAX_SEND_CHARS = 20_000;\n\nexport type { SendHow } from '../api-types.js';\n\nexport interface SendDeps {\n /** Queue it as a published comment (the comment route), resolving to what that route did with it: typed into an idle host Claude, left for the end of its turn, or null (no host terminal). */\n post: (id: string, body: string) => Promise<'typed' | 'next-turn' | null>;\n /** Its Claude runs in the PTY host. */\n hostRuns: (id: string) => boolean;\n /** Its Claude runs in a terminal outside work (seen in Claude Code's process files). */\n runningOutside: (id: string) => boolean;\n /** Start its Claude in the host, resuming its conversation, its first message saying a note is attached (NOTE_NUDGE). */\n start: (id: string) => Promise<boolean>;\n state: (id: string) => AgentState | null;\n /** It runs with permission checks off. */\n unsafe: (id: string) => boolean;\n archived: (id: string) => boolean;\n}\n\nexport type SendResult = { ok: true; how: SendHow; sentAt: string } | { ok: false; status: 400 | 409 | 502; error: string };\n\nexport async function sendToSession(\n id: string,\n text: string,\n deps: SendDeps,\n opts: { force?: boolean; now?: () => Date } = {},\n): Promise<SendResult> {\n const body = text.trim();\n if (!body) return { ok: false, status: 400, error: 'the message is empty' };\n if (body.length > MAX_SEND_CHARS) return { ok: false, status: 400, error: `the message is over ${MAX_SEND_CHARS} characters` };\n if (deps.archived(id)) return { ok: false, status: 409, error: 'it is archived: restore it first' };\n // A message to a Claude with permission checks off runs whatever it says,\n // unreviewed — and it may have come from another agent. Your say-so first.\n if (deps.unsafe(id) && !opts.force) {\n return {\n ok: false,\n status: 409,\n error:\n 'its Claude runs with permission checks off (--unsafe), so it would act on this without asking you; send with --force if you mean it',\n };\n }\n const sentAt = (opts.now?.() ?? new Date()).toISOString();\n // What the comment route did, as it decided it — not a second look at the state.\n const delivered = await deps.post(id, body);\n if (delivered) return { ok: true, how: delivered, sentAt };\n if (deps.hostRuns(id)) return { ok: true, how: 'next-turn', sentAt };\n if (deps.runningOutside(id)) return { ok: true, how: 'outside', sentAt };\n if (!(await deps.start(id)))\n return { ok: false, status: 502, error: 'queued, but its Claude could not be started: it gets it when you open the session' };\n return { ok: true, how: 'started', sentAt };\n}\n\n/** What `how` means, in a line. */\nexport function sendHowText(how: SendHow): string {\n switch (how) {\n case 'typed':\n return 'sent: typed into its terminal';\n case 'next-turn':\n return 'queued: it is working, so it gets this when the turn ends';\n case 'outside':\n return 'queued: its Claude runs in a terminal outside work, and gets this on its next turn there';\n case 'started':\n return 'sent: its Claude was started (resuming its conversation) with this as the first message';\n }\n}\n\nexport interface TurnStatus {\n state: AgentState;\n /** When it entered that state (ISO). */\n since: string;\n summary?: string;\n}\n\nexport interface WaitDeps {\n status: (id: string) => TurnStatus | null;\n sleep: (ms: number) => Promise<void>;\n now: () => number;\n}\n\nexport type WaitResult = { ok: true; status: TurnStatus } | { ok: false; reason: 'timeout'; status: TurnStatus | null };\n\n/**\n * Wait until the session isn't working: its turn ended (idle) or it asks\n * you something (needs input). With `after` (when a message was sent), only\n * a state entered after it counts — the turn that message started, not the\n * one before.\n */\nexport async function waitForTurn(\n id: string,\n deps: WaitDeps,\n opts: { after?: string; timeoutMs: number; pollMs?: number },\n): Promise<WaitResult> {\n const deadline = deps.now() + opts.timeoutMs;\n const after = opts.after ? Date.parse(opts.after) : null;\n for (;;) {\n const s = deps.status(id);\n const fresh = after === null || (!!s && Date.parse(s.since) > after);\n if (s && s.state !== 'working' && fresh) return { ok: true, status: s };\n if (deps.now() >= deadline) return { ok: false, reason: 'timeout', status: s };\n await deps.sleep(opts.pollMs ?? 1000);\n }\n}\n\n/** The permission prompt it is waiting on, if any (what `work answer` shows, and must send back). */\nexport function pendingRequest(status: { state: AgentState; request?: PermissionRequest } | null): PermissionRequest | null {\n return status?.state === 'needs_input' && status.request ? status.request : null;\n}\n\n/** Parse \"15m\", \"90s\", \"2h\", or a number of seconds. */\nexport function parseDuration(text: string): number | null {\n const m = /^\\s*(\\d+(?:\\.\\d+)?)\\s*(s|m|h)?\\s*$/i.exec(text);\n if (!m) return null;\n const n = Number(m[1]);\n const unit = (m[2] ?? 's').toLowerCase();\n return Math.round(n * (unit === 'h' ? 3_600_000 : unit === 'm' ? 60_000 : 1000));\n}\n"],"mappings":";;;AAeO,IAAM,iBAAiB;AAqB9B,eAAsB,cACpB,IACA,MACA,MACA,OAA8C,CAAC,GAC1B;AACrB,QAAM,OAAO,KAAK,KAAK;AACvB,MAAI,CAAC,KAAM,QAAO,EAAE,IAAI,OAAO,QAAQ,KAAK,OAAO,uBAAuB;AAC1E,MAAI,KAAK,SAAS,eAAgB,QAAO,EAAE,IAAI,OAAO,QAAQ,KAAK,OAAO,uBAAuB,cAAc,cAAc;AAC7H,MAAI,KAAK,SAAS,EAAE,EAAG,QAAO,EAAE,IAAI,OAAO,QAAQ,KAAK,OAAO,mCAAmC;AAGlG,MAAI,KAAK,OAAO,EAAE,KAAK,CAAC,KAAK,OAAO;AAClC,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,OACE;AAAA,IACJ;AAAA,EACF;AACA,QAAM,UAAU,KAAK,MAAM,KAAK,oBAAI,KAAK,GAAG,YAAY;AAExD,QAAM,YAAY,MAAM,KAAK,KAAK,IAAI,IAAI;AAC1C,MAAI,UAAW,QAAO,EAAE,IAAI,MAAM,KAAK,WAAW,OAAO;AACzD,MAAI,KAAK,SAAS,EAAE,EAAG,QAAO,EAAE,IAAI,MAAM,KAAK,aAAa,OAAO;A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M,MAAS,IAAK;AACjF;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/commands/shared/console-reporter.ts
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
var COLOR = {
|
|
6
|
+
step: chalk.cyan,
|
|
7
|
+
info: (s) => s,
|
|
8
|
+
detail: chalk.gray,
|
|
9
|
+
success: chalk.green,
|
|
10
|
+
warn: chalk.yellow,
|
|
11
|
+
error: chalk.red
|
|
12
|
+
};
|
|
13
|
+
function reportStreamFor(args) {
|
|
14
|
+
const end = args.indexOf("--");
|
|
15
|
+
const own = end === -1 ? args : args.slice(0, end);
|
|
16
|
+
return own.some((a) => a === "--json" || a === "--json=true") ? "stderr" : "stdout";
|
|
17
|
+
}
|
|
18
|
+
function consoleReporter(stream = "stdout") {
|
|
19
|
+
return (level, text) => {
|
|
20
|
+
const line = COLOR[level](text);
|
|
21
|
+
if (level === "error" || stream === "stderr") console.error(line);
|
|
22
|
+
else console.log(line);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
reportStreamFor,
|
|
28
|
+
consoleReporter
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=chunk-S5HJT7CM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/shared/console-reporter.ts"],"sourcesContent":["import chalk from 'chalk';\nimport type { ReportLevel, Reporter } from '../../core/platform/report.js';\n\n/**\n * How the CLI shows core's reports. Colors live here, not in core.\n *\n * `stream`: `work` writes to stdout (as it always has); `wd` writes status\n * to stderr, since its stdout carries data only (the review markdown). Errors\n * always go to stderr.\n */\nconst COLOR: Record<ReportLevel, (s: string) => string> = {\n step: chalk.cyan,\n info: (s) => s,\n detail: chalk.gray,\n success: chalk.green,\n warn: chalk.yellow,\n error: chalk.red,\n};\n\n/**\n * Where a `work` invocation shows its reports: stderr when it was asked for\n * `--json`, whose stdout must be the JSON and nothing else (a script parses\n * it — `work cleanup --apply --json` once mixed \"Removed worktree\" lines into\n * it); stdout otherwise. Arguments after a bare `--` belong to something else.\n */\nexport function reportStreamFor(args: readonly string[]): 'stdout' | 'stderr' {\n const end = args.indexOf('--');\n const own = end === -1 ? args : args.slice(0, end);\n return own.some((a) => a === '--json' || a === '--json=true') ? 'stderr' : 'stdout';\n}\n\nexport function consoleReporter(stream: 'stdout' | 'stderr' = 'stdout'): Reporter {\n return (level, text) => {\n const line = COLOR[level](text);\n if (level === 'error' || stream === 'stderr') console.error(line);\n else console.log(line);\n };\n}\n"],"mappings":";;;AAAA,OAAO,WAAW;AAUlB,IAAM,QAAoD;AAAA,EACxD,MAAM,MAAM;AAAA,EACZ,MAAM,CAAC,MAAM;AAAA,EACb,QAAQ,MAAM;AAAA,EACd,SAAS,MAAM;AAAA,EACf,MAAM,MAAM;AAAA,EACZ,OAAO,MAAM;AACf;AAQO,SAAS,gBAAgB,MAA8C;AAC5E,QAAM,MAAM,KAAK,QAAQ,IAAI;AAC7B,QAAM,MAAM,QAAQ,KAAK,OAAO,KAAK,MAAM,GAAG,GAAG;AACjD,SAAO,IAAI,KAAK,CAAC,MAAM,MAAM,YAAY,MAAM,aAAa,IAAI,WAAW;AAC7E;AAEO,SAAS,gBAAgB,SAA8B,UAAoB;AAChF,SAAO,CAAC,OAAO,SAAS;AACtB,UAAM,OAAO,MAAM,KAAK,EAAE,IAAI;AAC9B,QAAI,UAAU,WAAW,WAAW,SAAU,SAAQ,MAAM,IAAI;AAAA,QAC3D,SAAQ,IAAI,IAAI;AAAA,EACvB;AACF;","names":[]}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
peekPty
|
|
4
|
+
} from "./chunk-O3QTWVSK.js";
|
|
5
|
+
import {
|
|
6
|
+
sessionStatusView
|
|
7
|
+
} from "./chunk-6H3MLDGG.js";
|
|
8
|
+
import {
|
|
9
|
+
checkedOutBranch,
|
|
10
|
+
readPendingForSession
|
|
11
|
+
} from "./chunk-WF5SBVPZ.js";
|
|
12
|
+
import {
|
|
13
|
+
getCommentFileStore
|
|
14
|
+
} from "./chunk-5QK7GB5K.js";
|
|
15
|
+
import {
|
|
16
|
+
STAGE_WANTS_YOU,
|
|
17
|
+
archiveDirFor,
|
|
18
|
+
bestEffort,
|
|
19
|
+
keptList,
|
|
20
|
+
prStageOf,
|
|
21
|
+
promptsSince,
|
|
22
|
+
readArchive,
|
|
23
|
+
readSessionActivity,
|
|
24
|
+
readStatus,
|
|
25
|
+
snoozeActive,
|
|
26
|
+
withLiveClaude
|
|
27
|
+
} from "./chunk-M4FVCAT6.js";
|
|
28
|
+
import {
|
|
29
|
+
sessionIdFor
|
|
30
|
+
} from "./chunk-7NCW3LUT.js";
|
|
31
|
+
import {
|
|
32
|
+
agentOf,
|
|
33
|
+
agentWire,
|
|
34
|
+
readJsonlTail
|
|
35
|
+
} from "./chunk-PN44M5EE.js";
|
|
36
|
+
|
|
37
|
+
// src/core/sessions/session-wire.ts
|
|
38
|
+
import fs2 from "fs";
|
|
39
|
+
import path from "path";
|
|
40
|
+
|
|
41
|
+
// src/core/sessions/session-meta.ts
|
|
42
|
+
function readSessionMeta(sessionId, session) {
|
|
43
|
+
const comments = getCommentFileStore(sessionId).snapshot();
|
|
44
|
+
let drafts = 0;
|
|
45
|
+
let claude = 0;
|
|
46
|
+
for (const c of comments) {
|
|
47
|
+
if (c.status === "draft") drafts++;
|
|
48
|
+
if (c.author === "claude") claude++;
|
|
49
|
+
}
|
|
50
|
+
const activity = readSessionActivity(session);
|
|
51
|
+
const pending = readPendingForSession(sessionId).length;
|
|
52
|
+
const status = readStatus(sessionId);
|
|
53
|
+
return {
|
|
54
|
+
draftCount: drafts,
|
|
55
|
+
commentCount: comments.length,
|
|
56
|
+
claudeCount: claude,
|
|
57
|
+
ptyStatus: peekPty(sessionId) ? "running" : "idle",
|
|
58
|
+
lastActivity: activity.lastActivity,
|
|
59
|
+
activityState: activity.state,
|
|
60
|
+
pendingForClaudeCount: pending,
|
|
61
|
+
attention: status ? sessionStatusView(status, session, activity.lastActivity ?? 0) : null
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/core/conversations/context-usage.ts
|
|
66
|
+
function contextUsageFrom(entries, window) {
|
|
67
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
68
|
+
const e = entries[i];
|
|
69
|
+
if (e.role !== "agent" || e.sidechain || !e.usage) continue;
|
|
70
|
+
const used = e.usage.prompt + e.usage.reply;
|
|
71
|
+
if (used === 0) continue;
|
|
72
|
+
return { used, window: window(e.model, used), ...e.model ? { model: e.model } : {} };
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
var USAGE_TAIL_BYTES = 64 * 1024;
|
|
77
|
+
var cache = /* @__PURE__ */ new Map();
|
|
78
|
+
function readContextUsage(session) {
|
|
79
|
+
const conv = agentOf(session).conversation;
|
|
80
|
+
if (!conv) return null;
|
|
81
|
+
let t = null;
|
|
82
|
+
for (const f of conv.files(session)) if (!t || f.mtimeMs > t.mtimeMs) t = f;
|
|
83
|
+
if (!t) return null;
|
|
84
|
+
const key = `${t.file}:${t.size}:${t.mtimeMs}`;
|
|
85
|
+
const id = session.paths.join("|");
|
|
86
|
+
const hit = cache.get(id);
|
|
87
|
+
if (hit?.key === key) return hit.usage;
|
|
88
|
+
const usage = contextUsageFrom(conv.entries(readJsonlTail(t.file, USAGE_TAIL_BYTES)), conv.contextWindow);
|
|
89
|
+
cache.set(id, { key, usage });
|
|
90
|
+
return usage;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/core/conversations/session-title.ts
|
|
94
|
+
import fs from "fs";
|
|
95
|
+
var TITLE_CHARS = 80;
|
|
96
|
+
var HEAD_BYTES = 256 * 1024;
|
|
97
|
+
var cache2 = /* @__PURE__ */ new Map();
|
|
98
|
+
function firstPromptOf(file, toEntries) {
|
|
99
|
+
let size;
|
|
100
|
+
try {
|
|
101
|
+
size = fs.statSync(file).size;
|
|
102
|
+
} catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const hit = cache2.get(file);
|
|
106
|
+
if (hit && size >= hit.size && (hit.title !== null || size === hit.size || hit.size >= HEAD_BYTES)) return hit.title;
|
|
107
|
+
let text;
|
|
108
|
+
try {
|
|
109
|
+
const fd = fs.openSync(file, "r");
|
|
110
|
+
try {
|
|
111
|
+
const buf = Buffer.alloc(Math.min(size, HEAD_BYTES));
|
|
112
|
+
fs.readSync(fd, buf, 0, buf.length, 0);
|
|
113
|
+
text = buf.toString("utf8");
|
|
114
|
+
} finally {
|
|
115
|
+
fs.closeSync(fd);
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const lines = [];
|
|
121
|
+
for (const line of text.split("\n")) {
|
|
122
|
+
try {
|
|
123
|
+
lines.push(JSON.parse(line));
|
|
124
|
+
} catch {
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const first = promptsSince([toEntries(lines)], 0)[0]?.text ?? null;
|
|
128
|
+
const readable = first ? titleText(first) : null;
|
|
129
|
+
const title = readable ? clip(readable) : null;
|
|
130
|
+
cache2.set(file, { size, title });
|
|
131
|
+
return title;
|
|
132
|
+
}
|
|
133
|
+
var clip = (s) => s.length > TITLE_CHARS ? s.slice(0, TITLE_CHARS - 1).trimEnd() + "\u2026" : s;
|
|
134
|
+
function titleText(prompt) {
|
|
135
|
+
const flat = (s) => s.replace(/<\/?[A-Za-z][\w-]*(?:\s[^>]*)?>/g, " ").replace(/\s+/g, " ").trim();
|
|
136
|
+
const outside = flat(prompt.replace(/<pasted_content\b[^>]*>[\s\S]*?<\/pasted_content>/g, " "));
|
|
137
|
+
const text = outside || flat(prompt);
|
|
138
|
+
return text ? text : null;
|
|
139
|
+
}
|
|
140
|
+
function sessionTitle(s, fallbackPrompt) {
|
|
141
|
+
if (s.title?.trim()) return s.title.trim();
|
|
142
|
+
const conv = agentOf(s).conversation;
|
|
143
|
+
const oldestFirst = (conv?.files(s) ?? []).sort((a, b) => a.mtimeMs - b.mtimeMs);
|
|
144
|
+
for (const t of oldestFirst) {
|
|
145
|
+
const p = firstPromptOf(t.file, conv.entries);
|
|
146
|
+
if (p) return p;
|
|
147
|
+
}
|
|
148
|
+
const fallback = fallbackPrompt ? titleText(fallbackPrompt) : null;
|
|
149
|
+
if (fallback) return clip(fallback);
|
|
150
|
+
return s.jiraKey ?? null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/core/sessions/session-wire.ts
|
|
154
|
+
function sessionWire(s, opts = {}) {
|
|
155
|
+
const id = sessionIdFor(s);
|
|
156
|
+
const meta = readSessionMeta(id, s);
|
|
157
|
+
const shadowed = opts.shadowed?.(id) ?? false;
|
|
158
|
+
const claudes = shadowed ? null : opts.claudesFor?.(id) ?? null;
|
|
159
|
+
const reviewThreads = s.archivedAt ? 0 : opts.reviewThreadsFor?.(id) ?? 0;
|
|
160
|
+
const replyDrafts = s.archivedAt ? 0 : opts.replyDraftsFor?.(id) ?? 0;
|
|
161
|
+
const prStage = s.archivedAt ? null : opts.prStageFor?.(id) ?? null;
|
|
162
|
+
const wire = {
|
|
163
|
+
id,
|
|
164
|
+
target: s.target,
|
|
165
|
+
branch: s.branch,
|
|
166
|
+
isGroup: s.isGroup,
|
|
167
|
+
paths: s.paths,
|
|
168
|
+
baseBranch: s.baseBranch,
|
|
169
|
+
jiraKey: s.jiraKey,
|
|
170
|
+
createdAt: s.createdAt,
|
|
171
|
+
lastAccessedAt: s.lastAccessedAt,
|
|
172
|
+
draftCount: meta.draftCount,
|
|
173
|
+
commentCount: meta.commentCount,
|
|
174
|
+
claudeCount: meta.claudeCount,
|
|
175
|
+
ptyStatus: opts.ptyLive ? opts.ptyLive(id) ? "running" : "idle" : meta.ptyStatus,
|
|
176
|
+
lastActivity: shadowed ? null : meta.lastActivity,
|
|
177
|
+
// A running Claude is open even when it writes nothing (idle at its prompt).
|
|
178
|
+
activityState: shadowed ? "stale" : claudes ? claudes.busy ? "active" : meta.activityState === "active" ? "active" : "open" : meta.activityState,
|
|
179
|
+
...claudes ? { agents: claudes, claudes } : {},
|
|
180
|
+
agent: agentWire(agentOf(s)),
|
|
181
|
+
...s.archivedAt ? archiveInfo(id) : {},
|
|
182
|
+
title: bestEffort(
|
|
183
|
+
`title of ${s.target}:${s.branch}`,
|
|
184
|
+
() => sessionTitle(s, s.archivedAt ? readArchive(id)?.summary.prompts[0]?.text : null),
|
|
185
|
+
null
|
|
186
|
+
),
|
|
187
|
+
...s.title ? { titleIsYours: true } : {},
|
|
188
|
+
pendingForClaudeCount: meta.pendingForClaudeCount,
|
|
189
|
+
// Claude Code's own state file over what the hooks recorded, when newer.
|
|
190
|
+
attention: meta.attention && !shadowed && opts.claudesFor ? withLiveClaude(meta.attention, claudes, { known: opts.liveKnown === true, hosted: opts.hostedLive?.(id) ?? true }) : meta.attention ?? (shadowed || s.archivedAt ? null : opts.outputStatusFor?.(id) ?? null),
|
|
191
|
+
diffStat: opts.diffStatFor ? opts.diffStatFor(id, s, meta.attention !== null) : null,
|
|
192
|
+
archivedAt: s.archivedAt ?? null,
|
|
193
|
+
port: s.port ?? null,
|
|
194
|
+
context: s.archivedAt ? null : bestEffort(`context usage for ${s.target}:${s.branch}`, () => readContextUsage(s), null),
|
|
195
|
+
...reviewThreads > 0 ? { openReviewThreads: reviewThreads } : {},
|
|
196
|
+
...replyDrafts > 0 ? { replyDrafts } : {},
|
|
197
|
+
...prStage ? { prStage } : {},
|
|
198
|
+
...otherBranches(s)
|
|
199
|
+
};
|
|
200
|
+
const snooze = s.archivedAt ? null : opts.snoozeFor?.(id) ?? null;
|
|
201
|
+
if (snooze && snoozeActive(snooze, { attention: readStatus(id), openReviewThreads: wire.openReviewThreads, prStage: wire.prStage }))
|
|
202
|
+
wire.snoozed = { until: snooze.until };
|
|
203
|
+
const behind = s.archivedAt ? null : opts.behindFor?.(id, s) ?? null;
|
|
204
|
+
if (behind && behind.commits > 0) wire.behind = behind;
|
|
205
|
+
const stack = s.archivedAt ? null : opts.stackFor?.(id) ?? null;
|
|
206
|
+
if (stack?.parent) wire.stackedOn = stack.parent;
|
|
207
|
+
if (stack?.children) wire.stackedChildren = stack.children;
|
|
208
|
+
if (stack?.merged) wire.stackParentMerged = stack.merged;
|
|
209
|
+
if (opts.hasNote?.(id)) wire.hasNote = true;
|
|
210
|
+
const blockers = s.archivedAt ? [] : opts.blockedByFor?.(id) ?? [];
|
|
211
|
+
if (blockers.length) wire.blockedBy = blockers;
|
|
212
|
+
return wire;
|
|
213
|
+
}
|
|
214
|
+
function otherBranches(s) {
|
|
215
|
+
if (s.archivedAt || !s.branch) return {};
|
|
216
|
+
const out = [];
|
|
217
|
+
for (const p of s.paths) {
|
|
218
|
+
if (!fs2.existsSync(p)) continue;
|
|
219
|
+
const branch = checkedOutBranch(p);
|
|
220
|
+
if (branch !== s.branch) out.push({ repo: s.isGroup ? path.basename(p) : s.target, branch });
|
|
221
|
+
}
|
|
222
|
+
return out.length ? { onOtherBranch: out } : {};
|
|
223
|
+
}
|
|
224
|
+
function reviewThreadsOf(ci) {
|
|
225
|
+
return (ci?.repos ?? []).reduce((n, r) => n + (r.pr?.state === "OPEN" ? r.openThreads ?? 0 : 0), 0);
|
|
226
|
+
}
|
|
227
|
+
var stageSeenKey = (stageKey) => `stage:${stageKey}`;
|
|
228
|
+
function prStageWire(ci, seen) {
|
|
229
|
+
const stage = prStageOf(ci?.repos ?? []);
|
|
230
|
+
if (!stage) return null;
|
|
231
|
+
return STAGE_WANTS_YOU.has(stage.kind) && seen(stageSeenKey(stage.key)) ? { ...stage, seen: true } : stage;
|
|
232
|
+
}
|
|
233
|
+
function savedFiles(saved) {
|
|
234
|
+
const n = Object.values(saved ?? {}).filter((u) => !u.restoredAt && !u.restoreError).reduce((sum, u) => sum + u.files, 0);
|
|
235
|
+
return n ? { savedUncommitted: n } : {};
|
|
236
|
+
}
|
|
237
|
+
function archiveInfo(id) {
|
|
238
|
+
const rec = readArchive(id);
|
|
239
|
+
if (!rec) return {};
|
|
240
|
+
return {
|
|
241
|
+
archive: {
|
|
242
|
+
worktreeRemoved: rec.worktreeRemoved,
|
|
243
|
+
keptBecause: rec.keptBecause,
|
|
244
|
+
promptCount: rec.summary.promptCount,
|
|
245
|
+
prompts: rec.summary.prompts.map((p) => p.text),
|
|
246
|
+
lastSummary: rec.summary.lastSummary,
|
|
247
|
+
...rec.summary.written ? { written: rec.summary.written } : {},
|
|
248
|
+
...rec.buildFolders ? { buildFolders: rec.buildFolders } : {},
|
|
249
|
+
...savedFiles(rec.uncommitted),
|
|
250
|
+
...keptList(rec.kept) ? { kept: keptList(rec.kept) } : {}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function lastActiveMs(w) {
|
|
255
|
+
return Math.max(Date.parse(w.lastAccessedAt) || 0, w.lastActivity ?? 0, w.attention ? Date.parse(w.attention.updatedAt) || 0 : 0);
|
|
256
|
+
}
|
|
257
|
+
function createArchivedRows(archiveFile = (id) => path.join(archiveDirFor(id), "archive.json")) {
|
|
258
|
+
const rows = /* @__PURE__ */ new Map();
|
|
259
|
+
return (s, extra, build) => {
|
|
260
|
+
if (!s.archivedAt) return build();
|
|
261
|
+
const id = sessionIdFor(s);
|
|
262
|
+
let mtime = 0;
|
|
263
|
+
try {
|
|
264
|
+
mtime = fs2.statSync(archiveFile(id)).mtimeMs;
|
|
265
|
+
} catch {
|
|
266
|
+
}
|
|
267
|
+
const key = `${s.archivedAt}|${mtime}|${s.title ?? ""}|${s.lastAccessedAt}|${extra.hasNote}`;
|
|
268
|
+
const hit = rows.get(id);
|
|
269
|
+
if (hit?.key === key) return hit.row;
|
|
270
|
+
const row = build();
|
|
271
|
+
rows.set(id, { key, row });
|
|
272
|
+
return row;
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export {
|
|
277
|
+
readContextUsage,
|
|
278
|
+
sessionWire,
|
|
279
|
+
reviewThreadsOf,
|
|
280
|
+
stageSeenKey,
|
|
281
|
+
prStageWire,
|
|
282
|
+
lastActiveMs,
|
|
283
|
+
createArchivedRows
|
|
284
|
+
};
|
|
285
|
+
//# sourceMappingURL=chunk-SNAQOHNL.js.map
|