@musashishao/agent-kit 1.2.2 → 1.3.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 (39) hide show
  1. package/.agent/mcp-gateway/README.md +121 -0
  2. package/.agent/mcp-gateway/dist/index.d.ts +11 -0
  3. package/.agent/mcp-gateway/dist/index.js +504 -0
  4. package/.agent/mcp-gateway/dist/sync/debouncer.d.ts +56 -0
  5. package/.agent/mcp-gateway/dist/sync/debouncer.js +112 -0
  6. package/.agent/mcp-gateway/dist/sync/incremental_syncer.d.ts +58 -0
  7. package/.agent/mcp-gateway/dist/sync/incremental_syncer.js +172 -0
  8. package/.agent/mcp-gateway/dist/sync/index.d.ts +6 -0
  9. package/.agent/mcp-gateway/dist/sync/index.js +6 -0
  10. package/.agent/mcp-gateway/dist/sync/timestamp_checker.d.ts +69 -0
  11. package/.agent/mcp-gateway/dist/sync/timestamp_checker.js +169 -0
  12. package/.agent/mcp-gateway/package.json +28 -0
  13. package/.agent/mcp-gateway/src/index.ts +608 -0
  14. package/.agent/mcp-gateway/src/sync/debouncer.ts +129 -0
  15. package/.agent/mcp-gateway/src/sync/incremental_syncer.ts +237 -0
  16. package/.agent/mcp-gateway/src/sync/index.ts +7 -0
  17. package/.agent/mcp-gateway/src/sync/timestamp_checker.ts +194 -0
  18. package/.agent/scripts/ak_cli.py +533 -0
  19. package/.agent/scripts/setup_host.py +557 -0
  20. package/.agent/scripts/verify_install.py +174 -0
  21. package/.agent/skills/app-builder/SKILL.md +51 -1
  22. package/.agent/skills/app-builder/scripts/generate_ai_infra.py +510 -0
  23. package/.agent/skills/documentation-templates/SKILL.md +9 -1
  24. package/.agent/skills/documentation-templates/agents-template.md +202 -0
  25. package/.agent/skills/graph-mapper/SKILL.md +211 -0
  26. package/.agent/skills/graph-mapper/scripts/generate_graph.py +503 -0
  27. package/.agent/skills/rag-engineering/SKILL.md +342 -0
  28. package/.agent/skills/rag-engineering/chunking-strategies.md +229 -0
  29. package/.agent/skills/rag-engineering/contextual-retrieval.md +261 -0
  30. package/.agent/skills/rag-engineering/hybrid-search.md +356 -0
  31. package/.agent/skills/rag-engineering/scripts/chunk_code.py +606 -0
  32. package/.agent/templates/mcp_configs/claude_desktop.json +14 -0
  33. package/.agent/templates/mcp_configs/cursor.json +13 -0
  34. package/.agent/templates/mcp_configs/vscode.json +13 -0
  35. package/.agent/workflows/create.md +70 -2
  36. package/bin/cli.js +91 -0
  37. package/docs/AI_DATA_INFRASTRUCTURE.md +288 -0
  38. package/docs/CHANGELOG_AI_INFRA.md +111 -0
  39. package/package.json +7 -2
@@ -0,0 +1,510 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ AI Infrastructure Generator
4
+
5
+ Automatically generates AGENTS.md, dependency graph, and RAG structure
6
+ for new projects created via /create workflow.
7
+
8
+ Usage:
9
+ python generate_ai_infra.py --project-root ./my-project
10
+ """
11
+
12
+ import os
13
+ import json
14
+ import subprocess
15
+ import argparse
16
+ from pathlib import Path
17
+ from datetime import datetime
18
+ from typing import Dict, List, Optional
19
+
20
+
21
+ def detect_tech_stack(project_root: Path) -> Dict:
22
+ """Detect tech stack from project files."""
23
+ stack = {
24
+ 'frontend': None,
25
+ 'backend': None,
26
+ 'database': None,
27
+ 'styling': None,
28
+ 'testing': None,
29
+ 'language': None,
30
+ }
31
+
32
+ # Check package.json
33
+ package_json = project_root / 'package.json'
34
+ if package_json.exists():
35
+ try:
36
+ pkg = json.loads(package_json.read_text())
37
+ deps = {**pkg.get('dependencies', {}), **pkg.get('devDependencies', {})}
38
+
39
+ # Frontend
40
+ if 'next' in deps:
41
+ stack['frontend'] = 'Next.js'
42
+ elif 'react' in deps:
43
+ stack['frontend'] = 'React'
44
+ elif 'vue' in deps:
45
+ stack['frontend'] = 'Vue'
46
+ elif 'svelte' in deps:
47
+ stack['frontend'] = 'Svelte'
48
+
49
+ # Backend
50
+ if 'express' in deps:
51
+ stack['backend'] = 'Express'
52
+ elif 'fastify' in deps:
53
+ stack['backend'] = 'Fastify'
54
+ elif 'nestjs' in deps or '@nestjs/core' in deps:
55
+ stack['backend'] = 'NestJS'
56
+
57
+ # Database
58
+ if 'prisma' in deps or '@prisma/client' in deps:
59
+ stack['database'] = 'Prisma'
60
+ elif 'mongoose' in deps:
61
+ stack['database'] = 'MongoDB + Mongoose'
62
+ elif 'drizzle-orm' in deps:
63
+ stack['database'] = 'Drizzle ORM'
64
+
65
+ # Styling
66
+ if 'tailwindcss' in deps:
67
+ stack['styling'] = 'Tailwind CSS'
68
+ elif 'styled-components' in deps:
69
+ stack['styling'] = 'Styled Components'
70
+ elif 'sass' in deps:
71
+ stack['styling'] = 'Sass'
72
+
73
+ # Testing
74
+ if 'vitest' in deps:
75
+ stack['testing'] = 'Vitest'
76
+ elif 'jest' in deps:
77
+ stack['testing'] = 'Jest'
78
+ elif 'playwright' in deps or '@playwright/test' in deps:
79
+ stack['testing'] = 'Playwright'
80
+
81
+ # Language
82
+ if 'typescript' in deps:
83
+ stack['language'] = 'TypeScript'
84
+ else:
85
+ stack['language'] = 'JavaScript'
86
+
87
+ except json.JSONDecodeError:
88
+ pass
89
+
90
+ # Check Python files
91
+ requirements = project_root / 'requirements.txt'
92
+ pyproject = project_root / 'pyproject.toml'
93
+
94
+ if requirements.exists() or pyproject.exists():
95
+ stack['language'] = 'Python'
96
+
97
+ if requirements.exists():
98
+ content = requirements.read_text().lower()
99
+ if 'fastapi' in content:
100
+ stack['backend'] = 'FastAPI'
101
+ elif 'django' in content:
102
+ stack['backend'] = 'Django'
103
+ elif 'flask' in content:
104
+ stack['backend'] = 'Flask'
105
+
106
+ if 'sqlalchemy' in content:
107
+ stack['database'] = 'SQLAlchemy'
108
+ elif 'prisma' in content:
109
+ stack['database'] = 'Prisma'
110
+
111
+ if 'pytest' in content:
112
+ stack['testing'] = 'Pytest'
113
+
114
+ return stack
115
+
116
+
117
+ def detect_directory_structure(project_root: Path) -> Dict[str, str]:
118
+ """Detect and describe directory structure."""
119
+ structure = {}
120
+
121
+ common_dirs = {
122
+ 'src': 'Source code',
123
+ 'app': 'Next.js App Router pages',
124
+ 'pages': 'Next.js Pages Router / Vue pages',
125
+ 'components': 'React/Vue components',
126
+ 'lib': 'Utility functions and helpers',
127
+ 'utils': 'Utility functions',
128
+ 'hooks': 'Custom React hooks',
129
+ 'types': 'TypeScript type definitions',
130
+ 'api': 'API routes',
131
+ 'services': 'Business logic services',
132
+ 'models': 'Database models',
133
+ 'prisma': 'Prisma schema and migrations',
134
+ 'public': 'Static assets',
135
+ 'static': 'Static files',
136
+ 'tests': 'Test files',
137
+ '__tests__': 'Jest test files',
138
+ 'e2e': 'End-to-end tests',
139
+ 'docs': 'Documentation',
140
+ 'scripts': 'Build/utility scripts',
141
+ 'config': 'Configuration files',
142
+ }
143
+
144
+ for dir_name, description in common_dirs.items():
145
+ dir_path = project_root / dir_name
146
+ if dir_path.exists() and dir_path.is_dir():
147
+ structure[dir_name] = description
148
+
149
+ return structure
150
+
151
+
152
+ def detect_commands(project_root: Path) -> Dict[str, str]:
153
+ """Detect available npm/python commands."""
154
+ commands = {}
155
+
156
+ package_json = project_root / 'package.json'
157
+ if package_json.exists():
158
+ try:
159
+ pkg = json.loads(package_json.read_text())
160
+ scripts = pkg.get('scripts', {})
161
+
162
+ # Map common scripts
163
+ script_descriptions = {
164
+ 'dev': 'Start development server',
165
+ 'start': 'Start production server',
166
+ 'build': 'Build for production',
167
+ 'test': 'Run tests',
168
+ 'lint': 'Run linter',
169
+ 'format': 'Format code',
170
+ 'db:push': 'Push database schema',
171
+ 'db:migrate': 'Run database migrations',
172
+ 'db:studio': 'Open database studio',
173
+ }
174
+
175
+ for script, cmd in scripts.items():
176
+ desc = script_descriptions.get(script, cmd[:50])
177
+ commands[f'npm run {script}'] = desc
178
+
179
+ except json.JSONDecodeError:
180
+ pass
181
+
182
+ # Python commands
183
+ if (project_root / 'manage.py').exists():
184
+ commands['python manage.py runserver'] = 'Start Django server'
185
+ commands['python manage.py migrate'] = 'Run migrations'
186
+
187
+ if (project_root / 'pyproject.toml').exists():
188
+ commands['pytest'] = 'Run tests'
189
+ commands['uvicorn main:app --reload'] = 'Start FastAPI server'
190
+
191
+ return commands
192
+
193
+
194
+ def generate_agents_md(
195
+ project_root: Path,
196
+ project_name: str,
197
+ stack: Dict,
198
+ structure: Dict[str, str],
199
+ commands: Dict[str, str]
200
+ ) -> str:
201
+ """Generate AGENTS.md content."""
202
+
203
+ # Build tech stack table
204
+ stack_rows = []
205
+ layer_map = {
206
+ 'frontend': 'Frontend',
207
+ 'backend': 'Backend',
208
+ 'database': 'Database',
209
+ 'styling': 'Styling',
210
+ 'testing': 'Testing',
211
+ 'language': 'Language',
212
+ }
213
+ for key, layer in layer_map.items():
214
+ if stack.get(key):
215
+ stack_rows.append(f"| **{layer}** | {stack[key]} | - |")
216
+
217
+ stack_table = '\n'.join(stack_rows) if stack_rows else "| - | - | - |"
218
+
219
+ # Build directory map
220
+ dir_lines = []
221
+ for dir_name, desc in sorted(structure.items()):
222
+ dir_lines.append(f"│ ├── {dir_name}/{'':>15} # {desc}")
223
+ dir_map = '\n'.join(dir_lines) if dir_lines else "│ └── (empty project)"
224
+
225
+ # Build commands table
226
+ cmd_rows = []
227
+ for cmd, desc in list(commands.items())[:10]: # Limit to 10
228
+ cmd_rows.append(f"| `{cmd}` | {desc} |")
229
+ cmd_table = '\n'.join(cmd_rows) if cmd_rows else "| - | - |"
230
+
231
+ return f"""# AGENTS.md
232
+
233
+ > AI Navigation Map for **{project_name}**
234
+
235
+ ---
236
+
237
+ ## 📊 Project Pulse
238
+
239
+ | Metric | Value |
240
+ |--------|-------|
241
+ | **Status** | 🟢 Active |
242
+ | **Version** | 0.1.0 |
243
+ | **Last Updated** | {datetime.now().strftime('%Y-%m-%d')} |
244
+ | **Primary Language** | {stack.get('language', 'Unknown')} |
245
+
246
+ ---
247
+
248
+ ## 🛠️ Tech Stack
249
+
250
+ | Layer | Technology | Notes |
251
+ |-------|------------|-------|
252
+ {stack_table}
253
+
254
+ ---
255
+
256
+ ## 📁 Directory Map
257
+
258
+ ```
259
+ {project_name}/
260
+ {dir_map}
261
+ ├── .agent/ # AI agent configuration
262
+ └── AGENTS.md # This file
263
+ ```
264
+
265
+ ### Critical Paths
266
+
267
+ | Path | Purpose | ⚠️ Caution |
268
+ |------|---------|------------|
269
+ | `.env.local` | Environment secrets | Never commit |
270
+ | `prisma/schema.prisma` | Database schema | Requires migration |
271
+
272
+ ### Off-Limits (Do Not Modify)
273
+
274
+ - `node_modules/` - Dependencies
275
+ - `.next/` / `dist/` / `build/` - Build artifacts
276
+ - `__pycache__/` - Python cache
277
+
278
+ ---
279
+
280
+ ## 📜 Rules & Conventions
281
+
282
+ ### Naming Conventions
283
+
284
+ | Type | Convention | Example |
285
+ |------|------------|---------|
286
+ | Components | PascalCase | `UserProfile.tsx` |
287
+ | Hooks | camelCase with `use` prefix | `useAuth.ts` |
288
+ | Utils | camelCase | `formatDate.ts` |
289
+ | Constants | SCREAMING_SNAKE | `MAX_RETRY_COUNT` |
290
+
291
+ ### Code Style
292
+
293
+ - **TypeScript Strict Mode** - No `any` types allowed
294
+ - **Functional Components** - No class components
295
+ - **Server-First** - Prefer Server Components when using Next.js
296
+
297
+ ---
298
+
299
+ ## 🔧 Commands Reference
300
+
301
+ | Task | Command |
302
+ |------|---------|
303
+ {cmd_table}
304
+
305
+ ---
306
+
307
+ ## 🤖 AI Agent Instructions
308
+
309
+ ### When Modifying Code
310
+
311
+ 1. **Check Dependencies First** - Read `.agent/graph.json` for file relationships
312
+ 2. **Run Tests After Changes** - Verify with test command
313
+ 3. **Update Types** - If changing data structures, update type definitions
314
+
315
+ ### When Creating New Features
316
+
317
+ 1. Follow existing folder structure patterns
318
+ 2. Create component in appropriate directory
319
+ 3. Add types to designated types folder
320
+ 4. Write tests mirroring source path
321
+
322
+ ### MCP Servers Available
323
+
324
+ | Server | Purpose | When to Use |
325
+ |--------|---------|-------------|
326
+ | `filesystem` | Read/write project files | File operations |
327
+
328
+ ---
329
+
330
+ ## 📈 Current Focus
331
+
332
+ > Update this section to guide AI on current priorities
333
+
334
+ - [ ] Initial project setup
335
+ - [ ] Core feature implementation
336
+ - [ ] Testing and documentation
337
+
338
+ ---
339
+
340
+ *Generated by Agent Kit on {datetime.now().strftime('%Y-%m-%d %H:%M')}*
341
+ """
342
+
343
+
344
+ def setup_agent_directory(project_root: Path):
345
+ """Create .agent directory structure."""
346
+ agent_dir = project_root / '.agent'
347
+ rag_dir = agent_dir / 'rag'
348
+
349
+ # Create directories
350
+ agent_dir.mkdir(exist_ok=True)
351
+ rag_dir.mkdir(exist_ok=True)
352
+
353
+ # Create .gitkeep for rag directory
354
+ (rag_dir / '.gitkeep').touch()
355
+
356
+ # Create RAG readme
357
+ rag_readme = """# RAG Data Directory
358
+
359
+ This directory stores RAG (Retrieval-Augmented Generation) data for AI assistance.
360
+
361
+ ## Files
362
+
363
+ - `chunks.json` - Code chunks with metadata (generated by `chunk_code.py`)
364
+ - `embeddings.npy` - Vector embeddings (optional, for local vector DB)
365
+
366
+ ## Generate Chunks
367
+
368
+ ```bash
369
+ python .agent/skills/rag-engineering/scripts/chunk_code.py \\
370
+ --src ./src \\
371
+ --output .agent/rag/chunks.json
372
+ ```
373
+
374
+ ## Note
375
+
376
+ These files are typically gitignored as they can be regenerated.
377
+ Add to `.gitignore`:
378
+ ```
379
+ .agent/rag/chunks.json
380
+ .agent/rag/embeddings.npy
381
+ ```
382
+ """
383
+ (rag_dir / 'README.md').write_text(rag_readme)
384
+
385
+ return agent_dir
386
+
387
+
388
+ def run_graph_mapper(project_root: Path, agent_dir: Path) -> bool:
389
+ """Run graph-mapper script if source exists."""
390
+ src_dir = project_root / 'src'
391
+ app_dir = project_root / 'app'
392
+
393
+ # Determine source directory
394
+ if src_dir.exists():
395
+ source = src_dir
396
+ elif app_dir.exists():
397
+ source = app_dir
398
+ else:
399
+ print("No src/ or app/ directory found, skipping graph generation")
400
+ return False
401
+
402
+ # Check if graph-mapper script exists
403
+ script_path = Path(__file__).parent.parent / 'graph-mapper' / 'scripts' / 'generate_graph.py'
404
+
405
+ if not script_path.exists():
406
+ print(f"Graph mapper script not found at {script_path}")
407
+ return False
408
+
409
+ try:
410
+ result = subprocess.run(
411
+ [
412
+ 'python', str(script_path),
413
+ '--src', str(source),
414
+ '--output', str(agent_dir / 'graph.json'),
415
+ '--format', 'both'
416
+ ],
417
+ capture_output=True,
418
+ text=True,
419
+ cwd=str(project_root)
420
+ )
421
+
422
+ if result.returncode == 0:
423
+ print("✅ Dependency graph generated")
424
+ return True
425
+ else:
426
+ print(f"⚠️ Graph generation warning: {result.stderr}")
427
+ return False
428
+
429
+ except Exception as e:
430
+ print(f"⚠️ Could not run graph mapper: {e}")
431
+ return False
432
+
433
+
434
+ def main():
435
+ parser = argparse.ArgumentParser(description='Generate AI infrastructure for project')
436
+ parser.add_argument('--project-root', default='.', help='Project root directory')
437
+ parser.add_argument('--name', help='Project name (auto-detected if not provided)')
438
+ parser.add_argument('--skip-graph', action='store_true', help='Skip graph generation')
439
+
440
+ args = parser.parse_args()
441
+
442
+ project_root = Path(args.project_root).resolve()
443
+
444
+ if not project_root.exists():
445
+ print(f"Error: Project root '{project_root}' does not exist")
446
+ return 1
447
+
448
+ # Detect project name
449
+ project_name = args.name
450
+ if not project_name:
451
+ package_json = project_root / 'package.json'
452
+ if package_json.exists():
453
+ try:
454
+ pkg = json.loads(package_json.read_text())
455
+ project_name = pkg.get('name', project_root.name)
456
+ except:
457
+ project_name = project_root.name
458
+ else:
459
+ project_name = project_root.name
460
+
461
+ print(f"🚀 Generating AI infrastructure for: {project_name}")
462
+ print(f" Project root: {project_root}")
463
+
464
+ # Step 1: Detect tech stack
465
+ print("\n📦 Detecting tech stack...")
466
+ stack = detect_tech_stack(project_root)
467
+ for key, value in stack.items():
468
+ if value:
469
+ print(f" {key}: {value}")
470
+
471
+ # Step 2: Detect directory structure
472
+ print("\n📁 Analyzing directory structure...")
473
+ structure = detect_directory_structure(project_root)
474
+ print(f" Found {len(structure)} directories")
475
+
476
+ # Step 3: Detect commands
477
+ print("\n🔧 Detecting available commands...")
478
+ commands = detect_commands(project_root)
479
+ print(f" Found {len(commands)} commands")
480
+
481
+ # Step 4: Setup .agent directory
482
+ print("\n📂 Setting up .agent directory...")
483
+ agent_dir = setup_agent_directory(project_root)
484
+ print(f" Created: {agent_dir}")
485
+
486
+ # Step 5: Generate AGENTS.md
487
+ print("\n📝 Generating AGENTS.md...")
488
+ agents_md = generate_agents_md(project_root, project_name, stack, structure, commands)
489
+ agents_path = project_root / 'AGENTS.md'
490
+ agents_path.write_text(agents_md)
491
+ print(f" Created: {agents_path}")
492
+
493
+ # Step 6: Generate dependency graph
494
+ if not args.skip_graph:
495
+ print("\n🔗 Generating dependency graph...")
496
+ run_graph_mapper(project_root, agent_dir)
497
+
498
+ print("\n✅ AI Infrastructure setup complete!")
499
+ print("\nGenerated files:")
500
+ print(f" - {project_root}/AGENTS.md")
501
+ print(f" - {agent_dir}/")
502
+ if (agent_dir / 'graph.json').exists():
503
+ print(f" - {agent_dir}/graph.json")
504
+ print(f" - {agent_dir}/graph.md")
505
+
506
+ return 0
507
+
508
+
509
+ if __name__ == '__main__':
510
+ exit(main())
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: documentation-templates
3
- description: Documentation templates and structure guidelines. README, API docs, code comments, and AI-friendly documentation.
3
+ description: Documentation templates and structure guidelines. README, API docs, code comments, AGENTS.md for AI navigation, and AI-friendly documentation.
4
4
  allowed-tools: Read, Glob, Grep
5
5
  ---
6
6
 
@@ -10,6 +10,14 @@ allowed-tools: Read, Glob, Grep
10
10
 
11
11
  ---
12
12
 
13
+ ## 🔧 Quick Reference
14
+
15
+ | File | Purpose |
16
+ |------|---------|
17
+ | [agents-template.md](agents-template.md) | AGENTS.md - AI Navigation Map (Layer 1) |
18
+
19
+ ---
20
+
13
21
  ## 1. README Structure
14
22
 
15
23
  ### Essential Sections (Priority Order)