ted-mosby 1.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.
- package/LICENSE +21 -0
- package/README.md +238 -0
- package/dist/agent.d.ts +37 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +247 -0
- package/dist/agent.js.map +1 -0
- package/dist/claude-config.d.ts +58 -0
- package/dist/claude-config.d.ts.map +1 -0
- package/dist/claude-config.js +169 -0
- package/dist/claude-config.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1379 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +42 -0
- package/dist/config.js.map +1 -0
- package/dist/mcp-config.d.ts +45 -0
- package/dist/mcp-config.d.ts.map +1 -0
- package/dist/mcp-config.js +111 -0
- package/dist/mcp-config.js.map +1 -0
- package/dist/permissions.d.ts +32 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/permissions.js +165 -0
- package/dist/permissions.js.map +1 -0
- package/dist/planner.d.ts +42 -0
- package/dist/planner.d.ts.map +1 -0
- package/dist/planner.js +232 -0
- package/dist/planner.js.map +1 -0
- package/dist/prompts/wiki-system.d.ts +8 -0
- package/dist/prompts/wiki-system.d.ts.map +1 -0
- package/dist/prompts/wiki-system.js +249 -0
- package/dist/prompts/wiki-system.js.map +1 -0
- package/dist/rag/index.d.ts +84 -0
- package/dist/rag/index.d.ts.map +1 -0
- package/dist/rag/index.js +446 -0
- package/dist/rag/index.js.map +1 -0
- package/dist/tools/command-runner.d.ts +21 -0
- package/dist/tools/command-runner.d.ts.map +1 -0
- package/dist/tools/command-runner.js +67 -0
- package/dist/tools/command-runner.js.map +1 -0
- package/dist/tools/file-operations.d.ts +22 -0
- package/dist/tools/file-operations.d.ts.map +1 -0
- package/dist/tools/file-operations.js +119 -0
- package/dist/tools/file-operations.js.map +1 -0
- package/dist/tools/web-tools.d.ts +17 -0
- package/dist/tools/web-tools.d.ts.map +1 -0
- package/dist/tools/web-tools.js +122 -0
- package/dist/tools/web-tools.js.map +1 -0
- package/dist/wiki-agent.d.ts +81 -0
- package/dist/wiki-agent.d.ts.map +1 -0
- package/dist/wiki-agent.js +552 -0
- package/dist/wiki-agent.js.map +1 -0
- package/dist/workflows.d.ts +53 -0
- package/dist/workflows.d.ts.map +1 -0
- package/dist/workflows.js +169 -0
- package/dist/workflows.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
import { query, tool, createSdkMcpServer } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import { simpleGit } from 'simple-git';
|
|
6
|
+
import matter from 'gray-matter';
|
|
7
|
+
import { PermissionManager } from './permissions.js';
|
|
8
|
+
import { MCPConfigManager } from './mcp-config.js';
|
|
9
|
+
import { RAGSystem } from './rag/index.js';
|
|
10
|
+
import { WIKI_SYSTEM_PROMPT } from './prompts/wiki-system.js';
|
|
11
|
+
export class ArchitecturalWikiAgent {
|
|
12
|
+
config;
|
|
13
|
+
permissionManager;
|
|
14
|
+
mcpConfigManager;
|
|
15
|
+
customServer;
|
|
16
|
+
ragSystem = null;
|
|
17
|
+
repoPath = '';
|
|
18
|
+
outputDir = '';
|
|
19
|
+
sessionId;
|
|
20
|
+
constructor(config = {}) {
|
|
21
|
+
this.config = config;
|
|
22
|
+
if (config.apiKey) {
|
|
23
|
+
process.env.ANTHROPIC_API_KEY = config.apiKey;
|
|
24
|
+
}
|
|
25
|
+
if (!process.env.ANTHROPIC_API_KEY) {
|
|
26
|
+
throw new Error('Anthropic API key required. Set ANTHROPIC_API_KEY environment variable.');
|
|
27
|
+
}
|
|
28
|
+
this.permissionManager = config.permissionManager || new PermissionManager({ policy: 'permissive' });
|
|
29
|
+
this.mcpConfigManager = new MCPConfigManager();
|
|
30
|
+
this.customServer = this.createCustomToolServer();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generate wiki documentation for a repository
|
|
34
|
+
*/
|
|
35
|
+
async *generateWiki(options) {
|
|
36
|
+
// Phase 1: Clone or access repository
|
|
37
|
+
yield { type: 'phase', message: 'Preparing repository', progress: 0 };
|
|
38
|
+
this.repoPath = await this.prepareRepository(options.repoUrl, options.accessToken);
|
|
39
|
+
this.outputDir = path.resolve(options.outputDir);
|
|
40
|
+
// Ensure output directory exists
|
|
41
|
+
if (!fs.existsSync(this.outputDir)) {
|
|
42
|
+
fs.mkdirSync(this.outputDir, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
// Phase 2: Index codebase for RAG
|
|
45
|
+
yield { type: 'phase', message: 'Indexing codebase for semantic search', progress: 10 };
|
|
46
|
+
this.ragSystem = new RAGSystem({
|
|
47
|
+
storePath: path.join(this.outputDir, '.ted-mosby-cache'),
|
|
48
|
+
repoPath: this.repoPath
|
|
49
|
+
});
|
|
50
|
+
await this.ragSystem.indexRepository();
|
|
51
|
+
yield { type: 'step', message: `Indexed ${this.ragSystem.getDocumentCount()} code chunks` };
|
|
52
|
+
// Recreate tool server with RAG system initialized
|
|
53
|
+
this.customServer = this.createCustomToolServer();
|
|
54
|
+
// Phase 3: Run agent to generate wiki
|
|
55
|
+
yield { type: 'phase', message: 'Generating architectural documentation', progress: 20 };
|
|
56
|
+
const agentOptions = this.buildAgentOptions(options);
|
|
57
|
+
const prompt = this.buildGenerationPrompt(options);
|
|
58
|
+
// Stream agent execution using simple string prompt
|
|
59
|
+
try {
|
|
60
|
+
const queryResult = query({
|
|
61
|
+
prompt,
|
|
62
|
+
options: agentOptions
|
|
63
|
+
});
|
|
64
|
+
for await (const message of queryResult) {
|
|
65
|
+
// Capture session ID
|
|
66
|
+
if (message.type === 'system' && message.subtype === 'init') {
|
|
67
|
+
this.sessionId = message.session_id;
|
|
68
|
+
}
|
|
69
|
+
// Log errors from the agent
|
|
70
|
+
if (message.type === 'system' && message.subtype === 'error') {
|
|
71
|
+
console.error('Agent error:', message.error || message);
|
|
72
|
+
}
|
|
73
|
+
yield message;
|
|
74
|
+
}
|
|
75
|
+
yield { type: 'complete', message: 'Wiki generation complete', progress: 100 };
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
// Capture stderr if available
|
|
79
|
+
console.error('Query error details:', err.message);
|
|
80
|
+
if (err.stderr) {
|
|
81
|
+
console.error('Stderr:', err.stderr);
|
|
82
|
+
}
|
|
83
|
+
if (err.cause) {
|
|
84
|
+
console.error('Cause:', err.cause);
|
|
85
|
+
}
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Estimate generation time and cost without making API calls
|
|
91
|
+
*/
|
|
92
|
+
async estimateGeneration(options) {
|
|
93
|
+
// Prepare repository (clone if needed)
|
|
94
|
+
const repoPath = await this.prepareRepository(options.repoUrl, options.accessToken);
|
|
95
|
+
// Discover files
|
|
96
|
+
const { glob } = await import('glob');
|
|
97
|
+
const INDEXABLE_EXTENSIONS = [
|
|
98
|
+
'.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs',
|
|
99
|
+
'.py', '.pyx', '.go', '.rs',
|
|
100
|
+
'.java', '.kt', '.scala', '.rb', '.php',
|
|
101
|
+
'.c', '.cpp', '.h', '.hpp', '.cs', '.swift',
|
|
102
|
+
'.vue', '.svelte', '.json', '.yaml', '.yml', '.toml',
|
|
103
|
+
'.md', '.mdx'
|
|
104
|
+
];
|
|
105
|
+
const EXCLUDE_PATTERNS = [
|
|
106
|
+
'**/node_modules/**', '**/.git/**', '**/dist/**',
|
|
107
|
+
'**/build/**', '**/.next/**', '**/coverage/**',
|
|
108
|
+
'**/__pycache__/**', '**/venv/**', '**/.venv/**',
|
|
109
|
+
'**/vendor/**', '**/*.min.js', '**/*.bundle.js',
|
|
110
|
+
'**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml'
|
|
111
|
+
];
|
|
112
|
+
const files = [];
|
|
113
|
+
const byExtension = {};
|
|
114
|
+
const fileSizes = [];
|
|
115
|
+
for (const ext of INDEXABLE_EXTENSIONS) {
|
|
116
|
+
const matches = await glob(`**/*${ext}`, {
|
|
117
|
+
cwd: repoPath,
|
|
118
|
+
ignore: EXCLUDE_PATTERNS,
|
|
119
|
+
absolute: false
|
|
120
|
+
});
|
|
121
|
+
byExtension[ext] = matches.length;
|
|
122
|
+
files.push(...matches);
|
|
123
|
+
}
|
|
124
|
+
// Remove duplicates and gather sizes
|
|
125
|
+
const uniqueFiles = [...new Set(files)];
|
|
126
|
+
let totalSize = 0;
|
|
127
|
+
for (const file of uniqueFiles) {
|
|
128
|
+
try {
|
|
129
|
+
const fullPath = path.join(repoPath, file);
|
|
130
|
+
const stats = fs.statSync(fullPath);
|
|
131
|
+
totalSize += stats.size;
|
|
132
|
+
fileSizes.push({ path: file, size: stats.size });
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Skip files we can't read
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Sort by size and get largest
|
|
139
|
+
fileSizes.sort((a, b) => b.size - a.size);
|
|
140
|
+
const largestFiles = fileSizes.slice(0, 10);
|
|
141
|
+
// Estimate chunks (avg ~1500 chars per chunk)
|
|
142
|
+
const avgChunkSize = 1500;
|
|
143
|
+
const estimatedChunks = Math.ceil(totalSize / avgChunkSize);
|
|
144
|
+
// Estimate tokens (~4 chars per token for code)
|
|
145
|
+
const charsPerToken = 4;
|
|
146
|
+
const tokensPerChunk = avgChunkSize / charsPerToken;
|
|
147
|
+
const estimatedTokens = estimatedChunks * tokensPerChunk;
|
|
148
|
+
// Estimate API costs (Claude Sonnet pricing as of 2024)
|
|
149
|
+
// Input: $3 per 1M tokens, Output: $15 per 1M tokens
|
|
150
|
+
// Wiki generation typically reads chunks and generates docs
|
|
151
|
+
const inputTokensEstimate = estimatedTokens * 2; // Chunks read + context
|
|
152
|
+
const outputTokensEstimate = estimatedTokens * 0.5; // Generated docs
|
|
153
|
+
const inputCost = (inputTokensEstimate / 1_000_000) * 3;
|
|
154
|
+
const outputCost = (outputTokensEstimate / 1_000_000) * 15;
|
|
155
|
+
// Estimate time
|
|
156
|
+
// Indexing: ~100 files/min for embedding generation
|
|
157
|
+
// Generation: ~2 wiki pages/min with API calls
|
|
158
|
+
const indexingMinutes = uniqueFiles.length / 100;
|
|
159
|
+
const estimatedPages = Math.ceil(uniqueFiles.length / 10); // ~1 page per 10 source files
|
|
160
|
+
const generationMinutes = estimatedPages * 0.5;
|
|
161
|
+
return {
|
|
162
|
+
files: uniqueFiles.length,
|
|
163
|
+
estimatedChunks,
|
|
164
|
+
estimatedTokens: Math.round(estimatedTokens),
|
|
165
|
+
estimatedCost: {
|
|
166
|
+
input: Math.round(inputCost * 100) / 100,
|
|
167
|
+
output: Math.round(outputCost * 100) / 100,
|
|
168
|
+
total: Math.round((inputCost + outputCost) * 100) / 100
|
|
169
|
+
},
|
|
170
|
+
estimatedTime: {
|
|
171
|
+
indexingMinutes: Math.round(indexingMinutes * 10) / 10,
|
|
172
|
+
generationMinutes: Math.round(generationMinutes * 10) / 10,
|
|
173
|
+
totalMinutes: Math.round((indexingMinutes + generationMinutes) * 10) / 10
|
|
174
|
+
},
|
|
175
|
+
breakdown: {
|
|
176
|
+
byExtension: Object.fromEntries(Object.entries(byExtension).filter(([, count]) => count > 0)),
|
|
177
|
+
largestFiles
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Clone or access repository
|
|
183
|
+
*/
|
|
184
|
+
async prepareRepository(repoUrl, accessToken) {
|
|
185
|
+
// Check if it's a local path
|
|
186
|
+
if (fs.existsSync(repoUrl)) {
|
|
187
|
+
return path.resolve(repoUrl);
|
|
188
|
+
}
|
|
189
|
+
// Clone remote repository
|
|
190
|
+
const tempDir = path.join(process.cwd(), '.ted-mosby-repos');
|
|
191
|
+
if (!fs.existsSync(tempDir)) {
|
|
192
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
193
|
+
}
|
|
194
|
+
// Extract repo name from URL
|
|
195
|
+
const repoName = repoUrl.split('/').pop()?.replace('.git', '') || 'repo';
|
|
196
|
+
const clonePath = path.join(tempDir, repoName);
|
|
197
|
+
// If already cloned, pull latest
|
|
198
|
+
if (fs.existsSync(clonePath)) {
|
|
199
|
+
const git = simpleGit(clonePath);
|
|
200
|
+
await git.pull();
|
|
201
|
+
return clonePath;
|
|
202
|
+
}
|
|
203
|
+
// Clone with auth if token provided
|
|
204
|
+
let cloneUrl = repoUrl;
|
|
205
|
+
if (accessToken && repoUrl.includes('github.com')) {
|
|
206
|
+
cloneUrl = repoUrl.replace('https://', `https://${accessToken}@`);
|
|
207
|
+
}
|
|
208
|
+
const git = simpleGit();
|
|
209
|
+
await git.clone(cloneUrl, clonePath, ['--depth', '1']);
|
|
210
|
+
return clonePath;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Build agent options with MCP servers
|
|
214
|
+
*/
|
|
215
|
+
buildAgentOptions(wikiOptions) {
|
|
216
|
+
return {
|
|
217
|
+
model: wikiOptions.model || 'claude-sonnet-4-20250514',
|
|
218
|
+
cwd: this.repoPath,
|
|
219
|
+
systemPrompt: WIKI_SYSTEM_PROMPT,
|
|
220
|
+
mcpServers: {
|
|
221
|
+
// External MCP servers
|
|
222
|
+
'filesystem': {
|
|
223
|
+
command: 'npx',
|
|
224
|
+
args: ['-y', '@modelcontextprotocol/server-filesystem', this.repoPath]
|
|
225
|
+
},
|
|
226
|
+
// Custom in-process tools - pass SDK server directly
|
|
227
|
+
'tedmosby': this.customServer
|
|
228
|
+
},
|
|
229
|
+
allowedTools: [
|
|
230
|
+
// Filesystem tools
|
|
231
|
+
'mcp__filesystem__read_file',
|
|
232
|
+
'mcp__filesystem__read_multiple_files',
|
|
233
|
+
'mcp__filesystem__write_file',
|
|
234
|
+
'mcp__filesystem__list_directory',
|
|
235
|
+
'mcp__filesystem__directory_tree',
|
|
236
|
+
'mcp__filesystem__search_files',
|
|
237
|
+
'mcp__filesystem__get_file_info',
|
|
238
|
+
// Custom tedmosby tools
|
|
239
|
+
'mcp__tedmosby__search_codebase',
|
|
240
|
+
'mcp__tedmosby__write_wiki_page',
|
|
241
|
+
'mcp__tedmosby__analyze_code_structure'
|
|
242
|
+
],
|
|
243
|
+
maxTurns: 200,
|
|
244
|
+
permissionMode: 'acceptEdits',
|
|
245
|
+
includePartialMessages: true,
|
|
246
|
+
// Capture stderr from Claude Code subprocess
|
|
247
|
+
stderr: (data) => {
|
|
248
|
+
console.error('[Claude Code stderr]:', data);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Build the generation prompt
|
|
254
|
+
*/
|
|
255
|
+
buildGenerationPrompt(options) {
|
|
256
|
+
const configNote = options.configPath && fs.existsSync(options.configPath)
|
|
257
|
+
? `\n\nConfiguration file provided at: ${options.configPath}\nPlease read it first to understand the wiki structure requirements.`
|
|
258
|
+
: '';
|
|
259
|
+
return `Generate a comprehensive architectural documentation wiki for this repository.
|
|
260
|
+
|
|
261
|
+
**Repository:** ${options.repoUrl}
|
|
262
|
+
**Output Directory:** ${this.outputDir}
|
|
263
|
+
${options.targetPath ? `**Focus Area:** ${options.targetPath}` : ''}
|
|
264
|
+
${configNote}
|
|
265
|
+
|
|
266
|
+
Begin by:
|
|
267
|
+
1. Scanning the repository structure to understand the codebase layout
|
|
268
|
+
2. Identifying the key architectural components and patterns
|
|
269
|
+
3. Planning the wiki structure
|
|
270
|
+
4. Generating documentation with source code traceability
|
|
271
|
+
|
|
272
|
+
Remember: Every architectural concept MUST include file:line references to the source code.`;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Create custom MCP tool server for wiki-specific operations
|
|
276
|
+
*/
|
|
277
|
+
createCustomToolServer() {
|
|
278
|
+
const tools = [];
|
|
279
|
+
// Tool 1: search_codebase - RAG-powered semantic search
|
|
280
|
+
tools.push(tool('search_codebase', 'Semantic search over the codebase using embeddings. Returns relevant code snippets with file paths and line numbers. Use this to find code related to architectural concepts you are documenting.', {
|
|
281
|
+
query: z.string().describe('Natural language search query (e.g., "authentication handling", "database connection")'),
|
|
282
|
+
maxResults: z.number().min(1).max(20).optional().default(10).describe('Maximum number of results to return'),
|
|
283
|
+
fileTypes: z.array(z.string()).optional().describe('Filter by file extensions (e.g., [".ts", ".js"])'),
|
|
284
|
+
excludeTests: z.boolean().optional().default(true).describe('Exclude test files from results')
|
|
285
|
+
}, async (args) => {
|
|
286
|
+
if (!this.ragSystem) {
|
|
287
|
+
return {
|
|
288
|
+
content: [{
|
|
289
|
+
type: 'text',
|
|
290
|
+
text: 'Error: RAG system not initialized. Repository must be indexed first.'
|
|
291
|
+
}]
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
const results = await this.ragSystem.search(args.query, {
|
|
296
|
+
maxResults: args.maxResults || 10,
|
|
297
|
+
fileTypes: args.fileTypes,
|
|
298
|
+
excludeTests: args.excludeTests ?? true
|
|
299
|
+
});
|
|
300
|
+
const formatted = results.map((r, i) => `### Result ${i + 1} (score: ${r.score.toFixed(3)})\n` +
|
|
301
|
+
`**Source:** \`${r.filePath}:${r.startLine}-${r.endLine}\`\n\n` +
|
|
302
|
+
'```' + (r.language || '') + '\n' + r.content + '\n```').join('\n\n');
|
|
303
|
+
return {
|
|
304
|
+
content: [{
|
|
305
|
+
type: 'text',
|
|
306
|
+
text: results.length > 0
|
|
307
|
+
? `Found ${results.length} relevant code snippets:\n\n${formatted}`
|
|
308
|
+
: 'No relevant code found for this query.'
|
|
309
|
+
}]
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
return {
|
|
314
|
+
content: [{
|
|
315
|
+
type: 'text',
|
|
316
|
+
text: `Search error: ${error instanceof Error ? error.message : String(error)}`
|
|
317
|
+
}]
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
}));
|
|
321
|
+
// Tool 2: write_wiki_page - Write wiki documentation with validation
|
|
322
|
+
tools.push(tool('write_wiki_page', 'Write a wiki documentation page to the output directory. Validates markdown structure and adds frontmatter metadata.', {
|
|
323
|
+
pagePath: z.string().describe('Path relative to wiki root (e.g., "architecture/overview.md", "components/auth/index.md")'),
|
|
324
|
+
title: z.string().describe('Page title (used as H1 heading)'),
|
|
325
|
+
content: z.string().describe('Full markdown content (excluding the H1 title, which is added automatically)'),
|
|
326
|
+
frontmatter: z.object({
|
|
327
|
+
description: z.string().optional().describe('Brief page description for metadata'),
|
|
328
|
+
related: z.array(z.string()).optional().describe('Related page paths'),
|
|
329
|
+
sources: z.array(z.string()).optional().describe('Source files referenced in this page')
|
|
330
|
+
}).optional().describe('Page metadata')
|
|
331
|
+
}, async (args) => {
|
|
332
|
+
try {
|
|
333
|
+
const fullPath = path.join(this.outputDir, args.pagePath);
|
|
334
|
+
const dir = path.dirname(fullPath);
|
|
335
|
+
// Create directory if needed
|
|
336
|
+
if (!fs.existsSync(dir)) {
|
|
337
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
338
|
+
}
|
|
339
|
+
// Build content with frontmatter
|
|
340
|
+
const frontmatterData = {
|
|
341
|
+
title: args.title,
|
|
342
|
+
generated: new Date().toISOString(),
|
|
343
|
+
...args.frontmatter
|
|
344
|
+
};
|
|
345
|
+
const fullContent = matter.stringify(`# ${args.title}\n\n${args.content}`, frontmatterData);
|
|
346
|
+
// Write file
|
|
347
|
+
fs.writeFileSync(fullPath, fullContent, 'utf-8');
|
|
348
|
+
// Validate links and structure
|
|
349
|
+
const warnings = [];
|
|
350
|
+
// Check for broken internal links
|
|
351
|
+
const linkMatches = args.content.matchAll(/\[([^\]]+)\]\(([^)]+)\)/g);
|
|
352
|
+
for (const match of linkMatches) {
|
|
353
|
+
const linkPath = match[2];
|
|
354
|
+
if (linkPath.startsWith('./') || linkPath.startsWith('../')) {
|
|
355
|
+
const resolvedPath = path.resolve(dir, linkPath.split('#')[0]);
|
|
356
|
+
if (!fs.existsSync(resolvedPath) && !resolvedPath.endsWith('.md')) {
|
|
357
|
+
warnings.push(`Potential broken link: ${linkPath}`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
// Check for source traceability
|
|
362
|
+
const hasSourceRefs = args.content.includes('**Source:**') ||
|
|
363
|
+
args.content.includes('`src/') ||
|
|
364
|
+
args.content.includes('`lib/');
|
|
365
|
+
if (!hasSourceRefs && args.pagePath !== 'README.md' && args.pagePath !== 'glossary.md') {
|
|
366
|
+
warnings.push('Page may be missing source code references');
|
|
367
|
+
}
|
|
368
|
+
const response = `Successfully wrote wiki page: ${args.pagePath}` +
|
|
369
|
+
(warnings.length > 0 ? `\n\nWarnings:\n${warnings.map(w => `- ${w}`).join('\n')}` : '');
|
|
370
|
+
return {
|
|
371
|
+
content: [{
|
|
372
|
+
type: 'text',
|
|
373
|
+
text: response
|
|
374
|
+
}]
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
return {
|
|
379
|
+
content: [{
|
|
380
|
+
type: 'text',
|
|
381
|
+
text: `Failed to write wiki page: ${error instanceof Error ? error.message : String(error)}`
|
|
382
|
+
}]
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
}));
|
|
386
|
+
// Tool 3: analyze_code_structure - AST analysis for understanding code
|
|
387
|
+
tools.push(tool('analyze_code_structure', 'Analyze the structure of a code file to extract functions, classes, imports, and exports. Useful for understanding the architecture before documenting.', {
|
|
388
|
+
filePath: z.string().describe('Path to the file to analyze (relative to repo root)'),
|
|
389
|
+
analysisType: z.enum(['all', 'functions', 'classes', 'imports', 'exports', 'structure'])
|
|
390
|
+
.default('all')
|
|
391
|
+
.describe('Type of analysis to perform')
|
|
392
|
+
}, async (args) => {
|
|
393
|
+
try {
|
|
394
|
+
const fullPath = path.join(this.repoPath, args.filePath);
|
|
395
|
+
if (!fs.existsSync(fullPath)) {
|
|
396
|
+
return {
|
|
397
|
+
content: [{
|
|
398
|
+
type: 'text',
|
|
399
|
+
text: `File not found: ${args.filePath}`
|
|
400
|
+
}]
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
404
|
+
const lines = content.split('\n');
|
|
405
|
+
const ext = path.extname(args.filePath);
|
|
406
|
+
// Simple regex-based analysis (can be enhanced with tree-sitter later)
|
|
407
|
+
const analysis = {
|
|
408
|
+
functions: [],
|
|
409
|
+
classes: [],
|
|
410
|
+
imports: [],
|
|
411
|
+
exports: []
|
|
412
|
+
};
|
|
413
|
+
// TypeScript/JavaScript analysis
|
|
414
|
+
if (['.ts', '.tsx', '.js', '.jsx'].includes(ext)) {
|
|
415
|
+
lines.forEach((line, idx) => {
|
|
416
|
+
const lineNum = idx + 1;
|
|
417
|
+
// Functions
|
|
418
|
+
const funcMatch = line.match(/(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*(\([^)]*\))/);
|
|
419
|
+
if (funcMatch) {
|
|
420
|
+
analysis.functions.push({
|
|
421
|
+
name: funcMatch[1],
|
|
422
|
+
line: lineNum,
|
|
423
|
+
signature: `${funcMatch[1]}${funcMatch[2]}`
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
// Arrow functions assigned to const
|
|
427
|
+
const arrowMatch = line.match(/(?:export\s+)?const\s+(\w+)\s*=\s*(?:async\s+)?\([^)]*\)\s*(?::\s*[^=]+)?\s*=>/);
|
|
428
|
+
if (arrowMatch) {
|
|
429
|
+
analysis.functions.push({
|
|
430
|
+
name: arrowMatch[1],
|
|
431
|
+
line: lineNum,
|
|
432
|
+
signature: arrowMatch[1]
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
// Classes
|
|
436
|
+
const classMatch = line.match(/(?:export\s+)?class\s+(\w+)/);
|
|
437
|
+
if (classMatch) {
|
|
438
|
+
analysis.classes.push({
|
|
439
|
+
name: classMatch[1],
|
|
440
|
+
line: lineNum,
|
|
441
|
+
methods: []
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
// Imports
|
|
445
|
+
const importMatch = line.match(/import\s+.*\s+from\s+['"]([^'"]+)['"]/);
|
|
446
|
+
if (importMatch) {
|
|
447
|
+
analysis.imports.push({
|
|
448
|
+
module: importMatch[1],
|
|
449
|
+
line: lineNum
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
// Exports
|
|
453
|
+
const exportMatch = line.match(/export\s+(?:default\s+)?(?:class|function|const|let|var|interface|type|enum)\s+(\w+)/);
|
|
454
|
+
if (exportMatch) {
|
|
455
|
+
analysis.exports.push({
|
|
456
|
+
name: exportMatch[1],
|
|
457
|
+
line: lineNum
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
// Python analysis
|
|
463
|
+
if (ext === '.py') {
|
|
464
|
+
lines.forEach((line, idx) => {
|
|
465
|
+
const lineNum = idx + 1;
|
|
466
|
+
const funcMatch = line.match(/^(?:async\s+)?def\s+(\w+)\s*\(([^)]*)\)/);
|
|
467
|
+
if (funcMatch) {
|
|
468
|
+
analysis.functions.push({
|
|
469
|
+
name: funcMatch[1],
|
|
470
|
+
line: lineNum,
|
|
471
|
+
signature: `${funcMatch[1]}(${funcMatch[2]})`
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
const classMatch = line.match(/^class\s+(\w+)/);
|
|
475
|
+
if (classMatch) {
|
|
476
|
+
analysis.classes.push({
|
|
477
|
+
name: classMatch[1],
|
|
478
|
+
line: lineNum,
|
|
479
|
+
methods: []
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
const importMatch = line.match(/^(?:from\s+(\S+)\s+)?import\s+(.+)/);
|
|
483
|
+
if (importMatch) {
|
|
484
|
+
analysis.imports.push({
|
|
485
|
+
module: importMatch[1] || importMatch[2],
|
|
486
|
+
line: lineNum
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
// Format output
|
|
492
|
+
let output = `# Code Analysis: ${args.filePath}\n\n`;
|
|
493
|
+
output += `**Lines of Code:** ${lines.length}\n`;
|
|
494
|
+
output += `**Language:** ${ext.slice(1).toUpperCase()}\n\n`;
|
|
495
|
+
if (args.analysisType === 'all' || args.analysisType === 'structure') {
|
|
496
|
+
output += `## Summary\n`;
|
|
497
|
+
output += `- Functions: ${analysis.functions.length}\n`;
|
|
498
|
+
output += `- Classes: ${analysis.classes.length}\n`;
|
|
499
|
+
output += `- Imports: ${analysis.imports.length}\n`;
|
|
500
|
+
output += `- Exports: ${analysis.exports.length}\n\n`;
|
|
501
|
+
}
|
|
502
|
+
if ((args.analysisType === 'all' || args.analysisType === 'functions') && analysis.functions.length > 0) {
|
|
503
|
+
output += `## Functions\n`;
|
|
504
|
+
analysis.functions.forEach(f => {
|
|
505
|
+
output += `- \`${f.signature}\` (line ${f.line})\n`;
|
|
506
|
+
});
|
|
507
|
+
output += '\n';
|
|
508
|
+
}
|
|
509
|
+
if ((args.analysisType === 'all' || args.analysisType === 'classes') && analysis.classes.length > 0) {
|
|
510
|
+
output += `## Classes\n`;
|
|
511
|
+
analysis.classes.forEach(c => {
|
|
512
|
+
output += `- \`${c.name}\` (line ${c.line})\n`;
|
|
513
|
+
});
|
|
514
|
+
output += '\n';
|
|
515
|
+
}
|
|
516
|
+
if ((args.analysisType === 'all' || args.analysisType === 'imports') && analysis.imports.length > 0) {
|
|
517
|
+
output += `## Imports\n`;
|
|
518
|
+
analysis.imports.forEach(i => {
|
|
519
|
+
output += `- \`${i.module}\` (line ${i.line})\n`;
|
|
520
|
+
});
|
|
521
|
+
output += '\n';
|
|
522
|
+
}
|
|
523
|
+
if ((args.analysisType === 'all' || args.analysisType === 'exports') && analysis.exports.length > 0) {
|
|
524
|
+
output += `## Exports\n`;
|
|
525
|
+
analysis.exports.forEach(e => {
|
|
526
|
+
output += `- \`${e.name}\` (line ${e.line})\n`;
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
return {
|
|
530
|
+
content: [{
|
|
531
|
+
type: 'text',
|
|
532
|
+
text: output
|
|
533
|
+
}]
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
return {
|
|
538
|
+
content: [{
|
|
539
|
+
type: 'text',
|
|
540
|
+
text: `Analysis error: ${error instanceof Error ? error.message : String(error)}`
|
|
541
|
+
}]
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
}));
|
|
545
|
+
return createSdkMcpServer({
|
|
546
|
+
name: 'tedmosby',
|
|
547
|
+
version: '1.0.0',
|
|
548
|
+
tools
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
//# sourceMappingURL=wiki-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wiki-agent.js","sourceRoot":"","sources":["../src/wiki-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAClD,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AA+C9D,MAAM,OAAO,sBAAsB;IACzB,MAAM,CAAkB;IACxB,iBAAiB,CAAoB;IACrC,gBAAgB,CAAmB;IACnC,YAAY,CAAwC;IACpD,SA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C,YAAY,KAAK,KAAK,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACpG,MAAM,IAAI,cAAc,CAAC;oBACzB,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;wBAC3B,MAAM,IAAI,OAAO,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,IAAI,KAAK,CAAC;oBACjD,CAAC,CAAC,CAAC;gBACL,CAAC;gBAED,OAAO;oBACL,OAAO,EAAE,CAAC;4BACR,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,MAAM;yBACb,CAAC;iBACH,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO;oBACL,OAAO,EAAE,CAAC;4BACR,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,mBAAmB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;yBAClF,CAAC;iBACH,CAAC;YACJ,CAAC;QACH,CAAC,CACF,CACF,CAAC;QAEF,OAAO,kBAAkB,CAAC;YACxB,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,OAAO;YAChB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PermissionManager } from './permissions.js';
|
|
2
|
+
export interface WorkflowStep {
|
|
3
|
+
name: string;
|
|
4
|
+
tool?: string;
|
|
5
|
+
prompt?: string;
|
|
6
|
+
input?: any;
|
|
7
|
+
forEach?: string;
|
|
8
|
+
output?: string;
|
|
9
|
+
retry?: {
|
|
10
|
+
maxAttempts: number;
|
|
11
|
+
backoff: 'linear' | 'exponential';
|
|
12
|
+
retryOn?: string[];
|
|
13
|
+
};
|
|
14
|
+
onError?: 'stop' | 'continue' | 'skip';
|
|
15
|
+
}
|
|
16
|
+
export interface WorkflowDefinition {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
arguments: Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
type: string;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
default?: any;
|
|
24
|
+
description: string;
|
|
25
|
+
}>;
|
|
26
|
+
workflow: {
|
|
27
|
+
steps: WorkflowStep[];
|
|
28
|
+
};
|
|
29
|
+
permissions: string[];
|
|
30
|
+
requiresApproval?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface WorkflowContext {
|
|
33
|
+
variables: Map<string, any>;
|
|
34
|
+
agent: any;
|
|
35
|
+
permissionManager: PermissionManager;
|
|
36
|
+
}
|
|
37
|
+
export declare class WorkflowExecutor {
|
|
38
|
+
private permissionManager;
|
|
39
|
+
constructor(permissionManager: PermissionManager);
|
|
40
|
+
execute(workflow: WorkflowDefinition, args: Record<string, any>, context: WorkflowContext): Promise<any>;
|
|
41
|
+
executeStep(step: WorkflowStep, context: WorkflowContext): Promise<any>;
|
|
42
|
+
executeStepInternal(step: WorkflowStep, context: WorkflowContext): Promise<any>;
|
|
43
|
+
callTool(toolName: string, input: any, agent: any): Promise<any>;
|
|
44
|
+
queryAgent(prompt: string, agent: any): Promise<any>;
|
|
45
|
+
resolvePath(pattern: string, context: WorkflowContext): Promise<string[]>;
|
|
46
|
+
resolveTemplates(template: any, context: WorkflowContext): any;
|
|
47
|
+
extractVariableName(output: string): string;
|
|
48
|
+
shouldRetry(error: any, retry?: WorkflowStep['retry']): boolean;
|
|
49
|
+
calculateBackoff(attempt: number, backoff?: 'linear' | 'exponential'): number;
|
|
50
|
+
sleep(ms: number): Promise<void>;
|
|
51
|
+
loadWorkflow(commandName: string): Promise<WorkflowDefinition>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=workflows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../src/workfl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