musubi-cli 0.1.0 → 0.3.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.ja.md CHANGED
@@ -1,21 +1,42 @@
1
- # musubi
1
+ <p align="center">
2
+ <img src="site/assets/icon.svg" width="88" height="88" alt="">
3
+ </p>
2
4
 
3
- musubiは、あるエージェントのスキルの中身を、別のスキルと結ぶための提案です。
5
+ <h1 align="center">musubi</h1>
4
6
 
5
- スキルを入れる道具は既にあり、依存するスキルも一緒に入れて版を固定できます。
6
- ただし、使う側のスキルが依存先のどの中身に従うのかは、どの道具にも残りません。
7
- 中身とは、書く文書の書式、守る書き方の決まり、回す検査のことです。
8
- musubiでは、スキルが出す中身を名前と版で宣言し、別のスキルがその中身に従うと宣言します。
9
- スキルを使う時には、エージェントがその中身を読み込みます。
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
+ スキルを実行する時は、エージェントがそのコンテンツを読み込みます。
10
31
  この動きは、`SKILL.md`を読むどのエージェントでも同じです。
11
- 出す側の中身が変わると、従う側のスキルを確かめ直します。
32
+ 提供するコンテンツが変わると、準拠するスキルが再チェックされます。
12
33
 
13
- 定義は[spec/musubi.ja.md](spec/musubi.ja.md)に在ります。
34
+ 定義は[spec/musubi.ja.md](spec/musubi.ja.md)にあります。
14
35
 
15
- ## スキルの加わり方
36
+ ## スキルが参加する方法
16
37
 
17
- スキルは`SKILL.md`をそのまま持ち、その横に`musubi.json`を足します。
18
- 出す側は、出す中身を並べます。
38
+ スキルは`SKILL.md`をそのまま持ち、その隣に`musubi.json`を追加します。
39
+ providerは、提供するコンテンツを並べます。
19
40
 
20
41
  ```json
21
42
  {
@@ -26,7 +47,7 @@ musubiでは、スキルが出す中身を名前と版で宣言し、別のス
26
47
  }
27
48
  ```
28
49
 
29
- 使う側は、従う中身と、従える版と、最後に確かめた中身の指紋を並べます。
50
+ consumerは、準拠するコンテンツと、受け入れるバージョンと、最後にチェックしたコンテンツのフィンガープリントを並べます。
30
51
 
31
52
  ```json
32
53
  {
@@ -41,15 +62,19 @@ musubiでは、スキルが出す中身を名前と版で宣言し、別のス
41
62
  }
42
63
  ```
43
64
 
44
- 使う側の`SKILL.md`の本文は、`design-doc`のスキルを名前で開いて`design`の書式を読むようエージェントに伝えます。
45
- そのため、エージェントは新しい仕組みを持たずに中身を読み込めます。
46
- 2つのスキルは[examples/skills](examples/skills)に在ります。
65
+ consumerの`SKILL.md`の本文は、`design-doc`のスキルを名前で開いて`design`の書式を読むよう、エージェントに伝えます。
66
+ そのため、エージェントは新しい仕組みがなくてもコンテンツを読み込めます。
67
+ providerが無くても動くconsumerは、定義のバージョン`2026-11-20`を書き、準拠に`"optional": true`を足します。
68
+ するとエージェントは、providerがインストールされていない時にそのコンテンツ無しで作業を続けます。
69
+ 定義のバージョン`2026-11-21`では、さらに`"when": { "languages": ["ja"] }`を足せます。
70
+ 足すと、`musubi install --lang ja`がconsumerと一緒にproviderもインストールします。
71
+ 2つのスキルは[examples/skills](examples/skills)にあります。
47
72
 
48
- ## 確かめ方
73
+ ## チェック
49
74
 
50
- `musubi`の命令は宣言を確かめ、出す側の検査を使う側の例に回します。
75
+ `musubi`コマンドは宣言をチェックし、providerのチェックをconsumerの例に適用します。
51
76
  Node.js 22.18以降で動き、実行時の依存を持ちません。
52
- npmには`musubi-cli`の名前で出ており、入れた後はプロジェクトのフォルダで回します。
77
+ npmに`musubi-cli`として公開しており、インストールした後はプロジェクトのフォルダで実行します。
53
78
 
54
79
  ```bash
55
80
  npm install -g musubi-cli
@@ -57,10 +82,10 @@ musubi check
57
82
  musubi graph --out graph.html
58
83
  ```
59
84
 
60
- フォルダを渡さない時、`musubi check`は今のフォルダとホームのフォルダの`.claude/skills`、`.agents/skills`、`.github/skills`、`.gemini/skills`を読みます。
61
- 入れずに1回だけ回す時は、`npx musubi-cli check <スキルのフォルダ>`を使います。
85
+ フォルダを指定しない時、`musubi check`はカレントフォルダとホームフォルダにある`.claude/skills`、`.agents/skills`、`.github/skills`、`.gemini/skills`を読みます。
86
+ インストールせずに1回だけ実行する時は、`npx musubi-cli check <スキルのフォルダ>`を使います。
62
87
 
63
- このrepoを手元に写して回す時は、先に開発の依存を入れます。
88
+ このリポジトリをクローンして実行する時は、先に開発用の依存をインストールします。
64
89
 
65
90
  ```bash
66
91
  pnpm install
@@ -68,12 +93,61 @@ node src/cli.ts check examples/skills
68
93
  node src/cli.ts graph examples/skills --out graph.html
69
94
  ```
70
95
 
96
+ ## 準拠するスキルと一緒にインストールする
97
+
98
+ `musubi install`は、スキルと、その`musubi.json`が準拠するスキルを、`--from`で名指したフォルダかgitのリポジトリからまとめてインストールします。
99
+
100
+ ```bash
101
+ musubi install convey --from https://github.com/example/skills --to .claude/skills --lang ja
102
+ ```
103
+
104
+ インストール元の中からフォルダ名でスキルを探し、そのフォルダを`--to`へコピーします。
105
+ `--to`が無い時は、カレントフォルダの`.claude/skills`、`.agents/skills`、`.github/skills`、`.gemini/skills`のうち最初に在るフォルダを使います。
106
+ 必須の準拠のproviderは必ずインストールします。
107
+ 任意の準拠のproviderは、`--with <スキル名>`で名指した時か、準拠が`when`に利用者の言語を書いていて、その言語を`--lang`で渡した時にインストールします。
108
+ インストール済みのスキルはそのまま残し、最後に`musubi check`を実行します。
109
+
110
+ ## サイトにスキルを載せる
111
+
112
+ musubiのサイトは、定義と、GitHubで見つけたスキルを表示します。
113
+ スキルごとに、提供するコンテンツと、準拠するコンテンツと、そのスキルに準拠しているスキルが載ります。
114
+ スキルを載せる時は、スキルを置いた公開リポジトリに、GitHubのリポジトリの画面のAboutの設定でトピック`musubi-skills`を付けます。
115
+ PRは要りません。
116
+
117
+ サイトは更新するたびに、トピック`musubi-skills`を持つ公開リポジトリをGitHubで検索し、デフォルトブランチで`musubi.json`と`SKILL.md`が並ぶフォルダを全て載せます。
118
+ `musubi check`と同じチェックに通らない`musubi.json`を持つフォルダは、サイトをビルドする時にフォルダ名と理由を表示し、一覧から外します。
119
+
120
+ 管理者のスキルは、リポジトリごとに`registry/<owner>/<repo>.json`というファイルにも置き、載せるフォルダをリポジトリのルートからの相対パスで並べます。
121
+
122
+ ```json
123
+ {
124
+ "skills": ["plugins/doc-formats/skills/design-doc", "plugins/evm-dev/skills/contract-design"]
125
+ }
126
+ ```
127
+
128
+ `registry/excluded.json`には、サイトに載せない物を書きます。
129
+ リポジトリ全体は`<owner>/<repo>`、1つのフォルダは`<owner>/<repo>/<folder>`の形で並べます。
130
+
131
+ ```json
132
+ {
133
+ "excluded": ["someone/repo", "someone/other-repo/skills/old-skill"]
134
+ }
135
+ ```
136
+
137
+ サイトをビルドして手元の<http://localhost:3810/>で開く時は、`gh auth login`でログインしてから`pnpm site`を実行します。
138
+ このコマンドは`node site/build.ts`で、ログインしたghを使ってGitHubを検索し、ページを`site/dist/`に書き出してから、そのフォルダを配信します。
139
+ 公開したサイトは<https://musubi.cardene.dev/>にあり、`pnpm site:publish`で公開する手順は[docs/publishing.ja.md](docs/publishing.ja.md)にあります。
140
+
71
141
  ## 文書
72
142
 
73
- | 文書 | 持つ物 |
143
+ | 文書 | 内容 |
74
144
  |---|---|
75
145
  | [spec/musubi.ja.md](spec/musubi.ja.md) | 定義 |
76
- | [GLOSSARY.ja.md](GLOSSARY.ja.md) | 定義が使う語 |
77
- | [docs/adr](docs/adr) | 戻すのが高くつく判断と、採らなかった案 |
146
+ | [GLOSSARY.ja.md](GLOSSARY.ja.md) | 定義が使う用語 |
147
+ | [docs/publishing.ja.md](docs/publishing.ja.md) | サイトをGitHub Pagesへ公開する手順 |
148
+ | [docs/adr](docs/adr) | 元に戻すのが高くつく判断と、採らなかった案 |
149
+
150
+ ## ライセンス
78
151
 
79
- English: [README.md](README.md)
152
+ musubiはMITライセンスで公開しています。
153
+ 全文は[LICENSE](LICENSE)にあります。
package/README.md CHANGED
@@ -1,4 +1,24 @@
1
- # musubi
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">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>
2
22
 
3
23
  musubi is a proposal for binding the content of one agent skill to another.
4
24
 
@@ -39,6 +59,8 @@ A consumer lists the content it follows, the versions it accepts, and the finger
39
59
  ```
40
60
 
41
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
+ With definition version `2026-11-21` it can also add `"when": { "languages": ["ja"] }`, so that `musubi install --lang ja` installs the provider with it.
42
64
  [examples/skills](examples/skills) holds both skills.
43
65
 
44
66
  ## Checking
@@ -64,12 +86,58 @@ node src/cli.ts check examples/skills
64
86
  node src/cli.ts graph examples/skills --out graph.html
65
87
  ```
66
88
 
89
+ ## Installing a skill with the skills it follows
90
+
91
+ `musubi install` installs a skill together with the skills its `musubi.json` follows, from a folder or a git repository you name with `--from`.
92
+
93
+ ```bash
94
+ musubi install convey --from https://github.com/example/skills --to .claude/skills --lang ja
95
+ ```
96
+
97
+ It finds each skill in the source by its folder name and copies the folder into `--to`.
98
+ Without `--to` it uses the first of `.claude/skills`, `.agents/skills`, `.github/skills`, and `.gemini/skills` in the current folder.
99
+ The provider of a required follow is always installed.
100
+ The provider of an optional follow is installed when you name it with `--with <skill>`, or when the follow lists your language in `when` and you give it with `--lang`.
101
+ Skills already installed are kept as they are, and `musubi check` runs at the end.
102
+
103
+ ## Listing a skill on the site
104
+
105
+ 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.
106
+ To list your skills, give their public repository the topic `musubi-skills` in the About settings of the repository page on GitHub.
107
+ No pull request is needed.
108
+
109
+ 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`.
110
+ A folder whose `musubi.json` fails the checks `musubi check` runs is named with the reason when the site is built, and left out.
111
+
112
+ 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.
113
+
114
+ ```json
115
+ {
116
+ "skills": ["plugins/doc-formats/skills/design-doc", "plugins/evm-dev/skills/contract-design"]
117
+ }
118
+ ```
119
+
120
+ `registry/excluded.json` names what the site leaves out: a whole repository as `<owner>/<repo>`, or one folder as `<owner>/<repo>/<folder>`.
121
+
122
+ ```json
123
+ {
124
+ "excluded": ["someone/repo", "someone/other-repo/skills/old-skill"]
125
+ }
126
+ ```
127
+
128
+ To build the site and open it on your machine at <http://localhost:3810/>, sign in with `gh auth login` and run `pnpm site`.
129
+ 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.
130
+ 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`.
131
+
67
132
  ## Documents
68
133
 
69
134
  | Document | Holds |
70
135
  |---|---|
71
136
  | [spec/musubi.md](spec/musubi.md) | The definition |
72
137
  | [GLOSSARY.md](GLOSSARY.md) | The terms the definition uses |
138
+ | [docs/publishing.md](docs/publishing.md) | How the site is published to GitHub Pages |
73
139
  | [docs/adr](docs/adr) | Decisions that are costly to reverse, with the options not taken |
74
140
 
75
- Japanese: [README.ja.md](README.ja.md)
141
+ ## License
142
+
143
+ musubi is released under the MIT License. The full text is in [LICENSE](LICENSE).
package/dist/add.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { basename, join } from "node:path";
3
3
  import { load } from "./check.js";
4
- import { latestDefinition } from "./definition.js";
4
+ import { definitionVersions, latestDefinition, optionalVersions, whenVersions } from "./definition.js";
5
5
  import { fingerprint } from "./fingerprint.js";
6
6
  import { isObject } from "./json.js";
7
7
  import { Report } from "./report.js";
@@ -10,20 +10,24 @@ import { fingerprintFiles } from "./skills.js";
10
10
  // Content files an agent runs rather than reads, told apart by their extension in any case.
11
11
  const SCRIPT = /\.(py|sh|bash|js|mjs|cjs|ts)$/i;
12
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}\`.`;
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}\`.`;
18
19
  return [
19
- use,
20
+ optional ? `When the \`${skill}\` skill is installed, ${how}` : how[0].toUpperCase() + how.slice(1),
20
21
  "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
+ 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.`,
22
25
  ];
23
26
  }
24
27
  // 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) {
28
+ // musubi.json and prints the lines to put in its SKILL.md body. The languages, given only with
29
+ // optional, become "when" of the follow.
30
+ export function add(ref, roots, cwd, optional = false, languages = []) {
27
31
  const report = new Report(cwd);
28
32
  const fail = (message) => {
29
33
  report.print();
@@ -52,17 +56,24 @@ export function add(ref, roots, cwd) {
52
56
  return fail("musubi.json holds something other than one JSON object");
53
57
  json = current;
54
58
  }
59
+ // The fields written need a definition version that knows them. A file whose version does not is
60
+ // moved to the earliest version that does, so that older musubi commands still read it.
61
+ const knows = (version) => typeof version === "string" && (!optional || optionalVersions.has(version)) && (languages.length === 0 || whenVersions.has(version));
62
+ if (!knows(json.musubi))
63
+ json.musubi = definitionVersions.find(knows) ?? latestDefinition;
55
64
  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] : {};
65
+ // Keep fields the consumer already wrote, such as examples, after the ones this command owns.
66
+ const { version: _version, integrity: _integrity, optional: _optional, when: _when, ...kept } = isObject(follows[ref]) ? follows[ref] : {};
58
67
  follows[ref] = {
59
68
  version: `^${format(provided.version)}`,
60
69
  integrity: fingerprint(provider.dir, fingerprintFiles(provided)),
70
+ ...(optional ? { optional: true } : {}),
71
+ ...(languages.length > 0 ? { when: { languages } } : {}),
61
72
  ...kept,
62
73
  };
63
74
  json.follows = follows;
64
75
  writeFileSync(path, `${JSON.stringify(json, null, 2)}\n`);
65
76
  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`);
77
+ process.stdout.write(`${bodyLines(skillName, content, provided.file, optional).join("\n")}\n`);
67
78
  return 0;
68
79
  }
package/dist/check.js CHANGED
@@ -56,6 +56,10 @@ export function check(roots, cwd, update) {
56
56
  for (const follow of declaration.follows) {
57
57
  follows += 1;
58
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
+ }
59
63
  if (!provider) {
60
64
  report.problem(declaration.path, follow.line, `${consumer} follows ${follow.ref}, but no skill named ${follow.skill} is installed`);
61
65
  continue;
package/dist/cli.js CHANGED
@@ -4,38 +4,58 @@ import { resolve } from "node:path";
4
4
  import { add } from "./add.js";
5
5
  import { check } from "./check.js";
6
6
  import { graph } from "./graph.js";
7
- import { defaultRoots } from "./skills.js";
7
+ import { install } from "./install.js";
8
+ import { defaultRoots, LANGUAGE_TAG } from "./skills.js";
8
9
  const USAGE = `usage:
9
10
  musubi check [<skills folder>...] [--update]
10
11
  Checks every musubi.json in the folders. Without folders it reads .claude/skills, .agents/skills,
11
12
  .github/skills, and .gemini/skills in this folder and in the home folder.
12
13
  --update rewrites a fingerprint after its content passes the check again.
13
- musubi add <skill>/<content> [<skills folder>...]
14
+ musubi add <skill>/<content> [<skills folder>...] [--optional [--lang <language>]...]
14
15
  Run in a skill's folder: makes the skill follow the content and prints the lines for its SKILL.md.
16
+ --optional makes the follow optional: the skill reads the content only when the provider is installed.
17
+ --lang writes the languages for which musubi install installs the provider of the optional follow.
18
+ musubi install <skill>... --from <folder or git URL>... [--to <skills folder>] [--with <skill>]... [--lang <language>]...
19
+ Installs the skills and the skills they follow, found by folder name in the sources, then runs musubi check.
20
+ Without --to it installs into the first of .claude/skills, .agents/skills, .github/skills, and
21
+ .gemini/skills in this folder. The provider of an optional follow is installed only when --with names
22
+ it or a --lang language matches the follow's "when".
15
23
  musubi graph [<skills folder>...] [--out <file>]
16
24
  Writes an HTML page of the skills and the contents they follow (default musubi-graph.html).
17
25
  `;
26
+ // The options each command takes: flags stand alone, and the others take the word after them.
27
+ const FLAGS = { check: ["--update"], add: ["--optional"] };
28
+ const VALUES = { add: ["--lang"], install: ["--from", "--to", "--with", "--lang"], graph: ["--out"] };
18
29
  function main(argv) {
19
30
  const [command, ...rest] = argv;
31
+ if (command === "--help" || command === "-h") {
32
+ process.stdout.write(USAGE);
33
+ return 0;
34
+ }
20
35
  const cwd = process.cwd();
21
- const flags = new Set(rest.filter((arg) => arg.startsWith("--")));
36
+ const flags = new Set();
37
+ const values = new Map();
22
38
  const positional = [];
23
- let out = "musubi-graph.html";
24
39
  for (let i = 0; i < rest.length; i += 1) {
25
- if (rest[i] === "--out") {
26
- out = rest[i + 1] ?? "";
40
+ const arg = rest[i];
41
+ if (!arg.startsWith("--"))
42
+ positional.push(arg);
43
+ else if (FLAGS[command]?.includes(arg))
44
+ flags.add(arg);
45
+ else if (VALUES[command]?.includes(arg) && rest[i + 1] !== undefined && !rest[i + 1].startsWith("--") && rest[i + 1] !== "") {
46
+ values.set(arg, [...(values.get(arg) ?? []), rest[i + 1]]);
27
47
  i += 1;
28
48
  }
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;
49
+ else {
50
+ process.stderr.write(`musubi: unknown or incomplete option ${arg}\n${USAGE}`);
51
+ return 2;
52
+ }
36
53
  }
37
- if (unknown.length > 0 || (command === "graph" && out === "")) {
38
- process.stderr.write(`musubi: unknown or incomplete option ${unknown[0] ?? "--out"}\n${USAGE}`);
54
+ const all = (option) => values.get(option) ?? [];
55
+ const last = (option) => all(option).at(-1);
56
+ const badTag = all("--lang").find((tag) => !LANGUAGE_TAG.test(tag));
57
+ if (badTag !== undefined) {
58
+ process.stderr.write(`musubi: --lang takes a language tag such as ja or ja-JP, not "${badTag}"\n`);
39
59
  return 2;
40
60
  }
41
61
  const roots = (given, extra = []) => given.length > 0 ? given.map((r) => resolve(cwd, r)) : [...extra, ...defaultRoots(cwd, homedir())];
@@ -46,10 +66,30 @@ function main(argv) {
46
66
  const [ref, ...given] = positional;
47
67
  if (!ref)
48
68
  break;
49
- return add(ref, roots(given, [resolve(cwd, "..")]), cwd);
69
+ if (all("--lang").length > 0 && !flags.has("--optional")) {
70
+ process.stderr.write("musubi add: --lang needs --optional, because only an optional follow names languages\n");
71
+ return 2;
72
+ }
73
+ return add(ref, roots(given, [resolve(cwd, "..")]), cwd, flags.has("--optional"), all("--lang"));
50
74
  }
75
+ case "install":
76
+ if (positional.length === 0)
77
+ break;
78
+ if (all("--from").length === 0) {
79
+ process.stderr.write("musubi install: name at least one source with --from, a folder or a git URL\n");
80
+ return 2;
81
+ }
82
+ return install({
83
+ names: positional,
84
+ sources: all("--from"),
85
+ to: last("--to") ?? null,
86
+ with: all("--with"),
87
+ languages: all("--lang"),
88
+ cwd,
89
+ home: homedir(),
90
+ });
51
91
  case "graph":
52
- return graph(roots(positional), resolve(cwd, out), cwd);
92
+ return graph(roots(positional), resolve(cwd, last("--out") ?? "musubi-graph.html"), cwd);
53
93
  }
54
94
  process.stderr.write(USAGE);
55
95
  return 2;
@@ -1,4 +1,4 @@
1
- import { readdirSync } from "node:fs";
1
+ import { readdirSync, readFileSync } from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
3
  // The definition versions this command reads are the dated folders under schema/, so the dates
4
4
  // live in one place. The folder sits next to src/ in the repository and next to dist/ when installed.
@@ -7,5 +7,17 @@ export const definitionVersions = readdirSync(schemaDir)
7
7
  .filter((name) => /^\d{4}-\d{2}-\d{2}$/.test(name))
8
8
  .sort();
9
9
  export const latestDefinition = definitionVersions[definitionVersions.length - 1];
10
+ // The definition versions whose schema lets a follow carry a field, read from the schemas so that
11
+ // no date is written in the code.
12
+ function versionsKnowing(field) {
13
+ return new Set(definitionVersions.filter((version) => {
14
+ const schema = JSON.parse(readFileSync(`${schemaDir}${version}/musubi.schema.json`, "utf8"));
15
+ return schema?.$defs?.followed?.properties?.[field] !== undefined;
16
+ }));
17
+ }
18
+ // "optional" makes a follow optional (decision record 0007), and "when" names the languages for
19
+ // which musubi install installs the provider of an optional follow (decision record 0009).
20
+ export const optionalVersions = versionsKnowing("optional");
21
+ export const whenVersions = versionsKnowing("when");
10
22
  // Agents read a content file whole; Agent Skills suggests keeping SKILL.md under this many lines.
11
23
  export const READ_LINES = 500;