grok-cli-hurry-mode 1.0.4 → 1.0.5
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.
- package/dist/hooks/use-input-handler.js +588 -0
- package/dist/hooks/use-input-handler.js.map +1 -1
- package/dist/subagents/subagent-framework.d.ts +66 -0
- package/dist/subagents/subagent-framework.js +349 -0
- package/dist/subagents/subagent-framework.js.map +1 -0
- package/dist/tools/documentation/agent-system-generator.d.ts +30 -0
- package/dist/tools/documentation/agent-system-generator.js +816 -0
- package/dist/tools/documentation/agent-system-generator.js.map +1 -0
- package/dist/tools/documentation/api-docs-generator.d.ts +89 -0
- package/dist/tools/documentation/api-docs-generator.js +344 -0
- package/dist/tools/documentation/api-docs-generator.js.map +1 -0
- package/dist/tools/documentation/auto-update-system.d.ts +47 -0
- package/dist/tools/documentation/auto-update-system.js +278 -0
- package/dist/tools/documentation/auto-update-system.js.map +1 -0
- package/dist/tools/documentation/changelog-generator.d.ts +39 -0
- package/dist/tools/documentation/changelog-generator.js +255 -0
- package/dist/tools/documentation/changelog-generator.js.map +1 -0
- package/dist/tools/documentation/claude-md-parser.d.ts +25 -0
- package/dist/tools/documentation/claude-md-parser.js +108 -0
- package/dist/tools/documentation/claude-md-parser.js.map +1 -0
- package/dist/tools/documentation/comments-generator.d.ts +55 -0
- package/dist/tools/documentation/comments-generator.js +238 -0
- package/dist/tools/documentation/comments-generator.js.map +1 -0
- package/dist/tools/documentation/docs-menu.d.ts +9 -0
- package/dist/tools/documentation/docs-menu.js +57 -0
- package/dist/tools/documentation/docs-menu.js.map +1 -0
- package/dist/tools/documentation/readme-generator.d.ts +31 -0
- package/dist/tools/documentation/readme-generator.js +244 -0
- package/dist/tools/documentation/readme-generator.js.map +1 -0
- package/dist/tools/documentation/self-healing-system.d.ts +66 -0
- package/dist/tools/documentation/self-healing-system.js +444 -0
- package/dist/tools/documentation/self-healing-system.js.map +1 -0
- package/dist/tools/documentation/smart-prd-assistant.d.ts +45 -0
- package/dist/tools/documentation/smart-prd-assistant.js +325 -0
- package/dist/tools/documentation/smart-prd-assistant.js.map +1 -0
- package/dist/tools/documentation/update-agent-docs.d.ts +37 -0
- package/dist/tools/documentation/update-agent-docs.js +275 -0
- package/dist/tools/documentation/update-agent-docs.js.map +1 -0
- package/dist/tools/intelligence/ast-parser.js +22 -4
- package/dist/tools/intelligence/ast-parser.js.map +1 -1
- package/dist/ui/app.d.ts +2 -1
- package/dist/ui/app.js +27 -6
- package/dist/ui/app.js.map +1 -1
- package/dist/ui/components/api-key-input.d.ts +2 -1
- package/dist/ui/components/api-key-input.js +18 -3
- package/dist/ui/components/api-key-input.js.map +1 -1
- package/dist/ui/components/chat-history.d.ts +2 -1
- package/dist/ui/components/chat-history.js +35 -13
- package/dist/ui/components/chat-history.js.map +1 -1
- package/dist/ui/components/chat-input.d.ts +2 -1
- package/dist/ui/components/chat-input.js +36 -15
- package/dist/ui/components/chat-input.js.map +1 -1
- package/dist/ui/components/chat-interface.d.ts +2 -1
- package/dist/ui/components/chat-interface.js +39 -5
- package/dist/ui/components/chat-interface.js.map +1 -1
- package/dist/ui/components/command-suggestions.d.ts +2 -1
- package/dist/ui/components/command-suggestions.js +8 -3
- package/dist/ui/components/command-suggestions.js.map +1 -1
- package/dist/ui/components/confirmation-dialog.d.ts +2 -1
- package/dist/ui/components/confirmation-dialog.js +39 -4
- package/dist/ui/components/confirmation-dialog.js.map +1 -1
- package/dist/ui/components/diff-renderer.js +66 -57
- package/dist/ui/components/diff-renderer.js.map +1 -1
- package/dist/ui/components/loading-spinner.d.ts +2 -1
- package/dist/ui/components/loading-spinner.js +13 -3
- package/dist/ui/components/loading-spinner.js.map +1 -1
- package/dist/ui/components/mcp-status.d.ts +2 -1
- package/dist/ui/components/mcp-status.js +6 -3
- package/dist/ui/components/mcp-status.js.map +1 -1
- package/dist/ui/components/model-selection.d.ts +2 -1
- package/dist/ui/components/model-selection.js +11 -2
- package/dist/ui/components/model-selection.js.map +1 -1
- package/dist/ui/shared/max-sized-box.js +2 -2
- package/dist/ui/shared/max-sized-box.js.map +1 -1
- package/dist/ui/utils/code-colorizer.js +2 -2
- package/dist/ui/utils/code-colorizer.js.map +1 -1
- package/dist/ui/utils/markdown-renderer.d.ts +2 -1
- package/dist/ui/utils/markdown-renderer.js +3 -3
- package/dist/ui/utils/markdown-renderer.js.map +1 -1
- package/package.json +21 -12
@@ -0,0 +1,816 @@
|
|
1
|
+
import path from 'path';
|
2
|
+
import fs from 'fs/promises';
|
3
|
+
import { existsSync } from 'fs';
|
4
|
+
import { claudeMdParser } from './claude-md-parser.js';
|
5
|
+
export class AgentSystemGenerator {
|
6
|
+
constructor(config) {
|
7
|
+
this.config = config;
|
8
|
+
}
|
9
|
+
async generateAgentSystem() {
|
10
|
+
const agentPath = path.join(this.config.rootPath, '.agent');
|
11
|
+
const filesCreated = [];
|
12
|
+
try {
|
13
|
+
// Check if .agent already exists
|
14
|
+
if (existsSync(agentPath)) {
|
15
|
+
return {
|
16
|
+
success: false,
|
17
|
+
message: '.agent directory already exists. Use --rebuild to recreate.',
|
18
|
+
filesCreated: []
|
19
|
+
};
|
20
|
+
}
|
21
|
+
// Create .agent directory structure
|
22
|
+
await fs.mkdir(agentPath, { recursive: true });
|
23
|
+
await fs.mkdir(path.join(agentPath, 'system'), { recursive: true });
|
24
|
+
await fs.mkdir(path.join(agentPath, 'tasks'), { recursive: true });
|
25
|
+
await fs.mkdir(path.join(agentPath, 'sop'), { recursive: true });
|
26
|
+
await fs.mkdir(path.join(agentPath, 'incidents'), { recursive: true });
|
27
|
+
await fs.mkdir(path.join(agentPath, 'guardrails'), { recursive: true });
|
28
|
+
await fs.mkdir(path.join(agentPath, 'commands'), { recursive: true });
|
29
|
+
// Generate README.md (index file)
|
30
|
+
const readmeContent = this.generateReadmeContent();
|
31
|
+
await fs.writeFile(path.join(agentPath, 'README.md'), readmeContent);
|
32
|
+
filesCreated.push('.agent/README.md');
|
33
|
+
// Generate system documentation
|
34
|
+
const systemFiles = await this.generateSystemDocs(agentPath);
|
35
|
+
filesCreated.push(...systemFiles);
|
36
|
+
// Generate initial SOP
|
37
|
+
const sopFiles = await this.generateInitialSOPs(agentPath);
|
38
|
+
filesCreated.push(...sopFiles);
|
39
|
+
// Generate example task/PRD
|
40
|
+
const taskFiles = await this.generateExampleTask(agentPath);
|
41
|
+
filesCreated.push(...taskFiles);
|
42
|
+
// Generate command documentation
|
43
|
+
const commandFiles = await this.generateCommandDocs(agentPath);
|
44
|
+
filesCreated.push(...commandFiles);
|
45
|
+
// Update CLAUDE.md with documentation workflow
|
46
|
+
const documentationSection = claudeMdParser.generateDocumentationSection();
|
47
|
+
const claudeResult = await claudeMdParser.updateClaude(this.config.rootPath, documentationSection);
|
48
|
+
let claudeMessage = '';
|
49
|
+
if (claudeResult.success) {
|
50
|
+
claudeMessage = `\n\n${claudeResult.message}`;
|
51
|
+
if (!claudeResult.message.includes('already contains')) {
|
52
|
+
filesCreated.push('CLAUDE.md');
|
53
|
+
}
|
54
|
+
}
|
55
|
+
return {
|
56
|
+
success: true,
|
57
|
+
message: `✅ Agent documentation system created successfully!\n\nFiles created:\n${filesCreated.map(f => ` - ${f}`).join('\n')}${claudeMessage}`,
|
58
|
+
filesCreated
|
59
|
+
};
|
60
|
+
}
|
61
|
+
catch (error) {
|
62
|
+
return {
|
63
|
+
success: false,
|
64
|
+
message: `Failed to create agent system: ${error.message}`,
|
65
|
+
filesCreated
|
66
|
+
};
|
67
|
+
}
|
68
|
+
}
|
69
|
+
generateReadmeContent() {
|
70
|
+
return `# 📚 .agent Documentation System
|
71
|
+
|
72
|
+
## Overview
|
73
|
+
This directory contains AI agent documentation for ${this.config.projectName}. This system helps AI agents understand the project context efficiently without scanning the entire codebase.
|
74
|
+
|
75
|
+
## 📁 Directory Structure
|
76
|
+
|
77
|
+
### 📋 system/
|
78
|
+
Core project information and architecture:
|
79
|
+
- **architecture.md** - Project structure and design patterns
|
80
|
+
- **api-schema.md** - API endpoints and data schemas
|
81
|
+
- **database-schema.md** - Data models and database structure
|
82
|
+
- **critical-state.md** - Current system state snapshot
|
83
|
+
|
84
|
+
### 📝 tasks/
|
85
|
+
Product requirement documents and feature specifications:
|
86
|
+
- Store PRDs before implementation
|
87
|
+
- Reference related architecture and dependencies
|
88
|
+
- Track implementation progress
|
89
|
+
|
90
|
+
### 📖 sop/
|
91
|
+
Standard operating procedures and workflows:
|
92
|
+
- Development patterns and conventions
|
93
|
+
- Deployment and maintenance procedures
|
94
|
+
- Code review and testing guidelines
|
95
|
+
|
96
|
+
### 🚨 incidents/
|
97
|
+
Documented failures with root cause analysis:
|
98
|
+
- Error patterns and their fixes
|
99
|
+
- Recovery procedures
|
100
|
+
- Prevention strategies
|
101
|
+
|
102
|
+
### 🛡️ guardrails/
|
103
|
+
Enforceable rules to prevent recurring mistakes:
|
104
|
+
- Naming conventions
|
105
|
+
- Configuration constraints
|
106
|
+
- Implementation patterns
|
107
|
+
|
108
|
+
### ⚙️ commands/
|
109
|
+
Documentation for documentation system commands:
|
110
|
+
- Usage guides for /init-agent, /update-agent-docs, etc.
|
111
|
+
- Integration workflows
|
112
|
+
|
113
|
+
## 🎯 Usage Guidelines
|
114
|
+
|
115
|
+
### For AI Agents
|
116
|
+
1. **Always read README.md first** - Get project overview (this file)
|
117
|
+
2. **Check system/critical-state.md** - Understand current architecture
|
118
|
+
3. **Review relevant tasks/** - Check for related work or conflicts
|
119
|
+
4. **Follow sop/** patterns - Use established conventions
|
120
|
+
5. **Check guardrails/** - Avoid known failure patterns
|
121
|
+
|
122
|
+
### For Updates
|
123
|
+
- Run \`/update-agent-docs\` after significant changes
|
124
|
+
- Add new PRDs to tasks/ before implementation
|
125
|
+
- Update system docs when architecture changes
|
126
|
+
- Document new patterns in sop/
|
127
|
+
|
128
|
+
## 🔗 Cross-References
|
129
|
+
- Main project documentation: ../README.md
|
130
|
+
- Configuration: ../.grok/settings.json
|
131
|
+
- Build instructions: ../package.json
|
132
|
+
|
133
|
+
---
|
134
|
+
*Generated by Grok CLI Documentation System*
|
135
|
+
*Last updated: ${new Date().toISOString().split('T')[0]}*
|
136
|
+
`;
|
137
|
+
}
|
138
|
+
async generateSystemDocs(agentPath) {
|
139
|
+
const systemPath = path.join(agentPath, 'system');
|
140
|
+
const files = [];
|
141
|
+
// Architecture overview
|
142
|
+
const archContent = this.config.projectType === 'grok-cli'
|
143
|
+
? this.generateGrokArchitecture()
|
144
|
+
: this.generateExternalArchitecture();
|
145
|
+
await fs.writeFile(path.join(systemPath, 'architecture.md'), archContent);
|
146
|
+
files.push('.agent/system/architecture.md');
|
147
|
+
// Critical state snapshot
|
148
|
+
const criticalStateContent = this.generateCriticalState();
|
149
|
+
await fs.writeFile(path.join(systemPath, 'critical-state.md'), criticalStateContent);
|
150
|
+
files.push('.agent/system/critical-state.md');
|
151
|
+
// API schema (if applicable)
|
152
|
+
const apiContent = this.generateApiSchema();
|
153
|
+
await fs.writeFile(path.join(systemPath, 'api-schema.md'), apiContent);
|
154
|
+
files.push('.agent/system/api-schema.md');
|
155
|
+
return files;
|
156
|
+
}
|
157
|
+
generateGrokArchitecture() {
|
158
|
+
return `# 🏗️ Grok CLI Architecture
|
159
|
+
|
160
|
+
## Project Type
|
161
|
+
**CLI Application** - Conversational AI tool with terminal interface
|
162
|
+
|
163
|
+
## Technology Stack
|
164
|
+
- **Language**: TypeScript (ES Modules)
|
165
|
+
- **Runtime**: Node.js (Bun recommended)
|
166
|
+
- **UI**: Ink (React for terminal)
|
167
|
+
- **Build**: TypeScript compiler + tsup for dual builds
|
168
|
+
- **Package Manager**: Bun/NPM
|
169
|
+
|
170
|
+
## Core Architecture
|
171
|
+
|
172
|
+
### 🧠 Agent System (\`src/agent/\`)
|
173
|
+
- **GrokAgent**: Central orchestration with streaming, tool execution
|
174
|
+
- **Conversation Management**: Chat history and context handling
|
175
|
+
- **Model Integration**: X.AI Grok models via OpenAI-compatible API
|
176
|
+
|
177
|
+
### 🛠️ Tool System (\`src/tools/\`)
|
178
|
+
- **Modular Design**: Independent tools for specific operations
|
179
|
+
- **Core Tools**: File operations, bash execution, search
|
180
|
+
- **Advanced Tools**: Multi-file editing, code analysis, operation history
|
181
|
+
- **Documentation Tools**: NEW - Agent system generation and maintenance
|
182
|
+
|
183
|
+
### 🖥️ UI Components (\`src/ui/\`)
|
184
|
+
- **Chat Interface**: Streaming responses with tool execution display
|
185
|
+
- **Input Handling**: Enhanced terminal input with history and shortcuts
|
186
|
+
- **Component Library**: Reusable Ink components for consistent UX
|
187
|
+
|
188
|
+
### 🔌 MCP Integration (\`src/mcp/\`)
|
189
|
+
- **Model Context Protocol**: Extensible server integration
|
190
|
+
- **Supported Servers**: Linear, GitHub, custom servers
|
191
|
+
- **Transport Types**: stdio, HTTP, SSE
|
192
|
+
|
193
|
+
### ⚙️ Configuration (\`src/utils/\`)
|
194
|
+
- **Settings Management**: User and project-level config
|
195
|
+
- **Model Configuration**: Support for multiple AI models
|
196
|
+
- **File Locations**: ~/.grok/ for user, .grok/ for project
|
197
|
+
|
198
|
+
## Build & Distribution
|
199
|
+
- **Development**: \`bun run dev\` for live reload
|
200
|
+
- **Production**: \`npm run build\` → dist/ directory
|
201
|
+
- **Installation**: NPM global package
|
202
|
+
|
203
|
+
## Extension Points
|
204
|
+
- **Tool System**: Add new tools in src/tools/
|
205
|
+
- **MCP Servers**: Configure external service integration
|
206
|
+
- **UI Components**: Extend terminal interface capabilities
|
207
|
+
- **Commands**: Add slash commands in input handler
|
208
|
+
|
209
|
+
## Current Capabilities
|
210
|
+
✅ File operations (read, write, edit, multi-file)
|
211
|
+
✅ Bash command execution
|
212
|
+
✅ Code analysis and refactoring
|
213
|
+
✅ Search and replace operations
|
214
|
+
✅ MCP server integration
|
215
|
+
✅ Operation history and undo/redo
|
216
|
+
✅ Project-specific configuration
|
217
|
+
|
218
|
+
## Planned Enhancements
|
219
|
+
🔲 Documentation generation system
|
220
|
+
🔲 Subagent framework for context efficiency
|
221
|
+
🔲 Self-healing guardrails
|
222
|
+
🔲 Advanced code intelligence
|
223
|
+
🔲 CI/CD integration
|
224
|
+
|
225
|
+
*Updated: ${new Date().toISOString().split('T')[0]}*
|
226
|
+
`;
|
227
|
+
}
|
228
|
+
generateExternalArchitecture() {
|
229
|
+
return `# 🏗️ Project Architecture
|
230
|
+
|
231
|
+
## Project Overview
|
232
|
+
External project documented using Grok CLI's .agent system.
|
233
|
+
|
234
|
+
## Technology Stack
|
235
|
+
*To be analyzed and documented*
|
236
|
+
|
237
|
+
## Core Components
|
238
|
+
*To be identified during project analysis*
|
239
|
+
|
240
|
+
## Current State
|
241
|
+
- Project type: External
|
242
|
+
- Documentation system: Initialized
|
243
|
+
- Architecture analysis: Pending
|
244
|
+
|
245
|
+
## Next Steps
|
246
|
+
1. Run project analysis to identify:
|
247
|
+
- Technology stack and frameworks
|
248
|
+
- Core components and modules
|
249
|
+
- Build and deployment processes
|
250
|
+
- Dependencies and configurations
|
251
|
+
|
252
|
+
2. Update this file with findings
|
253
|
+
3. Create specific documentation for key components
|
254
|
+
|
255
|
+
*This is a template - update after project analysis*
|
256
|
+
*Updated: ${new Date().toISOString().split('T')[0]}*
|
257
|
+
`;
|
258
|
+
}
|
259
|
+
generateCriticalState() {
|
260
|
+
const timestamp = new Date().toISOString();
|
261
|
+
if (this.config.projectType === 'grok-cli') {
|
262
|
+
return `# 🔧 Current System State
|
263
|
+
|
264
|
+
## Architecture Overview
|
265
|
+
- **Type**: CLI application with React/Ink UI
|
266
|
+
- **Language**: TypeScript (ESM modules)
|
267
|
+
- **Build**: TypeScript compiler + tsup dual build (CJS/ESM)
|
268
|
+
- **Package**: NPM global installation
|
269
|
+
- **Runtime**: Node.js (Bun recommended)
|
270
|
+
|
271
|
+
## Core Components
|
272
|
+
- **Commands**: Slash-based in src/commands/ (limited - only MCP command currently)
|
273
|
+
- **Tools**: Modular tools in src/tools/ (extensive tool system)
|
274
|
+
- **UI**: Ink components in src/ui/
|
275
|
+
- **Settings**: File-based .grok/settings.json + ~/.grok/user-settings.json
|
276
|
+
- **Input**: Enhanced terminal input with history in src/hooks/
|
277
|
+
|
278
|
+
## Command System
|
279
|
+
- **Slash Commands**: Handled in useInputHandler.ts
|
280
|
+
- **Current Commands**: /help, /clear, /models, /commit-and-push, /exit
|
281
|
+
- **Command Registration**: Direct implementation in input handler
|
282
|
+
- **Extension Pattern**: Add to handleDirectCommand function
|
283
|
+
|
284
|
+
## Authentication & Storage
|
285
|
+
- **Auth**: Environment variable GROK_API_KEY or user settings
|
286
|
+
- **Storage**: Local file system only
|
287
|
+
- **Database**: None (settings via JSON files)
|
288
|
+
- **MCP**: Optional server integration
|
289
|
+
|
290
|
+
## Current Capabilities
|
291
|
+
- ✅ File operations (read, write, edit, multi-file)
|
292
|
+
- ✅ Bash command execution with output capture
|
293
|
+
- ✅ Code analysis (AST parsing, refactoring)
|
294
|
+
- ✅ Search functionality (ripgrep-based)
|
295
|
+
- ✅ Operation history and undo/redo
|
296
|
+
- ✅ MCP server integration
|
297
|
+
- ✅ Todo management system
|
298
|
+
- ❌ No documentation generation system (yet)
|
299
|
+
- ❌ No cloud storage integration
|
300
|
+
- ❌ No built-in authentication system
|
301
|
+
|
302
|
+
## Build Configuration
|
303
|
+
- **TypeScript**: ESM modules with dual CJS/ESM output
|
304
|
+
- **Dependencies**: Ink, React, commander, chalk, ripgrep
|
305
|
+
- **Scripts**: dev, build, start, lint, typecheck
|
306
|
+
|
307
|
+
## Known Limitations
|
308
|
+
- Command system not centralized (handled in input hook)
|
309
|
+
- No formal command registration system
|
310
|
+
- Limited built-in documentation capabilities
|
311
|
+
|
312
|
+
## Recent Changes
|
313
|
+
- Fixed React import issues for ESM compatibility
|
314
|
+
- Implemented dual-build system with tsup
|
315
|
+
- Reverted to working TypeScript build
|
316
|
+
|
317
|
+
Last Updated: ${timestamp}
|
318
|
+
Updated By: Agent System Generator during /init-agent
|
319
|
+
`;
|
320
|
+
}
|
321
|
+
else {
|
322
|
+
return `# 🔧 Current System State
|
323
|
+
|
324
|
+
## Project Analysis
|
325
|
+
- **Project Type**: External project
|
326
|
+
- **Documentation Status**: Initialized
|
327
|
+
- **Analysis Status**: Pending
|
328
|
+
|
329
|
+
## Discovered Components
|
330
|
+
*To be populated during analysis*
|
331
|
+
|
332
|
+
## Current Capabilities
|
333
|
+
*To be identified*
|
334
|
+
|
335
|
+
## Configuration
|
336
|
+
*To be documented*
|
337
|
+
|
338
|
+
## Dependencies
|
339
|
+
*To be analyzed*
|
340
|
+
|
341
|
+
Last Updated: ${timestamp}
|
342
|
+
Updated By: Agent System Generator during /init-agent
|
343
|
+
*This file will be updated as the project is analyzed*
|
344
|
+
`;
|
345
|
+
}
|
346
|
+
}
|
347
|
+
generateApiSchema() {
|
348
|
+
if (this.config.projectType === 'grok-cli') {
|
349
|
+
return `# 🔌 API Schema
|
350
|
+
|
351
|
+
## Grok API Integration
|
352
|
+
|
353
|
+
### Base Configuration
|
354
|
+
\`\`\`typescript
|
355
|
+
{
|
356
|
+
baseURL: "https://api.x.ai/v1",
|
357
|
+
defaultModel: "grok-code-fast-1",
|
358
|
+
apiKey: process.env.GROK_API_KEY
|
359
|
+
}
|
360
|
+
\`\`\`
|
361
|
+
|
362
|
+
### Available Models
|
363
|
+
- **grok-4-latest**: Latest Grok model with enhanced capabilities
|
364
|
+
- **grok-code-fast-1**: Optimized for code generation (default)
|
365
|
+
- **grok-3-fast**: Fast general-purpose model
|
366
|
+
|
367
|
+
### Tool Integration Schema
|
368
|
+
Tools follow OpenAI function calling format:
|
369
|
+
|
370
|
+
\`\`\`typescript
|
371
|
+
interface ToolCall {
|
372
|
+
id: string;
|
373
|
+
type: "function";
|
374
|
+
function: {
|
375
|
+
name: string;
|
376
|
+
arguments: string; // JSON stringified
|
377
|
+
};
|
378
|
+
}
|
379
|
+
|
380
|
+
interface ToolResult {
|
381
|
+
success: boolean;
|
382
|
+
output?: string;
|
383
|
+
error?: string;
|
384
|
+
}
|
385
|
+
\`\`\`
|
386
|
+
|
387
|
+
### MCP Server Schema
|
388
|
+
Model Context Protocol integration:
|
389
|
+
|
390
|
+
\`\`\`typescript
|
391
|
+
interface MCPServerConfig {
|
392
|
+
name: string;
|
393
|
+
transport: {
|
394
|
+
type: 'stdio' | 'http' | 'sse' | 'streamable_http';
|
395
|
+
command?: string;
|
396
|
+
args?: string[];
|
397
|
+
url?: string;
|
398
|
+
env?: Record<string, string>;
|
399
|
+
headers?: Record<string, string>;
|
400
|
+
};
|
401
|
+
}
|
402
|
+
\`\`\`
|
403
|
+
|
404
|
+
## Internal APIs
|
405
|
+
|
406
|
+
### Agent Interface
|
407
|
+
\`\`\`typescript
|
408
|
+
interface GrokAgent {
|
409
|
+
processUserMessageStream(input: string): AsyncGenerator<StreamChunk>;
|
410
|
+
executeBashCommand(command: string): Promise<ToolResult>;
|
411
|
+
setModel(model: string): void;
|
412
|
+
getCurrentModel(): string;
|
413
|
+
}
|
414
|
+
\`\`\`
|
415
|
+
|
416
|
+
### Tool Interface
|
417
|
+
\`\`\`typescript
|
418
|
+
interface Tool {
|
419
|
+
name: string;
|
420
|
+
description: string;
|
421
|
+
parameters: JSONSchema7;
|
422
|
+
execute(args: any): Promise<ToolResult>;
|
423
|
+
}
|
424
|
+
\`\`\`
|
425
|
+
|
426
|
+
*Updated: ${new Date().toISOString().split('T')[0]}*
|
427
|
+
`;
|
428
|
+
}
|
429
|
+
else {
|
430
|
+
return `# 🔌 API Schema
|
431
|
+
|
432
|
+
## Project APIs
|
433
|
+
*To be documented after project analysis*
|
434
|
+
|
435
|
+
## External Dependencies
|
436
|
+
*To be identified*
|
437
|
+
|
438
|
+
## Data Models
|
439
|
+
*To be documented*
|
440
|
+
|
441
|
+
*This file will be updated as APIs are discovered and analyzed*
|
442
|
+
*Updated: ${new Date().toISOString().split('T')[0]}*
|
443
|
+
`;
|
444
|
+
}
|
445
|
+
}
|
446
|
+
async generateInitialSOPs(agentPath) {
|
447
|
+
const sopPath = path.join(agentPath, 'sop');
|
448
|
+
const files = [];
|
449
|
+
// Documentation workflow SOP
|
450
|
+
const docWorkflowContent = `# 📚 Documentation Workflow SOP
|
451
|
+
|
452
|
+
## When to Update Documentation
|
453
|
+
|
454
|
+
### Trigger Events
|
455
|
+
1. **Architecture Changes**: New components, modified structure
|
456
|
+
2. **New Features**: Added functionality or tools
|
457
|
+
3. **Configuration Changes**: Settings, build process, dependencies
|
458
|
+
4. **After Major Commits**: Significant code changes
|
459
|
+
5. **Failed Operations**: Document lessons learned
|
460
|
+
|
461
|
+
### Update Process
|
462
|
+
|
463
|
+
#### 1. Before Implementation
|
464
|
+
- [ ] Read .agent/README.md for project overview
|
465
|
+
- [ ] Check .agent/system/critical-state.md for current architecture
|
466
|
+
- [ ] Review .agent/tasks/ for related work or conflicts
|
467
|
+
- [ ] Scan .agent/sop/ for established patterns
|
468
|
+
- [ ] Check .agent/guardrails/ for constraints
|
469
|
+
|
470
|
+
#### 2. During Implementation
|
471
|
+
- [ ] Store PRDs in .agent/tasks/ before coding
|
472
|
+
- [ ] Reference architecture docs for consistency
|
473
|
+
- [ ] Follow established patterns from SOPs
|
474
|
+
- [ ] Use cross-references between .agent docs
|
475
|
+
|
476
|
+
#### 3. After Implementation
|
477
|
+
- [ ] Run \`/update-agent-docs\` to capture changes
|
478
|
+
- [ ] Update .agent/system/ if architecture changed
|
479
|
+
- [ ] Add new SOPs for repeatable processes
|
480
|
+
- [ ] Link related tasks and documents
|
481
|
+
- [ ] Test documentation updates for accuracy
|
482
|
+
|
483
|
+
## Documentation Standards
|
484
|
+
|
485
|
+
### File Organization
|
486
|
+
- **system/**: Core architecture and state
|
487
|
+
- **tasks/**: PRDs and feature specifications
|
488
|
+
- **sop/**: Procedures and workflows
|
489
|
+
- **incidents/**: Failure documentation
|
490
|
+
- **guardrails/**: Prevention rules
|
491
|
+
|
492
|
+
### Writing Guidelines
|
493
|
+
- **Conciseness**: Keep sections under 300 tokens
|
494
|
+
- **Cross-linking**: Use relative links between docs
|
495
|
+
- **Consistency**: Follow established markdown patterns
|
496
|
+
- **Freshness**: Include update timestamps
|
497
|
+
- **Relevance**: Focus on actionable information
|
498
|
+
|
499
|
+
### Template Usage
|
500
|
+
- Use consistent headings and structure
|
501
|
+
- Include metadata (updated date, updated by)
|
502
|
+
- Reference related documents
|
503
|
+
- Maintain clear navigation
|
504
|
+
|
505
|
+
## Automation
|
506
|
+
- Auto-update triggers configured in .grok/settings.json
|
507
|
+
- Smart prompts after key file changes
|
508
|
+
- Token threshold reminders
|
509
|
+
- Integration with git commit hooks
|
510
|
+
|
511
|
+
*Updated: ${new Date().toISOString().split('T')[0]}*
|
512
|
+
`;
|
513
|
+
await fs.writeFile(path.join(sopPath, 'documentation-workflow.md'), docWorkflowContent);
|
514
|
+
files.push('.agent/sop/documentation-workflow.md');
|
515
|
+
// Adding new command SOP (Grok CLI specific)
|
516
|
+
if (this.config.projectType === 'grok-cli') {
|
517
|
+
const newCommandContent = `# ⚙️ Adding New Commands SOP
|
518
|
+
|
519
|
+
## Command System Architecture
|
520
|
+
|
521
|
+
### Current Implementation
|
522
|
+
- Commands handled in \`src/hooks/use-input-handler.ts\`
|
523
|
+
- Direct implementation in \`handleDirectCommand\` function
|
524
|
+
- No centralized command registry (yet)
|
525
|
+
|
526
|
+
### Command Types
|
527
|
+
|
528
|
+
#### 1. Slash Commands
|
529
|
+
Built-in commands starting with \`/\`:
|
530
|
+
- Implementation: Add to \`handleDirectCommand\` function
|
531
|
+
- Pattern: \`if (trimmedInput === "/your-command") { ... }\`
|
532
|
+
- Registration: Update \`commandSuggestions\` array
|
533
|
+
|
534
|
+
#### 2. Direct Bash Commands
|
535
|
+
Immediate execution commands:
|
536
|
+
- Pattern: Add to \`directBashCommands\` array
|
537
|
+
- Execution: Automatic bash execution
|
538
|
+
|
539
|
+
#### 3. Natural Language
|
540
|
+
AI-processed commands:
|
541
|
+
- Fallback: Processed by \`processUserMessage\`
|
542
|
+
- Tool selection: Automatic based on AI analysis
|
543
|
+
|
544
|
+
### Implementation Steps
|
545
|
+
|
546
|
+
#### 1. Add Slash Command
|
547
|
+
\`\`\`typescript
|
548
|
+
// In commandSuggestions array
|
549
|
+
{ command: "/your-command", description: "Your command description" }
|
550
|
+
|
551
|
+
// In handleDirectCommand function
|
552
|
+
if (trimmedInput === "/your-command") {
|
553
|
+
// Implementation logic
|
554
|
+
const result = await someOperation();
|
555
|
+
|
556
|
+
const entry: ChatEntry = {
|
557
|
+
type: "assistant",
|
558
|
+
content: result,
|
559
|
+
timestamp: new Date(),
|
560
|
+
};
|
561
|
+
setChatHistory((prev) => [...prev, entry]);
|
562
|
+
clearInput();
|
563
|
+
return true;
|
564
|
+
}
|
565
|
+
\`\`\`
|
566
|
+
|
567
|
+
#### 2. Add Tool-Based Command
|
568
|
+
Create tool in \`src/tools/\`, then reference in command handler.
|
569
|
+
|
570
|
+
#### 3. Update Documentation
|
571
|
+
- Add command to /help output
|
572
|
+
- Document in .agent/commands/
|
573
|
+
- Update this SOP if pattern changes
|
574
|
+
|
575
|
+
### Best Practices
|
576
|
+
- **Consistent UX**: Follow existing command patterns
|
577
|
+
- **Error Handling**: Provide clear feedback
|
578
|
+
- **Tool Integration**: Leverage existing tool system
|
579
|
+
- **State Management**: Update chat history appropriately
|
580
|
+
- **Input Cleanup**: Always call \`clearInput()\`
|
581
|
+
|
582
|
+
### Future Improvements
|
583
|
+
- Centralized command registry system
|
584
|
+
- Dynamic command loading
|
585
|
+
- Plugin-based command architecture
|
586
|
+
|
587
|
+
*Updated: ${new Date().toISOString().split('T')[0]}*
|
588
|
+
`;
|
589
|
+
await fs.writeFile(path.join(sopPath, 'adding-new-command.md'), newCommandContent);
|
590
|
+
files.push('.agent/sop/adding-new-command.md');
|
591
|
+
}
|
592
|
+
return files;
|
593
|
+
}
|
594
|
+
async generateExampleTask(agentPath) {
|
595
|
+
const tasksPath = path.join(agentPath, 'tasks');
|
596
|
+
const files = [];
|
597
|
+
const exampleContent = this.config.projectType === 'grok-cli'
|
598
|
+
? this.generateGrokExampleTask()
|
599
|
+
: this.generateExternalExampleTask();
|
600
|
+
await fs.writeFile(path.join(tasksPath, 'example-prd.md'), exampleContent);
|
601
|
+
files.push('.agent/tasks/example-prd.md');
|
602
|
+
return files;
|
603
|
+
}
|
604
|
+
generateGrokExampleTask() {
|
605
|
+
return `# 📋 Example PRD: Documentation System Enhancement
|
606
|
+
|
607
|
+
## Objective
|
608
|
+
Add comprehensive documentation generation capabilities to Grok CLI.
|
609
|
+
|
610
|
+
## Background
|
611
|
+
Grok CLI needs better documentation tools to help users document both the CLI itself and their projects efficiently.
|
612
|
+
|
613
|
+
## Requirements
|
614
|
+
|
615
|
+
### Must Have
|
616
|
+
- [ ] \`/init-agent\` command for .agent system creation
|
617
|
+
- [ ] \`/docs\` interactive menu for documentation options
|
618
|
+
- [ ] \`/readme\` command for README generation
|
619
|
+
- [ ] Integration with existing command system
|
620
|
+
|
621
|
+
### Should Have
|
622
|
+
- [ ] \`/api-docs\` for API documentation
|
623
|
+
- [ ] \`/comments\` for code comment generation
|
624
|
+
- [ ] Auto-update system for documentation maintenance
|
625
|
+
|
626
|
+
### Could Have
|
627
|
+
- [ ] Custom templates for different project types
|
628
|
+
- [ ] Documentation quality scoring
|
629
|
+
- [ ] Integration with external documentation tools
|
630
|
+
|
631
|
+
## Technical Approach
|
632
|
+
|
633
|
+
### Architecture Impact
|
634
|
+
- New tool directory: \`src/tools/documentation/\`
|
635
|
+
- Command integration: Update \`use-input-handler.ts\`
|
636
|
+
- New dependencies: Minimal (leverage existing tools)
|
637
|
+
|
638
|
+
### Implementation Strategy
|
639
|
+
1. **Phase 1**: Agent system generator tool
|
640
|
+
2. **Phase 2**: Core documentation commands
|
641
|
+
3. **Phase 3**: Advanced features and automation
|
642
|
+
|
643
|
+
### Compatibility
|
644
|
+
- Must not break existing functionality
|
645
|
+
- Should follow established command patterns
|
646
|
+
- Integrate with current tool system architecture
|
647
|
+
|
648
|
+
## Success Criteria
|
649
|
+
- [ ] Users can run \`/init-agent\` and get functional documentation
|
650
|
+
- [ ] Commands are discoverable and intuitive
|
651
|
+
- [ ] Generated documentation is high quality
|
652
|
+
- [ ] System integrates seamlessly with existing workflow
|
653
|
+
|
654
|
+
## Dependencies
|
655
|
+
- Existing AST parser tool
|
656
|
+
- Current search functionality
|
657
|
+
- File operation tools
|
658
|
+
- Command system in input handler
|
659
|
+
|
660
|
+
## Risks & Mitigation
|
661
|
+
- **Risk**: Command system complexity
|
662
|
+
- **Mitigation**: Follow existing patterns, minimal changes
|
663
|
+
|
664
|
+
## Timeline
|
665
|
+
- **Week 1-2**: Foundation and agent system
|
666
|
+
- **Week 3-4**: Core documentation commands
|
667
|
+
- **Week 5-6**: Advanced features and polish
|
668
|
+
|
669
|
+
---
|
670
|
+
*This is an example PRD showing the format and level of detail expected*
|
671
|
+
*Created: ${new Date().toISOString().split('T')[0]}*
|
672
|
+
*Status: Example/Template*
|
673
|
+
`;
|
674
|
+
}
|
675
|
+
generateExternalExampleTask() {
|
676
|
+
return `# 📋 Example PRD Template
|
677
|
+
|
678
|
+
## Objective
|
679
|
+
*Describe what you want to build or improve*
|
680
|
+
|
681
|
+
## Background
|
682
|
+
*Provide context about why this is needed*
|
683
|
+
|
684
|
+
## Requirements
|
685
|
+
|
686
|
+
### Must Have
|
687
|
+
- [ ] *Critical features that must be implemented*
|
688
|
+
|
689
|
+
### Should Have
|
690
|
+
- [ ] *Important features that add significant value*
|
691
|
+
|
692
|
+
### Could Have
|
693
|
+
- [ ] *Nice-to-have features for future consideration*
|
694
|
+
|
695
|
+
## Technical Approach
|
696
|
+
|
697
|
+
### Architecture Impact
|
698
|
+
*How will this change the system architecture?*
|
699
|
+
|
700
|
+
### Implementation Strategy
|
701
|
+
*High-level approach and phases*
|
702
|
+
|
703
|
+
### Dependencies
|
704
|
+
*What existing systems or external dependencies are required?*
|
705
|
+
|
706
|
+
## Success Criteria
|
707
|
+
- [ ] *How will you know this is successful?*
|
708
|
+
|
709
|
+
## Risks & Mitigation
|
710
|
+
- **Risk**: *Potential issues*
|
711
|
+
- **Mitigation**: *How to address them*
|
712
|
+
|
713
|
+
## Timeline
|
714
|
+
*Estimated implementation timeline*
|
715
|
+
|
716
|
+
---
|
717
|
+
*This is a template - replace with actual PRD content*
|
718
|
+
*Created: ${new Date().toISOString().split('T')[0]}*
|
719
|
+
*Status: Template*
|
720
|
+
`;
|
721
|
+
}
|
722
|
+
async generateCommandDocs(agentPath) {
|
723
|
+
const commandsPath = path.join(agentPath, 'commands');
|
724
|
+
const files = [];
|
725
|
+
// /init-agent documentation
|
726
|
+
const initAgentContent = `# 📖 /init-agent Command
|
727
|
+
|
728
|
+
## Purpose
|
729
|
+
Initialize the .agent documentation system for AI-first project understanding.
|
730
|
+
|
731
|
+
## Usage
|
732
|
+
\`\`\`bash
|
733
|
+
/init-agent
|
734
|
+
\`\`\`
|
735
|
+
|
736
|
+
## What It Does
|
737
|
+
|
738
|
+
### 1. Directory Creation
|
739
|
+
Creates \`.agent/\` folder structure:
|
740
|
+
- \`system/\` - Architecture and current state
|
741
|
+
- \`tasks/\` - PRDs and feature specifications
|
742
|
+
- \`sop/\` - Standard operating procedures
|
743
|
+
- \`incidents/\` - Failure documentation
|
744
|
+
- \`guardrails/\` - Prevention rules
|
745
|
+
- \`commands/\` - Command documentation
|
746
|
+
|
747
|
+
### 2. Initial Documentation
|
748
|
+
- **README.md**: Navigation and overview
|
749
|
+
- **system/architecture.md**: Project structure
|
750
|
+
- **system/critical-state.md**: Current system snapshot
|
751
|
+
- **system/api-schema.md**: APIs and interfaces
|
752
|
+
- **sop/documentation-workflow.md**: Update procedures
|
753
|
+
|
754
|
+
### 3. Integration
|
755
|
+
- Updates or creates CLAUDE.md with workflow instructions
|
756
|
+
- Configures documentation system for the project type
|
757
|
+
- Sets up foundation for other documentation commands
|
758
|
+
|
759
|
+
## Project Types
|
760
|
+
|
761
|
+
### Grok CLI (Internal)
|
762
|
+
- Documents Grok CLI's own architecture
|
763
|
+
- Includes command system patterns
|
764
|
+
- References existing tool structure
|
765
|
+
|
766
|
+
### External Project
|
767
|
+
- Generic project documentation template
|
768
|
+
- Prepares for project analysis
|
769
|
+
- Creates foundation for custom documentation
|
770
|
+
|
771
|
+
## Files Created
|
772
|
+
After running \`/init-agent\`, you'll have:
|
773
|
+
- \`.agent/README.md\` - Main index
|
774
|
+
- \`.agent/system/\` - 3 core architecture files
|
775
|
+
- \`.agent/sop/\` - Documentation procedures
|
776
|
+
- \`.agent/tasks/example-prd.md\` - PRD template
|
777
|
+
- \`.agent/commands/\` - Command documentation
|
778
|
+
|
779
|
+
## Next Steps
|
780
|
+
After initialization:
|
781
|
+
1. Review generated documentation
|
782
|
+
2. Customize templates for your project
|
783
|
+
3. Run \`/update-agent-docs\` after changes
|
784
|
+
4. Add PRDs to \`tasks/\` before implementation
|
785
|
+
|
786
|
+
## Error Handling
|
787
|
+
- Checks for existing \`.agent/\` directory
|
788
|
+
- Provides clear error messages
|
789
|
+
- Safe operation (won't overwrite)
|
790
|
+
|
791
|
+
*Updated: ${new Date().toISOString().split('T')[0]}*
|
792
|
+
`;
|
793
|
+
await fs.writeFile(path.join(commandsPath, 'init-agent.md'), initAgentContent);
|
794
|
+
files.push('.agent/commands/init-agent.md');
|
795
|
+
return files;
|
796
|
+
}
|
797
|
+
async rebuildAgentSystem() {
|
798
|
+
const agentPath = path.join(this.config.rootPath, '.agent');
|
799
|
+
try {
|
800
|
+
// Remove existing .agent directory if it exists
|
801
|
+
if (existsSync(agentPath)) {
|
802
|
+
await fs.rm(agentPath, { recursive: true, force: true });
|
803
|
+
}
|
804
|
+
// Generate new system
|
805
|
+
return await this.generateAgentSystem();
|
806
|
+
}
|
807
|
+
catch (error) {
|
808
|
+
return {
|
809
|
+
success: false,
|
810
|
+
message: `Failed to rebuild agent system: ${error.message}`,
|
811
|
+
filesCreated: []
|
812
|
+
};
|
813
|
+
}
|
814
|
+
}
|
815
|
+
}
|
816
|
+
//# sourceMappingURL=agent-system-generator.js.map
|