@mdless/cli 1.0.9 → 1.1.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/assets/ready-to-work.mp3 +0 -0
- package/assets/screenshot.png +0 -0
- package/package.json +8 -3
- package/skills/sentry/SKILL.md +39 -0
- package/src/agents/prompts/executor.md +136 -0
- package/src/agents/prompts/reviewer.md +80 -0
- package/src/agents/prompts/watcher.md +92 -0
- package/src/commands/agent.ts +278 -0
- package/src/commands/init.ts +64 -0
- package/src/commands/start.ts +224 -0
- package/src/index.ts +18 -0
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdless/cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Mind less, ship more. Share Claude Code skills across projects and teams.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"bin.mjs",
|
|
11
11
|
"src/",
|
|
12
|
-
"skills/"
|
|
12
|
+
"skills/",
|
|
13
|
+
"assets/"
|
|
13
14
|
],
|
|
14
15
|
"keywords": [
|
|
15
16
|
"cli",
|
|
@@ -21,12 +22,16 @@
|
|
|
21
22
|
"type": "git",
|
|
22
23
|
"url": "https://github.com/mdless/mdless-cli.git"
|
|
23
24
|
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
24
28
|
"dependencies": {
|
|
25
29
|
"@inquirer/prompts": "^8.2.0",
|
|
26
30
|
"commander": "^14.0.3",
|
|
27
31
|
"tsx": "^4.7.0"
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
30
|
-
"@types/bun": "^1.3.8"
|
|
34
|
+
"@types/bun": "^1.3.8",
|
|
35
|
+
"typescript": "^6.0.3"
|
|
31
36
|
}
|
|
32
37
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sentry
|
|
3
|
+
description: Investigate Sentry issues and errors using the sentry-cli
|
|
4
|
+
allowed-tools: Bash(sentry-cli:*), Read, Grep, Glob, Edit
|
|
5
|
+
argument-hint: [optional: issue ID]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Sentry
|
|
9
|
+
|
|
10
|
+
Investigate Sentry issues and errors using `sentry-cli`.
|
|
11
|
+
|
|
12
|
+
## Instructions
|
|
13
|
+
|
|
14
|
+
1. Based on $ARGUMENTS, run `sentry-cli issues list` directly:
|
|
15
|
+
- **No arguments**: `sentry-cli issues list -s unresolved --max-rows 10`
|
|
16
|
+
- **Issue ID provided**: `sentry-cli issues list -i <ID>`
|
|
17
|
+
|
|
18
|
+
2. If the command fails due to missing authentication or configuration, help the user create a `.sentryclirc` in the project root:
|
|
19
|
+
|
|
20
|
+
```ini
|
|
21
|
+
[auth]
|
|
22
|
+
token=<ask user for their token>
|
|
23
|
+
|
|
24
|
+
[defaults]
|
|
25
|
+
org=<ask user for org slug>
|
|
26
|
+
project=<ask user for project slug>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Make sure `.sentryclirc` is listed in `.gitignore` since it contains the auth token. Then retry the command.
|
|
30
|
+
|
|
31
|
+
3. Analyze the issues found. For each relevant issue, identify the likely root cause by reading the referenced source files.
|
|
32
|
+
|
|
33
|
+
4. If the user wants a fix, apply it directly. Otherwise, summarize findings and suggest next steps.
|
|
34
|
+
|
|
35
|
+
## Tips
|
|
36
|
+
|
|
37
|
+
- Use `sentry-cli issues list --query "is:unresolved level:error"` for unresolved errors only
|
|
38
|
+
- Use `--max-rows` and `--pages` to limit output
|
|
39
|
+
- Always prefer `sentry-cli` over the Sentry MCP or API
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Executor Agent
|
|
2
|
+
|
|
3
|
+
You implement fixes for work tracked in GitHub. You have two phases per invocation: Phase 1: Follow-up and Phase 2: New work.
|
|
4
|
+
|
|
5
|
+
Phase 1 always takes priority over Phase 2. Only move to Phase 2 if Phase 1 finds nothing.
|
|
6
|
+
|
|
7
|
+
Do one unit of work per invocation (one thread resolved, or one PR opened), then exit. The wrapper sleeps and re-invokes you.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Phase 1: Follow-up — Address unresolved PR comments
|
|
12
|
+
|
|
13
|
+
### Step 1 — List open work PRs
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
gh pr list --label mdless/work --state open \
|
|
17
|
+
--json number,headRefName,url
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Step 2 — Fetch unresolved threads
|
|
21
|
+
|
|
22
|
+
For each PR, run:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
gh api graphql -F owner=<owner> -F repo=<repo> -F pr=<number> -f query='
|
|
26
|
+
query($owner:String!, $repo:String!, $pr:Int!) {
|
|
27
|
+
repository(owner:$owner, name:$repo) {
|
|
28
|
+
pullRequest(number:$pr) {
|
|
29
|
+
reviewThreads(first:50) {
|
|
30
|
+
nodes {
|
|
31
|
+
id
|
|
32
|
+
isResolved
|
|
33
|
+
comments(first:20) {
|
|
34
|
+
nodes { id body path line author { login } }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Step 3 — Decide per thread
|
|
44
|
+
|
|
45
|
+
For each thread where `isResolved == false`, decide:
|
|
46
|
+
|
|
47
|
+
(a) Push back — comment is not pertinent, misunderstood, or out of scope.
|
|
48
|
+
→ Reply with a respectful, clear explanation. Then resolve the thread.
|
|
49
|
+
|
|
50
|
+
(b) Implement — comment is valid.
|
|
51
|
+
→ Check out the PR's branch in its existing worktree. Make the change, commit, push.
|
|
52
|
+
→ Reply briefly confirming what changed. Then resolve the thread.
|
|
53
|
+
|
|
54
|
+
### Step 4 — How to reply and resolve
|
|
55
|
+
|
|
56
|
+
Reply to a thread:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
gh api repos/<owner>/<repo>/pulls/<pr>/comments/<comment-id>/replies \
|
|
60
|
+
-f body='...'
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Resolve a thread:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
gh api graphql -F id=<threadId> -f query='
|
|
67
|
+
mutation($id:ID!) {
|
|
68
|
+
resolveReviewThread(input:{threadId:$id}) { thread { id } }
|
|
69
|
+
}'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Phase 2: New work — Implement an open issue
|
|
75
|
+
|
|
76
|
+
Only run this if Phase 1 had zero unresolved threads across all `mdless/work` PRs.
|
|
77
|
+
|
|
78
|
+
### Step 1 — List candidates
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
gh issue list --label mdless/work --state open \
|
|
82
|
+
--json number,title,body --limit 20
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Step 2 — Filter out issues with linked PRs
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
gh pr list --label mdless/work --state open --json number,body
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
A PR is linked to issue `N` if its body contains `Closes #N` or `Fixes #N`.
|
|
92
|
+
|
|
93
|
+
### Step 3 — Pick one issue
|
|
94
|
+
|
|
95
|
+
Pick the oldest unblocked issue.
|
|
96
|
+
|
|
97
|
+
### Step 4 — Create a worktree
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
git worktree add .mdless/worktrees/issue-<N> -b mdless/issue-<N>
|
|
101
|
+
cd .mdless/worktrees/issue-<N>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
If the worktree already exists, reuse it.
|
|
105
|
+
|
|
106
|
+
### Step 5 — Implement
|
|
107
|
+
|
|
108
|
+
Keep changes minimal and focused on the issue. No unrelated cleanup.
|
|
109
|
+
|
|
110
|
+
### Step 6 — Commit, push, open PR
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
git add -A
|
|
114
|
+
git commit -m "fix: <short summary>"
|
|
115
|
+
git push -u origin mdless/issue-<N>
|
|
116
|
+
gh pr create \
|
|
117
|
+
--label mdless/work \
|
|
118
|
+
--title "..." \
|
|
119
|
+
--body "Closes #<N>
|
|
120
|
+
|
|
121
|
+
<summary>"
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Step 7 — Log and exit
|
|
125
|
+
|
|
126
|
+
Print `opened PR #<pr> for issue #<N>` and stop.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Rules
|
|
131
|
+
|
|
132
|
+
- Always work inside `.mdless/worktrees/issue-<N>/`. Never modify the main worktree.
|
|
133
|
+
- Never merge PRs. Never approve PRs.
|
|
134
|
+
- Never remove the `mdless/work` label.
|
|
135
|
+
- If stuck (merge conflict you can't resolve, ambiguous issue), comment on the issue/PR explaining and exit. Do not force a bad fix.
|
|
136
|
+
- If a phase finds nothing, print `phase 1: nothing` or `phase 2: nothing` and exit.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Reviewer Agent
|
|
2
|
+
|
|
3
|
+
You review pull requests created by the executor. You either approve them (via a label) or leave actionable inline comments.
|
|
4
|
+
|
|
5
|
+
Do one PR per invocation, then exit. The wrapper sleeps and re-invokes you.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Workflow
|
|
10
|
+
|
|
11
|
+
### Step 1 — Find a PR to review
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
gh pr list --label mdless/work --state open \
|
|
15
|
+
--json number,url,reviews,reviewDecision,headRefName
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Skip a PR if any of these are true:
|
|
19
|
+
|
|
20
|
+
- It already has the `mdless/approved` label.
|
|
21
|
+
- It already has a review or review comment from you.
|
|
22
|
+
|
|
23
|
+
Pick the oldest PR that passes the filter.
|
|
24
|
+
|
|
25
|
+
### Step 2 — Read the diff and the linked issue
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
gh pr diff <number>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Find the linked issue in the PR body (`Closes #N`) and read it:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
gh issue view <N>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Step 3 — Review against this checklist
|
|
38
|
+
|
|
39
|
+
| Aspect | What to check |
|
|
40
|
+
| ----------- | ---------------------------------------------------------------------------- |
|
|
41
|
+
| Correctness | Does it actually solve the issue? |
|
|
42
|
+
| Scope | Any changes unrelated to the issue? |
|
|
43
|
+
| Bugs | Obvious off-by-one, null derefs, missed error paths, broken types? |
|
|
44
|
+
| Tests | If similar code has tests, are there new/updated tests here? |
|
|
45
|
+
| Guidelines | Read `CLAUDE.md` (and any nested ones). Flag clear violations of its rules. |
|
|
46
|
+
|
|
47
|
+
Do not review subjective style. Only flag what's explicitly documented in `CLAUDE.md` or what's an actual bug.
|
|
48
|
+
|
|
49
|
+
### Step 4 — Decide
|
|
50
|
+
|
|
51
|
+
#### Approve
|
|
52
|
+
|
|
53
|
+
If the PR is correct, scoped, and safe:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
gh pr edit <number> --add-label mdless/approved
|
|
57
|
+
gh pr comment <number> --body "<short reason for approval>"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Request changes
|
|
61
|
+
|
|
62
|
+
Leave inline comments on specific lines via the GitHub API:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
gh api repos/<owner>/<repo>/pulls/<pr>/comments \
|
|
66
|
+
-f body='...' -f commit_id='...' -f path='...' -F line=...
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Each comment must be specific and actionable — point to a line and say what to change and why.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Rules
|
|
74
|
+
|
|
75
|
+
- Do not use `gh pr review --approve`. GitHub blocks self-approval when the same auth created the PR. Use the `mdless/approved` label instead.
|
|
76
|
+
- Do not merge PRs. Only the human merges.
|
|
77
|
+
- Do not review the same PR twice in the same iteration.
|
|
78
|
+
- Be direct and concise. No filler like "great work!" or "lgtm with one nit".
|
|
79
|
+
- If a PR is too large or risky to judge confidently, leave a comment saying so and asking the human to review. Do not approve.
|
|
80
|
+
- If there is nothing to review, print `nothing to review` and exit.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Watcher Agent
|
|
2
|
+
|
|
3
|
+
You scan this project for problems and file GitHub issues so other agents can pick them up.
|
|
4
|
+
|
|
5
|
+
You never edit code or create PRs. Only issues.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Sources
|
|
10
|
+
|
|
11
|
+
Scan these in order. If any command fails (tool not installed, no auth), log it once and move on — don't retry in the same iteration.
|
|
12
|
+
|
|
13
|
+
### 1. Sentry — unresolved issues
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
sentry-cli issues list --status unresolved
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 2. TODO / FIXME comments
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
git grep -nE "TODO|FIXME" -- ':!*.md' ':!.mdless'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Only flag things that look actionable. Skip example/doc style comments.
|
|
26
|
+
|
|
27
|
+
### 3. Dependency vulnerabilities
|
|
28
|
+
|
|
29
|
+
Pick the audit command matching the project's lockfile:
|
|
30
|
+
|
|
31
|
+
- `npm audit --json`
|
|
32
|
+
- `pnpm audit --json`
|
|
33
|
+
- `yarn audit --json`
|
|
34
|
+
- `bun audit --json`
|
|
35
|
+
|
|
36
|
+
Only act on high and critical severity.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Workflow per candidate
|
|
41
|
+
|
|
42
|
+
### Step 1 — Deduplicate
|
|
43
|
+
|
|
44
|
+
Search existing issues with the `mdless/work` label:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
gh issue list --label mdless/work --state all --limit 200 \
|
|
48
|
+
--json number,title,body --search "<source-id>"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Each source has a unique id format embedded in the issue body:
|
|
52
|
+
|
|
53
|
+
| Source | Source-ID line |
|
|
54
|
+
| ------ | --------------------------------------- |
|
|
55
|
+
| Sentry | `Sentry-ID: <id>` |
|
|
56
|
+
| TODO | `Source-Ref: <file>:<line>` |
|
|
57
|
+
| CVE | `CVE: <cve-id>` or `Advisory: <ghsa-id>` |
|
|
58
|
+
|
|
59
|
+
If a matching issue exists (open or closed), skip — never duplicate.
|
|
60
|
+
|
|
61
|
+
### Step 2 — Create the issue
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
gh issue create --label mdless/work --title "..." --body "..."
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Title: concise and action-oriented.
|
|
68
|
+
Good: `Fix null deref in PaymentProcessor.charge`
|
|
69
|
+
Good: `Upgrade lodash to patch CVE-2024-XXXXX`
|
|
70
|
+
Bad: `Sentry issue ABC-456`
|
|
71
|
+
|
|
72
|
+
Body: start with metadata, then a separator, then details.
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
Source: sentry | todo | cve
|
|
76
|
+
<Source-ID line>
|
|
77
|
+
---
|
|
78
|
+
<problem description, affected files/area, repro details>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Step 3 — Log one line
|
|
82
|
+
|
|
83
|
+
- `created #123 sentry ABC-456`
|
|
84
|
+
- `skip todo src/foo.ts:42 (already #98)`
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Rules
|
|
89
|
+
|
|
90
|
+
- Every issue must have the `mdless/work` label.
|
|
91
|
+
- Be conservative: skipping a borderline case > spamming the tracker.
|
|
92
|
+
- If you find nothing new, print `no new issues` and exit. The wrapper sleeps and re-invokes you.
|
|
@@ -0,0 +1,278 @@
|
|
|
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 DEFAULT_SLEEP_SECONDS: Record<string, number> = {
|
|
6
|
+
watcher: 300,
|
|
7
|
+
executor: 60,
|
|
8
|
+
reviewer: 120,
|
|
9
|
+
};
|
|
10
|
+
const FALLBACK_SLEEP_SECONDS = 60;
|
|
11
|
+
|
|
12
|
+
function timestamp(): string {
|
|
13
|
+
const d = new Date();
|
|
14
|
+
return d.toTimeString().slice(0, 8);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function loadPrompt(name: string): string {
|
|
18
|
+
const promptPath = join(process.cwd(), ".mdless", "agents", `${name}.md`);
|
|
19
|
+
if (!existsSync(promptPath)) {
|
|
20
|
+
console.error(
|
|
21
|
+
`✗ no prompt found at ${promptPath}\n run \`mdless init\` to create the default prompts.`,
|
|
22
|
+
);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
return readFileSync(promptPath, "utf8");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const RESET = "\x1b[0m";
|
|
29
|
+
const DIM = "\x1b[2m";
|
|
30
|
+
const BOLD = "\x1b[1m";
|
|
31
|
+
const ITALIC = "\x1b[3m";
|
|
32
|
+
|
|
33
|
+
// Purple palette (256-color, Gemini-inspired)
|
|
34
|
+
const VIOLET = "\x1b[38;5;141m"; // primary
|
|
35
|
+
const LAVENDER = "\x1b[38;5;147m"; // soft accent
|
|
36
|
+
const DEEP_PURPLE = "\x1b[38;5;99m"; // search/grep
|
|
37
|
+
const PINK_PURPLE = "\x1b[38;5;177m"; // writes/edits
|
|
38
|
+
const MAGENTA_PURPLE = "\x1b[38;5;171m"; // task/agent
|
|
39
|
+
const PALE = "\x1b[38;5;153m"; // web
|
|
40
|
+
const SOFT_PINK = "\x1b[38;5;211m"; // errors (still readable)
|
|
41
|
+
|
|
42
|
+
const TOOL_COLORS: Record<string, string> = {
|
|
43
|
+
Bash: VIOLET,
|
|
44
|
+
Read: LAVENDER,
|
|
45
|
+
Write: PINK_PURPLE,
|
|
46
|
+
Edit: PINK_PURPLE,
|
|
47
|
+
MultiEdit: PINK_PURPLE,
|
|
48
|
+
Glob: DEEP_PURPLE,
|
|
49
|
+
Grep: DEEP_PURPLE,
|
|
50
|
+
WebFetch: PALE,
|
|
51
|
+
WebSearch: PALE,
|
|
52
|
+
Task: MAGENTA_PURPLE,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const AGENT_COLORS: Record<string, string> = {
|
|
56
|
+
watcher: LAVENDER,
|
|
57
|
+
executor: VIOLET,
|
|
58
|
+
reviewer: MAGENTA_PURPLE,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
function toolColor(name: string): string {
|
|
62
|
+
return TOOL_COLORS[name] ?? VIOLET;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function agentColor(name: string): string {
|
|
66
|
+
return AGENT_COLORS[name] ?? VIOLET;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function truncate(s: string, n: number): string {
|
|
70
|
+
const clean = s.replace(/\s+/g, " ").trim();
|
|
71
|
+
return clean.length > n ? clean.slice(0, n - 1) + "…" : clean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function summarizeToolInput(name: string, input: any): string {
|
|
75
|
+
if (!input || typeof input !== "object") return "";
|
|
76
|
+
switch (name) {
|
|
77
|
+
case "Bash":
|
|
78
|
+
return `$ ${truncate(input.command ?? "", 140)}`;
|
|
79
|
+
case "Read":
|
|
80
|
+
return input.file_path ?? "";
|
|
81
|
+
case "Write":
|
|
82
|
+
return input.file_path ?? "";
|
|
83
|
+
case "Edit":
|
|
84
|
+
case "MultiEdit":
|
|
85
|
+
return input.file_path ?? "";
|
|
86
|
+
case "Glob":
|
|
87
|
+
return input.pattern ?? "";
|
|
88
|
+
case "Grep": {
|
|
89
|
+
const where = input.path ? ` in ${input.path}` : input.glob ? ` (${input.glob})` : "";
|
|
90
|
+
return `"${truncate(input.pattern ?? "", 80)}"${where}`;
|
|
91
|
+
}
|
|
92
|
+
case "WebFetch":
|
|
93
|
+
case "WebSearch":
|
|
94
|
+
return input.url ?? input.query ?? "";
|
|
95
|
+
case "Task":
|
|
96
|
+
return truncate(input.description ?? input.prompt ?? "", 120);
|
|
97
|
+
default: {
|
|
98
|
+
const first = Object.values(input).find((v) => typeof v === "string");
|
|
99
|
+
return typeof first === "string" ? truncate(first, 120) : truncate(JSON.stringify(input), 120);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function summarizeToolResult(raw: string, isError: boolean): string {
|
|
105
|
+
if (!raw.trim()) return isError ? "(error, no output)" : "(no output)";
|
|
106
|
+
const lines = raw.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
107
|
+
if (lines.length === 0) return "(empty)";
|
|
108
|
+
const firstLine = lines[0]!;
|
|
109
|
+
|
|
110
|
+
if (firstLine.startsWith("{") || firstLine.startsWith("[")) {
|
|
111
|
+
try {
|
|
112
|
+
const parsed = JSON.parse(raw);
|
|
113
|
+
if (Array.isArray(parsed)) return `[${parsed.length} items]`;
|
|
114
|
+
if (parsed && typeof parsed === "object") {
|
|
115
|
+
const keys = Object.keys(parsed);
|
|
116
|
+
if (keys.length === 0) return "{}";
|
|
117
|
+
return `{${keys.slice(0, 4).join(", ")}${keys.length > 4 ? ", …" : ""}}`;
|
|
118
|
+
}
|
|
119
|
+
} catch {}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const extra = lines.length > 1 ? ` (+${lines.length - 1} lines)` : "";
|
|
123
|
+
return truncate(firstLine, 140) + extra;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function indent(text: string, prefix: string): string {
|
|
127
|
+
return text
|
|
128
|
+
.split("\n")
|
|
129
|
+
.map((line) => prefix + line)
|
|
130
|
+
.join("\n");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function formatStreamEvent(line: string): string | null {
|
|
134
|
+
let evt: any;
|
|
135
|
+
try {
|
|
136
|
+
evt = JSON.parse(line);
|
|
137
|
+
} catch {
|
|
138
|
+
return line + "\n";
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (evt.type === "system" && evt.subtype === "init") {
|
|
142
|
+
const session = (evt.session_id ?? "?").toString().slice(0, 8);
|
|
143
|
+
const tools = Array.isArray(evt.tools) ? evt.tools.length : 0;
|
|
144
|
+
return `${DIM} session ${session} · ${tools} tools loaded${RESET}\n\n`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (evt.type === "assistant" && evt.message?.content) {
|
|
148
|
+
const out: string[] = [];
|
|
149
|
+
for (const block of evt.message.content) {
|
|
150
|
+
if (block.type === "text" && block.text?.trim()) {
|
|
151
|
+
out.push("\n" + indent(block.text.trim(), " ") + "\n");
|
|
152
|
+
} else if (block.type === "tool_use") {
|
|
153
|
+
const summary = summarizeToolInput(block.name, block.input);
|
|
154
|
+
const color = toolColor(block.name);
|
|
155
|
+
out.push(` ${color}▸${RESET} ${color}${block.name.padEnd(9)}${RESET}${summary}`);
|
|
156
|
+
} else if (block.type === "thinking" && block.thinking?.trim()) {
|
|
157
|
+
out.push(` ${DIM}${ITALIC}~ ${truncate(block.thinking, 200)}${RESET}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return out.length ? out.join("\n") + "\n" : null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (evt.type === "user" && evt.message?.content) {
|
|
164
|
+
const out: string[] = [];
|
|
165
|
+
for (const block of evt.message.content) {
|
|
166
|
+
if (block.type === "tool_result") {
|
|
167
|
+
const raw = typeof block.content === "string"
|
|
168
|
+
? block.content
|
|
169
|
+
: Array.isArray(block.content)
|
|
170
|
+
? block.content.map((c: any) => c.text ?? "").join("\n")
|
|
171
|
+
: "";
|
|
172
|
+
const summary = summarizeToolResult(raw, !!block.is_error);
|
|
173
|
+
const arrow = block.is_error ? `${SOFT_PINK}└─ ✗${RESET}` : `${DIM}└─${RESET}`;
|
|
174
|
+
out.push(` ${arrow} ${DIM}${summary}${RESET}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return out.length ? out.join("\n") + "\n" : null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (evt.type === "result") {
|
|
181
|
+
const parts: string[] = [];
|
|
182
|
+
if (evt.num_turns != null) parts.push(`${evt.num_turns} turns`);
|
|
183
|
+
if (evt.duration_ms != null) parts.push(`${(evt.duration_ms / 1000).toFixed(1)}s`);
|
|
184
|
+
if (evt.total_cost_usd != null) parts.push(`$${evt.total_cost_usd.toFixed(4)}`);
|
|
185
|
+
const color = evt.is_error ? SOFT_PINK : LAVENDER;
|
|
186
|
+
const mark = evt.is_error ? "✗" : "✓";
|
|
187
|
+
return `\n ${color}${mark}${RESET} ${DIM}${parts.join(" · ")}${RESET}\n`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function runClaude(prompt: string, logStream: NodeJS.WritableStream): Promise<number> {
|
|
194
|
+
return new Promise((resolve) => {
|
|
195
|
+
const child = spawn(
|
|
196
|
+
"claude",
|
|
197
|
+
[
|
|
198
|
+
"-p",
|
|
199
|
+
prompt,
|
|
200
|
+
"--dangerously-skip-permissions",
|
|
201
|
+
"--verbose",
|
|
202
|
+
"--output-format",
|
|
203
|
+
"stream-json",
|
|
204
|
+
],
|
|
205
|
+
{ stdio: ["ignore", "pipe", "pipe"] },
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
let buf = "";
|
|
209
|
+
child.stdout.on("data", (chunk) => {
|
|
210
|
+
buf += chunk.toString();
|
|
211
|
+
let nl: number;
|
|
212
|
+
while ((nl = buf.indexOf("\n")) !== -1) {
|
|
213
|
+
const line = buf.slice(0, nl);
|
|
214
|
+
buf = buf.slice(nl + 1);
|
|
215
|
+
if (!line.trim()) continue;
|
|
216
|
+
const formatted = formatStreamEvent(line);
|
|
217
|
+
if (formatted) {
|
|
218
|
+
process.stdout.write(formatted);
|
|
219
|
+
logStream.write(formatted);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
child.stderr.on("data", (chunk) => {
|
|
224
|
+
process.stderr.write(chunk);
|
|
225
|
+
logStream.write(chunk);
|
|
226
|
+
});
|
|
227
|
+
child.on("error", (err) => {
|
|
228
|
+
const msg = `\n[agent] failed to spawn claude: ${err.message}\n`;
|
|
229
|
+
process.stderr.write(msg);
|
|
230
|
+
logStream.write(msg);
|
|
231
|
+
resolve(1);
|
|
232
|
+
});
|
|
233
|
+
child.on("exit", (code) => resolve(code ?? 0));
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function sleep(seconds: number): Promise<void> {
|
|
238
|
+
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export async function agentCommand(name: string): Promise<void> {
|
|
242
|
+
const prompt = loadPrompt(name);
|
|
243
|
+
const sleepSeconds =
|
|
244
|
+
Number(process.env.MDLESS_SLEEP) ||
|
|
245
|
+
DEFAULT_SLEEP_SECONDS[name] ||
|
|
246
|
+
FALLBACK_SLEEP_SECONDS;
|
|
247
|
+
|
|
248
|
+
const logDir = join(process.cwd(), ".mdless", "logs");
|
|
249
|
+
mkdirSync(logDir, { recursive: true });
|
|
250
|
+
const logStream = createWriteStream(join(logDir, `${name}.log`), { flags: "a" });
|
|
251
|
+
|
|
252
|
+
const titleColor = agentColor(name);
|
|
253
|
+
const banner =
|
|
254
|
+
`\n${titleColor}${BOLD} ✦ mdless · ${name}${RESET}\n` +
|
|
255
|
+
`${DIM} ${"─".repeat(40)}${RESET}\n` +
|
|
256
|
+
`${DIM} loop every ${sleepSeconds}s · logs in .mdless/logs/${name}.log${RESET}\n`;
|
|
257
|
+
process.stdout.write(banner);
|
|
258
|
+
logStream.write(banner);
|
|
259
|
+
|
|
260
|
+
process.on("SIGINT", () => {
|
|
261
|
+
process.stdout.write(`\n ${DIM}${name} stopped${RESET}\n`);
|
|
262
|
+
process.exit(0);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
while (true) {
|
|
266
|
+
const header = `\n${DIM}── ${timestamp()} ─────────────────────────────${RESET}\n`;
|
|
267
|
+
process.stdout.write(header);
|
|
268
|
+
logStream.write(header);
|
|
269
|
+
|
|
270
|
+
await runClaude(prompt, logStream);
|
|
271
|
+
|
|
272
|
+
const footer = `${DIM} sleeping ${sleepSeconds}s…${RESET}\n`;
|
|
273
|
+
process.stdout.write(footer);
|
|
274
|
+
logStream.write(footer);
|
|
275
|
+
|
|
276
|
+
await sleep(sleepSeconds);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
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
|
+
|
|
12
|
+
const SESSION_PREFIX = "mdless";
|
|
13
|
+
const LABELS: Array<{ name: string; color: string; description: string }> = [
|
|
14
|
+
{
|
|
15
|
+
name: "mdless/work",
|
|
16
|
+
color: "0E8A16",
|
|
17
|
+
description: "Tracked by the mdless agent system",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "mdless/approved",
|
|
21
|
+
color: "5319E7",
|
|
22
|
+
description: "Approved by the mdless reviewer agent",
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
function which(cmd: string): boolean {
|
|
27
|
+
const result = spawnSync("which", [cmd], { stdio: "ignore" });
|
|
28
|
+
return result.status === 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type InstallPlan = { manager: string; args: string[] } | null;
|
|
32
|
+
|
|
33
|
+
function installPlan(pkg: string): InstallPlan {
|
|
34
|
+
if (platform() === "darwin" && which("brew")) {
|
|
35
|
+
return { manager: "brew", args: ["install", pkg] };
|
|
36
|
+
}
|
|
37
|
+
if (platform() === "linux") {
|
|
38
|
+
if (which("apt-get")) return { manager: "sudo", args: ["apt-get", "install", "-y", pkg] };
|
|
39
|
+
if (which("dnf")) return { manager: "sudo", args: ["dnf", "install", "-y", pkg] };
|
|
40
|
+
if (which("pacman")) return { manager: "sudo", args: ["pacman", "-S", "--noconfirm", pkg] };
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function autoInstall(cmd: string): boolean {
|
|
46
|
+
const plan = installPlan(cmd);
|
|
47
|
+
if (!plan) {
|
|
48
|
+
console.error(`✗ Missing required command: ${cmd} (could not detect a package manager — install it manually)`);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
console.log(`! ${cmd} not found — installing via ${plan.manager}...`);
|
|
52
|
+
const result = spawnSync(plan.manager, plan.args, { stdio: "inherit" });
|
|
53
|
+
if (result.status !== 0 || !which(cmd)) {
|
|
54
|
+
console.error(`✗ Failed to install ${cmd}. Install it manually and re-run.`);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
console.log(`✓ ${cmd} installed`);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function checkPrereqs(): boolean {
|
|
62
|
+
const autoInstallable = ["tmux"];
|
|
63
|
+
const required = ["gh", "claude"];
|
|
64
|
+
const optional = ["sentry-cli"];
|
|
65
|
+
let ok = true;
|
|
66
|
+
|
|
67
|
+
for (const cmd of autoInstallable) {
|
|
68
|
+
if (!which(cmd) && !autoInstall(cmd)) ok = false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for (const cmd of required) {
|
|
72
|
+
if (!which(cmd)) {
|
|
73
|
+
console.error(`✗ Missing required command: ${cmd}`);
|
|
74
|
+
ok = false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const cmd of optional) {
|
|
78
|
+
if (!which(cmd)) {
|
|
79
|
+
console.log(`! Optional command not found: ${cmd} (watcher will skip this source)`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!ok) return false;
|
|
84
|
+
|
|
85
|
+
const auth = spawnSync("gh", ["auth", "status"], { stdio: "ignore" });
|
|
86
|
+
if (auth.status !== 0) {
|
|
87
|
+
console.error("✗ gh CLI is not authenticated. Run `gh auth login` first.");
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function ensureLabels(): void {
|
|
95
|
+
for (const label of LABELS) {
|
|
96
|
+
const result = spawnSync(
|
|
97
|
+
"gh",
|
|
98
|
+
[
|
|
99
|
+
"label",
|
|
100
|
+
"create",
|
|
101
|
+
label.name,
|
|
102
|
+
"--color",
|
|
103
|
+
label.color,
|
|
104
|
+
"--description",
|
|
105
|
+
label.description,
|
|
106
|
+
"--force",
|
|
107
|
+
],
|
|
108
|
+
{ stdio: "ignore" },
|
|
109
|
+
);
|
|
110
|
+
if (result.status === 0) {
|
|
111
|
+
console.log(`✓ label ${label.name}`);
|
|
112
|
+
} else {
|
|
113
|
+
console.log(`! could not create label ${label.name} (continuing)`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const GITIGNORE_ENTRIES = [".mdless/worktrees/", ".mdless/logs/"];
|
|
119
|
+
|
|
120
|
+
function ensureGitignore(): void {
|
|
121
|
+
const gitignore = join(process.cwd(), ".gitignore");
|
|
122
|
+
const existing = existsSync(gitignore) ? readFileSync(gitignore, "utf8") : "";
|
|
123
|
+
const lines = new Set(existing.split("\n").map((l) => l.trim()));
|
|
124
|
+
const missing = GITIGNORE_ENTRIES.filter((e) => !lines.has(e));
|
|
125
|
+
if (missing.length === 0) return;
|
|
126
|
+
|
|
127
|
+
const prefix = !existing || existing.endsWith("\n") ? "" : "\n";
|
|
128
|
+
appendFileSync(gitignore, prefix + missing.map((e) => `${e}\n`).join(""));
|
|
129
|
+
for (const entry of missing) {
|
|
130
|
+
console.log(`✓ added ${entry} to .gitignore`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function sessionName(): string {
|
|
135
|
+
return `${SESSION_PREFIX}-${basename(process.cwd())}`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function tmuxHasSession(name: string): boolean {
|
|
139
|
+
const result = spawnSync("tmux", ["has-session", "-t", name], { stdio: "ignore" });
|
|
140
|
+
return result.status === 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function discoverAgents(): string[] {
|
|
144
|
+
const agentsDir = join(process.cwd(), ".mdless", "agents");
|
|
145
|
+
if (!existsSync(agentsDir)) return [];
|
|
146
|
+
return readdirSync(agentsDir)
|
|
147
|
+
.filter((f) => f.endsWith(".md"))
|
|
148
|
+
.map((f) => f.slice(0, -3))
|
|
149
|
+
.sort();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function startTmux(agents: string[]): void {
|
|
153
|
+
const session = sessionName();
|
|
154
|
+
const cwd = process.cwd();
|
|
155
|
+
|
|
156
|
+
if (tmuxHasSession(session)) {
|
|
157
|
+
console.log(`Session ${session} already exists. Attaching...`);
|
|
158
|
+
spawnSync("tmux", ["attach", "-t", session], { stdio: "inherit" });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const [first, ...rest] = agents;
|
|
163
|
+
const cmds: string[][] = [
|
|
164
|
+
["new-session", "-d", "-s", session, "-n", "agents", "-c", cwd],
|
|
165
|
+
["set-option", "-t", session, "mouse", "on"],
|
|
166
|
+
["send-keys", "-t", session, `mdless agent ${first}`, "C-m"],
|
|
167
|
+
];
|
|
168
|
+
for (const name of rest) {
|
|
169
|
+
cmds.push(["split-window", "-h", "-t", session, "-c", cwd]);
|
|
170
|
+
cmds.push(["send-keys", "-t", session, `mdless agent ${name}`, "C-m"]);
|
|
171
|
+
}
|
|
172
|
+
cmds.push(["select-layout", "-t", session, "even-horizontal"]);
|
|
173
|
+
|
|
174
|
+
for (const args of cmds) {
|
|
175
|
+
const result = spawnSync("tmux", args, { stdio: "inherit" });
|
|
176
|
+
if (result.status !== 0) {
|
|
177
|
+
console.error(`tmux ${args.join(" ")} failed`);
|
|
178
|
+
process.exit(1);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
console.log(
|
|
183
|
+
`\n✓ tmux session ${session} started with ${agents.length} agent${agents.length === 1 ? "" : "s"}: ${agents.join(", ")}`,
|
|
184
|
+
);
|
|
185
|
+
console.log(` Attaching... (detach with Ctrl-b d, kill with: tmux kill-session -t ${session})\n`);
|
|
186
|
+
spawnSync("tmux", ["attach", "-t", session], { stdio: "inherit" });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function playStartupSound(): void {
|
|
190
|
+
const audioPath = join(import.meta.dirname!, "..", "..", "assets", "ready-to-work.mp3");
|
|
191
|
+
if (!existsSync(audioPath)) return;
|
|
192
|
+
|
|
193
|
+
const player = platform() === "darwin" ? "afplay" : platform() === "linux" ? "mpg123" : null;
|
|
194
|
+
if (!player || !which(player)) return;
|
|
195
|
+
|
|
196
|
+
spawn(player, [audioPath], { stdio: "ignore", detached: true }).unref();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function startCommand(): Promise<void> {
|
|
200
|
+
if (!existsSync(join(process.cwd(), ".git"))) {
|
|
201
|
+
console.error("✗ mdless work must be run inside a git repository.");
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const agents = discoverAgents();
|
|
206
|
+
if (agents.length === 0) {
|
|
207
|
+
console.error(
|
|
208
|
+
"✗ no agent prompts found in .mdless/agents/\n run `mdless init` to create the default prompts.",
|
|
209
|
+
);
|
|
210
|
+
process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (!checkPrereqs()) {
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
ensureLabels();
|
|
218
|
+
ensureGitignore();
|
|
219
|
+
mkdirSync(join(process.cwd(), ".mdless", "logs"), { recursive: true });
|
|
220
|
+
mkdirSync(join(process.cwd(), ".mdless", "worktrees"), { recursive: true });
|
|
221
|
+
|
|
222
|
+
playStartupSound();
|
|
223
|
+
startTmux(agents);
|
|
224
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import { select } from "@inquirer/prompts";
|
|
4
4
|
import packageJson from "../package.json" with { type: "json" };
|
|
5
|
+
import { agentCommand } from "./commands/agent.js";
|
|
6
|
+
import { initCommand } from "./commands/init.js";
|
|
5
7
|
import { scanCommand } from "./commands/scan.js";
|
|
6
8
|
import { skillsCommand } from "./commands/skills.js";
|
|
9
|
+
import { startCommand } from "./commands/start.js";
|
|
7
10
|
import { withExitHandler } from "./utils.js";
|
|
8
11
|
|
|
9
12
|
const banner = `
|
|
@@ -26,6 +29,16 @@ const commands = [
|
|
|
26
29
|
description: "Find Claude workspaces on your computer",
|
|
27
30
|
action: scanCommand,
|
|
28
31
|
},
|
|
32
|
+
{
|
|
33
|
+
name: "init",
|
|
34
|
+
description: "Copy the default agent prompts into .mdless/agents/",
|
|
35
|
+
action: initCommand,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "work",
|
|
39
|
+
description: "Launch the agents in .mdless/agents/ in a tmux session",
|
|
40
|
+
action: startCommand,
|
|
41
|
+
},
|
|
29
42
|
] as const;
|
|
30
43
|
|
|
31
44
|
async function interactiveMode(): Promise<void> {
|
|
@@ -67,6 +80,11 @@ for (const cmd of commands) {
|
|
|
67
80
|
program.command(cmd.name).description(cmd.description).action(cmd.action);
|
|
68
81
|
}
|
|
69
82
|
|
|
83
|
+
program
|
|
84
|
+
.command("agent <name>")
|
|
85
|
+
.description("Run a single agent loop (watcher | executor | reviewer)")
|
|
86
|
+
.action(agentCommand);
|
|
87
|
+
|
|
70
88
|
// If no arguments provided, show interactive mode
|
|
71
89
|
if (process.argv.length <= 2) {
|
|
72
90
|
interactiveMode();
|