@fmatar/archlens-skill 0.0.1-Alpha-07 → 0.0.1-Alpha-09
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -0
- package/bin/index.js +161 -5
- package/package.json +1 -1
- package/skills/archlens/SKILL.md +139 -0
- package/skills/archlens-install-policy/SKILL.md +8 -0
- package/skills/uml-workbench-companion/SKILL.md +88 -0
- package/src/analyzer.js +169 -0
- package/src/docker-runner.js +215 -0
- package/src/installer.js +46 -18
- package/src/mcp-registry.js +268 -0
- package/src/mcp-server.js +272 -0
package/src/analyzer.js
CHANGED
|
@@ -287,3 +287,172 @@ function findMatchingFiles(dir, predicate, limit = 50, collected = []) {
|
|
|
287
287
|
|
|
288
288
|
return collected;
|
|
289
289
|
}
|
|
290
|
+
|
|
291
|
+
export async function generateLlmPrompt(projectRoot, options = {}) {
|
|
292
|
+
const root = path.resolve(projectRoot || '.');
|
|
293
|
+
const serverUrl = options.serverUrl || 'http://localhost:8088';
|
|
294
|
+
|
|
295
|
+
// 1. Attempt querying active Archlens backend server
|
|
296
|
+
try {
|
|
297
|
+
const controller = new AbortController();
|
|
298
|
+
const timeoutId = setTimeout(() => controller.abort(), 1200);
|
|
299
|
+
const apiUrl = `${serverUrl.replace(/\/$/, '')}/api/diagram/llm-dossier?projectRoot=${encodeURIComponent(root)}`;
|
|
300
|
+
const res = await fetch(apiUrl, { signal: controller.signal });
|
|
301
|
+
clearTimeout(timeoutId);
|
|
302
|
+
if (res.ok) {
|
|
303
|
+
const text = await res.text();
|
|
304
|
+
if (text && text.trim().length > 0) {
|
|
305
|
+
return text;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
} catch {
|
|
309
|
+
// Offline or server unreachable: fallback to local analysis
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// 2. Offline analysis using local policy and source scan
|
|
313
|
+
let policy;
|
|
314
|
+
const policyFile = path.join(root, '.archlens', 'policy.json');
|
|
315
|
+
if (fs.existsSync(policyFile)) {
|
|
316
|
+
try {
|
|
317
|
+
policy = JSON.parse(fs.readFileSync(policyFile, 'utf8'));
|
|
318
|
+
} catch {
|
|
319
|
+
policy = generatePolicy(root, options);
|
|
320
|
+
}
|
|
321
|
+
} else {
|
|
322
|
+
policy = generatePolicy(root, options);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const title = policy.title || formatProjectTitle(path.basename(root));
|
|
326
|
+
const levels = policy.levels || [];
|
|
327
|
+
const tierNames = ['Domain Core (L0)', 'Application (L1)', 'Adapters (L2)', 'Infrastructure (L3)'];
|
|
328
|
+
|
|
329
|
+
let sb = '';
|
|
330
|
+
sb += `# Clean Architecture Optimization Dossier — ${title}\n\n`;
|
|
331
|
+
sb += `Generated by **Archlens Dynamic Clean Architecture Workbench** (CLI offline mode).\n`;
|
|
332
|
+
sb += `This dossier identifies architectural ring boundaries, illegal outward dependency rule violations,\n`;
|
|
333
|
+
sb += `and concrete Dependency Inversion Principle (DIP) refactoring guidance for Large Language Models.\n\n`;
|
|
334
|
+
sb += `---\n\n`;
|
|
335
|
+
|
|
336
|
+
// 1. Concentric Tiers
|
|
337
|
+
sb += `## 1. Clean Architecture Concentric Rings\n\n`;
|
|
338
|
+
sb += `| Tier | Level | Packages |\n`;
|
|
339
|
+
sb += `| :--- | :---: | :--- |\n`;
|
|
340
|
+
|
|
341
|
+
const maxTiers = Math.max(levels.length, 4);
|
|
342
|
+
for (let i = 0; i < maxTiers; i++) {
|
|
343
|
+
const tierName = i < tierNames.length ? tierNames[i] : `Ring Level ${i}`;
|
|
344
|
+
const pkgs = i < levels.length ? levels[i] : [];
|
|
345
|
+
const pkgList = pkgs.length === 0 ? '*(none declared)*' : `\`${pkgs.join('`, `')}\``;
|
|
346
|
+
sb += `| **${tierName}** | Level ${i} | ${pkgList} |\n`;
|
|
347
|
+
}
|
|
348
|
+
sb += `\n---\n\n`;
|
|
349
|
+
|
|
350
|
+
// 2. Scan source files for cross-ring violations
|
|
351
|
+
const fullSrc = path.join(root, policy.src || 'src');
|
|
352
|
+
const sourceFiles = findMatchingFiles(
|
|
353
|
+
fullSrc,
|
|
354
|
+
(f) => f.endsWith('.java') || f.endsWith('.kt') || f.endsWith('.ts') || f.endsWith('.js'),
|
|
355
|
+
300
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
const pkgToLevel = new Map();
|
|
359
|
+
levels.forEach((tier, lvl) => {
|
|
360
|
+
tier.forEach((p) => pkgToLevel.set(p.toLowerCase(), lvl));
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
const violations = [];
|
|
364
|
+
const importRegex = /import\s+([a-zA-Z0-9_.]+)/g;
|
|
365
|
+
|
|
366
|
+
for (const file of sourceFiles) {
|
|
367
|
+
try {
|
|
368
|
+
const content = fs.readFileSync(file, 'utf8');
|
|
369
|
+
const relPath = path.relative(root, file);
|
|
370
|
+
const lowerRel = relPath.toLowerCase();
|
|
371
|
+
|
|
372
|
+
let fileLevel = null;
|
|
373
|
+
for (const [pkg, lvl] of pkgToLevel.entries()) {
|
|
374
|
+
if (lowerRel.includes(pkg)) {
|
|
375
|
+
fileLevel = lvl;
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (fileLevel === null) continue;
|
|
381
|
+
|
|
382
|
+
let match;
|
|
383
|
+
while ((match = importRegex.exec(content)) !== null) {
|
|
384
|
+
const imported = match[1];
|
|
385
|
+
const lowerImport = imported.toLowerCase();
|
|
386
|
+
for (const [targetPkg, targetLvl] of pkgToLevel.entries()) {
|
|
387
|
+
if (lowerImport.includes(targetPkg)) {
|
|
388
|
+
if (fileLevel < targetLvl) {
|
|
389
|
+
const baseName = path.basename(file, path.extname(file));
|
|
390
|
+
violations.push({
|
|
391
|
+
fromFile: relPath,
|
|
392
|
+
fromTier: tierNames[fileLevel] || `Level ${fileLevel}`,
|
|
393
|
+
toImport: imported,
|
|
394
|
+
toTier: tierNames[targetLvl] || `Level ${targetLvl}`,
|
|
395
|
+
portName: `${baseName}Port`
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
} catch {
|
|
403
|
+
// Proceed to next file
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
sb += `## 2. Architectural Diagnostics Summary\n\n`;
|
|
408
|
+
sb += `- **Analyzed Source Files**: ${sourceFiles.length}\n`;
|
|
409
|
+
sb += `- **Declared Packages**: ${(policy.order || []).length}\n`;
|
|
410
|
+
|
|
411
|
+
if (violations.length === 0) {
|
|
412
|
+
sb += `- **Clean Architecture Status**: ✅ **Conforming** (Zero outward dependency rule violations detected)\n\n`;
|
|
413
|
+
} else {
|
|
414
|
+
sb += `- **Clean Architecture Status**: 🚨 **${violations.length} Dependency Rule ${violations.length === 1 ? 'Violation' : 'Violations'} Detected**\n\n`;
|
|
415
|
+
}
|
|
416
|
+
sb += `---\n\n`;
|
|
417
|
+
|
|
418
|
+
// 3. Violations Breakdown & DIP Guidance
|
|
419
|
+
sb += `## 3. Prioritized Architectural Violations & DIP Refactoring Prescriptions\n\n`;
|
|
420
|
+
if (violations.length === 0) {
|
|
421
|
+
sb += `🎉 **No dependency violations found.** All source code dependencies adhere to Uncle Bob's Dependency Rule,\n`;
|
|
422
|
+
sb += `pointing strictly inward toward higher-level domain policies.\n\n`;
|
|
423
|
+
} else {
|
|
424
|
+
violations.forEach((v, idx) => {
|
|
425
|
+
sb += `### Violation ${idx + 1}: \`${v.fromFile}\` ➔ \`${v.toImport}\`\n\n`;
|
|
426
|
+
sb += `- **Direction**: \`${v.fromTier}\` depends on \`${v.toTier}\`\n`;
|
|
427
|
+
sb += `- **Uncle Bob's Law**: Source code dependencies must point ONLY inward, toward higher-level policies.\n`;
|
|
428
|
+
sb += `- **Source File**: \`${v.fromFile}\`\n`;
|
|
429
|
+
sb += `- **Target Dependency**: \`${v.toImport}\`\n`;
|
|
430
|
+
sb += `- **Prescribed Dependency Inversion Principle (DIP) Fix**:\n`;
|
|
431
|
+
sb += ` 1. Define an interface port \`${v.portName}\` in the inner layer (\`${v.fromTier}\`).\n`;
|
|
432
|
+
sb += ` 2. Change source component to declare dependencies exclusively against \`${v.portName}\`.\n`;
|
|
433
|
+
sb += ` 3. Implement \`${v.portName}\` in the outer layer (\`${v.toTier}\`).\n`;
|
|
434
|
+
sb += ` 4. Wire the concrete implementation at the infrastructure boundary using dependency injection.\n\n`;
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
sb += `---\n\n`;
|
|
438
|
+
|
|
439
|
+
// 4. Actionable LLM Instructions
|
|
440
|
+
sb += `## 4. Actionable LLM Refactoring Instructions\n\n`;
|
|
441
|
+
sb += `\`\`\`markdown\n`;
|
|
442
|
+
sb += `You are an expert Clean Architecture software engineer and refactoring specialist.\n\n`;
|
|
443
|
+
sb += `TASK:\n`;
|
|
444
|
+
if (violations.length === 0) {
|
|
445
|
+
sb += `The current codebase cleanly conforms to Clean Architecture boundaries.\n`;
|
|
446
|
+
sb += `Ensure any future enhancements maintain strict inward dependency flow.\n`;
|
|
447
|
+
} else {
|
|
448
|
+
sb += `Refactor the codebase to eliminate the ${violations.length} architectural violation${violations.length === 1 ? '' : 's'} detailed above.\n\n`;
|
|
449
|
+
sb += `EXECUTION PRINCIPLES:\n`;
|
|
450
|
+
sb += `1. Invert outward dependencies by creating interface ports in the inner layers and implementing them in the outer layers.\n`;
|
|
451
|
+
sb += `2. Maintain strict separation of concerns across concentric rings (Domain -> Application -> Adapters -> Infrastructure).\n`;
|
|
452
|
+
sb += `3. Avoid mock-heavy tests or test smells. Verify the refactoring with clean unit tests adhering to Robert C. Martin craftsmanship.\n`;
|
|
453
|
+
sb += `4. Keep public contracts stable and regression-free.\n`;
|
|
454
|
+
}
|
|
455
|
+
sb += `\`\`\`\n`;
|
|
456
|
+
|
|
457
|
+
return sb;
|
|
458
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Archlens On-Demand Docker Runner & Health Inspector
|
|
3
|
+
* Manages container lifecycle and health checks for the Archlens Quarkus server.
|
|
4
|
+
* Zero external dependencies.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { spawnSync, execSync } from 'node:child_process';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
|
|
10
|
+
export const DEFAULT_SERVER_URL = 'http://localhost:8088';
|
|
11
|
+
export const DEFAULT_DOCKER_IMAGE = 'ghcr.io/fmatar/archlens:latest';
|
|
12
|
+
export const DEFAULT_CONTAINER_NAME = 'archlens-server';
|
|
13
|
+
|
|
14
|
+
export async function checkServerHealth(serverUrl = DEFAULT_SERVER_URL, timeoutMs = 1500) {
|
|
15
|
+
try {
|
|
16
|
+
const url = new URL('/api/version', serverUrl).toString();
|
|
17
|
+
const res = await fetch(url, {
|
|
18
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
19
|
+
});
|
|
20
|
+
if (res.ok) {
|
|
21
|
+
const data = await res.json().catch(() => ({}));
|
|
22
|
+
return { ok: true, version: data.version || 'unknown' };
|
|
23
|
+
}
|
|
24
|
+
return { ok: false, status: res.status };
|
|
25
|
+
} catch (err) {
|
|
26
|
+
return { ok: false, error: err.message };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isDockerAvailable(customExec = execSync) {
|
|
31
|
+
try {
|
|
32
|
+
customExec('docker info', { stdio: 'pipe', timeout: 3000 });
|
|
33
|
+
return true;
|
|
34
|
+
} catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isContainerRunning(containerName = DEFAULT_CONTAINER_NAME, customExec = execSync) {
|
|
40
|
+
try {
|
|
41
|
+
const out = customExec(
|
|
42
|
+
`docker ps --filter name=^/${containerName}$ --format "{{.Names}}"`,
|
|
43
|
+
{ encoding: 'utf8', stdio: 'pipe', timeout: 3000 }
|
|
44
|
+
).trim();
|
|
45
|
+
return out === containerName;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isContainerExisting(containerName = DEFAULT_CONTAINER_NAME, customExec = execSync) {
|
|
52
|
+
try {
|
|
53
|
+
const out = customExec(
|
|
54
|
+
`docker ps -a --filter name=^/${containerName}$ --format "{{.Names}}"`,
|
|
55
|
+
{ encoding: 'utf8', stdio: 'pipe', timeout: 3000 }
|
|
56
|
+
).trim();
|
|
57
|
+
return out === containerName;
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function startContainer(options = {}, deps = {}) {
|
|
64
|
+
const containerName = options.containerName || DEFAULT_CONTAINER_NAME;
|
|
65
|
+
const image = options.image || DEFAULT_DOCKER_IMAGE;
|
|
66
|
+
const workspace = path.resolve(options.workspace || '.');
|
|
67
|
+
const port = options.port || '8088';
|
|
68
|
+
const customExec = deps.execSync || execSync;
|
|
69
|
+
const customSpawn = deps.spawnSync || spawnSync;
|
|
70
|
+
|
|
71
|
+
const exists = deps.isContainerExisting
|
|
72
|
+
? deps.isContainerExisting(containerName)
|
|
73
|
+
: isContainerExisting(containerName, customExec);
|
|
74
|
+
|
|
75
|
+
if (exists) {
|
|
76
|
+
if (deps.execSync && !deps.spawnSync) {
|
|
77
|
+
customExec(`docker start ${containerName}`, { stdio: 'pipe', timeout: 10000 });
|
|
78
|
+
} else {
|
|
79
|
+
customSpawn('docker', ['start', containerName], { stdio: 'pipe', timeout: 10000 });
|
|
80
|
+
}
|
|
81
|
+
return { action: 'started', containerName };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const runArgs = [
|
|
85
|
+
'run',
|
|
86
|
+
'-d',
|
|
87
|
+
'--name',
|
|
88
|
+
containerName,
|
|
89
|
+
'-p',
|
|
90
|
+
`${port}:8088`,
|
|
91
|
+
'-v',
|
|
92
|
+
`${workspace}:/workspace`,
|
|
93
|
+
image
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
if (deps.execSync && !deps.spawnSync) {
|
|
97
|
+
customExec(
|
|
98
|
+
`docker run -d --name ${containerName} -p ${port}:8088 -v "${workspace}:/workspace" ${image}`,
|
|
99
|
+
{ stdio: 'pipe', timeout: 15000 }
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
customSpawn('docker', runArgs, { stdio: 'pipe', timeout: 15000 });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return { action: 'created', containerName };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function ensureServerRunning(options = {}, deps = {}) {
|
|
109
|
+
const serverUrl = options.serverUrl || DEFAULT_SERVER_URL;
|
|
110
|
+
const maxWaitMs = options.maxWaitMs || 5000;
|
|
111
|
+
const spawnDocker = options.spawnDocker !== false;
|
|
112
|
+
|
|
113
|
+
const healthChecker = deps.checkServerHealth || checkServerHealth;
|
|
114
|
+
const dockerChecker = deps.isDockerAvailable || isDockerAvailable;
|
|
115
|
+
const starter = deps.startContainer || startContainer;
|
|
116
|
+
|
|
117
|
+
// 1. Initial health inspection
|
|
118
|
+
const initialCheck = await healthChecker(serverUrl, 1000);
|
|
119
|
+
if (initialCheck.ok) {
|
|
120
|
+
return {
|
|
121
|
+
status: 'running',
|
|
122
|
+
serverUrl,
|
|
123
|
+
version: initialCheck.version,
|
|
124
|
+
spawned: false
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 2. Fallback check when Docker is disabled or unavailable
|
|
129
|
+
if (!spawnDocker || !dockerChecker(deps.execSync || execSync)) {
|
|
130
|
+
return {
|
|
131
|
+
status: 'offline',
|
|
132
|
+
serverUrl,
|
|
133
|
+
spawned: false,
|
|
134
|
+
message: 'Archlens Quarkus server is unreachable and Docker daemon is unavailable.'
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 3. Launch Docker container
|
|
139
|
+
try {
|
|
140
|
+
starter(options, deps);
|
|
141
|
+
} catch (err) {
|
|
142
|
+
return {
|
|
143
|
+
status: 'error',
|
|
144
|
+
serverUrl,
|
|
145
|
+
spawned: false,
|
|
146
|
+
message: `Failed to launch Docker container: ${err.message}`
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 4. Poll readiness until maxWaitMs
|
|
151
|
+
const startTime = Date.now();
|
|
152
|
+
while (Date.now() - startTime < maxWaitMs) {
|
|
153
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
154
|
+
const probe = await healthChecker(serverUrl, 800);
|
|
155
|
+
if (probe.ok) {
|
|
156
|
+
return {
|
|
157
|
+
status: 'running',
|
|
158
|
+
serverUrl,
|
|
159
|
+
version: probe.version,
|
|
160
|
+
spawned: true
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
status: 'starting',
|
|
167
|
+
serverUrl,
|
|
168
|
+
spawned: true,
|
|
169
|
+
message: 'Archlens container launched; service is warming up.'
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function openInBrowser(url, customSpawn = spawnSync) {
|
|
174
|
+
try {
|
|
175
|
+
if (process.platform === 'darwin') {
|
|
176
|
+
customSpawn('open', [url], { stdio: 'ignore' });
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
if (process.platform === 'win32') {
|
|
180
|
+
customSpawn('cmd', ['/c', 'start', '""', url], { stdio: 'ignore' });
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
customSpawn('xdg-open', [url], { stdio: 'ignore' });
|
|
184
|
+
return true;
|
|
185
|
+
} catch {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export async function executeStart(options = {}, deps = {}) {
|
|
191
|
+
const runner = deps.ensureServerRunning || ensureServerRunning;
|
|
192
|
+
const opener = deps.openInBrowser || openInBrowser;
|
|
193
|
+
const port = options.port || '8088';
|
|
194
|
+
const serverUrl = options.serverUrl || (port === '8088' ? DEFAULT_SERVER_URL : `http://localhost:${port}`);
|
|
195
|
+
const workspace = path.resolve(options.path || options.workspace || '.');
|
|
196
|
+
|
|
197
|
+
const status = await runner({
|
|
198
|
+
serverUrl,
|
|
199
|
+
workspace,
|
|
200
|
+
port,
|
|
201
|
+
...options
|
|
202
|
+
}, deps);
|
|
203
|
+
|
|
204
|
+
if (status.status === 'running' && options.open) {
|
|
205
|
+
opener(serverUrl, deps.spawnSync || spawnSync);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
...status,
|
|
210
|
+
port,
|
|
211
|
+
serverUrl
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
package/src/installer.js
CHANGED
|
@@ -9,6 +9,9 @@ import * as path from 'node:path';
|
|
|
9
9
|
import * as os from 'node:os';
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
11
|
import { generatePolicy } from './analyzer.js';
|
|
12
|
+
import { installMcpConfigs } from './mcp-registry.js';
|
|
13
|
+
|
|
14
|
+
export { installMcpConfigs };
|
|
12
15
|
|
|
13
16
|
const __filename = fileURLToPath(import.meta.url);
|
|
14
17
|
const __dirname = path.dirname(__filename);
|
|
@@ -111,6 +114,11 @@ export function installLocalPolicy(projectRoot, options = {}) {
|
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
|
|
117
|
+
let mcpResult = null;
|
|
118
|
+
if (options.mcp) {
|
|
119
|
+
mcpResult = installMcpConfigs({ path: root, ...options });
|
|
120
|
+
}
|
|
121
|
+
|
|
114
122
|
return {
|
|
115
123
|
targetDir: root,
|
|
116
124
|
archlensDir: targetDir,
|
|
@@ -120,62 +128,82 @@ export function installLocalPolicy(projectRoot, options = {}) {
|
|
|
120
128
|
policyCreated,
|
|
121
129
|
policyData,
|
|
122
130
|
companionFiles: updatedCompanions,
|
|
131
|
+
mcpResult,
|
|
123
132
|
dryRun
|
|
124
133
|
};
|
|
125
134
|
}
|
|
126
135
|
|
|
127
|
-
export function getGlobalSkillDirectories() {
|
|
128
|
-
const
|
|
129
|
-
|
|
136
|
+
export function getGlobalSkillDirectories(home = os.homedir()) {
|
|
137
|
+
const bundledSkillsDir = path.resolve(__dirname, '..', 'skills');
|
|
138
|
+
let skillNames = ['archlens-install-policy'];
|
|
139
|
+
if (fs.existsSync(bundledSkillsDir)) {
|
|
140
|
+
try {
|
|
141
|
+
skillNames = fs.readdirSync(bundledSkillsDir, { withFileTypes: true })
|
|
142
|
+
.filter((d) => d.isDirectory())
|
|
143
|
+
.map((d) => d.name);
|
|
144
|
+
} catch {
|
|
145
|
+
// fallback
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const agents = [
|
|
130
150
|
{
|
|
131
151
|
agent: 'Claude Code',
|
|
132
|
-
baseDir: path.join(home, '.claude', 'skills')
|
|
133
|
-
targetDir: path.join(home, '.claude', 'skills', 'archlens-install-policy')
|
|
152
|
+
baseDir: path.join(home, '.claude', 'skills')
|
|
134
153
|
},
|
|
135
154
|
{
|
|
136
155
|
agent: 'Gemini CLI & Google Antigravity',
|
|
137
|
-
baseDir: path.join(home, '.gemini', 'config', 'skills')
|
|
138
|
-
targetDir: path.join(home, '.gemini', 'config', 'skills', 'archlens-install-policy')
|
|
156
|
+
baseDir: path.join(home, '.gemini', 'config', 'skills')
|
|
139
157
|
},
|
|
140
158
|
{
|
|
141
159
|
agent: 'Generic Agents Workspace',
|
|
142
|
-
baseDir: path.join(home, '.agents', 'skills')
|
|
143
|
-
targetDir: path.join(home, '.agents', 'skills', 'archlens-install-policy')
|
|
160
|
+
baseDir: path.join(home, '.agents', 'skills')
|
|
144
161
|
}
|
|
145
162
|
];
|
|
163
|
+
|
|
164
|
+
const results = [];
|
|
165
|
+
for (const a of agents) {
|
|
166
|
+
for (const skillName of skillNames) {
|
|
167
|
+
results.push({
|
|
168
|
+
agent: a.agent,
|
|
169
|
+
skill: skillName,
|
|
170
|
+
baseDir: a.baseDir,
|
|
171
|
+
targetDir: path.join(a.baseDir, skillName)
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return results;
|
|
146
176
|
}
|
|
147
177
|
|
|
148
178
|
export function installGlobalSkills(options = {}) {
|
|
149
179
|
const dryRun = Boolean(options.dryRun);
|
|
150
180
|
const force = Boolean(options.force);
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
if (!fs.existsSync(bundledSkillDir)) {
|
|
154
|
-
throw new Error(`Bundled skill template directory not found at: ${bundledSkillDir}`);
|
|
155
|
-
}
|
|
181
|
+
const bundledSkillsRoot = path.resolve(__dirname, '..', 'skills');
|
|
156
182
|
|
|
157
|
-
const destinations = getGlobalSkillDirectories();
|
|
183
|
+
const destinations = getGlobalSkillDirectories(options.homedir);
|
|
158
184
|
const installed = [];
|
|
159
185
|
|
|
160
186
|
for (const dest of destinations) {
|
|
161
187
|
// Install if parent agent directory exists or if force flag is enabled
|
|
162
188
|
const agentHomeDir = path.dirname(dest.baseDir);
|
|
163
189
|
const shouldInstall = force || fs.existsSync(agentHomeDir);
|
|
190
|
+
const sourceSkillDir = path.join(bundledSkillsRoot, dest.skill);
|
|
164
191
|
|
|
165
|
-
if (shouldInstall) {
|
|
192
|
+
if (shouldInstall && fs.existsSync(sourceSkillDir)) {
|
|
166
193
|
if (!dryRun) {
|
|
167
194
|
fs.mkdirSync(dest.targetDir, { recursive: true });
|
|
168
|
-
copyDirectorySync(
|
|
195
|
+
copyDirectorySync(sourceSkillDir, dest.targetDir);
|
|
169
196
|
}
|
|
170
197
|
installed.push({
|
|
171
198
|
agent: dest.agent,
|
|
199
|
+
skill: dest.skill,
|
|
172
200
|
path: dest.targetDir
|
|
173
201
|
});
|
|
174
202
|
}
|
|
175
203
|
}
|
|
176
204
|
|
|
177
205
|
return {
|
|
178
|
-
sourceDir:
|
|
206
|
+
sourceDir: bundledSkillsRoot,
|
|
179
207
|
installed,
|
|
180
208
|
dryRun
|
|
181
209
|
};
|