magic-spec 1.0.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/.agent/workflows/magic/plan.md +12 -0
- package/.agent/workflows/magic/retrospective.md +12 -0
- package/.agent/workflows/magic/rule.md +12 -0
- package/.agent/workflows/magic/specification.md +12 -0
- package/.agent/workflows/magic/task.md +12 -0
- package/.magic/init.md +63 -0
- package/.magic/plan.md +289 -0
- package/.magic/retrospective.md +276 -0
- package/.magic/rule.md +96 -0
- package/.magic/scripts/init.ps1 +88 -0
- package/.magic/scripts/init.sh +85 -0
- package/.magic/specification.md +378 -0
- package/.magic/task.md +443 -0
- package/LICENSE +21 -0
- package/README.md +180 -0
- package/package.json +37 -0
- package/src/index.js +81 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { spawnSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
// Package root: installers/node/ — .magic, .agent, adapters synced here before publish
|
|
8
|
+
const pkgRoot = path.join(__dirname, '..');
|
|
9
|
+
const cwd = process.cwd();
|
|
10
|
+
|
|
11
|
+
// Parse arguments
|
|
12
|
+
const args = process.argv.slice(2);
|
|
13
|
+
const envFlag = args.find(a => a.startsWith('--env'));
|
|
14
|
+
const envValues = envFlag
|
|
15
|
+
? envFlag.includes('=')
|
|
16
|
+
? envFlag.split('=')[1].split(',')
|
|
17
|
+
: (args[args.indexOf(envFlag) + 1] || '').split(',').filter(Boolean)
|
|
18
|
+
: [];
|
|
19
|
+
|
|
20
|
+
const ADAPTERS = {
|
|
21
|
+
cursor: '.cursor/rules',
|
|
22
|
+
github: '.github',
|
|
23
|
+
kilocode: '.kilocode',
|
|
24
|
+
windsurf: '.windsurf/rules',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function copyDir(src, dest) {
|
|
28
|
+
if (!fs.existsSync(src)) {
|
|
29
|
+
console.warn(`⚠️ Source not found: ${src}`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
fs.cpSync(src, dest, { recursive: true, force: true });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.log('🪄 Initializing magic-spec...');
|
|
36
|
+
|
|
37
|
+
// 1. Copy .magic (SDD engine)
|
|
38
|
+
copyDir(path.join(pkgRoot, '.magic'), path.join(cwd, '.magic'));
|
|
39
|
+
|
|
40
|
+
// 2. Copy default agent adapter OR env-specific adapter
|
|
41
|
+
if (envValues.length > 0) {
|
|
42
|
+
for (const env of envValues) {
|
|
43
|
+
const adapterSrc = path.join(pkgRoot, 'adapters', env);
|
|
44
|
+
const adapterDest = path.join(cwd, ADAPTERS[env] || `.${env}`);
|
|
45
|
+
if (!ADAPTERS[env]) {
|
|
46
|
+
console.warn(`⚠️ Unknown --env value: "${env}". Falling back to default .agent/`);
|
|
47
|
+
console.warn(` Valid values: ${Object.keys(ADAPTERS).join(', ')}`);
|
|
48
|
+
console.warn(` To request a new adapter: https://github.com/teratron/magic-spec/issues`);
|
|
49
|
+
copyDir(path.join(pkgRoot, '.agent'), path.join(cwd, '.agent'));
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (!fs.existsSync(adapterSrc)) {
|
|
53
|
+
console.warn(`⚠️ Adapter "${env}" not yet implemented. Falling back to default .agent/`);
|
|
54
|
+
console.warn(` Copy .agent/workflows/magic/ manually to ${ADAPTERS[env]}/`);
|
|
55
|
+
copyDir(path.join(pkgRoot, '.agent'), path.join(cwd, '.agent'));
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
copyDir(adapterSrc, adapterDest);
|
|
59
|
+
console.log(`✅ Adapter installed: ${env} → ${ADAPTERS[env]}/`);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
// Default: install .agent/
|
|
63
|
+
copyDir(path.join(pkgRoot, '.agent'), path.join(cwd, '.agent'));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 3. Run init script
|
|
67
|
+
const isWindows = process.platform === 'win32';
|
|
68
|
+
const initScript = isWindows
|
|
69
|
+
? path.join(cwd, '.magic', 'scripts', 'init.ps1')
|
|
70
|
+
: path.join(cwd, '.magic', 'scripts', 'init.sh');
|
|
71
|
+
|
|
72
|
+
if (fs.existsSync(initScript)) {
|
|
73
|
+
if (isWindows) {
|
|
74
|
+
spawnSync('powershell.exe', ['-ExecutionPolicy', 'Bypass', '-File', initScript], { stdio: 'inherit' });
|
|
75
|
+
} else {
|
|
76
|
+
fs.chmodSync(initScript, '755');
|
|
77
|
+
spawnSync('bash', [initScript], { stdio: 'inherit' });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.log('✅ magic-spec initialized successfully!');
|