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,269 @@
1
+ import path from 'node:path';
2
+ import fs from 'node:fs';
3
+ import { SchemaGenerator } from './schema_generator.js';
4
+ export class HookGenerator {
5
+ repoRoot;
6
+ constructor(repoRoot) {
7
+ this.repoRoot = path.resolve(repoRoot).replace(/\\/g, '/');
8
+ }
9
+ /**
10
+ * Detects the line ending (\r\n or \n) of an existing file, defaulting to OS standard.
11
+ */
12
+ detectEol(filePath) {
13
+ if (fs.existsSync(filePath)) {
14
+ try {
15
+ const sample = fs.readFileSync(filePath, 'utf-8');
16
+ if (sample.includes('\r\n'))
17
+ return '\r\n';
18
+ if (sample.includes('\n'))
19
+ return '\n';
20
+ }
21
+ catch { }
22
+ }
23
+ return process.platform === 'win32' ? '\r\n' : '\n';
24
+ }
25
+ /**
26
+ * Normalizes content with the specified line ending.
27
+ */
28
+ formatWithEol(content, eol) {
29
+ return content.replace(/\r?\n/g, eol);
30
+ }
31
+ /**
32
+ * Safely updates or creates a markdown hook file (AGENTS.md, CLAUDE.md, GEMINI.md)
33
+ * using non-destructive fenced blocks (<!-- akbo:start -->...<!-- akbo:end -->).
34
+ */
35
+ writeMarkdownHook(filePath, content, options) {
36
+ const eol = this.detectEol(filePath);
37
+ const trimmedContent = content.trim();
38
+ const fencedBlock = `<!-- akbo:start -->\n${trimmedContent}\n<!-- akbo:end -->`;
39
+ if (options?.forceHooks || !fs.existsSync(filePath)) {
40
+ const fullPayload = this.formatWithEol(fencedBlock + '\n', eol);
41
+ fs.writeFileSync(filePath, fullPayload, 'utf-8');
42
+ return;
43
+ }
44
+ const existing = fs.readFileSync(filePath, 'utf-8');
45
+ const startTag = '<!-- akbo:start -->';
46
+ const endTag = '<!-- akbo:end -->';
47
+ if (existing.includes(startTag) && existing.includes(endTag)) {
48
+ const reg = new RegExp(`${startTag}[\\s\\S]*?${endTag}`, 'g');
49
+ const updated = existing.replace(reg, fencedBlock);
50
+ fs.writeFileSync(filePath, this.formatWithEol(updated, eol), 'utf-8');
51
+ }
52
+ else {
53
+ // Append non-destructively to existing repository instructions
54
+ const separator = existing.endsWith('\n') ? '\n' : '\n\n';
55
+ const updated = existing + separator + fencedBlock + '\n';
56
+ fs.writeFileSync(filePath, this.formatWithEol(updated, eol), 'utf-8');
57
+ }
58
+ }
59
+ generateAgentsMd(index, units) {
60
+ const systemName = index.system_name || 'Project';
61
+ // Group units by domain
62
+ const domainMap = {};
63
+ for (const u of units) {
64
+ if (!domainMap[u.domain])
65
+ domainMap[u.domain] = [];
66
+ domainMap[u.domain].push(`[\`${u.id}\`](file:///${this.repoRoot}/knowledge/${u.domain}/${u.id}.yaml) (${u.title})`);
67
+ }
68
+ const personaSections = Object.entries(domainMap).map(([domain, list]) => {
69
+ const title = domain.charAt(0).toUpperCase() + domain.slice(1);
70
+ return ` - **${title} Tasks**: Inspect ${list.join(', ')}.`;
71
+ }).join('\n');
72
+ // Key invariants from units
73
+ const invariants = units.slice(0, 8).map(u => {
74
+ const statement = u.rule || u.decision || u.description || '';
75
+ return `- **${u.title}**: ${statement}`;
76
+ }).join('\n');
77
+ return `# 🤖 ${systemName} — AI Agent Workspace Instructions
78
+
79
+ > **ATTENTION ALL AI AGENTS (Antigravity, Cursor, Claude Code, Windsurf, Copilot, Gemini CLI)**
80
+ > This workspace enforces an automated **AI-Native Knowledge Base System** located in [\`knowledge/\`](file:///${this.repoRoot}/knowledge/).
81
+
82
+ ---
83
+
84
+ ## 1. Mandatory Pre-Execution Protocol (Strict Invariant)
85
+
86
+ > [!IMPORTANT]
87
+ > **MANDATORY FIRST TOOL ACTION**:
88
+ > On **ANY** task (including bug investigation, general questions, architecture review, refactoring, or writing code/tests), your **VERY FIRST tool call MUST be \`view_file\` on [\`knowledge/index.yaml\`](file:///${this.repoRoot}/knowledge/index.yaml)**.
89
+ >
90
+ > **DO NOT** perform speculative keyword \`grep_search\`, \`find_by_name\`, or open application code files until you have consulted \`knowledge/index.yaml\` and loaded the relevant Knowledge Units.
91
+
92
+ 1. **Query Master Index First**: Call \`view_file\` on [\`knowledge/index.yaml\`](file:///${this.repoRoot}/knowledge/index.yaml) to identify the Knowledge Units matching your role and domain.
93
+ 2. **Retrieve Persona Knowledge Units**:
94
+ ${personaSections}
95
+ 3. **Enforce Directives**: Strictly follow all \`rule\`, \`do\`, and \`dont\` fields in loaded Knowledge Units before taking any action.
96
+
97
+ ---
98
+
99
+ ## 2. Core Project Invariants
100
+
101
+ ${invariants}
102
+ `;
103
+ }
104
+ generateClaudeMd(index, units) {
105
+ return this.generateAgentsMd(index, units);
106
+ }
107
+ /**
108
+ * Generates standard llms.txt file (compact index for LLMs and AI coding agents).
109
+ */
110
+ generateLlmsTxt(index, units) {
111
+ const systemName = index.system_name || 'System';
112
+ const desc = index.description || 'AI-Native Knowledge Base & Operational Architecture Standard';
113
+ const unitList = units.map(u => {
114
+ const summary = u.rule || u.decision || u.reason || '';
115
+ const cleanSummary = summary.length > 120 ? summary.slice(0, 117) + '...' : summary;
116
+ return `- [${u.title}](knowledge/${u.domain}/${u.id}.yaml): ${cleanSummary}`;
117
+ }).join('\n');
118
+ return `# ${systemName}
119
+
120
+ > ${desc}
121
+
122
+ ## Overview
123
+ This repository enforces an automated AI-Native Knowledge Base System (AKBO) with strict invariants.
124
+ Before executing tasks, coding agents must consult knowledge/index.yaml and adhere to active domain standards.
125
+
126
+ ## Core Directives & Commands
127
+ - Inspect context: \`akbo context <target-file>\`
128
+ - Search invariants: \`akbo invariants -f <file> -d <domain>\`
129
+ - Verify rules: \`akbo validate\`
130
+
131
+ ## Knowledge Base Units
132
+ ${unitList}
133
+ `;
134
+ }
135
+ /**
136
+ * Generates standard llms-full.txt file (comprehensive context including full invariant rules).
137
+ */
138
+ generateLlmsFullTxt(index, units) {
139
+ const systemName = index.system_name || 'System';
140
+ const desc = index.description || 'Comprehensive AI-Native Knowledge Base & Architecture Index';
141
+ const fullUnits = units.map(u => {
142
+ const isDecision = u.type === 'architecture_decision';
143
+ const body = isDecision
144
+ ? `**Decision**: ${u.decision || ''}\n**Context**: ${u.context || u.reason || ''}`
145
+ : `**Rule**: ${u.rule || ''}\n\n**Do**:\n${(u.do || []).map((d) => ` - ${d}`).join('\n')}\n\n**Don't**:\n${(u.dont || []).map((d) => ` - ${d}`).join('\n')}\n\n**Reason**: ${u.reason || ''}`;
146
+ return `### ${u.id}: ${u.title} (${u.domain})
147
+ - **Type**: ${u.type}
148
+ - **Status**: ${u.status || 'approved'}
149
+ - **Version**: ${u.version || '1.0.0'}
150
+ - **Applies To**: ${(u.applies_to || []).join(', ') || 'all'}
151
+
152
+ ${body}
153
+ `;
154
+ }).join('\n---\n\n');
155
+ return `# ${systemName} — Full AI Context
156
+
157
+ > ${desc}
158
+
159
+ ${fullUnits}
160
+ `;
161
+ }
162
+ generateCursorRules() {
163
+ return `# Cursor Rules - AI-Native Knowledge Base Protocol
164
+ Always read knowledge/index.yaml first before proposing or executing code changes.
165
+ Follow all rules, do, and dont guidelines specified in knowledge/*/*.yaml.
166
+ Use 'akbo context <target>' to retrieve 0-token architectural context slices before writing code.
167
+ Keep README.md continuously updated in lockstep whenever adding or modifying CLI commands, options, dependencies, or architecture.
168
+ `;
169
+ }
170
+ generateMcpConfig() {
171
+ const config = {
172
+ mcpServers: {
173
+ akbo: {
174
+ command: 'npx',
175
+ args: ['-y', 'akbo-cli', 'mcp'],
176
+ env: {}
177
+ }
178
+ }
179
+ };
180
+ return JSON.stringify(config, null, 2);
181
+ }
182
+ writeAllHooks(index, units, options) {
183
+ const writtenFiles = [];
184
+ // 1. AGENTS.md & GEMINI.md & CLAUDE.md
185
+ const agentsMdContent = this.generateAgentsMd(index, units);
186
+ const agentsPath = path.join(this.repoRoot, 'AGENTS.md');
187
+ const geminiPath = path.join(this.repoRoot, 'GEMINI.md');
188
+ const claudePath = path.join(this.repoRoot, 'CLAUDE.md');
189
+ this.writeMarkdownHook(agentsPath, agentsMdContent, options);
190
+ writtenFiles.push(agentsPath);
191
+ this.writeMarkdownHook(geminiPath, agentsMdContent, options);
192
+ writtenFiles.push(geminiPath);
193
+ this.writeMarkdownHook(claudePath, agentsMdContent, options);
194
+ writtenFiles.push(claudePath);
195
+ // 2. .cursorrules
196
+ const cursorRulesContent = this.generateCursorRules();
197
+ const cursorRulesPath = path.join(this.repoRoot, '.cursorrules');
198
+ const cursorEol = this.detectEol(cursorRulesPath);
199
+ if (options?.forceHooks || !fs.existsSync(cursorRulesPath)) {
200
+ fs.writeFileSync(cursorRulesPath, this.formatWithEol(cursorRulesContent, cursorEol), 'utf-8');
201
+ writtenFiles.push(cursorRulesPath);
202
+ }
203
+ else {
204
+ const existingRules = fs.readFileSync(cursorRulesPath, 'utf-8');
205
+ if (!existingRules.includes('knowledge/index.yaml')) {
206
+ const sep = existingRules.endsWith('\n') ? '' : '\n';
207
+ fs.writeFileSync(cursorRulesPath, this.formatWithEol(existingRules + sep + '\n' + cursorRulesContent, cursorEol), 'utf-8');
208
+ }
209
+ writtenFiles.push(cursorRulesPath);
210
+ }
211
+ // 3. .cursor/mcp.json and .vscode/mcp.json
212
+ const cursorMcpDir = path.join(this.repoRoot, '.cursor');
213
+ const vscodeMcpDir = path.join(this.repoRoot, '.vscode');
214
+ fs.mkdirSync(cursorMcpDir, { recursive: true });
215
+ fs.mkdirSync(vscodeMcpDir, { recursive: true });
216
+ const cursorMcpPath = path.join(cursorMcpDir, 'mcp.json');
217
+ const vscodeMcpPath = path.join(vscodeMcpDir, 'mcp.json');
218
+ const writeSafeMcpConfig = (filePath) => {
219
+ const eol = this.detectEol(filePath);
220
+ let targetObj = {
221
+ mcpServers: {
222
+ akbo: {
223
+ command: 'npx',
224
+ args: ['-y', 'akbo-cli', 'mcp'],
225
+ env: {}
226
+ }
227
+ }
228
+ };
229
+ if (!options?.forceHooks && fs.existsSync(filePath)) {
230
+ try {
231
+ const existingJson = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
232
+ if (existingJson && typeof existingJson === 'object') {
233
+ targetObj = existingJson;
234
+ if (!targetObj.mcpServers)
235
+ targetObj.mcpServers = {};
236
+ targetObj.mcpServers.akbo = {
237
+ command: 'npx',
238
+ args: ['-y', 'akbo-cli', 'mcp'],
239
+ env: {}
240
+ };
241
+ }
242
+ }
243
+ catch { }
244
+ }
245
+ fs.writeFileSync(filePath, this.formatWithEol(JSON.stringify(targetObj, null, 2) + '\n', eol), 'utf-8');
246
+ };
247
+ writeSafeMcpConfig(cursorMcpPath);
248
+ writtenFiles.push(cursorMcpPath);
249
+ writeSafeMcpConfig(vscodeMcpPath);
250
+ writtenFiles.push(vscodeMcpPath);
251
+ // 4. llms.txt & llms-full.txt
252
+ const llmsTxtContent = this.generateLlmsTxt(index, units);
253
+ const llmsTxtPath = path.join(this.repoRoot, 'llms.txt');
254
+ const llmsTxtEol = this.detectEol(llmsTxtPath);
255
+ fs.writeFileSync(llmsTxtPath, this.formatWithEol(llmsTxtContent, llmsTxtEol), 'utf-8');
256
+ writtenFiles.push(llmsTxtPath);
257
+ const llmsFullTxtContent = this.generateLlmsFullTxt(index, units);
258
+ const llmsFullTxtPath = path.join(this.repoRoot, 'llms-full.txt');
259
+ const llmsFullTxtEol = this.detectEol(llmsFullTxtPath);
260
+ fs.writeFileSync(llmsFullTxtPath, this.formatWithEol(llmsFullTxtContent, llmsFullTxtEol), 'utf-8');
261
+ writtenFiles.push(llmsFullTxtPath);
262
+ // 5. JSON Schemas & .vscode/settings.json IDE autocomplete mappings
263
+ const schemaGen = new SchemaGenerator(this.repoRoot);
264
+ const { writtenSchemas, settingsPath } = schemaGen.writeAll();
265
+ writtenFiles.push(...writtenSchemas);
266
+ writtenFiles.push(settingsPath);
267
+ return writtenFiles;
268
+ }
269
+ }
@@ -0,0 +1,43 @@
1
+ import type { KnowledgeUnitContent } from '../types.js';
2
+ import { type PoolConfig } from '../pool_resolver.js';
3
+ export interface SkillImportResult {
4
+ imported: {
5
+ skillPath: string;
6
+ unitId: string;
7
+ unitPath: string;
8
+ title: string;
9
+ }[];
10
+ skipped: string[];
11
+ errors: string[];
12
+ }
13
+ export interface SkillImportOptions {
14
+ repoRoot: string;
15
+ poolDir?: string;
16
+ sourceGlobs?: string[];
17
+ domain?: string;
18
+ force?: boolean;
19
+ }
20
+ export declare class SkillImporter {
21
+ private repoRoot;
22
+ poolConfig: PoolConfig;
23
+ constructor(repoRoot?: string, poolDir?: string);
24
+ /**
25
+ * Scans for SKILL.md files and converts them into validated, human_curated Knowledge Units.
26
+ */
27
+ importSkills(options: SkillImportOptions): Promise<SkillImportResult>;
28
+ /**
29
+ * Parses SKILL.md YAML frontmatter and markdown body into KnowledgeUnitContent.
30
+ */
31
+ parseSkillMarkdown(relPath: string, content: string, defaultDomain?: string, referenceFiles?: string[]): KnowledgeUnitContent | null;
32
+ /**
33
+ * Infers targeted file/directory globs (e.g. WebClient/**, Shared/ExportService/**)
34
+ * from skill description and content before falling back to repo-wide wildcards.
35
+ */
36
+ private inferTargetedPathGlobs;
37
+ /**
38
+ * Discovers supporting reference markdown files in sibling directories (e.g. references/*.md).
39
+ */
40
+ private discoverReferenceFiles;
41
+ private extractFirstHeading;
42
+ private registerInIndexYaml;
43
+ }