@fmatar/archlens-skill 0.1.0-Beta-11 → 1.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/README.md +33 -10
- package/bin/index.js +14 -2
- package/llms.txt +17 -3
- package/package.json +1 -1
- package/skills/archlens/SKILL.md +14 -1
- package/src/analyzer.js +135 -0
- package/src/checker.js +179 -20
- package/src/docker-runner.js +108 -5
- package/src/mcp-registry.js +185 -7
- package/src/mcp-server.js +339 -8
package/src/mcp-server.js
CHANGED
|
@@ -13,10 +13,24 @@ import { fileURLToPath } from 'node:url';
|
|
|
13
13
|
import { ARCHLENS_TOOL_SCHEMAS } from './mcp-registry.js';
|
|
14
14
|
import { ensureServerRunning, DEFAULT_SERVER_URL } from './docker-runner.js';
|
|
15
15
|
import { generateLlmPrompt, generatePolicy } from './analyzer.js';
|
|
16
|
+
import { checkArchitecture } from './checker.js';
|
|
16
17
|
|
|
17
18
|
const __filename = fileURLToPath(import.meta.url);
|
|
18
19
|
const __dirname = path.dirname(__filename);
|
|
19
20
|
|
|
21
|
+
function getPackageVersion() {
|
|
22
|
+
try {
|
|
23
|
+
const pkgPath = path.resolve(__dirname, '..', 'package.json');
|
|
24
|
+
if (fs.existsSync(pkgPath)) {
|
|
25
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
26
|
+
if (pkg.version) return pkg.version;
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
// ignore
|
|
30
|
+
}
|
|
31
|
+
return '1.1.0';
|
|
32
|
+
}
|
|
33
|
+
|
|
20
34
|
export function getMcpToolsList() {
|
|
21
35
|
return Object.values(ARCHLENS_TOOL_SCHEMAS).map((tool) => ({
|
|
22
36
|
name: tool.name,
|
|
@@ -33,20 +47,64 @@ export function getMcpResourcesList() {
|
|
|
33
47
|
description:
|
|
34
48
|
'Comprehensive Clean Architecture guide, concentric ring hierarchy, CLI commands, fitness invariants, and refactoring protocols for LLMs.',
|
|
35
49
|
mimeType: 'text/markdown'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
uri: 'archlens://policy',
|
|
53
|
+
name: 'Archlens Concentric Ring Policy (.archlens/policy.json)',
|
|
54
|
+
description: 'Active Clean Architecture concentric ring policy and fitness thresholds.',
|
|
55
|
+
mimeType: 'application/json'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
uri: 'archlens://fitness',
|
|
59
|
+
name: 'Archlens Architectural Fitness Evaluation',
|
|
60
|
+
description:
|
|
61
|
+
'Current Architectural Fitness Index (AFI), Screaming Architecture Score (SAS), and Main Sequence Distance evaluation.',
|
|
62
|
+
mimeType: 'application/json'
|
|
63
|
+
}
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function getMcpPromptsList() {
|
|
68
|
+
return [
|
|
69
|
+
{
|
|
70
|
+
name: 'architectural-review',
|
|
71
|
+
description:
|
|
72
|
+
'Generate a comprehensive Clean Architecture & Robert C. Martin Main Sequence review prompt for a target workspace.',
|
|
73
|
+
arguments: [
|
|
74
|
+
{
|
|
75
|
+
name: 'projectRoot',
|
|
76
|
+
description: 'Absolute or relative path to the target project directory. Defaults to current directory.',
|
|
77
|
+
required: false
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'dip-refactoring-guide',
|
|
83
|
+
description:
|
|
84
|
+
'Synthesize a surgical Dependency Inversion Principle (DIP) prompt to decouple an inner-ring caller from an outer-ring concrete class.',
|
|
85
|
+
arguments: [
|
|
86
|
+
{ name: 'fromClass', description: 'Fully qualified caller class name', required: true },
|
|
87
|
+
{ name: 'toClass', description: 'Fully qualified target concrete class name', required: true },
|
|
88
|
+
{
|
|
89
|
+
name: 'projectRoot',
|
|
90
|
+
description: 'Absolute or relative path to the target project directory. Defaults to current directory.',
|
|
91
|
+
required: false
|
|
92
|
+
}
|
|
93
|
+
]
|
|
36
94
|
}
|
|
37
95
|
];
|
|
38
96
|
}
|
|
39
97
|
|
|
40
98
|
export function readMcpResource(uri, options = {}, deps = {}) {
|
|
99
|
+
const projectRoot = path.resolve(options.path || '.');
|
|
100
|
+
const fileReader = deps.readFileSync || fs.readFileSync;
|
|
101
|
+
const fileExists = deps.existsSync || fs.existsSync;
|
|
102
|
+
|
|
41
103
|
if (uri === 'archlens://llms.txt') {
|
|
42
|
-
const projectRoot = path.resolve(options.path || '.');
|
|
43
104
|
const localLlmsPath = path.join(projectRoot, 'llms.txt');
|
|
44
105
|
const cliLlmsPath = path.resolve(__dirname, '..', 'llms.txt');
|
|
45
106
|
const rootLlmsPath = path.resolve(__dirname, '..', '..', 'llms.txt');
|
|
46
107
|
|
|
47
|
-
const fileReader = deps.readFileSync || fs.readFileSync;
|
|
48
|
-
const fileExists = deps.existsSync || fs.existsSync;
|
|
49
|
-
|
|
50
108
|
let content = '';
|
|
51
109
|
if (fileExists(localLlmsPath)) {
|
|
52
110
|
content = fileReader(localLlmsPath, 'utf8');
|
|
@@ -69,6 +127,36 @@ export function readMcpResource(uri, options = {}, deps = {}) {
|
|
|
69
127
|
};
|
|
70
128
|
}
|
|
71
129
|
|
|
130
|
+
if (uri === 'archlens://policy') {
|
|
131
|
+
const policyFile = path.join(projectRoot, '.archlens', 'policy.json');
|
|
132
|
+
const policyText = fileExists(policyFile)
|
|
133
|
+
? fileReader(policyFile, 'utf8')
|
|
134
|
+
: JSON.stringify(generatePolicy(projectRoot, options), null, 2);
|
|
135
|
+
return {
|
|
136
|
+
contents: [
|
|
137
|
+
{
|
|
138
|
+
uri,
|
|
139
|
+
mimeType: 'application/json',
|
|
140
|
+
text: policyText
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (uri === 'archlens://fitness') {
|
|
147
|
+
const checker = deps.checkArchitecture || checkArchitecture;
|
|
148
|
+
const report = checker(projectRoot, { detectCycles: true });
|
|
149
|
+
return {
|
|
150
|
+
contents: [
|
|
151
|
+
{
|
|
152
|
+
uri,
|
|
153
|
+
mimeType: 'application/json',
|
|
154
|
+
text: JSON.stringify(report.fitness || report, null, 2)
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
72
160
|
throw new Error(`Resource not found: ${uri}`);
|
|
73
161
|
}
|
|
74
162
|
|
|
@@ -175,8 +263,10 @@ export async function executeToolCall(toolName, args = {}, options = {}, deps =
|
|
|
175
263
|
|
|
176
264
|
if (isOnline) {
|
|
177
265
|
try {
|
|
178
|
-
const query = new URLSearchParams({
|
|
179
|
-
const res = await (deps.fetch || fetch)(
|
|
266
|
+
const query = new URLSearchParams({ projectRoot });
|
|
267
|
+
const res = await (deps.fetch || fetch)(
|
|
268
|
+
`${serverUrl}/api/snapshots/${encodeURIComponent(snapshotId)}?${query}`
|
|
269
|
+
);
|
|
180
270
|
if (res.ok) {
|
|
181
271
|
const json = await res.json();
|
|
182
272
|
return { content: [{ type: 'text', text: JSON.stringify(json, null, 2) }] };
|
|
@@ -203,6 +293,204 @@ export async function executeToolCall(toolName, args = {}, options = {}, deps =
|
|
|
203
293
|
};
|
|
204
294
|
}
|
|
205
295
|
|
|
296
|
+
if (toolName === 'synthesizeDipInversion') {
|
|
297
|
+
const fromClass = args.fromClass || args.sourceClass;
|
|
298
|
+
const toClass = args.toClass || args.targetClass;
|
|
299
|
+
if (!fromClass || !toClass) {
|
|
300
|
+
throw new Error("Missing required arguments: 'fromClass' and 'toClass'");
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (isOnline) {
|
|
304
|
+
try {
|
|
305
|
+
const query = new URLSearchParams({ from: fromClass, to: toClass, projectRoot });
|
|
306
|
+
const res = await (deps.fetch || fetch)(`${serverUrl}/api/violations/invert-plan?${query}`);
|
|
307
|
+
if (res.ok) {
|
|
308
|
+
const json = await res.json();
|
|
309
|
+
return { content: [{ type: 'text', text: JSON.stringify(json, null, 2) }] };
|
|
310
|
+
}
|
|
311
|
+
} catch (err) {
|
|
312
|
+
process.stderr.write(`[archlens-mcp] Online DIP synthesis error: ${err.message}.\n`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const simpleTarget = toClass.split('.').pop();
|
|
317
|
+
const portName = `${simpleTarget}Port`;
|
|
318
|
+
const blueprint = {
|
|
319
|
+
fromClass,
|
|
320
|
+
toClass,
|
|
321
|
+
sourceClass: fromClass,
|
|
322
|
+
targetClass: toClass,
|
|
323
|
+
portName,
|
|
324
|
+
portInterfaceName: portName,
|
|
325
|
+
portInterfaceCode: `public interface ${portName} {}`,
|
|
326
|
+
prescription: `Extract interface ${portName} in the inner layer of ${fromClass} and implement it in ${toClass}.`,
|
|
327
|
+
offline: true
|
|
328
|
+
};
|
|
329
|
+
return { content: [{ type: 'text', text: JSON.stringify(blueprint, null, 2) }] };
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (toolName === 'evaluateFitness') {
|
|
333
|
+
if (isOnline) {
|
|
334
|
+
try {
|
|
335
|
+
const query = new URLSearchParams({ projectRoot });
|
|
336
|
+
const res = await (deps.fetch || fetch)(`${serverUrl}/api/fitness?${query}`);
|
|
337
|
+
if (res.ok) {
|
|
338
|
+
const json = await res.json();
|
|
339
|
+
return { content: [{ type: 'text', text: JSON.stringify(json, null, 2) }] };
|
|
340
|
+
}
|
|
341
|
+
} catch (err) {
|
|
342
|
+
process.stderr.write(`[archlens-mcp] Online fitness fetch error: ${err.message}.\n`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const checker = deps.checkArchitecture || checkArchitecture;
|
|
347
|
+
const checkResult = await checker(projectRoot, { detectCycles: true });
|
|
348
|
+
return {
|
|
349
|
+
content: [
|
|
350
|
+
{
|
|
351
|
+
type: 'text',
|
|
352
|
+
text: JSON.stringify(
|
|
353
|
+
{
|
|
354
|
+
passed: checkResult.passed,
|
|
355
|
+
violationsCount: checkResult.violationsCount,
|
|
356
|
+
cyclesCount: checkResult.cyclesCount,
|
|
357
|
+
screaming: checkResult.screaming,
|
|
358
|
+
fitness: checkResult.fitness,
|
|
359
|
+
offline: true
|
|
360
|
+
},
|
|
361
|
+
null,
|
|
362
|
+
2
|
|
363
|
+
)
|
|
364
|
+
}
|
|
365
|
+
]
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (toolName === 'getFitnessHistory') {
|
|
370
|
+
if (isOnline) {
|
|
371
|
+
try {
|
|
372
|
+
const query = new URLSearchParams({ projectRoot });
|
|
373
|
+
const res = await (deps.fetch || fetch)(`${serverUrl}/api/fitness/history?${query}`);
|
|
374
|
+
if (res.ok) {
|
|
375
|
+
const json = await res.json();
|
|
376
|
+
return { content: [{ type: 'text', text: JSON.stringify(json, null, 2) }] };
|
|
377
|
+
}
|
|
378
|
+
} catch (err) {
|
|
379
|
+
process.stderr.write(`[archlens-mcp] Online fitness history error: ${err.message}.\n`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
content: [
|
|
384
|
+
{
|
|
385
|
+
type: 'text',
|
|
386
|
+
text: JSON.stringify(
|
|
387
|
+
{ trendDirection: 'STABLE', trend: 'STABLE', history: [], snapshots: [], offline: true },
|
|
388
|
+
null,
|
|
389
|
+
2
|
|
390
|
+
)
|
|
391
|
+
}
|
|
392
|
+
]
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (toolName === 'proposeScreamingMigration') {
|
|
397
|
+
if (isOnline) {
|
|
398
|
+
try {
|
|
399
|
+
const query = new URLSearchParams({ projectRoot });
|
|
400
|
+
const res = await (deps.fetch || fetch)(
|
|
401
|
+
`${serverUrl}/api/screaming/migration-proposal?${query}`
|
|
402
|
+
);
|
|
403
|
+
if (res.ok) {
|
|
404
|
+
const json = await res.json();
|
|
405
|
+
return { content: [{ type: 'text', text: JSON.stringify(json, null, 2) }] };
|
|
406
|
+
}
|
|
407
|
+
} catch (err) {
|
|
408
|
+
process.stderr.write(`[archlens-mcp] Online screaming migration error: ${err.message}.\n`);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return {
|
|
412
|
+
content: [
|
|
413
|
+
{
|
|
414
|
+
type: 'text',
|
|
415
|
+
text: JSON.stringify({ clusters: [], projectedSas: 1.0, offline: true }, null, 2)
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (toolName === 'getPolicy') {
|
|
422
|
+
if (isOnline) {
|
|
423
|
+
try {
|
|
424
|
+
const query = new URLSearchParams({ projectRoot });
|
|
425
|
+
const res = await (deps.fetch || fetch)(`${serverUrl}/api/policy?${query}`);
|
|
426
|
+
if (res.ok) {
|
|
427
|
+
const json = await res.json();
|
|
428
|
+
return { content: [{ type: 'text', text: JSON.stringify(json, null, 2) }] };
|
|
429
|
+
}
|
|
430
|
+
} catch (err) {
|
|
431
|
+
process.stderr.write(`[archlens-mcp] Online policy fetch error: ${err.message}.\n`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const policyFile = path.join(projectRoot, '.archlens', 'policy.json');
|
|
435
|
+
if (fs.existsSync(policyFile)) {
|
|
436
|
+
return { content: [{ type: 'text', text: fs.readFileSync(policyFile, 'utf8') }] };
|
|
437
|
+
}
|
|
438
|
+
const policy = generatePolicy(projectRoot, {});
|
|
439
|
+
return { content: [{ type: 'text', text: JSON.stringify(policy, null, 2) }] };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (toolName === 'syncDipAdr') {
|
|
443
|
+
const sourceClass = args.sourceClass || args.fromClass;
|
|
444
|
+
const targetClass = args.targetClass || args.toClass;
|
|
445
|
+
const interfacePortName = args.interfacePortName || args.portName;
|
|
446
|
+
const reason = args.reason || 'Invert outward Clean Architecture dependency via interface port';
|
|
447
|
+
if (!sourceClass || !targetClass || !interfacePortName) {
|
|
448
|
+
throw new Error(
|
|
449
|
+
"Missing required arguments: 'sourceClass', 'targetClass', and 'interfacePortName'"
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
if (isOnline) {
|
|
453
|
+
try {
|
|
454
|
+
const query = new URLSearchParams({ projectRoot });
|
|
455
|
+
const res = await (deps.fetch || fetch)(`${serverUrl}/api/mailbox/sync-adr?${query}`, {
|
|
456
|
+
method: 'POST',
|
|
457
|
+
headers: { 'Content-Type': 'application/json' },
|
|
458
|
+
body: JSON.stringify({
|
|
459
|
+
sourceClass,
|
|
460
|
+
targetClass,
|
|
461
|
+
interfacePortName,
|
|
462
|
+
reason
|
|
463
|
+
})
|
|
464
|
+
});
|
|
465
|
+
if (res.ok) {
|
|
466
|
+
const json = await res.json();
|
|
467
|
+
return { content: [{ type: 'text', text: JSON.stringify(json, null, 2) }] };
|
|
468
|
+
}
|
|
469
|
+
} catch (err) {
|
|
470
|
+
process.stderr.write(`[archlens-mcp] Online syncDipAdr error: ${err.message}.\n`);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
content: [
|
|
475
|
+
{
|
|
476
|
+
type: 'text',
|
|
477
|
+
text: JSON.stringify(
|
|
478
|
+
{
|
|
479
|
+
sourceClass,
|
|
480
|
+
targetClass,
|
|
481
|
+
interfacePortName,
|
|
482
|
+
reason,
|
|
483
|
+
status: 'recorded-offline',
|
|
484
|
+
offline: true
|
|
485
|
+
},
|
|
486
|
+
null,
|
|
487
|
+
2
|
|
488
|
+
)
|
|
489
|
+
}
|
|
490
|
+
]
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
|
|
206
494
|
throw new Error(`Unknown tool: ${toolName}`);
|
|
207
495
|
}
|
|
208
496
|
|
|
@@ -233,11 +521,12 @@ export async function handleMcpMessage(request, options = {}, deps = {}) {
|
|
|
233
521
|
protocolVersion: '2024-11-05',
|
|
234
522
|
capabilities: {
|
|
235
523
|
tools: {},
|
|
236
|
-
resources: {}
|
|
524
|
+
resources: {},
|
|
525
|
+
prompts: {}
|
|
237
526
|
},
|
|
238
527
|
serverInfo: {
|
|
239
528
|
name: 'archlens-mcp-server',
|
|
240
|
-
version: options.version ||
|
|
529
|
+
version: options.version || getPackageVersion()
|
|
241
530
|
}
|
|
242
531
|
}
|
|
243
532
|
};
|
|
@@ -251,6 +540,48 @@ export async function handleMcpMessage(request, options = {}, deps = {}) {
|
|
|
251
540
|
};
|
|
252
541
|
}
|
|
253
542
|
|
|
543
|
+
if (method === 'prompts/list') {
|
|
544
|
+
return {
|
|
545
|
+
jsonrpc: '2.0',
|
|
546
|
+
id,
|
|
547
|
+
result: {
|
|
548
|
+
prompts: getMcpPromptsList()
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (method === 'prompts/get') {
|
|
554
|
+
const promptName = params?.name;
|
|
555
|
+
const args = params?.arguments || {};
|
|
556
|
+
if (promptName === 'architectural-review') {
|
|
557
|
+
const dossierRes = await executeToolCall('exportLlmDossier', args, options, deps);
|
|
558
|
+
return {
|
|
559
|
+
jsonrpc: '2.0',
|
|
560
|
+
id,
|
|
561
|
+
result: {
|
|
562
|
+
description: 'Clean Architecture & Main Sequence review prompt',
|
|
563
|
+
messages: [{ role: 'user', content: dossierRes.content[0] }]
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
if (promptName === 'dip-refactoring-guide') {
|
|
568
|
+
const dipRes = await executeToolCall('synthesizeDipInversion', args, options, deps);
|
|
569
|
+
return {
|
|
570
|
+
jsonrpc: '2.0',
|
|
571
|
+
id,
|
|
572
|
+
result: {
|
|
573
|
+
description: 'Surgical Dependency Inversion Principle (DIP) refactoring prompt',
|
|
574
|
+
messages: [{ role: 'user', content: dipRes.content[0] }]
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
return {
|
|
579
|
+
jsonrpc: '2.0',
|
|
580
|
+
id,
|
|
581
|
+
error: { code: -32602, message: `Unknown prompt: ${promptName}` }
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
254
585
|
if (method === 'tools/list') {
|
|
255
586
|
return {
|
|
256
587
|
jsonrpc: '2.0',
|