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/dist/json.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// A JSON reader that remembers the line of every key, so problems can name the file and line.
|
|
2
|
+
export class JsonError extends Error {
|
|
3
|
+
line;
|
|
4
|
+
constructor(message, line) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.line = line;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function pointer(...keys) {
|
|
10
|
+
return keys.map((key) => `/${key.replace(/~/g, "~0").replace(/\//g, "~1")}`).join("");
|
|
11
|
+
}
|
|
12
|
+
export function parseLocated(text) {
|
|
13
|
+
let i = 0;
|
|
14
|
+
let line = 1;
|
|
15
|
+
const lines = new Map([["", 1]]);
|
|
16
|
+
const fail = (message) => {
|
|
17
|
+
throw new JsonError(message, line);
|
|
18
|
+
};
|
|
19
|
+
const space = () => {
|
|
20
|
+
while (i < text.length) {
|
|
21
|
+
const c = text[i];
|
|
22
|
+
if (c === "\n") {
|
|
23
|
+
line += 1;
|
|
24
|
+
i += 1;
|
|
25
|
+
}
|
|
26
|
+
else if (c === " " || c === "\t" || c === "\r") {
|
|
27
|
+
i += 1;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const string = () => {
|
|
35
|
+
const start = i;
|
|
36
|
+
i += 1;
|
|
37
|
+
while (i < text.length && text[i] !== '"') {
|
|
38
|
+
if (text[i] === "\n")
|
|
39
|
+
fail("a string runs past the end of the line");
|
|
40
|
+
i += text[i] === "\\" ? 2 : 1;
|
|
41
|
+
}
|
|
42
|
+
if (i >= text.length)
|
|
43
|
+
fail("a string is not closed");
|
|
44
|
+
i += 1;
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(text.slice(start, i));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return fail("a string has an invalid escape");
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const value = (at) => {
|
|
53
|
+
space();
|
|
54
|
+
const c = text[i];
|
|
55
|
+
if (c === "{") {
|
|
56
|
+
i += 1;
|
|
57
|
+
const object = {};
|
|
58
|
+
space();
|
|
59
|
+
if (text[i] === "}") {
|
|
60
|
+
i += 1;
|
|
61
|
+
return object;
|
|
62
|
+
}
|
|
63
|
+
for (;;) {
|
|
64
|
+
space();
|
|
65
|
+
if (text[i] !== '"')
|
|
66
|
+
fail("expected a key in double quotes");
|
|
67
|
+
const keyLine = line;
|
|
68
|
+
const key = string();
|
|
69
|
+
if (Object.hasOwn(object, key))
|
|
70
|
+
fail(`the key "${key}" appears twice`);
|
|
71
|
+
space();
|
|
72
|
+
if (text[i] !== ":")
|
|
73
|
+
fail(`expected ":" after "${key}"`);
|
|
74
|
+
i += 1;
|
|
75
|
+
const child = at + pointer(key);
|
|
76
|
+
lines.set(child, keyLine);
|
|
77
|
+
object[key] = value(child);
|
|
78
|
+
space();
|
|
79
|
+
if (text[i] === ",") {
|
|
80
|
+
i += 1;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (text[i] === "}") {
|
|
84
|
+
i += 1;
|
|
85
|
+
return object;
|
|
86
|
+
}
|
|
87
|
+
fail('expected "," or "}"');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (c === "[") {
|
|
91
|
+
i += 1;
|
|
92
|
+
const array = [];
|
|
93
|
+
space();
|
|
94
|
+
if (text[i] === "]") {
|
|
95
|
+
i += 1;
|
|
96
|
+
return array;
|
|
97
|
+
}
|
|
98
|
+
for (;;) {
|
|
99
|
+
space();
|
|
100
|
+
const child = `${at}/${array.length}`;
|
|
101
|
+
lines.set(child, line);
|
|
102
|
+
array.push(value(child));
|
|
103
|
+
space();
|
|
104
|
+
if (text[i] === ",") {
|
|
105
|
+
i += 1;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (text[i] === "]") {
|
|
109
|
+
i += 1;
|
|
110
|
+
return array;
|
|
111
|
+
}
|
|
112
|
+
fail('expected "," or "]"');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (c === '"')
|
|
116
|
+
return string();
|
|
117
|
+
const literal = /^(?:-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null)/.exec(text.slice(i));
|
|
118
|
+
if (!literal)
|
|
119
|
+
return fail("expected a value");
|
|
120
|
+
i += literal[0].length;
|
|
121
|
+
return JSON.parse(literal[0]);
|
|
122
|
+
};
|
|
123
|
+
const result = value("");
|
|
124
|
+
space();
|
|
125
|
+
if (i < text.length)
|
|
126
|
+
fail("unexpected text after the JSON value");
|
|
127
|
+
return { value: result, lines };
|
|
128
|
+
}
|
|
129
|
+
export function isObject(value) {
|
|
130
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
131
|
+
}
|
package/dist/report.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
// Collects problems as `<file>:<line>: <message>` and warnings, with paths relative to the
|
|
3
|
+
// folder the command runs in.
|
|
4
|
+
export class Report {
|
|
5
|
+
problems = [];
|
|
6
|
+
warnings = [];
|
|
7
|
+
cwd;
|
|
8
|
+
constructor(cwd) {
|
|
9
|
+
this.cwd = cwd;
|
|
10
|
+
}
|
|
11
|
+
problem(file, line, message) {
|
|
12
|
+
this.problems.push({ file, line, message });
|
|
13
|
+
}
|
|
14
|
+
warn(message) {
|
|
15
|
+
this.warnings.push(message);
|
|
16
|
+
}
|
|
17
|
+
where(file) {
|
|
18
|
+
return relative(this.cwd, file) || file;
|
|
19
|
+
}
|
|
20
|
+
print() {
|
|
21
|
+
for (const warning of this.warnings)
|
|
22
|
+
process.stderr.write(`warning: ${warning}\n`);
|
|
23
|
+
for (const p of this.problems)
|
|
24
|
+
process.stderr.write(`${this.where(p.file)}:${p.line}: ${p.message}\n`);
|
|
25
|
+
}
|
|
26
|
+
}
|
package/dist/rules.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { definitionVersions } from "./definition.js";
|
|
3
|
+
import { isObject, JsonError, parseLocated, pointer } from "./json.js";
|
|
4
|
+
const FIELDS = {
|
|
5
|
+
headings: { headings: "strings" },
|
|
6
|
+
forbid: { text: "strings" },
|
|
7
|
+
"table-columns": { heading: "string", columns: "strings" },
|
|
8
|
+
};
|
|
9
|
+
// Reads and validates a rules file, reporting each mistake at its line. Returns null when it is unusable.
|
|
10
|
+
export function readRules(path, report) {
|
|
11
|
+
let located;
|
|
12
|
+
try {
|
|
13
|
+
located = parseLocated(readFileSync(path, "utf8"));
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error instanceof JsonError)
|
|
17
|
+
report.problem(path, error.line, `not valid JSON: ${error.message}`);
|
|
18
|
+
else
|
|
19
|
+
report.problem(path, 1, "the check file cannot be read");
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const { value, lines } = located;
|
|
23
|
+
const at = (...keys) => lines.get(pointer(...keys)) ?? 1;
|
|
24
|
+
if (!isObject(value)) {
|
|
25
|
+
report.problem(path, 1, "a check file holds one JSON object");
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
let usable = true;
|
|
29
|
+
for (const key of Object.keys(value)) {
|
|
30
|
+
if (key !== "$schema" && key !== "musubi" && key !== "rules") {
|
|
31
|
+
report.problem(path, at(key), `unknown field "${key}"`);
|
|
32
|
+
usable = false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (typeof value.musubi !== "string" || !definitionVersions.includes(value.musubi)) {
|
|
36
|
+
report.problem(path, at("musubi"), `"musubi" must name a definition version (${definitionVersions.join(", ")})`);
|
|
37
|
+
usable = false;
|
|
38
|
+
}
|
|
39
|
+
if (!Array.isArray(value.rules)) {
|
|
40
|
+
report.problem(path, at("rules"), '"rules" must be a list of rules');
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const rules = [];
|
|
44
|
+
value.rules.forEach((rule, index) => {
|
|
45
|
+
const line = lines.get(`/rules/${index}`) ?? 1;
|
|
46
|
+
if (!isObject(rule) || typeof rule.kind !== "string" || !(rule.kind in FIELDS)) {
|
|
47
|
+
report.problem(path, line, `rule ${index + 1} has no known "kind" (${Object.keys(FIELDS).join(", ")})`);
|
|
48
|
+
usable = false;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const fields = FIELDS[rule.kind];
|
|
52
|
+
for (const key of Object.keys(rule)) {
|
|
53
|
+
if (key !== "kind" && !(key in fields)) {
|
|
54
|
+
report.problem(path, lines.get(`/rules/${index}${pointer(key)}`) ?? line, `rule ${index + 1} has an unknown field "${key}"`);
|
|
55
|
+
usable = false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const [key, type] of Object.entries(fields)) {
|
|
59
|
+
const field = rule[key];
|
|
60
|
+
const ok = type === "string"
|
|
61
|
+
? typeof field === "string" && field !== ""
|
|
62
|
+
: Array.isArray(field) && field.length > 0 && field.every((item) => typeof item === "string" && item !== "");
|
|
63
|
+
if (!ok) {
|
|
64
|
+
report.problem(path, line, `rule ${index + 1} needs "${key}" as ${type === "string" ? "text" : "a list of text"}`);
|
|
65
|
+
usable = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
rules.push(rule);
|
|
69
|
+
});
|
|
70
|
+
return usable ? rules : null;
|
|
71
|
+
}
|
|
72
|
+
// Lines outside fenced code blocks, with their 1-based numbers.
|
|
73
|
+
function prose(text) {
|
|
74
|
+
let fenced = false;
|
|
75
|
+
const out = [];
|
|
76
|
+
text.split("\n").forEach((raw, index) => {
|
|
77
|
+
const line = raw.replace(/\s+$/, "");
|
|
78
|
+
if (line.startsWith("```") || line.startsWith("~~~")) {
|
|
79
|
+
fenced = !fenced;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!fenced)
|
|
83
|
+
out.push({ number: index + 1, text: line });
|
|
84
|
+
});
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
const level = (text) => /^(#{1,6}) /.exec(text)?.[1].length ?? 0;
|
|
88
|
+
function cells(row) {
|
|
89
|
+
return row
|
|
90
|
+
.replace(/^\|/, "")
|
|
91
|
+
.replace(/\|$/, "")
|
|
92
|
+
.split("|")
|
|
93
|
+
.map((cell) => cell.trim());
|
|
94
|
+
}
|
|
95
|
+
// Applies the rules to one example. Sections the consumer added are skipped, because each rule
|
|
96
|
+
// looks only for what it requires.
|
|
97
|
+
export function applyRules(rules, text) {
|
|
98
|
+
const lines = prose(text);
|
|
99
|
+
const findings = [];
|
|
100
|
+
for (const rule of rules) {
|
|
101
|
+
if (rule.kind === "headings") {
|
|
102
|
+
let previous = null;
|
|
103
|
+
for (const heading of rule.headings) {
|
|
104
|
+
const found = lines.find((line) => line.text === heading);
|
|
105
|
+
if (!found) {
|
|
106
|
+
findings.push({ line: previous?.line ?? 1, message: `the heading "${heading}" is missing` });
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (previous && found.number < previous.line) {
|
|
110
|
+
findings.push({ line: found.number, message: `the heading "${heading}" must come after "${previous.heading}"` });
|
|
111
|
+
}
|
|
112
|
+
previous = { heading, line: found.number };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (rule.kind === "forbid") {
|
|
116
|
+
for (const needle of rule.text) {
|
|
117
|
+
for (const line of lines) {
|
|
118
|
+
if (line.text.includes(needle))
|
|
119
|
+
findings.push({ line: line.number, message: `"${needle}" must not remain` });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const start = lines.findIndex((line) => line.text === rule.heading);
|
|
125
|
+
if (start === -1) {
|
|
126
|
+
findings.push({ line: 1, message: `no heading "${rule.heading}" to hold the table` });
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const depth = level(rule.heading);
|
|
130
|
+
const section = [];
|
|
131
|
+
for (const line of lines.slice(start + 1)) {
|
|
132
|
+
const l = level(line.text);
|
|
133
|
+
if (l > 0 && l <= depth)
|
|
134
|
+
break;
|
|
135
|
+
section.push(line);
|
|
136
|
+
}
|
|
137
|
+
const header = section.findIndex((line, i) => line.text.startsWith("|") && /^\|[-:| ]+\|$/.test(section[i + 1]?.text ?? ""));
|
|
138
|
+
if (header === -1) {
|
|
139
|
+
findings.push({ line: lines[start].number, message: `no table under "${rule.heading}"` });
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const have = cells(section[header].text);
|
|
143
|
+
for (const column of rule.columns) {
|
|
144
|
+
if (!have.includes(column)) {
|
|
145
|
+
findings.push({
|
|
146
|
+
line: section[header].number,
|
|
147
|
+
message: `the table under "${rule.heading}" has no column "${column}"`,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return findings;
|
|
154
|
+
}
|
package/dist/semver.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Content versions are MAJOR.MINOR.PATCH, and ranges are `^X.Y.Z`, `~X.Y.Z`, or an exact `X.Y.Z`,
|
|
2
|
+
// read the way npm reads them.
|
|
3
|
+
const VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
4
|
+
export function parseVersion(text) {
|
|
5
|
+
const match = VERSION.exec(text);
|
|
6
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
7
|
+
}
|
|
8
|
+
export function parseRange(text) {
|
|
9
|
+
const operator = text.startsWith("^") || text.startsWith("~") ? text[0] : "";
|
|
10
|
+
const min = parseVersion(text.slice(operator.length));
|
|
11
|
+
if (!min)
|
|
12
|
+
return null;
|
|
13
|
+
const [major, minor, patch] = min;
|
|
14
|
+
let below;
|
|
15
|
+
if (operator === "^") {
|
|
16
|
+
if (major > 0)
|
|
17
|
+
below = [major + 1, 0, 0];
|
|
18
|
+
else if (minor > 0)
|
|
19
|
+
below = [0, minor + 1, 0];
|
|
20
|
+
else
|
|
21
|
+
below = [0, 0, patch + 1];
|
|
22
|
+
}
|
|
23
|
+
else if (operator === "~") {
|
|
24
|
+
below = [major, minor + 1, 0];
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
below = [major, minor, patch + 1];
|
|
28
|
+
}
|
|
29
|
+
return { text, min, below };
|
|
30
|
+
}
|
|
31
|
+
function compare(a, b) {
|
|
32
|
+
for (let i = 0; i < 3; i += 1)
|
|
33
|
+
if (a[i] !== b[i])
|
|
34
|
+
return a[i] - b[i];
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
export function satisfies(version, range) {
|
|
38
|
+
return compare(version, range.min) >= 0 && compare(version, range.below) < 0;
|
|
39
|
+
}
|
|
40
|
+
export function format(version) {
|
|
41
|
+
return version.join(".");
|
|
42
|
+
}
|
package/dist/skills.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
3
|
+
import { definitionVersions } from "./definition.js";
|
|
4
|
+
import { INTEGRITY } from "./fingerprint.js";
|
|
5
|
+
import { isObject, JsonError, parseLocated, pointer } from "./json.js";
|
|
6
|
+
import { readRules } from "./rules.js";
|
|
7
|
+
import { parseRange, parseVersion } from "./semver.js";
|
|
8
|
+
// The folders the agents read skills from, in the project and in the home folder.
|
|
9
|
+
const FOLDERS = [".claude/skills", ".agents/skills", ".github/skills", ".gemini/skills"];
|
|
10
|
+
export function defaultRoots(cwd, home) {
|
|
11
|
+
return [cwd, home].flatMap((base) => FOLDERS.map((folder) => resolve(base, folder)));
|
|
12
|
+
}
|
|
13
|
+
// Every folder directly under a root that holds a SKILL.md is a skill, named by its folder.
|
|
14
|
+
// When two roots hold the same name, the first root wins, as it does for the agents.
|
|
15
|
+
export function discover(roots, report) {
|
|
16
|
+
const skills = new Map();
|
|
17
|
+
const seen = new Set();
|
|
18
|
+
for (const root of roots.map((r) => resolve(r))) {
|
|
19
|
+
if (seen.has(root) || !existsSync(root) || !statSync(root).isDirectory())
|
|
20
|
+
continue;
|
|
21
|
+
seen.add(root);
|
|
22
|
+
for (const name of readdirSync(root).sort()) {
|
|
23
|
+
const dir = join(root, name);
|
|
24
|
+
if (!existsSync(join(dir, "SKILL.md")))
|
|
25
|
+
continue;
|
|
26
|
+
const first = skills.get(name);
|
|
27
|
+
if (first) {
|
|
28
|
+
report.warn(`${report.where(dir)} is shadowed by ${report.where(first.dir)}, which has the same name`);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
skills.set(name, { name, dir });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return skills;
|
|
35
|
+
}
|
|
36
|
+
const TOP = new Set(["$schema", "musubi", "provides", "follows"]);
|
|
37
|
+
const PROVIDED = new Set(["version", "file", "check"]);
|
|
38
|
+
const FOLLOWED = new Set(["version", "integrity", "examples"]);
|
|
39
|
+
const REF = /^[a-z0-9]+(?:-[a-z0-9]+)*\/[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
40
|
+
// A path written in musubi.json must name a file inside the skill's own folder.
|
|
41
|
+
function inside(skill, path) {
|
|
42
|
+
if (typeof path !== "string" || path === "" || isAbsolute(path))
|
|
43
|
+
return null;
|
|
44
|
+
const full = resolve(skill.dir, path);
|
|
45
|
+
const rel = relative(skill.dir, full);
|
|
46
|
+
return rel.startsWith("..") || isAbsolute(rel) ? null : rel.split("\\").join("/");
|
|
47
|
+
}
|
|
48
|
+
// Reads a skill's musubi.json and reports every mistake in it at its line.
|
|
49
|
+
export function readDeclaration(skill, report) {
|
|
50
|
+
const path = join(skill.dir, "musubi.json");
|
|
51
|
+
if (!existsSync(path))
|
|
52
|
+
return null;
|
|
53
|
+
const text = readFileSync(path, "utf8");
|
|
54
|
+
const declaration = { skill, path, text, provides: new Map(), follows: [] };
|
|
55
|
+
let located;
|
|
56
|
+
try {
|
|
57
|
+
located = parseLocated(text);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
report.problem(path, error instanceof JsonError ? error.line : 1, `not valid JSON: ${error.message}`);
|
|
61
|
+
return declaration;
|
|
62
|
+
}
|
|
63
|
+
const { value, lines } = located;
|
|
64
|
+
const at = (...keys) => lines.get(pointer(...keys)) ?? 1;
|
|
65
|
+
if (!isObject(value)) {
|
|
66
|
+
report.problem(path, 1, "musubi.json holds one JSON object");
|
|
67
|
+
return declaration;
|
|
68
|
+
}
|
|
69
|
+
for (const key of Object.keys(value))
|
|
70
|
+
if (!TOP.has(key))
|
|
71
|
+
report.problem(path, at(key), `unknown field "${key}"`);
|
|
72
|
+
if (typeof value.musubi !== "string" || !definitionVersions.includes(value.musubi)) {
|
|
73
|
+
const named = typeof value.musubi === "string" ? ` "${value.musubi}" is not one of them` : "";
|
|
74
|
+
report.problem(path, at("musubi"), `"musubi" must name a definition version (${definitionVersions.join(", ")});${named}`);
|
|
75
|
+
}
|
|
76
|
+
if (value.provides !== undefined) {
|
|
77
|
+
if (!isObject(value.provides))
|
|
78
|
+
report.problem(path, at("provides"), '"provides" must map content names to entries');
|
|
79
|
+
else {
|
|
80
|
+
for (const [name, entry] of Object.entries(value.provides)) {
|
|
81
|
+
const line = at("provides", name);
|
|
82
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name))
|
|
83
|
+
report.problem(path, line, `the content name "${name}" must be lowercase words joined by "-"`);
|
|
84
|
+
if (!isObject(entry)) {
|
|
85
|
+
report.problem(path, line, `"${name}" must be an object with "version" and "file"`);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
for (const key of Object.keys(entry))
|
|
89
|
+
if (!PROVIDED.has(key))
|
|
90
|
+
report.problem(path, at("provides", name, key), `unknown field "${key}" in "${name}"`);
|
|
91
|
+
const version = typeof entry.version === "string" ? parseVersion(entry.version) : null;
|
|
92
|
+
const versionLine = lines.get(pointer("provides", name, "version")) ?? line;
|
|
93
|
+
if (!version)
|
|
94
|
+
report.problem(path, versionLine, `the version of "${name}" must be MAJOR.MINOR.PATCH, such as 1.0.0`);
|
|
95
|
+
const file = inside(skill, entry.file);
|
|
96
|
+
if (!file)
|
|
97
|
+
report.problem(path, at("provides", name, "file"), `the file of "${name}" must be a path inside the skill folder`);
|
|
98
|
+
else if (!existsSync(join(skill.dir, file)))
|
|
99
|
+
report.problem(path, at("provides", name, "file"), `the file "${file}" of "${name}" does not exist`);
|
|
100
|
+
let check = null;
|
|
101
|
+
let rules = null;
|
|
102
|
+
if (entry.check !== undefined) {
|
|
103
|
+
const checkLine = at("provides", name, "check");
|
|
104
|
+
check = inside(skill, entry.check);
|
|
105
|
+
if (!check)
|
|
106
|
+
report.problem(path, checkLine, `the check of "${name}" must be a path inside the skill folder`);
|
|
107
|
+
else if (!check.endsWith(".json")) {
|
|
108
|
+
report.problem(path, checkLine, `the check of "${name}" must be a JSON rules file; musubi never runs provider code`);
|
|
109
|
+
check = null;
|
|
110
|
+
}
|
|
111
|
+
else if (!existsSync(join(skill.dir, check))) {
|
|
112
|
+
report.problem(path, checkLine, `the check "${check}" of "${name}" does not exist`);
|
|
113
|
+
check = null;
|
|
114
|
+
}
|
|
115
|
+
else
|
|
116
|
+
rules = readRules(join(skill.dir, check), report);
|
|
117
|
+
}
|
|
118
|
+
declaration.provides.set(name, { name, version, file: file && existsSync(join(skill.dir, file)) ? file : null, check, rules, line, versionLine });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (value.follows !== undefined) {
|
|
123
|
+
if (!isObject(value.follows))
|
|
124
|
+
report.problem(path, at("follows"), '"follows" must map "skill/content" names to entries');
|
|
125
|
+
else {
|
|
126
|
+
for (const [ref, entry] of Object.entries(value.follows)) {
|
|
127
|
+
const line = at("follows", ref);
|
|
128
|
+
if (!REF.test(ref)) {
|
|
129
|
+
report.problem(path, line, `"${ref}" must name a content as "<skill>/<content>"`);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (!isObject(entry)) {
|
|
133
|
+
report.problem(path, line, `"${ref}" must be an object with "version" and "integrity"`);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
for (const key of Object.keys(entry))
|
|
137
|
+
if (!FOLLOWED.has(key))
|
|
138
|
+
report.problem(path, at("follows", ref, key), `unknown field "${key}" in "${ref}"`);
|
|
139
|
+
const versionLine = lines.get(pointer("follows", ref, "version")) ?? line;
|
|
140
|
+
const range = typeof entry.version === "string" ? parseRange(entry.version) : null;
|
|
141
|
+
if (!range)
|
|
142
|
+
report.problem(path, versionLine, `the version range of "${ref}" must be ^X.Y.Z, ~X.Y.Z, or X.Y.Z`);
|
|
143
|
+
const integrityLine = lines.get(pointer("follows", ref, "integrity")) ?? line;
|
|
144
|
+
const integrity = typeof entry.integrity === "string" && INTEGRITY.test(entry.integrity) ? entry.integrity : null;
|
|
145
|
+
if (!integrity)
|
|
146
|
+
report.problem(path, integrityLine, `the fingerprint of "${ref}" must be sha256-<base64>; run musubi add to write it`);
|
|
147
|
+
const examples = [];
|
|
148
|
+
if (entry.examples !== undefined) {
|
|
149
|
+
if (!Array.isArray(entry.examples))
|
|
150
|
+
report.problem(path, at("follows", ref, "examples"), `"examples" of "${ref}" must be a list of paths`);
|
|
151
|
+
else {
|
|
152
|
+
entry.examples.forEach((example, index) => {
|
|
153
|
+
const exampleLine = lines.get(`${pointer("follows", ref, "examples")}/${index}`) ?? line;
|
|
154
|
+
const file = inside(skill, example);
|
|
155
|
+
if (!file)
|
|
156
|
+
report.problem(path, exampleLine, `the example "${String(example)}" must be a path inside the skill folder`);
|
|
157
|
+
else if (!existsSync(join(skill.dir, file)))
|
|
158
|
+
report.problem(path, exampleLine, `the example "${file}" does not exist`);
|
|
159
|
+
else
|
|
160
|
+
examples.push(file);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const [skillName, content] = ref.split("/");
|
|
165
|
+
declaration.follows.push({ ref, skill: skillName, content, range, integrity, examples, line, versionLine, integrityLine });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return declaration;
|
|
170
|
+
}
|
|
171
|
+
// The files a fingerprint covers, in the order the definition fixes.
|
|
172
|
+
export function fingerprintFiles(provided) {
|
|
173
|
+
return ["SKILL.md", provided.file ?? "", ...(provided.check ? [provided.check] : [])];
|
|
174
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "musubi-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Binds the content one agent skill provides to the skills that follow it, and checks them again when that content changes",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agent-skills",
|
|
7
|
+
"skills",
|
|
8
|
+
"SKILL.md",
|
|
9
|
+
"dependencies"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/cardene777/musubi.git"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"bin": {
|
|
18
|
+
"musubi": "dist/cli.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"schema",
|
|
23
|
+
"spec",
|
|
24
|
+
"README.md",
|
|
25
|
+
"README.ja.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22.18"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.build.json",
|
|
33
|
+
"test": "node --test --test-reporter=tap tests/*.test.ts",
|
|
34
|
+
"prepack": "tsc -p tsconfig.build.json"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^24.0.0",
|
|
38
|
+
"ajv": "^8.17.1",
|
|
39
|
+
"typescript": "^5.9.2"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "check.schema.json",
|
|
4
|
+
"title": "musubi check rules",
|
|
5
|
+
"description": "The rules a provider skill's check holds. musubi check reads them and never runs provider code.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["musubi", "rules"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"$schema": { "type": "string" },
|
|
11
|
+
"musubi": { "const": "2026-11-19" },
|
|
12
|
+
"rules": {
|
|
13
|
+
"type": "array",
|
|
14
|
+
"minItems": 1,
|
|
15
|
+
"items": {
|
|
16
|
+
"oneOf": [
|
|
17
|
+
{
|
|
18
|
+
"type": "object",
|
|
19
|
+
"additionalProperties": false,
|
|
20
|
+
"required": ["kind", "headings"],
|
|
21
|
+
"properties": {
|
|
22
|
+
"kind": { "const": "headings" },
|
|
23
|
+
"headings": {
|
|
24
|
+
"type": "array",
|
|
25
|
+
"minItems": 1,
|
|
26
|
+
"description": "Heading lines that must appear, in this order. Other headings may come between them.",
|
|
27
|
+
"items": { "type": "string", "minLength": 1 }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "object",
|
|
33
|
+
"additionalProperties": false,
|
|
34
|
+
"required": ["kind", "text"],
|
|
35
|
+
"properties": {
|
|
36
|
+
"kind": { "const": "forbid" },
|
|
37
|
+
"text": {
|
|
38
|
+
"type": "array",
|
|
39
|
+
"minItems": 1,
|
|
40
|
+
"description": "Text that must not remain outside code blocks.",
|
|
41
|
+
"items": { "type": "string", "minLength": 1 }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"type": "object",
|
|
47
|
+
"additionalProperties": false,
|
|
48
|
+
"required": ["kind", "heading", "columns"],
|
|
49
|
+
"properties": {
|
|
50
|
+
"kind": { "const": "table-columns" },
|
|
51
|
+
"heading": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"minLength": 1,
|
|
54
|
+
"description": "The heading line whose first table is checked."
|
|
55
|
+
},
|
|
56
|
+
"columns": {
|
|
57
|
+
"type": "array",
|
|
58
|
+
"minItems": 1,
|
|
59
|
+
"description": "Columns the table must have. It may have more.",
|
|
60
|
+
"items": { "type": "string", "minLength": 1 }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|