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
package/src/mcp.ts ADDED
@@ -0,0 +1,354 @@
1
+ /**
2
+ * MCP Server
3
+ *
4
+ * Model Context Protocol server for AI context.
5
+ * Provides tools, resources, and prompts for AI coding assistants.
6
+ */
7
+
8
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
10
+ import { z } from 'zod';
11
+
12
+ import { DatabaseClient } from './db/client.js';
13
+ import { OpenRouterClient, createOpenRouterClient, hasOpenRouterKey } from './embeddings/openrouter.js';
14
+ import { createIntelligentAnalyzer } from './analyzer/intelligent-analyzer.js';
15
+
16
+ /**
17
+ * Server configuration
18
+ */
19
+ export interface ServerConfig {
20
+ projectRoot: string;
21
+ dbPath?: string;
22
+ name?: string;
23
+ version?: string;
24
+ }
25
+
26
+ /**
27
+ * Tool context for handlers
28
+ */
29
+ interface ToolContext {
30
+ db: DatabaseClient;
31
+ openrouter: OpenRouterClient | null;
32
+ projectRoot: string;
33
+ }
34
+
35
+ /**
36
+ * Create and start the MCP server
37
+ */
38
+ export async function createServer(config: ServerConfig): Promise<McpServer> {
39
+ const {
40
+ projectRoot,
41
+ dbPath = '.ai-context.db',
42
+ name = 'k0ntext',
43
+ version = '1.0.0'
44
+ } = config;
45
+
46
+ // Initialize database
47
+ const db = new DatabaseClient(projectRoot, dbPath);
48
+
49
+ // Initialize OpenRouter client (optional)
50
+ let openrouter: OpenRouterClient | null = null;
51
+ if (hasOpenRouterKey()) {
52
+ try {
53
+ openrouter = createOpenRouterClient();
54
+ } catch (error) {
55
+ console.error('Warning: OpenRouter unavailable:', error);
56
+ }
57
+ }
58
+
59
+ // Create context for handlers
60
+ const ctx: ToolContext = { db, openrouter, projectRoot };
61
+
62
+ // Create MCP server
63
+ const server = new McpServer(
64
+ { name, version },
65
+ {
66
+ capabilities: {
67
+ tools: {},
68
+ resources: {},
69
+ prompts: {}
70
+ }
71
+ }
72
+ );
73
+
74
+ // ==================== Register Tools ====================
75
+
76
+ // search_context - Semantic search across indexed content
77
+ server.registerTool(
78
+ 'search_context',
79
+ {
80
+ description: 'Semantic search across all indexed content (workflows, agents, code, commits, docs)',
81
+ inputSchema: {
82
+ query: z.string().describe('Natural language search query'),
83
+ type: z.enum(['workflow', 'agent', 'command', 'code', 'commit', 'knowledge', 'config', 'doc', 'tool_config']).optional().describe('Filter by content type'),
84
+ limit: z.number().optional().describe('Maximum results (default: 10)')
85
+ }
86
+ },
87
+ async (args) => {
88
+ const { query, type, limit = 10 } = args as { query: string; type?: string; limit?: number };
89
+
90
+ // Text search (semantic search requires embeddings)
91
+ const results = ctx.db.searchText(query, type as any);
92
+
93
+ return {
94
+ content: [{
95
+ type: 'text',
96
+ text: JSON.stringify(results.slice(0, limit), null, 2)
97
+ }]
98
+ };
99
+ }
100
+ );
101
+
102
+ // get_item - Get a specific context item
103
+ server.registerTool(
104
+ 'get_item',
105
+ {
106
+ description: 'Get a specific context item by ID or path',
107
+ inputSchema: {
108
+ id: z.string().optional().describe('Context item ID'),
109
+ path: z.string().optional().describe('File path to look up')
110
+ }
111
+ },
112
+ async (args) => {
113
+ const { id, path: filePath } = args as { id?: string; path?: string };
114
+
115
+ let item = null;
116
+ if (id) {
117
+ item = ctx.db.getItem(id);
118
+ } else if (filePath) {
119
+ const items = ctx.db.getAllItems().filter(i => i.filePath === filePath);
120
+ item = items[0] || null;
121
+ }
122
+
123
+ return {
124
+ content: [{
125
+ type: 'text',
126
+ text: item ? JSON.stringify(item, null, 2) : 'Item not found'
127
+ }]
128
+ };
129
+ }
130
+ );
131
+
132
+ // add_knowledge - Store new knowledge
133
+ server.registerTool(
134
+ 'add_knowledge',
135
+ {
136
+ description: 'Store a new insight or fact about the codebase',
137
+ inputSchema: {
138
+ name: z.string().describe('Short name for the knowledge item'),
139
+ content: z.string().describe('The knowledge content'),
140
+ relatedTo: z.array(z.string()).optional().describe('IDs of related items')
141
+ }
142
+ },
143
+ async (args) => {
144
+ const { name, content, relatedTo } = args as { name: string; content: string; relatedTo?: string[] };
145
+
146
+ const item = ctx.db.upsertItem({
147
+ type: 'knowledge',
148
+ name,
149
+ content,
150
+ metadata: { relatedTo }
151
+ });
152
+
153
+ // Add relations if specified
154
+ if (relatedTo) {
155
+ for (const targetId of relatedTo) {
156
+ ctx.db.addRelation({
157
+ sourceId: item.id,
158
+ targetId,
159
+ relationType: 'references'
160
+ });
161
+ }
162
+ }
163
+
164
+ return {
165
+ content: [{
166
+ type: 'text',
167
+ text: `Knowledge item created: ${item.id}`
168
+ }]
169
+ };
170
+ }
171
+ );
172
+
173
+ // analyze - Run intelligent analysis
174
+ server.registerTool(
175
+ 'analyze',
176
+ {
177
+ description: 'Run intelligent analysis on the codebase using OpenRouter',
178
+ inputSchema: {
179
+ type: z.enum(['full', 'docs', 'code', 'tools']).optional().describe('Analysis type')
180
+ }
181
+ },
182
+ async (_args) => {
183
+ const analyzer = createIntelligentAnalyzer(ctx.projectRoot);
184
+ const analysis = await analyzer.analyze();
185
+
186
+ return {
187
+ content: [{
188
+ type: 'text',
189
+ text: JSON.stringify(analysis, null, 2)
190
+ }]
191
+ };
192
+ }
193
+ );
194
+
195
+ // get_tool_configs - Get AI tool configurations
196
+ server.registerTool(
197
+ 'get_tool_configs',
198
+ {
199
+ description: 'Get configurations for AI tools (Claude, Copilot, Cline, etc.)',
200
+ inputSchema: {
201
+ tool: z.enum(['claude', 'copilot', 'cline', 'antigravity', 'windsurf', 'aider', 'continue', 'cursor', 'gemini']).optional().describe('Specific tool to get configs for')
202
+ }
203
+ },
204
+ async (args) => {
205
+ const { tool } = args as { tool?: string };
206
+
207
+ const configs = tool
208
+ ? ctx.db.getToolConfigs(tool as any)
209
+ : ctx.db.getAllToolConfigs();
210
+
211
+ return {
212
+ content: [{
213
+ type: 'text',
214
+ text: JSON.stringify(configs, null, 2)
215
+ }]
216
+ };
217
+ }
218
+ );
219
+
220
+ // query_graph - Traverse knowledge graph
221
+ server.registerTool(
222
+ 'query_graph',
223
+ {
224
+ description: 'Traverse the knowledge graph from a starting point',
225
+ inputSchema: {
226
+ startId: z.string().describe('Starting context item ID'),
227
+ direction: z.enum(['outgoing', 'incoming', 'both']).optional().describe('Traversal direction'),
228
+ maxDepth: z.number().optional().describe('Maximum depth (default: 3)')
229
+ }
230
+ },
231
+ async (args) => {
232
+ const { startId, maxDepth = 3 } = args as { startId: string; maxDepth?: number };
233
+
234
+ const results = ctx.db.traverseGraph(startId, maxDepth);
235
+
236
+ return {
237
+ content: [{
238
+ type: 'text',
239
+ text: JSON.stringify(Array.from(results.entries()), null, 2)
240
+ }]
241
+ };
242
+ }
243
+ );
244
+
245
+ // get_stats - Database statistics
246
+ server.registerTool(
247
+ 'get_stats',
248
+ {
249
+ description: 'Get database and indexing statistics',
250
+ inputSchema: {}
251
+ },
252
+ async () => {
253
+ const stats = ctx.db.getStats();
254
+
255
+ return {
256
+ content: [{
257
+ type: 'text',
258
+ text: JSON.stringify(stats, null, 2)
259
+ }]
260
+ };
261
+ }
262
+ );
263
+
264
+ // ==================== Register Prompts ====================
265
+
266
+ // context-engineer prompt
267
+ server.registerPrompt(
268
+ 'context-engineer',
269
+ {
270
+ description: 'Initialize and configure the AI context system',
271
+ argsSchema: {
272
+ projectType: z.string().optional().describe('Type of project')
273
+ }
274
+ },
275
+ () => {
276
+ return {
277
+ messages: [{
278
+ role: 'user',
279
+ content: {
280
+ type: 'text',
281
+ text: `You are a Context Engineer specializing in setting up AI context systems.
282
+
283
+ Your goal is to analyze the current codebase and set up optimal AI context configuration.
284
+
285
+ Available tools:
286
+ - search_context: Search indexed content
287
+ - get_item: Get specific items
288
+ - add_knowledge: Store new insights
289
+ - analyze: Run intelligent analysis
290
+ - get_tool_configs: View AI tool configurations
291
+ - get_stats: View database statistics
292
+
293
+ Start by running 'analyze' to understand the codebase, then use 'add_knowledge' to capture important insights.`
294
+ }
295
+ }]
296
+ };
297
+ }
298
+ );
299
+
300
+ // core-architect prompt
301
+ server.registerPrompt(
302
+ 'core-architect',
303
+ {
304
+ description: 'Design system architecture',
305
+ argsSchema: {
306
+ focus: z.string().optional().describe('Area to focus on')
307
+ }
308
+ },
309
+ (args) => {
310
+ const { focus } = args as { focus?: string };
311
+ return {
312
+ messages: [{
313
+ role: 'user',
314
+ content: {
315
+ type: 'text',
316
+ text: `You are a Core Architect designing system architecture.
317
+ ${focus ? `Focus area: ${focus}` : ''}
318
+
319
+ Use the context tools to understand the existing architecture and propose improvements.`
320
+ }
321
+ }]
322
+ };
323
+ }
324
+ );
325
+
326
+ return server;
327
+ }
328
+
329
+ /**
330
+ * Start the server with stdio transport
331
+ */
332
+ export async function startServer(config: ServerConfig): Promise<void> {
333
+ const server = await createServer(config);
334
+ const transport = new StdioServerTransport();
335
+
336
+ await server.connect(transport);
337
+
338
+ console.error(`K0NTEXT MCP Server started`);
339
+ console.error(`Project root: ${config.projectRoot}`);
340
+ console.error(`Database: ${config.dbPath || '.ai-context.db'}`);
341
+ }
342
+
343
+ /**
344
+ * Main entry point
345
+ */
346
+ export async function main(): Promise<void> {
347
+ const projectRoot = process.env.K0NTEXT_PROJECT_ROOT || process.cwd();
348
+ const dbPath = process.env.K0NTEXT_DB_PATH;
349
+
350
+ await startServer({
351
+ projectRoot,
352
+ dbPath
353
+ });
354
+ }
@@ -0,0 +1,245 @@
1
+ # AI_CONTEXT.md - {{PROJECT_NAME}}
2
+
3
+ This file provides guidance to AI coding assistants when working with code in this repository.
4
+
5
+ ---
6
+
7
+ ## Project Identity
8
+
9
+ **Platform:** {{PROJECT_DESCRIPTION}}
10
+ **Domain:** {{PRODUCTION_URL}}
11
+ **Tech Stack:** {{TECH_STACK}}
12
+ **Status:** {{PROJECT_STATUS}}
13
+
14
+ **Quick Reference:**
15
+ - **API:** {{API_URL}}
16
+ - **Repo:** {{REPO_URL}}
17
+ - **Deploy:** {{DEPLOYMENT_PLATFORM}}
18
+
19
+ ---
20
+
21
+ ## Essential Commands
22
+
23
+ ### Development
24
+ ```bash
25
+ {{INSTALL_COMMAND}}
26
+ {{DEV_START_COMMAND}}
27
+ ```
28
+
29
+ ### Testing
30
+ ```bash
31
+ {{TEST_COMMAND}} # All tests
32
+ {{TEST_E2E_COMMAND}} # E2E only
33
+ {{TEST_COVERAGE_COMMAND}} # With coverage
34
+ ```
35
+
36
+ ### Database
37
+ ```bash
38
+ {{MIGRATION_CREATE_COMMAND}}
39
+ {{MIGRATION_RUN_COMMAND}}
40
+ ```
41
+
42
+ ### Deployment
43
+ ```bash
44
+ {{DEPLOY_COMMAND}}
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Navigation Rules
50
+
51
+ ### High-Level Task (Refactoring a Flow)
52
+ **Example:** "{{EXAMPLE_REFACTOR_TASK}}"
53
+
54
+ **Chain:**
55
+ 1. Start: [.k0ntext/indexes/workflows/CATEGORY_INDEX.md](./.k0ntext/indexes/workflows/CATEGORY_INDEX.md)
56
+ 2. Find: Relevant category
57
+ 3. Load: Domain index
58
+ 4. Detail: Workflow file
59
+ 5. Code: [.k0ntext/indexes/code/DOMAIN_LAYER_INDEX.md](./.k0ntext/indexes/code/DOMAIN_LAYER_INDEX.md)
60
+ 6. Implement: Use appropriate specialized agent
61
+
62
+ **Context Budget:** ~40k tokens (20% of 200k window)
63
+
64
+ ---
65
+
66
+ ### Low-Level Task (Fix Hardcoded Value)
67
+ **Example:** "{{EXAMPLE_LOWLEVEL_TASK}}"
68
+
69
+ **Chain:**
70
+ 1. Start: Search Patterns section below
71
+ 2. Pattern: Use grep/find
72
+ 3. Verify: [.k0ntext/indexes/code/REVERSE_INDEXES.md](./.k0ntext/indexes/code/REVERSE_INDEXES.md)
73
+ 4. Fix: Direct file edits
74
+ 5. Validate: Run tests
75
+
76
+ **Context Budget:** ~15k tokens (7.5% of 200k window)
77
+
78
+ ---
79
+
80
+ ### Feature Task (Add New Feature)
81
+ **Example:** "{{EXAMPLE_FEATURE_TASK}}"
82
+
83
+ **Chain:**
84
+ 1. Start: [.k0ntext/indexes/routing/CATEGORY_INDEX.md](./.k0ntext/indexes/routing/CATEGORY_INDEX.md)
85
+ 2. Route: [.k0ntext/indexes/routing/HIGH_LEVEL_ROUTER.md](./.k0ntext/indexes/routing/HIGH_LEVEL_ROUTER.md)
86
+ 3. Research: /rpi-research
87
+ 4. Plan: /rpi-plan
88
+ 5. Implement: /rpi-implement
89
+
90
+ **Context Budget:** ~50k tokens (25% of 200k window)
91
+
92
+ ---
93
+
94
+ ## Search Patterns
95
+
96
+ ### Finding Configuration Values
97
+
98
+ **Environment variables:**
99
+ ```bash
100
+ {{CONFIG_SEARCH_PATTERN}}
101
+ ```
102
+
103
+ **Hardcoded URLs/domains:**
104
+ ```bash
105
+ {{URL_SEARCH_PATTERN}}
106
+ ```
107
+
108
+ ---
109
+
110
+ ### Finding Business Logic
111
+
112
+ **Core Files:**
113
+ {{CORE_FILES_LIST}}
114
+
115
+ ---
116
+
117
+ ### Finding Database Schema
118
+
119
+ **Models:** {{MODELS_PATH}}
120
+ **Migrations:** {{MIGRATIONS_PATH}}
121
+
122
+ ---
123
+
124
+ ### Finding External Integrations
125
+
126
+ {{EXTERNAL_INTEGRATIONS_LIST}}
127
+
128
+ ---
129
+
130
+ ## System Architecture Mini-Map
131
+
132
+ {{ARCHITECTURE_DIAGRAM}}
133
+
134
+ ---
135
+
136
+ ## Index Directory
137
+
138
+ **3-Level Chain:** AI_CONTEXT.md → Category (5) → Domain (15) → Detail (53)
139
+
140
+ **Level 1 - Categories:** [.k0ntext/indexes/*/CATEGORY_INDEX.md](./.k0ntext/indexes/)
141
+ - Workflows, Code, Search, Agents, Routing
142
+
143
+ **Level 2 - Domains:** [.k0ntext/indexes/workflows/*.md](./.k0ntext/indexes/workflows/)
144
+ - {{WORKFLOW_DOMAINS_COUNT}} workflow domains, {{CODE_DOMAINS_COUNT}} code domains
145
+
146
+ **Level 3 - Details:** [.k0ntext/context/workflows/](./.k0ntext/context/workflows/), [.k0ntext/agents/](./.k0ntext/agents/), [.k0ntext/commands/](./.k0ntext/commands/)
147
+ - {{WORKFLOWS_COUNT}} workflows, {{AGENTS_COUNT}} agents, {{COMMANDS_COUNT}} commands
148
+
149
+ ---
150
+
151
+ ## Critical Constants
152
+
153
+ ### Domain & URLs
154
+ {{CRITICAL_URLS}}
155
+
156
+ ### Business Constants
157
+ {{BUSINESS_CONSTANTS}}
158
+
159
+ ---
160
+
161
+ ## Quick Reference
162
+
163
+ **Understanding:** [ARCHITECTURE_SNAPSHOT.md](./.k0ntext/context/ARCHITECTURE_SNAPSHOT.md), [workflows/CATEGORY_INDEX.md](./.k0ntext/indexes/workflows/CATEGORY_INDEX.md), [KNOWN_GOTCHAS.md](./.k0ntext/context/KNOWN_GOTCHAS.md)
164
+
165
+ **Implementing:** [workflows/*.md](./.k0ntext/context/workflows/), [CODE_TO_WORKFLOW_MAP.md](./.k0ntext/context/CODE_TO_WORKFLOW_MAP.md)
166
+
167
+ **Debugging:** {{DEBUGGING_QUICK_REFS}}
168
+
169
+ ---
170
+
171
+ ## Agent & Command Routing
172
+
173
+ **Agents:** {{AGENT_ROUTING_TABLE}}
174
+ **Full matrix:** [.k0ntext/indexes/agents/router.md](./.k0ntext/indexes/agents/router.md)
175
+
176
+ **Commands:** /rpi-research, /rpi-plan, /rpi-implement, /verify-docs-current, /validate-all, /help, /collab, /analytics
177
+ **All commands:** [.k0ntext/commands/](./.k0ntext/commands/)
178
+
179
+ ---
180
+
181
+ ## Gotcha Quick Reference
182
+
183
+ ### {{GOTCHA_CATEGORY_1}}
184
+ {{GOTCHA_1_ITEMS}}
185
+
186
+ ### {{GOTCHA_CATEGORY_2}}
187
+ {{GOTCHA_2_ITEMS}}
188
+
189
+ **Full gotchas:** [.k0ntext/context/KNOWN_GOTCHAS.md](./.k0ntext/context/KNOWN_GOTCHAS.md)
190
+
191
+ ---
192
+
193
+ ## Documentation System
194
+
195
+ **Navigation:** 3-level chain (AI_CONTEXT.md → Category → Domain → Detail)
196
+ **Self-maintaining:** CODE_TO_WORKFLOW_MAP.md guides updates after code changes
197
+ **Validation:** Run /verify-docs-current [file_path] after modifications
198
+ **RPI Workflow:** /rpi-research → /rpi-plan → /rpi-implement
199
+
200
+ **See:** [.k0ntext/RPI_WORKFLOW_PLAN.md](./.k0ntext/RPI_WORKFLOW_PLAN.md), [.k0ntext/README.md](./.k0ntext/README.md)
201
+
202
+ ---
203
+
204
+ ## Production
205
+
206
+ **Platform:** {{PRODUCTION_PLATFORM}}
207
+ **Services:** {{PRODUCTION_SERVICES}}
208
+ **Monitoring:** {{MONITORING_COMMANDS}}
209
+
210
+ ---
211
+
212
+ ## Key Constraints
213
+
214
+ **Migrations:** {{MIGRATION_CONSTRAINTS}}
215
+ **Testing:** {{TESTING_CONSTRAINTS}}
216
+ **Security:** {{SECURITY_CONSTRAINTS}}
217
+
218
+ ---
219
+
220
+ ## Maintenance
221
+
222
+ **After changes:** Check CODE_TO_WORKFLOW_MAP.md → Update workflows → Run /verify-docs-current
223
+ **Docs hub:** [.k0ntext/README.md](./.k0ntext/README.md)
224
+ **RPI:** [.k0ntext/RPI_WORKFLOW_PLAN.md](./.k0ntext/RPI_WORKFLOW_PLAN.md)
225
+
226
+ ---
227
+
228
+ ## AI Tools Configuration
229
+
230
+ This context is optimized for:
231
+ - **Claude Code** - Full context reading
232
+ - **GitHub Copilot** - See `.github/copilot-instructions.md`
233
+ - **Cline** - See `.clinerules`
234
+ - **Antigravity** - See `.agent/` directory
235
+
236
+ ---
237
+
238
+ ## Contact
239
+
240
+ {{CONTACT_INFO}}
241
+
242
+ ---
243
+
244
+ **Version:** 2.0 | **Last Updated:** {{DATE}} | **Context Target:** 200k
245
+ **Architecture:** 3-Level Chain-of-Index | **Index Files:** {{INDEX_FILES_COUNT}}