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,194 @@
1
+ import { Command } from 'commander';
2
+ import { DatabaseClient } from '../db/client.js';
3
+ import ora from 'ora';
4
+ import chalk from 'chalk';
5
+ import crypto from 'crypto';
6
+ import fs from 'fs/promises';
7
+
8
+ export interface SyncStatus {
9
+ synced: boolean;
10
+ differences: string[];
11
+ }
12
+
13
+ export interface SyncResult {
14
+ count: number;
15
+ files: string[];
16
+ }
17
+
18
+ export const syncCommand = new Command('sync')
19
+ .description('Synchronize context across all AI tools')
20
+ .option('--check', 'Only check synchronization status')
21
+ .option('--from <tool>', 'Sync from specific tool')
22
+ .option('--to <tool>', 'Sync to specific tool')
23
+ .option('--force', 'Force sync even if up-to-date')
24
+ .action(async (options) => {
25
+ const spinner = ora('Checking sync status...').start();
26
+
27
+ try {
28
+ const db = new DatabaseClient(process.cwd());
29
+ const syncManager = new SyncManager(db);
30
+
31
+ if (options.check) {
32
+ const status = await syncManager.checkStatus();
33
+ if (status.synced) {
34
+ spinner.succeed(chalk.green('All tools are synchronized'));
35
+ } else {
36
+ spinner.warn(chalk.yellow('Tools are out of sync'));
37
+ console.log(chalk.dim('Differences:'), status.differences.join(', '));
38
+ }
39
+ return;
40
+ }
41
+
42
+ if (options.from) {
43
+ spinner.text = `Syncing from ${options.from}...`;
44
+ await syncManager.syncFrom(options.from);
45
+ spinner.succeed(chalk.green(`Synced from ${options.from}`));
46
+ return;
47
+ }
48
+
49
+ // Default: sync all tools
50
+ spinner.text = 'Syncing all tools...';
51
+ const result = await syncManager.syncAll({ force: options.force });
52
+ spinner.succeed(chalk.green(`Synced ${result.count} tools`));
53
+
54
+ if (result.files.length > 0) {
55
+ console.log(chalk.dim('Synced:'), result.files.join(', '));
56
+ }
57
+
58
+ } catch (error) {
59
+ const errorMessage = error instanceof Error ? error.message : String(error);
60
+ spinner.fail(chalk.red('Sync failed'));
61
+ console.error(chalk.dim(errorMessage));
62
+ process.exit(1);
63
+ }
64
+ });
65
+
66
+ export class SyncManager {
67
+ constructor(private db: DatabaseClient) {}
68
+
69
+ async checkStatus(): Promise<SyncStatus> {
70
+ const tools = await this.getToolFiles();
71
+ const hashes = await this.getFileHashes(tools);
72
+ const differences: string[] = [];
73
+
74
+ for (const [tool, hash] of Object.entries(hashes)) {
75
+ const stored = this.db.getSyncState(tool);
76
+ const storedHash = Array.isArray(stored) && stored.length > 0 ? stored[0]?.contentHash : undefined;
77
+ if (storedHash !== undefined && storedHash !== hash) {
78
+ differences.push(tool);
79
+ }
80
+ }
81
+
82
+ return {
83
+ synced: differences.length === 0,
84
+ differences
85
+ };
86
+ }
87
+
88
+ async syncFrom(tool: string): Promise<void> {
89
+ const configs = this.db.getToolConfigs(tool as any);
90
+ if (!configs || configs.length === 0) {
91
+ throw new Error(`Tool ${tool} not found in database`);
92
+ }
93
+
94
+ // Sync logic - propagate changes from this tool to others
95
+ const content = await this.readToolFile(tool);
96
+ await this.propagateToTools(tool, content);
97
+ }
98
+
99
+ async syncAll(options: { force?: boolean }): Promise<SyncResult> {
100
+ const tools = ['claude', 'copilot', 'cline', 'antigravity', 'windsurf', 'aider', 'continue', 'cursor', 'gemini'];
101
+ const synced = [];
102
+
103
+ for (const tool of tools) {
104
+ try {
105
+ await this.syncTool(tool, options);
106
+ synced.push(tool);
107
+ } catch (error) {
108
+ const errorMessage = error instanceof Error ? error.message : String(error);
109
+ // Continue with other tools even if one fails
110
+ console.error(chalk.dim(`Failed to sync ${tool}: ${errorMessage}`));
111
+ }
112
+ }
113
+
114
+ return { count: synced.length, files: synced };
115
+ }
116
+
117
+ private async getToolFiles(): Promise<string[]> {
118
+ return ['claude', 'copilot', 'cline', 'antigravity', 'windsurf', 'aider', 'continue', 'cursor', 'gemini'];
119
+ }
120
+
121
+ private async getFileHashes(tools: string[]): Promise<Record<string, string>> {
122
+ const hashes: Record<string, string> = {};
123
+ const toolPaths: Record<string, string> = {
124
+ claude: 'AI_CONTEXT.md',
125
+ copilot: '.github/copilot-instructions.md',
126
+ cline: '.clinerules',
127
+ antigravity: '.agent/README.md',
128
+ windsurf: '.windsurf/rules.md',
129
+ aider: '.aider.conf.yml',
130
+ continue: '.continue/config.json',
131
+ cursor: '.cursorrules',
132
+ gemini: '.gemini/config.md'
133
+ };
134
+
135
+ for (const tool of tools) {
136
+ try {
137
+ const content = await fs.readFile(toolPaths[tool], 'utf-8');
138
+ hashes[tool] = crypto.createHash('sha256').update(content).digest('hex');
139
+ } catch (error) {
140
+ const message = error instanceof Error ? error.message : String(error);
141
+ console.error(
142
+ chalk.yellow(
143
+ `Warning: Failed to read tool file for "${tool}" at "${toolPaths[tool]}": ${message}`
144
+ )
145
+ );
146
+ hashes[tool] = '';
147
+ }
148
+ }
149
+
150
+ return hashes;
151
+ }
152
+
153
+ private async readToolFile(tool: string): Promise<string> {
154
+ const toolPaths: Record<string, string> = {
155
+ claude: 'AI_CONTEXT.md',
156
+ copilot: '.github/copilot-instructions.md',
157
+ cline: '.clinerules',
158
+ antigravity: '.agent/README.md',
159
+ windsurf: '.windsurf/rules.md',
160
+ aider: '.aider.conf.yml',
161
+ continue: '.continue/config.json',
162
+ cursor: '.cursorrules',
163
+ gemini: '.gemini/config.md'
164
+ };
165
+
166
+ return await fs.readFile(toolPaths[tool], 'utf-8');
167
+ }
168
+
169
+ private async propagateToTools(_fromTool: string, _content: string): Promise<void> {
170
+ // In a full implementation, this would parse the content
171
+ // and propagate it to all other tools
172
+ // For now, this is a placeholder
173
+ console.log(chalk.dim(`Propagating from ${_fromTool} to other tools...`));
174
+ }
175
+
176
+ private async syncTool(tool: string, options: { force?: boolean }): Promise<void> {
177
+ // Check if sync is needed
178
+ if (!options.force) {
179
+ const content = this.db.getAllItems();
180
+ if (content.length === 0) {
181
+ throw new Error(`No content in database for ${tool}`);
182
+ }
183
+ }
184
+
185
+ // Update sync state
186
+ this.db.updateSyncState({
187
+ id: `sync:${tool}`,
188
+ tool: tool,
189
+ contentHash: Date.now().toString(),
190
+ lastSync: new Date().toISOString(),
191
+ status: 'synced'
192
+ });
193
+ }
194
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Cleanup configuration options
3
+ */
4
+
5
+ export interface CleanupConfig {
6
+ /** Default dry run mode (safe mode) */
7
+ dryRun: boolean;
8
+
9
+ /** Default folders to keep */
10
+ defaultKeep: string[];
11
+
12
+ /** Verbose output by default */
13
+ verbose: boolean;
14
+
15
+ /** Maximum folder depth to scan */
16
+ maxDepth: number;
17
+
18
+ /** Timeout for folder operations in milliseconds */
19
+ timeout: number;
20
+
21
+ /** Default working directory */
22
+ cwd: string;
23
+ }
24
+
25
+ /**
26
+ * Default cleanup configuration
27
+ */
28
+ export const DEFAULT_CLEANUP_CONFIG: CleanupConfig = {
29
+ dryRun: true,
30
+ defaultKeep: ['.github', '.vscode', '.idea', '.devcontainer'],
31
+ verbose: false,
32
+ maxDepth: 3,
33
+ timeout: 30000,
34
+ cwd: process.cwd()
35
+ };
36
+
37
+ /**
38
+ * Get cleanup configuration (can be extended to load from file)
39
+ */
40
+ export function getCleanupConfig(): CleanupConfig {
41
+ return { ...DEFAULT_CLEANUP_CONFIG };
42
+ }