musubi-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.ja.md +79 -0
- package/README.md +74 -2
- package/dist/add.js +68 -0
- package/dist/check.js +119 -0
- package/dist/cli.js +57 -0
- package/dist/definition.js +11 -0
- package/dist/fingerprint.js +16 -0
- package/dist/graph.js +134 -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 +174 -0
- package/package.json +39 -4
- package/schema/2026-11-19/check.schema.json +68 -0
- package/schema/2026-11-19/musubi.schema.json +77 -0
- package/spec/musubi.ja.md +242 -0
- package/spec/musubi.md +233 -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,79 @@
|
|
|
1
|
+
# musubi
|
|
2
|
+
|
|
3
|
+
musubiは、あるエージェントのスキルの中身を、別のスキルと結ぶための提案です。
|
|
4
|
+
|
|
5
|
+
スキルを入れる道具は既にあり、依存するスキルも一緒に入れて版を固定できます。
|
|
6
|
+
ただし、使う側のスキルが依存先のどの中身に従うのかは、どの道具にも残りません。
|
|
7
|
+
中身とは、書く文書の書式、守る書き方の決まり、回す検査のことです。
|
|
8
|
+
musubiでは、スキルが出す中身を名前と版で宣言し、別のスキルがその中身に従うと宣言します。
|
|
9
|
+
スキルを使う時には、エージェントがその中身を読み込みます。
|
|
10
|
+
この動きは、`SKILL.md`を読むどのエージェントでも同じです。
|
|
11
|
+
出す側の中身が変わると、従う側のスキルを確かめ直します。
|
|
12
|
+
|
|
13
|
+
定義は[spec/musubi.ja.md](spec/musubi.ja.md)に在ります。
|
|
14
|
+
|
|
15
|
+
## スキルの加わり方
|
|
16
|
+
|
|
17
|
+
スキルは`SKILL.md`をそのまま持ち、その横に`musubi.json`を足します。
|
|
18
|
+
出す側は、出す中身を並べます。
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"musubi": "2026-11-19",
|
|
23
|
+
"provides": {
|
|
24
|
+
"design": { "version": "1.0.0", "file": "formats/design.md", "check": "checks/design.json" }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
使う側は、従う中身と、従える版と、最後に確かめた中身の指紋を並べます。
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"musubi": "2026-11-19",
|
|
34
|
+
"follows": {
|
|
35
|
+
"design-doc/design": {
|
|
36
|
+
"version": "^1.0.0",
|
|
37
|
+
"integrity": "sha256-yNSwpBT+xXEV5bGBqedpHmjWIHVi+JaAnRATAJ0s7wM=",
|
|
38
|
+
"examples": ["examples/orders-api.md"]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
使う側の`SKILL.md`の本文は、`design-doc`のスキルを名前で開いて`design`の書式を読むようエージェントに伝えます。
|
|
45
|
+
そのため、エージェントは新しい仕組みを持たずに中身を読み込めます。
|
|
46
|
+
2つのスキルは[examples/skills](examples/skills)に在ります。
|
|
47
|
+
|
|
48
|
+
## 確かめ方
|
|
49
|
+
|
|
50
|
+
`musubi`の命令は宣言を確かめ、出す側の検査を使う側の例に回します。
|
|
51
|
+
Node.js 22.18以降で動き、実行時の依存を持ちません。
|
|
52
|
+
npmには`musubi-cli`の名前で出ており、入れた後はプロジェクトのフォルダで回します。
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm install -g musubi-cli
|
|
56
|
+
musubi check
|
|
57
|
+
musubi graph --out graph.html
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
フォルダを渡さない時、`musubi check`は今のフォルダとホームのフォルダの`.claude/skills`、`.agents/skills`、`.github/skills`、`.gemini/skills`を読みます。
|
|
61
|
+
入れずに1回だけ回す時は、`npx musubi-cli check <スキルのフォルダ>`を使います。
|
|
62
|
+
|
|
63
|
+
このrepoを手元に写して回す時は、先に開発の依存を入れます。
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pnpm install
|
|
67
|
+
node src/cli.ts check examples/skills
|
|
68
|
+
node src/cli.ts graph examples/skills --out graph.html
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 文書
|
|
72
|
+
|
|
73
|
+
| 文書 | 持つ物 |
|
|
74
|
+
|---|---|
|
|
75
|
+
| [spec/musubi.ja.md](spec/musubi.ja.md) | 定義 |
|
|
76
|
+
| [GLOSSARY.ja.md](GLOSSARY.ja.md) | 定義が使う語 |
|
|
77
|
+
| [docs/adr](docs/adr) | 戻すのが高くつく判断と、採らなかった案 |
|
|
78
|
+
|
|
79
|
+
English: [README.md](README.md)
|
package/README.md
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
-
#
|
|
1
|
+
# musubi
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
musubi is a proposal for binding the content of one agent skill to another.
|
|
4
|
+
|
|
5
|
+
Package managers for agent skills already install a skill together with the skills it depends on and lock their versions.
|
|
6
|
+
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.
|
|
7
|
+
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`.
|
|
8
|
+
When the provided content changes, the skills that follow it are checked again.
|
|
9
|
+
|
|
10
|
+
The definition is in [spec/musubi.md](spec/musubi.md).
|
|
11
|
+
|
|
12
|
+
## How a skill takes part
|
|
13
|
+
|
|
14
|
+
A skill keeps its `SKILL.md` as it is and adds `musubi.json` next to it.
|
|
15
|
+
A provider lists the content it offers.
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"musubi": "2026-11-19",
|
|
20
|
+
"provides": {
|
|
21
|
+
"design": { "version": "1.0.0", "file": "formats/design.md", "check": "checks/design.json" }
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
A consumer lists the content it follows, the versions it accepts, and the fingerprint of the content it last checked.
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"musubi": "2026-11-19",
|
|
31
|
+
"follows": {
|
|
32
|
+
"design-doc/design": {
|
|
33
|
+
"version": "^1.0.0",
|
|
34
|
+
"integrity": "sha256-yNSwpBT+xXEV5bGBqedpHmjWIHVi+JaAnRATAJ0s7wM=",
|
|
35
|
+
"examples": ["examples/orders-api.md"]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
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.
|
|
42
|
+
[examples/skills](examples/skills) holds both skills.
|
|
43
|
+
|
|
44
|
+
## Checking
|
|
45
|
+
|
|
46
|
+
The `musubi` command checks the declarations and applies each provider's check to the consumers' examples.
|
|
47
|
+
It needs Node.js 22.18 or later and has no runtime dependencies.
|
|
48
|
+
It is published on npm as `musubi-cli`; once installed, run it in a project folder.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install -g musubi-cli
|
|
52
|
+
musubi check
|
|
53
|
+
musubi graph --out graph.html
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Without folders, `musubi check` reads `.claude/skills`, `.agents/skills`, `.github/skills`, and `.gemini/skills` in the current folder and in the home folder.
|
|
57
|
+
To run it once without installing, use `npx musubi-cli check <skills folder>`.
|
|
58
|
+
|
|
59
|
+
To run it from a clone of this repository, install the development dependencies first.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm install
|
|
63
|
+
node src/cli.ts check examples/skills
|
|
64
|
+
node src/cli.ts graph examples/skills --out graph.html
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Documents
|
|
68
|
+
|
|
69
|
+
| Document | Holds |
|
|
70
|
+
|---|---|
|
|
71
|
+
| [spec/musubi.md](spec/musubi.md) | The definition |
|
|
72
|
+
| [GLOSSARY.md](GLOSSARY.md) | The terms the definition uses |
|
|
73
|
+
| [docs/adr](docs/adr) | Decisions that are costly to reverse, with the options not taken |
|
|
74
|
+
|
|
75
|
+
Japanese: [README.ja.md](README.ja.md)
|
package/dist/add.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
import { load } from "./check.js";
|
|
4
|
+
import { latestDefinition } 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.
|
|
14
|
+
export function bodyLines(skill, content, file) {
|
|
15
|
+
const use = SCRIPT.test(file)
|
|
16
|
+
? `Run the \`${content}\` of the \`${skill}\` skill: open the \`${skill}\` skill by name and run the file it names for \`${content}\`.`
|
|
17
|
+
: `Write in the \`${content}\` format of the \`${skill}\` skill: open the \`${skill}\` skill by name and read the file it names for \`${content}\`.`;
|
|
18
|
+
return [
|
|
19
|
+
use,
|
|
20
|
+
"If the `musubi` command is available, run `musubi check` before reading, and stop if it fails.",
|
|
21
|
+
`If the \`${skill}\` skill is not installed, do not start: tell the user that \`${skill}\` is missing and how to install it, then stop.`,
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
// Run in a consumer skill's folder: writes the range and the fingerprint of one content into its
|
|
25
|
+
// musubi.json and prints the lines to put in its SKILL.md body.
|
|
26
|
+
export function add(ref, roots, cwd) {
|
|
27
|
+
const report = new Report(cwd);
|
|
28
|
+
const fail = (message) => {
|
|
29
|
+
report.print();
|
|
30
|
+
process.stderr.write(`musubi add: ${message}\n`);
|
|
31
|
+
return 1;
|
|
32
|
+
};
|
|
33
|
+
if (!existsSync(join(cwd, "SKILL.md")))
|
|
34
|
+
return fail("run this in the folder of the skill that follows the content");
|
|
35
|
+
const [skillName, content] = ref.split("/");
|
|
36
|
+
if (!skillName || !content || ref.split("/").length !== 2)
|
|
37
|
+
return fail(`"${ref}" must name a content as <skill>/<content>`);
|
|
38
|
+
const { skills, declarations } = load(roots, report);
|
|
39
|
+
const provider = skills.get(skillName);
|
|
40
|
+
if (!provider)
|
|
41
|
+
return fail(`no skill named ${skillName} is installed, so ${ref} cannot be added`);
|
|
42
|
+
const provided = declarations.get(skillName)?.provides.get(content);
|
|
43
|
+
if (!provided)
|
|
44
|
+
return fail(`${skillName} provides no content named ${content}, so ${ref} cannot be added`);
|
|
45
|
+
if (!provided.version || !provided.file)
|
|
46
|
+
return fail(`the declaration of ${ref} has mistakes; run musubi check to see them`);
|
|
47
|
+
const path = join(cwd, "musubi.json");
|
|
48
|
+
let json = { musubi: latestDefinition };
|
|
49
|
+
if (existsSync(path)) {
|
|
50
|
+
const current = JSON.parse(readFileSync(path, "utf8"));
|
|
51
|
+
if (!isObject(current))
|
|
52
|
+
return fail("musubi.json holds something other than one JSON object");
|
|
53
|
+
json = current;
|
|
54
|
+
}
|
|
55
|
+
const follows = isObject(json.follows) ? json.follows : {};
|
|
56
|
+
// Keep fields the consumer already wrote, such as examples, after the two this command owns.
|
|
57
|
+
const { version: _version, integrity: _integrity, ...kept } = isObject(follows[ref]) ? follows[ref] : {};
|
|
58
|
+
follows[ref] = {
|
|
59
|
+
version: `^${format(provided.version)}`,
|
|
60
|
+
integrity: fingerprint(provider.dir, fingerprintFiles(provided)),
|
|
61
|
+
...kept,
|
|
62
|
+
};
|
|
63
|
+
json.follows = follows;
|
|
64
|
+
writeFileSync(path, `${JSON.stringify(json, null, 2)}\n`);
|
|
65
|
+
process.stderr.write(`musubi add: wrote ${ref} ^${format(provided.version)} to ${basename(cwd)}/musubi.json\n`);
|
|
66
|
+
process.stdout.write(`${bodyLines(skillName, content, provided.file).join("\n")}\n`);
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
package/dist/check.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
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) {
|
|
60
|
+
report.problem(declaration.path, follow.line, `${consumer} follows ${follow.ref}, but no skill named ${follow.skill} is installed`);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const provided = declarations.get(follow.skill)?.provides.get(follow.content);
|
|
64
|
+
if (!provided) {
|
|
65
|
+
report.problem(declaration.path, follow.line, `${consumer} follows ${follow.ref}, but ${follow.skill} provides no content named ${follow.content}`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!provided.version || !provided.file || !follow.range)
|
|
69
|
+
continue;
|
|
70
|
+
if (!satisfies(provided.version, follow.range)) {
|
|
71
|
+
report.problem(declaration.path, follow.versionLine, `${consumer} accepts ${follow.range.text} of ${follow.ref}, but ${follow.skill} provides ${format(provided.version)}`);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const body = readFileSync(join(provider.dir, provided.file), "utf8");
|
|
75
|
+
const lineCount = body.split("\n").length - (body.endsWith("\n") ? 1 : 0);
|
|
76
|
+
if (lineCount > READ_LINES) {
|
|
77
|
+
report.warn(`${follow.ref} is ${lineCount} lines, over the ${READ_LINES} lines Agent Skills suggests for SKILL.md; agents read it whole`);
|
|
78
|
+
}
|
|
79
|
+
const now = fingerprint(provider.dir, fingerprintFiles(provided));
|
|
80
|
+
const changed = follow.integrity !== null && now !== follow.integrity;
|
|
81
|
+
if (changed && !update) {
|
|
82
|
+
report.problem(declaration.path, follow.integrityLine, `${consumer}: the fingerprint of ${follow.ref} does not match, so its content changed after the last check; ` +
|
|
83
|
+
"review the change and run musubi check --update");
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const before = report.problems.length;
|
|
87
|
+
if (provided.rules) {
|
|
88
|
+
for (const example of follow.examples) {
|
|
89
|
+
const path = join(declaration.skill.dir, example);
|
|
90
|
+
for (const finding of applyRules(provided.rules, readFileSync(path, "utf8"))) {
|
|
91
|
+
report.problem(path, finding.line, `${finding.message} (${follow.ref})`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (changed && follow.integrity && report.problems.length === before) {
|
|
96
|
+
rewrites.push({ declaration, line: follow.integrityLine, from: follow.integrity, to: now });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const cycle = findCycle(declarations);
|
|
101
|
+
if (cycle) {
|
|
102
|
+
const first = declarations.get(cycle[0]);
|
|
103
|
+
const follow = first?.follows.find((f) => f.skill === cycle[1]);
|
|
104
|
+
report.problem(first?.path ?? cwd, follow?.line ?? 1, `the skills follow each other in a cycle: ${cycle.join(" -> ")}`);
|
|
105
|
+
}
|
|
106
|
+
for (const rewrite of rewrites) {
|
|
107
|
+
const lines = readFileSync(rewrite.declaration.path, "utf8").split("\n");
|
|
108
|
+
lines[rewrite.line - 1] = lines[rewrite.line - 1].replace(rewrite.from, rewrite.to);
|
|
109
|
+
writeFileSync(rewrite.declaration.path, lines.join("\n"));
|
|
110
|
+
}
|
|
111
|
+
report.print();
|
|
112
|
+
if (report.problems.length > 0) {
|
|
113
|
+
process.stderr.write(`musubi check: ${report.problems.length} problem${report.problems.length === 1 ? "" : "s"}\n`);
|
|
114
|
+
return 1;
|
|
115
|
+
}
|
|
116
|
+
const updated = rewrites.length > 0 ? `, updated=${rewrites.length}` : "";
|
|
117
|
+
process.stdout.write(`musubi check: ok (skills=${skills.size}, follows=${follows}${updated})\n`);
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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>...]
|
|
14
|
+
Run in a skill's folder: makes the skill follow the content and prints the lines for its SKILL.md.
|
|
15
|
+
musubi graph [<skills folder>...] [--out <file>]
|
|
16
|
+
Writes an HTML page of the skills and the contents they follow (default musubi-graph.html).
|
|
17
|
+
`;
|
|
18
|
+
function main(argv) {
|
|
19
|
+
const [command, ...rest] = argv;
|
|
20
|
+
const cwd = process.cwd();
|
|
21
|
+
const flags = new Set(rest.filter((arg) => arg.startsWith("--")));
|
|
22
|
+
const positional = [];
|
|
23
|
+
let out = "musubi-graph.html";
|
|
24
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
25
|
+
if (rest[i] === "--out") {
|
|
26
|
+
out = rest[i + 1] ?? "";
|
|
27
|
+
i += 1;
|
|
28
|
+
}
|
|
29
|
+
else if (!rest[i].startsWith("--"))
|
|
30
|
+
positional.push(rest[i]);
|
|
31
|
+
}
|
|
32
|
+
const unknown = [...flags].filter((flag) => !(command === "check" && flag === "--update") && !(command === "graph" && flag === "--out"));
|
|
33
|
+
if (command === "--help" || command === "-h") {
|
|
34
|
+
process.stdout.write(USAGE);
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
if (unknown.length > 0 || (command === "graph" && out === "")) {
|
|
38
|
+
process.stderr.write(`musubi: unknown or incomplete option ${unknown[0] ?? "--out"}\n${USAGE}`);
|
|
39
|
+
return 2;
|
|
40
|
+
}
|
|
41
|
+
const roots = (given, extra = []) => given.length > 0 ? given.map((r) => resolve(cwd, r)) : [...extra, ...defaultRoots(cwd, homedir())];
|
|
42
|
+
switch (command) {
|
|
43
|
+
case "check":
|
|
44
|
+
return check(roots(positional), cwd, flags.has("--update"));
|
|
45
|
+
case "add": {
|
|
46
|
+
const [ref, ...given] = positional;
|
|
47
|
+
if (!ref)
|
|
48
|
+
break;
|
|
49
|
+
return add(ref, roots(given, [resolve(cwd, "..")]), cwd);
|
|
50
|
+
}
|
|
51
|
+
case "graph":
|
|
52
|
+
return graph(roots(positional), resolve(cwd, out), cwd);
|
|
53
|
+
}
|
|
54
|
+
process.stderr.write(USAGE);
|
|
55
|
+
return 2;
|
|
56
|
+
}
|
|
57
|
+
process.exitCode = main(process.argv.slice(2));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { readdirSync } 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
|
+
// Agents read a content file whole; Agent Skills suggests keeping SKILL.md under this many lines.
|
|
11
|
+
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}=$/;
|
package/dist/graph.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { load } from "./check.js";
|
|
3
|
+
import { Report } from "./report.js";
|
|
4
|
+
import { format } from "./semver.js";
|
|
5
|
+
const escape = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
6
|
+
// Inside a quoted attribute only "&", "<", and the quote need escaping, so edges keep their "->".
|
|
7
|
+
const attribute = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
8
|
+
const NODE_W = 220;
|
|
9
|
+
const NODE_H = 64;
|
|
10
|
+
const GAP_X = 120;
|
|
11
|
+
const GAP_Y = 28;
|
|
12
|
+
const PAD = 24;
|
|
13
|
+
// Writes one self-contained HTML page that draws each skill as a box and each followed content as
|
|
14
|
+
// an arrow from the consumer to the provider. Providers sit to the right of the skills that follow them.
|
|
15
|
+
export function graph(roots, out, cwd) {
|
|
16
|
+
const report = new Report(cwd);
|
|
17
|
+
const { declarations } = load(roots, report);
|
|
18
|
+
const edges = [];
|
|
19
|
+
for (const declaration of declarations.values()) {
|
|
20
|
+
for (const follow of declaration.follows) {
|
|
21
|
+
edges.push({ from: declaration.skill.name, to: follow.skill, ref: follow.ref, range: follow.range?.text ?? "?" });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const names = new Set([...declarations.keys(), ...edges.map((e) => e.to)]);
|
|
25
|
+
// A skill's column is the length of the longest chain of skills that follow it, so arrows point right.
|
|
26
|
+
const depth = new Map();
|
|
27
|
+
const column = (name, seen) => {
|
|
28
|
+
if (depth.has(name))
|
|
29
|
+
return depth.get(name);
|
|
30
|
+
if (seen.has(name))
|
|
31
|
+
return 0;
|
|
32
|
+
seen.add(name);
|
|
33
|
+
const followers = edges.filter((e) => e.to === name).map((e) => column(e.from, seen) + 1);
|
|
34
|
+
const value = followers.length > 0 ? Math.max(...followers) : 0;
|
|
35
|
+
depth.set(name, value);
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
38
|
+
const nodes = new Map();
|
|
39
|
+
const rows = new Map();
|
|
40
|
+
for (const name of [...names].sort()) {
|
|
41
|
+
const c = column(name, new Set());
|
|
42
|
+
const row = rows.get(c) ?? 0;
|
|
43
|
+
rows.set(c, row + 1);
|
|
44
|
+
const provides = [...(declarations.get(name)?.provides.values() ?? [])].map((p) => `${p.name} ${p.version ? format(p.version) : "?"}`);
|
|
45
|
+
nodes.set(name, { name, column: c, row, provides });
|
|
46
|
+
}
|
|
47
|
+
const columns = Math.max(1, ...[...nodes.values()].map((n) => n.column + 1));
|
|
48
|
+
const maxRows = Math.max(1, ...rows.values());
|
|
49
|
+
const width = PAD * 2 + columns * NODE_W + (columns - 1) * GAP_X;
|
|
50
|
+
const height = PAD * 2 + maxRows * NODE_H + (maxRows - 1) * GAP_Y;
|
|
51
|
+
const x = (n) => PAD + n.column * (NODE_W + GAP_X);
|
|
52
|
+
const y = (n) => PAD + n.row * (NODE_H + GAP_Y);
|
|
53
|
+
const edgeSvg = edges
|
|
54
|
+
.map((e) => {
|
|
55
|
+
const a = nodes.get(e.from);
|
|
56
|
+
const b = nodes.get(e.to);
|
|
57
|
+
const x1 = x(a) + NODE_W;
|
|
58
|
+
const y1 = y(a) + NODE_H / 2;
|
|
59
|
+
const x2 = x(b);
|
|
60
|
+
const y2 = y(b) + NODE_H / 2;
|
|
61
|
+
const mid = (x1 + x2) / 2;
|
|
62
|
+
const label = `${e.ref.split("/")[1]} ${e.range}`;
|
|
63
|
+
return [
|
|
64
|
+
`<g class="edge" data-edge="${attribute(`${e.from} -> ${e.ref}`)}">`,
|
|
65
|
+
`<path d="M${x1},${y1} C${mid},${y1} ${mid},${y2} ${x2 - 6},${y2}" marker-end="url(#arrow)"/>`,
|
|
66
|
+
`<text x="${mid}" y="${(y1 + y2) / 2 - 8}" text-anchor="middle">${escape(label)}</text>`,
|
|
67
|
+
"</g>",
|
|
68
|
+
].join("");
|
|
69
|
+
})
|
|
70
|
+
.join("\n");
|
|
71
|
+
const nodeSvg = [...nodes.values()]
|
|
72
|
+
.map((n) => {
|
|
73
|
+
const detail = n.provides.length > 0 ? `provides ${n.provides.join(", ")}` : declarations.has(n.name) ? "follows only" : "not installed";
|
|
74
|
+
return [
|
|
75
|
+
`<g class="node${declarations.has(n.name) ? "" : " missing"}" data-skill="${attribute(n.name)}">`,
|
|
76
|
+
`<rect x="${x(n)}" y="${y(n)}" width="${NODE_W}" height="${NODE_H}" rx="10"/>`,
|
|
77
|
+
`<text class="name" x="${x(n) + 14}" y="${y(n) + 26}">${escape(n.name)}</text>`,
|
|
78
|
+
`<text class="detail" x="${x(n) + 14}" y="${y(n) + 46}">${escape(detail)}</text>`,
|
|
79
|
+
"</g>",
|
|
80
|
+
].join("");
|
|
81
|
+
})
|
|
82
|
+
.join("\n");
|
|
83
|
+
const rowsHtml = edges
|
|
84
|
+
.map((e) => `<tr><td>${escape(e.from)}</td><td>${escape(e.ref)}</td><td>${escape(e.range)}</td></tr>`)
|
|
85
|
+
.join("\n");
|
|
86
|
+
const html = `<!doctype html>
|
|
87
|
+
<html lang="en">
|
|
88
|
+
<head>
|
|
89
|
+
<meta charset="utf-8">
|
|
90
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
91
|
+
<title>Skill dependencies</title>
|
|
92
|
+
<style>
|
|
93
|
+
:root { --bg: #f7f7f5; --fg: #1d1d1b; --muted: #5f5f5a; --box: #ffffff; --line: #8a8a84; --accent: #2f6f5e; }
|
|
94
|
+
@media (prefers-color-scheme: dark) { :root { --bg: #161615; --fg: #ecece8; --muted: #a3a39c; --box: #22221f; --line: #77776f; --accent: #6fbfa6; } }
|
|
95
|
+
body { margin: 0; padding: 24px 16px; background: var(--bg); color: var(--fg); font: 15px/1.5 system-ui, sans-serif; }
|
|
96
|
+
h1 { font-size: 20px; margin: 0 0 4px; }
|
|
97
|
+
p { margin: 0 0 16px; color: var(--muted); }
|
|
98
|
+
.canvas { overflow-x: auto; }
|
|
99
|
+
svg text { fill: var(--fg); font: 13px system-ui, sans-serif; }
|
|
100
|
+
.node rect { fill: var(--box); stroke: var(--accent); stroke-width: 1.5; }
|
|
101
|
+
.node.missing rect { stroke: #c0503a; stroke-dasharray: 5 4; }
|
|
102
|
+
.node .name { font-weight: 600; font-size: 14px; }
|
|
103
|
+
.node .detail { fill: var(--muted); font-size: 12px; }
|
|
104
|
+
.edge path { fill: none; stroke: var(--line); stroke-width: 1.5; }
|
|
105
|
+
.edge text { fill: var(--muted); font-size: 12px; }
|
|
106
|
+
#arrow path { fill: var(--line); }
|
|
107
|
+
table { border-collapse: collapse; margin-top: 20px; }
|
|
108
|
+
th, td { text-align: left; padding: 6px 14px 6px 0; border-bottom: 1px solid var(--line); }
|
|
109
|
+
</style>
|
|
110
|
+
</head>
|
|
111
|
+
<body>
|
|
112
|
+
<h1>Skill dependencies</h1>
|
|
113
|
+
<p>Each arrow runs from a skill to the content it follows. ${nodes.size} skills, ${edges.length} followed contents.</p>
|
|
114
|
+
<div class="canvas">
|
|
115
|
+
<svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="img" aria-label="Skill dependency graph">
|
|
116
|
+
<defs><marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="8" markerHeight="8" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z"/></marker></defs>
|
|
117
|
+
${edgeSvg}
|
|
118
|
+
${nodeSvg}
|
|
119
|
+
</svg>
|
|
120
|
+
</div>
|
|
121
|
+
<table>
|
|
122
|
+
<thead><tr><th>Skill</th><th>Follows</th><th>Range</th></tr></thead>
|
|
123
|
+
<tbody>
|
|
124
|
+
${rowsHtml}
|
|
125
|
+
</tbody>
|
|
126
|
+
</table>
|
|
127
|
+
</body>
|
|
128
|
+
</html>
|
|
129
|
+
`;
|
|
130
|
+
writeFileSync(out, html);
|
|
131
|
+
report.print();
|
|
132
|
+
process.stderr.write(`musubi graph: wrote ${report.where(out)} (skills=${nodes.size}, follows=${edges.length})\n`);
|
|
133
|
+
return 0;
|
|
134
|
+
}
|