musubi-cli 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.ja.md +137 -0
- package/README.md +127 -2
- package/dist/add.js +75 -0
- package/dist/check.js +123 -0
- package/dist/cli.js +58 -0
- package/dist/definition.js +17 -0
- package/dist/fingerprint.js +16 -0
- package/dist/graph.js +263 -0
- package/dist/json.js +131 -0
- package/dist/report.js +26 -0
- package/dist/rules.js +154 -0
- package/dist/semver.js +42 -0
- package/dist/skills.js +180 -0
- package/package.json +42 -4
- package/schema/2026-11-19/check.schema.json +68 -0
- package/schema/2026-11-19/musubi.schema.json +77 -0
- package/schema/2026-11-20/check.schema.json +68 -0
- package/schema/2026-11-20/musubi.schema.json +81 -0
- package/spec/musubi.ja.md +261 -0
- package/spec/musubi.md +245 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cardene777
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.ja.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="site/assets/icon.svg" width="88" height="88" alt="">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">musubi</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">スキルが提供するコンテンツとそれに準拠するスキルを結ぶ</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/musubi-cli"><img src="https://img.shields.io/npm/v/musubi-cli" alt="npmのバージョン"></a>
|
|
11
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MITライセンス"></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/musubi-cli"><img src="https://img.shields.io/node/v/musubi-cli" alt="Node.jsのバージョン"></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://musubi.cardene.dev/ja/">サイト</a> · <a href="spec/musubi.ja.md">定義</a> · <a href="README.md">English</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<img src="docs/assets/binding.svg" width="720" alt="design-docがdesign 1.0.0を提供し、contract-designとdapp-architectureとwallet-designが^1.0.0で準拠する">
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
musubiは、あるエージェントのスキルのコンテンツを、別のスキルと結び付けるための提案です。
|
|
24
|
+
|
|
25
|
+
エージェントのスキルのパッケージマネージャーは既にあり、スキルを依存するスキルと一緒にインストールして、バージョンを固定できます。
|
|
26
|
+
ただし、スキルが依存先のどの部分に準拠するのかは記録しません。
|
|
27
|
+
その部分とは、書く文書の書式や、守る書き方のルールや、実行するチェックのことです。
|
|
28
|
+
musubiでは、スキルが提供するコンテンツを名前とバージョン付きで宣言し、別のスキルがそのコンテンツに準拠すると宣言します。
|
|
29
|
+
|
|
30
|
+
スキルを実行する時は、エージェントがそのコンテンツを読み込みます。
|
|
31
|
+
この動きは、`SKILL.md`を読むどのエージェントでも同じです。
|
|
32
|
+
提供するコンテンツが変わると、準拠するスキルが再チェックされます。
|
|
33
|
+
|
|
34
|
+
定義は[spec/musubi.ja.md](spec/musubi.ja.md)にあります。
|
|
35
|
+
|
|
36
|
+
## スキルが参加する方法
|
|
37
|
+
|
|
38
|
+
スキルは`SKILL.md`をそのまま持ち、その隣に`musubi.json`を追加します。
|
|
39
|
+
providerは、提供するコンテンツを並べます。
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"musubi": "2026-11-19",
|
|
44
|
+
"provides": {
|
|
45
|
+
"design": { "version": "1.0.0", "file": "formats/design.md", "check": "checks/design.json" }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
consumerは、準拠するコンテンツと、受け入れるバージョンと、最後にチェックしたコンテンツのフィンガープリントを並べます。
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"musubi": "2026-11-19",
|
|
55
|
+
"follows": {
|
|
56
|
+
"design-doc/design": {
|
|
57
|
+
"version": "^1.0.0",
|
|
58
|
+
"integrity": "sha256-yNSwpBT+xXEV5bGBqedpHmjWIHVi+JaAnRATAJ0s7wM=",
|
|
59
|
+
"examples": ["examples/orders-api.md"]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
consumerの`SKILL.md`の本文は、`design-doc`のスキルを名前で開いて`design`の書式を読むよう、エージェントに伝えます。
|
|
66
|
+
そのため、エージェントは新しい仕組みがなくてもコンテンツを読み込めます。
|
|
67
|
+
providerが無くても動くconsumerは、定義のバージョン`2026-11-20`を書き、準拠に`"optional": true`を足します。
|
|
68
|
+
するとエージェントは、providerがインストールされていない時にそのコンテンツ無しで作業を続けます。
|
|
69
|
+
2つのスキルは[examples/skills](examples/skills)にあります。
|
|
70
|
+
|
|
71
|
+
## チェック
|
|
72
|
+
|
|
73
|
+
`musubi`コマンドは宣言をチェックし、providerのチェックをconsumerの例に適用します。
|
|
74
|
+
Node.js 22.18以降で動き、実行時の依存を持ちません。
|
|
75
|
+
npmに`musubi-cli`として公開しており、インストールした後はプロジェクトのフォルダで実行します。
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm install -g musubi-cli
|
|
79
|
+
musubi check
|
|
80
|
+
musubi graph --out graph.html
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
フォルダを指定しない時、`musubi check`はカレントフォルダとホームフォルダにある`.claude/skills`、`.agents/skills`、`.github/skills`、`.gemini/skills`を読みます。
|
|
84
|
+
インストールせずに1回だけ実行する時は、`npx musubi-cli check <スキルのフォルダ>`を使います。
|
|
85
|
+
|
|
86
|
+
このリポジトリをクローンして実行する時は、先に開発用の依存をインストールします。
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
pnpm install
|
|
90
|
+
node src/cli.ts check examples/skills
|
|
91
|
+
node src/cli.ts graph examples/skills --out graph.html
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## サイトにスキルを載せる
|
|
95
|
+
|
|
96
|
+
musubiのサイトは、定義と、GitHubで見つけたスキルを表示します。
|
|
97
|
+
スキルごとに、提供するコンテンツと、準拠するコンテンツと、そのスキルに準拠しているスキルが載ります。
|
|
98
|
+
スキルを載せる時は、スキルを置いた公開リポジトリに、GitHubのリポジトリの画面のAboutの設定でトピック`musubi-skills`を付けます。
|
|
99
|
+
PRは要りません。
|
|
100
|
+
|
|
101
|
+
サイトは更新するたびに、トピック`musubi-skills`を持つ公開リポジトリをGitHubで検索し、デフォルトブランチで`musubi.json`と`SKILL.md`が並ぶフォルダを全て載せます。
|
|
102
|
+
`musubi check`と同じチェックに通らない`musubi.json`を持つフォルダは、サイトをビルドする時にフォルダ名と理由を表示し、一覧から外します。
|
|
103
|
+
|
|
104
|
+
管理者のスキルは、リポジトリごとに`registry/<owner>/<repo>.json`というファイルにも置き、載せるフォルダをリポジトリのルートからの相対パスで並べます。
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"skills": ["plugins/doc-formats/skills/design-doc", "plugins/evm-dev/skills/contract-design"]
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`registry/excluded.json`には、サイトに載せない物を書きます。
|
|
113
|
+
リポジトリ全体は`<owner>/<repo>`、1つのフォルダは`<owner>/<repo>/<folder>`の形で並べます。
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"excluded": ["someone/repo", "someone/other-repo/skills/old-skill"]
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
サイトをビルドして手元の<http://localhost:3810/>で開く時は、`gh auth login`でログインしてから`pnpm site`を実行します。
|
|
122
|
+
このコマンドは`node site/build.ts`で、ログインしたghを使ってGitHubを検索し、ページを`site/dist/`に書き出してから、そのフォルダを配信します。
|
|
123
|
+
公開したサイトは<https://musubi.cardene.dev/>にあり、`pnpm site:publish`で公開する手順は[docs/publishing.ja.md](docs/publishing.ja.md)にあります。
|
|
124
|
+
|
|
125
|
+
## 文書
|
|
126
|
+
|
|
127
|
+
| 文書 | 内容 |
|
|
128
|
+
|---|---|
|
|
129
|
+
| [spec/musubi.ja.md](spec/musubi.ja.md) | 定義 |
|
|
130
|
+
| [GLOSSARY.ja.md](GLOSSARY.ja.md) | 定義が使う用語 |
|
|
131
|
+
| [docs/publishing.ja.md](docs/publishing.ja.md) | サイトをGitHub Pagesへ公開する手順 |
|
|
132
|
+
| [docs/adr](docs/adr) | 元に戻すのが高くつく判断と、採らなかった案 |
|
|
133
|
+
|
|
134
|
+
## ライセンス
|
|
135
|
+
|
|
136
|
+
musubiはMITライセンスで公開しています。
|
|
137
|
+
全文は[LICENSE](LICENSE)にあります。
|
package/README.md
CHANGED
|
@@ -1,3 +1,128 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="site/assets/icon.svg" width="88" height="88" alt="">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<h1 align="center">musubi</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">Bind what one skill provides to the skills that follow it</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/musubi-cli"><img src="https://img.shields.io/npm/v/musubi-cli" alt="npm version"></a>
|
|
11
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license"></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/musubi-cli"><img src="https://img.shields.io/node/v/musubi-cli" alt="Node.js version"></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://musubi.cardene.dev/">Website</a> · <a href="spec/musubi.md">Definition</a> · <a href="README.ja.md">日本語</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<img src="docs/assets/binding.svg" width="720" alt="design-doc provides design 1.0.0, and contract-design, dapp-architecture, and wallet-design follow it at ^1.0.0">
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
musubi is a proposal for binding the content of one agent skill to another.
|
|
24
|
+
|
|
25
|
+
Package managers for agent skills already install a skill together with the skills it depends on and lock their versions.
|
|
26
|
+
What they do not record is which part of a dependency a skill follows: the document format it writes in, the writing rules it obeys, or the check it runs.
|
|
27
|
+
musubi lets a skill declare the content it provides under a name and a version, lets another skill declare that it follows that content, and lets an agent load the content when the skill runs, the same way in every agent that reads `SKILL.md`.
|
|
28
|
+
When the provided content changes, the skills that follow it are checked again.
|
|
29
|
+
|
|
30
|
+
The definition is in [spec/musubi.md](spec/musubi.md).
|
|
31
|
+
|
|
32
|
+
## How a skill takes part
|
|
33
|
+
|
|
34
|
+
A skill keeps its `SKILL.md` as it is and adds `musubi.json` next to it.
|
|
35
|
+
A provider lists the content it offers.
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"musubi": "2026-11-19",
|
|
40
|
+
"provides": {
|
|
41
|
+
"design": { "version": "1.0.0", "file": "formats/design.md", "check": "checks/design.json" }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
A consumer lists the content it follows, the versions it accepts, and the fingerprint of the content it last checked.
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"musubi": "2026-11-19",
|
|
51
|
+
"follows": {
|
|
52
|
+
"design-doc/design": {
|
|
53
|
+
"version": "^1.0.0",
|
|
54
|
+
"integrity": "sha256-yNSwpBT+xXEV5bGBqedpHmjWIHVi+JaAnRATAJ0s7wM=",
|
|
55
|
+
"examples": ["examples/orders-api.md"]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The consumer's `SKILL.md` body tells the agent to open the `design-doc` skill by name and read its `design` format, so agents need nothing new to load it.
|
|
62
|
+
A consumer that also works without the provider names definition version `2026-11-20` and adds `"optional": true` to the follow; the agent then goes on without the content when the provider is not installed.
|
|
63
|
+
[examples/skills](examples/skills) holds both skills.
|
|
64
|
+
|
|
65
|
+
## Checking
|
|
66
|
+
|
|
67
|
+
The `musubi` command checks the declarations and applies each provider's check to the consumers' examples.
|
|
68
|
+
It needs Node.js 22.18 or later and has no runtime dependencies.
|
|
69
|
+
It is published on npm as `musubi-cli`; once installed, run it in a project folder.
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm install -g musubi-cli
|
|
73
|
+
musubi check
|
|
74
|
+
musubi graph --out graph.html
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Without folders, `musubi check` reads `.claude/skills`, `.agents/skills`, `.github/skills`, and `.gemini/skills` in the current folder and in the home folder.
|
|
78
|
+
To run it once without installing, use `npx musubi-cli check <skills folder>`.
|
|
79
|
+
|
|
80
|
+
To run it from a clone of this repository, install the development dependencies first.
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pnpm install
|
|
84
|
+
node src/cli.ts check examples/skills
|
|
85
|
+
node src/cli.ts graph examples/skills --out graph.html
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Listing a skill on the site
|
|
89
|
+
|
|
90
|
+
The musubi site shows the definition and the skills it finds on GitHub, with what each one provides, what it follows, and which skills follow it.
|
|
91
|
+
To list your skills, give their public repository the topic `musubi-skills` in the About settings of the repository page on GitHub.
|
|
92
|
+
No pull request is needed.
|
|
93
|
+
|
|
94
|
+
Each time the site is updated, it searches GitHub for public repositories with the topic `musubi-skills` and lists every folder on the default branch that holds both `musubi.json` and `SKILL.md`.
|
|
95
|
+
A folder whose `musubi.json` fails the checks `musubi check` runs is named with the reason when the site is built, and left out.
|
|
96
|
+
|
|
97
|
+
The maintainers' own skills are also named in `registry/<owner>/<repo>.json`, one file per repository, which lists the skill folders relative to the repository root.
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"skills": ["plugins/doc-formats/skills/design-doc", "plugins/evm-dev/skills/contract-design"]
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`registry/excluded.json` names what the site leaves out: a whole repository as `<owner>/<repo>`, or one folder as `<owner>/<repo>/<folder>`.
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"excluded": ["someone/repo", "someone/other-repo/skills/old-skill"]
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
To build the site and open it on your machine at <http://localhost:3810/>, sign in with `gh auth login` and run `pnpm site`.
|
|
114
|
+
It runs `node site/build.ts`, which searches GitHub with your gh sign-in, writes the pages to `site/dist/`, and then serves that folder.
|
|
115
|
+
The public site is at <https://musubi.cardene.dev/>, and [docs/publishing.md](docs/publishing.md) explains how to publish it with `pnpm site:publish`.
|
|
116
|
+
|
|
117
|
+
## Documents
|
|
118
|
+
|
|
119
|
+
| Document | Holds |
|
|
120
|
+
|---|---|
|
|
121
|
+
| [spec/musubi.md](spec/musubi.md) | The definition |
|
|
122
|
+
| [GLOSSARY.md](GLOSSARY.md) | The terms the definition uses |
|
|
123
|
+
| [docs/publishing.md](docs/publishing.md) | How the site is published to GitHub Pages |
|
|
124
|
+
| [docs/adr](docs/adr) | Decisions that are costly to reverse, with the options not taken |
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
musubi is released under the MIT License. The full text is in [LICENSE](LICENSE).
|
package/dist/add.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
import { load } from "./check.js";
|
|
4
|
+
import { latestDefinition, optionalVersions } from "./definition.js";
|
|
5
|
+
import { fingerprint } from "./fingerprint.js";
|
|
6
|
+
import { isObject } from "./json.js";
|
|
7
|
+
import { Report } from "./report.js";
|
|
8
|
+
import { format } from "./semver.js";
|
|
9
|
+
import { fingerprintFiles } from "./skills.js";
|
|
10
|
+
// Content files an agent runs rather than reads, told apart by their extension in any case.
|
|
11
|
+
const SCRIPT = /\.(py|sh|bash|js|mjs|cjs|ts)$/i;
|
|
12
|
+
// The three lines a consumer's SKILL.md body carries for one content it follows. The first line
|
|
13
|
+
// tells the agent to run a script and to read anything else as a format. For an optional follow the
|
|
14
|
+
// first line applies only when the provider is installed, and the last one goes on without it.
|
|
15
|
+
export function bodyLines(skill, content, file, optional = false) {
|
|
16
|
+
const how = SCRIPT.test(file)
|
|
17
|
+
? `run the \`${content}\` of the \`${skill}\` skill: open the \`${skill}\` skill by name and run the file it names for \`${content}\`.`
|
|
18
|
+
: `write in the \`${content}\` format of the \`${skill}\` skill: open the \`${skill}\` skill by name and read the file it names for \`${content}\`.`;
|
|
19
|
+
return [
|
|
20
|
+
optional ? `When the \`${skill}\` skill is installed, ${how}` : how[0].toUpperCase() + how.slice(1),
|
|
21
|
+
"If the `musubi` command is available, run `musubi check` before reading, and stop if it fails.",
|
|
22
|
+
optional
|
|
23
|
+
? `If the \`${skill}\` skill is not installed, go on without the \`${content}\` of \`${skill}\`.`
|
|
24
|
+
: `If the \`${skill}\` skill is not installed, do not start: tell the user that \`${skill}\` is missing and how to install it, then stop.`,
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
// Run in a consumer skill's folder: writes the range and the fingerprint of one content into its
|
|
28
|
+
// musubi.json and prints the lines to put in its SKILL.md body.
|
|
29
|
+
export function add(ref, roots, cwd, optional = false) {
|
|
30
|
+
const report = new Report(cwd);
|
|
31
|
+
const fail = (message) => {
|
|
32
|
+
report.print();
|
|
33
|
+
process.stderr.write(`musubi add: ${message}\n`);
|
|
34
|
+
return 1;
|
|
35
|
+
};
|
|
36
|
+
if (!existsSync(join(cwd, "SKILL.md")))
|
|
37
|
+
return fail("run this in the folder of the skill that follows the content");
|
|
38
|
+
const [skillName, content] = ref.split("/");
|
|
39
|
+
if (!skillName || !content || ref.split("/").length !== 2)
|
|
40
|
+
return fail(`"${ref}" must name a content as <skill>/<content>`);
|
|
41
|
+
const { skills, declarations } = load(roots, report);
|
|
42
|
+
const provider = skills.get(skillName);
|
|
43
|
+
if (!provider)
|
|
44
|
+
return fail(`no skill named ${skillName} is installed, so ${ref} cannot be added`);
|
|
45
|
+
const provided = declarations.get(skillName)?.provides.get(content);
|
|
46
|
+
if (!provided)
|
|
47
|
+
return fail(`${skillName} provides no content named ${content}, so ${ref} cannot be added`);
|
|
48
|
+
if (!provided.version || !provided.file)
|
|
49
|
+
return fail(`the declaration of ${ref} has mistakes; run musubi check to see them`);
|
|
50
|
+
const path = join(cwd, "musubi.json");
|
|
51
|
+
let json = { musubi: latestDefinition };
|
|
52
|
+
if (existsSync(path)) {
|
|
53
|
+
const current = JSON.parse(readFileSync(path, "utf8"));
|
|
54
|
+
if (!isObject(current))
|
|
55
|
+
return fail("musubi.json holds something other than one JSON object");
|
|
56
|
+
json = current;
|
|
57
|
+
}
|
|
58
|
+
// An optional follow needs a definition version that knows the field.
|
|
59
|
+
if (optional && !(typeof json.musubi === "string" && optionalVersions.has(json.musubi)))
|
|
60
|
+
json.musubi = latestDefinition;
|
|
61
|
+
const follows = isObject(json.follows) ? json.follows : {};
|
|
62
|
+
// Keep fields the consumer already wrote, such as examples, after the ones this command owns.
|
|
63
|
+
const { version: _version, integrity: _integrity, optional: _optional, ...kept } = isObject(follows[ref]) ? follows[ref] : {};
|
|
64
|
+
follows[ref] = {
|
|
65
|
+
version: `^${format(provided.version)}`,
|
|
66
|
+
integrity: fingerprint(provider.dir, fingerprintFiles(provided)),
|
|
67
|
+
...(optional ? { optional: true } : {}),
|
|
68
|
+
...kept,
|
|
69
|
+
};
|
|
70
|
+
json.follows = follows;
|
|
71
|
+
writeFileSync(path, `${JSON.stringify(json, null, 2)}\n`);
|
|
72
|
+
process.stderr.write(`musubi add: wrote ${ref} ^${format(provided.version)} to ${basename(cwd)}/musubi.json\n`);
|
|
73
|
+
process.stdout.write(`${bodyLines(skillName, content, provided.file, optional).join("\n")}\n`);
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
package/dist/check.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { READ_LINES } from "./definition.js";
|
|
4
|
+
import { fingerprint } from "./fingerprint.js";
|
|
5
|
+
import { Report } from "./report.js";
|
|
6
|
+
import { applyRules } from "./rules.js";
|
|
7
|
+
import { discover, fingerprintFiles, readDeclaration } from "./skills.js";
|
|
8
|
+
import { format, satisfies } from "./semver.js";
|
|
9
|
+
export function load(roots, report) {
|
|
10
|
+
const skills = discover(roots, report);
|
|
11
|
+
const declarations = new Map();
|
|
12
|
+
for (const skill of skills.values()) {
|
|
13
|
+
const declaration = readDeclaration(skill, report);
|
|
14
|
+
if (declaration)
|
|
15
|
+
declarations.set(skill.name, declaration);
|
|
16
|
+
}
|
|
17
|
+
return { skills, declarations };
|
|
18
|
+
}
|
|
19
|
+
// Follows form a graph from each skill to the skills it follows. A cycle makes an agent read the
|
|
20
|
+
// same content again and again, so the first cycle found is refused with its path.
|
|
21
|
+
function findCycle(declarations) {
|
|
22
|
+
const state = new Map();
|
|
23
|
+
const path = [];
|
|
24
|
+
const visit = (name) => {
|
|
25
|
+
if (state.get(name) === "done")
|
|
26
|
+
return null;
|
|
27
|
+
if (state.get(name) === "open")
|
|
28
|
+
return [...path.slice(path.indexOf(name)), name];
|
|
29
|
+
state.set(name, "open");
|
|
30
|
+
path.push(name);
|
|
31
|
+
for (const follow of declarations.get(name)?.follows ?? []) {
|
|
32
|
+
if (!declarations.has(follow.skill))
|
|
33
|
+
continue;
|
|
34
|
+
const cycle = visit(follow.skill);
|
|
35
|
+
if (cycle)
|
|
36
|
+
return cycle;
|
|
37
|
+
}
|
|
38
|
+
path.pop();
|
|
39
|
+
state.set(name, "done");
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
for (const name of [...declarations.keys()].sort()) {
|
|
43
|
+
const cycle = visit(name);
|
|
44
|
+
if (cycle)
|
|
45
|
+
return cycle;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
export function check(roots, cwd, update) {
|
|
50
|
+
const report = new Report(cwd);
|
|
51
|
+
const { skills, declarations } = load(roots, report);
|
|
52
|
+
let follows = 0;
|
|
53
|
+
const rewrites = [];
|
|
54
|
+
for (const declaration of declarations.values()) {
|
|
55
|
+
const consumer = declaration.skill.name;
|
|
56
|
+
for (const follow of declaration.follows) {
|
|
57
|
+
follows += 1;
|
|
58
|
+
const provider = skills.get(follow.skill);
|
|
59
|
+
if (!provider && follow.optional) {
|
|
60
|
+
report.warn(`${consumer} follows ${follow.ref} only when ${follow.skill} is installed; it is not, so this follow was skipped`);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!provider) {
|
|
64
|
+
report.problem(declaration.path, follow.line, `${consumer} follows ${follow.ref}, but no skill named ${follow.skill} is installed`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const provided = declarations.get(follow.skill)?.provides.get(follow.content);
|
|
68
|
+
if (!provided) {
|
|
69
|
+
report.problem(declaration.path, follow.line, `${consumer} follows ${follow.ref}, but ${follow.skill} provides no content named ${follow.content}`);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (!provided.version || !provided.file || !follow.range)
|
|
73
|
+
continue;
|
|
74
|
+
if (!satisfies(provided.version, follow.range)) {
|
|
75
|
+
report.problem(declaration.path, follow.versionLine, `${consumer} accepts ${follow.range.text} of ${follow.ref}, but ${follow.skill} provides ${format(provided.version)}`);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const body = readFileSync(join(provider.dir, provided.file), "utf8");
|
|
79
|
+
const lineCount = body.split("\n").length - (body.endsWith("\n") ? 1 : 0);
|
|
80
|
+
if (lineCount > READ_LINES) {
|
|
81
|
+
report.warn(`${follow.ref} is ${lineCount} lines, over the ${READ_LINES} lines Agent Skills suggests for SKILL.md; agents read it whole`);
|
|
82
|
+
}
|
|
83
|
+
const now = fingerprint(provider.dir, fingerprintFiles(provided));
|
|
84
|
+
const changed = follow.integrity !== null && now !== follow.integrity;
|
|
85
|
+
if (changed && !update) {
|
|
86
|
+
report.problem(declaration.path, follow.integrityLine, `${consumer}: the fingerprint of ${follow.ref} does not match, so its content changed after the last check; ` +
|
|
87
|
+
"review the change and run musubi check --update");
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const before = report.problems.length;
|
|
91
|
+
if (provided.rules) {
|
|
92
|
+
for (const example of follow.examples) {
|
|
93
|
+
const path = join(declaration.skill.dir, example);
|
|
94
|
+
for (const finding of applyRules(provided.rules, readFileSync(path, "utf8"))) {
|
|
95
|
+
report.problem(path, finding.line, `${finding.message} (${follow.ref})`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (changed && follow.integrity && report.problems.length === before) {
|
|
100
|
+
rewrites.push({ declaration, line: follow.integrityLine, from: follow.integrity, to: now });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const cycle = findCycle(declarations);
|
|
105
|
+
if (cycle) {
|
|
106
|
+
const first = declarations.get(cycle[0]);
|
|
107
|
+
const follow = first?.follows.find((f) => f.skill === cycle[1]);
|
|
108
|
+
report.problem(first?.path ?? cwd, follow?.line ?? 1, `the skills follow each other in a cycle: ${cycle.join(" -> ")}`);
|
|
109
|
+
}
|
|
110
|
+
for (const rewrite of rewrites) {
|
|
111
|
+
const lines = readFileSync(rewrite.declaration.path, "utf8").split("\n");
|
|
112
|
+
lines[rewrite.line - 1] = lines[rewrite.line - 1].replace(rewrite.from, rewrite.to);
|
|
113
|
+
writeFileSync(rewrite.declaration.path, lines.join("\n"));
|
|
114
|
+
}
|
|
115
|
+
report.print();
|
|
116
|
+
if (report.problems.length > 0) {
|
|
117
|
+
process.stderr.write(`musubi check: ${report.problems.length} problem${report.problems.length === 1 ? "" : "s"}\n`);
|
|
118
|
+
return 1;
|
|
119
|
+
}
|
|
120
|
+
const updated = rewrites.length > 0 ? `, updated=${rewrites.length}` : "";
|
|
121
|
+
process.stdout.write(`musubi check: ok (skills=${skills.size}, follows=${follows}${updated})\n`);
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { add } from "./add.js";
|
|
5
|
+
import { check } from "./check.js";
|
|
6
|
+
import { graph } from "./graph.js";
|
|
7
|
+
import { defaultRoots } from "./skills.js";
|
|
8
|
+
const USAGE = `usage:
|
|
9
|
+
musubi check [<skills folder>...] [--update]
|
|
10
|
+
Checks every musubi.json in the folders. Without folders it reads .claude/skills, .agents/skills,
|
|
11
|
+
.github/skills, and .gemini/skills in this folder and in the home folder.
|
|
12
|
+
--update rewrites a fingerprint after its content passes the check again.
|
|
13
|
+
musubi add <skill>/<content> [<skills folder>...] [--optional]
|
|
14
|
+
Run in a skill's folder: makes the skill follow the content and prints the lines for its SKILL.md.
|
|
15
|
+
--optional makes the follow optional: the skill reads the content only when the provider is installed.
|
|
16
|
+
musubi graph [<skills folder>...] [--out <file>]
|
|
17
|
+
Writes an HTML page of the skills and the contents they follow (default musubi-graph.html).
|
|
18
|
+
`;
|
|
19
|
+
function main(argv) {
|
|
20
|
+
const [command, ...rest] = argv;
|
|
21
|
+
const cwd = process.cwd();
|
|
22
|
+
const flags = new Set(rest.filter((arg) => arg.startsWith("--")));
|
|
23
|
+
const positional = [];
|
|
24
|
+
let out = "musubi-graph.html";
|
|
25
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
26
|
+
if (rest[i] === "--out") {
|
|
27
|
+
out = rest[i + 1] ?? "";
|
|
28
|
+
i += 1;
|
|
29
|
+
}
|
|
30
|
+
else if (!rest[i].startsWith("--"))
|
|
31
|
+
positional.push(rest[i]);
|
|
32
|
+
}
|
|
33
|
+
const unknown = [...flags].filter((flag) => !(command === "check" && flag === "--update") && !(command === "graph" && flag === "--out") && !(command === "add" && flag === "--optional"));
|
|
34
|
+
if (command === "--help" || command === "-h") {
|
|
35
|
+
process.stdout.write(USAGE);
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
if (unknown.length > 0 || (command === "graph" && out === "")) {
|
|
39
|
+
process.stderr.write(`musubi: unknown or incomplete option ${unknown[0] ?? "--out"}\n${USAGE}`);
|
|
40
|
+
return 2;
|
|
41
|
+
}
|
|
42
|
+
const roots = (given, extra = []) => given.length > 0 ? given.map((r) => resolve(cwd, r)) : [...extra, ...defaultRoots(cwd, homedir())];
|
|
43
|
+
switch (command) {
|
|
44
|
+
case "check":
|
|
45
|
+
return check(roots(positional), cwd, flags.has("--update"));
|
|
46
|
+
case "add": {
|
|
47
|
+
const [ref, ...given] = positional;
|
|
48
|
+
if (!ref)
|
|
49
|
+
break;
|
|
50
|
+
return add(ref, roots(given, [resolve(cwd, "..")]), cwd, flags.has("--optional"));
|
|
51
|
+
}
|
|
52
|
+
case "graph":
|
|
53
|
+
return graph(roots(positional), resolve(cwd, out), cwd);
|
|
54
|
+
}
|
|
55
|
+
process.stderr.write(USAGE);
|
|
56
|
+
return 2;
|
|
57
|
+
}
|
|
58
|
+
process.exitCode = main(process.argv.slice(2));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
// The definition versions this command reads are the dated folders under schema/, so the dates
|
|
4
|
+
// live in one place. The folder sits next to src/ in the repository and next to dist/ when installed.
|
|
5
|
+
export const schemaDir = fileURLToPath(new URL("../schema/", import.meta.url));
|
|
6
|
+
export const definitionVersions = readdirSync(schemaDir)
|
|
7
|
+
.filter((name) => /^\d{4}-\d{2}-\d{2}$/.test(name))
|
|
8
|
+
.sort();
|
|
9
|
+
export const latestDefinition = definitionVersions[definitionVersions.length - 1];
|
|
10
|
+
// The definition versions whose schema lets a follow say "optional" (decision record 0007), read
|
|
11
|
+
// from the schemas so that no date is written in the code.
|
|
12
|
+
export const optionalVersions = new Set(definitionVersions.filter((version) => {
|
|
13
|
+
const schema = JSON.parse(readFileSync(`${schemaDir}${version}/musubi.schema.json`, "utf8"));
|
|
14
|
+
return schema?.$defs?.followed?.properties?.optional !== undefined;
|
|
15
|
+
}));
|
|
16
|
+
// Agents read a content file whole; Agent Skills suggests keeping SKILL.md under this many lines.
|
|
17
|
+
export const READ_LINES = 500;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
// The fingerprint of one content: sha256 over each file's path, byte length, and bytes, in the
|
|
5
|
+
// order the provider's SKILL.md, the content file, and the check file, written as `sha256-<base64>`.
|
|
6
|
+
export function fingerprint(skillDir, paths) {
|
|
7
|
+
const hash = createHash("sha256");
|
|
8
|
+
for (const path of paths) {
|
|
9
|
+
const bytes = readFileSync(join(skillDir, path));
|
|
10
|
+
hash.update(`${path}\n${bytes.length}\n`);
|
|
11
|
+
hash.update(bytes);
|
|
12
|
+
hash.update("\n");
|
|
13
|
+
}
|
|
14
|
+
return `sha256-${hash.digest("base64")}`;
|
|
15
|
+
}
|
|
16
|
+
export const INTEGRITY = /^sha256-[A-Za-z0-9+/]{43}=$/;
|