@mdless/cli 1.0.9 β 1.2.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 +16 -29
- package/assets/ready-to-work.mp3 +0 -0
- package/assets/screenshot.png +0 -0
- package/package.json +8 -4
- package/src/agents/prompts/curator.md +84 -0
- package/src/agents/prompts/developer.md +136 -0
- package/src/agents/prompts/reviewer.md +80 -0
- package/src/commands/agent.ts +262 -0
- package/src/commands/init.ts +64 -0
- package/src/commands/start.ts +233 -0
- package/src/index.ts +14 -8
- package/src/utils.ts +0 -28
- package/skills/ci-errors/SKILL.md +0 -29
- package/skills/commit/SKILL.md +0 -27
- package/skills/pr/SKILL.md +0 -22
- package/skills/pr-comments/SKILL.md +0 -26
- package/src/commands/scan.ts +0 -90
- package/src/commands/skills.ts +0 -73
- package/src/config.ts +0 -42
package/README.md
CHANGED
|
@@ -4,21 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**Mind less, ship more.**
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Yeah, we're tired of that too.
|
|
10
|
-
|
|
11
|
-
## π€ Why "mdless"?
|
|
12
|
-
|
|
13
|
-
Two reasons:
|
|
14
|
-
|
|
15
|
-
1. Write less markdown. Skills are maintained by the community, so you don't have to craft every SKILL.md from scratch.
|
|
16
|
-
|
|
17
|
-
2. Mind less - stop overthinking - and just ship that shit out.
|
|
18
|
-
|
|
19
|
-
Mdless lets you share your superpowers across projects and teams. Skills live in your repo, not on your machineβso your whole team gets to be a superhero.
|
|
20
|
-
|
|
21
|
-
No more "it works on my Claude." No more copy-pasting skills between repos. No more explaining to Eddy how to set up his `.claude` folder for the fifth time.
|
|
7
|
+
Run custom Claude Code agent loops from markdown prompts in your repo.
|
|
22
8
|
|
|
23
9
|
## π¦ Installation
|
|
24
10
|
|
|
@@ -36,28 +22,29 @@ npm install -g @mdless/cli
|
|
|
36
22
|
|
|
37
23
|
## π Key Features
|
|
38
24
|
|
|
39
|
-
####
|
|
25
|
+
#### Set up agent prompts
|
|
40
26
|
|
|
41
27
|
```bash
|
|
42
|
-
mdless
|
|
28
|
+
mdless init
|
|
43
29
|
```
|
|
44
30
|
|
|
45
|
-
|
|
46
|
-
| ---------------------------------------------- | ------------------------------------------------- |
|
|
47
|
-
| [**commit**](skills/commit/SKILL.md) | Writes commit messages so you don't have to think |
|
|
48
|
-
| [**pr**](skills/pr/SKILL.md) | Creates PRs with actual descriptions |
|
|
49
|
-
| [**pr-comments**](skills/pr-comments/SKILL.md) | Responds to PR comments (politely) |
|
|
50
|
-
| [**ci-errors**](skills/ci-errors/SKILL.md) | Reads CI logs and fixes the errors |
|
|
31
|
+
Copies default prompts into `.mdless/agents/`. Edit them to match your project.
|
|
51
32
|
|
|
52
|
-
|
|
33
|
+
#### Run agents in tmux
|
|
53
34
|
|
|
54
|
-
|
|
35
|
+
```bash
|
|
36
|
+
mdless work
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Launches every prompt in `.mdless/agents/` as a looping agent in a tmux session.
|
|
55
40
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
#### Run a single agent
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
mdless agent <name>
|
|
45
|
+
```
|
|
59
46
|
|
|
60
|
-
|
|
47
|
+
Runs one agent on repeat using `.mdless/agents/<name>.md`.
|
|
61
48
|
|
|
62
49
|
## π License
|
|
63
50
|
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdless/cli",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "Mind less, ship more.
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Mind less, ship more. Agent loops for Claude Code projects.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"mdless": "bin.mjs"
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"bin.mjs",
|
|
11
11
|
"src/",
|
|
12
|
-
"
|
|
12
|
+
"assets/"
|
|
13
13
|
],
|
|
14
14
|
"keywords": [
|
|
15
15
|
"cli",
|
|
@@ -21,12 +21,16 @@
|
|
|
21
21
|
"type": "git",
|
|
22
22
|
"url": "https://github.com/mdless/mdless-cli.git"
|
|
23
23
|
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
24
27
|
"dependencies": {
|
|
25
28
|
"@inquirer/prompts": "^8.2.0",
|
|
26
29
|
"commander": "^14.0.3",
|
|
27
30
|
"tsx": "^4.7.0"
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
|
-
"@types/bun": "^1.3.8"
|
|
33
|
+
"@types/bun": "^1.3.8",
|
|
34
|
+
"typescript": "^6.0.3"
|
|
31
35
|
}
|
|
32
36
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Curator 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. TODO / FIXME comments
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
git grep -nE "TODO|FIXME" -- ':!*.md' ':!.mdless'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Only flag things that look actionable. Skip example/doc style comments.
|
|
20
|
+
|
|
21
|
+
### 2. Dependency vulnerabilities
|
|
22
|
+
|
|
23
|
+
Pick the audit command matching the project's lockfile:
|
|
24
|
+
|
|
25
|
+
- `npm audit --json`
|
|
26
|
+
- `pnpm audit --json`
|
|
27
|
+
- `yarn audit --json`
|
|
28
|
+
- `bun audit --json`
|
|
29
|
+
|
|
30
|
+
Only act on high and critical severity.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Workflow per candidate
|
|
35
|
+
|
|
36
|
+
### Step 1 β Deduplicate
|
|
37
|
+
|
|
38
|
+
Search existing issues with the `mdless/work` label:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
gh issue list --label mdless/work --state all --limit 200 \
|
|
42
|
+
--json number,title,body --search "<source-id>"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Each source has a unique id format embedded in the issue body:
|
|
46
|
+
|
|
47
|
+
| Source | Source-ID line |
|
|
48
|
+
| ------ | --------------------------------------- |
|
|
49
|
+
| TODO | `Source-Ref: <file>:<line>` |
|
|
50
|
+
| CVE | `CVE: <cve-id>` or `Advisory: <ghsa-id>` |
|
|
51
|
+
|
|
52
|
+
If a matching issue exists (open or closed), skip β never duplicate.
|
|
53
|
+
|
|
54
|
+
### Step 2 β Create the issue
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
gh issue create --label mdless/work --title "..." --body "..."
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Title: concise and action-oriented.
|
|
61
|
+
Good: `Fix null deref in PaymentProcessor.charge`
|
|
62
|
+
Good: `Upgrade lodash to patch CVE-2024-XXXXX`
|
|
63
|
+
|
|
64
|
+
Body: start with metadata, then a separator, then details.
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
Source: todo | cve
|
|
68
|
+
<Source-ID line>
|
|
69
|
+
---
|
|
70
|
+
<problem description, affected files/area, repro details>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Step 3 β Log one line
|
|
74
|
+
|
|
75
|
+
- `created #123 todo src/foo.ts:42`
|
|
76
|
+
- `skip todo src/bar.ts:10 (already #98)`
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Rules
|
|
81
|
+
|
|
82
|
+
- Every issue must have the `mdless/work` label.
|
|
83
|
+
- Be conservative: skipping a borderline case > spamming the tracker.
|
|
84
|
+
- If you find nothing new, print `no new issues` and exit. The wrapper sleeps and re-invokes you.
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Developer 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 developer agent. 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,262 @@
|
|
|
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
|
+
}
|
|
@@ -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,233 @@
|
|
|
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
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
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 {
|
|
6
|
-
import {
|
|
5
|
+
import { agentCommand } from "./commands/agent.js";
|
|
6
|
+
import { initCommand } from "./commands/init.js";
|
|
7
|
+
import { startCommand } from "./commands/start.js";
|
|
7
8
|
import { withExitHandler } from "./utils.js";
|
|
8
9
|
|
|
9
10
|
const banner = `
|
|
@@ -17,14 +18,14 @@ const banner = `
|
|
|
17
18
|
|
|
18
19
|
const commands = [
|
|
19
20
|
{
|
|
20
|
-
name: "
|
|
21
|
-
description: "
|
|
22
|
-
action:
|
|
21
|
+
name: "init",
|
|
22
|
+
description: "Copy the default agent prompts into .mdless/agents/",
|
|
23
|
+
action: initCommand,
|
|
23
24
|
},
|
|
24
25
|
{
|
|
25
|
-
name: "
|
|
26
|
-
description: "
|
|
27
|
-
action:
|
|
26
|
+
name: "work",
|
|
27
|
+
description: "Launch the agents in .mdless/agents/ in a tmux session",
|
|
28
|
+
action: startCommand,
|
|
28
29
|
},
|
|
29
30
|
] as const;
|
|
30
31
|
|
|
@@ -67,6 +68,11 @@ for (const cmd of commands) {
|
|
|
67
68
|
program.command(cmd.name).description(cmd.description).action(cmd.action);
|
|
68
69
|
}
|
|
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
|
+
|
|
70
76
|
// If no arguments provided, show interactive mode
|
|
71
77
|
if (process.argv.length <= 2) {
|
|
72
78
|
interactiveMode();
|
package/src/utils.ts
CHANGED
|
@@ -1,39 +1,11 @@
|
|
|
1
|
-
import { readdirSync, statSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
|
|
5
1
|
export function exit(): never {
|
|
6
2
|
console.log("\nAborted.");
|
|
7
3
|
process.exit(0);
|
|
8
4
|
}
|
|
9
5
|
|
|
10
|
-
export function getDirectories(path: string): string[] {
|
|
11
|
-
return readdirSync(path).filter((name) =>
|
|
12
|
-
statSync(join(path, name)).isDirectory()
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
6
|
export function withExitHandler<T>(promise: Promise<T>): Promise<T> {
|
|
17
7
|
return promise.catch((e: Error) => {
|
|
18
8
|
if (e.name === "ExitPromptError") exit();
|
|
19
9
|
throw e;
|
|
20
10
|
});
|
|
21
11
|
}
|
|
22
|
-
|
|
23
|
-
export function truncatePath(path: string, maxLength = 50): string {
|
|
24
|
-
const home = homedir();
|
|
25
|
-
let display = path.startsWith(home) ? path.replace(home, "~") : path;
|
|
26
|
-
if (display.length > maxLength) {
|
|
27
|
-
display = "..." + display.slice(-maxLength + 3);
|
|
28
|
-
}
|
|
29
|
-
return display;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function clearLine(): void {
|
|
33
|
-
process.stdout.write("\r\x1b[K");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function formatDuration(ms: number): string {
|
|
37
|
-
if (ms < 1000) return `${ms}ms`;
|
|
38
|
-
return `${(ms / 1000).toFixed(1)}s`;
|
|
39
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: ci-errors
|
|
3
|
-
description: Fetch failing CI logs for the current PR, analyze errors, and fix them
|
|
4
|
-
allowed-tools: Bash(gh:*), Bash(git:*), Read, Grep, Glob, Edit
|
|
5
|
-
argument-hint: [optional: specific check name to focus on]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# CI Errors
|
|
9
|
-
|
|
10
|
-
Fetch failing CI logs for the current PR, analyze the errors, and fix them.
|
|
11
|
-
|
|
12
|
-
## Instructions
|
|
13
|
-
|
|
14
|
-
1. Run `gh pr view --json number,title,headRefName` to confirm there is an open PR. If not, stop.
|
|
15
|
-
|
|
16
|
-
2. Get failing checks:
|
|
17
|
-
```bash
|
|
18
|
-
gh pr checks --json name,bucket,link,state --jq '[.[] | select(.bucket == "fail")]'
|
|
19
|
-
```
|
|
20
|
-
If no checks are failing, tell the user and stop. Filter by $ARGUMENTS if provided.
|
|
21
|
-
|
|
22
|
-
3. Extract `run_id` and `job_id` from each failing check link (format: `.../actions/runs/<run_id>/job/<job_id>`).
|
|
23
|
-
Fetch logs with `gh run view <run_id> --log-failed`. Fall back to annotations if unavailable.
|
|
24
|
-
|
|
25
|
-
4. Categorize each failure (test, lint/type, build, or other) and identify the root cause.
|
|
26
|
-
|
|
27
|
-
5. Fix each error: read the source, apply the fix, explain what changed.
|
|
28
|
-
|
|
29
|
-
6. Summarize what was fixed and suggest the user re-run CI.
|
package/skills/commit/SKILL.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: commit
|
|
3
|
-
description: Stage and commit changes with a conventional commit message
|
|
4
|
-
allowed-tools: Bash(git:*)
|
|
5
|
-
argument-hint: [optional: what to commit]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Commit
|
|
9
|
-
|
|
10
|
-
Stage and commit changes using conventional commit messages.
|
|
11
|
-
|
|
12
|
-
## Instructions
|
|
13
|
-
|
|
14
|
-
1. Check `git status --short` to see what changes exist
|
|
15
|
-
2. Stage relevant files for commit
|
|
16
|
-
3. Verify nothing is staged that shouldn't be
|
|
17
|
-
4. Create a commit using conventional format: `<type>: <description>`
|
|
18
|
-
|
|
19
|
-
Only push the commit if specifically instructed to do so.
|
|
20
|
-
|
|
21
|
-
## Conventional Commit Types
|
|
22
|
-
|
|
23
|
-
`feat` | `fix` | `docs` | `style` | `refactor` | `perf` | `test` | `chore` | `ci`
|
|
24
|
-
|
|
25
|
-
Description: short summary (50 chars or less), lowercase, no period.
|
|
26
|
-
|
|
27
|
-
Use $ARGUMENTS as guidance for what to commit. If not provided, commit all unstaged changes.
|
package/skills/pr/SKILL.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pr
|
|
3
|
-
description: Commit changes, push, and create/update a pull request
|
|
4
|
-
allowed-tools: Bash(git:*), Bash(gh:*), Read, Edit
|
|
5
|
-
argument-hint: [optional: branch/commit message guidance]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Create PR
|
|
9
|
-
|
|
10
|
-
Commit changes, push, and create/update a pull request.
|
|
11
|
-
|
|
12
|
-
## Instructions
|
|
13
|
-
|
|
14
|
-
1. Check `git status` and current branch
|
|
15
|
-
2. If on main/master, create a feature branch. Otherwise stay on current branch.
|
|
16
|
-
3. Stage and commit changes using conventional commit format
|
|
17
|
-
4. Push to origin (use `-u` if branch is new)
|
|
18
|
-
5. Check if PR exists with `gh pr view`
|
|
19
|
-
6. If no PR, create one with `gh pr create` (include a summary of the changes)
|
|
20
|
-
7. Open in browser with `gh pr view --web`
|
|
21
|
-
|
|
22
|
-
Use $ARGUMENTS as guidance for branch name and commit message.
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pr-comments
|
|
3
|
-
description: Review and respond to PR comments
|
|
4
|
-
allowed-tools: Bash(gh:*), Bash(git:*), Read, Edit
|
|
5
|
-
argument-hint: [optional: e.g. "reply to antoine saying we should add tests"]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# PR Comments
|
|
9
|
-
|
|
10
|
-
Review and respond to comments on a pull request.
|
|
11
|
-
|
|
12
|
-
## Instructions
|
|
13
|
-
|
|
14
|
-
1. Get the PR number: `gh pr view --json number -q .number`
|
|
15
|
-
|
|
16
|
-
2. Fetch review comments using `gh api` for the current PR
|
|
17
|
-
|
|
18
|
-
3. For each comment, show: file, line, author, body. Then suggest either:
|
|
19
|
-
- A code fix (if requesting a change)
|
|
20
|
-
- A reply (if it's a question/discussion)
|
|
21
|
-
|
|
22
|
-
4. Ask the user what to do: apply fix, reply, skip, or custom action
|
|
23
|
-
|
|
24
|
-
5. Execute: for fixes, edit/commit/push. For replies, post via `gh api`.
|
|
25
|
-
|
|
26
|
-
Use $ARGUMENTS to guide actions (e.g., "fix all issues" or "reply to antoine").
|
package/src/commands/scan.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { readdirSync, statSync, existsSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { join, basename } from "node:path";
|
|
4
|
-
import { loadConfig, saveConfig } from "../config.js";
|
|
5
|
-
import { clearLine, formatDuration, truncatePath } from "../utils.js";
|
|
6
|
-
|
|
7
|
-
const EXCLUSIONS = new Set([
|
|
8
|
-
"node_modules",
|
|
9
|
-
"dist",
|
|
10
|
-
"build",
|
|
11
|
-
"Library",
|
|
12
|
-
"Applications",
|
|
13
|
-
"__pycache__",
|
|
14
|
-
"venv",
|
|
15
|
-
"worktrees",
|
|
16
|
-
"workspaces",
|
|
17
|
-
"tmp",
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
function* walkDirectories(dir: string): Generator<string> {
|
|
21
|
-
let entries: string[];
|
|
22
|
-
try {
|
|
23
|
-
entries = readdirSync(dir);
|
|
24
|
-
} catch {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
for (const entry of entries) {
|
|
29
|
-
if (entry.startsWith(".") || EXCLUSIONS.has(entry)) continue;
|
|
30
|
-
|
|
31
|
-
const fullPath = join(dir, entry);
|
|
32
|
-
let stat;
|
|
33
|
-
try {
|
|
34
|
-
stat = statSync(fullPath);
|
|
35
|
-
} catch {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (stat.isDirectory()) {
|
|
40
|
-
yield fullPath;
|
|
41
|
-
yield* walkDirectories(fullPath);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function isClaudeWorkspace(dir: string): boolean {
|
|
47
|
-
return existsSync(join(dir, ".claude")) && existsSync(join(dir, ".git"));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function scanCommand(): Promise<void> {
|
|
51
|
-
const startTime = Date.now();
|
|
52
|
-
const home = homedir();
|
|
53
|
-
|
|
54
|
-
console.log(`Scanning from ${home}...`);
|
|
55
|
-
|
|
56
|
-
const found: string[] = [];
|
|
57
|
-
let scanned = 0;
|
|
58
|
-
|
|
59
|
-
for (const dir of walkDirectories(home)) {
|
|
60
|
-
scanned++;
|
|
61
|
-
if (isClaudeWorkspace(dir)) {
|
|
62
|
-
found.push(dir);
|
|
63
|
-
}
|
|
64
|
-
if (scanned % 100 === 0) {
|
|
65
|
-
clearLine();
|
|
66
|
-
process.stdout.write(
|
|
67
|
-
` ${scanned.toLocaleString()} checked, ${found.length} found | ${truncatePath(dir)}`,
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
clearLine();
|
|
73
|
-
|
|
74
|
-
const config = loadConfig();
|
|
75
|
-
config.workingDirectories = found.map((path) => ({
|
|
76
|
-
path,
|
|
77
|
-
name: basename(path),
|
|
78
|
-
sync: true,
|
|
79
|
-
}));
|
|
80
|
-
saveConfig(config);
|
|
81
|
-
|
|
82
|
-
const duration = formatDuration(Date.now() - startTime);
|
|
83
|
-
console.log(`\nβ Found ${found.length} workspaces in ${duration}`);
|
|
84
|
-
|
|
85
|
-
for (const dir of found) {
|
|
86
|
-
console.log(` β’ ${basename(dir)}`);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
console.log(`\nSaved to ~/.mdless/config.json`);
|
|
90
|
-
}
|
package/src/commands/skills.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { checkbox, confirm } from "@inquirer/prompts";
|
|
2
|
-
import { cpSync, existsSync, mkdirSync, rmSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { exit, getDirectories, withExitHandler } from "../utils.js";
|
|
5
|
-
|
|
6
|
-
export async function skillsCommand(): Promise<void> {
|
|
7
|
-
const cwd = process.cwd();
|
|
8
|
-
const claudeDir = join(cwd, ".claude");
|
|
9
|
-
|
|
10
|
-
if (!existsSync(claudeDir)) {
|
|
11
|
-
const shouldCreate = await withExitHandler(
|
|
12
|
-
confirm({ message: "No .claude folder found. Create one?" })
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
if (!shouldCreate) {
|
|
16
|
-
exit();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
mkdirSync(claudeDir);
|
|
20
|
-
console.log("β Created .claude folder.");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const skillsDir = join(import.meta.dirname!, "..", "..", "skills");
|
|
24
|
-
const skills = getDirectories(skillsDir);
|
|
25
|
-
const destSkillsDir = join(claudeDir, "skills");
|
|
26
|
-
|
|
27
|
-
function isInstalled(skill: string): boolean {
|
|
28
|
-
return existsSync(join(destSkillsDir, skill));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const selected = await withExitHandler(
|
|
32
|
-
checkbox({
|
|
33
|
-
message: "Select skills to install:",
|
|
34
|
-
choices: skills.map((skill) => ({
|
|
35
|
-
name: skill,
|
|
36
|
-
value: skill,
|
|
37
|
-
checked: isInstalled(skill),
|
|
38
|
-
})),
|
|
39
|
-
})
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const installed: string[] = [];
|
|
43
|
-
const removed: string[] = [];
|
|
44
|
-
|
|
45
|
-
for (const skill of skills) {
|
|
46
|
-
const src = join(skillsDir, skill);
|
|
47
|
-
const dest = join(destSkillsDir, skill);
|
|
48
|
-
const wasInstalled = isInstalled(skill);
|
|
49
|
-
const shouldBeInstalled = selected.includes(skill);
|
|
50
|
-
|
|
51
|
-
if (shouldBeInstalled && !wasInstalled) {
|
|
52
|
-
cpSync(src, dest, { recursive: true });
|
|
53
|
-
installed.push(skill);
|
|
54
|
-
} else if (!shouldBeInstalled && wasInstalled) {
|
|
55
|
-
rmSync(dest, { recursive: true });
|
|
56
|
-
removed.push(skill);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (installed.length > 0 || removed.length > 0) {
|
|
61
|
-
console.log("β Changes applied.");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const finalSkills = existsSync(destSkillsDir)
|
|
65
|
-
? getDirectories(destSkillsDir)
|
|
66
|
-
: [];
|
|
67
|
-
|
|
68
|
-
if (finalSkills.length > 0) {
|
|
69
|
-
console.log(`\nProject skills: ${finalSkills.join(", ")}`);
|
|
70
|
-
} else {
|
|
71
|
-
console.log("\nNo skills in this project.");
|
|
72
|
-
}
|
|
73
|
-
}
|
package/src/config.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
|
|
5
|
-
export const MDLESS_DIR = join(homedir(), ".mdless");
|
|
6
|
-
export const CONFIG_PATH = join(MDLESS_DIR, "config.json");
|
|
7
|
-
|
|
8
|
-
export interface WorkingDirectory {
|
|
9
|
-
path: string;
|
|
10
|
-
name: string;
|
|
11
|
-
sync: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface MdlessConfig {
|
|
15
|
-
version: 1;
|
|
16
|
-
workingDirectories: WorkingDirectory[];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function ensureConfigDir(): void {
|
|
20
|
-
if (!existsSync(MDLESS_DIR)) {
|
|
21
|
-
mkdirSync(MDLESS_DIR, { recursive: true });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function loadConfig(): MdlessConfig {
|
|
26
|
-
ensureConfigDir();
|
|
27
|
-
|
|
28
|
-
if (!existsSync(CONFIG_PATH)) {
|
|
29
|
-
return {
|
|
30
|
-
version: 1,
|
|
31
|
-
workingDirectories: [],
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const content = readFileSync(CONFIG_PATH, "utf-8");
|
|
36
|
-
return JSON.parse(content) as MdlessConfig;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function saveConfig(config: MdlessConfig): void {
|
|
40
|
-
ensureConfigDir();
|
|
41
|
-
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + "\n");
|
|
42
|
-
}
|