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,119 @@
|
|
|
1
|
+
import { readFile, writeFile, access, readdir, stat } from 'fs/promises';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { glob } from 'glob';
|
|
4
|
+
export class FileOperations {
|
|
5
|
+
permissionManager;
|
|
6
|
+
baseDir;
|
|
7
|
+
constructor(permissionManager, baseDir = process.cwd()) {
|
|
8
|
+
this.permissionManager = permissionManager;
|
|
9
|
+
this.baseDir = resolve(baseDir);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Validates that a path is within the allowed base directory.
|
|
13
|
+
* Prevents directory traversal attacks and access outside sandbox.
|
|
14
|
+
*/
|
|
15
|
+
validatePath(filePath) {
|
|
16
|
+
const absolutePath = resolve(this.baseDir, filePath);
|
|
17
|
+
// Ensure path is within baseDir (prevent directory traversal)
|
|
18
|
+
if (!absolutePath.startsWith(this.baseDir + '/') && absolutePath !== this.baseDir) {
|
|
19
|
+
throw new Error(`Access denied: Path "${filePath}" is outside the allowed directory "${this.baseDir}"`);
|
|
20
|
+
}
|
|
21
|
+
return absolutePath;
|
|
22
|
+
}
|
|
23
|
+
async readFile(filePath) {
|
|
24
|
+
try {
|
|
25
|
+
const safePath = this.validatePath(filePath);
|
|
26
|
+
return await readFile(safePath, 'utf-8');
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error instanceof Error && error.message.startsWith('Access denied:')) {
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`Failed to read file ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async writeFile(filePath, content) {
|
|
36
|
+
// Validate path first (before permission check)
|
|
37
|
+
const safePath = this.validatePath(filePath);
|
|
38
|
+
// Request permission before writing
|
|
39
|
+
const permission = await this.permissionManager.requestPermission({
|
|
40
|
+
action: 'write_file',
|
|
41
|
+
resource: filePath,
|
|
42
|
+
details: `Writing ${content.length} characters`
|
|
43
|
+
});
|
|
44
|
+
if (!permission.allowed) {
|
|
45
|
+
throw new Error(`Permission denied: Cannot write to ${filePath}`);
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
await writeFile(safePath, content, 'utf-8');
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new Error(`Failed to write file ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async fileExists(filePath) {
|
|
55
|
+
try {
|
|
56
|
+
const safePath = this.validatePath(filePath);
|
|
57
|
+
await access(safePath);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error instanceof Error && error.message.startsWith('Access denied:')) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async listFiles(dirPath) {
|
|
68
|
+
try {
|
|
69
|
+
const safePath = this.validatePath(dirPath);
|
|
70
|
+
const entries = await readdir(safePath, { withFileTypes: true });
|
|
71
|
+
return entries
|
|
72
|
+
.filter(entry => entry.isFile())
|
|
73
|
+
.map(entry => entry.name);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (error instanceof Error && error.message.startsWith('Access denied:')) {
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
throw new Error(`Failed to list files in ${dirPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async findFiles(pattern, cwd) {
|
|
83
|
+
// Block directory traversal patterns
|
|
84
|
+
if (pattern.includes('..')) {
|
|
85
|
+
throw new Error('Access denied: Path traversal patterns (..) not allowed');
|
|
86
|
+
}
|
|
87
|
+
// Always use baseDir as root, ignore cwd parameter for security
|
|
88
|
+
try {
|
|
89
|
+
const results = await glob(pattern, {
|
|
90
|
+
cwd: this.baseDir,
|
|
91
|
+
absolute: true,
|
|
92
|
+
ignore: ['node_modules/**', '.git/**']
|
|
93
|
+
});
|
|
94
|
+
// Double-check all results are within baseDir
|
|
95
|
+
return results.filter(p => p.startsWith(this.baseDir + '/') || p === this.baseDir);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throw new Error(`Failed to find files matching ${pattern}: ${error instanceof Error ? error.message : String(error)}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async getFileStats(filePath) {
|
|
102
|
+
try {
|
|
103
|
+
const safePath = this.validatePath(filePath);
|
|
104
|
+
const stats = await stat(safePath);
|
|
105
|
+
return {
|
|
106
|
+
size: stats.size,
|
|
107
|
+
modified: stats.mtime,
|
|
108
|
+
isDirectory: stats.isDirectory()
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
if (error instanceof Error && error.message.startsWith('Access denied:')) {
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
throw new Error(`Failed to get stats for ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=file-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-operations.js","sourceRoot":"","sources":["../../src/tools/file-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAA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AAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,CAAC;QACrF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QACxH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,QAAgB;QACjC,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;YAC7C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAA;YAClC,OAAO;gBACL,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,QAAQ,EAAE,KAAK,CAAC,KAAK;gBACrB,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE;aACjC,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;gBACzE,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,2BAA2B,QAAQ,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QACnH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PermissionManager } from '../permissions.js';
|
|
2
|
+
export interface SearchResult {
|
|
3
|
+
title: string;
|
|
4
|
+
url: string;
|
|
5
|
+
snippet: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class WebTools {
|
|
8
|
+
private readonly userAgent;
|
|
9
|
+
private permissionManager;
|
|
10
|
+
constructor(permissionManager: PermissionManager);
|
|
11
|
+
fetch(url: string): Promise<string>;
|
|
12
|
+
fetchText(url: string): Promise<string>;
|
|
13
|
+
search(query: string, maxResults?: number): Promise<string[]>;
|
|
14
|
+
extractLinks(html: string, baseUrl?: string): string[];
|
|
15
|
+
extractMetadata(html: string): Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=web-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-tools.d.ts","sourceRoot":"","sources":["../../src/tools/web-tools.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8H;IACxJ,OAAO,CAAC,iBAAiB,CAAoB;gBAEjC,iBAAiB,EAAE,iBAAiB;IAI1C,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAyBnC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAevC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAyCvE,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAsBtD,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAuBtD"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import * as cheerio from 'cheerio';
|
|
3
|
+
export class WebTools {
|
|
4
|
+
userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36';
|
|
5
|
+
permissionManager;
|
|
6
|
+
constructor(permissionManager) {
|
|
7
|
+
this.permissionManager = permissionManager;
|
|
8
|
+
}
|
|
9
|
+
async fetch(url) {
|
|
10
|
+
// Request permission before making network request
|
|
11
|
+
const permission = await this.permissionManager.requestPermission({
|
|
12
|
+
action: 'network_request',
|
|
13
|
+
resource: url,
|
|
14
|
+
details: 'Fetching web page content'
|
|
15
|
+
});
|
|
16
|
+
if (!permission.allowed) {
|
|
17
|
+
throw new Error(`Permission denied: Cannot fetch ${url}`);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const response = await axios.get(url, {
|
|
21
|
+
headers: {
|
|
22
|
+
'User-Agent': this.userAgent
|
|
23
|
+
},
|
|
24
|
+
timeout: 10000
|
|
25
|
+
});
|
|
26
|
+
return response.data;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new Error(`Failed to fetch ${url}: ${error instanceof Error ? error.message : String(error)}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async fetchText(url) {
|
|
33
|
+
try {
|
|
34
|
+
const html = await this.fetch(url);
|
|
35
|
+
const $ = cheerio.load(html);
|
|
36
|
+
// Remove script and style elements
|
|
37
|
+
$('script, style').remove();
|
|
38
|
+
// Get text content
|
|
39
|
+
return $('body').text().replace(/\s+/g, ' ').trim();
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new Error(`Failed to extract text from ${url}: ${error instanceof Error ? error.message : String(error)}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async search(query, maxResults = 10) {
|
|
46
|
+
try {
|
|
47
|
+
// Use DuckDuckGo HTML search (no API key required)
|
|
48
|
+
const searchUrl = `https://html.duckduckgo.com/html/?q=${encodeURIComponent(query)}`;
|
|
49
|
+
const response = await axios.get(searchUrl, {
|
|
50
|
+
headers: {
|
|
51
|
+
'User-Agent': 'Mozilla/5.0 (compatible; ResearchBot/1.0)'
|
|
52
|
+
},
|
|
53
|
+
timeout: 10000
|
|
54
|
+
});
|
|
55
|
+
const $ = cheerio.load(response.data);
|
|
56
|
+
const results = [];
|
|
57
|
+
// Extract search results from DuckDuckGo HTML
|
|
58
|
+
$('.result').each((index, element) => {
|
|
59
|
+
if (index >= maxResults)
|
|
60
|
+
return false;
|
|
61
|
+
const titleEl = $(element).find('.result__a');
|
|
62
|
+
const snippetEl = $(element).find('.result__snippet');
|
|
63
|
+
const url = titleEl.attr('href');
|
|
64
|
+
const title = titleEl.text().trim();
|
|
65
|
+
const snippet = snippetEl.text().trim();
|
|
66
|
+
if (title && snippet) {
|
|
67
|
+
results.push(`**${title}**\n${snippet}\n${url || ''}`);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (results.length === 0) {
|
|
71
|
+
return [`No results found for: "${query}"`];
|
|
72
|
+
}
|
|
73
|
+
return results;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.error('Web search failed:', error instanceof Error ? error.message : String(error));
|
|
77
|
+
return [`Search failed: ${error instanceof Error ? error.message : 'Unknown error'}. Try using web_fetch with a specific URL instead.`];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
extractLinks(html, baseUrl) {
|
|
81
|
+
try {
|
|
82
|
+
const $ = cheerio.load(html);
|
|
83
|
+
const links = [];
|
|
84
|
+
$('a[href]').each((_, element) => {
|
|
85
|
+
const href = $(element).attr('href');
|
|
86
|
+
if (href) {
|
|
87
|
+
if (baseUrl && href.startsWith('/')) {
|
|
88
|
+
links.push(new URL(href, baseUrl).toString());
|
|
89
|
+
}
|
|
90
|
+
else if (href.startsWith('http')) {
|
|
91
|
+
links.push(href);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return links;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
throw new Error(`Failed to extract links: ${error instanceof Error ? error.message : String(error)}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
extractMetadata(html) {
|
|
102
|
+
try {
|
|
103
|
+
const $ = cheerio.load(html);
|
|
104
|
+
const metadata = {};
|
|
105
|
+
// Extract title
|
|
106
|
+
metadata.title = $('title').text().trim();
|
|
107
|
+
// Extract meta tags
|
|
108
|
+
$('meta').each((_, element) => {
|
|
109
|
+
const name = $(element).attr('name') || $(element).attr('property');
|
|
110
|
+
const content = $(element).attr('content');
|
|
111
|
+
if (name && content) {
|
|
112
|
+
metadata[name] = content;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return metadata;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
throw new Error(`Failed to extract metadata: ${error instanceof Error ? error.message : String(error)}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=web-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-tools.js","sourceRoot":"","sources":["../../src/tools/web-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AASlC,MAAM,OAAO,QAAQ;IACF,SAAS,GAAG,2HAA2H,CAAA;IAChJ,iBAAiB,CAAoB;IAE7C,YAAY,iBAAoC;QAC9C,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAW;QACrB,mDAAmD;QACnD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC;YAChE,MAAM,EAAE,iBAAiB;YACzB,QAAQ,EAAE,GAAG;YACb,OAAO,EAAE,2BAA2B;SACrC,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU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CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QACvG,CAAC;IACH,CAAC;IAED,eAAe,CAAC,IAAY;QAC1B,IAAI,CAAC;YACH,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAC5B,MAAM,QAAQ,GAA2B,EAAE,CAAA;YAE3C,gBAAgB;YAChB,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAA;YAEzC,oBAAoB;YACpB,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE;gBAC5B,MAAM,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;gBACnE,MAAM,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;gBAE1C,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC;oBACpB,QAAQ,CAAC,IAAI,CAAC,GAAG,OAAO,CAAA;gBAC1B,CAAC;YACH,CAAC,CAAC,CAAA;YAEF,OAAO,QAAQ,CAAA;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,+BAA+B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC1G,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { PermissionManager } from './permissions.js';
|
|
2
|
+
export interface WikiGenerationOptions {
|
|
3
|
+
repoUrl: string;
|
|
4
|
+
outputDir: string;
|
|
5
|
+
configPath?: string;
|
|
6
|
+
accessToken?: string;
|
|
7
|
+
model?: string;
|
|
8
|
+
targetPath?: string;
|
|
9
|
+
forceRegenerate?: boolean;
|
|
10
|
+
verbose?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface WikiAgentConfig {
|
|
13
|
+
verbose?: boolean;
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
permissionManager?: PermissionManager;
|
|
16
|
+
workingDir?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ProgressEvent {
|
|
19
|
+
type: 'phase' | 'step' | 'file' | 'complete' | 'error';
|
|
20
|
+
message: string;
|
|
21
|
+
detail?: string;
|
|
22
|
+
progress?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface GenerationEstimate {
|
|
25
|
+
files: number;
|
|
26
|
+
estimatedChunks: number;
|
|
27
|
+
estimatedTokens: number;
|
|
28
|
+
estimatedCost: {
|
|
29
|
+
input: number;
|
|
30
|
+
output: number;
|
|
31
|
+
total: number;
|
|
32
|
+
};
|
|
33
|
+
estimatedTime: {
|
|
34
|
+
indexingMinutes: number;
|
|
35
|
+
generationMinutes: number;
|
|
36
|
+
totalMinutes: number;
|
|
37
|
+
};
|
|
38
|
+
breakdown: {
|
|
39
|
+
byExtension: Record<string, number>;
|
|
40
|
+
largestFiles: Array<{
|
|
41
|
+
path: string;
|
|
42
|
+
size: number;
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export declare class ArchitecturalWikiAgent {
|
|
47
|
+
private config;
|
|
48
|
+
private permissionManager;
|
|
49
|
+
private mcpConfigManager;
|
|
50
|
+
private customServer;
|
|
51
|
+
private ragSystem;
|
|
52
|
+
private repoPath;
|
|
53
|
+
private outputDir;
|
|
54
|
+
private sessionId?;
|
|
55
|
+
constructor(config?: WikiAgentConfig);
|
|
56
|
+
/**
|
|
57
|
+
* Generate wiki documentation for a repository
|
|
58
|
+
*/
|
|
59
|
+
generateWiki(options: WikiGenerationOptions): AsyncGenerator<ProgressEvent | any>;
|
|
60
|
+
/**
|
|
61
|
+
* Estimate generation time and cost without making API calls
|
|
62
|
+
*/
|
|
63
|
+
estimateGeneration(options: WikiGenerationOptions): Promise<GenerationEstimate>;
|
|
64
|
+
/**
|
|
65
|
+
* Clone or access repository
|
|
66
|
+
*/
|
|
67
|
+
private prepareRepository;
|
|
68
|
+
/**
|
|
69
|
+
* Build agent options with MCP servers
|
|
70
|
+
*/
|
|
71
|
+
private buildAgentOptions;
|
|
72
|
+
/**
|
|
73
|
+
* Build the generation prompt
|
|
74
|
+
*/
|
|
75
|
+
private buildGenerationPrompt;
|
|
76
|
+
/**
|
|
77
|
+
* Create custom MCP tool server for wiki-specific operations
|
|
78
|
+
*/
|
|
79
|
+
private createCustomToolServer;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=wiki-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wiki-agent.d.ts","sourceRoot":"","sources":["../src/wiki-agent.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAKrD,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG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