claude-second-brain 1.0.0 → 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 +79 -35
- package/bin/agents.js +320 -0
- package/bin/create.js +1030 -125
- package/package.json +2 -2
- package/template/AGENTS.md +9 -0
- package/template/README.md +31 -18
package/README.md
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
**Your notes don't compound. This wiki does.**
|
|
5
5
|
|
|
6
|
-
[](https://www.npmjs.com/package/claude-second-brain) [](https://opensource.org/licenses/MIT) [](https://www.npmjs.com/package/claude-second-brain) [](https://opensource.org/licenses/MIT) [](https://deepwiki.com/jessepinkman9900/claude-second-brain)
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
The fastest way to start your personal knowledge base powered by Obsidian, Claude Code, qmd, and
|
|
9
|
+
The fastest way to start your personal knowledge base powered by [Obsidian](https://obsidian.md), your AI coding agent ([Claude Code](https://claude.ai/code), Codex, Cursor, GitHub Copilot, Gemini CLI, and more), [qmd](https://github.com/tobi/qmd), and git.
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
```
|
|
@@ -14,12 +14,12 @@ npx claude-second-brain
|
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
One command gives you a fully wired knowledge system:
|
|
17
|
-
- [Claude](https://claude.ai/) ingests your sources and maintains a cross-linked wiki
|
|
17
|
+
- Your AI agent ([Claude Code](https://claude.ai/code), Codex, Cursor, …) ingests your sources and maintains a cross-linked wiki
|
|
18
18
|
- [qmd](https://github.com/tobi/qmd) powers local semantic search
|
|
19
19
|
- The scaffolded folder **is your Obsidian vault** — open it directly in [Obsidian](https://obsidian.md), with [obsidian-git](https://github.com/Vinzent03/obsidian-git) pre-configured for seamless sync
|
|
20
|
-
- GitHub is the source of truth — version history, anywhere access, and a backup you control
|
|
20
|
+
- A git ([GitHub](https://github.com), [Cloudflare Artifacts](https://developers.cloudflare.com/artifacts/), or any remote) is the source of truth — version history, anywhere access, and a backup you control
|
|
21
21
|
|
|
22
|
-
You've been reading papers, articles, and books for years. Drop a source in, run `/brain-ingest`, and
|
|
22
|
+
You've been reading papers, articles, and books for years. Drop a source in, run `/brain-ingest`, and your agent reads it — extracts what matters, cross-links it to everything you already know, and files it. Ask a question six months later and get cited answers, not a list of files to re-read.
|
|
23
23
|
|
|
24
24
|
> **Inspired by [Andrej Karpathy's approach to LLM-powered knowledge management](https://x.com/karpathy/status/2040470801506541998?s=20)** — share an "idea file" with an LLM agent and let it build and maintain your knowledge base.
|
|
25
25
|
|
|
@@ -30,10 +30,10 @@ You've been reading papers, articles, and books for years. Drop a source in, run
|
|
|
30
30
|
|
|
31
31
|
## How this is different
|
|
32
32
|
|
|
33
|
-
This is not a RAG system. It's not a chatbot over your notes. It's an actively maintained, cross-linked wiki — five structured page types, YAML frontmatter, and a set of
|
|
33
|
+
This is not a RAG system. It's not a chatbot over your notes. It's an actively maintained, cross-linked wiki — five structured page types, YAML frontmatter, and a set of agent skills that run the whole thing — in Claude Code, Codex, Cursor, Copilot, or any agent that supports [Agent Skills](https://agentskills.io).
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
The schema (`CLAUDE.md`) is that idea file.
|
|
36
|
+
The schema (`CLAUDE.md`) is that idea file. Your agent reads it every session (other agents reach it through `AGENTS.md`).
|
|
37
37
|
|
|
38
38
|
---
|
|
39
39
|
|
|
@@ -41,10 +41,10 @@ The schema (`CLAUDE.md`) is that idea file. Claude reads it every session.
|
|
|
41
41
|
|
|
42
42
|
| Tool | Role |
|
|
43
43
|
|---|---|
|
|
44
|
-
| **Claude Code
|
|
44
|
+
| **Your agent** (Claude Code, Codex, Cursor, Copilot, …) | Reads sources, writes wiki pages, cross-links, flags contradictions |
|
|
45
45
|
| **qmd** | Local hybrid search (vector + BM25) across your entire wiki |
|
|
46
46
|
| **Obsidian** | Graph view, backlinks, mobile reading — offline, no extra sync |
|
|
47
|
-
| **
|
|
47
|
+
| **Git** (GitHub, Cloudflare Artifacts, …) | Source of truth — version history, your agent anywhere, Obsidian sync |
|
|
48
48
|
|
|
49
49
|
Everything is pre-configured. You bring the sources.
|
|
50
50
|
|
|
@@ -67,9 +67,11 @@ csb
|
|
|
67
67
|
|
|
68
68
|
The CLI will ask:
|
|
69
69
|
- **Brain name** — what to call this brain (default: `my-brain`)
|
|
70
|
-
- **
|
|
70
|
+
- **Git remote** — GitHub (private repo via `gh`), Cloudflare Artifacts (via wrangler), or skip
|
|
71
|
+
- **Register qmd collections after install?**
|
|
72
|
+
- **Install skills for which agents?** — Claude Code plus any detected agent is preselected
|
|
71
73
|
|
|
72
|
-
Creates the brain at `~/.claude-second-brain/my-brain/`, registers it in `~/.claude-second-brain/config.toml`,
|
|
74
|
+
Creates the brain at `~/.claude-second-brain/my-brain/`, registers it in `~/.claude-second-brain/config.toml`, runs `pnpm install` (using your system pnpm 10+, or mise to fetch node + pnpm if it's missing), registers the qmd collections, installs the skills for the agents you picked, and runs `git init`.
|
|
73
75
|
|
|
74
76
|
**Step 2 — Generate vector embeddings**
|
|
75
77
|
|
|
@@ -95,15 +97,15 @@ Open `~/.claude-second-brain/my-brain/` as a vault in Obsidian — the folder is
|
|
|
95
97
|
|
|
96
98
|
---
|
|
97
99
|
|
|
98
|
-
##
|
|
100
|
+
## Agent skills included
|
|
99
101
|
|
|
100
102
|
The wiki ships with a set of slash commands that cover the full workflow. No manual prompting, no copy-pasting.
|
|
101
103
|
|
|
102
104
|
### Daily workflow
|
|
103
105
|
|
|
104
|
-
**`/brain-ingest`** — Drop a file into `raw-sources/articles/`, `raw-sources/pdfs/`, or `raw-sources/personal/`. Run `/brain-ingest`.
|
|
106
|
+
**`/brain-ingest`** — Drop a file into `raw-sources/articles/`, `raw-sources/pdfs/`, or `raw-sources/personal/`. Run `/brain-ingest`. Your agent summarizes the source, asks what matters most to you, creates a `wiki/sources/` page, updates or creates related topic pages, flags any contradictions with existing knowledge, and logs everything.
|
|
105
107
|
|
|
106
|
-
**`/brain-search`** — Ask anything about what you know.
|
|
108
|
+
**`/brain-search`** — Ask anything about what you know. Your agent runs hybrid semantic search across the wiki, reads the most relevant pages, and writes an answer with inline `[[wiki/page]]` citations. If the answer synthesizes multiple pages in a novel way, it offers to file it as a permanent `wiki/qa/` entry.
|
|
107
109
|
|
|
108
110
|
**`/lint`** — Health-check the wiki. Surfaces orphan pages, broken links, unresolved contradictions, and data gaps. Reports findings and applies fixes where possible.
|
|
109
111
|
|
|
@@ -115,22 +117,38 @@ The wiki ships with a set of slash commands that cover the full workflow. No man
|
|
|
115
117
|
|
|
116
118
|
---
|
|
117
119
|
|
|
120
|
+
## Works with any agent
|
|
121
|
+
|
|
122
|
+
The wiki skills follow the open [Agent Skills](https://agentskills.io/specification) format, so the same `/brain-ingest`, `/brain-search`, `/brain-refresh`, `/brain-rebuild` and `/lint` work in every agent that supports skills. The CLI installs them for the agents you pick:
|
|
123
|
+
|
|
124
|
+
| Agent | Global skills dir | Vault skills dir |
|
|
125
|
+
|---|---|---|
|
|
126
|
+
| Claude Code | `~/.claude/skills` (symlink) | `.claude/skills` |
|
|
127
|
+
| Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Amp, Cline | `~/.agents/skills` | `.agents/skills` |
|
|
128
|
+
| Windsurf | `~/.codeium/windsurf/skills` (symlink) | `.windsurf/skills` |
|
|
129
|
+
| Goose | `~/.config/goose/skills` (symlink) | `.goose/skills` |
|
|
130
|
+
| Kiro CLI, Roo Code, Continue, Junie, Augment | `~/.<agent>/skills` (symlink) | `.<agent>/skills` |
|
|
131
|
+
|
|
132
|
+
The vault's operating instructions live in `CLAUDE.md`, with an `AGENTS.md` that points agents which read that file (Codex, Cursor, Copilot, …) to it. Using an agent that isn't listed? Copy the skill folders from `~/.agents/skills` into its skills directory.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
118
136
|
## Access from anywhere
|
|
119
137
|
|
|
120
|
-
**Edit anywhere —
|
|
121
|
-
|
|
138
|
+
**Edit anywhere — your agent on desktop, web or mobile**
|
|
139
|
+
The vault is a plain git repo, so any agent that can clone it can work on it: run it locally, or use a cloud agent with GitHub access (Claude Code on the web and mobile, Codex cloud, Copilot coding agent, Cursor background agents, …) to ingest a source, run a query, or update a page from your phone.
|
|
122
140
|
|
|
123
141
|
**Read anywhere — Obsidian desktop and mobile**
|
|
124
142
|
Open the repo as an Obsidian vault. The bundled `.obsidian` folder pre-configures the [obsidian-git](https://github.com/Vinzent03/obsidian-git) community plugin — no setup required, just enable it. Your wiki syncs automatically on every commit. For iOS: put the repo folder inside iCloud Drive — Obsidian Mobile picks it up natively with no extra setup. Graph view, backlinks, offline reading — all working.
|
|
125
143
|
|
|
126
|
-
**Browse anywhere —
|
|
127
|
-
It's a plain
|
|
144
|
+
**Browse anywhere — your git host**
|
|
145
|
+
It's a plain git repo. On GitHub (or any host with a web UI), view and edit files directly in the browser at any time.
|
|
128
146
|
|
|
129
147
|
---
|
|
130
148
|
|
|
131
149
|
## How it works
|
|
132
150
|
|
|
133
|
-
Sources flow in on the left,
|
|
151
|
+
Sources flow in on the left, your agent synthesizes them into the wiki, qmd indexes every page into a local hybrid search index, and git makes the whole vault editable from Obsidian and your agent on any device.
|
|
134
152
|
|
|
135
153
|
```mermaid
|
|
136
154
|
flowchart TB
|
|
@@ -141,7 +159,7 @@ flowchart TB
|
|
|
141
159
|
S3[personal/]
|
|
142
160
|
end
|
|
143
161
|
|
|
144
|
-
subgraph Skills["
|
|
162
|
+
subgraph Skills["Agent skills"]
|
|
145
163
|
direction LR
|
|
146
164
|
I["/brain-ingest"]
|
|
147
165
|
Q["/brain-search"]
|
|
@@ -158,14 +176,14 @@ flowchart TB
|
|
|
158
176
|
|
|
159
177
|
QMD[("qmd.sqlite<br/>vector + BM25<br/>hybrid index")]
|
|
160
178
|
|
|
161
|
-
subgraph Remote["
|
|
179
|
+
subgraph Remote["Git remote — source of truth"]
|
|
162
180
|
GH[private repo]
|
|
163
181
|
end
|
|
164
182
|
|
|
165
183
|
subgraph Read["Read / edit anywhere"]
|
|
166
184
|
direction LR
|
|
167
185
|
OB["Obsidian<br/>graph · backlinks · mobile"]
|
|
168
|
-
CC["
|
|
186
|
+
CC["Your agent<br/>desktop, web + mobile"]
|
|
169
187
|
end
|
|
170
188
|
|
|
171
189
|
User((you))
|
|
@@ -226,12 +244,12 @@ All brains live under `~/.claude-second-brain/`. A central `config.toml` tracks
|
|
|
226
244
|
~/.claude-second-brain/
|
|
227
245
|
├── config.toml ← Brain registry (default brain, paths, git remotes)
|
|
228
246
|
└── my-brain/
|
|
229
|
-
├── CLAUDE.md ← The schema.
|
|
230
|
-
├── raw-sources/ ← Your raw inputs.
|
|
247
|
+
├── CLAUDE.md ← The schema. Your agent reads this every session.
|
|
248
|
+
├── raw-sources/ ← Your raw inputs. The agent never modifies these.
|
|
231
249
|
│ ├── articles/
|
|
232
250
|
│ ├── pdfs/
|
|
233
251
|
│ └── personal/
|
|
234
|
-
├── wiki/ ←
|
|
252
|
+
├── wiki/ ← The agent owns this entirely.
|
|
235
253
|
│ ├── index.md
|
|
236
254
|
│ ├── log.md
|
|
237
255
|
│ ├── overview.md
|
|
@@ -245,21 +263,44 @@ All brains live under `~/.claude-second-brain/`. A central `config.toml` tracks
|
|
|
245
263
|
|
|
246
264
|
Run `npx claude-second-brain` again to create additional brains. Each gets its own folder, its own qmd index, and its own git remote — fully isolated. The global skills (`/brain-ingest`, `/brain-search`, `/brain-refresh`) always operate on the **default brain** declared in `config.toml`. The first brain you create is set as the default automatically.
|
|
247
265
|
|
|
248
|
-
Manage brains from the CLI:
|
|
266
|
+
Manage brains from the CLI (`csb` is the short alias — swap for `npx claude-second-brain` if not installed globally):
|
|
249
267
|
|
|
250
268
|
```bash
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
269
|
+
csb ls # list all brains (default marked with *)
|
|
270
|
+
csb use <name> # switch the default brain
|
|
271
|
+
csb rm <name> # remove a brain (deletes its folder + config entry)
|
|
272
|
+
csb path # print the default brain's directory
|
|
273
|
+
csb path qmd # print the default brain's qmd index path
|
|
274
|
+
csb path config # print ~/.claude-second-brain/config.toml
|
|
275
|
+
csb qmd query -c wiki "<terms>" # run qmd against the default brain
|
|
276
|
+
csb exec -- pnpm qmd:reindex # run any command inside the default brain
|
|
277
|
+
csb skills --agent codex,cursor # install/update skills for more agents
|
|
278
|
+
csb git-token # renew a Cloudflare Artifacts git token (90 days)
|
|
279
|
+
csb doctor # verify tools, config, skills, and each brain
|
|
256
280
|
```
|
|
257
281
|
|
|
282
|
+
Every subcommand accepts `--help` for details (`csb rm --help`, `csb path --help`, …).
|
|
283
|
+
|
|
258
284
|
---
|
|
259
285
|
|
|
260
286
|
## Installing and updating skills
|
|
261
287
|
|
|
262
|
-
Skills
|
|
288
|
+
The skills follow the [Agent Skills](https://agentskills.io/specification) format, so they work in Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf, Goose and more. `/brain-ingest`, `/brain-search`, and `/brain-refresh` install globally during setup; `/brain-rebuild` and `/lint` live inside the vault.
|
|
289
|
+
|
|
290
|
+
Setup asks which agents to install for (Claude Code plus any agent it detects is preselected). It uses the same layout as [`npx skills`](https://github.com/vercel-labs/skills):
|
|
291
|
+
|
|
292
|
+
- Global skills are written once to `~/.agents/skills/<name>`. Codex, Cursor, Copilot, Gemini CLI, OpenCode, Amp and Cline read that folder directly.
|
|
293
|
+
- Agents with their own folder get a symlink to it, e.g. `~/.claude/skills/brain-search → ~/.agents/skills/brain-search` (or `~/.codeium/windsurf/skills`, `~/.config/goose/skills`, …). If symlinks aren't available, or you pass `--copy`, the skill is copied instead.
|
|
294
|
+
- In the vault, `/brain-rebuild` and `/lint` live in `.claude/skills/` and are copied into each other selected agent's project folder (`.agents/skills/`, `.windsurf/skills/`, …).
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
# Pick agents up front (comma-separated, or `all`); CSB_AGENTS works too
|
|
298
|
+
npx claude-second-brain my-brain --agent claude-code,codex,github-copilot
|
|
299
|
+
|
|
300
|
+
# Add agents later, or update skills after upgrading
|
|
301
|
+
npx claude-second-brain skills --agent cursor,windsurf
|
|
302
|
+
npx claude-second-brain skills --list # supported agents and their skills dirs
|
|
303
|
+
```
|
|
263
304
|
|
|
264
305
|
### Update the built-in wiki skills
|
|
265
306
|
|
|
@@ -269,6 +310,9 @@ The wiki's own skills are scaffolded at creation time. To pull in improvements,
|
|
|
269
310
|
# Install or update all 5 wiki skills from the latest template
|
|
270
311
|
npx skills add https://github.com/jessepinkman9900/claude-second-brain/tree/main/template/.claude/skills -a claude-code -y
|
|
271
312
|
|
|
313
|
+
# Same, for other agents (npx skills asks which agents if you omit -a)
|
|
314
|
+
npx skills add https://github.com/jessepinkman9900/claude-second-brain/tree/main/template/.claude/skills -a codex -a cursor -y
|
|
315
|
+
|
|
272
316
|
# Or update a specific skill
|
|
273
317
|
npx skills add https://github.com/jessepinkman9900/claude-second-brain/tree/main/template/.claude/skills --skill brain-ingest -a claude-code -y
|
|
274
318
|
```
|
|
@@ -285,14 +329,14 @@ npx skills update -a claude-code
|
|
|
285
329
|
|
|
286
330
|
- [ ] GitHub Actions to invoke `/brain-refresh` on a schedule
|
|
287
331
|
- [ ] GitHub agentic workflows — auto-ingest on push, scheduled lint, auto-summary on new sources
|
|
288
|
-
- [ ] More
|
|
332
|
+
- [ ] More wiki skills (source discovery, topic clustering)
|
|
289
333
|
|
|
290
334
|
---
|
|
291
335
|
|
|
292
336
|
## Requirements
|
|
293
337
|
|
|
294
|
-
- [mise](https://mise.jdx.dev/) —
|
|
295
|
-
- [Claude Code](https://claude.ai/code)
|
|
338
|
+
- [pnpm](https://pnpm.io) 10+ on Node 22+, or [mise](https://mise.jdx.dev/) — if pnpm isn't installed, the CLI installs mise and uses it to fetch node + pnpm
|
|
339
|
+
- An AI coding agent that supports [Agent Skills](https://agentskills.io) — [Claude Code](https://claude.ai/code), Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf, Goose, …
|
|
296
340
|
- [Obsidian](https://obsidian.md/) — optional but recommended
|
|
297
341
|
|
|
298
342
|
---
|
package/bin/agents.js
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// Agent registry + installer for Agent Skills (https://agentskills.io).
|
|
2
|
+
//
|
|
3
|
+
// Mirrors the model used by vercel-labs/skills (`npx skills`):
|
|
4
|
+
// - Every agent has a project skills dir and a global skills dir.
|
|
5
|
+
// - `.agents/skills` (project) and `~/.agents/skills` (global) are the shared
|
|
6
|
+
// "canonical" locations. Agents whose project dir is `.agents/skills` are
|
|
7
|
+
// "universal" and read the canonical dir directly — no extra copy needed.
|
|
8
|
+
// - Other agents get a symlink from their own skills dir to the canonical
|
|
9
|
+
// copy, falling back to a plain copy when symlinks aren't available
|
|
10
|
+
// (e.g. Windows without developer mode). `copy` mode always copies.
|
|
11
|
+
//
|
|
12
|
+
// Paths and detection checks follow vercel-labs/skills src/agents.ts.
|
|
13
|
+
|
|
14
|
+
import { existsSync, readFileSync } from "fs"
|
|
15
|
+
import { cp, lstat, mkdir, readlink, realpath, rm, symlink, writeFile } from "fs/promises"
|
|
16
|
+
import { homedir, platform } from "os"
|
|
17
|
+
import { dirname, join, relative, resolve } from "path"
|
|
18
|
+
|
|
19
|
+
const home = homedir()
|
|
20
|
+
const configHome = process.env.XDG_CONFIG_HOME?.trim() || join(home, ".config")
|
|
21
|
+
const claudeHome = process.env.CLAUDE_CONFIG_DIR?.trim() || join(home, ".claude")
|
|
22
|
+
const codexHome = process.env.CODEX_HOME?.trim() || join(home, ".codex")
|
|
23
|
+
|
|
24
|
+
export const CANONICAL_PROJECT_DIR = ".agents/skills"
|
|
25
|
+
export const CANONICAL_GLOBAL_DIR = join(home, ".agents", "skills")
|
|
26
|
+
|
|
27
|
+
export const DEFAULT_AGENT = "claude-code"
|
|
28
|
+
|
|
29
|
+
// `globalSkillsDir: null` = the agent reads ~/.agents/skills globally.
|
|
30
|
+
// `launch` is shown in the post-setup "Next steps": a CLI command, or an app to open the vault in.
|
|
31
|
+
export const AGENTS = {
|
|
32
|
+
"claude-code": {
|
|
33
|
+
displayName: "Claude Code",
|
|
34
|
+
skillsDir: ".claude/skills",
|
|
35
|
+
globalSkillsDir: join(claudeHome, "skills"),
|
|
36
|
+
launch: { cmd: "claude" },
|
|
37
|
+
detect: () => existsSync(claudeHome),
|
|
38
|
+
},
|
|
39
|
+
codex: {
|
|
40
|
+
displayName: "Codex",
|
|
41
|
+
skillsDir: ".agents/skills",
|
|
42
|
+
globalSkillsDir: null,
|
|
43
|
+
launch: { cmd: "codex" },
|
|
44
|
+
detect: () => existsSync(codexHome) || existsSync("/etc/codex"),
|
|
45
|
+
},
|
|
46
|
+
cursor: {
|
|
47
|
+
displayName: "Cursor",
|
|
48
|
+
skillsDir: ".agents/skills",
|
|
49
|
+
globalSkillsDir: null,
|
|
50
|
+
launch: { cmd: "cursor ." },
|
|
51
|
+
detect: () => existsSync(join(home, ".cursor")),
|
|
52
|
+
},
|
|
53
|
+
"gemini-cli": {
|
|
54
|
+
displayName: "Gemini CLI",
|
|
55
|
+
skillsDir: ".agents/skills",
|
|
56
|
+
globalSkillsDir: null,
|
|
57
|
+
launch: { cmd: "gemini" },
|
|
58
|
+
detect: () => existsSync(join(home, ".gemini")),
|
|
59
|
+
},
|
|
60
|
+
"github-copilot": {
|
|
61
|
+
displayName: "GitHub Copilot",
|
|
62
|
+
skillsDir: ".agents/skills",
|
|
63
|
+
globalSkillsDir: null,
|
|
64
|
+
launch: { cmd: "copilot" },
|
|
65
|
+
detect: () => existsSync(join(home, ".copilot")),
|
|
66
|
+
},
|
|
67
|
+
opencode: {
|
|
68
|
+
displayName: "OpenCode",
|
|
69
|
+
skillsDir: ".agents/skills",
|
|
70
|
+
globalSkillsDir: null,
|
|
71
|
+
launch: { cmd: "opencode" },
|
|
72
|
+
detect: () => existsSync(join(configHome, "opencode")),
|
|
73
|
+
},
|
|
74
|
+
amp: {
|
|
75
|
+
displayName: "Amp",
|
|
76
|
+
skillsDir: ".agents/skills",
|
|
77
|
+
globalSkillsDir: null,
|
|
78
|
+
launch: { cmd: "amp" },
|
|
79
|
+
detect: () => existsSync(join(configHome, "amp")),
|
|
80
|
+
},
|
|
81
|
+
cline: {
|
|
82
|
+
displayName: "Cline",
|
|
83
|
+
skillsDir: ".agents/skills",
|
|
84
|
+
globalSkillsDir: null,
|
|
85
|
+
launch: { app: "VS Code" },
|
|
86
|
+
detect: () => existsSync(join(home, ".cline")),
|
|
87
|
+
},
|
|
88
|
+
windsurf: {
|
|
89
|
+
displayName: "Windsurf",
|
|
90
|
+
skillsDir: ".windsurf/skills",
|
|
91
|
+
globalSkillsDir: join(home, ".codeium/windsurf/skills"),
|
|
92
|
+
launch: { cmd: "windsurf ." },
|
|
93
|
+
detect: () => existsSync(join(home, ".codeium/windsurf")),
|
|
94
|
+
},
|
|
95
|
+
goose: {
|
|
96
|
+
displayName: "Goose",
|
|
97
|
+
skillsDir: ".goose/skills",
|
|
98
|
+
globalSkillsDir: join(configHome, "goose/skills"),
|
|
99
|
+
launch: { cmd: "goose session" },
|
|
100
|
+
detect: () => existsSync(join(configHome, "goose")),
|
|
101
|
+
},
|
|
102
|
+
"kiro-cli": {
|
|
103
|
+
displayName: "Kiro CLI",
|
|
104
|
+
skillsDir: ".kiro/skills",
|
|
105
|
+
globalSkillsDir: join(home, ".kiro/skills"),
|
|
106
|
+
launch: { cmd: "kiro-cli" },
|
|
107
|
+
detect: () => existsSync(join(home, ".kiro")),
|
|
108
|
+
},
|
|
109
|
+
roo: {
|
|
110
|
+
displayName: "Roo Code",
|
|
111
|
+
skillsDir: ".roo/skills",
|
|
112
|
+
globalSkillsDir: join(home, ".roo/skills"),
|
|
113
|
+
launch: { app: "VS Code" },
|
|
114
|
+
detect: () => existsSync(join(home, ".roo")),
|
|
115
|
+
},
|
|
116
|
+
continue: {
|
|
117
|
+
displayName: "Continue",
|
|
118
|
+
skillsDir: ".continue/skills",
|
|
119
|
+
globalSkillsDir: join(home, ".continue/skills"),
|
|
120
|
+
launch: { app: "VS Code" },
|
|
121
|
+
detect: () => existsSync(join(home, ".continue")),
|
|
122
|
+
},
|
|
123
|
+
junie: {
|
|
124
|
+
displayName: "Junie",
|
|
125
|
+
skillsDir: ".junie/skills",
|
|
126
|
+
globalSkillsDir: join(home, ".junie/skills"),
|
|
127
|
+
launch: { app: "a JetBrains IDE" },
|
|
128
|
+
detect: () => existsSync(join(home, ".junie")),
|
|
129
|
+
},
|
|
130
|
+
augment: {
|
|
131
|
+
displayName: "Augment",
|
|
132
|
+
skillsDir: ".augment/skills",
|
|
133
|
+
globalSkillsDir: join(home, ".augment/skills"),
|
|
134
|
+
launch: { cmd: "auggie" },
|
|
135
|
+
detect: () => existsSync(join(home, ".augment")),
|
|
136
|
+
},
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export const AGENT_IDS = Object.keys(AGENTS)
|
|
140
|
+
|
|
141
|
+
export function isUniversal(id) {
|
|
142
|
+
return AGENTS[id].skillsDir === CANONICAL_PROJECT_DIR
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function detectAgents() {
|
|
146
|
+
return AGENT_IDS.filter(id => {
|
|
147
|
+
try { return AGENTS[id].detect() } catch { return false }
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Parse "a,b c" / "all" into validated agent ids. Throws on unknown ids.
|
|
152
|
+
export function parseAgentList(value) {
|
|
153
|
+
const ids = String(value || "").split(/[\s,]+/).map(s => s.trim()).filter(Boolean)
|
|
154
|
+
if (ids.includes("all")) return [...AGENT_IDS]
|
|
155
|
+
const unknown = ids.filter(id => !AGENTS[id])
|
|
156
|
+
if (unknown.length) {
|
|
157
|
+
throw new Error(`Unknown agent${unknown.length === 1 ? "" : "s"}: ${unknown.join(", ")}. Known: ${AGENT_IDS.join(", ")}, all.`)
|
|
158
|
+
}
|
|
159
|
+
return [...new Set(ids)]
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Pull `--agent <ids>` / `-a <ids>` (repeatable) and `--copy` out of argv.
|
|
163
|
+
// Returns { agents: string[] | null, copy: boolean, rest: string[] }.
|
|
164
|
+
export function parseAgentFlags(args) {
|
|
165
|
+
let agents = null
|
|
166
|
+
let copy = false
|
|
167
|
+
const rest = []
|
|
168
|
+
for (let i = 0; i < args.length; i++) {
|
|
169
|
+
const a = args[i]
|
|
170
|
+
if (a === "--agent" || a === "-a" || a === "--agents") {
|
|
171
|
+
const v = args[++i]
|
|
172
|
+
if (!v || v.startsWith("-")) throw new Error(`${a} needs a value, e.g. ${a} claude-code,codex`)
|
|
173
|
+
agents = [...(agents || []), ...parseAgentList(v)]
|
|
174
|
+
continue
|
|
175
|
+
}
|
|
176
|
+
if (a.startsWith("--agent=") || a.startsWith("--agents=")) {
|
|
177
|
+
agents = [...(agents || []), ...parseAgentList(a.slice(a.indexOf("=") + 1))]
|
|
178
|
+
continue
|
|
179
|
+
}
|
|
180
|
+
if (a === "--copy") { copy = true; continue }
|
|
181
|
+
rest.push(a)
|
|
182
|
+
}
|
|
183
|
+
return { agents: agents ? [...new Set(agents)] : null, copy, rest }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Resolve which agents to install for.
|
|
187
|
+
// explicit (--agent) > CSB_AGENTS env > interactive multiselect > detected + claude-code
|
|
188
|
+
export async function resolveAgents({ explicit, isInteractive, prompts }) {
|
|
189
|
+
if (explicit && explicit.length) return explicit
|
|
190
|
+
if (process.env.CSB_AGENTS?.trim()) return parseAgentList(process.env.CSB_AGENTS)
|
|
191
|
+
|
|
192
|
+
const detected = detectAgents()
|
|
193
|
+
const defaults = [...new Set([DEFAULT_AGENT, ...detected])]
|
|
194
|
+
if (!isInteractive || !prompts) return defaults
|
|
195
|
+
|
|
196
|
+
const picked = await prompts.multiselect({
|
|
197
|
+
message: "Install skills for which agents?",
|
|
198
|
+
options: AGENT_IDS.map(id => ({
|
|
199
|
+
value: id,
|
|
200
|
+
label: AGENTS[id].displayName,
|
|
201
|
+
hint: [
|
|
202
|
+
detected.includes(id) ? "detected" : null,
|
|
203
|
+
isUniversal(id) ? ".agents/skills" : AGENTS[id].skillsDir,
|
|
204
|
+
].filter(Boolean).join(" · "),
|
|
205
|
+
})),
|
|
206
|
+
initialValues: defaults,
|
|
207
|
+
required: true,
|
|
208
|
+
})
|
|
209
|
+
if (prompts.isCancel(picked)) return null
|
|
210
|
+
return picked
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Where a global skill lives for an agent (null = reads the canonical dir).
|
|
214
|
+
export function globalSkillDirFor(id, name) {
|
|
215
|
+
const dir = AGENTS[id].globalSkillsDir
|
|
216
|
+
return dir ? join(dir, name) : null
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function samePath(a, b) {
|
|
220
|
+
try { return (await realpath(a)) === (await realpath(b)) } catch { return false }
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Point `linkPath` at `target` with a relative symlink (junction on Windows).
|
|
224
|
+
// Returns true on success, false if the caller should fall back to copying.
|
|
225
|
+
async function createSymlink(target, linkPath) {
|
|
226
|
+
try {
|
|
227
|
+
if (resolve(target) === resolve(linkPath)) return true
|
|
228
|
+
if (await samePath(target, linkPath)) return true
|
|
229
|
+
try {
|
|
230
|
+
const st = await lstat(linkPath)
|
|
231
|
+
if (st.isSymbolicLink()) {
|
|
232
|
+
const current = await readlink(linkPath)
|
|
233
|
+
if (resolve(dirname(linkPath), current) === resolve(target)) return true
|
|
234
|
+
}
|
|
235
|
+
await rm(linkPath, { recursive: true, force: true })
|
|
236
|
+
} catch {
|
|
237
|
+
// linkPath doesn't exist — fine.
|
|
238
|
+
}
|
|
239
|
+
await mkdir(dirname(linkPath), { recursive: true })
|
|
240
|
+
// Resolve the parent through symlinks (e.g. ~/.claude/skills -> elsewhere)
|
|
241
|
+
// so the relative target is computed from where the link really lives.
|
|
242
|
+
const realParent = await realpath(dirname(linkPath))
|
|
243
|
+
const isWin = platform() === "win32"
|
|
244
|
+
const linkTarget = isWin ? resolve(target) : relative(realParent, resolve(target))
|
|
245
|
+
await symlink(linkTarget, linkPath, isWin ? "junction" : undefined)
|
|
246
|
+
return true
|
|
247
|
+
} catch {
|
|
248
|
+
return false
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async function copyInto(srcDir, destDir) {
|
|
253
|
+
try {
|
|
254
|
+
const st = await lstat(destDir)
|
|
255
|
+
if (st.isSymbolicLink() || st.isDirectory()) await rm(destDir, { recursive: true, force: true })
|
|
256
|
+
} catch { /* missing */ }
|
|
257
|
+
await mkdir(dirname(destDir), { recursive: true })
|
|
258
|
+
await cp(srcDir, destDir, { recursive: true })
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Write a skill's canonical global copy at ~/.agents/skills/<name>.
|
|
262
|
+
export async function writeCanonicalSkill(name, files) {
|
|
263
|
+
const dir = join(CANONICAL_GLOBAL_DIR, name)
|
|
264
|
+
// If an older install left a symlink here, replace it with a real dir.
|
|
265
|
+
try {
|
|
266
|
+
if ((await lstat(dir)).isSymbolicLink()) await rm(dir, { force: true })
|
|
267
|
+
} catch { /* missing */ }
|
|
268
|
+
await mkdir(dir, { recursive: true })
|
|
269
|
+
for (const [file, content] of Object.entries(files)) {
|
|
270
|
+
await writeFile(join(dir, file), content, "utf8")
|
|
271
|
+
}
|
|
272
|
+
return dir
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Expose the canonical copy of `name` to an agent's global skills dir.
|
|
276
|
+
// Returns { agent, path, mode: "canonical" | "symlink" | "copy" }.
|
|
277
|
+
export async function linkGlobalSkill(id, name, { copy = false } = {}) {
|
|
278
|
+
const canonical = join(CANONICAL_GLOBAL_DIR, name)
|
|
279
|
+
const dest = globalSkillDirFor(id, name)
|
|
280
|
+
if (!dest) return { agent: id, path: canonical, mode: "canonical" }
|
|
281
|
+
if (await samePath(dest, canonical)) {
|
|
282
|
+
// Already linked (or the agent's whole skills dir points at ~/.agents/skills).
|
|
283
|
+
let isLink = false
|
|
284
|
+
try { isLink = (await lstat(dest)).isSymbolicLink() } catch { /* missing */ }
|
|
285
|
+
return isLink
|
|
286
|
+
? { agent: id, path: dest, mode: "symlink" }
|
|
287
|
+
: { agent: id, path: canonical, mode: "canonical" }
|
|
288
|
+
}
|
|
289
|
+
if (!copy && (await createSymlink(canonical, dest))) {
|
|
290
|
+
return { agent: id, path: dest, mode: "symlink" }
|
|
291
|
+
}
|
|
292
|
+
await copyInto(canonical, dest)
|
|
293
|
+
return { agent: id, path: dest, mode: "copy" }
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Copy a set of skill dirs into each agent's project skills dir inside `root`.
|
|
297
|
+
// Project installs always copy — vaults are git repos, and real files sync
|
|
298
|
+
// across machines where symlinks may not. Returns the list of dirs written.
|
|
299
|
+
export async function installProjectSkills(root, srcSkillsDir, skillNames, agents) {
|
|
300
|
+
const srcResolved = resolve(srcSkillsDir)
|
|
301
|
+
const targets = [...new Set(agents.map(id => AGENTS[id].skillsDir))]
|
|
302
|
+
const written = []
|
|
303
|
+
for (const rel of targets) {
|
|
304
|
+
const destRoot = join(root, rel)
|
|
305
|
+
if (resolve(destRoot) === srcResolved) continue
|
|
306
|
+
for (const name of skillNames) {
|
|
307
|
+
await copyInto(join(srcSkillsDir, name), join(destRoot, name))
|
|
308
|
+
}
|
|
309
|
+
written.push(rel)
|
|
310
|
+
}
|
|
311
|
+
return written
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export function readSkillVersionSync(dir) {
|
|
315
|
+
try {
|
|
316
|
+
return JSON.parse(readFileSync(join(dir, ".csb-version"), "utf8")).version || null
|
|
317
|
+
} catch {
|
|
318
|
+
return null
|
|
319
|
+
}
|
|
320
|
+
}
|