akbo-cli 0.0.0-stage → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +786 -2
  2. package/dist/catalog_store.d.ts +131 -0
  3. package/dist/catalog_store.js +506 -0
  4. package/dist/cleaner.d.ts +11 -0
  5. package/dist/cleaner.js +92 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +1961 -0
  8. package/dist/dream_engine.d.ts +61 -0
  9. package/dist/dream_engine.js +330 -0
  10. package/dist/extractors/base.d.ts +35 -0
  11. package/dist/extractors/base.js +17 -0
  12. package/dist/extractors/custom_extractor.d.ts +55 -0
  13. package/dist/extractors/custom_extractor.js +198 -0
  14. package/dist/extractors/dotnet_extractor.d.ts +11 -0
  15. package/dist/extractors/dotnet_extractor.js +579 -0
  16. package/dist/extractors/golang_extractor.d.ts +11 -0
  17. package/dist/extractors/golang_extractor.js +73 -0
  18. package/dist/extractors/index.d.ts +14 -0
  19. package/dist/extractors/index.js +30 -0
  20. package/dist/extractors/jvm_extractor.d.ts +11 -0
  21. package/dist/extractors/jvm_extractor.js +319 -0
  22. package/dist/extractors/node_extractor.d.ts +11 -0
  23. package/dist/extractors/node_extractor.js +306 -0
  24. package/dist/extractors/proto_graphql_extractor.d.ts +11 -0
  25. package/dist/extractors/proto_graphql_extractor.js +125 -0
  26. package/dist/extractors/python_extractor.d.ts +11 -0
  27. package/dist/extractors/python_extractor.js +298 -0
  28. package/dist/extractors/rust_extractor.d.ts +11 -0
  29. package/dist/extractors/rust_extractor.js +66 -0
  30. package/dist/graph_builder.d.ts +87 -0
  31. package/dist/graph_builder.js +1516 -0
  32. package/dist/guard_service.d.ts +33 -0
  33. package/dist/guard_service.js +167 -0
  34. package/dist/harvester.d.ts +38 -0
  35. package/dist/harvester.js +461 -0
  36. package/dist/hook_generator.d.ts +34 -0
  37. package/dist/hook_generator.js +269 -0
  38. package/dist/importers/skill_importer.d.ts +43 -0
  39. package/dist/importers/skill_importer.js +470 -0
  40. package/dist/index.d.ts +20 -0
  41. package/dist/index.js +20 -0
  42. package/dist/indexer.d.ts +19 -0
  43. package/dist/indexer.js +108 -0
  44. package/dist/init_service.d.ts +37 -0
  45. package/dist/init_service.js +246 -0
  46. package/dist/mcp_server.d.ts +10 -0
  47. package/dist/mcp_server.js +846 -0
  48. package/dist/pool_resolver.d.ts +40 -0
  49. package/dist/pool_resolver.js +84 -0
  50. package/dist/provider.d.ts +135 -0
  51. package/dist/provider.js +880 -0
  52. package/dist/query_service.d.ts +33 -0
  53. package/dist/query_service.js +161 -0
  54. package/dist/schema_generator.d.ts +236 -0
  55. package/dist/schema_generator.js +264 -0
  56. package/dist/standards_loader.d.ts +7 -0
  57. package/dist/standards_loader.js +33 -0
  58. package/dist/types.d.ts +323 -0
  59. package/dist/types.js +123 -0
  60. package/dist/unit_synthesizer.d.ts +22 -0
  61. package/dist/unit_synthesizer.js +196 -0
  62. package/dist/validator.d.ts +13 -0
  63. package/dist/validator.js +152 -0
  64. package/dist/version.d.ts +6 -0
  65. package/dist/version.js +16 -0
  66. package/dist/watcher.d.ts +38 -0
  67. package/dist/watcher.js +132 -0
  68. package/package.json +56 -6
  69. package/schemas/index-schema.json +98 -0
  70. package/schemas/knowledge-unit.json +154 -0
@@ -0,0 +1,33 @@
1
+ export interface GuardViolation {
2
+ invariantId: string;
3
+ title: string;
4
+ rule: string;
5
+ forbiddenPattern: string;
6
+ severity: 'block' | 'warn';
7
+ reason: string;
8
+ }
9
+ export interface GuardEvaluationResult {
10
+ allowed: boolean;
11
+ targetFile: string;
12
+ violations: GuardViolation[];
13
+ warnings: string[];
14
+ }
15
+ export interface CheckStagedResult {
16
+ success: boolean;
17
+ filesChecked: number;
18
+ violations: Record<string, GuardViolation[]>;
19
+ warnings: Record<string, string[]>;
20
+ }
21
+ export declare class GuardService {
22
+ private targetDir;
23
+ private poolDir?;
24
+ constructor(targetDir?: string, poolDir?: string);
25
+ /**
26
+ * Evaluates proposed file content or diff against applicable invariants and architectural standards.
27
+ */
28
+ evaluate(filePath: string, contentOrDiff: string): GuardEvaluationResult;
29
+ /**
30
+ * Executes pre-commit / CI gate verification across git staged files.
31
+ */
32
+ checkStaged(): CheckStagedResult;
33
+ }
@@ -0,0 +1,167 @@
1
+ import path from 'node:path';
2
+ import { execSync } from 'node:child_process';
3
+ import { GraphBuilder } from './graph_builder.js';
4
+ import { StandardsLoader } from './standards_loader.js';
5
+ import { KnowledgePoolResolver } from './pool_resolver.js';
6
+ export class GuardService {
7
+ targetDir;
8
+ poolDir;
9
+ constructor(targetDir = process.cwd(), poolDir) {
10
+ this.targetDir = path.resolve(targetDir);
11
+ this.poolDir = poolDir;
12
+ }
13
+ /**
14
+ * Evaluates proposed file content or diff against applicable invariants and architectural standards.
15
+ */
16
+ evaluate(filePath, contentOrDiff) {
17
+ const poolConfig = KnowledgePoolResolver.resolve(this.targetDir, { explicitPoolDir: this.poolDir });
18
+ const graphBuilder = new GraphBuilder(this.targetDir, poolConfig.poolDir);
19
+ const invariants = graphBuilder.loadKnowledgeUnits();
20
+ const standards = StandardsLoader.load(this.targetDir, poolConfig.poolDir);
21
+ const normPath = filePath.replace(/\\/g, '/');
22
+ const applicableInvariants = invariants.filter(inv => graphBuilder.matchesAppliesTo(inv, normPath));
23
+ const violations = [];
24
+ const warnings = [];
25
+ // 1. Check deprecated patterns from .akb/standards.yaml
26
+ if (standards?.standards?.deprecated_patterns) {
27
+ for (const dep of standards.standards.deprecated_patterns) {
28
+ if (dep.appliesTo && !graphBuilder.matchesAppliesTo({ applies_to: [dep.appliesTo] }, normPath)) {
29
+ continue;
30
+ }
31
+ try {
32
+ const reg = new RegExp(dep.pattern, 'im');
33
+ if (reg.test(contentOrDiff)) {
34
+ violations.push({
35
+ invariantId: 'STANDARDS-DEPRECATED',
36
+ title: `Deprecated Pattern: ${dep.pattern}`,
37
+ rule: `Pattern "${dep.pattern}" is deprecated${dep.migrationTarget ? `. Migrate to ${dep.migrationTarget}` : ''}.`,
38
+ forbiddenPattern: dep.pattern,
39
+ severity: 'block',
40
+ reason: dep.reason || dep.description || 'Violates repository architectural standards.'
41
+ });
42
+ }
43
+ }
44
+ catch {
45
+ if (contentOrDiff.includes(dep.pattern)) {
46
+ violations.push({
47
+ invariantId: 'STANDARDS-DEPRECATED',
48
+ title: `Deprecated Pattern: ${dep.pattern}`,
49
+ rule: `Pattern "${dep.pattern}" is deprecated.`,
50
+ forbiddenPattern: dep.pattern,
51
+ severity: 'block',
52
+ reason: dep.reason || dep.description || 'Violates repository architectural standards.'
53
+ });
54
+ }
55
+ }
56
+ }
57
+ }
58
+ // 2. Check active Knowledge Units
59
+ for (const inv of applicableInvariants) {
60
+ if (inv.superseded_by) {
61
+ warnings.push(`Warning: Applicable invariant ${inv.id} has been superseded by ${inv.superseded_by}.`);
62
+ }
63
+ const dontItems = inv.dont || [];
64
+ for (const dont of dontItems) {
65
+ // Extract backticked code tokens or common forbidden code expressions (e.g. `require()`, `eval()`, `CommonJS require`)
66
+ const backtickMatches = dont.match(/`([^`]+)`/g);
67
+ const codeTokens = backtickMatches
68
+ ? backtickMatches.map(m => m.replace(/`/g, '').trim())
69
+ : [];
70
+ // Check explicit code tokens found in backticks
71
+ for (const token of codeTokens) {
72
+ if (token.length > 2 && contentOrDiff.includes(token)) {
73
+ violations.push({
74
+ invariantId: inv.id,
75
+ title: inv.title,
76
+ rule: inv.rule,
77
+ forbiddenPattern: token,
78
+ severity: inv.status === 'draft' ? 'warn' : 'block',
79
+ reason: `Violates "dont" directive: "${dont}". ${inv.reason}`
80
+ });
81
+ }
82
+ }
83
+ // Direct pattern matching for common keywords mentioned in "dont"
84
+ const patternsToTest = [
85
+ { keyword: 'require(', label: 'CommonJS require()' },
86
+ { keyword: 'eval(', label: 'eval()' },
87
+ { keyword: 'Thread.Sleep(', label: 'Thread.Sleep()' },
88
+ { keyword: 'DROP TABLE', label: 'Raw SQL DROP TABLE' },
89
+ { keyword: 'TRUNCATE TABLE', label: 'Raw SQL TRUNCATE TABLE' }
90
+ ];
91
+ for (const pt of patternsToTest) {
92
+ if (dont.toLowerCase().includes(pt.keyword.toLowerCase()) && contentOrDiff.includes(pt.keyword)) {
93
+ if (!violations.some(v => v.invariantId === inv.id && v.forbiddenPattern === pt.keyword)) {
94
+ violations.push({
95
+ invariantId: inv.id,
96
+ title: inv.title,
97
+ rule: inv.rule,
98
+ forbiddenPattern: pt.keyword,
99
+ severity: inv.status === 'draft' ? 'warn' : 'block',
100
+ reason: `Violates "dont" directive: "${dont}". ${inv.reason}`
101
+ });
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
107
+ const blockingViolations = violations.filter(v => v.severity === 'block');
108
+ return {
109
+ allowed: blockingViolations.length === 0,
110
+ targetFile: normPath,
111
+ violations,
112
+ warnings
113
+ };
114
+ }
115
+ /**
116
+ * Executes pre-commit / CI gate verification across git staged files.
117
+ */
118
+ checkStaged() {
119
+ const result = {
120
+ success: true,
121
+ filesChecked: 0,
122
+ violations: {},
123
+ warnings: {}
124
+ };
125
+ let stagedFilesStr = '';
126
+ try {
127
+ stagedFilesStr = execSync('git diff --cached --name-only', {
128
+ cwd: this.targetDir,
129
+ encoding: 'utf-8',
130
+ stdio: ['pipe', 'pipe', 'ignore']
131
+ }).trim();
132
+ }
133
+ catch {
134
+ return result;
135
+ }
136
+ if (!stagedFilesStr) {
137
+ return result;
138
+ }
139
+ const stagedFiles = stagedFilesStr
140
+ .split('\n')
141
+ .map(f => f.trim())
142
+ .filter(f => f.length > 0);
143
+ for (const file of stagedFiles) {
144
+ result.filesChecked++;
145
+ let diff = '';
146
+ try {
147
+ diff = execSync(`git diff --cached -- "${file}"`, {
148
+ cwd: this.targetDir,
149
+ encoding: 'utf-8',
150
+ stdio: ['pipe', 'pipe', 'ignore']
151
+ });
152
+ }
153
+ catch { }
154
+ if (!diff)
155
+ continue;
156
+ const evalRes = this.evaluate(file, diff);
157
+ if (!evalRes.allowed) {
158
+ result.success = false;
159
+ result.violations[file] = evalRes.violations;
160
+ }
161
+ if (evalRes.warnings.length > 0) {
162
+ result.warnings[file] = evalRes.warnings;
163
+ }
164
+ }
165
+ return result;
166
+ }
167
+ }
@@ -0,0 +1,38 @@
1
+ import type { RepositorySkeleton } from './types.js';
2
+ import { type CodebaseExtractor } from './extractors/index.js';
3
+ import { type PoolConfig } from './pool_resolver.js';
4
+ /**
5
+ * Checks whether a "packages" directory is a legacy .NET NuGet packages repository
6
+ * (contains repositories.config or versioned nupkg folders, and lacks package.json workspaces).
7
+ */
8
+ export declare function isNuGetPackagesDir(repoRoot: string): boolean;
9
+ /**
10
+ * Maps simple ignore patterns into glob-safe patterns (matching nested directories)
11
+ * for fast-glob / globby traversal performance on large monorepos.
12
+ */
13
+ export declare function getGlobSafeIgnores(ignores: string[]): string[];
14
+ export declare class Harvester {
15
+ static readonly MAX_FILE_SIZE_BYTES: number;
16
+ static readonly PREVIEW_CHUNK_SIZE_BYTES: number;
17
+ private repoRoot;
18
+ poolConfig: PoolConfig;
19
+ private ig;
20
+ private extractors;
21
+ constructor(repoRoot: string, extractors?: CodebaseExtractor[], poolDir?: string);
22
+ /**
23
+ * Safely reads a file with size guards to prevent V8 out-of-memory errors
24
+ * and catastrophic regex backtracking on massive or generated files.
25
+ */
26
+ readFileSafe(fullPath: string): string | null;
27
+ private loadGitignoreFile;
28
+ private initIgnore;
29
+ harvest(options?: {
30
+ useCache?: boolean;
31
+ cachePath?: string;
32
+ }): Promise<RepositorySkeleton>;
33
+ private analyzeTopology;
34
+ private extractManifests;
35
+ private extractSchemas;
36
+ private extractRoutesAndCommands;
37
+ private extractScriptsAndWorkflows;
38
+ }