BREAKING CHANGE(aidoc): migrate agent orchestration to new runAgent API and filesystem tools; refactor model handling and update README and tests
This commit is contained in:
@@ -28,55 +28,31 @@ export class Readme {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
// Use DualAgentOrchestrator with filesystem tool for agent-driven exploration
|
||||
const readmeOrchestrator = new plugins.smartagent.DualAgentOrchestrator({
|
||||
smartAiInstance: this.aiDocsRef.smartAiInstance,
|
||||
defaultProvider: 'openai',
|
||||
maxIterations: 25,
|
||||
maxResultChars: 15000, // Limit tool output to prevent token explosion
|
||||
maxHistoryMessages: 20, // Limit history window
|
||||
logPrefix: '[README]',
|
||||
onProgress: (event) => logger.log(event.logLevel, event.logMessage),
|
||||
guardianPolicyPrompt: `
|
||||
You validate README generation tool calls and outputs.
|
||||
// Use runAgent with filesystem tool for agent-driven exploration
|
||||
const fsTools = plugins.smartagentTools.filesystemTool({ rootDir: this.projectDir });
|
||||
|
||||
APPROVE tool calls for:
|
||||
- Reading any files within the project directory (package.json, ts/*.ts, readme.md, etc.)
|
||||
- Using tree to see project structure
|
||||
- Using glob to find source files
|
||||
- Listing directory contents
|
||||
|
||||
REJECT tool calls for:
|
||||
- Reading files outside the project directory
|
||||
- Writing, deleting, or modifying any files
|
||||
- Any destructive operations
|
||||
|
||||
For final README output, APPROVE if:
|
||||
- README follows proper markdown format
|
||||
- Contains Install and Usage sections
|
||||
- Code examples are correct TypeScript/ESM syntax
|
||||
- Documentation is comprehensive and helpful
|
||||
|
||||
REJECT final output if:
|
||||
- README is incomplete or poorly formatted
|
||||
- Contains licensing information (added separately)
|
||||
- Uses CommonJS syntax instead of ESM
|
||||
- Contains "in conclusion" or similar filler
|
||||
`,
|
||||
});
|
||||
|
||||
// Register scoped filesystem tool for agent exploration
|
||||
readmeOrchestrator.registerScopedFilesystemTool(this.projectDir);
|
||||
|
||||
await readmeOrchestrator.start();
|
||||
|
||||
const readmeTaskPrompt = `
|
||||
const readmeSystemPrompt = `
|
||||
You create markdown READMEs for npm projects. You only output the markdown readme.
|
||||
|
||||
You have access to filesystem tools to explore the project. Use them to understand the codebase.
|
||||
|
||||
IMPORTANT RULES:
|
||||
- Only READ files within the project directory
|
||||
- Do NOT write, delete, or modify any files
|
||||
- README must follow proper markdown format
|
||||
- Must contain Install and Usage sections
|
||||
- Code examples must use correct TypeScript/ESM syntax
|
||||
- Documentation must be comprehensive and helpful
|
||||
- Do NOT include licensing information (added separately)
|
||||
- Do NOT use CommonJS syntax - only ESM
|
||||
- Do NOT include "in conclusion" or similar filler
|
||||
`;
|
||||
|
||||
const readmeTaskPrompt = `
|
||||
PROJECT DIRECTORY: ${this.projectDir}
|
||||
|
||||
Use the filesystem tool to explore the project and understand what it does:
|
||||
1. First, use tree to see the project structure (maxDepth: 3)
|
||||
Use the filesystem tools to explore the project and understand what it does:
|
||||
1. First, use list_directory to see the project structure
|
||||
2. Read package.json to understand the package name, description, and dependencies
|
||||
3. Read the existing readme.md if it exists (use it as a base, improve and expand)
|
||||
4. Read readme.hints.md if it exists (contains hints for documentation)
|
||||
@@ -106,15 +82,19 @@ Then generate a comprehensive README following this template:
|
||||
]
|
||||
`;
|
||||
|
||||
const readmeResult = await readmeOrchestrator.run(readmeTaskPrompt);
|
||||
await readmeOrchestrator.stop();
|
||||
logger.log('info', 'Starting README generation with agent...');
|
||||
|
||||
if (!readmeResult.success) {
|
||||
throw new Error(`README generation failed: ${readmeResult.status}`);
|
||||
}
|
||||
const readmeResult = await plugins.smartagent.runAgent({
|
||||
model: this.aiDocsRef.model,
|
||||
prompt: readmeTaskPrompt,
|
||||
system: readmeSystemPrompt,
|
||||
tools: fsTools,
|
||||
maxSteps: 25,
|
||||
onToolCall: (toolName) => logger.log('info', `[README] Tool call: ${toolName}`),
|
||||
});
|
||||
|
||||
// Clean up markdown formatting if wrapped in code blocks
|
||||
let resultMessage = readmeResult.result
|
||||
let resultMessage = readmeResult.text
|
||||
.replace(/^```markdown\n?/i, '')
|
||||
.replace(/\n?```$/i, '');
|
||||
|
||||
@@ -142,40 +122,19 @@ Then generate a comprehensive README following this template:
|
||||
.encoding('utf8')
|
||||
.read();
|
||||
|
||||
// Create a new orchestrator with filesystem tool for each submodule
|
||||
const subModuleOrchestrator = new plugins.smartagent.DualAgentOrchestrator({
|
||||
smartAiInstance: this.aiDocsRef.smartAiInstance,
|
||||
defaultProvider: 'openai',
|
||||
maxIterations: 20,
|
||||
maxResultChars: 12000,
|
||||
maxHistoryMessages: 15,
|
||||
logPrefix: `[README:${subModule}]`,
|
||||
onProgress: (event) => logger.log(event.logLevel, event.logMessage),
|
||||
guardianPolicyPrompt: `
|
||||
You validate README generation for submodules.
|
||||
const subModuleFsTools = plugins.smartagentTools.filesystemTool({ rootDir: subModulePath });
|
||||
|
||||
APPROVE tool calls for:
|
||||
- Reading any files within the submodule directory
|
||||
- Using tree to see structure
|
||||
- Using glob to find source files
|
||||
const subModuleSystemPrompt = `
|
||||
You create markdown READMEs for npm projects. You only output the markdown readme.
|
||||
|
||||
REJECT tool calls for:
|
||||
- Reading files outside the submodule directory
|
||||
- Writing, deleting, or modifying any files
|
||||
- Any destructive operations
|
||||
|
||||
APPROVE final README if comprehensive, well-formatted markdown with ESM TypeScript examples.
|
||||
REJECT incomplete READMEs or those with licensing info.
|
||||
`,
|
||||
});
|
||||
|
||||
// Register scoped filesystem tool for the submodule directory
|
||||
subModuleOrchestrator.registerScopedFilesystemTool(subModulePath);
|
||||
|
||||
await subModuleOrchestrator.start();
|
||||
IMPORTANT RULES:
|
||||
- Only READ files within the submodule directory
|
||||
- Do NOT write, delete, or modify any files
|
||||
- README must be comprehensive, well-formatted markdown with ESM TypeScript examples
|
||||
- Do NOT include licensing information (added separately)
|
||||
`;
|
||||
|
||||
const subModulePrompt = `
|
||||
You create markdown READMEs for npm projects. You only output the markdown readme.
|
||||
SUB MODULE: ${subModule}
|
||||
SUB MODULE DIRECTORY: ${subModulePath}
|
||||
|
||||
@@ -183,8 +142,8 @@ IMPORTANT: YOU ARE CREATING THE README FOR THIS SUB MODULE: ${subModule}
|
||||
The Sub Module will be published with:
|
||||
${JSON.stringify(tspublishData, null, 2)}
|
||||
|
||||
Use the filesystem tool to explore the submodule:
|
||||
1. Use tree to see the submodule structure
|
||||
Use the filesystem tools to explore the submodule:
|
||||
1. Use list_directory to see the submodule structure
|
||||
2. Read package.json to understand the submodule
|
||||
3. Read source files in ts/ directory to understand the implementation
|
||||
|
||||
@@ -208,21 +167,23 @@ Generate a README following the template:
|
||||
Don't use \`\`\` at the beginning or end. Only for code blocks.
|
||||
`;
|
||||
|
||||
const subModuleResult = await subModuleOrchestrator.run(subModulePrompt);
|
||||
await subModuleOrchestrator.stop();
|
||||
const subModuleResult = await plugins.smartagent.runAgent({
|
||||
model: this.aiDocsRef.model,
|
||||
prompt: subModulePrompt,
|
||||
system: subModuleSystemPrompt,
|
||||
tools: subModuleFsTools,
|
||||
maxSteps: 20,
|
||||
onToolCall: (toolName) => logger.log('info', `[README:${subModule}] Tool call: ${toolName}`),
|
||||
});
|
||||
|
||||
if (subModuleResult.success) {
|
||||
const subModuleReadmeString = subModuleResult.result
|
||||
.replace(/^```markdown\n?/i, '')
|
||||
.replace(/\n?```$/i, '') + '\n' + legalInfo;
|
||||
await plugins.fsInstance
|
||||
.file(plugins.path.join(subModulePath, 'readme.md'))
|
||||
.encoding('utf8')
|
||||
.write(subModuleReadmeString);
|
||||
logger.log('success', `Built readme for ${subModule}`);
|
||||
} else {
|
||||
logger.log('error', `Failed to build readme for ${subModule}: ${subModuleResult.status}`);
|
||||
}
|
||||
const subModuleReadmeString = subModuleResult.text
|
||||
.replace(/^```markdown\n?/i, '')
|
||||
.replace(/\n?```$/i, '') + '\n' + legalInfo;
|
||||
await plugins.fsInstance
|
||||
.file(plugins.path.join(subModulePath, 'readme.md'))
|
||||
.encoding('utf8')
|
||||
.write(subModuleReadmeString);
|
||||
logger.log('success', `Built readme for ${subModule}`);
|
||||
}
|
||||
|
||||
return resultMessage;
|
||||
|
||||
Reference in New Issue
Block a user