@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,887 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
spawn_default
|
|
4
|
+
} from "./chunk-RCYI7SRA.js";
|
|
5
|
+
import {
|
|
6
|
+
atomicWriteFile,
|
|
7
|
+
getConfigPath,
|
|
8
|
+
isAgentId
|
|
9
|
+
} from "./chunk-7HEB6SQS.js";
|
|
10
|
+
|
|
11
|
+
// src/core/platform/ai-launcher.ts
|
|
12
|
+
import fs from "fs";
|
|
13
|
+
var AI_TOOL_PRESETS = {
|
|
14
|
+
claude: {
|
|
15
|
+
unsafe: "--dangerously-skip-permissions",
|
|
16
|
+
resume: "--continue",
|
|
17
|
+
promptFile: "--prompt-file",
|
|
18
|
+
prompt: ""
|
|
19
|
+
// positional
|
|
20
|
+
},
|
|
21
|
+
opencode: {
|
|
22
|
+
unsafe: "",
|
|
23
|
+
// no equivalent — permissions are configured elsewhere
|
|
24
|
+
resume: "--continue",
|
|
25
|
+
promptFile: "",
|
|
26
|
+
// no file flag — content gets inlined via promptFlag
|
|
27
|
+
prompt: "--prompt"
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var KNOWN_TOOLS = [
|
|
31
|
+
{ name: "Claude Code (claude)", value: "claude" },
|
|
32
|
+
{ name: "OpenCode (opencode)", value: "opencode" }
|
|
33
|
+
];
|
|
34
|
+
function getAiTool(config) {
|
|
35
|
+
const command = (config.aiCommand ?? "claude").trim();
|
|
36
|
+
const parts = command.split(/\s+/).filter(Boolean);
|
|
37
|
+
const cmd = parts[0] || "claude";
|
|
38
|
+
const baseArgs = parts.slice(1);
|
|
39
|
+
const preset = AI_TOOL_PRESETS[cmd] ?? AI_TOOL_PRESETS.claude;
|
|
40
|
+
const overrides = config.aiCommandFlags ?? {};
|
|
41
|
+
return {
|
|
42
|
+
cmd,
|
|
43
|
+
baseArgs,
|
|
44
|
+
unsafeFlag: overrides.unsafe ?? preset.unsafe,
|
|
45
|
+
resumeFlag: overrides.resume ?? preset.resume,
|
|
46
|
+
promptFileFlag: overrides.promptFile ?? preset.promptFile,
|
|
47
|
+
promptFlag: overrides.prompt ?? preset.prompt
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function buildAiLaunchArgs(tool, opts = {}) {
|
|
51
|
+
const args = [...tool.baseArgs];
|
|
52
|
+
if (opts.unsafe && tool.unsafeFlag) args.push(tool.unsafeFlag);
|
|
53
|
+
if (opts.resume && tool.resumeFlag) args.push(tool.resumeFlag);
|
|
54
|
+
let inlinePrompt = opts.initialPrompt;
|
|
55
|
+
if (opts.promptFile) {
|
|
56
|
+
if (tool.promptFileFlag) {
|
|
57
|
+
args.push(tool.promptFileFlag, opts.promptFile);
|
|
58
|
+
} else if (tool.promptFlag) {
|
|
59
|
+
try {
|
|
60
|
+
inlinePrompt = fs.readFileSync(opts.promptFile, "utf-8");
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (inlinePrompt) {
|
|
66
|
+
if (tool.promptFlag) args.push(tool.promptFlag, inlinePrompt);
|
|
67
|
+
else args.push(inlinePrompt);
|
|
68
|
+
}
|
|
69
|
+
return { cmd: tool.cmd, args };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/core/platform/process.ts
|
|
73
|
+
import fs2 from "fs";
|
|
74
|
+
import os from "os";
|
|
75
|
+
import { execFile, spawn, spawnSync } from "child_process";
|
|
76
|
+
function isPidAlive(pid) {
|
|
77
|
+
try {
|
|
78
|
+
process.kill(pid, 0);
|
|
79
|
+
return true;
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
var procFs = {
|
|
85
|
+
link: (p) => {
|
|
86
|
+
try {
|
|
87
|
+
return fs2.readlinkSync(p);
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
file: (p) => {
|
|
93
|
+
try {
|
|
94
|
+
return fs2.readFileSync(p, "utf-8");
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
pids: () => {
|
|
100
|
+
try {
|
|
101
|
+
return fs2.readdirSync("/proc").filter((n) => /^\d+$/.test(n)).map(Number);
|
|
102
|
+
} catch {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var baseName = (p) => p.split("/").pop() || p;
|
|
108
|
+
function linuxProcessName(pid, read = procFs) {
|
|
109
|
+
const exe = read.link(`/proc/${pid}/exe`);
|
|
110
|
+
if (exe) return baseName(exe.replace(/ \(deleted\)$/, ""));
|
|
111
|
+
const argv0 = (read.file(`/proc/${pid}/cmdline`) ?? "").split("\0")[0];
|
|
112
|
+
if (argv0) return baseName(argv0.split(" ")[0]);
|
|
113
|
+
const comm = (read.file(`/proc/${pid}/comm`) ?? "").trim();
|
|
114
|
+
return comm || null;
|
|
115
|
+
}
|
|
116
|
+
function linuxProcessTable(read = procFs) {
|
|
117
|
+
const out = /* @__PURE__ */ new Map();
|
|
118
|
+
for (const pid of read.pids()) {
|
|
119
|
+
const name = linuxProcessName(pid, read);
|
|
120
|
+
if (name) out.set(pid, name);
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
function processName(pid) {
|
|
125
|
+
try {
|
|
126
|
+
if (process.platform === "win32") {
|
|
127
|
+
const r2 = spawnSync("tasklist", ["/FI", `PID eq ${pid}`, "/FO", "CSV", "/NH"], {
|
|
128
|
+
encoding: "utf-8",
|
|
129
|
+
windowsHide: true,
|
|
130
|
+
timeout: 5e3
|
|
131
|
+
});
|
|
132
|
+
const m = /^"([^"]+)","(\d+)"/.exec((r2.stdout ?? "").trim());
|
|
133
|
+
return m && Number(m[2]) === pid ? m[1] : null;
|
|
134
|
+
}
|
|
135
|
+
if (process.platform === "linux") return isPidAlive(pid) ? linuxProcessName(pid) : null;
|
|
136
|
+
const r = spawnSync("ps", ["-o", "comm=", "-p", String(pid)], { encoding: "utf-8", timeout: 5e3 });
|
|
137
|
+
const name = (r.stdout ?? "").trim();
|
|
138
|
+
return r.status === 0 && name ? name.split("/").pop() : null;
|
|
139
|
+
} catch {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
var recentTable = null;
|
|
144
|
+
var refreshingTable = null;
|
|
145
|
+
function recentProcessTable(maxAgeMs, now = Date.now()) {
|
|
146
|
+
if (!recentTable || now - recentTable.at >= maxAgeMs) {
|
|
147
|
+
refreshingTable ??= processTableAsync().then((table) => void (table.size > 0 && (recentTable = { at: Date.now(), table }))).finally(() => void (refreshingTable = null));
|
|
148
|
+
}
|
|
149
|
+
return recentTable?.table ?? null;
|
|
150
|
+
}
|
|
151
|
+
function processTableAsync() {
|
|
152
|
+
if (process.platform === "linux") return Promise.resolve(linuxProcessTable());
|
|
153
|
+
return new Promise((resolve) => {
|
|
154
|
+
const win = process.platform === "win32";
|
|
155
|
+
const [cmd, args] = win ? ["tasklist", ["/FO", "CSV", "/NH"]] : ["ps", ["-A", "-o", "pid=,comm="]];
|
|
156
|
+
execFile(
|
|
157
|
+
cmd,
|
|
158
|
+
args,
|
|
159
|
+
{ encoding: "utf-8", windowsHide: true, timeout: 8e3, maxBuffer: 16 * 1024 * 1024 },
|
|
160
|
+
(_err, stdout) => {
|
|
161
|
+
resolve(parseProcessTable(stdout ?? "", win));
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function parseProcessTable(stdout, win) {
|
|
167
|
+
const out = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
169
|
+
if (win) {
|
|
170
|
+
const m = /^"([^"]+)","(\d+)"/.exec(line);
|
|
171
|
+
if (m) out.set(Number(m[2]), m[1]);
|
|
172
|
+
} else {
|
|
173
|
+
const m = /^\s*(\d+)\s+(.+)$/.exec(line);
|
|
174
|
+
if (m) out.set(Number(m[1]), m[2].trim().split("/").pop());
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
function processTable() {
|
|
180
|
+
if (process.platform === "linux") return linuxProcessTable();
|
|
181
|
+
try {
|
|
182
|
+
const win = process.platform === "win32";
|
|
183
|
+
const r = win ? spawnSync("tasklist", ["/FO", "CSV", "/NH"], { encoding: "utf-8", windowsHide: true, timeout: 8e3, maxBuffer: 16 * 1024 * 1024 }) : spawnSync("ps", ["-A", "-o", "pid=,comm="], { encoding: "utf-8", timeout: 8e3, maxBuffer: 16 * 1024 * 1024 });
|
|
184
|
+
return parseProcessTable(r.stdout ?? "", win);
|
|
185
|
+
} catch {
|
|
186
|
+
return /* @__PURE__ */ new Map();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function bootTime() {
|
|
190
|
+
return Date.now() - os.uptime() * 1e3;
|
|
191
|
+
}
|
|
192
|
+
function killTree(pid) {
|
|
193
|
+
if (process.platform === "win32") {
|
|
194
|
+
return spawnSync("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", windowsHide: true }).status === 0;
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
process.kill(pid);
|
|
198
|
+
return true;
|
|
199
|
+
} catch {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function spawnDetachedWork(workBin, args, logFile) {
|
|
204
|
+
const log = fs2.openSync(logFile, "a");
|
|
205
|
+
try {
|
|
206
|
+
const child = spawn(process.execPath, [workBin, ...args], {
|
|
207
|
+
detached: true,
|
|
208
|
+
stdio: ["ignore", log, log],
|
|
209
|
+
windowsHide: true
|
|
210
|
+
});
|
|
211
|
+
child.unref();
|
|
212
|
+
} finally {
|
|
213
|
+
fs2.closeSync(log);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// src/core/platform/internal-run.ts
|
|
218
|
+
var INTERNAL_RUN_ENV = "WORK_INTERNAL_CLAUDE";
|
|
219
|
+
function internalRunEnv() {
|
|
220
|
+
return { [INTERNAL_RUN_ENV]: "1" };
|
|
221
|
+
}
|
|
222
|
+
function isInternalRun() {
|
|
223
|
+
return process.env[INTERNAL_RUN_ENV] === "1";
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/core/agents/index.ts
|
|
227
|
+
import fs7 from "fs";
|
|
228
|
+
import path7 from "path";
|
|
229
|
+
|
|
230
|
+
// src/core/agents/claude/adapter.ts
|
|
231
|
+
import path6 from "path";
|
|
232
|
+
|
|
233
|
+
// src/core/agents/claude/files.ts
|
|
234
|
+
import path2 from "path";
|
|
235
|
+
|
|
236
|
+
// src/core/agents/claude/activity.ts
|
|
237
|
+
import fs3 from "fs";
|
|
238
|
+
import os2 from "os";
|
|
239
|
+
import path from "path";
|
|
240
|
+
function encodeProjectDir(p) {
|
|
241
|
+
return path.resolve(p).replace(/[^A-Za-z0-9]/g, "-");
|
|
242
|
+
}
|
|
243
|
+
var listings = /* @__PURE__ */ new Map();
|
|
244
|
+
var NAMES_MAX_AGE_MS = 2e3;
|
|
245
|
+
function projectTranscripts(projectDir, now = Date.now()) {
|
|
246
|
+
let dirMtimeMs;
|
|
247
|
+
try {
|
|
248
|
+
dirMtimeMs = fs3.statSync(projectDir).mtimeMs;
|
|
249
|
+
} catch {
|
|
250
|
+
listings.delete(projectDir);
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
let hit = listings.get(projectDir);
|
|
254
|
+
if (!hit || hit.dirMtimeMs !== dirMtimeMs || now - hit.at >= NAMES_MAX_AGE_MS) {
|
|
255
|
+
let names = [];
|
|
256
|
+
try {
|
|
257
|
+
names = fs3.readdirSync(projectDir).filter((n) => n.endsWith(".jsonl"));
|
|
258
|
+
} catch {
|
|
259
|
+
}
|
|
260
|
+
hit = { at: now, dirMtimeMs, names };
|
|
261
|
+
listings.set(projectDir, hit);
|
|
262
|
+
}
|
|
263
|
+
const files = [];
|
|
264
|
+
for (const name of hit.names) {
|
|
265
|
+
try {
|
|
266
|
+
const file = path.join(projectDir, name);
|
|
267
|
+
const st = fs3.statSync(file);
|
|
268
|
+
files.push({ file, mtimeMs: st.mtimeMs, size: st.size });
|
|
269
|
+
} catch {
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return files;
|
|
273
|
+
}
|
|
274
|
+
function latestJsonlMtimeMs(projectDir) {
|
|
275
|
+
let latest = 0;
|
|
276
|
+
for (const f of projectTranscripts(projectDir)) if (f.mtimeMs > latest) latest = f.mtimeMs;
|
|
277
|
+
return latest;
|
|
278
|
+
}
|
|
279
|
+
function getClaudeActivityMs(launchPath) {
|
|
280
|
+
const dir = path.join(os2.homedir(), ".claude", "projects", encodeProjectDir(launchPath));
|
|
281
|
+
return latestJsonlMtimeMs(dir);
|
|
282
|
+
}
|
|
283
|
+
function hasClaudeConversation(dir) {
|
|
284
|
+
return getClaudeActivityMs(dir) > 0;
|
|
285
|
+
}
|
|
286
|
+
function resolveResumeLaunch(session) {
|
|
287
|
+
const existing = session.paths.filter((p) => fs3.existsSync(p));
|
|
288
|
+
const first = existing[0] ?? session.paths[0];
|
|
289
|
+
const defaultPath = session.isGroup ? path.dirname(first) : first;
|
|
290
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
291
|
+
if (session.isGroup) {
|
|
292
|
+
for (const p of existing) candidates.add(path.dirname(p));
|
|
293
|
+
for (const p of existing) candidates.add(p);
|
|
294
|
+
} else {
|
|
295
|
+
for (const p of existing) candidates.add(p);
|
|
296
|
+
}
|
|
297
|
+
let launchPath = defaultPath;
|
|
298
|
+
let bestMs = 0;
|
|
299
|
+
for (const c of candidates) {
|
|
300
|
+
const ms = getClaudeActivityMs(c);
|
|
301
|
+
if (ms > bestMs) {
|
|
302
|
+
bestMs = ms;
|
|
303
|
+
launchPath = c;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return { launchPath, hasConversation: bestMs > 0 };
|
|
307
|
+
}
|
|
308
|
+
function claudeProjectsRoot() {
|
|
309
|
+
return path.join(os2.homedir(), ".claude", "projects");
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// src/core/agents/claude/files.ts
|
|
313
|
+
function listTranscripts(session) {
|
|
314
|
+
const dirs = session.isGroup ? [...new Set(session.paths.map((p) => path2.dirname(p)))] : session.paths;
|
|
315
|
+
const out = [];
|
|
316
|
+
for (const d of dirs) out.push(...projectTranscripts(path2.join(claudeProjectsRoot(), encodeProjectDir(d))));
|
|
317
|
+
return out;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/core/agents/claude/env.ts
|
|
321
|
+
var PARENT_SESSION_VARS = [
|
|
322
|
+
"CLAUDECODE",
|
|
323
|
+
"CLAUDE_CODE_CHILD_SESSION",
|
|
324
|
+
"CLAUDE_CODE_SESSION_ID",
|
|
325
|
+
"CLAUDE_CODE_SESSION_ATTENDED",
|
|
326
|
+
"CLAUDE_CODE_BRIDGE_SESSION_ID",
|
|
327
|
+
"CLAUDE_CODE_MESSAGING_SOCKET",
|
|
328
|
+
"CLAUDE_CODE_MESSAGING_TOKEN",
|
|
329
|
+
"CLAUDE_CODE_ENTRYPOINT",
|
|
330
|
+
"CLAUDE_CODE_EXECPATH",
|
|
331
|
+
"CLAUDE_PID"
|
|
332
|
+
];
|
|
333
|
+
function withoutParentSession(env) {
|
|
334
|
+
const drop = new Set(PARENT_SESSION_VARS);
|
|
335
|
+
return Object.fromEntries(Object.entries(env).filter(([k]) => !drop.has(k.toUpperCase())));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/core/conversations/jsonl.ts
|
|
339
|
+
import fs4 from "fs";
|
|
340
|
+
var TAIL_BYTES = 256 * 1024;
|
|
341
|
+
function parseLines(text) {
|
|
342
|
+
const out = [];
|
|
343
|
+
for (const raw of text.split("\n")) {
|
|
344
|
+
const line = raw.trim();
|
|
345
|
+
if (!line.startsWith("{")) continue;
|
|
346
|
+
try {
|
|
347
|
+
const entry = JSON.parse(line);
|
|
348
|
+
if (entry && typeof entry === "object" && !Array.isArray(entry)) out.push(entry);
|
|
349
|
+
} catch {
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return out;
|
|
353
|
+
}
|
|
354
|
+
function readJsonlTail(transcriptPath, bytes = TAIL_BYTES) {
|
|
355
|
+
if (!transcriptPath) return [];
|
|
356
|
+
let text;
|
|
357
|
+
try {
|
|
358
|
+
const fd = fs4.openSync(transcriptPath, "r");
|
|
359
|
+
try {
|
|
360
|
+
const size = fs4.fstatSync(fd).size;
|
|
361
|
+
const start = Math.max(0, size - bytes);
|
|
362
|
+
const buf = Buffer.alloc(size - start);
|
|
363
|
+
fs4.readSync(fd, buf, 0, buf.length, start);
|
|
364
|
+
text = buf.toString("utf-8");
|
|
365
|
+
} finally {
|
|
366
|
+
fs4.closeSync(fd);
|
|
367
|
+
}
|
|
368
|
+
} catch {
|
|
369
|
+
return [];
|
|
370
|
+
}
|
|
371
|
+
return parseLines(text);
|
|
372
|
+
}
|
|
373
|
+
var SINCE_CHUNK_BYTES = 2 * 1024 * 1024;
|
|
374
|
+
var SINCE_MAX_BYTES = 64 * 1024 * 1024;
|
|
375
|
+
async function readJsonlSince(transcriptPath, sinceMs, timeOf, opts = {}) {
|
|
376
|
+
const chunk = Math.max(1, opts.chunkBytes ?? SINCE_CHUNK_BYTES);
|
|
377
|
+
const max = Math.max(chunk, opts.maxBytes ?? SINCE_MAX_BYTES);
|
|
378
|
+
let fh;
|
|
379
|
+
try {
|
|
380
|
+
fh = await fs4.promises.open(transcriptPath, "r");
|
|
381
|
+
} catch {
|
|
382
|
+
return { lines: [], partial: false };
|
|
383
|
+
}
|
|
384
|
+
try {
|
|
385
|
+
const size = (await fh.stat()).size;
|
|
386
|
+
let bytes = Math.min(chunk, size);
|
|
387
|
+
for (; ; ) {
|
|
388
|
+
const start = size - bytes;
|
|
389
|
+
const buf = Buffer.alloc(bytes);
|
|
390
|
+
await fh.read(buf, 0, bytes, start);
|
|
391
|
+
const lines = parseLines(buf.toString("utf-8"));
|
|
392
|
+
const earliest = lines.map(timeOf).find((ms) => Number.isFinite(ms));
|
|
393
|
+
if (start === 0 || earliest !== void 0 && earliest < sinceMs) return { lines, partial: false };
|
|
394
|
+
if (bytes >= max) return { lines, partial: true };
|
|
395
|
+
bytes = Math.min(size, bytes * 2, max);
|
|
396
|
+
}
|
|
397
|
+
} catch {
|
|
398
|
+
return { lines: [], partial: false };
|
|
399
|
+
} finally {
|
|
400
|
+
await fh.close();
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// src/core/agents/claude/transcript-entry.ts
|
|
405
|
+
function contentBlocks(entry) {
|
|
406
|
+
const c = entry.message?.content;
|
|
407
|
+
if (typeof c === "string") return [{ type: "text", text: c }];
|
|
408
|
+
if (!Array.isArray(c)) return [];
|
|
409
|
+
return c.filter((b) => !!b && typeof b === "object");
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// src/core/agents/claude/transcript.ts
|
|
413
|
+
function readTranscriptTail(transcriptPath, bytes = TAIL_BYTES) {
|
|
414
|
+
return readJsonlTail(transcriptPath, bytes);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// src/core/agents/claude/entries.ts
|
|
418
|
+
var NOT_TYPED = /^\s*(<command-name>|<command-message>|<local-command-|<system-reminder>|<bash-|<task-notification>|\[Request interrupted|Caveat: )/;
|
|
419
|
+
function promptText(e) {
|
|
420
|
+
if (e.type !== "user" || e.isSidechain === true || e.isMeta === true) return null;
|
|
421
|
+
const blocks = contentBlocks(e);
|
|
422
|
+
if (blocks.some((b) => b.type === "tool_result")) return null;
|
|
423
|
+
const text = blocks.filter((b) => b.type === "text" && typeof b.text === "string").map((b) => b.text).join("\n").trim();
|
|
424
|
+
if (!text || NOT_TYPED.test(text)) return null;
|
|
425
|
+
return text;
|
|
426
|
+
}
|
|
427
|
+
var MAX_TOOL_DETAIL = 400;
|
|
428
|
+
function str(input, key) {
|
|
429
|
+
const v = input?.[key];
|
|
430
|
+
return typeof v === "string" && v.trim() ? v : void 0;
|
|
431
|
+
}
|
|
432
|
+
function describeToolUse(tool, input) {
|
|
433
|
+
const detail = (tool === "Bash" || tool === "PowerShell" ? str(input, "command") : void 0) ?? str(input, "file_path") ?? str(input, "notebook_path") ?? str(input, "url") ?? str(input, "query") ?? str(input, "pattern") ?? str(input, "description") ?? (input && typeof input === "object" ? JSON.stringify(input) : "");
|
|
434
|
+
const flat = detail.replace(/\s*\r?\n\s*/g, " \u23CE ").trim();
|
|
435
|
+
return flat.length > MAX_TOOL_DETAIL ? flat.slice(0, MAX_TOOL_DETAIL - 1) + "\u2026" : flat;
|
|
436
|
+
}
|
|
437
|
+
var num = (v) => typeof v === "number" && Number.isFinite(v) && v > 0 ? v : 0;
|
|
438
|
+
function isCommandEcho(e) {
|
|
439
|
+
const text = contentBlocks(e).map((b) => typeof b.text === "string" ? b.text : "").join("").trimStart();
|
|
440
|
+
return /^<(command-name|command-message|command-args|local-command-stdout|local-command-stderr|local-command-caveat)>/.test(text);
|
|
441
|
+
}
|
|
442
|
+
var isMetaLine = (e) => e.isMeta === true || e.isCompactSummary === true || e.isVisibleInTranscriptOnly === true;
|
|
443
|
+
function lineEntries(e) {
|
|
444
|
+
const at = typeof e.timestamp === "string" ? e.timestamp : "";
|
|
445
|
+
const meta = isMetaLine(e);
|
|
446
|
+
const base = {
|
|
447
|
+
at,
|
|
448
|
+
...typeof e.uuid === "string" && e.uuid ? { id: e.uuid } : {},
|
|
449
|
+
...e.isSidechain === true ? { sidechain: true } : {},
|
|
450
|
+
...meta ? { meta: true } : {}
|
|
451
|
+
};
|
|
452
|
+
const prompt = meta ? null : promptText(e);
|
|
453
|
+
if (prompt) return [{ ...base, role: "you", text: prompt }];
|
|
454
|
+
const blocks = contentBlocks(e);
|
|
455
|
+
if (e.type === "user" && blocks.some((b) => b.type === "tool_result")) return [{ ...base, role: "tool-result", text: "" }];
|
|
456
|
+
if (e.type === "user") return [{ ...base, role: "other", text: "", ...!meta && !isCommandEcho(e) ? { turn: true } : {} }];
|
|
457
|
+
if (e.type !== "assistant") return [{ ...base, role: "other", text: "" }];
|
|
458
|
+
const out = [];
|
|
459
|
+
const text = blocks.filter((b) => b.type === "text" && typeof b.text === "string").map((b) => b.text).join("\n").trim();
|
|
460
|
+
const u = e.message?.usage;
|
|
461
|
+
const usage = u && typeof u === "object" ? { prompt: num(u.input_tokens) + num(u.cache_read_input_tokens) + num(u.cache_creation_input_tokens), reply: num(u.output_tokens) } : null;
|
|
462
|
+
const model = typeof e.message?.model === "string" ? e.message.model : void 0;
|
|
463
|
+
out.push({
|
|
464
|
+
...base,
|
|
465
|
+
role: "agent",
|
|
466
|
+
text: meta ? "" : text,
|
|
467
|
+
...usage && usage.prompt + usage.reply > 0 ? { usage } : {},
|
|
468
|
+
...model ? { model } : {}
|
|
469
|
+
});
|
|
470
|
+
for (const b of blocks) {
|
|
471
|
+
if (b.type === "tool_use" && typeof b.name === "string")
|
|
472
|
+
out.push({ ...base, role: "tool", tool: b.name, text: describeToolUse(b.name, b.input) });
|
|
473
|
+
}
|
|
474
|
+
return out;
|
|
475
|
+
}
|
|
476
|
+
function claudeEntries(lines) {
|
|
477
|
+
const out = [];
|
|
478
|
+
for (const l of lines) if (l && typeof l === "object") out.push(...lineEntries(l));
|
|
479
|
+
return out;
|
|
480
|
+
}
|
|
481
|
+
var DEFAULT_WINDOW = 2e5;
|
|
482
|
+
var LARGE_WINDOW = 1e6;
|
|
483
|
+
function claudeContextWindow(model, used) {
|
|
484
|
+
return model && /\[1m\]/i.test(model) || used > DEFAULT_WINDOW ? LARGE_WINDOW : DEFAULT_WINDOW;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/core/agents/claude/permission.ts
|
|
488
|
+
import path3 from "path";
|
|
489
|
+
function pendingToolUse(entries) {
|
|
490
|
+
const answered = /* @__PURE__ */ new Set();
|
|
491
|
+
for (const e of entries) {
|
|
492
|
+
for (const b of contentBlocks(e)) {
|
|
493
|
+
if (b.type === "tool_result" && typeof b.tool_use_id === "string") answered.add(b.tool_use_id);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
let found = null;
|
|
497
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
498
|
+
const e = entries[i];
|
|
499
|
+
if (e.type === "user") {
|
|
500
|
+
if (found) break;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (e.type !== "assistant") continue;
|
|
504
|
+
const blocks = contentBlocks(e);
|
|
505
|
+
for (let j = blocks.length - 1; j >= 0; j--) {
|
|
506
|
+
const b = blocks[j];
|
|
507
|
+
if (b.type !== "tool_use" || typeof b.name !== "string") continue;
|
|
508
|
+
if (typeof b.id === "string" && answered.has(b.id)) continue;
|
|
509
|
+
found = { tool: b.name, detail: describeToolUse(b.name, b.input) };
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return found;
|
|
513
|
+
}
|
|
514
|
+
var QUESTION_RE = /Do you want to\b/;
|
|
515
|
+
var YES_SELECTED_RE = /❯\s*1\.\s*Yes\b/;
|
|
516
|
+
var squash = (s) => s.replace(/[\s\u2500-\u257f]+/g, "");
|
|
517
|
+
function screenAnchor(req) {
|
|
518
|
+
if (req.tool === "Bash" || req.tool === "PowerShell") return squash(req.detail.split(" \u23CE ")[0]).slice(0, 40);
|
|
519
|
+
if (/[\\/]/.test(req.detail) && !/^https?:/.test(req.detail)) return path3.basename(req.detail.replace(/\\/g, "/"));
|
|
520
|
+
return "";
|
|
521
|
+
}
|
|
522
|
+
function checkDialog(screen, req) {
|
|
523
|
+
if (!QUESTION_RE.test(screen)) return { ok: false, reason: "no-dialog" };
|
|
524
|
+
const anchor = screenAnchor(req);
|
|
525
|
+
if (anchor && !squash(screen).includes(anchor)) return { ok: false, reason: "other-request" };
|
|
526
|
+
if (!YES_SELECTED_RE.test(screen)) return { ok: false, reason: "not-default" };
|
|
527
|
+
return { ok: true };
|
|
528
|
+
}
|
|
529
|
+
var ANSWER_KEYS = { allow: "\r", deny: "\x1B" };
|
|
530
|
+
|
|
531
|
+
// src/core/agents/claude/hooks.ts
|
|
532
|
+
var installer = null;
|
|
533
|
+
var loadInstaller = async () => installer ??= await import("./command-hook-installer-SGEJTZ2Y.js");
|
|
534
|
+
var CLAUDE_EVENT = {
|
|
535
|
+
"turn-start": "UserPromptSubmit",
|
|
536
|
+
"turn-end": "Stop",
|
|
537
|
+
notify: "Notification"
|
|
538
|
+
};
|
|
539
|
+
var asPayload = (p) => p && typeof p === "object" ? p : {};
|
|
540
|
+
var str2 = (v) => typeof v === "string" ? v : void 0;
|
|
541
|
+
function lastAssistantText(transcriptPath) {
|
|
542
|
+
const entries = readTranscriptTail(transcriptPath);
|
|
543
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
544
|
+
if (entries[i].type !== "assistant") continue;
|
|
545
|
+
const text = contentBlocks(entries[i]).filter((b) => b.type === "text" && typeof b.text === "string").map((b) => b.text).join("\n").trim();
|
|
546
|
+
if (text) return text;
|
|
547
|
+
}
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
function claudeStatusEvent(edge, payload) {
|
|
551
|
+
const p = asPayload(payload);
|
|
552
|
+
switch (edge) {
|
|
553
|
+
case "turn-start":
|
|
554
|
+
return { kind: "prompt", prompt: str2(p.prompt) };
|
|
555
|
+
case "turn-end":
|
|
556
|
+
return { kind: "stop", lastMessage: lastAssistantText(str2(p.transcript_path)) ?? void 0 };
|
|
557
|
+
case "notify": {
|
|
558
|
+
const request = pendingToolUse(readTranscriptTail(str2(p.transcript_path)));
|
|
559
|
+
const type = str2(p.notification_type);
|
|
560
|
+
return { kind: "notification", message: str2(p.message), ...type ? { type } : {}, ...request ? { request } : {} };
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
var toClaude = (h) => ({ owner: h.owner, event: CLAUDE_EVENT[h.edge] });
|
|
565
|
+
var claudeEvents = {
|
|
566
|
+
install: async (hooks, remove = []) => (await loadInstaller()).syncCommandHooks(
|
|
567
|
+
hooks.map((h) => ({ ...toClaude(h), command: h.command, ...h.timeoutSec ? { timeoutSec: h.timeoutSec } : {} })),
|
|
568
|
+
remove.map(toClaude)
|
|
569
|
+
),
|
|
570
|
+
// A shutdown handler can't wait for an import: it uses the installer the
|
|
571
|
+
// start-up install loaded (work web always installs first). Nothing loaded:
|
|
572
|
+
// this process installed nothing, so there is nothing of its to remove.
|
|
573
|
+
removeSync: (hooks) => installer?.removeCommandHooksSync(hooks.map(toClaude)),
|
|
574
|
+
read: (edge, payload) => ({ cwd: str2(asPayload(payload).cwd), status: claudeStatusEvent(edge, payload) }),
|
|
575
|
+
// turn-start: stdout is added to the prompt. turn-end: `decision: block`
|
|
576
|
+
// keeps Claude in the turn and feeds `reason` back to it.
|
|
577
|
+
handOver: (edge, text) => edge === "turn-start" ? text + "\n" : JSON.stringify({ decision: "block", reason: text }) + "\n"
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
// src/core/agents/claude/live.ts
|
|
581
|
+
import fs5 from "fs";
|
|
582
|
+
import os3 from "os";
|
|
583
|
+
import path4 from "path";
|
|
584
|
+
var isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
585
|
+
function parseLiveClaude(raw) {
|
|
586
|
+
if (!isObj(raw)) return null;
|
|
587
|
+
const { pid, sessionId, cwd, status, startedAt, statusUpdatedAt, waitingFor } = raw;
|
|
588
|
+
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return null;
|
|
589
|
+
if (typeof sessionId !== "string" || !sessionId || typeof cwd !== "string" || !cwd) return null;
|
|
590
|
+
return {
|
|
591
|
+
pid,
|
|
592
|
+
conversationId: sessionId,
|
|
593
|
+
cwd,
|
|
594
|
+
busy: status === "busy",
|
|
595
|
+
state: status === "busy" || status === "idle" || status === "waiting" ? status : null,
|
|
596
|
+
stateAt: typeof statusUpdatedAt === "number" ? statusUpdatedAt : null,
|
|
597
|
+
waitingFor: typeof waitingFor === "string" && waitingFor ? waitingFor : null,
|
|
598
|
+
startedAt: typeof startedAt === "number" ? startedAt : null
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
var CLAUDE_EXE = /^(claude|node)(\.exe)?$/i;
|
|
602
|
+
function aliveOnly(list, table, bootMs) {
|
|
603
|
+
return list.filter((c) => {
|
|
604
|
+
const name = table.get(c.pid);
|
|
605
|
+
if (!name || !CLAUDE_EXE.test(name)) return false;
|
|
606
|
+
return c.startedAt === null || c.startedAt >= bootMs - 6e4;
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
var TTL_MS = 5e3;
|
|
610
|
+
var cache = null;
|
|
611
|
+
function claudeSessionsDir() {
|
|
612
|
+
return path4.join(process.env.CLAUDE_CONFIG_DIR || path4.join(os3.homedir(), ".claude"), "sessions");
|
|
613
|
+
}
|
|
614
|
+
function readLiveClaudes(dir = claudeSessionsDir(), now = Date.now(), table) {
|
|
615
|
+
if (!table && cache && now - cache.at < TTL_MS && dir === claudeSessionsDir()) return cache.list;
|
|
616
|
+
let names;
|
|
617
|
+
try {
|
|
618
|
+
names = fs5.readdirSync(dir).filter((n) => /^\d+\.json$/.test(n));
|
|
619
|
+
} catch {
|
|
620
|
+
return [];
|
|
621
|
+
}
|
|
622
|
+
const parsed = [];
|
|
623
|
+
for (const n of names) {
|
|
624
|
+
try {
|
|
625
|
+
const c = parseLiveClaude(JSON.parse(fs5.readFileSync(path4.join(dir, n), "utf8")));
|
|
626
|
+
if (c) parsed.push(c);
|
|
627
|
+
} catch {
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
const list = parsed.length ? aliveOnly(parsed, table ?? processTable(), bootTime()) : [];
|
|
631
|
+
if (!table) cache = { at: now, list };
|
|
632
|
+
return list;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// src/core/agents/typing.ts
|
|
636
|
+
var SUBMIT_DELAY_MS = 250;
|
|
637
|
+
var typeThenEnter = async (write, text, wait = (ms) => new Promise((r) => setTimeout(r, ms))) => {
|
|
638
|
+
if (!await write(text)) return false;
|
|
639
|
+
await wait(SUBMIT_DELAY_MS);
|
|
640
|
+
return write("\r");
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
// src/core/agents/claude/internal.ts
|
|
644
|
+
import os4 from "os";
|
|
645
|
+
function internalClaudeSpawn(opts = {}) {
|
|
646
|
+
return {
|
|
647
|
+
args: ["-p", "--tools", "", "--strict-mcp-config", ...opts.model ? ["--model", opts.model] : []],
|
|
648
|
+
cwd: os4.tmpdir(),
|
|
649
|
+
env: { ...process.env, ...internalRunEnv() }
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// src/core/agents/claude/workspace.ts
|
|
654
|
+
import fs6 from "fs";
|
|
655
|
+
import path5 from "path";
|
|
656
|
+
var claudeAllowRule = (r) => `Bash(${r.command}${r.prefix ? ":*" : ""})`;
|
|
657
|
+
var claudeWorkspace = {
|
|
658
|
+
write(dir, { allow, hooks }) {
|
|
659
|
+
fs6.mkdirSync(path5.join(dir, ".claude"), { recursive: true });
|
|
660
|
+
const byEvent = {};
|
|
661
|
+
for (const h of hooks) {
|
|
662
|
+
(byEvent[CLAUDE_EVENT[h.edge]] ??= []).push({
|
|
663
|
+
hooks: [{ type: "command", command: h.command, ...h.timeoutSec ? { timeout: h.timeoutSec } : {} }]
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
const settings = { permissions: { allow: allow.map(claudeAllowRule) }, hooks: byEvent };
|
|
667
|
+
atomicWriteFile(path5.join(dir, ".claude", "settings.json"), JSON.stringify(settings, null, 2) + "\n");
|
|
668
|
+
return [path5.join(".claude", "settings.json")];
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
// src/core/agents/claude/skills.ts
|
|
673
|
+
var MARKETPLACE_REPO = "moberghr/moberg-plugins";
|
|
674
|
+
var MARKETPLACE_NAME = "moberg-plugins";
|
|
675
|
+
var PLUGIN_SPEC = "work-tree@moberg-plugins";
|
|
676
|
+
var runClaude = (args) => {
|
|
677
|
+
const r = spawn_default.sync("claude", args, { encoding: "utf8", timeout: 6e4, windowsHide: true, stdio: "pipe" });
|
|
678
|
+
const text = (v) => typeof v === "string" ? v : "";
|
|
679
|
+
return { ok: !r.error && r.status === 0, stdout: text(r.stdout), stderr: r.error ? r.error.message : text(r.stderr) };
|
|
680
|
+
};
|
|
681
|
+
var lastLine = (r) => `${r.stderr ?? ""}
|
|
682
|
+
${r.stdout}`.split("\n").map((l) => l.trim()).filter(Boolean).pop() ?? "";
|
|
683
|
+
function isInstalled(listJson) {
|
|
684
|
+
try {
|
|
685
|
+
const list = JSON.parse(listJson);
|
|
686
|
+
return Array.isArray(list) && list.some((p) => !!p && typeof p === "object" && p.id === PLUGIN_SPEC);
|
|
687
|
+
} catch {
|
|
688
|
+
return false;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
function claudeSkillsWith(run) {
|
|
692
|
+
return {
|
|
693
|
+
async install() {
|
|
694
|
+
if (!run(["--version"]).ok) return { ok: false, message: "Claude Code (the `claude` CLI) is not installed" };
|
|
695
|
+
const list = run(["plugin", "marketplace", "list"]);
|
|
696
|
+
if (!(list.ok && list.stdout.includes(MARKETPLACE_NAME))) {
|
|
697
|
+
const add = run(["plugin", "marketplace", "add", MARKETPLACE_REPO, "--scope", "user", "--sparse", ".claude-plugin"]);
|
|
698
|
+
if (!add.ok)
|
|
699
|
+
return {
|
|
700
|
+
ok: false,
|
|
701
|
+
message: `could not register the Claude Code plugin marketplace (run \`claude plugin marketplace add ${MARKETPLACE_REPO}\`)`
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
const install = run(["plugin", "install", PLUGIN_SPEC, "--scope", "user"]);
|
|
705
|
+
if (install.ok) return { ok: true, message: `installed the Claude Code plugin ${PLUGIN_SPEC}` };
|
|
706
|
+
if (isInstalled(run(["plugin", "list", "--json"]).stdout))
|
|
707
|
+
return { ok: true, message: `the Claude Code plugin ${PLUGIN_SPEC} is installed` };
|
|
708
|
+
const why = lastLine(install);
|
|
709
|
+
return {
|
|
710
|
+
ok: false,
|
|
711
|
+
message: `could not install the Claude Code plugin${why ? ` (${why})` : ""}: run \`claude plugin install ${PLUGIN_SPEC} --scope user\``
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
var claudeSkills = claudeSkillsWith(runClaude);
|
|
717
|
+
|
|
718
|
+
// src/core/agents/claude/adapter.ts
|
|
719
|
+
var CLAUDE_SMALL_MODEL = "haiku";
|
|
720
|
+
var TAIL_BYTES2 = 4 * 1024 * 1024;
|
|
721
|
+
var MAX_FILES = 3;
|
|
722
|
+
var shown = (e) => !e.sidechain && (e.role === "you" || e.role === "tool" || e.role === "agent" && e.text !== "");
|
|
723
|
+
var claudeAgent = {
|
|
724
|
+
id: "claude",
|
|
725
|
+
name: "Claude Code",
|
|
726
|
+
launch: {
|
|
727
|
+
// The configured command when it is Claude (`claude --model opus`); plain `claude` otherwise.
|
|
728
|
+
tool: (config) => getAiTool(config && getAiTool(config).cmd === "claude" ? config : {}),
|
|
729
|
+
canResume: (cwd) => hasClaudeConversation(cwd),
|
|
730
|
+
resumeLaunch: (s) => resolveResumeLaunch(s),
|
|
731
|
+
cleanEnv: (env) => withoutParentSession(env)
|
|
732
|
+
},
|
|
733
|
+
conversation: {
|
|
734
|
+
files: (s) => listTranscripts(s),
|
|
735
|
+
entries: claudeEntries,
|
|
736
|
+
contextWindow: claudeContextWindow,
|
|
737
|
+
read(session, { last }) {
|
|
738
|
+
const files = listTranscripts(session).sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
739
|
+
const got = [];
|
|
740
|
+
for (const f of files.slice(0, MAX_FILES)) {
|
|
741
|
+
got.push(...claudeEntries(readTranscriptTail(f.file, TAIL_BYTES2)).filter(shown));
|
|
742
|
+
if (got.length >= last) break;
|
|
743
|
+
}
|
|
744
|
+
return got.sort((a, b) => a.at.localeCompare(b.at)).slice(-last);
|
|
745
|
+
},
|
|
746
|
+
// Its projects folder for the folder Claude runs in (the worktree, or a group's root): `--continue` finds it there.
|
|
747
|
+
lastWriteMs: (cwd) => getClaudeActivityMs(cwd),
|
|
748
|
+
restoreDir: (s) => {
|
|
749
|
+
const cwd = s.isGroup && s.paths[0] ? path6.dirname(s.paths[0]) : s.paths[0];
|
|
750
|
+
return cwd ? path6.join(claudeProjectsRoot(), encodeProjectDir(cwd)) : null;
|
|
751
|
+
}
|
|
752
|
+
},
|
|
753
|
+
events: claudeEvents,
|
|
754
|
+
// Its transcripts, and the per-process state files (a Claude opened or closed in a terminal tab shows at once).
|
|
755
|
+
activityRoots: () => [claudeProjectsRoot(), claudeSessionsDir()],
|
|
756
|
+
live: { running: (table) => readLiveClaudes(void 0, void 0, table) },
|
|
757
|
+
input: {
|
|
758
|
+
submit: typeThenEnter,
|
|
759
|
+
// Its dialog: "Do you want to …?" over a menu with "❯ 1. Yes"; Enter takes Yes, Esc is "No, and tell Claude what to do differently".
|
|
760
|
+
permissionDialog: { check: checkDialog, keys: { allow: ANSWER_KEYS.allow, deny: ANSWER_KEYS.deny } }
|
|
761
|
+
},
|
|
762
|
+
// `claude -p --tools "" --strict-mcp-config [--model haiku]` in a neutral folder, tagged internal.
|
|
763
|
+
oneShot: { command: ({ small }) => ({ cmd: "claude", ...internalClaudeSpawn(small ? { model: CLAUDE_SMALL_MODEL } : {}) }) },
|
|
764
|
+
instructionsFile: "CLAUDE.md",
|
|
765
|
+
workspace: claudeWorkspace,
|
|
766
|
+
skills: claudeSkills
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
// src/core/agents/index.ts
|
|
770
|
+
var settingsCache = null;
|
|
771
|
+
function agentSettings() {
|
|
772
|
+
const file = getConfigPath();
|
|
773
|
+
let key;
|
|
774
|
+
try {
|
|
775
|
+
const st = fs7.statSync(file);
|
|
776
|
+
key = `${file}|${st.size}|${st.mtimeMs}`;
|
|
777
|
+
} catch {
|
|
778
|
+
return {};
|
|
779
|
+
}
|
|
780
|
+
if (settingsCache?.key === key) return settingsCache.value;
|
|
781
|
+
let value = {};
|
|
782
|
+
try {
|
|
783
|
+
const p = JSON.parse(fs7.readFileSync(file, "utf8"));
|
|
784
|
+
value = {
|
|
785
|
+
...typeof p.aiCommand === "string" ? { aiCommand: p.aiCommand } : {},
|
|
786
|
+
...p.aiCommandFlags && typeof p.aiCommandFlags === "object" ? { aiCommandFlags: p.aiCommandFlags } : {},
|
|
787
|
+
...isAgentId(p.internalAgent) ? { internalAgent: p.internalAgent } : {},
|
|
788
|
+
...isAgentId(p.assistantAgent) ? { assistantAgent: p.assistantAgent } : {}
|
|
789
|
+
};
|
|
790
|
+
} catch {
|
|
791
|
+
}
|
|
792
|
+
settingsCache = { key, value };
|
|
793
|
+
return value;
|
|
794
|
+
}
|
|
795
|
+
function agentOf(session) {
|
|
796
|
+
return agentFor(agentSettings(), session);
|
|
797
|
+
}
|
|
798
|
+
var ADAPTERS = /* @__PURE__ */ new Map([[claudeAgent.id, claudeAgent]]);
|
|
799
|
+
function isKnownAgent(id) {
|
|
800
|
+
return !!id && ADAPTERS.has(id);
|
|
801
|
+
}
|
|
802
|
+
function plainAgent(id) {
|
|
803
|
+
return {
|
|
804
|
+
id,
|
|
805
|
+
name: id,
|
|
806
|
+
launch: {
|
|
807
|
+
tool: (config) => getAiTool(config && getAiTool(config).cmd === id ? config : { aiCommand: id }),
|
|
808
|
+
canResume: () => false,
|
|
809
|
+
resumeLaunch: (s) => ({ launchPath: s.isGroup ? path7.dirname(s.paths[0] ?? "") : s.paths[0] ?? "", hasConversation: false }),
|
|
810
|
+
cleanEnv: (env) => ({ ...env })
|
|
811
|
+
},
|
|
812
|
+
// Text, a pause, Enter — and no dialog to answer by keystroke (its screen is unknown).
|
|
813
|
+
input: { submit: typeThenEnter },
|
|
814
|
+
// The shared convention (Codex, Copilot CLI, opencode read it).
|
|
815
|
+
instructionsFile: "AGENTS.md"
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
function knownAgents() {
|
|
819
|
+
return [...ADAPTERS.values()];
|
|
820
|
+
}
|
|
821
|
+
function agentWriteMs(cwd) {
|
|
822
|
+
return Math.max(0, ...knownAgents().map((a) => a.conversation?.lastWriteMs?.(cwd) ?? 0));
|
|
823
|
+
}
|
|
824
|
+
function activityRoots() {
|
|
825
|
+
return knownAgents().flatMap((a) => a.activityRoots?.() ?? []);
|
|
826
|
+
}
|
|
827
|
+
function lineTimeOf(conv) {
|
|
828
|
+
return (line) => {
|
|
829
|
+
const at = conv.entries([line])[0]?.at;
|
|
830
|
+
return at ? Date.parse(at) : NaN;
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
function liveAgents(table) {
|
|
834
|
+
return knownAgents().flatMap((a) => a.live?.running(table) ?? []);
|
|
835
|
+
}
|
|
836
|
+
function assistantAgent(config) {
|
|
837
|
+
return agentById(config?.assistantAgent ?? "claude");
|
|
838
|
+
}
|
|
839
|
+
function internalAgent(config) {
|
|
840
|
+
return agentById(config?.internalAgent ?? "claude");
|
|
841
|
+
}
|
|
842
|
+
function agentWire(a) {
|
|
843
|
+
return {
|
|
844
|
+
id: a.id,
|
|
845
|
+
name: a.name,
|
|
846
|
+
can: { read: !!a.conversation, hooks: !!a.events, live: !!a.live, answer: !!a.input.permissionDialog }
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
function agentById(id) {
|
|
850
|
+
return ADAPTERS.get(id) ?? plainAgent(id);
|
|
851
|
+
}
|
|
852
|
+
function agentToRecord(config) {
|
|
853
|
+
const cmd = getAiTool(config ?? {}).cmd;
|
|
854
|
+
return isKnownAgent(cmd) ? cmd : void 0;
|
|
855
|
+
}
|
|
856
|
+
function agentFor(config, session) {
|
|
857
|
+
return agentById(isKnownAgent(session?.agent) ? session.agent : getAiTool(config ?? {}).cmd);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
export {
|
|
861
|
+
KNOWN_TOOLS,
|
|
862
|
+
buildAiLaunchArgs,
|
|
863
|
+
readJsonlTail,
|
|
864
|
+
readJsonlSince,
|
|
865
|
+
isPidAlive,
|
|
866
|
+
processName,
|
|
867
|
+
recentProcessTable,
|
|
868
|
+
bootTime,
|
|
869
|
+
killTree,
|
|
870
|
+
spawnDetachedWork,
|
|
871
|
+
internalRunEnv,
|
|
872
|
+
isInternalRun,
|
|
873
|
+
agentSettings,
|
|
874
|
+
agentOf,
|
|
875
|
+
knownAgents,
|
|
876
|
+
agentWriteMs,
|
|
877
|
+
activityRoots,
|
|
878
|
+
lineTimeOf,
|
|
879
|
+
liveAgents,
|
|
880
|
+
assistantAgent,
|
|
881
|
+
internalAgent,
|
|
882
|
+
agentWire,
|
|
883
|
+
agentById,
|
|
884
|
+
agentToRecord,
|
|
885
|
+
agentFor
|
|
886
|
+
};
|
|
887
|
+
//# sourceMappingURL=chunk-PN44M5EE.js.map
|