k0ntext 3.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 (239) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +623 -0
  3. package/bin/k0ntext.js +12 -0
  4. package/dist/agents/cleanup-agent.d.ts +39 -0
  5. package/dist/agents/cleanup-agent.d.ts.map +1 -0
  6. package/dist/agents/cleanup-agent.js +56 -0
  7. package/dist/agents/cleanup-agent.js.map +1 -0
  8. package/dist/agents/performance-agent.d.ts +37 -0
  9. package/dist/agents/performance-agent.d.ts.map +1 -0
  10. package/dist/agents/performance-agent.js +91 -0
  11. package/dist/agents/performance-agent.js.map +1 -0
  12. package/dist/analyzer/index.d.ts +5 -0
  13. package/dist/analyzer/index.d.ts.map +1 -0
  14. package/dist/analyzer/index.js +5 -0
  15. package/dist/analyzer/index.js.map +1 -0
  16. package/dist/analyzer/intelligent-analyzer.d.ts +111 -0
  17. package/dist/analyzer/intelligent-analyzer.d.ts.map +1 -0
  18. package/dist/analyzer/intelligent-analyzer.js +537 -0
  19. package/dist/analyzer/intelligent-analyzer.js.map +1 -0
  20. package/dist/cli/commands/cleanup.d.ts +3 -0
  21. package/dist/cli/commands/cleanup.d.ts.map +1 -0
  22. package/dist/cli/commands/cleanup.js +24 -0
  23. package/dist/cli/commands/cleanup.js.map +1 -0
  24. package/dist/cli/commands/export.d.ts +9 -0
  25. package/dist/cli/commands/export.d.ts.map +1 -0
  26. package/dist/cli/commands/export.js +72 -0
  27. package/dist/cli/commands/export.js.map +1 -0
  28. package/dist/cli/commands/import.d.ts +9 -0
  29. package/dist/cli/commands/import.d.ts.map +1 -0
  30. package/dist/cli/commands/import.js +62 -0
  31. package/dist/cli/commands/import.js.map +1 -0
  32. package/dist/cli/commands/performance.d.ts +9 -0
  33. package/dist/cli/commands/performance.d.ts.map +1 -0
  34. package/dist/cli/commands/performance.js +36 -0
  35. package/dist/cli/commands/performance.js.map +1 -0
  36. package/dist/cli/commands/validate.d.ts +9 -0
  37. package/dist/cli/commands/validate.d.ts.map +1 -0
  38. package/dist/cli/commands/validate.js +82 -0
  39. package/dist/cli/commands/validate.js.map +1 -0
  40. package/dist/cli/commands/watch.d.ts +9 -0
  41. package/dist/cli/commands/watch.d.ts.map +1 -0
  42. package/dist/cli/commands/watch.js +72 -0
  43. package/dist/cli/commands/watch.js.map +1 -0
  44. package/dist/cli/generate.d.ts +3 -0
  45. package/dist/cli/generate.d.ts.map +1 -0
  46. package/dist/cli/generate.js +194 -0
  47. package/dist/cli/generate.js.map +1 -0
  48. package/dist/cli/index.d.ts +9 -0
  49. package/dist/cli/index.d.ts.map +1 -0
  50. package/dist/cli/index.js +448 -0
  51. package/dist/cli/index.js.map +1 -0
  52. package/dist/cli/sync.d.ts +26 -0
  53. package/dist/cli/sync.d.ts.map +1 -0
  54. package/dist/cli/sync.js +163 -0
  55. package/dist/cli/sync.js.map +1 -0
  56. package/dist/config/cleanup-config.d.ts +26 -0
  57. package/dist/config/cleanup-config.d.ts.map +1 -0
  58. package/dist/config/cleanup-config.js +21 -0
  59. package/dist/config/cleanup-config.js.map +1 -0
  60. package/dist/db/client.d.ts +284 -0
  61. package/dist/db/client.d.ts.map +1 -0
  62. package/dist/db/client.js +688 -0
  63. package/dist/db/client.js.map +1 -0
  64. package/dist/db/index.d.ts +6 -0
  65. package/dist/db/index.d.ts.map +1 -0
  66. package/dist/db/index.js +6 -0
  67. package/dist/db/index.js.map +1 -0
  68. package/dist/db/schema.d.ts +41 -0
  69. package/dist/db/schema.d.ts.map +1 -0
  70. package/dist/db/schema.js +226 -0
  71. package/dist/db/schema.js.map +1 -0
  72. package/dist/embeddings/index.d.ts +5 -0
  73. package/dist/embeddings/index.d.ts.map +1 -0
  74. package/dist/embeddings/index.js +5 -0
  75. package/dist/embeddings/index.js.map +1 -0
  76. package/dist/embeddings/openrouter.d.ts +133 -0
  77. package/dist/embeddings/openrouter.d.ts.map +1 -0
  78. package/dist/embeddings/openrouter.js +455 -0
  79. package/dist/embeddings/openrouter.js.map +1 -0
  80. package/dist/index.d.ts +14 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/index.js +18 -0
  83. package/dist/index.js.map +1 -0
  84. package/dist/mcp.d.ts +29 -0
  85. package/dist/mcp.d.ts.map +1 -0
  86. package/dist/mcp.js +257 -0
  87. package/dist/mcp.js.map +1 -0
  88. package/docs/ARCHIVE/MIGRATE_TO_NEW_REPO.md +222 -0
  89. package/docs/ARCHIVE/MIGRATE_TO_UNIFIED.md +220 -0
  90. package/docs/CLEANUP.md +76 -0
  91. package/docs/MCP_QUICKSTART.md +219 -0
  92. package/docs/QUICKSTART.md +119 -0
  93. package/docs/TROUBLESHOOTING.md +611 -0
  94. package/package.json +100 -0
  95. package/skills/context-optimize/SKILL.md +86 -0
  96. package/skills/implement/SKILL.md +150 -0
  97. package/skills/plan/SKILL.md +143 -0
  98. package/skills/research/SKILL.md +103 -0
  99. package/skills/validate/SKILL.md +62 -0
  100. package/skills/verify-docs/SKILL.md +77 -0
  101. package/src/agents/cleanup-agent.ts +96 -0
  102. package/src/agents/performance-agent.ts +117 -0
  103. package/src/analyzer/index.ts +10 -0
  104. package/src/analyzer/intelligent-analyzer.ts +640 -0
  105. package/src/cli/commands/cleanup.ts +26 -0
  106. package/src/cli/commands/export.ts +82 -0
  107. package/src/cli/commands/import.ts +73 -0
  108. package/src/cli/commands/performance.ts +40 -0
  109. package/src/cli/commands/validate.ts +98 -0
  110. package/src/cli/commands/watch.ts +83 -0
  111. package/src/cli/generate.ts +219 -0
  112. package/src/cli/index.ts +510 -0
  113. package/src/cli/sync.ts +194 -0
  114. package/src/config/cleanup-config.ts +42 -0
  115. package/src/db/client.ts +949 -0
  116. package/src/db/index.ts +19 -0
  117. package/src/db/schema.ts +241 -0
  118. package/src/embeddings/index.ts +11 -0
  119. package/src/embeddings/openrouter.ts +592 -0
  120. package/src/index.ts +57 -0
  121. package/src/mcp.ts +354 -0
  122. package/templates/AI_CONTEXT.md.template +245 -0
  123. package/templates/base/README.md +260 -0
  124. package/templates/base/RPI_WORKFLOW_PLAN.md +325 -0
  125. package/templates/base/agents/api-developer.md +76 -0
  126. package/templates/base/agents/context-engineer.md +525 -0
  127. package/templates/base/agents/core-architect.md +76 -0
  128. package/templates/base/agents/database-ops.md +76 -0
  129. package/templates/base/agents/deployment-ops.md +76 -0
  130. package/templates/base/agents/integration-hub.md +76 -0
  131. package/templates/base/analytics/README.md +114 -0
  132. package/templates/base/automation/config.json +58 -0
  133. package/templates/base/automation/generators/code-mapper.js +308 -0
  134. package/templates/base/automation/generators/index-builder.js +321 -0
  135. package/templates/base/automation/hooks/post-commit.sh +83 -0
  136. package/templates/base/automation/hooks/pre-commit.sh +103 -0
  137. package/templates/base/ci-templates/README.md +108 -0
  138. package/templates/base/ci-templates/github-actions/context-check.yml +144 -0
  139. package/templates/base/ci-templates/github-actions/validate-docs.yml +105 -0
  140. package/templates/base/commands/analytics.md +238 -0
  141. package/templates/base/commands/auto-sync.md +172 -0
  142. package/templates/base/commands/collab.md +194 -0
  143. package/templates/base/commands/context-optimize.md +226 -0
  144. package/templates/base/commands/help.md +485 -0
  145. package/templates/base/commands/rpi-implement.md +164 -0
  146. package/templates/base/commands/rpi-plan.md +147 -0
  147. package/templates/base/commands/rpi-research.md +145 -0
  148. package/templates/base/commands/session-resume.md +144 -0
  149. package/templates/base/commands/session-save.md +112 -0
  150. package/templates/base/commands/validate-all.md +77 -0
  151. package/templates/base/commands/verify-docs-current.md +86 -0
  152. package/templates/base/config/base.json +57 -0
  153. package/templates/base/config/environments/development.json +13 -0
  154. package/templates/base/config/environments/production.json +17 -0
  155. package/templates/base/config/environments/staging.json +13 -0
  156. package/templates/base/config/local.json.example +21 -0
  157. package/templates/base/context/.meta/generated-at.json +18 -0
  158. package/templates/base/context/ARCHITECTURE_SNAPSHOT.md +156 -0
  159. package/templates/base/context/CODE_TO_WORKFLOW_MAP.md +94 -0
  160. package/templates/base/context/FILE_OWNERSHIP.md +57 -0
  161. package/templates/base/context/INTEGRATION_POINTS.md +92 -0
  162. package/templates/base/context/KNOWN_GOTCHAS.md +195 -0
  163. package/templates/base/context/TESTING_MAP.md +95 -0
  164. package/templates/base/context/WORKFLOW_INDEX.md +129 -0
  165. package/templates/base/context/workflows/WORKFLOW_TEMPLATE.md +294 -0
  166. package/templates/base/indexes/agents/CAPABILITY_MATRIX.md +255 -0
  167. package/templates/base/indexes/agents/CATEGORY_INDEX.md +44 -0
  168. package/templates/base/indexes/code/CATEGORY_INDEX.md +38 -0
  169. package/templates/base/indexes/routing/CATEGORY_INDEX.md +39 -0
  170. package/templates/base/indexes/search/CATEGORY_INDEX.md +39 -0
  171. package/templates/base/indexes/workflows/CATEGORY_INDEX.md +38 -0
  172. package/templates/base/knowledge/README.md +98 -0
  173. package/templates/base/knowledge/sessions/README.md +88 -0
  174. package/templates/base/knowledge/sessions/TEMPLATE.md +150 -0
  175. package/templates/base/knowledge/shared/decisions/0001-adopt-context-engineering.md +144 -0
  176. package/templates/base/knowledge/shared/decisions/README.md +49 -0
  177. package/templates/base/knowledge/shared/decisions/TEMPLATE.md +123 -0
  178. package/templates/base/knowledge/shared/patterns/README.md +62 -0
  179. package/templates/base/knowledge/shared/patterns/TEMPLATE.md +120 -0
  180. package/templates/base/plans/PLAN_TEMPLATE.md +316 -0
  181. package/templates/base/plans/active/.gitkeep +0 -0
  182. package/templates/base/plans/completed/.gitkeep +0 -0
  183. package/templates/base/research/RESEARCH_TEMPLATE.md +245 -0
  184. package/templates/base/research/active/.gitkeep +0 -0
  185. package/templates/base/research/completed/.gitkeep +0 -0
  186. package/templates/base/schemas/agent.schema.json +141 -0
  187. package/templates/base/schemas/anchors.schema.json +54 -0
  188. package/templates/base/schemas/automation.schema.json +93 -0
  189. package/templates/base/schemas/command.schema.json +134 -0
  190. package/templates/base/schemas/hashes.schema.json +40 -0
  191. package/templates/base/schemas/manifest.schema.json +117 -0
  192. package/templates/base/schemas/plan.schema.json +136 -0
  193. package/templates/base/schemas/research.schema.json +115 -0
  194. package/templates/base/schemas/roles.schema.json +34 -0
  195. package/templates/base/schemas/session.schema.json +77 -0
  196. package/templates/base/schemas/settings.schema.json +244 -0
  197. package/templates/base/schemas/staleness.schema.json +53 -0
  198. package/templates/base/schemas/team-config.schema.json +42 -0
  199. package/templates/base/schemas/workflow.schema.json +126 -0
  200. package/templates/base/session/checkpoints/.gitkeep +2 -0
  201. package/templates/base/session/current/state.json +20 -0
  202. package/templates/base/session/history/.gitkeep +2 -0
  203. package/templates/base/settings.json +3 -0
  204. package/templates/base/standards/COMPATIBILITY.md +219 -0
  205. package/templates/base/standards/EXTENSION_GUIDELINES.md +280 -0
  206. package/templates/base/standards/QUALITY_CHECKLIST.md +211 -0
  207. package/templates/base/standards/README.md +66 -0
  208. package/templates/base/sync/anchors.json +6 -0
  209. package/templates/base/sync/hashes.json +6 -0
  210. package/templates/base/sync/staleness.json +10 -0
  211. package/templates/base/team/README.md +168 -0
  212. package/templates/base/team/config.json +79 -0
  213. package/templates/base/team/roles.json +145 -0
  214. package/templates/base/tools/bin/claude-context.js +151 -0
  215. package/templates/base/tools/lib/anchor-resolver.js +276 -0
  216. package/templates/base/tools/lib/config-loader.js +363 -0
  217. package/templates/base/tools/lib/detector.js +350 -0
  218. package/templates/base/tools/lib/diagnose.js +206 -0
  219. package/templates/base/tools/lib/drift-detector.js +373 -0
  220. package/templates/base/tools/lib/errors.js +199 -0
  221. package/templates/base/tools/lib/index.js +36 -0
  222. package/templates/base/tools/lib/init.js +192 -0
  223. package/templates/base/tools/lib/logger.js +230 -0
  224. package/templates/base/tools/lib/placeholder.js +201 -0
  225. package/templates/base/tools/lib/session-manager.js +354 -0
  226. package/templates/base/tools/lib/validate.js +521 -0
  227. package/templates/base/tools/package.json +49 -0
  228. package/templates/handlebars/aider-config.hbs +146 -0
  229. package/templates/handlebars/antigravity.hbs +377 -0
  230. package/templates/handlebars/claude.hbs +183 -0
  231. package/templates/handlebars/cline.hbs +62 -0
  232. package/templates/handlebars/continue-config.hbs +116 -0
  233. package/templates/handlebars/copilot.hbs +130 -0
  234. package/templates/handlebars/partials/gotcha-list.hbs +11 -0
  235. package/templates/handlebars/partials/header.hbs +3 -0
  236. package/templates/handlebars/partials/workflow-summary.hbs +16 -0
  237. package/templates/handlebars/windsurf-rules.hbs +69 -0
  238. package/templates/hooks/post-commit.hbs +28 -0
  239. package/templates/hooks/pre-commit.hbs +46 -0
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Export Command
5
+ *
6
+ * Exports context database to various formats (JSON, markdown).
7
+ */
8
+
9
+ import { Command } from 'commander';
10
+ import chalk from 'chalk';
11
+ import ora from 'ora';
12
+ import fs from 'fs';
13
+ import path from 'path';
14
+
15
+ export const exportCommand = new Command('export')
16
+ .description('Export context database to file')
17
+ .argument('<output>', 'Output file path')
18
+ .option('--format <format>', 'Export format (json, markdown)', 'json')
19
+ .option('--type <type>', 'Filter by context type')
20
+ .action(async (output, options) => {
21
+ const spinner = ora();
22
+ const projectRoot = process.cwd();
23
+
24
+ try {
25
+ spinner.start('Exporting database...');
26
+
27
+ const { DatabaseClient } = await import('../../db/client.js');
28
+ const db = new DatabaseClient(projectRoot);
29
+
30
+ const items = options.type
31
+ ? db.getItemsByType(options.type)
32
+ : db.getAllItems();
33
+
34
+ db.close();
35
+
36
+ const outputPath = path.resolve(projectRoot, output);
37
+
38
+ if (options.format === 'json') {
39
+ const exportData = {
40
+ version: '1.0.0',
41
+ exportedAt: new Date().toISOString(),
42
+ itemCount: items.length,
43
+ items: items.map(item => ({
44
+ id: item.id,
45
+ type: item.type,
46
+ name: item.name,
47
+ content: item.content,
48
+ metadata: item.metadata,
49
+ filePath: item.filePath
50
+ }))
51
+ };
52
+
53
+ fs.writeFileSync(outputPath, JSON.stringify(exportData, null, 2));
54
+ } else if (options.format === 'markdown') {
55
+ let markdown = `# K0ntext Export\n\n`;
56
+ markdown += `**Exported:** ${new Date().toISOString()}\n`;
57
+ markdown += `**Items:** ${items.length}\n\n`;
58
+
59
+ for (const item of items) {
60
+ markdown += `## ${item.name} (${item.type})\n\n`;
61
+ markdown += `**ID:** \`${item.id}\`\n\n`;
62
+ if (item.filePath) {
63
+ markdown += `**Path:** \`${item.filePath}\`\n\n`;
64
+ }
65
+ markdown += `${item.content}\n\n---\n\n`;
66
+ }
67
+
68
+ fs.writeFileSync(outputPath, markdown);
69
+ } else {
70
+ spinner.fail('Invalid format');
71
+ console.error(chalk.red(`\nError: Format must be 'json' or 'markdown'`));
72
+ process.exit(1);
73
+ }
74
+
75
+ spinner.succeed(`Exported ${items.length} items to ${outputPath}`);
76
+
77
+ } catch (error) {
78
+ spinner.fail('Export failed');
79
+ console.error(chalk.red(`\nError: ${error instanceof Error ? error.message : error}`));
80
+ process.exit(1);
81
+ }
82
+ });
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Import Command
5
+ *
6
+ * Imports context data from exported files.
7
+ */
8
+
9
+ import { Command } from 'commander';
10
+ import chalk from 'chalk';
11
+ import ora from 'ora';
12
+ import fs from 'fs';
13
+ import path from 'path';
14
+
15
+ export const importCommand = new Command('import')
16
+ .description('Import context data from file')
17
+ .argument('<input>', 'Input file path')
18
+ .option('--format <format>', 'Import format (json, markdown)', 'json')
19
+ .option('--merge', 'Merge with existing data (default: replace)')
20
+ .action(async (input, options) => {
21
+ const spinner = ora();
22
+ const projectRoot = process.cwd();
23
+
24
+ try {
25
+ const inputPath = path.resolve(projectRoot, input);
26
+
27
+ if (!fs.existsSync(inputPath)) {
28
+ spinner.fail('Input file not found');
29
+ console.error(chalk.red(`\nError: File not found: ${inputPath}`));
30
+ process.exit(1);
31
+ }
32
+
33
+ spinner.start('Importing data...');
34
+
35
+ const { DatabaseClient } = await import('../../db/client.js');
36
+ const db = new DatabaseClient(projectRoot);
37
+
38
+ let importCount = 0;
39
+
40
+ if (options.format === 'json') {
41
+ const content = fs.readFileSync(inputPath, 'utf-8');
42
+ const data = JSON.parse(content);
43
+
44
+ if (!data.items || !Array.isArray(data.items)) {
45
+ throw new Error('Invalid import file format');
46
+ }
47
+
48
+ for (const item of data.items) {
49
+ db.upsertItem({
50
+ type: item.type,
51
+ name: item.name,
52
+ content: item.content,
53
+ metadata: item.metadata,
54
+ filePath: item.filePath
55
+ });
56
+ importCount++;
57
+ }
58
+ } else {
59
+ spinner.fail('Markdown import not yet supported');
60
+ console.error(chalk.yellow(`\nNote: Only JSON format is currently supported for import.`));
61
+ process.exit(1);
62
+ }
63
+
64
+ db.close();
65
+
66
+ spinner.succeed(`Imported ${importCount} items from ${input}`);
67
+
68
+ } catch (error) {
69
+ spinner.fail('Import failed');
70
+ console.error(chalk.red(`\nError: ${error instanceof Error ? error.message : error}`));
71
+ process.exit(1);
72
+ }
73
+ });
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Performance Command
5
+ *
6
+ * Display performance metrics and optimization suggestions.
7
+ */
8
+
9
+ import { Command } from 'commander';
10
+ import chalk from 'chalk';
11
+
12
+ export const performanceCommand = new Command('performance')
13
+ .description('Show performance metrics and suggestions')
14
+ .option('--json', 'Output as JSON')
15
+ .action(async (options) => {
16
+ try {
17
+ const { PerformanceMonitorAgent } = await import('../../agents/performance-agent.js');
18
+ const agent = new PerformanceMonitorAgent(process.cwd());
19
+
20
+ if (options.json) {
21
+ console.log(JSON.stringify(agent.getMetrics(), null, 2));
22
+ } else {
23
+ console.log(agent.generateReport());
24
+
25
+ const suggestions = agent.suggestOptimizations();
26
+ if (suggestions.length > 0) {
27
+ console.log(chalk.bold('\nOptimization Suggestions:'));
28
+ for (const suggestion of suggestions) {
29
+ console.log(` ${chalk.cyan('•')} ${suggestion}`);
30
+ }
31
+ }
32
+ }
33
+
34
+ agent.close();
35
+
36
+ } catch (error) {
37
+ console.error(chalk.red(`\nError: ${error instanceof Error ? error.message : error}`));
38
+ process.exit(1);
39
+ }
40
+ });
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Validate Command
5
+ *
6
+ * Validates context files and AI tool configurations for correctness.
7
+ */
8
+
9
+ import { Command } from 'commander';
10
+ import chalk from 'chalk';
11
+ import ora from 'ora';
12
+ import path from 'path';
13
+ import fs from 'fs';
14
+
15
+ export const validateCommand = new Command('validate')
16
+ .description('Validate context files and configurations')
17
+ .option('--fix', 'Automatically fix validation errors when possible')
18
+ .option('--strict', 'Treat warnings as errors')
19
+ .action(async (options) => {
20
+ const spinner = ora();
21
+ const projectRoot = process.cwd();
22
+
23
+ try {
24
+ spinner.start('Validating context files...');
25
+
26
+ const { DatabaseClient } = await import('../../db/client.js');
27
+ const db = new DatabaseClient(projectRoot);
28
+
29
+ // First check database health
30
+ const health = db.healthCheck();
31
+ if (!health.healthy) {
32
+ spinner.fail('Database health check failed');
33
+ console.error(chalk.red(`\nError: ${health.error}`));
34
+ process.exit(1);
35
+ }
36
+
37
+ const issues: Array<{ file: string; issue: string; severity: 'error' | 'warning' }> = [];
38
+
39
+ // Validate context items
40
+ const items = db.getAllItems();
41
+ for (const item of items) {
42
+ if (item.filePath) {
43
+ const fullPath = path.join(projectRoot, item.filePath);
44
+ if (!fs.existsSync(fullPath)) {
45
+ issues.push({
46
+ file: item.filePath,
47
+ issue: 'File referenced in database does not exist',
48
+ severity: 'error'
49
+ });
50
+ }
51
+ }
52
+
53
+ // Validate content is not empty
54
+ if (!item.content || item.content.trim().length === 0) {
55
+ issues.push({
56
+ file: item.name,
57
+ issue: 'Content is empty',
58
+ severity: 'warning'
59
+ });
60
+ }
61
+ }
62
+
63
+ db.close();
64
+
65
+ spinner.stop();
66
+
67
+ if (issues.length === 0) {
68
+ console.log(chalk.green('\n✓ All validations passed!'));
69
+ return;
70
+ }
71
+
72
+ const errorCount = issues.filter(i => i.severity === 'error').length;
73
+ const warningCount = issues.filter(i => i.severity === 'warning').length;
74
+
75
+ console.log(chalk.bold(`\nValidation Results:`));
76
+ console.log(` ${chalk.red('✖')} Errors: ${errorCount}`);
77
+ console.log(` ${chalk.yellow('⚠')} Warnings: ${warningCount}`);
78
+
79
+ for (const issue of issues) {
80
+ const icon = issue.severity === 'error' ? chalk.red('✖') : chalk.yellow('⚠');
81
+ console.log(`\n ${icon} ${issue.file}`);
82
+ console.log(` ${issue.issue}`);
83
+ }
84
+
85
+ if (options.strict && warningCount > 0) {
86
+ process.exit(1);
87
+ }
88
+
89
+ if (errorCount > 0) {
90
+ process.exit(1);
91
+ }
92
+
93
+ } catch (error) {
94
+ spinner.fail('Validation failed');
95
+ console.error(chalk.red(`\nError: ${error instanceof Error ? error.message : error}`));
96
+ process.exit(1);
97
+ }
98
+ });
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Watch Command
5
+ *
6
+ * Watch for file changes and automatically update the index.
7
+ */
8
+
9
+ import { Command } from 'commander';
10
+ import chalk from 'chalk';
11
+ import ora from 'ora';
12
+
13
+ export const watchCommand = new Command('watch')
14
+ .description('Watch for file changes and auto-update index')
15
+ .option('-d, --delay <ms>', 'Debounce delay in milliseconds', '1000')
16
+ .action(async (options) => {
17
+ const spinner = ora();
18
+ const projectRoot = process.cwd();
19
+ let debounceTimer: NodeJS.Timeout | null = null;
20
+
21
+ try {
22
+ const { createIntelligentAnalyzer } = await import('../../analyzer/intelligent-analyzer.js');
23
+ const { DatabaseClient } = await import('../../db/client.js');
24
+
25
+ const analyzer = createIntelligentAnalyzer(projectRoot);
26
+ const db = new DatabaseClient(projectRoot);
27
+
28
+ console.log(chalk.cyan('\n👀 Watching for file changes...\n'));
29
+ console.log(chalk.gray('Press Ctrl+C to stop\n'));
30
+
31
+ const onChange = async (filePath: string) => {
32
+ // Debounce rapid changes
33
+ if (debounceTimer) {
34
+ clearTimeout(debounceTimer);
35
+ }
36
+
37
+ debounceTimer = setTimeout(async () => {
38
+ spinner.start(`Indexing: ${filePath}`);
39
+
40
+ try {
41
+ const relativePath = filePath.replace(projectRoot + '/', '').replace(projectRoot, '');
42
+ const fs = await import('fs');
43
+ const content = fs.readFileSync(filePath, 'utf-8');
44
+
45
+ // Determine type based on path
46
+ let type: 'doc' | 'code' | 'tool_config' = 'code';
47
+ if (filePath.includes('.claude') && !filePath.endsWith('README.md')) {
48
+ type = 'tool_config';
49
+ } else if (filePath.endsWith('README.md')) {
50
+ type = 'doc';
51
+ }
52
+
53
+ db.upsertItem({
54
+ type,
55
+ name: filePath.split('/').pop() || 'unknown',
56
+ content,
57
+ filePath: relativePath,
58
+ metadata: { size: content.length }
59
+ });
60
+
61
+ spinner.succeed(`Indexed: ${relativePath}`);
62
+ } catch (error) {
63
+ spinner.fail(`Failed to index: ${filePath}`);
64
+ }
65
+ }, parseInt(options.delay as string, 10));
66
+ };
67
+
68
+ const cleanup = analyzer.setupFileWatcher(onChange);
69
+
70
+ // Keep process alive
71
+ process.on('SIGINT', () => {
72
+ console.log(chalk.gray('\n\nStopping watcher...'));
73
+ cleanup();
74
+ db.close();
75
+ process.exit(0);
76
+ });
77
+
78
+ } catch (error) {
79
+ spinner.fail('Watch failed to start');
80
+ console.error(chalk.red(`\nError: ${error instanceof Error ? error.message : error}`));
81
+ process.exit(1);
82
+ }
83
+ });
@@ -0,0 +1,219 @@
1
+ import { Command } from 'commander';
2
+ import { DatabaseClient } from '../db/client.js';
3
+ import ora from 'ora';
4
+ import chalk from 'chalk';
5
+ import fs from 'fs/promises';
6
+ import path from 'path';
7
+
8
+ export const generateCommand = new Command('generate')
9
+ .description('Generate context files for all AI tools')
10
+ .option('-ai, --ai <tools>', 'Generate for specific tools (comma-separated)')
11
+ .option('--force', 'Force regenerate all files')
12
+ .option('-v, --verbose', 'Show detailed output')
13
+ .action(async (options) => {
14
+ const spinner = ora('Generating context files...').start();
15
+
16
+ try {
17
+ const db = new DatabaseClient(process.cwd());
18
+
19
+ // Check if database has content
20
+ const stats = db.getStats();
21
+ if (stats.items === 0) {
22
+ spinner.warn(chalk.yellow('No context found in database. Run `k0ntext index` first.'));
23
+ return;
24
+ }
25
+
26
+ spinner.text = `Found ${stats.items} context items`;
27
+
28
+ // Determine which tools to generate for
29
+ const toolsParam = options.ai ? options.ai.split(',') : ['all'];
30
+ const tools = toolsParam.includes('all') ?
31
+ ['claude', 'copilot', 'cline', 'antigravity', 'windsurf', 'aider', 'continue', 'cursor', 'gemini'] :
32
+ toolsParam;
33
+
34
+ spinner.text = `Generating context for ${tools.length} tools...`;
35
+
36
+ const generated = [];
37
+ const skipped = [];
38
+
39
+ for (const tool of tools) {
40
+ try {
41
+ const toolPath = await generateForTool(tool, db, options.force);
42
+ if (toolPath) {
43
+ generated.push(tool);
44
+ spinner.text = `Generated ${tool} context`;
45
+ } else {
46
+ skipped.push(tool);
47
+ }
48
+ } catch (error) {
49
+ const errorMessage = error instanceof Error ? error.message : String(error);
50
+ spinner.fail(chalk.red(`Failed to generate ${tool}: ${errorMessage}`));
51
+ if (options.verbose) {
52
+ console.error(chalk.dim((error as Error).stack));
53
+ }
54
+ }
55
+ }
56
+
57
+ spinner.succeed(chalk.green(`Generated context for ${generated.length} tools`));
58
+
59
+ if (skipped.length > 0) {
60
+ console.log(chalk.dim(`Skipped: ${skipped.join(', ')}`));
61
+ }
62
+
63
+ if (options.verbose) {
64
+ console.log(chalk.dim('Generated:'), generated.join(', '));
65
+ }
66
+
67
+ } catch (error) {
68
+ const errorMessage = error instanceof Error ? error.message : String(error);
69
+ spinner.fail(chalk.red('Generation failed'));
70
+ console.error(chalk.dim(errorMessage));
71
+ if (options.verbose) {
72
+ console.error(chalk.dim((error as Error).stack));
73
+ }
74
+ process.exit(1);
75
+ }
76
+ });
77
+
78
+ async function generateForTool(
79
+ tool: string,
80
+ db: DatabaseClient,
81
+ force: boolean
82
+ ): Promise<string | null> {
83
+ const toolConfigs: Record<string, { path: string; template: string }> = {
84
+ claude: { path: 'AI_CONTEXT.md', template: 'claude' },
85
+ copilot: { path: '.github/copilot-instructions.md', template: 'copilot' },
86
+ cline: { path: '.clinerules', template: 'cline' },
87
+ antigravity: { path: '.agent/README.md', template: 'antigravity' },
88
+ windsurf: { path: '.windsurf/rules.md', template: 'windsurf' },
89
+ aider: { path: '.aider.conf.yml', template: 'aider' },
90
+ continue: { path: '.continue/config.json', template: 'continue' },
91
+ cursor: { path: '.cursorrules', template: 'cursor' },
92
+ gemini: { path: '.gemini/config.md', template: 'gemini' },
93
+ };
94
+
95
+ const config = toolConfigs[tool];
96
+ if (!config) {
97
+ return null;
98
+ }
99
+
100
+ // Check if file exists and force is not set
101
+ if (!force) {
102
+ try {
103
+ await fs.access(config.path);
104
+ return null; // File exists, skip
105
+ } catch {
106
+ // File doesn't exist, proceed
107
+ }
108
+ }
109
+
110
+ // Get context from database
111
+ const contextItems = db.getAllItems();
112
+
113
+ // Generate content based on tool
114
+ const content = generateContent(tool, contextItems);
115
+
116
+ // Ensure directory exists
117
+ const dir = path.dirname(config.path);
118
+ await fs.mkdir(dir, { recursive: true });
119
+
120
+ // Write file
121
+ await fs.writeFile(config.path, content, 'utf-8');
122
+
123
+ return config.path;
124
+ }
125
+
126
+ function generateContent(tool: string, contextItems: Array<any>): string {
127
+ // Basic content generation - in production this would use templates
128
+ const projectName = contextItems.find(i => i.type === 'config' && i.name === 'project')?.content?.name || 'Project';
129
+ const description = contextItems.find(i => i.type === 'config' && i.name === 'project')?.content?.description || '';
130
+
131
+ switch (tool) {
132
+ case 'claude':
133
+ return generateClaudeContext(projectName, description, contextItems);
134
+ case 'copilot':
135
+ return generateCopilotContext(projectName, description, contextItems);
136
+ case 'cline':
137
+ return generateClineContext(projectName, description, contextItems);
138
+ case 'aider':
139
+ return generateAiderConfig(contextItems);
140
+ default:
141
+ return `# ${tool.charAt(0).toUpperCase() + tool.slice(1)} Context\n\nProject: ${projectName}\n${description}`;
142
+ }
143
+ }
144
+
145
+ function generateClaudeContext(projectName: string, description: string, items: Array<{ type: string; name: string; content?: string }>): string {
146
+ return `# ${projectName}
147
+
148
+ ${description}
149
+
150
+ ## Project Structure
151
+
152
+ ${items.filter(i => i.type === 'workflow').map(i => `### ${i.name}\n${i.content?.substring(0, 200)}...`).join('\n\n')}
153
+
154
+ ## Key Files
155
+
156
+ ${items.filter(i => i.type === 'code').slice(0, 10).map(i => `- \`${i.name}\``).join('\n')}
157
+
158
+ ---
159
+ *Generated by k0ntext v3.0.0*
160
+ `;
161
+ }
162
+
163
+ function generateCopilotContext(projectName: string, description: string, items: Array<{ type: string; name: string; content?: string }>): string {
164
+ return `# ${projectName}
165
+
166
+ ${description}
167
+
168
+ ## Tech Stack
169
+ - Node.js 18+
170
+ - TypeScript
171
+
172
+ ## Key Patterns
173
+ ${items.filter(i => i.type === 'workflow').slice(0, 5).map(i => `- ${i.name}: ${i.content?.substring(0, 100)}...`).join('\n')}
174
+
175
+ ---
176
+ *Generated by k0ntext v3.0.0*
177
+ `;
178
+ }
179
+
180
+ function generateClineContext(projectName: string, description: string, items: Array<{ type: string; name: string; content?: string }>): string {
181
+ return `# ${projectName} - Cline Rules
182
+
183
+ ${description}
184
+
185
+ ## Architecture
186
+ ${items.filter(i => i.type === 'workflow').slice(0, 3).map(i => `### ${i.name}\n${i.content?.substring(0, 150)}...`).join('\n\n')}
187
+
188
+ ## Development Commands
189
+ - \`npm install\` - Install dependencies
190
+ - \`npm test\` - Run tests
191
+ - \`npm run build\` - Build project
192
+
193
+ ---
194
+ *Generated by k0ntext v3.0.0*
195
+ `;
196
+ }
197
+
198
+ function generateAiderConfig(_items: Array<{ type: string; name: string; content?: string }>): string {
199
+ return `# Aider Configuration
200
+ model: claude-3-5-sonnet-20241022
201
+ auto-commits: false
202
+ map-tokens: 2048
203
+
204
+ # Always read these files
205
+ read:
206
+ - README.md
207
+ - AI_CONTEXT.md
208
+
209
+ # Testing
210
+ test-cmd: npm test
211
+ auto-test: false
212
+
213
+ # Language
214
+ language: typescript
215
+
216
+ ---
217
+ *Generated by k0ntext v3.0.0*
218
+ `;
219
+ }