@fabersep/spec 0.0.0-stage → 0.2.1
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/.claude-plugin/plugin.json +10 -0
- package/CHANGELOG.md +29 -0
- package/LICENSE +202 -0
- package/README.md +132 -2
- package/package.json +53 -4
- package/plugin.json +17 -0
- package/rules/documentation-rules.md +76 -0
- package/skills/faber-discuss/SKILL.md +147 -0
- package/skills/faber-discuss/discuss_log.py +286 -0
- package/skills/faber-discuss/discuss_round.py +379 -0
- package/skills/faber-extract-features/SKILL.md +46 -0
- package/skills/faber-init-arch/SKILL.md +44 -0
- package/skills/faber-init-prd/SKILL.md +38 -0
- package/skills/faber-new-feature/SKILL.md +51 -0
- package/src/cli.mjs +314 -0
- package/src/installer.mjs +471 -0
- package/src/prompt.mjs +114 -0
- package/templates/architecture.md +93 -0
- package/templates/feature-bdd.md +54 -0
- package/templates/feature-prd.md +80 -0
- package/templates/master-prd.md +114 -0
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as os from 'node:os';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
export const PACKAGE_ROOT = path.resolve(__dirname, '..');
|
|
10
|
+
export const META_FILENAME = '.faber-spec-meta.json';
|
|
11
|
+
|
|
12
|
+
export function getPackageVersion() {
|
|
13
|
+
const pkgPath = path.join(PACKAGE_ROOT, 'package.json');
|
|
14
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
15
|
+
return pkg.version;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getUserHome() {
|
|
19
|
+
return process.env.FABER_USER_HOME || os.homedir();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getCanonicalRoot(userHome = getUserHome()) {
|
|
23
|
+
return path.join(userHome, '.faber', 'spec');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getSkillNames(sourceRoot = PACKAGE_ROOT) {
|
|
27
|
+
const skillsDir = path.join(sourceRoot, 'skills');
|
|
28
|
+
if (!fs.existsSync(skillsDir)) return [];
|
|
29
|
+
return fs
|
|
30
|
+
.readdirSync(skillsDir, { withFileTypes: true })
|
|
31
|
+
.filter((entry) => entry.isDirectory() && entry.name.startsWith('faber-'))
|
|
32
|
+
.map((entry) => entry.name)
|
|
33
|
+
.sort();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getEngineDefs(userHome = getUserHome()) {
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
id: 'antigravity',
|
|
40
|
+
label: 'Antigravity',
|
|
41
|
+
detectPath: path.join(userHome, '.gemini'),
|
|
42
|
+
detectHint: '~/.gemini',
|
|
43
|
+
mode: 'plugin',
|
|
44
|
+
targetPath: path.join(userHome, '.gemini', 'config', 'plugins', 'faber-spec'),
|
|
45
|
+
targetHint: '~/.gemini/config/plugins/faber-spec',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'claude-code',
|
|
49
|
+
label: 'Claude Code / Desktop',
|
|
50
|
+
detectPath: path.join(userHome, '.claude'),
|
|
51
|
+
detectHint: '~/.claude',
|
|
52
|
+
mode: 'plugin',
|
|
53
|
+
targetPath: path.join(userHome, '.claude', 'skills', 'faber-spec'),
|
|
54
|
+
targetHint: '~/.claude/skills/faber-spec',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: 'codex',
|
|
58
|
+
label: 'OpenAI Codex',
|
|
59
|
+
detectPath: path.join(userHome, '.codex'),
|
|
60
|
+
detectHint: '~/.codex',
|
|
61
|
+
mode: 'skills',
|
|
62
|
+
targetPath: path.join(userHome, '.codex', 'skills'),
|
|
63
|
+
targetHint: '~/.codex/skills/faber-*',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'cursor',
|
|
67
|
+
label: 'Cursor',
|
|
68
|
+
detectPath: path.join(userHome, '.cursor'),
|
|
69
|
+
detectHint: '~/.cursor',
|
|
70
|
+
mode: 'skills',
|
|
71
|
+
targetPath: path.join(userHome, '.cursor', 'skills'),
|
|
72
|
+
targetHint: '~/.cursor/skills/faber-*',
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function detectEngines(userHome = getUserHome()) {
|
|
78
|
+
return getEngineDefs(userHome).map((engine) => ({
|
|
79
|
+
...engine,
|
|
80
|
+
detected: fs.existsSync(engine.detectPath),
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function shouldCopyEntry(srcPath) {
|
|
85
|
+
const base = path.basename(srcPath);
|
|
86
|
+
if (base === '__pycache__' || base === '.DS_Store' || base.endsWith('.pyc')) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function copyTree(src, dst) {
|
|
93
|
+
if (!shouldCopyEntry(src)) return;
|
|
94
|
+
const stat = fs.statSync(src);
|
|
95
|
+
if (stat.isDirectory()) {
|
|
96
|
+
fs.mkdirSync(dst, { recursive: true });
|
|
97
|
+
for (const entry of fs.readdirSync(src)) {
|
|
98
|
+
copyTree(path.join(src, entry), path.join(dst, entry));
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
102
|
+
fs.copyFileSync(src, dst);
|
|
103
|
+
fs.chmodSync(dst, stat.mode);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function stageCanonicalInstall({
|
|
108
|
+
userHome = getUserHome(),
|
|
109
|
+
sourceRoot = PACKAGE_ROOT,
|
|
110
|
+
dryRun = false,
|
|
111
|
+
} = {}) {
|
|
112
|
+
const canonicalRoot = getCanonicalRoot(userHome);
|
|
113
|
+
const version = getPackageVersion();
|
|
114
|
+
const itemsToStage = [
|
|
115
|
+
'plugin.json',
|
|
116
|
+
'.claude-plugin',
|
|
117
|
+
'rules',
|
|
118
|
+
'templates',
|
|
119
|
+
'skills',
|
|
120
|
+
'LICENSE',
|
|
121
|
+
'README.md',
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
if (dryRun) {
|
|
125
|
+
return { canonicalRoot, version, staged: false };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
fs.rmSync(canonicalRoot, { recursive: true, force: true });
|
|
129
|
+
fs.mkdirSync(canonicalRoot, { recursive: true });
|
|
130
|
+
|
|
131
|
+
for (const rel of itemsToStage) {
|
|
132
|
+
const src = path.join(sourceRoot, rel);
|
|
133
|
+
if (fs.existsSync(src)) {
|
|
134
|
+
copyTree(src, path.join(canonicalRoot, rel));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const meta = {
|
|
139
|
+
name: '@fabersep/spec',
|
|
140
|
+
version,
|
|
141
|
+
installedAt: new Date().toISOString(),
|
|
142
|
+
skills: getSkillNames(canonicalRoot),
|
|
143
|
+
};
|
|
144
|
+
fs.writeFileSync(
|
|
145
|
+
path.join(canonicalRoot, META_FILENAME),
|
|
146
|
+
JSON.stringify(meta, null, 2) + '\n',
|
|
147
|
+
'utf8',
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
return { canonicalRoot, version, staged: true, skills: meta.skills };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function isSymlink(p) {
|
|
154
|
+
try {
|
|
155
|
+
return fs.lstatSync(p).isSymbolicLink();
|
|
156
|
+
} catch {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function isInside(child, parent) {
|
|
162
|
+
const rel = path.relative(parent, child);
|
|
163
|
+
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function hasOwnerMarker(dir) {
|
|
167
|
+
if (!fs.existsSync(dir)) return false;
|
|
168
|
+
if (fs.existsSync(path.join(dir, META_FILENAME))) return true;
|
|
169
|
+
const pluginJson = path.join(dir, 'plugin.json');
|
|
170
|
+
if (fs.existsSync(pluginJson)) {
|
|
171
|
+
try {
|
|
172
|
+
const parsed = JSON.parse(fs.readFileSync(pluginJson, 'utf8'));
|
|
173
|
+
if (parsed.name === 'faber-spec') return true;
|
|
174
|
+
} catch {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const skillMd = path.join(dir, 'SKILL.md');
|
|
179
|
+
if (fs.existsSync(skillMd) && path.basename(dir).startsWith('faber-')) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// A path is ours only when it (or, for a link, the folder it points to) carries the
|
|
186
|
+
// FaberSEP Spec marker, the faber-spec plugin manifest, or a faber-* skill. A user's
|
|
187
|
+
// own folder or link is never treated as ours.
|
|
188
|
+
function isManagedTarget(p, { canonicalRoot } = {}) {
|
|
189
|
+
if (isSymlink(p)) {
|
|
190
|
+
const target = path.resolve(path.dirname(p), fs.readlinkSync(p));
|
|
191
|
+
if (canonicalRoot && isInside(target, canonicalRoot)) return true;
|
|
192
|
+
let real;
|
|
193
|
+
try {
|
|
194
|
+
real = fs.realpathSync(p);
|
|
195
|
+
} catch {
|
|
196
|
+
return false; // dangling link outside our store: not ours
|
|
197
|
+
}
|
|
198
|
+
return hasOwnerMarker(real);
|
|
199
|
+
}
|
|
200
|
+
return hasOwnerMarker(p);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function linkTargetOf(p) {
|
|
204
|
+
return isSymlink(p) ? path.resolve(path.dirname(p), fs.readlinkSync(p)) : null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function linkOrCopyDir(src, dst, { dryRun = false, canonicalRoot } = {}) {
|
|
208
|
+
let backedUpTo = null;
|
|
209
|
+
if (isSymlink(dst) || fs.existsSync(dst)) {
|
|
210
|
+
if (isManagedTarget(dst, { canonicalRoot })) {
|
|
211
|
+
if (!dryRun) {
|
|
212
|
+
fs.rmSync(dst, { recursive: true, force: true });
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
backedUpTo = `${dst}.bak.${Date.now()}`;
|
|
216
|
+
if (!dryRun) {
|
|
217
|
+
fs.renameSync(dst, backedUpTo);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (dryRun) {
|
|
223
|
+
return { method: 'symlink', backedUpTo };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
227
|
+
try {
|
|
228
|
+
const type = process.platform === 'win32' ? 'junction' : 'dir';
|
|
229
|
+
fs.symlinkSync(src, dst, type);
|
|
230
|
+
return { method: 'symlink', backedUpTo };
|
|
231
|
+
} catch (err) {
|
|
232
|
+
if (err && (err.code === 'EPERM' || err.code === 'EACCES' || err.code === 'EXDEV')) {
|
|
233
|
+
copyTree(src, dst);
|
|
234
|
+
if (!fs.existsSync(path.join(dst, META_FILENAME))) {
|
|
235
|
+
fs.writeFileSync(
|
|
236
|
+
path.join(dst, META_FILENAME),
|
|
237
|
+
JSON.stringify({ name: '@fabersep/spec', version: getPackageVersion() }, null, 2) + '\n',
|
|
238
|
+
'utf8',
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
return { method: 'copy', backedUpTo };
|
|
242
|
+
}
|
|
243
|
+
throw err;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Remove faber-* entries in a per-skill tool folder that an earlier FaberSEP Spec
|
|
248
|
+
// install created but the current version no longer ships. Only links into our own
|
|
249
|
+
// store (or linked checkout) and copies carrying our marker are touched, so skills
|
|
250
|
+
// from other packages that share the faber- prefix stay in place.
|
|
251
|
+
function removeStaleSkills(dir, currentSkills, { roots, dryRun }) {
|
|
252
|
+
if (!fs.existsSync(dir)) return [];
|
|
253
|
+
const keep = new Set(currentSkills);
|
|
254
|
+
const removed = [];
|
|
255
|
+
for (const name of fs.readdirSync(dir)) {
|
|
256
|
+
if (!name.startsWith('faber-') || keep.has(name)) continue;
|
|
257
|
+
const p = path.join(dir, name);
|
|
258
|
+
const target = linkTargetOf(p);
|
|
259
|
+
const ours = target
|
|
260
|
+
? roots.some((root) => isInside(target, path.join(root, 'skills')))
|
|
261
|
+
: fs.existsSync(path.join(p, META_FILENAME));
|
|
262
|
+
if (!ours) continue;
|
|
263
|
+
if (!dryRun) fs.rmSync(p, { recursive: true, force: true });
|
|
264
|
+
removed.push(p);
|
|
265
|
+
}
|
|
266
|
+
return removed;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function installEngines({
|
|
270
|
+
engines,
|
|
271
|
+
userHome = getUserHome(),
|
|
272
|
+
sourceRoot = PACKAGE_ROOT,
|
|
273
|
+
linkDev = false,
|
|
274
|
+
dryRun = false,
|
|
275
|
+
} = {}) {
|
|
276
|
+
const allDefs = new Map(getEngineDefs(userHome).map((e) => [e.id, e]));
|
|
277
|
+
const selectedIds = engines && engines.length > 0 ? engines : [];
|
|
278
|
+
for (const id of selectedIds) {
|
|
279
|
+
if (!allDefs.has(id)) {
|
|
280
|
+
throw new Error(`Unknown engine "${id}". Supported: ${[...allDefs.keys()].join(', ')}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const effectiveRoot = linkDev
|
|
285
|
+
? path.resolve(sourceRoot)
|
|
286
|
+
: stageCanonicalInstall({ userHome, sourceRoot, dryRun }).canonicalRoot;
|
|
287
|
+
|
|
288
|
+
const skills = getSkillNames(linkDev ? effectiveRoot : sourceRoot);
|
|
289
|
+
const canonicalRoot = getCanonicalRoot(userHome);
|
|
290
|
+
const results = [];
|
|
291
|
+
|
|
292
|
+
for (const id of selectedIds) {
|
|
293
|
+
const def = allDefs.get(id);
|
|
294
|
+
if (def.mode === 'plugin') {
|
|
295
|
+
const outcome = linkOrCopyDir(effectiveRoot, def.targetPath, { dryRun, canonicalRoot });
|
|
296
|
+
results.push({
|
|
297
|
+
engine: id,
|
|
298
|
+
label: def.label,
|
|
299
|
+
mode: 'plugin',
|
|
300
|
+
targets: [def.targetPath],
|
|
301
|
+
method: outcome.method,
|
|
302
|
+
backedUpTo: outcome.backedUpTo,
|
|
303
|
+
});
|
|
304
|
+
} else {
|
|
305
|
+
const targets = [];
|
|
306
|
+
let method = 'symlink';
|
|
307
|
+
const backups = [];
|
|
308
|
+
for (const skill of skills) {
|
|
309
|
+
const srcSkill = path.join(effectiveRoot, 'skills', skill);
|
|
310
|
+
const dstSkill = path.join(def.targetPath, skill);
|
|
311
|
+
const outcome = linkOrCopyDir(srcSkill, dstSkill, { dryRun, canonicalRoot });
|
|
312
|
+
targets.push(dstSkill);
|
|
313
|
+
method = outcome.method;
|
|
314
|
+
if (outcome.backedUpTo) backups.push(outcome.backedUpTo);
|
|
315
|
+
}
|
|
316
|
+
const staleRemoved = removeStaleSkills(def.targetPath, skills, {
|
|
317
|
+
roots: [canonicalRoot, effectiveRoot],
|
|
318
|
+
dryRun,
|
|
319
|
+
});
|
|
320
|
+
results.push({
|
|
321
|
+
engine: id,
|
|
322
|
+
label: def.label,
|
|
323
|
+
mode: 'skills',
|
|
324
|
+
targets,
|
|
325
|
+
method,
|
|
326
|
+
backedUpTo: backups.length > 0 ? backups : null,
|
|
327
|
+
staleRemoved,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return {
|
|
333
|
+
version: getPackageVersion(),
|
|
334
|
+
canonicalRoot: effectiveRoot,
|
|
335
|
+
skills,
|
|
336
|
+
dryRun,
|
|
337
|
+
results,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export function getStatus({ userHome = getUserHome() } = {}) {
|
|
342
|
+
const canonicalRoot = getCanonicalRoot(userHome);
|
|
343
|
+
const metaPath = path.join(canonicalRoot, META_FILENAME);
|
|
344
|
+
let meta = null;
|
|
345
|
+
if (fs.existsSync(metaPath)) {
|
|
346
|
+
try {
|
|
347
|
+
meta = JSON.parse(fs.readFileSync(metaPath, 'utf8'));
|
|
348
|
+
} catch {
|
|
349
|
+
meta = null;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const expectedSkills = meta?.skills || getSkillNames(PACKAGE_ROOT);
|
|
354
|
+
const owned = (p) => (isSymlink(p) || fs.existsSync(p)) && isManagedTarget(p, { canonicalRoot });
|
|
355
|
+
const present = (p) => isSymlink(p) || fs.existsSync(p);
|
|
356
|
+
const linkedRoots = new Set();
|
|
357
|
+
const engines = detectEngines(userHome).map((engine) => {
|
|
358
|
+
if (engine.mode === 'plugin') {
|
|
359
|
+
const installed = owned(engine.targetPath);
|
|
360
|
+
const linkTarget = linkTargetOf(engine.targetPath);
|
|
361
|
+
if (installed && linkTarget && !isInside(linkTarget, canonicalRoot)) linkedRoots.add(linkTarget);
|
|
362
|
+
return {
|
|
363
|
+
...engine,
|
|
364
|
+
installed,
|
|
365
|
+
unmanaged: !installed && present(engine.targetPath),
|
|
366
|
+
linkTarget,
|
|
367
|
+
installedSkills: installed ? expectedSkills : [],
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
const installedSkills = [];
|
|
371
|
+
const unmanagedSkills = [];
|
|
372
|
+
for (const skill of expectedSkills) {
|
|
373
|
+
const p = path.join(engine.targetPath, skill);
|
|
374
|
+
if (owned(p)) {
|
|
375
|
+
installedSkills.push(skill);
|
|
376
|
+
const t = linkTargetOf(p);
|
|
377
|
+
if (t && !isInside(t, canonicalRoot)) linkedRoots.add(path.dirname(path.dirname(t)));
|
|
378
|
+
} else if (present(p)) {
|
|
379
|
+
unmanagedSkills.push(skill);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
...engine,
|
|
384
|
+
installed: installedSkills.length > 0,
|
|
385
|
+
unmanaged: installedSkills.length === 0 && unmanagedSkills.length > 0,
|
|
386
|
+
unmanagedSkills,
|
|
387
|
+
linkTarget: null,
|
|
388
|
+
installedSkills,
|
|
389
|
+
};
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
const linkedRoot = linkedRoots.size > 0 ? [...linkedRoots][0] : null;
|
|
393
|
+
let linkedVersion = null;
|
|
394
|
+
if (linkedRoot) {
|
|
395
|
+
try {
|
|
396
|
+
linkedVersion = JSON.parse(fs.readFileSync(path.join(linkedRoot, 'package.json'), 'utf8')).version;
|
|
397
|
+
} catch {
|
|
398
|
+
linkedVersion = null;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return {
|
|
403
|
+
canonicalRoot,
|
|
404
|
+
canonicalExists: fs.existsSync(canonicalRoot),
|
|
405
|
+
installedVersion: meta?.version || null,
|
|
406
|
+
linkedRoot,
|
|
407
|
+
linkedVersion,
|
|
408
|
+
packageVersion: getPackageVersion(),
|
|
409
|
+
skills: expectedSkills,
|
|
410
|
+
engines,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export function uninstallEngines({
|
|
415
|
+
engines,
|
|
416
|
+
userHome = getUserHome(),
|
|
417
|
+
removeCanonical = true,
|
|
418
|
+
dryRun = false,
|
|
419
|
+
} = {}) {
|
|
420
|
+
const allDefs = getEngineDefs(userHome);
|
|
421
|
+
const targetIds = engines && engines.length > 0 ? new Set(engines) : new Set(allDefs.map((e) => e.id));
|
|
422
|
+
const canonicalRoot = getCanonicalRoot(userHome);
|
|
423
|
+
const skillNames = new Set([
|
|
424
|
+
...getSkillNames(PACKAGE_ROOT),
|
|
425
|
+
...(fs.existsSync(canonicalRoot) ? getSkillNames(canonicalRoot) : []),
|
|
426
|
+
]);
|
|
427
|
+
|
|
428
|
+
const removed = [];
|
|
429
|
+
|
|
430
|
+
for (const def of allDefs) {
|
|
431
|
+
if (!targetIds.has(def.id)) continue;
|
|
432
|
+
if (def.mode === 'plugin') {
|
|
433
|
+
if ((isSymlink(def.targetPath) || fs.existsSync(def.targetPath)) && isManagedTarget(def.targetPath, { canonicalRoot })) {
|
|
434
|
+
if (!dryRun) {
|
|
435
|
+
fs.rmSync(def.targetPath, { recursive: true, force: true });
|
|
436
|
+
}
|
|
437
|
+
removed.push({ engine: def.id, label: def.label, path: def.targetPath });
|
|
438
|
+
}
|
|
439
|
+
} else {
|
|
440
|
+
for (const skill of skillNames) {
|
|
441
|
+
const p = path.join(def.targetPath, skill);
|
|
442
|
+
if ((isSymlink(p) || fs.existsSync(p)) && isManagedTarget(p, { canonicalRoot })) {
|
|
443
|
+
if (!dryRun) {
|
|
444
|
+
fs.rmSync(p, { recursive: true, force: true });
|
|
445
|
+
}
|
|
446
|
+
removed.push({ engine: def.id, label: def.label, path: p });
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
let removedCanonical = false;
|
|
453
|
+
const remainingInstalled =
|
|
454
|
+
engines && engines.length > 0
|
|
455
|
+
? allDefs.some((def) => {
|
|
456
|
+
if (targetIds.has(def.id)) return false;
|
|
457
|
+
const ours = (p) => (isSymlink(p) || fs.existsSync(p)) && isManagedTarget(p, { canonicalRoot });
|
|
458
|
+
if (def.mode === 'plugin') return ours(def.targetPath);
|
|
459
|
+
return [...skillNames].some((skill) => ours(path.join(def.targetPath, skill)));
|
|
460
|
+
})
|
|
461
|
+
: false;
|
|
462
|
+
|
|
463
|
+
if (removeCanonical && !remainingInstalled && fs.existsSync(canonicalRoot)) {
|
|
464
|
+
if (!dryRun) {
|
|
465
|
+
fs.rmSync(canonicalRoot, { recursive: true, force: true });
|
|
466
|
+
}
|
|
467
|
+
removedCanonical = true;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
return { removed, removedCanonical, canonicalRoot, dryRun };
|
|
471
|
+
}
|
package/src/prompt.mjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as readline from 'node:readline';
|
|
2
|
+
|
|
3
|
+
const ESC = '\x1b';
|
|
4
|
+
const CYAN = `${ESC}[36m`;
|
|
5
|
+
const GREEN = `${ESC}[32m`;
|
|
6
|
+
const DIM = `${ESC}[2m`;
|
|
7
|
+
const BOLD = `${ESC}[1m`;
|
|
8
|
+
const RESET = `${ESC}[0m`;
|
|
9
|
+
|
|
10
|
+
function useColor() {
|
|
11
|
+
return Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function fmt(code, text) {
|
|
15
|
+
return useColor() ? `${code}${text}${RESET}` : text;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Zero-dependency interactive checkbox prompt for Node.js TTYs.
|
|
20
|
+
* items: Array<{ id: string, label: string, hint?: string, checked: boolean }>
|
|
21
|
+
* Returns selected ids or null if cancelled.
|
|
22
|
+
*/
|
|
23
|
+
export function promptMultiSelect({ title, subtitle, items }) {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
const stdin = process.stdin;
|
|
26
|
+
const stdout = process.stdout;
|
|
27
|
+
const state = items.map((item) => ({ ...item }));
|
|
28
|
+
let cursor = 0;
|
|
29
|
+
let renderedLines = 0;
|
|
30
|
+
|
|
31
|
+
function render() {
|
|
32
|
+
if (renderedLines > 0) {
|
|
33
|
+
stdout.write(`${ESC}[${renderedLines}A${ESC}[0J`);
|
|
34
|
+
}
|
|
35
|
+
const lines = [];
|
|
36
|
+
lines.push(fmt(BOLD, title));
|
|
37
|
+
if (subtitle) {
|
|
38
|
+
lines.push(fmt(DIM, subtitle));
|
|
39
|
+
}
|
|
40
|
+
lines.push('');
|
|
41
|
+
for (let i = 0; i < state.length; i++) {
|
|
42
|
+
const item = state[i];
|
|
43
|
+
const isCurrent = i === cursor;
|
|
44
|
+
const pointer = isCurrent ? fmt(CYAN, '>') : ' ';
|
|
45
|
+
const box = item.checked ? fmt(GREEN, '[x]') : fmt(DIM, '[ ]');
|
|
46
|
+
const label = isCurrent ? fmt(BOLD, item.label.padEnd(23)) : item.label.padEnd(23);
|
|
47
|
+
const hint = item.hint ? fmt(DIM, item.hint) : '';
|
|
48
|
+
lines.push(` ${pointer} ${box} ${label} ${hint}`.trimEnd());
|
|
49
|
+
}
|
|
50
|
+
lines.push('');
|
|
51
|
+
const selectedCount = state.filter((s) => s.checked).length;
|
|
52
|
+
lines.push(
|
|
53
|
+
fmt(
|
|
54
|
+
DIM,
|
|
55
|
+
` ${selectedCount} selected • ↑/↓ move • Space toggle • a toggle all • Enter install • q cancel`,
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
stdout.write(lines.join('\n') + '\n');
|
|
59
|
+
renderedLines = lines.length;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function cleanup() {
|
|
63
|
+
stdin.removeListener('keypress', onKeypress);
|
|
64
|
+
if (stdin.isTTY) {
|
|
65
|
+
stdin.setRawMode(false);
|
|
66
|
+
}
|
|
67
|
+
stdin.pause();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function onKeypress(str, key) {
|
|
71
|
+
if (!key) return;
|
|
72
|
+
if ((key.ctrl && key.name === 'c') || key.name === 'escape' || str === 'q') {
|
|
73
|
+
cleanup();
|
|
74
|
+
stdout.write('\n');
|
|
75
|
+
resolve(null);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (key.name === 'up' || str === 'k') {
|
|
79
|
+
cursor = (cursor - 1 + state.length) % state.length;
|
|
80
|
+
render();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (key.name === 'down' || str === 'j') {
|
|
84
|
+
cursor = (cursor + 1) % state.length;
|
|
85
|
+
render();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (key.name === 'space' || str === ' ') {
|
|
89
|
+
state[cursor].checked = !state[cursor].checked;
|
|
90
|
+
render();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (str === 'a') {
|
|
94
|
+
const allChecked = state.every((s) => s.checked);
|
|
95
|
+
for (const item of state) item.checked = !allChecked;
|
|
96
|
+
render();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (key.name === 'return' || key.name === 'enter') {
|
|
100
|
+
cleanup();
|
|
101
|
+
stdout.write('\n');
|
|
102
|
+
resolve(state.filter((s) => s.checked).map((s) => s.id));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
readline.emitKeypressEvents(stdin);
|
|
107
|
+
if (stdin.isTTY) {
|
|
108
|
+
stdin.setRawMode(true);
|
|
109
|
+
}
|
|
110
|
+
stdin.resume();
|
|
111
|
+
stdin.on('keypress', onKeypress);
|
|
112
|
+
render();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: project.architecture
|
|
3
|
+
type: architecture
|
|
4
|
+
status: draft # draft | in_review | verified | stale | deprecated
|
|
5
|
+
last_updated: YYYY-MM-DD
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# <Project Name> — Architecture Guide
|
|
9
|
+
|
|
10
|
+
> **Purpose:** Documents the verified technical architecture of the repository — runtime environment, module boundaries, key data flows, external interfaces, and architectural invariants. Grounded strictly in codebase reality.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 1. System Overview & Runtime Topology
|
|
15
|
+
|
|
16
|
+
Brief description of how the system runs (single CLI/library, local stdio MCP server, client-server web app, multi-tier monorepo, etc.), its primary language/runtime, and external dependencies.
|
|
17
|
+
|
|
18
|
+
```mermaid
|
|
19
|
+
flowchart TD
|
|
20
|
+
Entry["Entry Point (CLI / MCP / API / UI)"] --> Core["Core Domain / Engine"]
|
|
21
|
+
Core --> Storage["Local Files / Cache / Database / External APIs"]
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 2. Module Boundaries
|
|
27
|
+
|
|
28
|
+
> Focus on high-level module responsibilities and allowed dependencies; avoid embedding full file trees that drift quickly.
|
|
29
|
+
|
|
30
|
+
| Module / Directory | Responsibility | Allowed Dependencies | Notes |
|
|
31
|
+
| :--- | :--- | :--- | :--- |
|
|
32
|
+
| `<path>` | [Single clear responsibility] | [Internal/external modules] | [Constraints or entry points] |
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 3. Core Data & Execution Flows
|
|
37
|
+
|
|
38
|
+
Trace the 1–3 most important end-to-end execution paths through the codebase (using exact module/file names verified from source).
|
|
39
|
+
|
|
40
|
+
### Flow 1: <Primary Pipeline / Request Flow>
|
|
41
|
+
```mermaid
|
|
42
|
+
sequenceDiagram
|
|
43
|
+
participant Caller
|
|
44
|
+
participant Entry as Entry Module
|
|
45
|
+
participant Core as Core Module
|
|
46
|
+
participant Out as Output / Storage
|
|
47
|
+
Caller->>Entry: Invoke command / request
|
|
48
|
+
Entry->>Core: Validate & execute
|
|
49
|
+
Core->>Out: Persist / format result
|
|
50
|
+
Out-->>Caller: Structured response
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 4. Public Interfaces & Contracts
|
|
56
|
+
|
|
57
|
+
Document the external surfaces that users or other tools rely on (keep only the subsections that apply):
|
|
58
|
+
|
|
59
|
+
- **CLI Commands & Flags:** [Command names, key options, exit codes]
|
|
60
|
+
- **MCP Tools / Resources / Prompts:** [Tool names, inputs, outputs]
|
|
61
|
+
- **Programmatic API / Exports:** [Main exported functions/types]
|
|
62
|
+
- **HTTP / Event Contracts / Schemas:** [Endpoints, JSON schemas, versioned formats]
|
|
63
|
+
- **Storage / Artifact Formats:** [On-disk cache, config files, database schema]
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 5. Cross-Cutting Concerns
|
|
68
|
+
|
|
69
|
+
| Concern | Status | Implementation / Approach | Location |
|
|
70
|
+
| :--- | :--- | :--- | :--- |
|
|
71
|
+
| **Error Handling** | `[Implemented / Partial / None / N/A]` | [Strategy] | `<path>` |
|
|
72
|
+
| **Configuration & Defaults** | `[Implemented / Partial / None / N/A]` | [Strategy] | `<path>` |
|
|
73
|
+
| **Caching & Incrementality** | `[Implemented / Partial / None / N/A]` | [Strategy] | `<path>` |
|
|
74
|
+
| **Security & Privacy** | `[Implemented / Partial / None / N/A]` | [Strategy] | `<path>` |
|
|
75
|
+
| **Logging & Diagnostics** | `[Implemented / Partial / None / N/A]` | [Strategy] | `<path>` |
|
|
76
|
+
| **Testing & Quality Gates** | `[Implemented / Partial / None / N/A]` | [Test runner, golden tests, CI] | `<path>` |
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 6. Architectural Invariants & Anti-Patterns
|
|
81
|
+
|
|
82
|
+
### Invariants (Must Hold)
|
|
83
|
+
- [e.g., Zero network calls during local scan; strict TypeScript compilation; schema compatibility.]
|
|
84
|
+
|
|
85
|
+
### Prohibited Practices
|
|
86
|
+
- ❌ **[Anti-pattern 1]:** [What to avoid and why]
|
|
87
|
+
- ❌ **[Anti-pattern 2]:** [What to avoid and why]
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 7. Technical Debt & Open Architectural Questions
|
|
92
|
+
|
|
93
|
+
- **GAP-01:** [Known architectural debt, missing coverage, or unresolved scaling question]
|