akbo-cli 0.0.0-stage → 1.9.4

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 (66) hide show
  1. package/README.md +706 -2
  2. package/dist/catalog_store.d.ts +78 -0
  3. package/dist/catalog_store.js +375 -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 +1596 -0
  8. package/dist/extractors/base.d.ts +35 -0
  9. package/dist/extractors/base.js +17 -0
  10. package/dist/extractors/custom_extractor.d.ts +55 -0
  11. package/dist/extractors/custom_extractor.js +198 -0
  12. package/dist/extractors/dotnet_extractor.d.ts +11 -0
  13. package/dist/extractors/dotnet_extractor.js +579 -0
  14. package/dist/extractors/golang_extractor.d.ts +11 -0
  15. package/dist/extractors/golang_extractor.js +73 -0
  16. package/dist/extractors/index.d.ts +14 -0
  17. package/dist/extractors/index.js +30 -0
  18. package/dist/extractors/jvm_extractor.d.ts +11 -0
  19. package/dist/extractors/jvm_extractor.js +319 -0
  20. package/dist/extractors/node_extractor.d.ts +11 -0
  21. package/dist/extractors/node_extractor.js +306 -0
  22. package/dist/extractors/proto_graphql_extractor.d.ts +11 -0
  23. package/dist/extractors/proto_graphql_extractor.js +125 -0
  24. package/dist/extractors/python_extractor.d.ts +11 -0
  25. package/dist/extractors/python_extractor.js +298 -0
  26. package/dist/extractors/rust_extractor.d.ts +11 -0
  27. package/dist/extractors/rust_extractor.js +66 -0
  28. package/dist/graph_builder.d.ts +87 -0
  29. package/dist/graph_builder.js +1498 -0
  30. package/dist/harvester.d.ts +38 -0
  31. package/dist/harvester.js +461 -0
  32. package/dist/hook_generator.d.ts +26 -0
  33. package/dist/hook_generator.js +203 -0
  34. package/dist/importers/skill_importer.d.ts +43 -0
  35. package/dist/importers/skill_importer.js +470 -0
  36. package/dist/index.d.ts +17 -0
  37. package/dist/index.js +17 -0
  38. package/dist/indexer.d.ts +19 -0
  39. package/dist/indexer.js +108 -0
  40. package/dist/init_service.d.ts +37 -0
  41. package/dist/init_service.js +246 -0
  42. package/dist/mcp_server.d.ts +10 -0
  43. package/dist/mcp_server.js +632 -0
  44. package/dist/pool_resolver.d.ts +40 -0
  45. package/dist/pool_resolver.js +84 -0
  46. package/dist/provider.d.ts +135 -0
  47. package/dist/provider.js +880 -0
  48. package/dist/query_service.d.ts +33 -0
  49. package/dist/query_service.js +161 -0
  50. package/dist/schema_generator.d.ts +236 -0
  51. package/dist/schema_generator.js +264 -0
  52. package/dist/standards_loader.d.ts +7 -0
  53. package/dist/standards_loader.js +33 -0
  54. package/dist/types.d.ts +265 -0
  55. package/dist/types.js +105 -0
  56. package/dist/unit_synthesizer.d.ts +22 -0
  57. package/dist/unit_synthesizer.js +196 -0
  58. package/dist/validator.d.ts +13 -0
  59. package/dist/validator.js +152 -0
  60. package/dist/version.d.ts +6 -0
  61. package/dist/version.js +16 -0
  62. package/dist/watcher.d.ts +38 -0
  63. package/dist/watcher.js +132 -0
  64. package/package.json +56 -6
  65. package/schemas/index-schema.json +98 -0
  66. package/schemas/knowledge-unit.json +154 -0
@@ -0,0 +1,78 @@
1
+ import { type ValidationResult } from './validator.js';
2
+ export interface UpsertUnitsOptions {
3
+ targetDir: string;
4
+ poolDir?: string;
5
+ validate?: boolean;
6
+ }
7
+ export interface UpsertResult {
8
+ success: boolean;
9
+ count: number;
10
+ units: string[];
11
+ validation?: ValidationResult;
12
+ error?: string;
13
+ }
14
+ export interface GetUnitResult {
15
+ id: string;
16
+ domain: string;
17
+ file: string;
18
+ fullPath: string;
19
+ unit: Record<string, any>;
20
+ rawYaml: string;
21
+ }
22
+ export interface DeleteUnitResult {
23
+ success: boolean;
24
+ deletedId: string;
25
+ filePath?: string;
26
+ validation?: ValidationResult;
27
+ error?: string;
28
+ }
29
+ /**
30
+ * Detects whether content uses CRLF or LF line endings.
31
+ * Falls back to Windows default (\r\n) or POSIX default (\n).
32
+ */
33
+ export declare function detectEol(content?: string): string;
34
+ /**
35
+ * Normalizes text to the target EOL sequence (\r\n or \n).
36
+ */
37
+ export declare function normalizeEol(text: string, eol: string): string;
38
+ /**
39
+ * Normalizes applies_to glob patterns:
40
+ * - Converts backslashes (\) to POSIX slashes (/)
41
+ * - Strips leading ./
42
+ * - Strips repository root folder name prefix if present (e.g. "Monorepo/Subproject/**" -> "Subproject/**")
43
+ */
44
+ export declare function normalizeAppliesTo(patterns?: string[], repoRoot?: string): string[];
45
+ /**
46
+ * Atomically writes content to a file via a temporary file and rename,
47
+ * preserving target or detected EOL line endings.
48
+ */
49
+ export declare function atomicWriteFile(targetPath: string, content: string, explicitEol?: string): void;
50
+ /**
51
+ * Parses raw JSON or YAML text into an array of knowledge unit definitions.
52
+ * Defensively strips UTF-8 Byte Order Mark (BOM: \uFEFF) emitted by PowerShell.
53
+ */
54
+ export declare function parseUnitsFromText(rawText: string): Array<Record<string, any>>;
55
+ export declare class CatalogStore {
56
+ /**
57
+ * Upserts one or more knowledge units atomically into the pool's knowledge directory,
58
+ * updates knowledge/index.yaml once with atomic rename and EOL preservation,
59
+ * and optionally executes runtime validation.
60
+ */
61
+ static upsertUnits(units: Array<Record<string, any>>, options: UpsertUnitsOptions): Promise<UpsertResult>;
62
+ /**
63
+ * Retrieves a knowledge unit by ID from the knowledge pool.
64
+ */
65
+ static getUnit(id: string, options: {
66
+ targetDir: string;
67
+ poolDir?: string;
68
+ }): GetUnitResult | null;
69
+ /**
70
+ * Deletes a knowledge unit from the pool, removes its index reference,
71
+ * decrements unit count, clears caches, and optionally validates.
72
+ */
73
+ static deleteUnit(id: string, options: {
74
+ targetDir: string;
75
+ poolDir?: string;
76
+ validate?: boolean;
77
+ }): Promise<DeleteUnitResult>;
78
+ }
@@ -0,0 +1,375 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import YAML from 'yaml';
4
+ import { KnowledgePoolResolver } from './pool_resolver.js';
5
+ import { KnowledgeValidator } from './validator.js';
6
+ import { GraphBuilder } from './graph_builder.js';
7
+ import { StandardKnowledgeUnitSchema, DecisionKnowledgeUnitSchema } from './types.js';
8
+ /**
9
+ * Detects whether content uses CRLF or LF line endings.
10
+ * Falls back to Windows default (\r\n) or POSIX default (\n).
11
+ */
12
+ export function detectEol(content) {
13
+ if (content) {
14
+ if (content.includes('\r\n'))
15
+ return '\r\n';
16
+ if (content.includes('\n'))
17
+ return '\n';
18
+ }
19
+ return process.platform === 'win32' ? '\r\n' : '\n';
20
+ }
21
+ /**
22
+ * Normalizes text to the target EOL sequence (\r\n or \n).
23
+ */
24
+ export function normalizeEol(text, eol) {
25
+ const lf = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
26
+ return eol === '\n' ? lf : lf.replace(/\n/g, eol);
27
+ }
28
+ /**
29
+ * Normalizes applies_to glob patterns:
30
+ * - Converts backslashes (\) to POSIX slashes (/)
31
+ * - Strips leading ./
32
+ * - Strips repository root folder name prefix if present (e.g. "Monorepo/Subproject/**" -> "Subproject/**")
33
+ */
34
+ export function normalizeAppliesTo(patterns = [], repoRoot) {
35
+ const repoBase = repoRoot ? path.basename(repoRoot).toLowerCase() : undefined;
36
+ return patterns.map(pat => {
37
+ let p = pat.replace(/\\/g, '/').replace(/^\.\//, '');
38
+ if (repoBase && p.toLowerCase().startsWith(`${repoBase}/`)) {
39
+ p = p.slice(repoBase.length + 1);
40
+ }
41
+ return p;
42
+ });
43
+ }
44
+ /**
45
+ * Atomically writes content to a file via a temporary file and rename,
46
+ * preserving target or detected EOL line endings.
47
+ */
48
+ export function atomicWriteFile(targetPath, content, explicitEol) {
49
+ const dir = path.dirname(targetPath);
50
+ if (!fs.existsSync(dir)) {
51
+ fs.mkdirSync(dir, { recursive: true });
52
+ }
53
+ let existingContent;
54
+ if (fs.existsSync(targetPath)) {
55
+ try {
56
+ existingContent = fs.readFileSync(targetPath, 'utf-8');
57
+ }
58
+ catch { }
59
+ }
60
+ const targetEol = explicitEol || detectEol(existingContent);
61
+ const formattedContent = normalizeEol(content, targetEol);
62
+ const tmpPath = `${targetPath}.${Date.now()}.${Math.random().toString(36).substring(2, 8)}.tmp`;
63
+ fs.writeFileSync(tmpPath, formattedContent, 'utf-8');
64
+ fs.renameSync(tmpPath, targetPath);
65
+ }
66
+ /**
67
+ * Parses raw JSON or YAML text into an array of knowledge unit definitions.
68
+ * Defensively strips UTF-8 Byte Order Mark (BOM: \uFEFF) emitted by PowerShell.
69
+ */
70
+ export function parseUnitsFromText(rawText) {
71
+ const clean = rawText.replace(/^\uFEFF/, '').trim();
72
+ if (!clean)
73
+ return [];
74
+ let parsed;
75
+ if (clean.startsWith('{') || clean.startsWith('[')) {
76
+ try {
77
+ parsed = JSON.parse(clean);
78
+ }
79
+ catch {
80
+ parsed = YAML.parse(clean);
81
+ }
82
+ }
83
+ else {
84
+ parsed = YAML.parse(clean);
85
+ }
86
+ if (Array.isArray(parsed)) {
87
+ return parsed;
88
+ }
89
+ if (parsed && Array.isArray(parsed.units)) {
90
+ return parsed.units;
91
+ }
92
+ if (parsed && typeof parsed === 'object') {
93
+ return [parsed];
94
+ }
95
+ return [];
96
+ }
97
+ export class CatalogStore {
98
+ /**
99
+ * Upserts one or more knowledge units atomically into the pool's knowledge directory,
100
+ * updates knowledge/index.yaml once with atomic rename and EOL preservation,
101
+ * and optionally executes runtime validation.
102
+ */
103
+ static async upsertUnits(units, options) {
104
+ if (!units || units.length === 0) {
105
+ return { success: true, count: 0, units: [] };
106
+ }
107
+ const targetDir = path.resolve(options.targetDir);
108
+ const poolConfig = KnowledgePoolResolver.resolve(targetDir, { explicitPoolDir: options.poolDir });
109
+ const savedUnits = [];
110
+ // Process and validate all units before writing
111
+ const validatedData = [];
112
+ for (const unit of units) {
113
+ if (!unit.id || typeof unit.id !== 'string') {
114
+ return { success: false, count: 0, units: [], error: 'Every unit must have a non-empty string "id".' };
115
+ }
116
+ const domain = (unit.domain || 'development').trim();
117
+ const isDecision = unit.type === 'architecture_decision' || domain === 'decisions' || typeof unit.decision === 'string';
118
+ let validUnit;
119
+ if (isDecision) {
120
+ const payload = {
121
+ id: unit.id,
122
+ type: 'architecture_decision',
123
+ title: unit.title || unit.id,
124
+ domain: 'decisions',
125
+ decision: unit.decision || unit.rule || '',
126
+ context: unit.context || unit.reason || undefined,
127
+ status: unit.status || 'approved',
128
+ version: unit.version || '1.0.0',
129
+ authority: unit.authority || { level: 'human_curated', confidence: 'verified' },
130
+ owner: unit.owner || { team: 'core_architecture' },
131
+ applies_to: normalizeAppliesTo(unit.applies_to || [], targetDir),
132
+ related_items: unit.related_items || []
133
+ };
134
+ const validation = DecisionKnowledgeUnitSchema.safeParse(payload);
135
+ if (!validation.success) {
136
+ return {
137
+ success: false,
138
+ count: 0,
139
+ units: [],
140
+ error: `Validation failed for decision unit "${unit.id}": ${validation.error.message}`
141
+ };
142
+ }
143
+ validUnit = validation.data;
144
+ }
145
+ else {
146
+ const payload = {
147
+ id: unit.id,
148
+ type: unit.type || 'development_standard',
149
+ title: unit.title || unit.id,
150
+ domain,
151
+ status: unit.status || 'approved',
152
+ version: unit.version || '1.0.0',
153
+ authority: unit.authority || { level: 'human_curated', confidence: 'verified' },
154
+ owner: unit.owner || { team: 'core_architecture' },
155
+ applies_to: normalizeAppliesTo(unit.applies_to || [], targetDir),
156
+ rule: unit.rule || '',
157
+ do: Array.isArray(unit.do) && unit.do.length > 0 ? unit.do : ['Follow the standard rule directives.'],
158
+ dont: Array.isArray(unit.dont) && unit.dont.length > 0 ? unit.dont : ['Do not violate the standard rule directives.'],
159
+ reason: unit.reason || 'Guarantees architectural compliance and system consistency.',
160
+ related_items: unit.related_items || []
161
+ };
162
+ const validation = StandardKnowledgeUnitSchema.safeParse(payload);
163
+ if (!validation.success) {
164
+ return {
165
+ success: false,
166
+ count: 0,
167
+ units: [],
168
+ error: `Validation failed for unit "${unit.id}": ${validation.error.message}`
169
+ };
170
+ }
171
+ validUnit = validation.data;
172
+ }
173
+ const domainDir = path.join(poolConfig.knowledgeDir, validUnit.domain);
174
+ const unitFilePath = path.join(domainDir, `${validUnit.id}.yaml`);
175
+ const yamlString = YAML.stringify(validUnit);
176
+ validatedData.push({
177
+ filePath: unitFilePath,
178
+ yamlString,
179
+ id: validUnit.id,
180
+ domain: validUnit.domain,
181
+ title: validUnit.title
182
+ });
183
+ }
184
+ // Write all validated unit files atomically
185
+ for (const item of validatedData) {
186
+ atomicWriteFile(item.filePath, item.yamlString);
187
+ savedUnits.push({ id: item.id, domain: item.domain, title: item.title });
188
+ }
189
+ // Update poolDir/knowledge/index.yaml once atomically
190
+ const indexPath = path.join(poolConfig.knowledgeDir, 'index.yaml');
191
+ let indexObj = {
192
+ system_name: path.basename(targetDir),
193
+ repository_root: targetDir.replace(/\\/g, '/'),
194
+ knowledge_units_count: 0,
195
+ last_updated: new Date().toISOString().split('T')[0],
196
+ knowledge_units: {}
197
+ };
198
+ let existingIndexRaw;
199
+ if (fs.existsSync(indexPath)) {
200
+ try {
201
+ existingIndexRaw = fs.readFileSync(indexPath, 'utf-8');
202
+ indexObj = YAML.parse(existingIndexRaw) || indexObj;
203
+ }
204
+ catch { }
205
+ }
206
+ if (!indexObj.repository_root) {
207
+ indexObj.repository_root = targetDir.replace(/\\/g, '/');
208
+ }
209
+ indexObj.knowledge_units = indexObj.knowledge_units || {};
210
+ for (const saved of savedUnits) {
211
+ indexObj.knowledge_units[saved.domain] = indexObj.knowledge_units[saved.domain] || [];
212
+ const domainList = indexObj.knowledge_units[saved.domain];
213
+ const existingIdx = domainList.findIndex((u) => u.id === saved.id);
214
+ const entry = {
215
+ id: saved.id,
216
+ file: `knowledge/${saved.domain}/${saved.id}.yaml`,
217
+ title: saved.title
218
+ };
219
+ if (existingIdx >= 0) {
220
+ domainList[existingIdx] = entry;
221
+ }
222
+ else {
223
+ domainList.push(entry);
224
+ }
225
+ }
226
+ let totalCount = 0;
227
+ for (const d of Object.keys(indexObj.knowledge_units)) {
228
+ if (Array.isArray(indexObj.knowledge_units[d])) {
229
+ totalCount += indexObj.knowledge_units[d].length;
230
+ }
231
+ }
232
+ indexObj.knowledge_units_count = totalCount;
233
+ indexObj.last_updated = new Date().toISOString().split('T')[0];
234
+ atomicWriteFile(indexPath, YAML.stringify(indexObj), detectEol(existingIndexRaw));
235
+ // Invalidate caches
236
+ GraphBuilder.clearCache();
237
+ let validationResult;
238
+ if (options.validate) {
239
+ const validator = new KnowledgeValidator(targetDir, poolConfig.poolDir);
240
+ validationResult = await validator.validate();
241
+ }
242
+ return {
243
+ success: true,
244
+ count: savedUnits.length,
245
+ units: savedUnits.map(u => u.id),
246
+ validation: validationResult
247
+ };
248
+ }
249
+ /**
250
+ * Retrieves a knowledge unit by ID from the knowledge pool.
251
+ */
252
+ static getUnit(id, options) {
253
+ const targetDir = path.resolve(options.targetDir);
254
+ const poolConfig = KnowledgePoolResolver.resolve(targetDir, { explicitPoolDir: options.poolDir });
255
+ const kDir = poolConfig.knowledgeDir;
256
+ if (!fs.existsSync(kDir))
257
+ return null;
258
+ // First check index.yaml
259
+ const indexPath = path.join(kDir, 'index.yaml');
260
+ let targetRelFile;
261
+ if (fs.existsSync(indexPath)) {
262
+ try {
263
+ const indexDoc = YAML.parse(fs.readFileSync(indexPath, 'utf-8'));
264
+ if (indexDoc?.knowledge_units) {
265
+ for (const d of Object.keys(indexDoc.knowledge_units)) {
266
+ const list = indexDoc.knowledge_units[d];
267
+ if (Array.isArray(list)) {
268
+ const match = list.find((item) => item.id === id);
269
+ if (match && match.file) {
270
+ targetRelFile = match.file;
271
+ break;
272
+ }
273
+ }
274
+ }
275
+ }
276
+ }
277
+ catch { }
278
+ }
279
+ let fullPath = targetRelFile ? path.resolve(poolConfig.poolDir, targetRelFile) : undefined;
280
+ if (!fullPath || !fs.existsSync(fullPath)) {
281
+ // Direct file search across knowledge/<domain>/<id>.yaml
282
+ try {
283
+ const entries = fs.readdirSync(kDir, { withFileTypes: true });
284
+ for (const entry of entries) {
285
+ if (entry.isDirectory()) {
286
+ const candidate = path.join(kDir, entry.name, `${id}.yaml`);
287
+ const candidateYml = path.join(kDir, entry.name, `${id}.yml`);
288
+ if (fs.existsSync(candidate)) {
289
+ fullPath = candidate;
290
+ break;
291
+ }
292
+ if (fs.existsSync(candidateYml)) {
293
+ fullPath = candidateYml;
294
+ break;
295
+ }
296
+ }
297
+ }
298
+ }
299
+ catch { }
300
+ }
301
+ if (!fullPath || !fs.existsSync(fullPath)) {
302
+ return null;
303
+ }
304
+ const rawYaml = fs.readFileSync(fullPath, 'utf-8');
305
+ const unit = YAML.parse(rawYaml) || {};
306
+ const domain = unit.domain || path.basename(path.dirname(fullPath));
307
+ const relFile = path.relative(poolConfig.poolDir, fullPath).replace(/\\/g, '/');
308
+ return {
309
+ id: unit.id || id,
310
+ domain,
311
+ file: relFile,
312
+ fullPath,
313
+ unit,
314
+ rawYaml
315
+ };
316
+ }
317
+ /**
318
+ * Deletes a knowledge unit from the pool, removes its index reference,
319
+ * decrements unit count, clears caches, and optionally validates.
320
+ */
321
+ static async deleteUnit(id, options) {
322
+ const targetDir = path.resolve(options.targetDir);
323
+ const poolConfig = KnowledgePoolResolver.resolve(targetDir, { explicitPoolDir: options.poolDir });
324
+ const existing = CatalogStore.getUnit(id, options);
325
+ if (!existing) {
326
+ return {
327
+ success: false,
328
+ deletedId: id,
329
+ error: `Knowledge unit "${id}" was not found in knowledge pool.`
330
+ };
331
+ }
332
+ // Delete the YAML file
333
+ if (fs.existsSync(existing.fullPath)) {
334
+ fs.unlinkSync(existing.fullPath);
335
+ }
336
+ // Update index.yaml
337
+ const indexPath = path.join(poolConfig.knowledgeDir, 'index.yaml');
338
+ let existingIndexRaw;
339
+ if (fs.existsSync(indexPath)) {
340
+ try {
341
+ existingIndexRaw = fs.readFileSync(indexPath, 'utf-8');
342
+ const indexObj = YAML.parse(existingIndexRaw);
343
+ if (indexObj?.knowledge_units) {
344
+ for (const d of Object.keys(indexObj.knowledge_units)) {
345
+ if (Array.isArray(indexObj.knowledge_units[d])) {
346
+ indexObj.knowledge_units[d] = indexObj.knowledge_units[d].filter((u) => u.id !== id);
347
+ }
348
+ }
349
+ let total = 0;
350
+ for (const d of Object.keys(indexObj.knowledge_units)) {
351
+ if (Array.isArray(indexObj.knowledge_units[d])) {
352
+ total += indexObj.knowledge_units[d].length;
353
+ }
354
+ }
355
+ indexObj.knowledge_units_count = total;
356
+ indexObj.last_updated = new Date().toISOString().split('T')[0];
357
+ atomicWriteFile(indexPath, YAML.stringify(indexObj), detectEol(existingIndexRaw));
358
+ }
359
+ }
360
+ catch { }
361
+ }
362
+ GraphBuilder.clearCache();
363
+ let validationResult;
364
+ if (options.validate) {
365
+ const validator = new KnowledgeValidator(targetDir, poolConfig.poolDir);
366
+ validationResult = await validator.validate();
367
+ }
368
+ return {
369
+ success: true,
370
+ deletedId: id,
371
+ filePath: existing.fullPath,
372
+ validation: validationResult
373
+ };
374
+ }
375
+ }
@@ -0,0 +1,11 @@
1
+ export interface CleanOptions {
2
+ includeDist?: boolean;
3
+ }
4
+ export interface CleanResult {
5
+ removed: string[];
6
+ totalBytesFreed: number;
7
+ }
8
+ /**
9
+ * Safely removes intermediate and temporary AKBO artifacts while preserving user configurations.
10
+ */
11
+ export declare function cleanArtifacts(dir: string, options?: CleanOptions): CleanResult;
@@ -0,0 +1,92 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ /**
4
+ * Calculates total size of a directory recursively.
5
+ */
6
+ function getDirectorySize(dirPath) {
7
+ let size = 0;
8
+ try {
9
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
10
+ for (const entry of entries) {
11
+ const fullPath = path.join(dirPath, entry.name);
12
+ if (entry.isDirectory()) {
13
+ size += getDirectorySize(fullPath);
14
+ }
15
+ else if (entry.isFile()) {
16
+ try {
17
+ size += fs.statSync(fullPath).size;
18
+ }
19
+ catch {
20
+ // Ignore unreadable files
21
+ }
22
+ }
23
+ }
24
+ }
25
+ catch {
26
+ // Ignore unreadable directories
27
+ }
28
+ return size;
29
+ }
30
+ const PRESERVED_CONFIG_FILES = new Set([
31
+ 'standards.yaml',
32
+ 'standards.yml',
33
+ 'standards.json',
34
+ 'custom-extractors.yaml',
35
+ 'custom-extractors.yml',
36
+ 'custom-extractors.json',
37
+ 'ignore'
38
+ ]);
39
+ /**
40
+ * Safely removes intermediate and temporary AKBO artifacts while preserving user configurations.
41
+ */
42
+ export function cleanArtifacts(dir, options = {}) {
43
+ const targetDir = path.resolve(dir);
44
+ const removed = [];
45
+ let totalBytesFreed = 0;
46
+ const akbDir = path.join(targetDir, '.akb');
47
+ if (fs.existsSync(akbDir)) {
48
+ try {
49
+ const entries = fs.readdirSync(akbDir);
50
+ const hasPreserved = entries.some(e => PRESERVED_CONFIG_FILES.has(e));
51
+ if (!hasPreserved) {
52
+ const size = getDirectorySize(akbDir);
53
+ totalBytesFreed += size;
54
+ fs.rmSync(akbDir, { recursive: true, force: true });
55
+ removed.push('.akb');
56
+ }
57
+ else {
58
+ // Only remove non-preserved files/folders inside .akb
59
+ for (const entry of entries) {
60
+ if (!PRESERVED_CONFIG_FILES.has(entry)) {
61
+ const entryPath = path.join(akbDir, entry);
62
+ const size = getDirectorySize(entryPath);
63
+ totalBytesFreed += size;
64
+ fs.rmSync(entryPath, { recursive: true, force: true });
65
+ removed.push(`.akb/${entry}`);
66
+ }
67
+ }
68
+ }
69
+ }
70
+ catch {
71
+ // Skip deletion failures
72
+ }
73
+ }
74
+ if (options.includeDist) {
75
+ const distDir = path.join(targetDir, 'dist');
76
+ if (fs.existsSync(distDir)) {
77
+ try {
78
+ const size = getDirectorySize(distDir);
79
+ totalBytesFreed += size;
80
+ fs.rmSync(distDir, { recursive: true, force: true });
81
+ removed.push('dist');
82
+ }
83
+ catch {
84
+ // Skip deletion failures
85
+ }
86
+ }
87
+ }
88
+ return {
89
+ removed,
90
+ totalBytesFreed
91
+ };
92
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import 'dotenv/config';