@fmatar/archlens-skill 0.1.0-Beta-08 → 0.1.0-Beta-10

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 CHANGED
@@ -12,7 +12,17 @@ Analyzes any project repository, detects programming languages and package hiera
12
12
 
13
13
  ## ⚡ Quickstart
14
14
 
15
- ### Option A: Run via NPX
15
+ ### Option A: Install AI Assistant Skills via Open Skills Standard (Recommended for Agents)
16
+ Using the open [Vercel Labs Skills](https://github.com/vercel-labs/skills) standard, you can add Archlens capabilities across 15+ AI coding assistants (Claude Code, Cursor, Antigravity, Copilot, Codex, Windsurf, Zed):
17
+ ```bash
18
+ # Add to all detected AI assistants in project or globally:
19
+ npx skills add fmatar/archlens
20
+
21
+ # Or add to a specific assistant:
22
+ npx skills add fmatar/archlens --agent claude-code
23
+ ```
24
+
25
+ ### Option B: Run Policy Scaffolder via NPX
16
26
 
17
27
  ```bash
18
28
  # Production Stable (recommended)
@@ -25,13 +35,13 @@ npx @fmatar/archlens-skill@dev
25
35
  npx github:fmatar/archlens
26
36
  ```
27
37
 
28
- ### Option B: Install Globally via NPM
38
+ ### Option C: Install Globally via NPM
29
39
  ```bash
30
40
  npm install -g @fmatar/archlens-skill
31
41
  archlens-skill
32
42
  ```
33
43
 
34
- ### Option C: Run from Local Repository Clone
44
+ ### Option D: Run from Local Repository Clone
35
45
  ```bash
36
46
  # Install globally from the local repository:
37
47
  npm install -g ./cli
@@ -41,7 +51,6 @@ archlens-skill
41
51
  node ./cli/bin/index.js
42
52
  ```
43
53
 
44
-
45
54
  ---
46
55
 
47
56
  ## 🚀 Key Features
package/bin/index.js CHANGED
@@ -371,13 +371,18 @@ function executeGlobalInstall(options) {
371
371
  ui.step(2, 2, `Deploying AI Assistant Skills Globally${modeSuffix}`);
372
372
  const result = installGlobalSkills(options);
373
373
 
374
- if (result.installed.length === 0) {
374
+ if (result.method === 'skills-cli') {
375
+ ui.success(`Installed Archlens skills across AI agents via vercel-labs/skills CLI${modeSuffix}`);
376
+ } else if (result.installed.length === 0) {
375
377
  ui.warn('No active AI agent directories found (~/.claude, ~/.gemini). Use --force to deploy anyway.');
376
378
  } else {
377
379
  for (const inst of result.installed) {
378
380
  ui.success(`Installed skill for ${inst.agent}: ${inst.path}${modeSuffix}`);
379
381
  }
380
382
  }
383
+
384
+ console.log(`\n ${ui.colors.dim}💡 Tip: You can also manage Archlens skills with the open Skills CLI:${ui.colors.reset}`);
385
+ console.log(` ${ui.colors.cyan}npx skills add fmatar/archlens${ui.colors.reset}\n`);
381
386
  }
382
387
 
383
388
  function executeUpgrade(targetRoot, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fmatar/archlens-skill",
3
- "version": "0.1.0-Beta-08",
3
+ "version": "0.1.0-Beta-10",
4
4
  "description": "Cross-platform CLI and installer for Archlens Clean Architecture governance policies and AI assistant skills",
5
5
  "main": "src/installer.js",
6
6
  "type": "module",
@@ -50,7 +50,13 @@ Archlens models codebases as concentric circular rings. Source code dependencies
50
50
 
51
51
  ## ⚡ CLI & Quickstart Commands
52
52
 
53
- Archlens is executed cross-platform via NPX or Node CLI:
53
+ Install Archlens across 15+ coding agents (Antigravity, Claude Code, Cursor, Gemini CLI) via `skills.sh`:
54
+ ```bash
55
+ # Add Archlens to your active agent skills library:
56
+ npx skills add fmatar/archlens
57
+ ```
58
+
59
+ Or execute directly on demand via NPX:
54
60
 
55
61
  ```bash
56
62
  # Initialize Clean Architecture policy in target project:
@@ -60,12 +60,30 @@ def find_common_package_prefix(source_dir: Path) -> str:
60
60
  if not source_dir.exists():
61
61
  return ""
62
62
 
63
+ known_layer_terms = {
64
+ "domain", "model", "models", "entity", "entities", "core",
65
+ "application", "app", "usecase", "usecases", "service", "services", "port", "ports",
66
+ "adapter", "adapters", "controller", "controllers", "gateway", "gateways",
67
+ "presenter", "presenters", "repository", "repositories", "resource", "resources", "api", "dto",
68
+ "infrastructure", "infra", "persistence", "db", "database", "config", "configuration", "web", "server"
69
+ }
70
+
63
71
  java_files = list(source_dir.glob("**/*.java"))
64
72
  if not java_files:
65
73
  kt_files = list(source_dir.glob("**/*.kt"))
66
74
  if kt_files:
67
75
  java_files = kt_files
68
76
 
77
+ if not java_files:
78
+ excluded = {"__pycache__", "venv", ".venv", "node_modules", "tests", "test", "dist", "build", "target", "site-packages"}
79
+ dirs = [
80
+ d for d in source_dir.iterdir()
81
+ if d.is_dir() and not d.name.startswith(".") and d.name not in excluded and not d.name.endswith(".egg-info")
82
+ ]
83
+ if len(dirs) == 1 and dirs[0].name.lower() not in known_layer_terms and (dirs[0] / "__init__.py").exists():
84
+ return dirs[0].name
85
+ return ""
86
+
69
87
  packages = []
70
88
  for jf in java_files[:100]:
71
89
  try:
@@ -87,13 +105,6 @@ def find_common_package_prefix(source_dir: Path) -> str:
87
105
  else:
88
106
  break
89
107
 
90
- known_layer_terms = {
91
- "domain", "model", "models", "entity", "entities", "core",
92
- "application", "app", "usecase", "usecases", "service", "services", "port", "ports",
93
- "adapter", "adapters", "controller", "controllers", "gateway", "gateways",
94
- "presenter", "presenters", "repository", "repositories", "resource", "resources", "api", "dto",
95
- "infrastructure", "infra", "persistence", "db", "database", "config", "configuration", "web", "server"
96
- }
97
108
  while common and common[-1].lower() in known_layer_terms:
98
109
  common.pop()
99
110
 
@@ -113,9 +124,10 @@ def discover_subpackages(source_dir: Path, prefix: str) -> list[str]:
113
124
  else:
114
125
  break
115
126
 
127
+ excluded = {"__pycache__", "venv", ".venv", "node_modules", "tests", "test", "dist", "build", "target", "site-packages"}
116
128
  subpackages = []
117
129
  for item in sorted(search_root.iterdir()):
118
- if item.is_dir() and not item.name.startswith("."):
130
+ if item.is_dir() and not item.name.startswith(".") and item.name not in excluded and not item.name.endswith(".egg-info"):
119
131
  subpackages.append(item.name)
120
132
 
121
133
  return subpackages
package/src/analyzer.js CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  import * as fs from 'node:fs';
9
9
  import * as path from 'node:path';
10
+ import { extractFileImports } from './checker.js';
10
11
 
11
12
  export function detectProjectLanguage(projectRoot) {
12
13
  const root = path.resolve(projectRoot);
@@ -188,8 +189,39 @@ export function findCommonPackagePrefix(sourceDir) {
188
189
  return '';
189
190
  }
190
191
 
192
+ const architecturalKeywords = new Set([
193
+ 'domain', 'model', 'models', 'entity', 'entities', 'core',
194
+ 'application', 'app', 'usecase', 'usecases', 'service', 'services', 'port', 'ports',
195
+ 'adapter', 'adapters', 'controller', 'controllers', 'gateway', 'gateways',
196
+ 'presenter', 'presenters', 'repository', 'repositories', 'resource', 'resources', 'api', 'dto',
197
+ 'infrastructure', 'infra', 'persistence', 'db', 'database', 'config', 'configuration', 'web', 'server'
198
+ ]);
199
+
191
200
  const javaFiles = findMatchingFiles(resolved, (f) => f.endsWith('.java') || f.endsWith('.kt'), 100);
192
201
  if (javaFiles.length === 0) {
202
+ // Python package prefix detection (e.g. src/my_package/__init__.py with nested layer subpackages)
203
+ try {
204
+ const ignored = new Set([
205
+ '__pycache__', 'venv', '.venv', 'node_modules', 'tests', 'test', 'dist', 'build', 'target', 'site-packages'
206
+ ]);
207
+ const dirs = fs
208
+ .readdirSync(resolved, { withFileTypes: true })
209
+ .filter(
210
+ (e) =>
211
+ e.isDirectory() &&
212
+ !e.name.startsWith('.') &&
213
+ !ignored.has(e.name) &&
214
+ !e.name.endsWith('.egg-info')
215
+ );
216
+ if (dirs.length === 1 && !architecturalKeywords.has(dirs[0].name.toLowerCase())) {
217
+ const pkgDir = path.join(resolved, dirs[0].name);
218
+ if (fs.existsSync(path.join(pkgDir, '__init__.py'))) {
219
+ return dirs[0].name;
220
+ }
221
+ }
222
+ } catch {
223
+ // Ignore unreadable directories
224
+ }
193
225
  return '';
194
226
  }
195
227
 
@@ -226,14 +258,6 @@ export function findCommonPackagePrefix(sourceDir) {
226
258
  }
227
259
  }
228
260
 
229
- const architecturalKeywords = new Set([
230
- 'domain', 'model', 'models', 'entity', 'entities', 'core',
231
- 'application', 'app', 'usecase', 'usecases', 'service', 'services', 'port', 'ports',
232
- 'adapter', 'adapters', 'controller', 'controllers', 'gateway', 'gateways',
233
- 'presenter', 'presenters', 'repository', 'repositories', 'resource', 'resources', 'api', 'dto',
234
- 'infrastructure', 'infra', 'persistence', 'db', 'database', 'config', 'configuration', 'web', 'server'
235
- ]);
236
-
237
261
  while (common.length > 0 && architecturalKeywords.has(common[common.length - 1].toLowerCase())) {
238
262
  common.pop();
239
263
  }
@@ -241,6 +265,19 @@ export function findCommonPackagePrefix(sourceDir) {
241
265
  return common.join('.');
242
266
  }
243
267
 
268
+ const EXCLUDED_SUBPACKAGE_DIRS = new Set([
269
+ '__pycache__',
270
+ 'venv',
271
+ '.venv',
272
+ 'node_modules',
273
+ 'tests',
274
+ 'test',
275
+ 'dist',
276
+ 'build',
277
+ 'target',
278
+ 'site-packages'
279
+ ]);
280
+
244
281
  export function discoverSubpackages(sourceDir, prefix) {
245
282
  const resolved = path.resolve(sourceDir);
246
283
  if (!fs.existsSync(resolved)) {
@@ -266,7 +303,13 @@ export function discoverSubpackages(sourceDir, prefix) {
266
303
 
267
304
  const entries = fs.readdirSync(searchPath, { withFileTypes: true });
268
305
  return entries
269
- .filter((e) => e.isDirectory() && !e.name.startsWith('.'))
306
+ .filter(
307
+ (e) =>
308
+ e.isDirectory() &&
309
+ !e.name.startsWith('.') &&
310
+ !EXCLUDED_SUBPACKAGE_DIRS.has(e.name) &&
311
+ !e.name.endsWith('.egg-info')
312
+ )
270
313
  .map((e) => e.name)
271
314
  .sort();
272
315
  }
@@ -325,17 +368,97 @@ export function classifyLayers(subpackages) {
325
368
  return { order, levels };
326
369
  }
327
370
 
371
+ export function parseImportLinterConfig(projectRoot) {
372
+ const root = path.resolve(projectRoot);
373
+ for (const filename of ['.importlinter', 'pyproject.toml']) {
374
+ const cfgPath = path.join(root, filename);
375
+ if (!fs.existsSync(cfgPath)) continue;
376
+ try {
377
+ const content = fs.readFileSync(cfgPath, 'utf8');
378
+ if (filename === 'pyproject.toml' && !content.includes('importlinter')) continue;
379
+
380
+ let rootPackage = null;
381
+ const rootPkgMatch = content.match(/root_packages?\s*=\s*(?:\[\s*)?['"]?([a-zA-Z0-9_]+)['"]?/);
382
+ if (rootPkgMatch && rootPkgMatch[1]) {
383
+ rootPackage = rootPkgMatch[1].trim();
384
+ }
385
+
386
+ let layers = null;
387
+ const tomlLayersMatch = content.match(/layers\s*=\s*\[([\s\S]*?)\]/);
388
+ if (tomlLayersMatch) {
389
+ const rawEntries = tomlLayersMatch[1]
390
+ .split(/[,\n]/)
391
+ .map((s) => s.replace(/#.*$/, '').replace(/['"]/g, '').trim())
392
+ .filter(Boolean);
393
+ if (rawEntries.length > 0) {
394
+ layers = rawEntries;
395
+ }
396
+ } else if (filename === '.importlinter') {
397
+ const iniLayersMatch = content.match(/layers\s*=\s*\n((?:[ \t]+[^\n]+\n?)+)/);
398
+ if (iniLayersMatch) {
399
+ layers = iniLayersMatch[1]
400
+ .split('\n')
401
+ .map((s) => s.trim())
402
+ .filter(Boolean);
403
+ }
404
+ }
405
+
406
+ if (layers && layers.length > 0) {
407
+ // import-linter orders layers outermost (high-level) -> innermost (low-level).
408
+ // Reverse into Archlens concentric rings: Level 0 (innermost domain) -> outer rings.
409
+ const levels = [...layers].reverse().map((entry) =>
410
+ entry
411
+ .split(':')
412
+ .map((pkg) => {
413
+ let clean = pkg.trim();
414
+ if (rootPackage && clean.startsWith(`${rootPackage}.`)) {
415
+ clean = clean.slice(rootPackage.length + 1);
416
+ }
417
+ return clean;
418
+ })
419
+ .filter(Boolean)
420
+ );
421
+ const order = [];
422
+ for (const group of levels) {
423
+ for (const p of group) {
424
+ if (!order.includes(p)) order.push(p);
425
+ }
426
+ }
427
+ return { rootPackage, levels, order };
428
+ }
429
+
430
+ if (rootPackage) {
431
+ return { rootPackage, levels: null, order: null };
432
+ }
433
+ } catch {
434
+ // Ignore malformed config
435
+ }
436
+ }
437
+ return null;
438
+ }
439
+
328
440
  export function generatePolicy(projectRoot, options = {}) {
329
441
  const root = path.resolve(projectRoot);
330
442
  const lang = options.lang || detectProjectLanguage(root);
331
443
  const srcRoot = options.src || detectSourceRoot(root, lang);
332
444
  const fullSrc = path.join(root, srcRoot);
333
445
 
334
- const prefix = options.prefix !== undefined ? options.prefix : findCommonPackagePrefix(fullSrc);
446
+ const importLinter = lang === 'python' ? parseImportLinterConfig(root) : null;
447
+ const prefix =
448
+ options.prefix !== undefined
449
+ ? options.prefix
450
+ : importLinter?.rootPackage || findCommonPackagePrefix(fullSrc);
335
451
  const title = options.title || formatProjectTitle(path.basename(root));
336
452
 
337
- const subpackages = discoverSubpackages(fullSrc, prefix);
338
- const { order, levels } = classifyLayers(subpackages);
453
+ let order;
454
+ let levels;
455
+ if (importLinter?.levels && importLinter.levels.length > 0) {
456
+ levels = importLinter.levels;
457
+ order = importLinter.order;
458
+ } else {
459
+ const subpackages = discoverSubpackages(fullSrc, prefix);
460
+ ({ order, levels } = classifyLayers(subpackages));
461
+ }
339
462
 
340
463
  const foreignMap = {
341
464
  java: ['java.', 'jakarta.', 'org.springframework.', 'io.quarkus.'],
@@ -374,7 +497,22 @@ function findMatchingFiles(dir, predicate, limit = 50, collected = []) {
374
497
  return collected;
375
498
  }
376
499
 
377
- const skipDirs = new Set(['.git', 'node_modules', 'target', 'build', '.gradle', '.idea', '.vscode']);
500
+ const skipDirs = new Set([
501
+ '.git',
502
+ 'node_modules',
503
+ 'target',
504
+ 'build',
505
+ '.gradle',
506
+ '.idea',
507
+ '.vscode',
508
+ 'venv',
509
+ '.venv',
510
+ '__pycache__',
511
+ 'site-packages',
512
+ 'tests',
513
+ 'test',
514
+ 'dist'
515
+ ]);
378
516
 
379
517
  try {
380
518
  const entries = fs.readdirSync(dir, { withFileTypes: true });
@@ -383,7 +521,7 @@ function findMatchingFiles(dir, predicate, limit = 50, collected = []) {
383
521
  const fullPath = path.join(dir, entry.name);
384
522
 
385
523
  if (entry.isDirectory()) {
386
- if (!skipDirs.has(entry.name)) {
524
+ if (!entry.name.startsWith('.') && !skipDirs.has(entry.name) && !entry.name.endsWith('.egg-info')) {
387
525
  findMatchingFiles(fullPath, predicate, limit, collected);
388
526
  }
389
527
  } else if (entry.isFile() && predicate(entry.name)) {
@@ -460,7 +598,14 @@ export async function generateLlmPrompt(projectRoot, options = {}) {
460
598
  const fullSrc = path.join(root, policy.src || 'src');
461
599
  const sourceFiles = findMatchingFiles(
462
600
  fullSrc,
463
- (f) => f.endsWith('.java') || f.endsWith('.kt') || f.endsWith('.ts') || f.endsWith('.js'),
601
+ (f) =>
602
+ (f.endsWith('.java') ||
603
+ f.endsWith('.kt') ||
604
+ f.endsWith('.ts') ||
605
+ f.endsWith('.js') ||
606
+ f.endsWith('.py')) &&
607
+ !f.startsWith('test_') &&
608
+ !f.endsWith('_test.py'),
464
609
  300
465
610
  );
466
611
 
@@ -470,7 +615,6 @@ export async function generateLlmPrompt(projectRoot, options = {}) {
470
615
  });
471
616
 
472
617
  const violations = [];
473
- const importRegex = /import\s+([a-zA-Z0-9_.]+)/g;
474
618
 
475
619
  for (const file of sourceFiles) {
476
620
  try {
@@ -488,21 +632,25 @@ export async function generateLlmPrompt(projectRoot, options = {}) {
488
632
 
489
633
  if (fileLevel === null) continue;
490
634
 
491
- let match;
492
- while ((match = importRegex.exec(content)) !== null) {
493
- const imported = match[1];
635
+ const fileImports = extractFileImports(content, file, fullSrc);
636
+ const seenLinePkgViolations = new Set();
637
+ for (const { imported, line } of fileImports) {
494
638
  const lowerImport = imported.toLowerCase();
495
639
  for (const [targetPkg, targetLvl] of pkgToLevel.entries()) {
496
640
  if (lowerImport.includes(targetPkg)) {
497
641
  if (fileLevel < targetLvl) {
498
- const baseName = path.basename(file, path.extname(file));
499
- violations.push({
500
- fromFile: relPath,
501
- fromTier: tierNames[fileLevel] || `Level ${fileLevel}`,
502
- toImport: imported,
503
- toTier: tierNames[targetLvl] || `Level ${targetLvl}`,
504
- portName: `${baseName}Port`
505
- });
642
+ const dedupKey = `${line}:${targetPkg}`;
643
+ if (!seenLinePkgViolations.has(dedupKey)) {
644
+ seenLinePkgViolations.add(dedupKey);
645
+ const baseName = path.basename(file, path.extname(file));
646
+ violations.push({
647
+ fromFile: relPath,
648
+ fromTier: tierNames[fileLevel] || `Level ${fileLevel}`,
649
+ toImport: imported,
650
+ toTier: tierNames[targetLvl] || `Level ${targetLvl}`,
651
+ portName: `${baseName}Port`
652
+ });
653
+ }
506
654
  }
507
655
  break;
508
656
  }
package/src/checker.js CHANGED
@@ -24,7 +24,13 @@ function findMatchingFiles(dir, predicate, maxFiles = 500, results = []) {
24
24
  entry.name === 'node_modules' ||
25
25
  entry.name === 'target' ||
26
26
  entry.name === 'dist' ||
27
- entry.name === 'build'
27
+ entry.name === 'build' ||
28
+ entry.name === 'venv' ||
29
+ entry.name === '__pycache__' ||
30
+ entry.name === 'site-packages' ||
31
+ entry.name === 'tests' ||
32
+ entry.name === 'test' ||
33
+ entry.name.endsWith('.egg-info')
28
34
  ) {
29
35
  continue;
30
36
  }
@@ -335,6 +341,188 @@ export function suggestFeatureClusters(packages, sourceFiles = []) {
335
341
  };
336
342
  }
337
343
 
344
+ function resolvePythonRelativeImport(packageName, imported) {
345
+ if (!imported || !imported.startsWith('.')) return imported;
346
+ let dotCount = 0;
347
+ while (dotCount < imported.length && imported[dotCount] === '.') dotCount++;
348
+ const rest = imported.slice(dotCount);
349
+ const pkgParts = packageName ? packageName.split('.').filter(Boolean) : [];
350
+ const targetLen = Math.max(0, pkgParts.length - (dotCount - 1));
351
+ const base = pkgParts.slice(0, targetLen).join('.');
352
+ if (!base) return rest;
353
+ return rest ? `${base}.${rest}` : base;
354
+ }
355
+
356
+ function extractPythonStatements(content) {
357
+ const rawLines = content.split('\n');
358
+ const statements = [];
359
+ let currentStmt = '';
360
+ let stmtLine = 1;
361
+ let inTripleDouble = false;
362
+ let inTripleSingle = false;
363
+ let parenDepth = 0;
364
+
365
+ for (let lineIdx = 0; lineIdx < rawLines.length; lineIdx++) {
366
+ const line = rawLines[lineIdx];
367
+ const lineNo = lineIdx + 1;
368
+ let lineBuf = '';
369
+ let i = 0;
370
+
371
+ while (i < line.length) {
372
+ if (inTripleDouble) {
373
+ const close = line.indexOf('"""', i);
374
+ if (close !== -1) {
375
+ inTripleDouble = false;
376
+ i = close + 3;
377
+ } else break;
378
+ continue;
379
+ }
380
+ if (inTripleSingle) {
381
+ const close = line.indexOf("'''", i);
382
+ if (close !== -1) {
383
+ inTripleSingle = false;
384
+ i = close + 3;
385
+ } else break;
386
+ continue;
387
+ }
388
+ if (line.startsWith('"""', i)) {
389
+ inTripleDouble = true;
390
+ i += 3;
391
+ continue;
392
+ }
393
+ if (line.startsWith("'''", i)) {
394
+ inTripleSingle = true;
395
+ i += 3;
396
+ continue;
397
+ }
398
+ const c = line[i];
399
+ if (c === '#') break;
400
+ if (c === '"' || c === "'") {
401
+ const quote = c;
402
+ lineBuf += c;
403
+ i++;
404
+ while (i < line.length) {
405
+ const sc = line[i];
406
+ lineBuf += sc;
407
+ if (sc === '\\' && i + 1 < line.length) {
408
+ i++;
409
+ lineBuf += line[i];
410
+ } else if (sc === quote) {
411
+ i++;
412
+ break;
413
+ }
414
+ i++;
415
+ }
416
+ continue;
417
+ }
418
+ if (c === '(' || c === '[' || c === '{') parenDepth++;
419
+ else if (c === ')' || c === ']' || c === '}') parenDepth = Math.max(0, parenDepth - 1);
420
+ else if (c === ';' && parenDepth === 0) {
421
+ const emitted = (currentStmt ? `${currentStmt} ${lineBuf}` : lineBuf).trim();
422
+ if (emitted) statements.push({ text: emitted, line: currentStmt ? stmtLine : lineNo });
423
+ currentStmt = '';
424
+ lineBuf = '';
425
+ i++;
426
+ continue;
427
+ }
428
+ lineBuf += c;
429
+ i++;
430
+ }
431
+
432
+ if (inTripleDouble || inTripleSingle) continue;
433
+
434
+ const trimmedRight = lineBuf.trimEnd();
435
+ if (trimmedRight.endsWith('\\')) {
436
+ if (!currentStmt) stmtLine = lineNo;
437
+ currentStmt += (currentStmt ? ' ' : '') + trimmedRight.slice(0, -1).trim();
438
+ continue;
439
+ }
440
+ if (parenDepth > 0) {
441
+ if (trimmedRight.trim()) {
442
+ if (!currentStmt) stmtLine = lineNo;
443
+ currentStmt += (currentStmt ? ' ' : '') + trimmedRight.trim();
444
+ }
445
+ continue;
446
+ }
447
+ if (currentStmt) {
448
+ const emitted = `${currentStmt} ${trimmedRight.trim()}`.trim();
449
+ if (emitted) statements.push({ text: emitted, line: stmtLine });
450
+ currentStmt = '';
451
+ } else if (trimmedRight.trim()) {
452
+ statements.push({ text: trimmedRight.trim(), line: lineNo });
453
+ }
454
+ }
455
+ if (currentStmt.trim()) {
456
+ statements.push({ text: currentStmt.trim(), line: stmtLine });
457
+ }
458
+ return statements;
459
+ }
460
+
461
+ export function extractFileImports(content, filePath, fullSrc) {
462
+ if (!filePath.endsWith('.py')) {
463
+ const results = [];
464
+ const importRegex = /import\s+(?:static\s+)?([a-zA-Z0-9_.]+)/;
465
+ const lines = content.split('\n');
466
+ for (let i = 0; i < lines.length; i++) {
467
+ const m = importRegex.exec(lines[i]);
468
+ if (m) results.push({ imported: m[1], line: i + 1 });
469
+ }
470
+ return results;
471
+ }
472
+
473
+ let rel = fullSrc ? path.relative(fullSrc, filePath).replace(/\\/g, '/') : path.basename(filePath);
474
+ if (rel.startsWith('src/')) rel = rel.slice(4);
475
+ const isInit = path.basename(filePath) === '__init__.py';
476
+ const modId = rel.replace(/\.py$/, '').replace(/\/__init__$/, '').replace(/\//g, '.');
477
+ const packageName = isInit ? modId : (modId.includes('.') ? modId.slice(0, modId.lastIndexOf('.')) : modId);
478
+
479
+ const results = [];
480
+ const fromRegex = /^from\s+([a-zA-Z0-9_.]+)(?:\s+|(?<=\.))import\s+(.+)$/;
481
+ const directRegex = /^import\s+([a-zA-Z0-9_., ]+)$/;
482
+ const dynRegex = /(?:importlib\.import_module|__import__)\s*\(\s*['"]([a-zA-Z0-9_.]+)['"]/g;
483
+
484
+ for (const { text, line } of extractPythonStatements(content)) {
485
+ const fromMatch = fromRegex.exec(text);
486
+ if (fromMatch) {
487
+ const resolvedMod = resolvePythonRelativeImport(packageName, fromMatch[1].trim());
488
+ const itemsClause = fromMatch[2].replace(/[()]/g, ' ').trim();
489
+ let emittedSpecific = false;
490
+ for (const rawPart of itemsClause.split(',')) {
491
+ const token = rawPart.trim();
492
+ if (!token) continue;
493
+ const orig = token.split(/\s+/)[0].trim();
494
+ if (orig && orig !== '*' && /^[a-zA-Z_]/.test(orig)) {
495
+ results.push({ imported: resolvedMod ? `${resolvedMod}.${orig}` : orig, line });
496
+ emittedSpecific = true;
497
+ }
498
+ }
499
+ if (!emittedSpecific && resolvedMod) {
500
+ results.push({ imported: resolvedMod, line });
501
+ }
502
+ continue;
503
+ }
504
+
505
+ const directMatch = directRegex.exec(text);
506
+ if (directMatch) {
507
+ for (const rawPart of directMatch[1].replace(/[()]/g, ' ').split(',')) {
508
+ const orig = rawPart.trim().split(/\s+/)[0].trim();
509
+ if (orig && /^[a-zA-Z_]/.test(orig)) {
510
+ results.push({ imported: orig, line });
511
+ }
512
+ }
513
+ continue;
514
+ }
515
+
516
+ let dynMatch;
517
+ dynRegex.lastIndex = 0;
518
+ while ((dynMatch = dynRegex.exec(text)) !== null) {
519
+ const resolvedDyn = resolvePythonRelativeImport(packageName, dynMatch[1].trim());
520
+ if (resolvedDyn) results.push({ imported: resolvedDyn, line });
521
+ }
522
+ }
523
+ return results;
524
+ }
525
+
338
526
  export async function checkArchitecture(projectRoot, options = {}) {
339
527
  const root = path.resolve(projectRoot || '.');
340
528
  const policy = loadProjectPolicy(root);
@@ -360,13 +548,19 @@ export async function checkArchitecture(projectRoot, options = {}) {
360
548
  const fullSrc = path.join(root, policy.src || 'src');
361
549
  const sourceFiles = findMatchingFiles(
362
550
  fullSrc,
363
- (f) => f.endsWith('.java') || f.endsWith('.kt') || f.endsWith('.ts') || f.endsWith('.js'),
551
+ (f) =>
552
+ (f.endsWith('.java') ||
553
+ f.endsWith('.kt') ||
554
+ f.endsWith('.ts') ||
555
+ f.endsWith('.js') ||
556
+ f.endsWith('.py')) &&
557
+ !f.startsWith('test_') &&
558
+ !f.endsWith('_test.py'),
364
559
  500
365
560
  );
366
561
 
367
562
  const violations = [];
368
563
  const packageEdges = new Map();
369
- const importRegex = /import\s+(?:static\s+)?([a-zA-Z0-9_.]+)/;
370
564
 
371
565
  for (const file of sourceFiles) {
372
566
  try {
@@ -386,22 +580,22 @@ export async function checkArchitecture(projectRoot, options = {}) {
386
580
 
387
581
  if (fileLevel === null) continue;
388
582
 
389
- const lines = content.split('\n');
390
- for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
391
- const line = lines[lineIndex];
392
- const match = importRegex.exec(line);
393
- if (match) {
394
- const imported = match[1];
395
- const lowerImport = imported.toLowerCase();
396
- for (const [targetPkg, targetLvl] of pkgToLevel.entries()) {
397
- if (lowerImport.includes(targetPkg)) {
398
- if (filePackage && filePackage !== targetPkg) {
399
- if (!packageEdges.has(filePackage)) {
400
- packageEdges.set(filePackage, new Set());
401
- }
402
- packageEdges.get(filePackage).add(targetPkg);
583
+ const fileImports = extractFileImports(content, file, fullSrc);
584
+ const seenLinePkgViolations = new Set();
585
+ for (const { imported, line } of fileImports) {
586
+ const lowerImport = imported.toLowerCase();
587
+ for (const [targetPkg, targetLvl] of pkgToLevel.entries()) {
588
+ if (lowerImport.includes(targetPkg)) {
589
+ if (filePackage && filePackage !== targetPkg) {
590
+ if (!packageEdges.has(filePackage)) {
591
+ packageEdges.set(filePackage, new Set());
403
592
  }
404
- if (fileLevel < targetLvl) {
593
+ packageEdges.get(filePackage).add(targetPkg);
594
+ }
595
+ if (fileLevel < targetLvl) {
596
+ const dedupKey = `${line}:${targetPkg}`;
597
+ if (!seenLinePkgViolations.has(dedupKey)) {
598
+ seenLinePkgViolations.add(dedupKey);
405
599
  const baseName = path.basename(file, path.extname(file));
406
600
  violations.push({
407
601
  fromFile: relPath,
@@ -409,11 +603,11 @@ export async function checkArchitecture(projectRoot, options = {}) {
409
603
  toImport: imported,
410
604
  toTier: tierNames[targetLvl] || `Level ${targetLvl}`,
411
605
  portName: `${baseName}Port`,
412
- line: lineIndex + 1
606
+ line
413
607
  });
414
608
  }
415
- break;
416
609
  }
610
+ break;
417
611
  }
418
612
  }
419
613
  }
package/src/installer.js CHANGED
@@ -7,6 +7,7 @@
7
7
  import * as fs from 'node:fs';
8
8
  import * as path from 'node:path';
9
9
  import * as os from 'node:os';
10
+ import { spawnSync } from 'node:child_process';
10
11
  import { fileURLToPath } from 'node:url';
11
12
  import { generatePolicy } from './analyzer.js';
12
13
  import { installMcpConfigs } from './mcp-registry.js';
@@ -180,6 +181,31 @@ export function installGlobalSkills(options = {}) {
180
181
  const force = Boolean(options.force);
181
182
  const bundledSkillsRoot = path.resolve(__dirname, '..', 'skills');
182
183
 
184
+ // Attempt using vercel-labs/skills CLI if available and not explicitly disabled
185
+ if (!options.homedir && options.preferVercelSkills !== false && !dryRun) {
186
+ try {
187
+ const isWin = process.platform === 'win32';
188
+ const npxCmd = isWin ? 'npx.cmd' : 'npx';
189
+ // Install skills package from GitHub or local bundled skills via `npx skills add`
190
+ const skillsProc = spawnSync(npxCmd, ['--yes', 'skills', 'add', bundledSkillsRoot, '-g', '--copy', '-y'], {
191
+ encoding: 'utf8',
192
+ timeout: 15000,
193
+ stdio: ['ignore', 'pipe', 'pipe']
194
+ });
195
+ if (skillsProc.status === 0) {
196
+ return {
197
+ sourceDir: bundledSkillsRoot,
198
+ method: 'skills-cli',
199
+ output: skillsProc.stdout,
200
+ installed: [{ agent: 'All Supported Agents (via vercel-labs/skills)', skill: 'archlens-suite', path: 'global' }],
201
+ dryRun: false
202
+ };
203
+ }
204
+ } catch {
205
+ // Fallback seamlessly to native direct directory installation
206
+ }
207
+ }
208
+
183
209
  const destinations = getGlobalSkillDirectories(options.homedir);
184
210
  const installed = [];
185
211
 
@@ -204,6 +230,7 @@ export function installGlobalSkills(options = {}) {
204
230
 
205
231
  return {
206
232
  sourceDir: bundledSkillsRoot,
233
+ method: 'direct-copy',
207
234
  installed,
208
235
  dryRun
209
236
  };