@moberg_hr/work-tree 1.15.0 → 2.0.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 +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 -11892
- 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-7H4BJ2YA.js +308 -0
- package/dist/chunk-7H4BJ2YA.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-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-CLGVSX36.js +668 -0
- package/dist/chunk-CLGVSX36.js.map +1 -0
- package/dist/chunk-CXEC5W5V.js +267 -0
- package/dist/chunk-CXEC5W5V.js.map +1 -0
- package/dist/chunk-DW4JPVXB.js +41 -0
- package/dist/chunk-DW4JPVXB.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-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-KA4JVX5U.js +295 -0
- package/dist/chunk-KA4JVX5U.js.map +1 -0
- package/dist/chunk-KGZ6OZ2T.js +102 -0
- package/dist/chunk-KGZ6OZ2T.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-MAGGGRSB.js +9 -0
- package/dist/chunk-MAGGGRSB.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-PZ4RG6EW.js +132 -0
- package/dist/chunk-PZ4RG6EW.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-YLG6DO5Y.js +162 -0
- package/dist/chunk-YLG6DO5Y.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-X45MA74G.js +192 -0
- package/dist/cleanup-X45MA74G.js.map +1 -0
- package/dist/cli-52VWEHIQ.js +18 -0
- package/dist/cli-52VWEHIQ.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-YU3NOW6G.js +118 -0
- package/dist/pr-YU3NOW6G.js.map +1 -0
- package/dist/prune-26FYYFTO.js +92 -0
- package/dist/prune-26FYYFTO.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-2UHJQ4DY.js +108 -0
- package/dist/remove-2UHJQ4DY.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-3CTAXM6J.js +96 -0
- package/dist/sync-3CTAXM6J.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 -11880
- package/dist/wd-bin.js.map +1 -1
- package/dist/web/assets/PtyView-BrP-ENHg.css +1 -0
- package/dist/web/assets/PtyView-M4b0GFVs.js +90 -0
- package/dist/web/assets/PtyView-M4b0GFVs.js.map +1 -0
- package/dist/web/assets/index-5hi1kMKy.js +116 -0
- package/dist/web/assets/index-5hi1kMKy.js.map +1 -0
- package/dist/web/assets/index-L8mjakHP.css +1 -0
- package/dist/web/index.html +3 -5
- package/dist/web-BI3MRQEM.js +7662 -0
- package/dist/web-BI3MRQEM.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-BgVq8Uj_.js +0 -107
- package/dist/web/assets/index-BgVq8Uj_.js.map +0 -1
- package/dist/web/assets/index-ubbitWeW.css +0 -1
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
scopeHashFor
|
|
4
|
+
} from "./chunk-ZSHWP2VS.js";
|
|
5
|
+
import {
|
|
6
|
+
readStoreComments
|
|
7
|
+
} from "./chunk-5QK7GB5K.js";
|
|
8
|
+
import {
|
|
9
|
+
loadHistory
|
|
10
|
+
} from "./chunk-M4FVCAT6.js";
|
|
11
|
+
import {
|
|
12
|
+
sessionIdFor,
|
|
13
|
+
tx,
|
|
14
|
+
withDb
|
|
15
|
+
} from "./chunk-7NCW3LUT.js";
|
|
16
|
+
|
|
17
|
+
// src/core/git/git-head.ts
|
|
18
|
+
import fs from "fs";
|
|
19
|
+
import path from "path";
|
|
20
|
+
function checkedOutBranch(checkout) {
|
|
21
|
+
try {
|
|
22
|
+
const dotGit = path.join(checkout, ".git");
|
|
23
|
+
let gitDir = dotGit;
|
|
24
|
+
if (fs.statSync(dotGit).isFile()) {
|
|
25
|
+
const m = /^gitdir:\s*(.+?)\s*$/m.exec(fs.readFileSync(dotGit, "utf8"));
|
|
26
|
+
if (!m) return null;
|
|
27
|
+
gitDir = path.resolve(checkout, m[1]);
|
|
28
|
+
}
|
|
29
|
+
return branchFromHead(fs.readFileSync(path.join(gitDir, "HEAD"), "utf8"));
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function branchFromHead(head) {
|
|
35
|
+
const m = /^ref:\s*refs\/heads\/(.+?)\s*$/m.exec(head);
|
|
36
|
+
return m ? m[1] : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/core/comments/pending-delivery.ts
|
|
40
|
+
import fs2 from "fs";
|
|
41
|
+
import path2 from "path";
|
|
42
|
+
function deliveredIds(d, sessionId) {
|
|
43
|
+
return new Set(
|
|
44
|
+
d.prepare("SELECT comment_id FROM comment_deliveries WHERE session_id = ?").all(sessionId).map(
|
|
45
|
+
(r) => r.comment_id
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
function normalize(p) {
|
|
50
|
+
return path2.resolve(p).replace(/\\/g, "/").toLowerCase();
|
|
51
|
+
}
|
|
52
|
+
function owns(candidate, current, root) {
|
|
53
|
+
if (!!candidate.archivedAt !== !!current.archivedAt) return !candidate.archivedAt;
|
|
54
|
+
const onBranch = checkedOutBranch(root);
|
|
55
|
+
const a = candidate.branch === onBranch;
|
|
56
|
+
const b = current.branch === onBranch;
|
|
57
|
+
if (a !== b) return a;
|
|
58
|
+
return (Date.parse(candidate.lastAccessedAt) || 0) > (Date.parse(current.lastAccessedAt) || 0);
|
|
59
|
+
}
|
|
60
|
+
function findSessionForCwd(cwd, sessions = loadHistory()) {
|
|
61
|
+
const here = normalize(cwd);
|
|
62
|
+
let best = null;
|
|
63
|
+
for (const s of sessions) {
|
|
64
|
+
const roots = s.isGroup && s.paths[0] ? [...s.paths, path2.dirname(s.paths[0])] : s.paths;
|
|
65
|
+
for (const root of roots) {
|
|
66
|
+
const r = normalize(root);
|
|
67
|
+
if (!(here === r || here.startsWith(r + "/"))) continue;
|
|
68
|
+
if (!best || r.length > best.len || r.length === best.len && owns(s, best.session, root)) {
|
|
69
|
+
best = { session: s, root, len: r.length };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!best) return null;
|
|
74
|
+
const own = new Set(best.session.paths.map(normalize));
|
|
75
|
+
const top = normalize(best.root);
|
|
76
|
+
for (let dir = path2.resolve(cwd); normalize(dir) !== top && normalize(dir).startsWith(top + "/"); dir = path2.dirname(dir)) {
|
|
77
|
+
if (!own.has(normalize(dir)) && fs2.existsSync(path2.join(dir, ".git"))) return null;
|
|
78
|
+
if (path2.dirname(dir) === dir) break;
|
|
79
|
+
}
|
|
80
|
+
return best.session;
|
|
81
|
+
}
|
|
82
|
+
function isPendingFor(delivered) {
|
|
83
|
+
return (c) => c.status === "published" && c.author === "user" && !delivered.has(c.id);
|
|
84
|
+
}
|
|
85
|
+
var NOTE_NUDGE = "work has new notes for you (review feedback, CI results or comments); they are attached to this message. Work through them now.";
|
|
86
|
+
function readPendingForSession(sessionId) {
|
|
87
|
+
const delivered = withDb((d) => deliveredIds(d, sessionId));
|
|
88
|
+
return readStoreComments(sessionId).filter(isPendingFor(delivered));
|
|
89
|
+
}
|
|
90
|
+
function scopeStoreIdsForPaths(paths) {
|
|
91
|
+
const resolved = paths.map((p) => path2.resolve(p));
|
|
92
|
+
const ids = /* @__PURE__ */ new Set();
|
|
93
|
+
ids.add(`scope-${scopeHashFor(resolved)}`);
|
|
94
|
+
for (const p of resolved) ids.add(`scope-${scopeHashFor([p])}`);
|
|
95
|
+
return [...ids];
|
|
96
|
+
}
|
|
97
|
+
function readPendingForWorktree(session) {
|
|
98
|
+
const sessionId = sessionIdFor(session);
|
|
99
|
+
const delivered = withDb((d) => deliveredIds(d, sessionId));
|
|
100
|
+
const pending = isPendingFor(delivered);
|
|
101
|
+
const seen = /* @__PURE__ */ new Set();
|
|
102
|
+
const out = [];
|
|
103
|
+
const collect = (storeId) => {
|
|
104
|
+
for (const c of readStoreComments(storeId)) {
|
|
105
|
+
if (seen.has(c.id) || !pending(c)) continue;
|
|
106
|
+
seen.add(c.id);
|
|
107
|
+
out.push(c);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
collect(sessionId);
|
|
111
|
+
for (const storeId of scopeStoreIdsForPaths(session.paths)) collect(storeId);
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
function claimForDelivery(sessionId, ids) {
|
|
115
|
+
if (ids.length === 0) return [];
|
|
116
|
+
return tx((d) => {
|
|
117
|
+
const ins = d.prepare("INSERT OR IGNORE INTO comment_deliveries (session_id, comment_id) VALUES (?, ?)");
|
|
118
|
+
return ids.filter((id) => ins.run(sessionId, id).changes > 0);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
var MAX_BODY_BYTES = 4 * 1024;
|
|
122
|
+
var MAX_TOTAL_BYTES = 32 * 1024;
|
|
123
|
+
function formatPendingForPrompt(pending) {
|
|
124
|
+
if (pending.length === 0) return "";
|
|
125
|
+
const sorted = [...pending].sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
126
|
+
const general = sorted.filter((c) => c.side === "general" && !c.parentId);
|
|
127
|
+
const inline = sorted.filter((c) => c.side !== "general" && !c.parentId);
|
|
128
|
+
const replies = sorted.filter((c) => c.parentId);
|
|
129
|
+
const lines = [];
|
|
130
|
+
lines.push("<system-reminder>");
|
|
131
|
+
lines.push(`New review comments from \`work web\` (${pending.length} item${pending.length === 1 ? "" : "s"}):`);
|
|
132
|
+
lines.push("");
|
|
133
|
+
if (general.length > 0) {
|
|
134
|
+
lines.push("## General notes");
|
|
135
|
+
for (const c of general) {
|
|
136
|
+
lines.push(formatFullBody("-", c));
|
|
137
|
+
}
|
|
138
|
+
lines.push("");
|
|
139
|
+
}
|
|
140
|
+
if (inline.length > 0) {
|
|
141
|
+
lines.push("## Inline comments");
|
|
142
|
+
for (const c of inline) {
|
|
143
|
+
const where = `${c.repo}/${c.file}:${c.line} (${c.side})`;
|
|
144
|
+
lines.push(formatBody(`- ${where}`, c));
|
|
145
|
+
}
|
|
146
|
+
lines.push("");
|
|
147
|
+
}
|
|
148
|
+
if (replies.length > 0) {
|
|
149
|
+
lines.push("## Replies");
|
|
150
|
+
for (const c of replies) {
|
|
151
|
+
lines.push(formatBody(`- (reply to ${c.parentId})`, c));
|
|
152
|
+
}
|
|
153
|
+
lines.push("");
|
|
154
|
+
}
|
|
155
|
+
lines.push(
|
|
156
|
+
'Address them as part of your next response. You can reply via the same review UI by posting back to the latest review URL at `~/.work/web.url` + `/api/sessions/<id>/comments` with `author: "claude"`.'
|
|
157
|
+
);
|
|
158
|
+
lines.push("</system-reminder>");
|
|
159
|
+
const out = lines.join("\n");
|
|
160
|
+
if (out.length <= MAX_TOTAL_BYTES) return out;
|
|
161
|
+
const trimmed = out.slice(0, MAX_TOTAL_BYTES - 200);
|
|
162
|
+
return trimmed + `
|
|
163
|
+
|
|
164
|
+
(\u2026review payload truncated for context-window safety; ${pending.length} comment(s) total \u2014 open work web for the full list.)
|
|
165
|
+
</system-reminder>`;
|
|
166
|
+
}
|
|
167
|
+
function formatBody(prefix, c) {
|
|
168
|
+
const lead = c.body.split("\n")[0].trim();
|
|
169
|
+
const capped = lead.length > MAX_BODY_BYTES ? `${lead.slice(0, MAX_BODY_BYTES)}\u2026` : lead;
|
|
170
|
+
return `${prefix}: ${capped}${c.body.includes("\n") ? " \u2026" : ""}`;
|
|
171
|
+
}
|
|
172
|
+
function formatFullBody(prefix, c) {
|
|
173
|
+
const body = c.body.trim();
|
|
174
|
+
const capped = body.length > MAX_BODY_BYTES ? `${body.slice(0, MAX_BODY_BYTES)}\u2026` : body;
|
|
175
|
+
const bodyLines = capped.split("\n");
|
|
176
|
+
if (bodyLines.length === 1) return `${prefix}: ${bodyLines[0]}`;
|
|
177
|
+
const [first, ...rest] = bodyLines;
|
|
178
|
+
return [`${prefix}: ${first}`, ...rest.map((l) => ` ${l}`)].join("\n");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export {
|
|
182
|
+
checkedOutBranch,
|
|
183
|
+
findSessionForCwd,
|
|
184
|
+
NOTE_NUDGE,
|
|
185
|
+
readPendingForSession,
|
|
186
|
+
readPendingForWorktree,
|
|
187
|
+
claimForDelivery,
|
|
188
|
+
formatPendingForPrompt
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=chunk-WF5SBVPZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/git/git-head.ts","../src/core/comments/pending-delivery.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\n/**\n * The branch checked out in a checkout, read from its HEAD file — no `git`\n * process, so the session list can ask for every session on every request.\n * A worktree's `.git` is a file (`gitdir: <repo>/.git/worktrees/<name>`)\n * whose HEAD names the branch; a base checkout's `.git` is the folder.\n *\n * null: detached HEAD, not a checkout, or unreadable.\n */\nexport function checkedOutBranch(checkout: string): string | null {\n try {\n const dotGit = path.join(checkout, '.git');\n let gitDir = dotGit;\n if (fs.statSync(dotGit).isFile()) {\n const m = /^gitdir:\\s*(.+?)\\s*$/m.exec(fs.readFileSync(dotGit, 'utf8'));\n if (!m) return null;\n gitDir = path.resolve(checkout, m[1]);\n }\n return branchFromHead(fs.readFileSync(path.join(gitDir, 'HEAD'), 'utf8'));\n } catch {\n return null;\n }\n}\n\n/** `ref: refs/heads/fix/x` → `fix/x`; a commit sha (detached) → null. */\nexport function branchFromHead(head: string): string | null {\n const m = /^ref:\\s*refs\\/heads\\/(.+?)\\s*$/m.exec(head);\n return m ? m[1] : null;\n}\n","/**\n * Bridge between `work web` review comments and any live Claude session\n * running in the same worktree. Storage (state.db, see db.ts):\n *\n * comments the comment stores (comment-file-store.ts)\n * comment_deliveries (session, comment id) pairs surfaced to Claude\n *\n * \"Pending\" = published, user-authored, not in the delivered list. Replies\n * authored by Claude (author === 'claude') are excluded — Claude wrote\n * them; we don't need to echo them back.\n *\n * Delivery is lazy: when a Claude in the matching worktree submits a\n * prompt, the hook reads pending comments via this module, prints them as\n * a system-reminder block to stdout (which Claude Code injects into the\n * conversation), and marks them delivered.\n */\n\nimport { checkedOutBranch } from '../git/git-head.js';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { loadHistory, type WorktreeSession } from '../sessions/history.js';\nimport { sessionIdFor } from '../sessions/session-id.js';\nimport { readStoreComments } from './comment-file-store.js';\nimport { scopeHashFor } from '../diff/repo-spec.js';\nimport { tx, withDb, type Db } from '../platform/db.js';\nimport type { Comment } from './comment-types.js';\n\nfunction deliveredIds(d: Db, sessionId: string): Set<string> {\n return new Set(\n (d.prepare('SELECT comment_id FROM comment_deliveries WHERE session_id = ?').all(sessionId) as Array<{ comment_id: string }>).map(\n (r) => r.comment_id,\n ),\n );\n}\n\n/** Norm-path comparison that mirrors what we do server-side. */\nfunction normalize(p: string): string {\n return path.resolve(p).replace(/\\\\/g, '/').toLowerCase();\n}\n\n/** Map a Claude cwd back to a session. Tries direct-match against any\n * session's path first, then ancestor match (so cwd inside a subdir of a\n * worktree still resolves to the worktree's session). */\n/**\n * Two sessions on one folder (an old entry and a newer one, a typo'd target\n * re-added): which of them a Claude there is. Not an archived one when the\n * other isn't; then the one whose branch is checked out there; then the one\n * entered last. The oldest used to win, so status and comments went to an\n * entry nobody looks at.\n */\nfunction owns(candidate: WorktreeSession, current: WorktreeSession, root: string): boolean {\n if (!!candidate.archivedAt !== !!current.archivedAt) return !candidate.archivedAt;\n const onBranch = checkedOutBranch(root);\n const a = candidate.branch === onBranch;\n const b = current.branch === onBranch;\n if (a !== b) return a;\n return (Date.parse(candidate.lastAccessedAt) || 0) > (Date.parse(current.lastAccessedAt) || 0);\n}\n\nexport function findSessionForCwd(cwd: string, sessions: WorktreeSession[] = loadHistory()): WorktreeSession | null {\n const here = normalize(cwd);\n // Deepest root containing cwd wins, so nested worktrees disambiguate. A\n // group's roots include the group root (the sub-repos' parent) — that's\n // where `work tree` launches Claude for a group, so hooks fire from there.\n let best: { session: WorktreeSession; root: string; len: number } | null = null;\n for (const s of sessions) {\n const roots = s.isGroup && s.paths[0] ? [...s.paths, path.dirname(s.paths[0])] : s.paths;\n for (const root of roots) {\n const r = normalize(root);\n if (!(here === r || here.startsWith(r + '/'))) continue;\n if (!best || r.length > best.len || (r.length === best.len && owns(s, best.session, root))) {\n best = { session: s, root, len: r.length };\n }\n }\n }\n if (!best) return null;\n // A separate checkout nested INSIDE the session's tree (a git worktree at\n // <repo>/.claude/worktrees/x, a vendored repo) is not this session: its\n // Claude must not report status, take checkpoints or receive comments as\n // if it were the parent. Any `.git` between cwd and the matched root —\n // other than the session's own repos — marks a different checkout.\n // (Plain fs checks: this runs on every hook.)\n const own = new Set(best.session.paths.map(normalize));\n const top = normalize(best.root);\n for (let dir = path.resolve(cwd); normalize(dir) !== top && normalize(dir).startsWith(top + '/'); dir = path.dirname(dir)) {\n if (!own.has(normalize(dir)) && fs.existsSync(path.join(dir, '.git'))) return null;\n if (path.dirname(dir) === dir) break;\n }\n return best.session;\n}\n\nfunction isPendingFor(delivered: Set<string>) {\n return (c: Comment) => c.status === 'published' && c.author === 'user' && !delivered.has(c.id);\n}\n\n/** Returns published user comments that haven't been delivered yet.\n * Reads through the file-store cache so we see in-flight writes\n * (`session-meta.ts` and other readers couldn't, when they re-read the\n * disk directly). */\n/**\n * The line typed into an idle Claude (or given as the first prompt of one\n * work starts) so its UserPromptSubmit hook attaches the pending comments.\n * Short on purpose: a long typed note got mangled by Claude Code's paste\n * handling. It says where the content is, so it reads right in the\n * transcript.\n */\nexport const NOTE_NUDGE =\n 'work has new notes for you (review feedback, CI results or comments); they are attached to this message. Work through them now.';\n\nexport function readPendingForSession(sessionId: string): Comment[] {\n const delivered = withDb((d) => deliveredIds(d, sessionId));\n return readStoreComments(sessionId).filter(isPendingFor(delivered));\n}\n\n/** Comment-store ids for every `wd` scope that could cover this worktree.\n * A scope is keyed by `sha1` of its sorted repo roots (see\n * `repo-spec.scopeHashFor`), so from a session's paths we can rebuild the\n * exact ids without consulting `work web`'s in-memory scope registry:\n * - the whole-set hash → a group `wd` opened at the group root, or the\n * single-repo `wd` (one path);\n * - each individual path's hash → a `wd` opened inside one sub-repo of a\n * group worktree.\n * `registerScope` hashes `path.resolve()`d roots, so we resolve here too or\n * the hashes won't line up. Mirrors `scope-manager.commentStoreIdForScope`\n * (`scope-<hash>`). */\nfunction scopeStoreIdsForPaths(paths: string[]): string[] {\n const resolved = paths.map((p) => path.resolve(p));\n const ids = new Set<string>();\n ids.add(`scope-${scopeHashFor(resolved)}`);\n for (const p of resolved) ids.add(`scope-${scopeHashFor([p])}`);\n return [...ids];\n}\n\n/**\n * Pending comments for a whole worktree: the session's own comment store\n * PLUS any `wd` / `wd -c` scope review store covering the same paths.\n *\n * `wd` registers its review under a scope-hash comment store, not the\n * session store the hook reads — without this merge, comments left in the\n * `wd` review UI would never reach the Claude running in that worktree.\n * Delivered-tracking stays per-session (one `<sessionId>.delivered.json`),\n * so a comment surfaced here won't be re-delivered regardless of which\n * store it came from.\n */\nexport function readPendingForWorktree(session: WorktreeSession): Comment[] {\n const sessionId = sessionIdFor(session);\n const delivered = withDb((d) => deliveredIds(d, sessionId));\n const pending = isPendingFor(delivered);\n const seen = new Set<string>();\n const out: Comment[] = [];\n const collect = (storeId: string) => {\n for (const c of readStoreComments(storeId)) {\n if (seen.has(c.id) || !pending(c)) continue;\n seen.add(c.id);\n out.push(c);\n }\n };\n collect(sessionId);\n for (const storeId of scopeStoreIdsForPaths(session.paths)) collect(storeId);\n return out;\n}\n\n/** Persist a delivery batch, so these ids are never surfaced again. */\nexport function markDelivered(sessionId: string, ids: string[]): void {\n if (ids.length === 0) return;\n tx((d) => {\n const ins = d.prepare('INSERT OR IGNORE INTO comment_deliveries (session_id, comment_id) VALUES (?, ?)');\n for (const id of ids) ins.run(sessionId, id);\n });\n}\n\n/**\n * Claim comments for delivery: of `ids`, return the ones nobody has\n * delivered yet, and mark them delivered — atomically. Two deliverers\n * racing (a Stop hook and the PTY push for the same comment) then can't\n * both send it: only the one that claimed it does. A deliverer whose send\n * fails gives the ids back with `releaseClaim`.\n */\nexport function claimForDelivery(sessionId: string, ids: string[]): string[] {\n if (ids.length === 0) return [];\n // INSERT OR IGNORE in one write transaction: a row inserted here is our\n // claim; one that already existed was someone else's.\n return tx((d) => {\n const ins = d.prepare('INSERT OR IGNORE INTO comment_deliveries (session_id, comment_id) VALUES (?, ?)');\n return ids.filter((id) => ins.run(sessionId, id).changes > 0);\n });\n}\n\n/** Undo a claim whose delivery failed, so the next hook picks them up. */\nexport function releaseClaim(sessionId: string, ids: string[]): void {\n if (ids.length === 0) return;\n tx((d) => {\n const del = d.prepare('DELETE FROM comment_deliveries WHERE session_id = ? AND comment_id = ?');\n for (const id of ids) del.run(sessionId, id);\n });\n}\n\n/** Cap the size of one comment body we surface to Claude. A pathologically\n * long comment shouldn't blow out Claude's context — we truncate, then\n * hint at the rest via \"(truncated)\". 4 KB is generous for a code-review\n * note while leaving headroom for batches. */\nconst MAX_BODY_BYTES = 4 * 1024;\n/** Overall cap on the whole system-reminder payload. Multiple long\n * comments at once still get bounded. */\nconst MAX_TOTAL_BYTES = 32 * 1024;\n\n/**\n * Format pending comments as a system-reminder block suitable for stdout.\n * Returns empty string when there's nothing pending — the caller (the\n * `work hook` CLI) just exits silently in that case.\n *\n * Truncates pathologically long bodies and caps the overall payload so\n * one runaway comment can't displace the rest of Claude's context.\n */\nexport function formatPendingForPrompt(pending: Comment[]): string {\n if (pending.length === 0) return '';\n\n const sorted = [...pending].sort((a, b) => a.createdAt.localeCompare(b.createdAt));\n\n const general = sorted.filter((c) => c.side === 'general' && !c.parentId);\n const inline = sorted.filter((c) => c.side !== 'general' && !c.parentId);\n const replies = sorted.filter((c) => c.parentId);\n\n const lines: string[] = [];\n lines.push('<system-reminder>');\n lines.push(`New review comments from \\`work web\\` (${pending.length} item${pending.length === 1 ? '' : 's'}):`);\n lines.push('');\n\n if (general.length > 0) {\n lines.push('## General notes');\n for (const c of general) {\n // General notes (this is where `work broadcast` lands) may be multi-line\n // prompts — deliver the whole body, not just line 1. Only the byte cap\n // applies. Inline/reply comments still use the one-line `formatBody`.\n lines.push(formatFullBody('-', c));\n }\n lines.push('');\n }\n\n if (inline.length > 0) {\n lines.push('## Inline comments');\n for (const c of inline) {\n const where = `${c.repo}/${c.file}:${c.line} (${c.side})`;\n lines.push(formatBody(`- ${where}`, c));\n }\n lines.push('');\n }\n\n if (replies.length > 0) {\n lines.push('## Replies');\n for (const c of replies) {\n lines.push(formatBody(`- (reply to ${c.parentId})`, c));\n }\n lines.push('');\n }\n\n lines.push(\n 'Address them as part of your next response. You can reply via the same review UI by posting back to the latest review URL at `~/.work/web.url` + `/api/sessions/<id>/comments` with `author: \"claude\"`.',\n );\n lines.push('</system-reminder>');\n const out = lines.join('\\n');\n if (out.length <= MAX_TOTAL_BYTES) return out;\n const trimmed = out.slice(0, MAX_TOTAL_BYTES - 200);\n return (\n trimmed +\n '\\n\\n(…review payload truncated for context-window safety; ' +\n `${pending.length} comment(s) total — open work web for the full list.)\\n` +\n '</system-reminder>'\n );\n}\n\nfunction formatBody(prefix: string, c: Comment): string {\n const lead = c.body.split('\\n')[0].trim();\n const capped = lead.length > MAX_BODY_BYTES ? `${lead.slice(0, MAX_BODY_BYTES)}…` : lead;\n return `${prefix}: ${capped}${c.body.includes('\\n') ? ' …' : ''}`;\n}\n\n/** Like `formatBody` but preserves the full multi-line body (only the byte\n * cap applies). Multi-line bodies are emitted under the bullet, indented, so\n * a broadcast prompt arrives intact rather than truncated to its first line. */\nfunction formatFullBody(prefix: string, c: Comment): string {\n const body = c.body.trim();\n const capped = body.length > MAX_BODY_BYTES ? `${body.slice(0, MAX_BODY_BYTES)}…` : body;\n const bodyLines = capped.split('\\n');\n if (bodyLines.length === 1) return `${prefix}: ${bodyLines[0]}`;\n const [first, ...rest] = bodyLines;\n return [`${prefix}: ${first}`, ...rest.map((l) => ` ${l}`)].join('\\n');\n}\n\n/** Re-export so consumers don't have to know which module owns it. */\nexport { sessionIdFor };\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAUV,SAAS,iBAAiB,UAAiC;AAChE,MAAI;AACF,UAAM,SAAS,KAAK,KAAK,UAAU,MAAM;AACzC,QAAI,SAAS;AACb,QAAI,GAAG,SAAS,MAAM,EAAE,OAAO,GAAG;AAChC,YAAM,IAAI,wBAAwB,KAAK,GAAG,aAAa,QAAQ,MAAM,CAAC;AACtE,UAAI,CAAC,EAAG,QAAO;AACf,eAAS,KAAK,QAAQ,UAAU,EAAE,CAAC,CAAC;AAAA,IACtC;AACA,WAAO,eAAe,GAAG,aAAa,KAAK,KAAK,QAAQ,MAAM,GAAG,MAAM,CAAC;AAAA,EAC1E,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,eAAe,MAA6B;AAC1D,QAAM,IAAI,kCAAkC,KAAK,IAAI;AACrD,SAAO,IAAI,EAAE,CAAC,IAAI;AACpB;;;ACZA,OAAOA,SAAQ;AACf,OAAOC,WAAU;AAQjB,SAAS,aAAa,GAAO,WAAgC;AAC3D,SAAO,IAAI;AAAA,IACR,EAAE,QAAQ,gEAAgE,EAAE,IAAI,SAAS,EAAoC;AAAA,MAC5H,CAAC,MAAM,EAAE;AAAA,IACX;AAAA,EACF;AACF;AAGA,SAAS,UAAU,GAAmB;AACpC,SAAOC,MAAK,QAAQ,CAAC,EAAE,QAAQ,OAAO,GAAG,EAAE,YAAY;AACzD;AAYA,SAAS,KAAK,WAA4B,SAA0B,MAAuB;AACzF,MAAI,CAAC,CAAC,UAAU,eAAe,CAAC,CAAC,QAAQ,WAAY,QAAO,CAAC,UAAU;AACvE,QAAM,WAAW,iBAAiB,IAAI;AACtC,QAAM,IAAI,UAAU,WAAW;AAC/B,QAAM,IA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AE,QAAQ,KAAK,CAAC,CAAC;AAAA,IACxD;AACA,UAAM,KAAK,EAAE;AAAA,EACf;AAEA,QAAM;AAAA,IACJ;AAAA,EACF;AACA,QAAM,KAAK,oBAAoB;AAC/B,QAAM,MAAM,MAAM,KAAK,IAAI;AAC3B,MAAI,IAAI,UAAU,gBAAiB,QAAO;AAC1C,QAAM,UAAU,IAAI,MAAM,GAAG,kBAAkB,GAAG;AAClD,SACE,UACA;AAAA;AAAA,6DACG,QAAQ,MAAM;AAAA;AAGrB;AAEA,SAAS,WAAW,QAAgB,GAAoB;AACtD,QAAM,OAAO,EAAE,KAAK,MAAM,IAAI,EAAE,CAAC,EAAE,KAAK;AACxC,QAAM,SAAS,KAAK,SAAS,iBAAiB,GAAG,KAAK,MAAM,GAAG,cAAc,CAAC,WAAM;AACpF,SAAO,GAAG,MAAM,KAAK,MAAM,GAAG,EAAE,KAAK,SAAS,IAAI,IAAI,YAAO,EAAE;AACjE;AAKA,SAAS,eAAe,QAAgB,GAAoB;AAC1D,QAAM,OAAO,EAAE,KAAK,KAAK;AACzB,QAAM,SAAS,KAAK,SAAS,iBAAiB,GAAG,KAAK,MAAM,GAAG,cAAc,CAAC,WAAM;AACpF,QAAM,YAAY,OAAO,MAAM,IAAI;AACnC,MAAI,UAAU,WAAW,EAAG,QAAO,GAAG,MAAM,KAAK,UAAU,CAAC,CAAC;AAC7D,QAAM,CAAC,OAAO,GAAG,IAAI,IAAI;AACzB,SAAO,CAAC,GAAG,MAAM,KAAK,KAAK,IAAI,GAAG,KAAK,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC,EAAE,KAAK,IAAI;AACxE;","names":["fs","path","path","fs"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/core/sessions/fleet.ts
|
|
4
|
+
function selectSessions(sessions, filter) {
|
|
5
|
+
return sessions.filter((s) => {
|
|
6
|
+
if (filter.target && s.target !== filter.target) return false;
|
|
7
|
+
if (filter.branch && s.branch !== filter.branch) return false;
|
|
8
|
+
return true;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function expandRunUnits(sessions) {
|
|
12
|
+
const units = [];
|
|
13
|
+
for (const session of sessions) {
|
|
14
|
+
for (const p of session.paths) {
|
|
15
|
+
units.push({ session, path: p });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return units;
|
|
19
|
+
}
|
|
20
|
+
function anyFailed(results) {
|
|
21
|
+
return results.some((r) => !r.ok);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
selectSessions,
|
|
26
|
+
expandRunUnits,
|
|
27
|
+
anyFailed
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=chunk-WMJIU3YW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/sessions/fleet.ts"],"sourcesContent":["/**\n * Shared selection logic for the fleet commands (`work run`, `work broadcast`).\n * Pure helpers so command files stay thin and the filtering is unit-testable.\n *\n * Direction: core does NOT import from commands. Commands import these.\n */\n\nimport type { WorktreeSession } from './history.js';\n\nexport interface FleetFilter {\n /** Restrict to sessions whose target matches this alias/group name. */\n target?: string;\n /** With `target`, further restrict to a single branch. */\n branch?: string;\n}\n\n/**\n * Select the sessions a fleet command should act on.\n *\n * - No filter → every session.\n * - `target` only → all sessions for that target.\n * - `target` + `branch` → the single matching session (if any).\n *\n * `branch` without `target` is ignored for selection but the caller is\n * expected to reject that combination up front (it's ambiguous).\n */\nexport function selectSessions(sessions: WorktreeSession[], filter: FleetFilter): WorktreeSession[] {\n return sessions.filter((s) => {\n if (filter.target && s.target !== filter.target) return false;\n if (filter.branch && s.branch !== filter.branch) return false;\n return true;\n });\n}\n\nexport interface RunUnit {\n session: WorktreeSession;\n /** A single worktree directory to run the command in. */\n path: string;\n}\n\n/**\n * Flatten selected sessions into one unit of work per worktree path. Group\n * sessions contribute one unit per path. Order is stable (session order,\n * then path order) so sequential runs are deterministic.\n */\nexport function expandRunUnits(sessions: WorktreeSession[]): RunUnit[] {\n const units: RunUnit[] = [];\n for (const session of sessions) {\n for (const p of session.paths) {\n units.push({ session, path: p });\n }\n }\n return units;\n}\n\nexport interface RunResult extends RunUnit {\n /** Exit code; null when the process was killed by a signal. */\n code: number | null;\n ok: boolean;\n}\n\n/** True when any unit failed (non-zero / signalled). */\nexport function anyFailed(results: RunResult[]): boolean {\n return results.some((r) => !r.ok);\n}\n"],"mappings":";;;AA0BO,SAAS,eAAe,UAA6B,QAAwC;AAClG,SAAO,SAAS,OAAO,CAAC,MAAM;AAC5B,QAAI,OAAO,UAAU,EAAE,WAAW,OAAO,OAAQ,QAAO;AACxD,QAAI,OAAO,UAAU,EAAE,WAAW,OAAO,OAAQ,QAAO;AACxD,WAAO;AAAA,EACT,CAAC;AACH;AAaO,SAAS,eAAe,UAAwC;AACrE,QAAM,QAAmB,CAAC;AAC1B,aAAW,WAAW,UAAU;AAC9B,eAAW,KAAK,QAAQ,OAAO;AAC7B,YAAM,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;AAAA,IACjC;AAAA,EACF;AACA,SAAO;AACT;AASO,SAAS,UAAU,SAA+B;AACvD,SAAO,QAAQ,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE;AAClC;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
readStatus
|
|
4
|
+
} from "./chunk-M4FVCAT6.js";
|
|
5
|
+
|
|
6
|
+
// src/commands/shared/turn-wait.ts
|
|
7
|
+
var cliWaitDeps = {
|
|
8
|
+
status: (id) => {
|
|
9
|
+
const s = readStatus(id);
|
|
10
|
+
return s ? { state: s.state, since: s.since, ...s.summary ? { summary: s.summary } : {} } : null;
|
|
11
|
+
},
|
|
12
|
+
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
13
|
+
now: () => Date.now()
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
cliWaitDeps
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-XJDEROHY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/shared/turn-wait.ts"],"sourcesContent":["import { readStatus } from '../../core/status/session-status.js';\nimport type { WaitDeps } from '../../core/sessions/session-control.js';\n\n/** waitForTurn's I/O for the CLI: the hook-recorded status in state.db, polled. */\nexport const cliWaitDeps: WaitDeps = {\n status: (id) => {\n const s = readStatus(id);\n return s ? { state: s.state, since: s.since, ...(s.summary ? { summary: s.summary } : {}) } : null;\n },\n sleep: (ms) => new Promise((r) => setTimeout(r, ms)),\n now: () => Date.now(),\n};\n"],"mappings":";;;;;;AAIO,IAAM,cAAwB;AAAA,EACnC,QAAQ,CAAC,OAAO;AACd,UAAM,IAAI,WAAW,EAAE;AACvB,WAAO,IAAI,EAAE,OAAO,EAAE,OAAO,OAAO,EAAE,OAAO,GAAI,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,IAAI,CAAC,EAAG,IAAI;AAAA,EAChG;AAAA,EACA,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAAA,EACnD,KAAK,MAAM,KAAK,IAAI;AACtB;","names":[]}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
mergeSteps,
|
|
4
|
+
workSteps,
|
|
5
|
+
workedBetween,
|
|
6
|
+
workedByDay,
|
|
7
|
+
worklogTime
|
|
8
|
+
} from "./chunk-M4FVCAT6.js";
|
|
9
|
+
import {
|
|
10
|
+
json,
|
|
11
|
+
tx,
|
|
12
|
+
withDb
|
|
13
|
+
} from "./chunk-7NCW3LUT.js";
|
|
14
|
+
import {
|
|
15
|
+
agentOf
|
|
16
|
+
} from "./chunk-PN44M5EE.js";
|
|
17
|
+
|
|
18
|
+
// src/core/jira/jira-worklog.ts
|
|
19
|
+
function worklogSettings(config, env = process.env) {
|
|
20
|
+
const w = config?.jiraWorklog;
|
|
21
|
+
if (!w?.site || !w.email) return null;
|
|
22
|
+
const site = w.site.replace(/^https?:\/\//, "").replace(/\/.*$/, "");
|
|
23
|
+
if (!/^[a-z0-9.-]+$/i.test(site)) return null;
|
|
24
|
+
const token = w.token ?? env[w.tokenEnv ?? "JIRA_API_TOKEN"];
|
|
25
|
+
return token ? { site, email: w.email, token } : null;
|
|
26
|
+
}
|
|
27
|
+
var isIssueKey = (k) => /^[A-Z][A-Z0-9_]+-\d+$/.test(k);
|
|
28
|
+
function jiraStarted(d) {
|
|
29
|
+
const pad = (n, w = 2) => String(Math.abs(n)).padStart(w, "0");
|
|
30
|
+
const off = -d.getTimezoneOffset();
|
|
31
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}.000${off >= 0 ? "+" : "-"}${pad(Math.floor(Math.abs(off) / 60))}${pad(Math.abs(off) % 60)}`;
|
|
32
|
+
}
|
|
33
|
+
var quarterSeconds = (ms) => Math.max(1, Math.ceil(ms / (15 * 6e4))) * 15 * 60;
|
|
34
|
+
var CLAIM_MS = 2 * 6e4;
|
|
35
|
+
function readDay(db, sessionId, day) {
|
|
36
|
+
const r = db.prepare("SELECT data FROM worklogs WHERE session_id = ? AND day = ?").get(sessionId, day);
|
|
37
|
+
const v = r ? json.parse(r.data) : null;
|
|
38
|
+
return v && typeof v.seconds === "number" && typeof v.issueKey === "string" && Array.isArray(v.ids) ? v : null;
|
|
39
|
+
}
|
|
40
|
+
function writeDay(db, sessionId, day, v) {
|
|
41
|
+
db.prepare("INSERT OR REPLACE INTO worklogs (session_id, day, data) VALUES (?, ?, ?)").run(sessionId, day, JSON.stringify(v));
|
|
42
|
+
}
|
|
43
|
+
function loggedDays(sessionId) {
|
|
44
|
+
const rows = withDb(
|
|
45
|
+
(d) => d.prepare("SELECT day, data FROM worklogs WHERE session_id = ?").all(sessionId)
|
|
46
|
+
);
|
|
47
|
+
const out = {};
|
|
48
|
+
for (const r of rows) {
|
|
49
|
+
const v = json.parse(r.data);
|
|
50
|
+
if (v && typeof v.seconds === "number" && typeof v.issueKey === "string") out[r.day] = v;
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
async function logWorkDay(sessionId, issueKey, day, ms, post, now = /* @__PURE__ */ new Date()) {
|
|
55
|
+
if (!isIssueKey(issueKey)) return { ok: false, status: 400, error: `not a Jira issue key: ${issueKey}` };
|
|
56
|
+
if (ms < 6e4) return { ok: false, status: 409, error: "no work that day to log" };
|
|
57
|
+
const total = quarterSeconds(ms);
|
|
58
|
+
const claim = tx((db) => {
|
|
59
|
+
const prev2 = readDay(db, sessionId, day);
|
|
60
|
+
if (prev2?.postingUntil && Date.parse(prev2.postingUntil) > now.getTime()) return { busy: true };
|
|
61
|
+
const already2 = prev2 && prev2.issueKey === issueKey ? prev2.seconds : 0;
|
|
62
|
+
const more2 = total - already2;
|
|
63
|
+
if (more2 <= 0) return { already: already2, more: more2 };
|
|
64
|
+
const held = {
|
|
65
|
+
...prev2 ?? { issueKey, seconds: 0, ids: [], at: now.toISOString() },
|
|
66
|
+
postingUntil: new Date(now.getTime() + CLAIM_MS).toISOString()
|
|
67
|
+
};
|
|
68
|
+
writeDay(db, sessionId, day, held);
|
|
69
|
+
return { prev: prev2, already: already2, more: more2 };
|
|
70
|
+
});
|
|
71
|
+
if ("busy" in claim) return { ok: false, status: 409, error: `already being logged for ${day}` };
|
|
72
|
+
const { already, more } = claim;
|
|
73
|
+
if (more <= 0) return { ok: false, status: 409, error: `already logged (${worklogTime(already * 1e3)} on ${day})` };
|
|
74
|
+
const prev = claim.prev;
|
|
75
|
+
const [y, m, d] = day.split("-").map(Number);
|
|
76
|
+
const started = new Date(y, m - 1, d, 9, 0, 0);
|
|
77
|
+
let id;
|
|
78
|
+
try {
|
|
79
|
+
id = await post(issueKey, {
|
|
80
|
+
timeSpentSeconds: more,
|
|
81
|
+
started: jiraStarted(started),
|
|
82
|
+
comment: {
|
|
83
|
+
type: "doc",
|
|
84
|
+
version: 1,
|
|
85
|
+
content: [{ type: "paragraph", content: [{ type: "text", text: "Logged from work (Claude Code session time)" }] }]
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
} catch (err) {
|
|
89
|
+
tx((db) => {
|
|
90
|
+
if (prev) writeDay(db, sessionId, day, prev);
|
|
91
|
+
else db.prepare("DELETE FROM worklogs WHERE session_id = ? AND day = ?").run(sessionId, day);
|
|
92
|
+
});
|
|
93
|
+
return { ok: false, status: 502, error: `Jira refused it: ${err.message}` };
|
|
94
|
+
}
|
|
95
|
+
tx(
|
|
96
|
+
(db) => writeDay(db, sessionId, day, {
|
|
97
|
+
issueKey,
|
|
98
|
+
seconds: already + more,
|
|
99
|
+
ids: [...prev?.issueKey === issueKey ? prev.ids : [], id],
|
|
100
|
+
at: now.toISOString()
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
return { ok: true, logged: more, total: already + more, text: `${worklogTime(more * 1e3)} logged on ${issueKey} for ${day}` };
|
|
104
|
+
}
|
|
105
|
+
function jiraWorklogPoster(s, fetchImpl = fetch) {
|
|
106
|
+
return async (issueKey, body) => {
|
|
107
|
+
if (!isIssueKey(issueKey)) throw new Error(`not a Jira issue key: ${issueKey}`);
|
|
108
|
+
const res = await fetchImpl(`https://${s.site}/rest/api/3/issue/${issueKey}/worklog`, {
|
|
109
|
+
method: "POST",
|
|
110
|
+
headers: {
|
|
111
|
+
Authorization: `Basic ${Buffer.from(`${s.email}:${s.token}`).toString("base64")}`,
|
|
112
|
+
"Content-Type": "application/json",
|
|
113
|
+
Accept: "application/json"
|
|
114
|
+
},
|
|
115
|
+
body: JSON.stringify(body)
|
|
116
|
+
});
|
|
117
|
+
if (!res.ok) throw new Error(`${res.status} ${(await res.text().catch(() => "")).slice(0, 200)}`);
|
|
118
|
+
const out = await res.json().catch(() => ({}));
|
|
119
|
+
return typeof out.id === "string" ? out.id : "";
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/core/conversations/work-time-source.ts
|
|
124
|
+
import fs from "fs";
|
|
125
|
+
var CHUNK = 1 << 20;
|
|
126
|
+
var DAYS_SHOWN = 14;
|
|
127
|
+
var MAX_FILES = 400;
|
|
128
|
+
var HEAD_BYTES = 256;
|
|
129
|
+
var files = /* @__PURE__ */ new Map();
|
|
130
|
+
async function readHead(fh, size) {
|
|
131
|
+
const buf = Buffer.alloc(Math.min(HEAD_BYTES, size));
|
|
132
|
+
const { bytesRead } = await fh.read(buf, 0, buf.length, 0);
|
|
133
|
+
return buf.subarray(0, bytesRead).toString("base64");
|
|
134
|
+
}
|
|
135
|
+
async function readOn(file, size, mtimeMs, st, toEntries) {
|
|
136
|
+
const fh = await fs.promises.open(file, "r");
|
|
137
|
+
try {
|
|
138
|
+
const head = await readHead(fh, size);
|
|
139
|
+
const appended = !!st && size >= st.offset && !(size === st.offset && mtimeMs !== st.mtimeMs) && head.startsWith(st.head.slice(0, head.length)) && st.head.startsWith(head.slice(0, st.head.length));
|
|
140
|
+
const state = appended ? { ...st, steps: [...st.steps], mtimeMs, head } : { offset: 0, mtimeMs, lastMs: null, steps: [], prompts: 0, firstMs: null, head };
|
|
141
|
+
let carry = Buffer.alloc(0);
|
|
142
|
+
while (state.offset + carry.length < size) {
|
|
143
|
+
const at = state.offset + carry.length;
|
|
144
|
+
const buf = Buffer.alloc(Math.min(CHUNK, size - at));
|
|
145
|
+
const { bytesRead } = await fh.read(buf, 0, buf.length, at);
|
|
146
|
+
if (bytesRead === 0) break;
|
|
147
|
+
const data = Buffer.concat([carry, buf.subarray(0, bytesRead)]);
|
|
148
|
+
const cut = data.lastIndexOf(10);
|
|
149
|
+
if (cut === -1) {
|
|
150
|
+
carry = data;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const whole = data.subarray(0, cut).toString("utf8");
|
|
154
|
+
carry = data.subarray(cut + 1);
|
|
155
|
+
state.offset += cut + 1;
|
|
156
|
+
const lines = [];
|
|
157
|
+
for (const line of whole.split("\n")) {
|
|
158
|
+
if (!line.trim()) continue;
|
|
159
|
+
try {
|
|
160
|
+
lines.push(JSON.parse(line));
|
|
161
|
+
} catch {
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const entries = toEntries(lines);
|
|
165
|
+
const r = workSteps(entries, state.lastMs);
|
|
166
|
+
state.steps.push(...r.steps);
|
|
167
|
+
state.lastMs = r.lastMs;
|
|
168
|
+
if (state.firstMs === null) {
|
|
169
|
+
const first = entries.find((e) => Number.isFinite(Date.parse(e.at)));
|
|
170
|
+
if (first) state.firstMs = Date.parse(first.at);
|
|
171
|
+
}
|
|
172
|
+
state.prompts += entries.filter((e) => e.role === "you" && !e.sidechain).length;
|
|
173
|
+
await new Promise((r2) => setImmediate(r2));
|
|
174
|
+
}
|
|
175
|
+
return state;
|
|
176
|
+
} finally {
|
|
177
|
+
await fh.close();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async function sessionWorkTime(s, now = Date.now()) {
|
|
181
|
+
const steps = [];
|
|
182
|
+
let prompts = 0;
|
|
183
|
+
let firstMs = null;
|
|
184
|
+
let lastMs = null;
|
|
185
|
+
const conv = agentOf(s).conversation;
|
|
186
|
+
for (const t of conv?.files(s) ?? []) {
|
|
187
|
+
let st = files.get(t.file);
|
|
188
|
+
if (!st || st.offset !== t.size || st.mtimeMs !== t.mtimeMs) {
|
|
189
|
+
try {
|
|
190
|
+
st = await readOn(t.file, t.size, t.mtimeMs, st, conv.entries);
|
|
191
|
+
} catch {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
files.delete(t.file);
|
|
196
|
+
files.set(t.file, st);
|
|
197
|
+
while (files.size > MAX_FILES) files.delete(files.keys().next().value);
|
|
198
|
+
steps.push(...st.steps);
|
|
199
|
+
prompts += st.prompts;
|
|
200
|
+
if (st.firstMs !== null) firstMs = firstMs === null ? st.firstMs : Math.min(firstMs, st.firstMs);
|
|
201
|
+
if (st.lastMs !== null) lastMs = lastMs === null ? st.lastMs : Math.max(lastMs, st.lastMs);
|
|
202
|
+
}
|
|
203
|
+
const since = now - DAYS_SHOWN * 24 * 36e5;
|
|
204
|
+
const merged = mergeSteps(steps);
|
|
205
|
+
return {
|
|
206
|
+
workedMs: workedBetween(merged),
|
|
207
|
+
prompts,
|
|
208
|
+
byDay: workedByDay(merged, since),
|
|
209
|
+
firstAt: firstMs === null ? null : new Date(firstMs).toISOString(),
|
|
210
|
+
lastAt: lastMs === null ? null : new Date(lastMs).toISOString()
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export {
|
|
215
|
+
worklogSettings,
|
|
216
|
+
loggedDays,
|
|
217
|
+
logWorkDay,
|
|
218
|
+
jiraWorklogPoster,
|
|
219
|
+
sessionWorkTime
|
|
220
|
+
};
|
|
221
|
+
//# sourceMappingURL=chunk-YKODIG22.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/jira/jira-worklog.ts","../src/core/conversations/work-time-source.ts"],"sourcesContent":["import { json, tx, withDb, type Db } from '../platform/db.js';\nimport type { WorkConfig } from '../platform/config.js';\nimport { worklogTime } from '../conversations/work-time-view.js';\n\n/**\n * Writing a session's worked time (work-time.ts) to its Jira issue as a\n * worklog — `acli` has no worklog command, so this talks to Jira's REST API\n * with an API token from config `jiraWorklog` (the token from an environment\n * variable by default; it never leaves the server). What was logged per day\n * is kept (state.db `worklogs`, gone with the session), so asking again logs\n * only what was added since, and never the same time twice.\n */\n\nexport interface WorklogSettings {\n /** The Jira site: `acme.atlassian.net` (https only). */\n site: string;\n email: string;\n token: string;\n}\n\n/** The settings, when complete: `jiraWorklog: { site, email, tokenEnv? (default JIRA_API_TOKEN) | token? }`. */\nexport function worklogSettings(config: WorkConfig | null, env: NodeJS.ProcessEnv = process.env): WorklogSettings | null {\n const w = config?.jiraWorklog;\n if (!w?.site || !w.email) return null;\n const site = w.site.replace(/^https?:\\/\\//, '').replace(/\\/.*$/, '');\n if (!/^[a-z0-9.-]+$/i.test(site)) return null;\n const token = w.token ?? env[w.tokenEnv ?? 'JIRA_API_TOKEN'];\n return token ? { site, email: w.email, token } : null;\n}\n\n/** A Jira issue key (`PAY-12`); the URL path is built from it, so nothing else passes. Pure. */\nexport const isIssueKey = (k: string): boolean => /^[A-Z][A-Z0-9_]+-\\d+$/.test(k);\n\n/** Jira's `started`: local time with its offset (\"2026-10-01T09:00:00.000+0200\"). Pure. */\nexport function jiraStarted(d: Date): string {\n const pad = (n: number, w = 2) => String(Math.abs(n)).padStart(w, '0');\n const off = -d.getTimezoneOffset();\n return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}.000${off >= 0 ? '+' : '-'}${pad(Math.floor(Math.abs(off) / 60))}${pad(Math.abs(off) % 60)}`;\n}\n\n/** Rounded up to a quarter of an hour, in seconds (what worklogTime says). Pure. */\nexport const quarterSeconds = (ms: number): number => Math.max(1, Math.ceil(ms / (15 * 60_000))) * 15 * 60;\n\nexport interface LoggedDay {\n issueKey: string;\n seconds: number;\n ids: string[];\n at: string;\n /** A call is posting this day to Jira until then (the claim, logWorkDay). */\n postingUntil?: string;\n}\n\n/** How long a claim holds: past it, a call that died mid-post no longer blocks the day. */\nconst CLAIM_MS = 2 * 60_000;\n\nfunction readDay(db: Db, sessionId: string, day: string): LoggedDay | null {\n const r = db.prepare('SELECT data FROM worklogs WHERE session_id = ? AND day = ?').get(sessionId, day) as { data: string } | undefined;\n const v = r ? (json.parse(r.data) as LoggedDay | null) : null;\n return v && typeof v.seconds === 'number' && typeof v.issueKey === 'string' && Array.isArray(v.ids) ? v : null;\n}\n\nfunction writeDay(db: Db, sessionId: string, day: string, v: LoggedDay): void {\n db.prepare('INSERT OR REPLACE INTO worklogs (session_id, day, data) VALUES (?, ?, ?)').run(sessionId, day, JSON.stringify(v));\n}\n\nexport function loggedDays(sessionId: string): Record<string, LoggedDay> {\n const rows = withDb(\n (d) => d.prepare('SELECT day, data FROM worklogs WHERE session_id = ?').all(sessionId) as Array<{ day: string; data: string }>,\n );\n const out: Record<string, LoggedDay> = {};\n for (const r of rows) {\n const v = json.parse(r.data) as LoggedDay | null;\n if (v && typeof v.seconds === 'number' && typeof v.issueKey === 'string') out[r.day] = v;\n }\n return out;\n}\n\nexport type WorklogResult =\n { ok: true; logged: number; total: number; text: string } | { ok: false; status: 400 | 409 | 502; error: string };\n\n/**\n * Log a day's work (`ms`, from work-time) to `issueKey`: what isn't logged\n * yet for that day, rounded up to a quarter hour. `post` sends one worklog\n * (Jira's REST API), returning its id.\n */\nexport async function logWorkDay(\n sessionId: string,\n issueKey: string,\n day: string,\n ms: number,\n post: (issueKey: string, body: { timeSpentSeconds: number; started: string; comment: unknown }) => Promise<string>,\n now = new Date(),\n): Promise<WorklogResult> {\n if (!isIssueKey(issueKey)) return { ok: false, status: 400, error: `not a Jira issue key: ${issueKey}` };\n if (ms < 60_000) return { ok: false, status: 409, error: 'no work that day to log' };\n const total = quarterSeconds(ms);\n // Claim the day before posting (a tx can't span the await): a second call\n // — another tab, `work time --log` beside the dashboard — sees the claim\n // and refuses instead of posting the same time to Jira again.\n const claim = tx((db) => {\n const prev = readDay(db, sessionId, day);\n if (prev?.postingUntil && Date.parse(prev.postingUntil) > now.getTime()) return { busy: true as const };\n const already = prev && prev.issueKey === issueKey ? prev.seconds : 0;\n const more = total - already;\n if (more <= 0) return { already, more };\n const held: LoggedDay = {\n ...(prev ?? { issueKey, seconds: 0, ids: [], at: now.toISOString() }),\n postingUntil: new Date(now.getTime() + CLAIM_MS).toISOString(),\n };\n writeDay(db, sessionId, day, held);\n return { prev, already, more };\n });\n if ('busy' in claim) return { ok: false, status: 409, error: `already being logged for ${day}` };\n const { already, more } = claim;\n if (more <= 0) return { ok: false, status: 409, error: `already logged (${worklogTime(already * 1000)} on ${day})` };\n const prev = claim.prev;\n const [y, m, d] = day.split('-').map(Number);\n const started = new Date(y, m - 1, d, 9, 0, 0);\n let id: string;\n try {\n id = await post(issueKey, {\n timeSpentSeconds: more,\n started: jiraStarted(started),\n comment: {\n type: 'doc',\n version: 1,\n content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Logged from work (Claude Code session time)' }] }],\n },\n });\n } catch (err) {\n // Let go of the claim: the day is as it was.\n tx((db) => {\n if (prev) writeDay(db, sessionId, day, prev);\n else db.prepare('DELETE FROM worklogs WHERE session_id = ? AND day = ?').run(sessionId, day);\n });\n return { ok: false, status: 502, error: `Jira refused it: ${(err as Error).message}` };\n }\n tx((db) =>\n writeDay(db, sessionId, day, {\n issueKey,\n seconds: already + more,\n ids: [...(prev?.issueKey === issueKey ? prev.ids : []), id],\n at: now.toISOString(),\n }),\n );\n return { ok: true, logged: more, total: already + more, text: `${worklogTime(more * 1000)} logged on ${issueKey} for ${day}` };\n}\n\n/** Jira's REST call for one worklog (fetch; https; basic auth with the API token). */\nexport function jiraWorklogPoster(s: WorklogSettings, fetchImpl: typeof fetch = fetch) {\n return async (issueKey: string, body: unknown): Promise<string> => {\n if (!isIssueKey(issueKey)) throw new Error(`not a Jira issue key: ${issueKey}`);\n const res = await fetchImpl(`https://${s.site}/rest/api/3/issue/${issueKey}/worklog`, {\n method: 'POST',\n headers: {\n Authorization: `Basic ${Buffer.from(`${s.email}:${s.token}`).toString('base64')}`,\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n },\n body: JSON.stringify(body),\n });\n if (!res.ok) throw new Error(`${res.status} ${(await res.text().catch(() => '')).slice(0, 200)}`);\n const out = (await res.json().catch(() => ({}))) as { id?: unknown };\n return typeof out.id === 'string' ? out.id : '';\n };\n}\n","import fs from 'node:fs';\nimport { agentOf } from '../agents/index.js';\nimport type { ConversationEntry } from '../agents/types.js';\nimport type { WorktreeSession } from '../sessions/session-types.js';\nimport { mergeSteps, workedBetween, workedByDay, workSteps, type WorkStep } from './work-time.js';\nimport type { WorkTimeWire } from '../api-types.js';\n\n/**\n * A session's Claude working time (work-time.ts) from all its transcripts.\n * Each file is read once, then only what was appended since — a transcript\n * only grows; one that shrank, changed without growing, or whose first bytes\n * differ was rewritten, and is read again — a megabyte at a time with a pause\n * between, so a long conversation doesn't hold up the server. Kept in memory\n * (two numbers per step), at most MAX_FILES files, the least recently asked\n * about going first: cheap to rebuild.\n */\n\nconst CHUNK = 1 << 20;\nconst DAYS_SHOWN = 14;\nconst MAX_FILES = 400;\n/** How much of a file's start identifies it (a rewrite starts differently). */\nconst HEAD_BYTES = 256;\n\ninterface FileState {\n /** Bytes read up to the last complete line. */\n offset: number;\n mtimeMs: number;\n lastMs: number | null;\n steps: WorkStep[];\n prompts: number;\n firstMs: number | null;\n /** Its first bytes, as read. */\n head: string;\n}\n\nconst files = new Map<string, FileState>();\n\nasync function readHead(fh: fs.promises.FileHandle, size: number): Promise<string> {\n const buf = Buffer.alloc(Math.min(HEAD_BYTES, size));\n const { bytesRead } = await fh.read(buf, 0, buf.length, 0);\n return buf.subarray(0, bytesRead).toString('base64');\n}\n\n/** Read what was appended to `file` since `st` (or all of it), line by line. */\nasync function readOn(\n file: string,\n size: number,\n mtimeMs: number,\n st: FileState | undefined,\n toEntries: (lines: readonly unknown[]) => ConversationEntry[],\n): Promise<FileState> {\n const fh = await fs.promises.open(file, 'r');\n try {\n const head = await readHead(fh, size);\n // Appended to, or rewritten? An append grows it and leaves its start as it was.\n const appended =\n !!st &&\n size >= st.offset &&\n !(size === st.offset && mtimeMs !== st.mtimeMs) &&\n head.startsWith(st.head.slice(0, head.length)) &&\n st.head.startsWith(head.slice(0, st.head.length));\n const state: FileState = appended\n ? { ...st!, steps: [...st!.steps], mtimeMs, head }\n : { offset: 0, mtimeMs, lastMs: null, steps: [], prompts: 0, firstMs: null, head };\n // Bytes read past the last newline (kept as bytes: a character can be cut in two).\n let carry = Buffer.alloc(0);\n while (state.offset + carry.length < size) {\n const at = state.offset + carry.length;\n const buf = Buffer.alloc(Math.min(CHUNK, size - at));\n const { bytesRead } = await fh.read(buf, 0, buf.length, at);\n if (bytesRead === 0) break;\n const data = Buffer.concat([carry, buf.subarray(0, bytesRead)]);\n const cut = data.lastIndexOf(0x0a);\n // An incomplete last line stays for the next read (the file is being written).\n if (cut === -1) {\n carry = data;\n continue;\n }\n const whole = data.subarray(0, cut).toString('utf8');\n carry = data.subarray(cut + 1);\n state.offset += cut + 1;\n const lines: unknown[] = [];\n for (const line of whole.split('\\n')) {\n if (!line.trim()) continue;\n try {\n lines.push(JSON.parse(line));\n } catch {\n /* a torn or foreign line: skip it */\n }\n }\n const entries = toEntries(lines);\n const r = workSteps(entries, state.lastMs);\n state.steps.push(...r.steps);\n state.lastMs = r.lastMs;\n if (state.firstMs === null) {\n const first = entries.find((e) => Number.isFinite(Date.parse(e.at)));\n if (first) state.firstMs = Date.parse(first.at);\n }\n state.prompts += entries.filter((e) => e.role === 'you' && !e.sidechain).length;\n // Let the server breathe between megabytes.\n await new Promise((r2) => setImmediate(r2));\n }\n return state;\n } finally {\n await fh.close();\n }\n}\n\n/** How long the session's Claude worked: in all, per day (the last two weeks), and the prompts it was given. */\nexport async function sessionWorkTime(s: WorktreeSession, now = Date.now()): Promise<WorkTimeWire> {\n const steps: WorkStep[] = [];\n let prompts = 0;\n let firstMs: number | null = null;\n let lastMs: number | null = null;\n const conv = agentOf(s).conversation;\n for (const t of conv?.files(s) ?? []) {\n let st = files.get(t.file);\n if (!st || st.offset !== t.size || st.mtimeMs !== t.mtimeMs) {\n try {\n st = await readOn(t.file, t.size, t.mtimeMs, st, conv!.entries);\n } catch {\n continue; // gone or unreadable: count what can be read\n }\n }\n // Most recently asked about last; the oldest go past MAX_FILES.\n files.delete(t.file);\n files.set(t.file, st);\n while (files.size > MAX_FILES) files.delete(files.keys().next().value!);\n steps.push(...st.steps);\n prompts += st.prompts;\n if (st.firstMs !== null) firstMs = firstMs === null ? st.firstMs : Math.min(firstMs, st.firstMs);\n if (st.lastMs !== null) lastMs = lastMs === null ? st.lastMs : Math.max(lastMs, st.lastMs);\n }\n const since = now - DAYS_SHOWN * 24 * 3600_000;\n // Two transcripts working at the same time count that time once.\n const merged = mergeSteps(steps);\n return {\n workedMs: workedBetween(merged),\n prompts,\n byDay: workedByDay(merged, since),\n firstAt: firstMs === null ? null : new Date(firstMs).toISOString(),\n lastAt: lastMs === null ? null : new Date(lastMs).toISOString(),\n };\n}\n\n/** Forget what was read (tests). */\nexport function resetWorkTimeCache(): void {\n files.clear();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBO,SAAS,gBAAgB,QAA2B,MAAyB,QAAQ,KAA6B;AACvH,QAAM,IAAI,QAAQ;AAClB,MAAI,CAAC,GAAG,QAAQ,CAAC,EAAE,MAAO,QAAO;AACjC,QAAM,OAAO,EAAE,KAAK,QAAQ,gBAAgB,EAAE,EAAE,QAAQ,SAAS,EAAE;AACnE,MAAI,CAAC,iBAAiB,KAAK,IAAI,EAAG,QAAO;AACzC,QAAM,QAAQ,EAAE,SAAS,IAAI,EAAE,YAAY,gBAAgB;AAC3D,SAAO,QAAQ,EAAE,MAAM,OAAO,EAAE,OAAO,MAAM,IAAI;AACnD;AAGO,IAAM,aAAa,CAAC,MAAuB,wBAAwB,KAAK,CAAC;AAGzE,SAAS,YAAY,GAAiB;AAC3C,QAAM,MAAM,CAAC,GAAW,IAAI,MAAM,OAAO,KAAK,IAAI,CAAC,CAAC,EAAE,SAAS,GAAG,GAAG;AACrE,QAAM,MAAM,CAAC,EAAE,kBAAkB;AACjC,SAAO,GAAG,EAAE,YAAY,CAAC,IAAI,IAAI,EAAE,SAAS,IAAI,CAAC,CAAC,IAAI,IAAI,EAAE,QAAQ,CAAC,CAAC,IAAI,IAAI,EAAE,SAAS,CAAC,CAAC,IAAI,IAAI,EAAE,WAAW,CAAC,CAAC,IAAI,IAAI,EAAE,WAAW,CAAC,C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