@mdless/cli 1.2.0 → 1.3.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 +104 -13
- package/assets/it-just-works.mp3 +0 -0
- package/assets/lets-go.mp3 +0 -0
- package/assets/we-cant-expect-god-to-do-all-the-work.mp3 +0 -0
- package/assets/work-work.mp3 +0 -0
- package/dist/index.js +4455 -0
- package/package.json +22 -12
- package/src/agents/prompts/orchestrator.md +218 -0
- package/assets/screenshot.png +0 -0
- package/bin.mjs +0 -21
- package/src/agents/prompts/curator.md +0 -84
- package/src/agents/prompts/developer.md +0 -136
- package/src/agents/prompts/reviewer.md +0 -80
- package/src/commands/agent.ts +0 -262
- package/src/commands/init.ts +0 -64
- package/src/commands/start.ts +0 -233
- package/src/index.ts +0 -81
- package/src/utils.ts +0 -11
package/src/commands/agent.ts
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, createWriteStream } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
|
|
5
|
-
const SLEEP_SECONDS = 60;
|
|
6
|
-
|
|
7
|
-
function timestamp(): string {
|
|
8
|
-
const d = new Date();
|
|
9
|
-
return d.toTimeString().slice(0, 8);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function loadPrompt(name: string): string {
|
|
13
|
-
const promptPath = join(process.cwd(), ".mdless", "agents", `${name}.md`);
|
|
14
|
-
if (!existsSync(promptPath)) {
|
|
15
|
-
console.error(
|
|
16
|
-
`✗ no prompt found at ${promptPath}\n run \`mdless init\` to create the default prompts.`,
|
|
17
|
-
);
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
return readFileSync(promptPath, "utf8");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const RESET = "\x1b[0m";
|
|
24
|
-
const DIM = "\x1b[2m";
|
|
25
|
-
const BOLD = "\x1b[1m";
|
|
26
|
-
const ITALIC = "\x1b[3m";
|
|
27
|
-
|
|
28
|
-
// Purple palette (256-color, Gemini-inspired)
|
|
29
|
-
const VIOLET = "\x1b[38;5;141m"; // primary
|
|
30
|
-
const LAVENDER = "\x1b[38;5;147m"; // soft accent
|
|
31
|
-
const DEEP_PURPLE = "\x1b[38;5;99m"; // search/grep
|
|
32
|
-
const PINK_PURPLE = "\x1b[38;5;177m"; // writes/edits
|
|
33
|
-
const MAGENTA_PURPLE = "\x1b[38;5;171m"; // task/agent
|
|
34
|
-
const PALE = "\x1b[38;5;153m"; // web
|
|
35
|
-
const SOFT_PINK = "\x1b[38;5;211m"; // errors (still readable)
|
|
36
|
-
|
|
37
|
-
const TOOL_COLORS: Record<string, string> = {
|
|
38
|
-
Bash: VIOLET,
|
|
39
|
-
Read: LAVENDER,
|
|
40
|
-
Write: PINK_PURPLE,
|
|
41
|
-
Edit: PINK_PURPLE,
|
|
42
|
-
MultiEdit: PINK_PURPLE,
|
|
43
|
-
Glob: DEEP_PURPLE,
|
|
44
|
-
Grep: DEEP_PURPLE,
|
|
45
|
-
WebFetch: PALE,
|
|
46
|
-
WebSearch: PALE,
|
|
47
|
-
Task: MAGENTA_PURPLE,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const AGENT_COLOR = VIOLET;
|
|
51
|
-
|
|
52
|
-
function toolColor(name: string): string {
|
|
53
|
-
return TOOL_COLORS[name] ?? VIOLET;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function truncate(s: string, n: number): string {
|
|
57
|
-
const clean = s.replace(/\s+/g, " ").trim();
|
|
58
|
-
return clean.length > n ? clean.slice(0, n - 1) + "…" : clean;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function summarizeToolInput(name: string, input: any): string {
|
|
62
|
-
if (!input || typeof input !== "object") return "";
|
|
63
|
-
switch (name) {
|
|
64
|
-
case "Bash":
|
|
65
|
-
return `$ ${truncate(input.command ?? "", 140)}`;
|
|
66
|
-
case "Read":
|
|
67
|
-
return input.file_path ?? "";
|
|
68
|
-
case "Write":
|
|
69
|
-
return input.file_path ?? "";
|
|
70
|
-
case "Edit":
|
|
71
|
-
case "MultiEdit":
|
|
72
|
-
return input.file_path ?? "";
|
|
73
|
-
case "Glob":
|
|
74
|
-
return input.pattern ?? "";
|
|
75
|
-
case "Grep": {
|
|
76
|
-
const where = input.path ? ` in ${input.path}` : input.glob ? ` (${input.glob})` : "";
|
|
77
|
-
return `"${truncate(input.pattern ?? "", 80)}"${where}`;
|
|
78
|
-
}
|
|
79
|
-
case "WebFetch":
|
|
80
|
-
case "WebSearch":
|
|
81
|
-
return input.url ?? input.query ?? "";
|
|
82
|
-
case "Task":
|
|
83
|
-
return truncate(input.description ?? input.prompt ?? "", 120);
|
|
84
|
-
default: {
|
|
85
|
-
const first = Object.values(input).find((v) => typeof v === "string");
|
|
86
|
-
return typeof first === "string" ? truncate(first, 120) : truncate(JSON.stringify(input), 120);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function summarizeToolResult(raw: string, isError: boolean): string {
|
|
92
|
-
if (!raw.trim()) return isError ? "(error, no output)" : "(no output)";
|
|
93
|
-
const lines = raw.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
94
|
-
if (lines.length === 0) return "(empty)";
|
|
95
|
-
const firstLine = lines[0]!;
|
|
96
|
-
|
|
97
|
-
if (firstLine.startsWith("{") || firstLine.startsWith("[")) {
|
|
98
|
-
try {
|
|
99
|
-
const parsed = JSON.parse(raw);
|
|
100
|
-
if (Array.isArray(parsed)) return `[${parsed.length} items]`;
|
|
101
|
-
if (parsed && typeof parsed === "object") {
|
|
102
|
-
const keys = Object.keys(parsed);
|
|
103
|
-
if (keys.length === 0) return "{}";
|
|
104
|
-
return `{${keys.slice(0, 4).join(", ")}${keys.length > 4 ? ", …" : ""}}`;
|
|
105
|
-
}
|
|
106
|
-
} catch {}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const extra = lines.length > 1 ? ` (+${lines.length - 1} lines)` : "";
|
|
110
|
-
return truncate(firstLine, 140) + extra;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function indent(text: string, prefix: string): string {
|
|
114
|
-
return text
|
|
115
|
-
.split("\n")
|
|
116
|
-
.map((line) => prefix + line)
|
|
117
|
-
.join("\n");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function formatStreamEvent(line: string): string | null {
|
|
121
|
-
let evt: any;
|
|
122
|
-
try {
|
|
123
|
-
evt = JSON.parse(line);
|
|
124
|
-
} catch {
|
|
125
|
-
return line + "\n";
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (evt.type === "system" && evt.subtype === "init") {
|
|
129
|
-
const session = (evt.session_id ?? "?").toString().slice(0, 8);
|
|
130
|
-
const tools = Array.isArray(evt.tools) ? evt.tools.length : 0;
|
|
131
|
-
return `${DIM} session ${session} · ${tools} tools loaded${RESET}\n\n`;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (evt.type === "assistant" && evt.message?.content) {
|
|
135
|
-
const out: string[] = [];
|
|
136
|
-
for (const block of evt.message.content) {
|
|
137
|
-
if (block.type === "text" && block.text?.trim()) {
|
|
138
|
-
out.push("\n" + indent(block.text.trim(), " ") + "\n");
|
|
139
|
-
} else if (block.type === "tool_use") {
|
|
140
|
-
const summary = summarizeToolInput(block.name, block.input);
|
|
141
|
-
const color = toolColor(block.name);
|
|
142
|
-
out.push(` ${color}▸${RESET} ${color}${block.name.padEnd(9)}${RESET}${summary}`);
|
|
143
|
-
} else if (block.type === "thinking" && block.thinking?.trim()) {
|
|
144
|
-
out.push(` ${DIM}${ITALIC}~ ${truncate(block.thinking, 200)}${RESET}`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return out.length ? out.join("\n") + "\n" : null;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (evt.type === "user" && evt.message?.content) {
|
|
151
|
-
const out: string[] = [];
|
|
152
|
-
for (const block of evt.message.content) {
|
|
153
|
-
if (block.type === "tool_result") {
|
|
154
|
-
const raw = typeof block.content === "string"
|
|
155
|
-
? block.content
|
|
156
|
-
: Array.isArray(block.content)
|
|
157
|
-
? block.content.map((c: any) => c.text ?? "").join("\n")
|
|
158
|
-
: "";
|
|
159
|
-
const summary = summarizeToolResult(raw, !!block.is_error);
|
|
160
|
-
const arrow = block.is_error ? `${SOFT_PINK}└─ ✗${RESET}` : `${DIM}└─${RESET}`;
|
|
161
|
-
out.push(` ${arrow} ${DIM}${summary}${RESET}`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return out.length ? out.join("\n") + "\n" : null;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (evt.type === "result") {
|
|
168
|
-
const parts: string[] = [];
|
|
169
|
-
if (evt.num_turns != null) parts.push(`${evt.num_turns} turns`);
|
|
170
|
-
if (evt.duration_ms != null) parts.push(`${(evt.duration_ms / 1000).toFixed(1)}s`);
|
|
171
|
-
if (evt.total_cost_usd != null) parts.push(`$${evt.total_cost_usd.toFixed(4)}`);
|
|
172
|
-
const color = evt.is_error ? SOFT_PINK : LAVENDER;
|
|
173
|
-
const mark = evt.is_error ? "✗" : "✓";
|
|
174
|
-
return `\n ${color}${mark}${RESET} ${DIM}${parts.join(" · ")}${RESET}\n`;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function runClaude(prompt: string, logStream: NodeJS.WritableStream): Promise<number> {
|
|
181
|
-
return new Promise((resolve) => {
|
|
182
|
-
const child = spawn(
|
|
183
|
-
"claude",
|
|
184
|
-
[
|
|
185
|
-
"-p",
|
|
186
|
-
prompt,
|
|
187
|
-
"--dangerously-skip-permissions",
|
|
188
|
-
"--verbose",
|
|
189
|
-
"--output-format",
|
|
190
|
-
"stream-json",
|
|
191
|
-
],
|
|
192
|
-
{ stdio: ["ignore", "pipe", "pipe"] },
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
let buf = "";
|
|
196
|
-
child.stdout.on("data", (chunk) => {
|
|
197
|
-
buf += chunk.toString();
|
|
198
|
-
let nl: number;
|
|
199
|
-
while ((nl = buf.indexOf("\n")) !== -1) {
|
|
200
|
-
const line = buf.slice(0, nl);
|
|
201
|
-
buf = buf.slice(nl + 1);
|
|
202
|
-
if (!line.trim()) continue;
|
|
203
|
-
const formatted = formatStreamEvent(line);
|
|
204
|
-
if (formatted) {
|
|
205
|
-
process.stdout.write(formatted);
|
|
206
|
-
logStream.write(formatted);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
child.stderr.on("data", (chunk) => {
|
|
211
|
-
process.stderr.write(chunk);
|
|
212
|
-
logStream.write(chunk);
|
|
213
|
-
});
|
|
214
|
-
child.on("error", (err) => {
|
|
215
|
-
const msg = `\n[agent] failed to spawn claude: ${err.message}\n`;
|
|
216
|
-
process.stderr.write(msg);
|
|
217
|
-
logStream.write(msg);
|
|
218
|
-
resolve(1);
|
|
219
|
-
});
|
|
220
|
-
child.on("exit", (code) => resolve(code ?? 0));
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function sleep(seconds: number): Promise<void> {
|
|
225
|
-
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export async function agentCommand(name: string): Promise<void> {
|
|
229
|
-
const prompt = loadPrompt(name);
|
|
230
|
-
const sleepSeconds = Number(process.env.MDLESS_SLEEP) || SLEEP_SECONDS;
|
|
231
|
-
|
|
232
|
-
const logDir = join(process.cwd(), ".mdless", "logs");
|
|
233
|
-
mkdirSync(logDir, { recursive: true });
|
|
234
|
-
const logStream = createWriteStream(join(logDir, `${name}.log`), { flags: "a" });
|
|
235
|
-
|
|
236
|
-
const titleColor = AGENT_COLOR;
|
|
237
|
-
const banner =
|
|
238
|
-
`\n${titleColor}${BOLD} ✦ mdless · ${name}${RESET}\n` +
|
|
239
|
-
`${DIM} ${"─".repeat(40)}${RESET}\n` +
|
|
240
|
-
`${DIM} loop every ${sleepSeconds}s · logs in .mdless/logs/${name}.log${RESET}\n`;
|
|
241
|
-
process.stdout.write(banner);
|
|
242
|
-
logStream.write(banner);
|
|
243
|
-
|
|
244
|
-
process.on("SIGINT", () => {
|
|
245
|
-
process.stdout.write(`\n ${DIM}${name} stopped${RESET}\n`);
|
|
246
|
-
process.exit(0);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
while (true) {
|
|
250
|
-
const header = `\n${DIM}── ${timestamp()} ─────────────────────────────${RESET}\n`;
|
|
251
|
-
process.stdout.write(header);
|
|
252
|
-
logStream.write(header);
|
|
253
|
-
|
|
254
|
-
await runClaude(prompt, logStream);
|
|
255
|
-
|
|
256
|
-
const footer = `${DIM} sleeping ${sleepSeconds}s…${RESET}\n`;
|
|
257
|
-
process.stdout.write(footer);
|
|
258
|
-
logStream.write(footer);
|
|
259
|
-
|
|
260
|
-
await sleep(sleepSeconds);
|
|
261
|
-
}
|
|
262
|
-
}
|
package/src/commands/init.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
appendFileSync,
|
|
3
|
-
copyFileSync,
|
|
4
|
-
existsSync,
|
|
5
|
-
mkdirSync,
|
|
6
|
-
readFileSync,
|
|
7
|
-
readdirSync,
|
|
8
|
-
} from "node:fs";
|
|
9
|
-
import { join } from "node:path";
|
|
10
|
-
|
|
11
|
-
const BUNDLED_PROMPTS_DIR = join(
|
|
12
|
-
import.meta.dirname!,
|
|
13
|
-
"..",
|
|
14
|
-
"agents",
|
|
15
|
-
"prompts",
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
const GITIGNORE_ENTRIES = [".mdless/worktrees/", ".mdless/logs/"];
|
|
19
|
-
|
|
20
|
-
function ensureGitignore(): void {
|
|
21
|
-
const gitignore = join(process.cwd(), ".gitignore");
|
|
22
|
-
const existing = existsSync(gitignore) ? readFileSync(gitignore, "utf8") : "";
|
|
23
|
-
const lines = new Set(existing.split("\n").map((l) => l.trim()));
|
|
24
|
-
const missing = GITIGNORE_ENTRIES.filter((e) => !lines.has(e));
|
|
25
|
-
if (missing.length === 0) return;
|
|
26
|
-
|
|
27
|
-
const prefix = !existing || existing.endsWith("\n") ? "" : "\n";
|
|
28
|
-
appendFileSync(gitignore, prefix + missing.map((e) => `${e}\n`).join(""));
|
|
29
|
-
for (const entry of missing) {
|
|
30
|
-
console.log(`✓ added ${entry} to .gitignore`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function initCommand(): Promise<void> {
|
|
35
|
-
const targetDir = join(process.cwd(), ".mdless", "agents");
|
|
36
|
-
mkdirSync(targetDir, { recursive: true });
|
|
37
|
-
|
|
38
|
-
ensureGitignore();
|
|
39
|
-
|
|
40
|
-
const files = readdirSync(BUNDLED_PROMPTS_DIR).filter((f) => f.endsWith(".md"));
|
|
41
|
-
if (files.length === 0) {
|
|
42
|
-
console.error(`✗ no bundled prompts found at ${BUNDLED_PROMPTS_DIR}`);
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let copied = 0;
|
|
47
|
-
let skipped = 0;
|
|
48
|
-
for (const file of files) {
|
|
49
|
-
const dest = join(targetDir, file);
|
|
50
|
-
if (existsSync(dest)) {
|
|
51
|
-
console.log(`! ${file} already exists in .mdless/agents/ (skipped)`);
|
|
52
|
-
skipped++;
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
copyFileSync(join(BUNDLED_PROMPTS_DIR, file), dest);
|
|
56
|
-
console.log(`✓ ${file}`);
|
|
57
|
-
copied++;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
console.log(
|
|
61
|
-
`\n${copied} copied, ${skipped} skipped → .mdless/agents/`,
|
|
62
|
-
);
|
|
63
|
-
console.log(`Edit those files to customize prompts, then run \`mdless work\`.`);
|
|
64
|
-
}
|
package/src/commands/start.ts
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
existsSync,
|
|
4
|
-
mkdirSync,
|
|
5
|
-
readFileSync,
|
|
6
|
-
readdirSync,
|
|
7
|
-
appendFileSync,
|
|
8
|
-
} from "node:fs";
|
|
9
|
-
import { basename, join } from "node:path";
|
|
10
|
-
import { platform } from "node:os";
|
|
11
|
-
import { confirm } from "@inquirer/prompts";
|
|
12
|
-
import { initCommand } from "./init.js";
|
|
13
|
-
import { withExitHandler } from "../utils.js";
|
|
14
|
-
|
|
15
|
-
const SESSION_PREFIX = "mdless";
|
|
16
|
-
const LABELS: Array<{ name: string; color: string; description: string }> = [
|
|
17
|
-
{
|
|
18
|
-
name: "mdless/work",
|
|
19
|
-
color: "0E8A16",
|
|
20
|
-
description: "Tracked by the mdless agent system",
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
name: "mdless/approved",
|
|
24
|
-
color: "5319E7",
|
|
25
|
-
description: "Approved via mdless",
|
|
26
|
-
},
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
function which(cmd: string): boolean {
|
|
30
|
-
const result = spawnSync("which", [cmd], { stdio: "ignore" });
|
|
31
|
-
return result.status === 0;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type InstallPlan = { manager: string; args: string[] } | null;
|
|
35
|
-
|
|
36
|
-
function installPlan(pkg: string): InstallPlan {
|
|
37
|
-
if (platform() === "darwin" && which("brew")) {
|
|
38
|
-
return { manager: "brew", args: ["install", pkg] };
|
|
39
|
-
}
|
|
40
|
-
if (platform() === "linux") {
|
|
41
|
-
if (which("apt-get")) return { manager: "sudo", args: ["apt-get", "install", "-y", pkg] };
|
|
42
|
-
if (which("dnf")) return { manager: "sudo", args: ["dnf", "install", "-y", pkg] };
|
|
43
|
-
if (which("pacman")) return { manager: "sudo", args: ["pacman", "-S", "--noconfirm", pkg] };
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function autoInstall(cmd: string): boolean {
|
|
49
|
-
const plan = installPlan(cmd);
|
|
50
|
-
if (!plan) {
|
|
51
|
-
console.error(`✗ Missing required command: ${cmd} (could not detect a package manager — install it manually)`);
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
console.log(`! ${cmd} not found — installing via ${plan.manager}...`);
|
|
55
|
-
const result = spawnSync(plan.manager, plan.args, { stdio: "inherit" });
|
|
56
|
-
if (result.status !== 0 || !which(cmd)) {
|
|
57
|
-
console.error(`✗ Failed to install ${cmd}. Install it manually and re-run.`);
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
console.log(`✓ ${cmd} installed`);
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function checkPrereqs(): boolean {
|
|
65
|
-
const autoInstallable = ["tmux"];
|
|
66
|
-
const required = ["gh", "claude"];
|
|
67
|
-
let ok = true;
|
|
68
|
-
|
|
69
|
-
for (const cmd of autoInstallable) {
|
|
70
|
-
if (!which(cmd) && !autoInstall(cmd)) ok = false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
for (const cmd of required) {
|
|
74
|
-
if (!which(cmd)) {
|
|
75
|
-
console.error(`✗ Missing required command: ${cmd}`);
|
|
76
|
-
ok = false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!ok) return false;
|
|
81
|
-
|
|
82
|
-
const auth = spawnSync("gh", ["auth", "status"], { stdio: "ignore" });
|
|
83
|
-
if (auth.status !== 0) {
|
|
84
|
-
console.error("✗ gh CLI is not authenticated. Run `gh auth login` first.");
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function ensureLabels(): void {
|
|
92
|
-
for (const label of LABELS) {
|
|
93
|
-
const result = spawnSync(
|
|
94
|
-
"gh",
|
|
95
|
-
[
|
|
96
|
-
"label",
|
|
97
|
-
"create",
|
|
98
|
-
label.name,
|
|
99
|
-
"--color",
|
|
100
|
-
label.color,
|
|
101
|
-
"--description",
|
|
102
|
-
label.description,
|
|
103
|
-
"--force",
|
|
104
|
-
],
|
|
105
|
-
{ stdio: "ignore" },
|
|
106
|
-
);
|
|
107
|
-
if (result.status === 0) {
|
|
108
|
-
console.log(`✓ label ${label.name}`);
|
|
109
|
-
} else {
|
|
110
|
-
console.log(`! could not create label ${label.name} (continuing)`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const GITIGNORE_ENTRIES = [".mdless/worktrees/", ".mdless/logs/"];
|
|
116
|
-
|
|
117
|
-
function ensureGitignore(): void {
|
|
118
|
-
const gitignore = join(process.cwd(), ".gitignore");
|
|
119
|
-
const existing = existsSync(gitignore) ? readFileSync(gitignore, "utf8") : "";
|
|
120
|
-
const lines = new Set(existing.split("\n").map((l) => l.trim()));
|
|
121
|
-
const missing = GITIGNORE_ENTRIES.filter((e) => !lines.has(e));
|
|
122
|
-
if (missing.length === 0) return;
|
|
123
|
-
|
|
124
|
-
const prefix = !existing || existing.endsWith("\n") ? "" : "\n";
|
|
125
|
-
appendFileSync(gitignore, prefix + missing.map((e) => `${e}\n`).join(""));
|
|
126
|
-
for (const entry of missing) {
|
|
127
|
-
console.log(`✓ added ${entry} to .gitignore`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function sessionName(): string {
|
|
132
|
-
return `${SESSION_PREFIX}-${basename(process.cwd())}`;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function tmuxHasSession(name: string): boolean {
|
|
136
|
-
const result = spawnSync("tmux", ["has-session", "-t", name], { stdio: "ignore" });
|
|
137
|
-
return result.status === 0;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function discoverAgents(): string[] {
|
|
141
|
-
const agentsDir = join(process.cwd(), ".mdless", "agents");
|
|
142
|
-
if (!existsSync(agentsDir)) return [];
|
|
143
|
-
return readdirSync(agentsDir)
|
|
144
|
-
.filter((f) => f.endsWith(".md"))
|
|
145
|
-
.map((f) => f.slice(0, -3))
|
|
146
|
-
.sort();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function startTmux(agents: string[]): void {
|
|
150
|
-
const session = sessionName();
|
|
151
|
-
const cwd = process.cwd();
|
|
152
|
-
|
|
153
|
-
if (tmuxHasSession(session)) {
|
|
154
|
-
console.log(`Session ${session} already exists. Attaching...`);
|
|
155
|
-
spawnSync("tmux", ["attach", "-t", session], { stdio: "inherit" });
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const [first, ...rest] = agents;
|
|
160
|
-
const cmds: string[][] = [
|
|
161
|
-
["new-session", "-d", "-s", session, "-n", "agents", "-c", cwd],
|
|
162
|
-
["set-option", "-t", session, "mouse", "on"],
|
|
163
|
-
["send-keys", "-t", session, `mdless agent ${first}`, "C-m"],
|
|
164
|
-
];
|
|
165
|
-
for (const name of rest) {
|
|
166
|
-
cmds.push(["split-window", "-h", "-t", session, "-c", cwd]);
|
|
167
|
-
cmds.push(["send-keys", "-t", session, `mdless agent ${name}`, "C-m"]);
|
|
168
|
-
}
|
|
169
|
-
cmds.push(["select-layout", "-t", session, "even-horizontal"]);
|
|
170
|
-
|
|
171
|
-
for (const args of cmds) {
|
|
172
|
-
const result = spawnSync("tmux", args, { stdio: "inherit" });
|
|
173
|
-
if (result.status !== 0) {
|
|
174
|
-
console.error(`tmux ${args.join(" ")} failed`);
|
|
175
|
-
process.exit(1);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
console.log(
|
|
180
|
-
`\n✓ tmux session ${session} started with ${agents.length} agent${agents.length === 1 ? "" : "s"}: ${agents.join(", ")}`,
|
|
181
|
-
);
|
|
182
|
-
console.log(` Attaching... (detach with Ctrl-b d, kill with: tmux kill-session -t ${session})\n`);
|
|
183
|
-
spawnSync("tmux", ["attach", "-t", session], { stdio: "inherit" });
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function playStartupSound(): void {
|
|
187
|
-
const audioPath = join(import.meta.dirname!, "..", "..", "assets", "ready-to-work.mp3");
|
|
188
|
-
if (!existsSync(audioPath)) return;
|
|
189
|
-
|
|
190
|
-
const player = platform() === "darwin" ? "afplay" : platform() === "linux" ? "mpg123" : null;
|
|
191
|
-
if (!player || !which(player)) return;
|
|
192
|
-
|
|
193
|
-
spawn(player, [audioPath], { stdio: "ignore", detached: true }).unref();
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export async function startCommand(): Promise<void> {
|
|
197
|
-
if (!existsSync(join(process.cwd(), ".git"))) {
|
|
198
|
-
console.error("✗ mdless work must be run inside a git repository.");
|
|
199
|
-
process.exit(1);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
let agents = discoverAgents();
|
|
203
|
-
if (agents.length === 0) {
|
|
204
|
-
console.log("! no agent prompts found in .mdless/agents/");
|
|
205
|
-
const shouldInit = await withExitHandler(
|
|
206
|
-
confirm({
|
|
207
|
-
message: "Run `mdless init` to copy the default prompts?",
|
|
208
|
-
default: true,
|
|
209
|
-
}),
|
|
210
|
-
);
|
|
211
|
-
if (!shouldInit) {
|
|
212
|
-
process.exit(1);
|
|
213
|
-
}
|
|
214
|
-
await initCommand();
|
|
215
|
-
agents = discoverAgents();
|
|
216
|
-
if (agents.length === 0) {
|
|
217
|
-
console.error("✗ init ran but no prompts were found. Aborting.");
|
|
218
|
-
process.exit(1);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (!checkPrereqs()) {
|
|
223
|
-
process.exit(1);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
ensureLabels();
|
|
227
|
-
ensureGitignore();
|
|
228
|
-
mkdirSync(join(process.cwd(), ".mdless", "logs"), { recursive: true });
|
|
229
|
-
mkdirSync(join(process.cwd(), ".mdless", "worktrees"), { recursive: true });
|
|
230
|
-
|
|
231
|
-
playStartupSound();
|
|
232
|
-
startTmux(agents);
|
|
233
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env tsx
|
|
2
|
-
import { Command } from "commander";
|
|
3
|
-
import { select } from "@inquirer/prompts";
|
|
4
|
-
import packageJson from "../package.json" with { type: "json" };
|
|
5
|
-
import { agentCommand } from "./commands/agent.js";
|
|
6
|
-
import { initCommand } from "./commands/init.js";
|
|
7
|
-
import { startCommand } from "./commands/start.js";
|
|
8
|
-
import { withExitHandler } from "./utils.js";
|
|
9
|
-
|
|
10
|
-
const banner = `
|
|
11
|
-
\x1b[38;5;135m██╗\x1b[0m \x1b[38;5;141m███╗ ███╗\x1b[38;5;147m██████╗ \x1b[38;5;153m██╗ \x1b[38;5;159m███████╗\x1b[38;5;195m███████╗\x1b[38;5;231m███████╗
|
|
12
|
-
\x1b[38;5;135m╚██╗\x1b[0m \x1b[38;5;141m████╗ ████║\x1b[38;5;147m██╔══██╗\x1b[38;5;153m██║ \x1b[38;5;159m██╔════╝\x1b[38;5;195m██╔════╝\x1b[38;5;231m██╔════╝
|
|
13
|
-
\x1b[38;5;135m ╚██╗\x1b[0m \x1b[38;5;141m██╔████╔██║\x1b[38;5;147m██║ ██║\x1b[38;5;153m██║ \x1b[38;5;159m█████╗ \x1b[38;5;195m███████╗\x1b[38;5;231m███████╗
|
|
14
|
-
\x1b[38;5;135m ██╔╝\x1b[0m \x1b[38;5;141m██║╚██╔╝██║\x1b[38;5;147m██║ ██║\x1b[38;5;153m██║ \x1b[38;5;159m██╔══╝ \x1b[38;5;195m╚════██║\x1b[38;5;231m╚════██║
|
|
15
|
-
\x1b[38;5;135m██╔╝\x1b[0m \x1b[38;5;141m██║ ╚═╝ ██║\x1b[38;5;147m██████╔╝\x1b[38;5;153m███████╗\x1b[38;5;159m███████╗\x1b[38;5;195m███████║\x1b[38;5;231m███████║
|
|
16
|
-
\x1b[38;5;135m╚═╝\x1b[0m \x1b[38;5;141m╚═╝ ╚═╝\x1b[38;5;147m╚═════╝ \x1b[38;5;153m╚══════╝\x1b[38;5;159m╚══════╝\x1b[38;5;195m╚══════╝\x1b[38;5;231m╚══════╝\x1b[0m
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
const commands = [
|
|
20
|
-
{
|
|
21
|
-
name: "init",
|
|
22
|
-
description: "Copy the default agent prompts into .mdless/agents/",
|
|
23
|
-
action: initCommand,
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: "work",
|
|
27
|
-
description: "Launch the agents in .mdless/agents/ in a tmux session",
|
|
28
|
-
action: startCommand,
|
|
29
|
-
},
|
|
30
|
-
] as const;
|
|
31
|
-
|
|
32
|
-
async function interactiveMode(): Promise<void> {
|
|
33
|
-
console.log(banner);
|
|
34
|
-
console.log(
|
|
35
|
-
`\x1b[2m Mind less, ship more. v${packageJson.version}\x1b[0m\n`,
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const choice = await withExitHandler(
|
|
39
|
-
select({
|
|
40
|
-
message: "What would you like to do?",
|
|
41
|
-
choices: [
|
|
42
|
-
...commands.map((cmd) => ({
|
|
43
|
-
name: cmd.name,
|
|
44
|
-
value: cmd.name,
|
|
45
|
-
description: cmd.description,
|
|
46
|
-
})),
|
|
47
|
-
{ name: "exit", value: "exit", description: "Exit the CLI" },
|
|
48
|
-
],
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
if (choice === "exit") {
|
|
53
|
-
process.exit(0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const command = commands.find((cmd) => cmd.name === choice);
|
|
57
|
-
if (command) {
|
|
58
|
-
await command.action();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const program = new Command()
|
|
63
|
-
.name("mdless")
|
|
64
|
-
.description("CLI tools for Claude Code hard-working devs")
|
|
65
|
-
.version(packageJson.version);
|
|
66
|
-
|
|
67
|
-
for (const cmd of commands) {
|
|
68
|
-
program.command(cmd.name).description(cmd.description).action(cmd.action);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
program
|
|
72
|
-
.command("agent <name>")
|
|
73
|
-
.description("Run a single agent on repeat — reads the prompt from .mdless/agents/<name>.md")
|
|
74
|
-
.action(agentCommand);
|
|
75
|
-
|
|
76
|
-
// If no arguments provided, show interactive mode
|
|
77
|
-
if (process.argv.length <= 2) {
|
|
78
|
-
interactiveMode();
|
|
79
|
-
} else {
|
|
80
|
-
program.parse();
|
|
81
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function exit(): never {
|
|
2
|
-
console.log("\nAborted.");
|
|
3
|
-
process.exit(0);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function withExitHandler<T>(promise: Promise<T>): Promise<T> {
|
|
7
|
-
return promise.catch((e: Error) => {
|
|
8
|
-
if (e.name === "ExitPromptError") exit();
|
|
9
|
-
throw e;
|
|
10
|
-
});
|
|
11
|
-
}
|