musubix7 0.1.0 → 0.1.2
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/.github/skills/existing-code-requirements/LICENSE +21 -0
- package/.github/skills/existing-code-requirements/SKILL.md +74 -0
- package/.github/skills/sdd-tdd/LICENSE +21 -0
- package/.github/skills/sdd-tdd/SKILL.md +20 -8
- package/.github/skills/sdd-tdd/references/contracts.md +33 -0
- package/.github/skills/sdd-tdd/references/helpers.md +63 -0
- package/.github/skills/sdd-tdd/references/interview.md +1 -1
- package/.github/skills/sdd-tdd/references/orca-handoff.md +108 -0
- package/.github/skills/sdd-tdd/references/verification.md +4 -0
- package/.github/skills/sdd-tdd/references/workflow.md +24 -0
- package/.github/skills/sdd-tdd/scripts/context.mjs +79 -0
- package/.github/skills/sdd-tdd/scripts/contract.mjs +102 -0
- package/.github/skills/sdd-tdd/scripts/evidence.mjs +4 -4
- package/.github/skills/sdd-tdd/scripts/install.mjs +201 -0
- package/.github/skills/sdd-tdd/scripts/tdd.mjs +52 -0
- package/LICENSE +21 -0
- package/README-ja.md +191 -0
- package/README.md +180 -65
- package/bin/musubix.mjs +19 -0
- package/package.json +19 -8
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { inside, isObject, nonempty, snapshot, validId } from './evidence.mjs';
|
|
6
|
+
|
|
7
|
+
const digest = (data) => createHash('sha256').update(data).digest('hex');
|
|
8
|
+
export const requireThat = (condition, message) => { if (!condition) throw new Error(message); };
|
|
9
|
+
const uniqueList = (list) => Array.isArray(list) && list.length > 0 &&
|
|
10
|
+
list.every(nonempty) && new Set(list).size === list.length;
|
|
11
|
+
const decision = (value) => isObject(value) &&
|
|
12
|
+
['updated', 'unaffected'].includes(value.status) && nonempty(value.reason);
|
|
13
|
+
|
|
14
|
+
export function bindContract(root, contract) {
|
|
15
|
+
const { binding, ...declaration } = contract;
|
|
16
|
+
return { declaration: digest(JSON.stringify(declaration)), inputs: snapshot(root, contract.inputs) };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function checkBinding(root, contract, read = readFileSync) {
|
|
20
|
+
const { binding, ...declaration } = contract;
|
|
21
|
+
requireThat(isObject(binding) && binding.declaration === digest(JSON.stringify(declaration)),
|
|
22
|
+
'stale/missing declaration binding');
|
|
23
|
+
const inputs = snapshot(root, contract.inputs, read);
|
|
24
|
+
requireThat(isObject(binding.inputs) && Object.keys(binding.inputs).length === Object.keys(inputs).length &&
|
|
25
|
+
Object.keys(inputs).every((p) => binding.inputs[p] === inputs[p]), 'stale/missing input binding');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function checkContract(root, contract) {
|
|
29
|
+
const io = { files: 0, bytes: 0 };
|
|
30
|
+
const read = (file) => {
|
|
31
|
+
const data = readFileSync(file);
|
|
32
|
+
io.files++;
|
|
33
|
+
io.bytes += data.length;
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
requireThat(isObject(contract) && uniqueList(contract.specs) && uniqueList(contract.tests),
|
|
38
|
+
'specs/tests must be nonempty unique paths');
|
|
39
|
+
const definitions = (paths, regex, label) => {
|
|
40
|
+
const ids = new Set();
|
|
41
|
+
for (const path of paths) {
|
|
42
|
+
const text = read(inside(root, path)).toString('utf8');
|
|
43
|
+
for (const match of text.matchAll(regex)) {
|
|
44
|
+
requireThat(!ids.has(match[1]), `duplicate ${label}: ${match[1]}`);
|
|
45
|
+
ids.add(match[1]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
requireThat(ids.size > 0, `missing ${label} definitions`);
|
|
49
|
+
return ids;
|
|
50
|
+
};
|
|
51
|
+
const reqs = definitions(contract.specs, /^\|\s*(REQ-[A-Za-z0-9_-]+)\s*\|/gm, 'REQ');
|
|
52
|
+
const tests = definitions(contract.tests, /^\s*(?:\/\/|#|<!--|\/\*|\*)?\s*SDD-TEST:\s*(TEST-[A-Za-z0-9_-]+)\s*(?:-->|\*\/)?\s*$/gm, 'TEST');
|
|
53
|
+
requireThat(Array.isArray(contract.links) && contract.links.length > 0, 'missing links');
|
|
54
|
+
const pairs = new Set();
|
|
55
|
+
for (const link of contract.links) {
|
|
56
|
+
requireThat(isObject(link) && reqs.has(link.req) && tests.has(link.test), 'unknown REQ/TEST');
|
|
57
|
+
const pair = `${link.req}:${link.test}`;
|
|
58
|
+
requireThat(!pairs.has(pair), `duplicate link: ${pair}`);
|
|
59
|
+
pairs.add(pair);
|
|
60
|
+
}
|
|
61
|
+
requireThat([...reqs].every((req) => contract.links.some((l) => l.req === req)) &&
|
|
62
|
+
[...tests].every((test) => contract.links.some((l) => l.test === test)), 'unmapped REQ/TEST');
|
|
63
|
+
const required = new Set([...contract.specs, ...contract.tests]);
|
|
64
|
+
if (contract.change !== undefined) {
|
|
65
|
+
const c = contract.change;
|
|
66
|
+
requireThat(isObject(c) && validId(c.id) && ['feature', 'bugfix', 'refactor'].includes(c.kind) &&
|
|
67
|
+
Array.isArray(c.previousDone) && c.previousDone.every(validId) &&
|
|
68
|
+
new Set(c.previousDone).size === c.previousDone.length && !c.previousDone.includes(c.id),
|
|
69
|
+
'invalid/new change id, kind or previousDone');
|
|
70
|
+
requireThat(contract.specs.includes(c.owner), 'unknown owner spec');
|
|
71
|
+
requireThat(Array.isArray(c.refs) && c.refs.length > 0 &&
|
|
72
|
+
c.refs.every((r) => decision(r) && nonempty(r.path)) &&
|
|
73
|
+
new Set(c.refs.map((r) => r.path)).size === c.refs.length &&
|
|
74
|
+
c.refs.some((r) => r.path === c.owner), 'missing/duplicate references or reasons');
|
|
75
|
+
for (const ref of c.refs) required.add(ref.path);
|
|
76
|
+
requireThat(isObject(c.impacts) &&
|
|
77
|
+
['requirements', 'specification', 'design', 'plan', 'tests', 'api', 'data', 'config']
|
|
78
|
+
.every((area) => decision(c.impacts[area])), 'missing impact decision/reason');
|
|
79
|
+
}
|
|
80
|
+
requireThat(uniqueList(contract.inputs) && [...required].every((p) => contract.inputs.includes(p)),
|
|
81
|
+
'missing required inputs');
|
|
82
|
+
checkBinding(root, contract, read);
|
|
83
|
+
return { ok: true, issues: [], io };
|
|
84
|
+
} catch (error) {
|
|
85
|
+
return { ok: false, issues: [error.message], io };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
90
|
+
try {
|
|
91
|
+
const [action, file, ...extra] = process.argv.slice(2);
|
|
92
|
+
requireThat(['bind', 'check'].includes(action) && file && extra.length === 0,
|
|
93
|
+
'usage: contract.mjs bind|check <contract.json>');
|
|
94
|
+
const contract = JSON.parse(readFileSync(inside(process.cwd(), file)));
|
|
95
|
+
const result = action === 'bind' ? bindContract(process.cwd(), contract) : checkContract(process.cwd(), contract);
|
|
96
|
+
console.log(JSON.stringify(result));
|
|
97
|
+
if (result.ok === false) process.exitCode = 1;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error(`ERROR: ${error.message}`);
|
|
100
|
+
process.exitCode = 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -3,11 +3,11 @@ import { existsSync, mkdirSync, readFileSync, realpathSync, statSync, unlinkSync
|
|
|
3
3
|
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
|
|
6
|
-
const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
7
|
-
const nonempty = (value) => typeof value === 'string' && value.trim().length > 0;
|
|
8
|
-
const validId = (id) => typeof id === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$/.test(id);
|
|
6
|
+
export const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
7
|
+
export const nonempty = (value) => typeof value === 'string' && value.trim().length > 0;
|
|
8
|
+
export const validId = (id) => typeof id === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$/.test(id);
|
|
9
9
|
|
|
10
|
-
function inside(root, path) {
|
|
10
|
+
export function inside(root, path) {
|
|
11
11
|
const file = realpathSync(resolve(root, path));
|
|
12
12
|
const rel = relative(realpathSync(root), file);
|
|
13
13
|
if (!rel || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, realpathSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { inside, isObject, nonempty } from './evidence.mjs';
|
|
6
|
+
import { requireThat } from './contract.mjs';
|
|
7
|
+
|
|
8
|
+
const hash = (data) => createHash('sha256').update(data).digest('hex');
|
|
9
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
10
|
+
|
|
11
|
+
function tree(directory) {
|
|
12
|
+
const files = {};
|
|
13
|
+
const walk = (dir, prefix) => {
|
|
14
|
+
for (const name of readdirSync(dir).sort()) {
|
|
15
|
+
const file = join(dir, name);
|
|
16
|
+
const path = prefix ? `${prefix}/${name}` : name;
|
|
17
|
+
const stat = lstatSync(file);
|
|
18
|
+
requireThat(!stat.isSymbolicLink(), `symlink inside Skill tree: ${path}`);
|
|
19
|
+
if (stat.isDirectory()) walk(file, path);
|
|
20
|
+
else {
|
|
21
|
+
requireThat(stat.isFile(), `unsupported file: ${path}`);
|
|
22
|
+
Object.defineProperty(files, path, { value: hash(readFileSync(file)), enumerable: true });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
walk(directory, '');
|
|
27
|
+
requireThat(Object.hasOwn(files, 'SKILL.md'), 'missing SKILL.md');
|
|
28
|
+
return files;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function safePath(root, path) {
|
|
32
|
+
const full = resolve(root, path);
|
|
33
|
+
const rel = relative(root, full);
|
|
34
|
+
requireThat(rel && rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel),
|
|
35
|
+
`invalid destination: ${path}`);
|
|
36
|
+
let current = root;
|
|
37
|
+
for (const segment of rel.split(sep)) {
|
|
38
|
+
current = join(current, segment);
|
|
39
|
+
if (lstatSync(current, { throwIfNoEntry: false })) inside(root, current);
|
|
40
|
+
}
|
|
41
|
+
return full;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function physicalPath(path) {
|
|
45
|
+
return lstatSync(path, { throwIfNoEntry: false }) ? realpathSync(path) :
|
|
46
|
+
join(physicalPath(dirname(path)), basename(path));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function contains(parent, child) {
|
|
50
|
+
const rel = relative(parent, child);
|
|
51
|
+
return rel === '' || (rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function targetState(root, mode, locations) {
|
|
55
|
+
return locations.map((path, index) => {
|
|
56
|
+
const full = safePath(root, path);
|
|
57
|
+
const stat = lstatSync(full, { throwIfNoEntry: false });
|
|
58
|
+
if (!stat) return null;
|
|
59
|
+
requireThat(stat.isDirectory() || stat.isSymbolicLink(), `not a Skill directory: ${path}`);
|
|
60
|
+
const link = stat.isSymbolicLink() ? readlinkSync(full) : null;
|
|
61
|
+
if (index === 1 && mode === 'link') {
|
|
62
|
+
requireThat(link !== null && realpathSync(full) === realpathSync(safePath(root, locations[0])),
|
|
63
|
+
'Claude link must point to this project Copilot Skill');
|
|
64
|
+
}
|
|
65
|
+
return { link, files: tree(full) };
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function prepareSkill(source, target, options, origins) {
|
|
70
|
+
const { mode, identity, adopt = false, skill = 'sdd-tdd' } = options;
|
|
71
|
+
requireThat(['sdd-tdd', 'existing-code-requirements'].includes(skill), 'unsupported Skill');
|
|
72
|
+
requireThat(['copy', 'link'].includes(mode) && nonempty(identity), 'mode copy/link and source identity required');
|
|
73
|
+
const locations = [`.github/skills/${skill}`, `.claude/skills/${skill}`];
|
|
74
|
+
const root = realpathSync(target);
|
|
75
|
+
const origin = realpathSync(source);
|
|
76
|
+
const files = tree(origin);
|
|
77
|
+
const metadataPath = skill === 'sdd-tdd' ? '.sdd/skill-install.json' : `.sdd/skill-install-${skill}.json`;
|
|
78
|
+
const metadata = safePath(root, metadataPath);
|
|
79
|
+
for (const path of [...locations, metadataPath]) {
|
|
80
|
+
const destination = physicalPath(safePath(root, path));
|
|
81
|
+
requireThat(origins.every((source) => !contains(source, destination) && !contains(destination, source)),
|
|
82
|
+
`destination overlaps Skill source: ${path}`);
|
|
83
|
+
}
|
|
84
|
+
const storedText = lstatSync(metadata, { throwIfNoEntry: false }) ? readFileSync(metadata, 'utf8') : null;
|
|
85
|
+
const stored = storedText === null ? null : JSON.parse(storedText);
|
|
86
|
+
const before = targetState(root, mode, locations);
|
|
87
|
+
const differences = locations.flatMap((location, index) =>
|
|
88
|
+
[...new Set([...Object.keys(files), ...Object.keys(before[index]?.files ?? {})])].sort()
|
|
89
|
+
.map((path) => ({
|
|
90
|
+
path: `${location}/${path}`,
|
|
91
|
+
status: !Object.hasOwn(files, path) ? 'remove' : !before[index]?.files[path] ? 'add' :
|
|
92
|
+
before[index].files[path] === files[path] ? 'unchanged' : 'change',
|
|
93
|
+
})));
|
|
94
|
+
let baseline = 'unknown';
|
|
95
|
+
const result = { ok: true, baseline, identity, mode, differences, changed: false };
|
|
96
|
+
try {
|
|
97
|
+
if (storedText !== null) {
|
|
98
|
+
baseline = 'known';
|
|
99
|
+
requireThat(isObject(stored) && stored.version === 1 && stored.mode === mode &&
|
|
100
|
+
isObject(stored.files) && Array.isArray(stored.targets), 'invalid baseline or mode change; manual review required');
|
|
101
|
+
requireThat(same(before, stored.targets), 'local edit/missing/extra files or changed link; protected');
|
|
102
|
+
requireThat(Object.keys(stored.files).every((p) => Object.hasOwn(files, p)),
|
|
103
|
+
'source removes files; manual review required (no deletion)');
|
|
104
|
+
} else if (before.some(Boolean)) {
|
|
105
|
+
requireThat(adopt === true, 'unknown baseline; explicit adopt of identical content required');
|
|
106
|
+
requireThat(before.every((s) => !s || same(s.files, files)), 'unknown baseline differs; protected');
|
|
107
|
+
baseline = 'adopt-identical';
|
|
108
|
+
} else {
|
|
109
|
+
baseline = 'new';
|
|
110
|
+
}
|
|
111
|
+
result.baseline = baseline;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
Object.assign(result, { ok: false, baseline, issues: [error.message] });
|
|
114
|
+
}
|
|
115
|
+
const recheck = () => {
|
|
116
|
+
requireThat(same(before, targetState(root, mode, locations)), 'destination changed after preview');
|
|
117
|
+
requireThat(same(files, tree(origin)), 'source changed after preview');
|
|
118
|
+
requireThat((lstatSync(metadata, { throwIfNoEntry: false }) ? readFileSync(metadata, 'utf8') : null) === storedText,
|
|
119
|
+
'baseline changed after preview');
|
|
120
|
+
};
|
|
121
|
+
const apply = () => {
|
|
122
|
+
// Recheck immediately before writing. This is not a transaction or a multi-writer lock.
|
|
123
|
+
recheck();
|
|
124
|
+
if (same(stored, { version: 1, identity, mode, files, targets: before }) &&
|
|
125
|
+
before.every((s) => s && same(s.files, files))) return result;
|
|
126
|
+
result.changed = true;
|
|
127
|
+
for (let index = 0; index < locations.length; index++) {
|
|
128
|
+
const destination = safePath(root, locations[index]);
|
|
129
|
+
if (index === 1 && mode === 'link') {
|
|
130
|
+
if (!before[index]) {
|
|
131
|
+
mkdirSync(safePath(root, dirname(locations[index])), { recursive: true });
|
|
132
|
+
symlinkSync(`../../.github/skills/${skill}`, destination, 'dir');
|
|
133
|
+
}
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
mkdirSync(destination, { recursive: true });
|
|
137
|
+
for (const path of Object.keys(files)) {
|
|
138
|
+
if (before[index]?.files[path] === files[path]) continue;
|
|
139
|
+
const to = safePath(root, `${locations[index]}/${path}`);
|
|
140
|
+
mkdirSync(dirname(to), { recursive: true });
|
|
141
|
+
const data = readFileSync(join(origin, path));
|
|
142
|
+
requireThat(hash(data) === files[path], `source changed: ${path}`);
|
|
143
|
+
writeFileSync(to, data);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const after = targetState(root, mode, locations);
|
|
147
|
+
requireThat(after.every((s) => s && same(s.files, files)) && same(files, tree(origin)),
|
|
148
|
+
'post-update identity mismatch; preserve files and inspect manually');
|
|
149
|
+
mkdirSync(safePath(root, '.sdd'), { recursive: true });
|
|
150
|
+
writeFileSync(metadata, JSON.stringify({ version: 1, identity, mode, files, targets: after }, null, 2) + '\n');
|
|
151
|
+
return result;
|
|
152
|
+
};
|
|
153
|
+
return { result, recheck, apply };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function installSkills(sources, target, options = {}) {
|
|
157
|
+
const plans = [];
|
|
158
|
+
try {
|
|
159
|
+
requireThat(Array.isArray(sources) && sources.length > 0, 'Skill sources required');
|
|
160
|
+
requireThat(new Set(sources.map((s) => s.skill)).size === sources.length, 'duplicate Skill');
|
|
161
|
+
const origins = sources.map((s) => realpathSync(s.source));
|
|
162
|
+
for (const { source, skill } of sources) {
|
|
163
|
+
plans.push(prepareSkill(source, target, { ...options, skill }, origins));
|
|
164
|
+
}
|
|
165
|
+
if (plans.some((p) => !p.result.ok)) {
|
|
166
|
+
return { ok: false, changed: false, incomplete: false, results: plans.map((p) => p.result),
|
|
167
|
+
issues: plans.flatMap((p) => p.result.issues ?? []) };
|
|
168
|
+
}
|
|
169
|
+
if (options.apply) {
|
|
170
|
+
for (const plan of plans) plan.recheck();
|
|
171
|
+
for (const plan of plans) plan.apply();
|
|
172
|
+
}
|
|
173
|
+
return { ok: true, changed: plans.some((p) => p.result.changed), results: plans.map((p) => p.result) };
|
|
174
|
+
} catch (error) {
|
|
175
|
+
const changed = plans.some((p) => p.result.changed);
|
|
176
|
+
return { ok: false, issues: [error.message], changed, incomplete: changed,
|
|
177
|
+
results: plans.map((p) => p.result) };
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function installSkill(source, target, options = {}) {
|
|
182
|
+
const batch = installSkills([{ source, skill: options.skill ?? 'sdd-tdd' }], target, options);
|
|
183
|
+
return batch.ok ? batch.results[0] : {
|
|
184
|
+
...batch.results[0], ok: false, baseline: batch.results[0]?.baseline ?? 'unknown',
|
|
185
|
+
differences: batch.results[0]?.differences ?? [], issues: batch.issues,
|
|
186
|
+
changed: batch.changed, incomplete: batch.incomplete,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
191
|
+
const [action, source, target, mode, identity, ...flags] = process.argv.slice(2);
|
|
192
|
+
if (!['preview', 'apply'].includes(action) || !source || !target ||
|
|
193
|
+
flags.some((f) => f !== '--adopt') || flags.length > 1) {
|
|
194
|
+
console.error('usage: install.mjs preview|apply <source> <target-root> copy|link <identity> [--adopt]');
|
|
195
|
+
process.exitCode = 1;
|
|
196
|
+
} else {
|
|
197
|
+
const result = installSkill(source, target, { mode, identity, adopt: flags.includes('--adopt'), apply: action === 'apply' });
|
|
198
|
+
console.log(JSON.stringify(result));
|
|
199
|
+
if (!result.ok) process.exitCode = 1;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { inside, isObject, nonempty, snapshot, validId } from './evidence.mjs';
|
|
5
|
+
import { checkBinding, requireThat } from './contract.mjs';
|
|
6
|
+
|
|
7
|
+
export function checkTdd(root, record) {
|
|
8
|
+
try {
|
|
9
|
+
requireThat(isObject(record) && ['feature', 'bugfix', 'refactor'].includes(record.kind) &&
|
|
10
|
+
Array.isArray(record.events) && record.events.length === 2, 'invalid TDD record');
|
|
11
|
+
const [first, green] = record.events;
|
|
12
|
+
for (const e of record.events) {
|
|
13
|
+
requireThat(isObject(e) && validId(e.test) && nonempty(e.command) && e.executed === true &&
|
|
14
|
+
e.skipped === 0 && e.otherFailures === 0 && Number.isSafeInteger(e.assertionFailures) &&
|
|
15
|
+
e.assertionFailures >= 0 && Number.isSafeInteger(e.start) && Number.isSafeInteger(e.end) &&
|
|
16
|
+
e.start >= 0 && e.end >= e.start && isObject(e.testInputs) &&
|
|
17
|
+
Object.keys(e.testInputs).length > 0, 'invalid/unexecuted/skipped/error event');
|
|
18
|
+
}
|
|
19
|
+
const pass = (e) => e.status === 'pass' && e.exitCode === 0 && e.assertionFailures === 0;
|
|
20
|
+
requireThat(first.end <= green.start && green.phase === 'green' && pass(green), 'invalid order/Green');
|
|
21
|
+
if (record.kind === 'refactor') {
|
|
22
|
+
requireThat(first.phase === 'baseline' && pass(first), 'refactor requires Green baseline');
|
|
23
|
+
} else {
|
|
24
|
+
requireThat(first.phase === 'red' && first.status === 'fail' &&
|
|
25
|
+
Number.isSafeInteger(first.exitCode) && first.exitCode > 0 && first.assertionFailures > 0,
|
|
26
|
+
'Red must be assertion failure, not setup/compile/skip');
|
|
27
|
+
}
|
|
28
|
+
requireThat(first.test === green.test && first.command === green.command, 'changed test/command');
|
|
29
|
+
const paths = Object.keys(green.testInputs);
|
|
30
|
+
const current = snapshot(root, paths);
|
|
31
|
+
requireThat(Object.keys(first.testInputs).length === paths.length &&
|
|
32
|
+
paths.every((p) => first.testInputs[p] === current[p] && green.testInputs[p] === current[p] &&
|
|
33
|
+
record.inputs.includes(p)), 'changed/stale/missing test inputs');
|
|
34
|
+
checkBinding(root, record);
|
|
35
|
+
return { ok: true, issues: [] };
|
|
36
|
+
} catch (error) {
|
|
37
|
+
return { ok: false, issues: [error.message] };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
42
|
+
try {
|
|
43
|
+
const [action, file, ...extra] = process.argv.slice(2);
|
|
44
|
+
requireThat(action === 'check' && file && extra.length === 0, 'usage: tdd.mjs check <record.json>');
|
|
45
|
+
const result = checkTdd(process.cwd(), JSON.parse(readFileSync(inside(process.cwd(), file))));
|
|
46
|
+
console.log(JSON.stringify(result));
|
|
47
|
+
if (!result.ok) process.exitCode = 1;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(`ERROR: ${error.message}`);
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nahisaho
|
|
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,191 @@
|
|
|
1
|
+
# musubix7
|
|
2
|
+
|
|
3
|
+
**仕様駆動開発(SDD)とテスト駆動開発(TDD)によるAIコーディングを支援するAgent Skills。**
|
|
4
|
+
GitHub Copilot CLI と Claude Code で利用できます。どちらか一方のホストを選べます。
|
|
5
|
+
|
|
6
|
+
[English](README.md) | 日本語
|
|
7
|
+
|
|
8
|
+
musubix7は、要件の確認、仕様、計画、テスト、完了判断をつなぐ**プロセスハーネス**です。
|
|
9
|
+
独自のモデルやエージェント実行基盤ではありません。コーディング、テスト実行、計画、承認操作は
|
|
10
|
+
利用するホストCLIに委ねます。**どちらか片方のホストだけで利用できます。**
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Skillを選ぶ
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
| Skill | 使う場面 |
|
|
17
|
+
| ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
18
|
+
| [`sdd-tdd`](.github/skills/sdd-tdd/SKILL.md) | ゼロからの開発、またはmusubix7で一度完成し、仕様・テスト・完了記録を持つ対象の変更単位SDD/TDD。明示対象はTypeScript/Node.js、Python、Rust。 |
|
|
19
|
+
| [`existing-code-requirements`](.github/skills/existing-code-requirements/SKILL.md) | 既存コードを限定読取し、根拠付きの要件定義書ドラフトを作成。既定はread-onlyの調査・文書化であり、対象source/test/configは変更しません。 |
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
ECRは新規開発の自動前処理ではありません。ドラフトを作るだけでは`sdd-tdd`の完成済み条件を満たしません。
|
|
23
|
+
手順の一部は言語非依存ですが、他言語への対応・実証を約束するものではありません。
|
|
24
|
+
スキルやhelperはエージェントの判断・実行を保証するsecurity boundaryではありません。
|
|
25
|
+
AIの通常判断は「AI承認」と記し、人間承認を偽りません。未解決の意図や必要な高リスク同意はblockerとして残します。
|
|
26
|
+
|
|
27
|
+
## インストール
|
|
28
|
+
|
|
29
|
+
### 前提
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
| 用途 | 必要なもの |
|
|
33
|
+
| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
34
|
+
| ホスト | [GitHub Copilot CLIの導入・認証](https://docs.github.com/en/copilot/how-tos/copilot-cli/cli-getting-started)、または[Claude Codeの導入](https://code.claude.com/docs/en/setup)・[認証](https://code.claude.com/docs/en/authentication)。利用権限と認証は各ホストで別途準備します。 |
|
|
35
|
+
| 下記の配置CLI | Node.js **22以上**。npm手順にはnpm、Git手順にはGitも必要です。Skill本文を読むだけならNode/npmは不要ですが、同梱helperにはNode.js 22以上が必要です。 |
|
|
36
|
+
| 開発対象 | そのプロジェクト標準の言語ツール・テストrunner。付属TypeScript例の再現は別途Node.js **24以上**と`npm ci`が必要です。 |
|
|
37
|
+
| 書込権限 | 導入先プロジェクトrootの`.github/skills/`、`.claude/skills/`、`.sdd/`。共有CLI設定や認証を変更する必要はありません。 |
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Gitソースからインストールする方法
|
|
41
|
+
|
|
42
|
+
**導入先プロジェクトのrootから**、未使用の隣接ディレクトリを取得先にして実行します。
|
|
43
|
+
`main`のソースには既存の`bin/musubix.mjs`があります。registry packageは実行しません。
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
git clone --branch main --single-branch https://github.com/nahisaho/musubix7.git ../musubix7-skills &&
|
|
47
|
+
git -C ../musubix7-skills rev-parse HEAD &&
|
|
48
|
+
node ../musubix7-skills/bin/musubix.mjs init
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
取得先を変更する場合は3行すべてのパスを揃えてください。表示される導入元commitを控え、
|
|
52
|
+
最後のコマンドも導入先rootで実行します。**この再構成したREADMEは0.1.2候補に含まれ、旧tagの成果物には含まれません。**
|
|
53
|
+
|
|
54
|
+
### npm でインストールする方法(推奨)
|
|
55
|
+
|
|
56
|
+
2026-11-27の公開metadataでは`latest`は**0.1.1**です。
|
|
57
|
+
公開済み0.1.0/0.1.1はCLI・ECR・MIT LICENSEを欠く旧8ファイル版のため、この導入には使えません。
|
|
58
|
+
訂正版**0.1.2**候補は両Skill・CLI・MIT表示・両READMEを含み、所有者による手動公開の準備中です。
|
|
59
|
+
公開済みの正規版としてはまだ確認していません。
|
|
60
|
+
[npmの0.1.2](https://www.npmjs.com/package/musubix7/v/0.1.2)と
|
|
61
|
+
[GitHub Release](https://github.com/nahisaho/musubix7/releases/tag/v0.1.2)は別々に確認してください。
|
|
62
|
+
|
|
63
|
+
**現在のlatestでは実行しないでください。latestがCLI対応の訂正版になったことを確認した後にだけ**、
|
|
64
|
+
導入先プロジェクトrootで実行します。
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
npm install musubix7@latest && npx musubix init
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
package名は`musubix7`、bin名は`musubix`です。`@latest`は数値版を指定せずnpmの最新版を選びます。
|
|
71
|
+
`&&`でinstall失敗時に`npx`が実行されないようにしています。
|
|
72
|
+
導入したpackageにローカルの`musubix`実行ファイルが必要です。実行ファイルがない状態で
|
|
73
|
+
`npx`を実行したり、無関係な同名packageを代用として取得したりしないでください。
|
|
74
|
+
|
|
75
|
+
### 配置先と安全な再実行
|
|
76
|
+
|
|
77
|
+
`musubix init`は**呼出cwd**へ両Skillをコピーします。ホスト選択optionはありません。
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
| Skill | Copilot CLI | Claude Code |
|
|
81
|
+
| ---------------------------- | -------------------------------------------- | -------------------------------------------- |
|
|
82
|
+
| `sdd-tdd` | `.github/skills/sdd-tdd/` | `.claude/skills/sdd-tdd/` |
|
|
83
|
+
| `existing-code-requirements` | `.github/skills/existing-code-requirements/` | `.claude/skills/existing-code-requirements/` |
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
導入baselineは`.sdd/skill-install.json`と`.sdd/skill-install-existing-code-requirements.json`です。
|
|
87
|
+
同一source・identity・配置・baselineの再実行は書込なしです。既存の手動配置は同一内容でも
|
|
88
|
+
unknown baselineとして停止し、ローカル編集、余剰・欠落、mode変更、危険なリンクも非zeroで拒否します。
|
|
89
|
+
元ファイルとmetadataを保全して差分を確認してください。forceや自動上書きはありません。
|
|
90
|
+
他writerと同時に実行しないでください。全配置を先行検査しますが完全な原子性は保証せず、
|
|
91
|
+
途中I/O失敗は`incomplete: true`として報告し、書込済みを自動rollbackしません。
|
|
92
|
+
|
|
93
|
+
`init`はgit操作、依存install、Skillの実行、共有設定・認証の変更を行いません。
|
|
94
|
+
片ホストだけに手動導入する場合は、確認したソースの各Skillディレクトリ**全体**を上表の必要な場所へコピーし、
|
|
95
|
+
既存のファイル・ディレクトリ・壊れたリンクを含むリンクがあれば停止して差分を確認します。
|
|
96
|
+
Claudeの相対リンク方式や更新preview→確認→applyは
|
|
97
|
+
[導入helperの説明](.github/skills/sdd-tdd/references/helpers.md#安全な導入更新)を参照してください。
|
|
98
|
+
その位置引数CLIは**sdd-tdd専用**であり、ECRのソースを渡してはいけません。
|
|
99
|
+
コピーは自動同期されないため、更新時も導入元の版と両配置の編集差分を確認します。
|
|
100
|
+
|
|
101
|
+
導入先rootで`copilot`または`claude`を起動します。Copilotでは`copilot skill list`で配置を確認できます。
|
|
102
|
+
対話で`/sdd-tdd`、`/existing-code-requirements`、またはSkill名を明示した自然言語を使い、
|
|
103
|
+
対象の`SKILL.md`が読み込まれたことを確認してください。配置・発見だけでは手順の実行成功ではありません。
|
|
104
|
+
|
|
105
|
+
## ゼロから開発する
|
|
106
|
+
|
|
107
|
+
`sdd-tdd`を明示し、最初の小さな機能から始めます。
|
|
108
|
+
|
|
109
|
+
1. 目的・成功条件・対象外を確認し、判断に影響する不明点だけを解決します。
|
|
110
|
+
2. `.sdd/specs/<feature>.md`に唯一の仕様、受入条件、例・反例、安定REQ IDとテスト対応を記します。
|
|
111
|
+
3. ホストの計画機能で依存・完了条件を整理し、プロジェクト標準runnerで意味あるassertionの**Red**を実行します。
|
|
112
|
+
4. **同じテスト**を最小実装で**Green**にし、必要ならrefactorと影響する回帰を行います。
|
|
113
|
+
5. 仕様・実装・テストを照合し、必要な検証・証拠・レビューを揃えてDoneを記録します。失敗・skip・未実施は成功にしません。
|
|
114
|
+
|
|
115
|
+
依頼例(コピーして調整してください):
|
|
116
|
+
|
|
117
|
+
```text
|
|
118
|
+
sdd-tddを使い、このrootでTypeScriptの割引計算をゼロから作ってください。
|
|
119
|
+
金額は0以上の整数、割引率は0〜100の整数とし、割引後の金額は小数点以下を切り捨てます。
|
|
120
|
+
範囲外は拒否し、UI・DB・公開は対象外です。不明点だけを確認し、仕様と受入条件を先に定義してください。
|
|
121
|
+
ホストの計画、実assertion Red、同じテストのGreen、必要な回帰と証拠、Doneまで進め、
|
|
122
|
+
実行済・再利用・未実施を区別してください。
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
環境・import・compilerの失敗やskipはTDDのRedではありません。
|
|
126
|
+
詳細は[ワークフロー](.github/skills/sdd-tdd/references/workflow.md)と
|
|
127
|
+
[検証](.github/skills/sdd-tdd/references/verification.md)を参照してください。
|
|
128
|
+
|
|
129
|
+
## 既存コードから要件を整理し、機能を追加する
|
|
130
|
+
|
|
131
|
+
まず`existing-code-requirements`で**読取範囲と出力先**を指定します。
|
|
132
|
+
観測事実・推定意図・未知・要求された将来状態を分け、path・symbol・test等の根拠を残します。
|
|
133
|
+
既存正本・ID・ユーザー編集は保全し、未実行testを成功や正しい業務要件の証拠にしません。
|
|
134
|
+
|
|
135
|
+
```text
|
|
136
|
+
existing-code-requirementsを使い、このrootの既存割引機能から要件ドラフトを作ってください。
|
|
137
|
+
入口はsrc/discount.ts、読取はsrc/discount.ts、tests/discount.test.ts、
|
|
138
|
+
既存の.sdd/specs/discount.mdと直接参照する設定のみ、合計最大800行です。
|
|
139
|
+
出力は.sdd/specs/discount.mdとし、既存文書・ID・編集を保全して限定差分にしてください。
|
|
140
|
+
観測事実・推定意図・未知・要求された将来状態と根拠を分け、
|
|
141
|
+
未知や矛盾、未実行テストを明記してください。source/test/configは変更せず、
|
|
142
|
+
不足する読取範囲があれば拡大前に止めて報告してください。
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
例のパスは自分のプロジェクトに置き換えてください。ドラフト後は意図・矛盾を解決し、
|
|
146
|
+
不足する要件と実testsを補い、必要なテストを**実行**して検証gapを明示します。
|
|
147
|
+
musubix7で仕様・テスト・Doneが揃った完成baselineを**実際に確立してから**、変更単位SDD/TDDへ進みます。
|
|
148
|
+
baselineが不足する間は先に補うか、未完として残してください。ドラフトだけで完成済みgateは通りません。
|
|
149
|
+
その後の依頼例:
|
|
150
|
+
|
|
151
|
+
```text
|
|
152
|
+
仕様・実テスト・Doneで確認した完成baselineを照合してから、sdd-tddで変更DISCOUNT-002を進めてください。
|
|
153
|
+
割引率の上限を50に変更します。旧DoneとREQ IDを保全し、影響する正本・受入・ホスト計画を先に更新して、
|
|
154
|
+
新しい期待のassertion Red→同じテストGreen→必要な回帰と証拠→この変更のDoneを記録してください。
|
|
155
|
+
完成baselineが確認できなければ機能追加を始めず、不足を報告してください。
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**refactorは別の明示指示がある場合だけ**です。許可範囲と保つ挙動を定め、実際のGreen baselineを確認してから、
|
|
159
|
+
限定変更→同じテストと必要な回帰のGreenという**Green→Green**で進めます。
|
|
160
|
+
baselineが失敗・欠落・skip・実行不能なら該当コードを変更しません。これは機能追加のRed→Greenとは別であり、
|
|
161
|
+
人工Redや都合のよいテスト期待の変更をしません。
|
|
162
|
+
|
|
163
|
+
## 対応範囲と確認水準
|
|
164
|
+
|
|
165
|
+
上の依頼文は**利用例**であり、今回新たに実行した実証ではありません。
|
|
166
|
+
文書上の対応、配置検査、手動適用、native実セッションを区別します。
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
| 区分 | 範囲・制限 |
|
|
170
|
+
| ------------ | -------------------------------------------------------------------------------------------------------------------------- |
|
|
171
|
+
| 対応するホスト | Copilot CLIとClaude Code。同じSkill本文を利用し、具体的な機能・権限はホストの版と設定に従います。 |
|
|
172
|
+
| 配置の実証 | 従来のローカルtarball導入はLinux / Node.js 24で確認。Node.js 22の下限や全OSでの実証ではありません。 |
|
|
173
|
+
| 従来のSDD/TDD実証 | LinuxのCopilotとClaude Codeで発見・読込・新規/継続変更の実assertion Red→同一test Greenを確認した記録があります。最新版の全native triggerを再実証したものではありません。 |
|
|
174
|
+
| ECRの実証 | Copilot ACPで明示読取・手動適用による文書化、明示refactor、baseline失敗時の停止。最新版のnative自動trigger・Claude・全OS実行は未実証です。 |
|
|
175
|
+
| 将来の確認 | macOS/native Windowsは[既存の追跡先 #15](https://github.com/nahisaho/musubix7/issues/15)でpending。WSL専用実機も未実証であり、今回の必須gateに追加しません。 |
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
履歴と詳しい限界:
|
|
179
|
+
[SDD/TDDホスト記録](https://github.com/nahisaho/musubix7/blob/724998279e5221b2a9f7bccb63caec511809bfa5/artifacts/item9/host-check.md)、
|
|
180
|
+
[ECR記録](https://github.com/nahisaho/musubix7/blob/724998279e5221b2a9f7bccb63caec511809bfa5/artifacts/item17-refactor/report.md)、
|
|
181
|
+
[3言語の例](https://github.com/nahisaho/musubix7/blob/724998279e5221b2a9f7bccb63caec511809bfa5/examples/README.md)。
|
|
182
|
+
これらはnpm非同梱のため固定Gitソースへリンクしています。
|
|
183
|
+
[ホスト差分](.github/skills/sdd-tdd/references/hosts.md)の「Claude実セッション未検証」は当時の記録であり、
|
|
184
|
+
後のLinux実証は上表・記録を参照してください。過去の成功を最新版の成功に読み替えません。
|
|
185
|
+
|
|
186
|
+
## ライセンス
|
|
187
|
+
|
|
188
|
+
musubix7のコード・Skill・文書・例は、別途表示のあるものを除き[MIT License](LICENSE)です。
|
|
189
|
+
Skillディレクトリ全体と同梱`LICENSE`をコピーし、コピー・改変・再配布時には著作権表示と許諾表示を保持してください。
|
|
190
|
+
`init`も各Skillへ表示を配置し、導入先プロジェクトのライセンスは変更しません。
|
|
191
|
+
依存・第三者由来のものはそれぞれの条件に従います。
|