update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { AiDoc } from '../classes.aidoc.js';
|
||||
import * as plugins from '../plugins.js';
|
||||
import { ProjectContext } from './projectcontext.js';
|
||||
import { logger } from '../logging.js';
|
||||
|
||||
interface IDescriptionInterface {
|
||||
description: string;
|
||||
@@ -18,43 +19,60 @@ export class Description {
|
||||
}
|
||||
|
||||
public async build() {
|
||||
// Gather project context upfront to avoid token explosion from filesystem tool
|
||||
const projectContext = new ProjectContext(this.projectDir);
|
||||
const files = await projectContext.gatherFiles();
|
||||
const contextString = await projectContext.convertFilesToContext([
|
||||
files.smartfilePackageJSON,
|
||||
files.smartfilesNpmextraJSON,
|
||||
...files.smartfilesMod.slice(0, 10), // Limit to first 10 source files for description
|
||||
]);
|
||||
|
||||
// Use DualAgentOrchestrator for description generation
|
||||
// Use DualAgentOrchestrator with filesystem tool for agent-driven exploration
|
||||
const descriptionOrchestrator = new plugins.smartagent.DualAgentOrchestrator({
|
||||
smartAiInstance: this.aiDocsRef.smartAiInstance,
|
||||
defaultProvider: 'openai',
|
||||
maxIterations: 15,
|
||||
maxResultChars: 10000, // Limit tool output to prevent token explosion
|
||||
maxHistoryMessages: 15, // Limit history window
|
||||
logPrefix: '[Description]',
|
||||
onProgress: (event) => logger.log(event.logLevel, event.logMessage),
|
||||
guardianPolicyPrompt: `
|
||||
You validate description generation.
|
||||
You validate description generation tool calls and outputs.
|
||||
|
||||
APPROVE if:
|
||||
APPROVE tool calls for:
|
||||
- Reading package.json, npmextra.json, or source files in the ts/ directory
|
||||
- Listing directory contents to understand project structure
|
||||
- Using tree to see project structure
|
||||
|
||||
REJECT tool calls for:
|
||||
- Reading files outside the project directory
|
||||
- Writing, deleting, or modifying any files
|
||||
- Any destructive operations
|
||||
|
||||
For final output, APPROVE if:
|
||||
- JSON is valid and parseable
|
||||
- Description is a clear, concise one-sentence summary
|
||||
- Keywords are relevant to the project's use cases
|
||||
- Both description and keywords fields are present
|
||||
|
||||
REJECT if:
|
||||
REJECT final output if:
|
||||
- JSON is malformed or wrapped in markdown code blocks
|
||||
- Description is too long or vague
|
||||
- Keywords are irrelevant or generic
|
||||
`,
|
||||
});
|
||||
|
||||
// Register scoped filesystem tool for agent exploration
|
||||
descriptionOrchestrator.registerScopedFilesystemTool(this.projectDir);
|
||||
|
||||
await descriptionOrchestrator.start();
|
||||
|
||||
const descriptionTaskPrompt = `
|
||||
You create a project description and keywords for an npm package.
|
||||
|
||||
Analyze the project files provided below to understand the codebase, then generate a description and keywords.
|
||||
PROJECT DIRECTORY: ${this.projectDir}
|
||||
|
||||
Your response must be valid JSON adhering to this interface:
|
||||
Use the filesystem tool to explore the project and understand what it does:
|
||||
1. First, use tree to see the project structure
|
||||
2. Read package.json to understand the package name and current description
|
||||
3. Read npmextra.json if it exists for additional metadata
|
||||
4. Read key source files in ts/ directory to understand the implementation
|
||||
|
||||
Then generate a description and keywords based on your exploration.
|
||||
|
||||
Your FINAL response must be valid JSON adhering to this interface:
|
||||
{
|
||||
description: string; // a sensible short, one sentence description of the project
|
||||
keywords: string[]; // an array of tags that describe the project based on use cases
|
||||
@@ -63,12 +81,6 @@ Your response must be valid JSON adhering to this interface:
|
||||
Important: Answer only in valid JSON.
|
||||
Your answer should be parseable with JSON.parse() without modifying anything.
|
||||
Don't wrap the JSON in \`\`\`json\`\`\` - just return the raw JSON object.
|
||||
|
||||
Here are the project files:
|
||||
|
||||
${contextString}
|
||||
|
||||
Generate the description based on these files.
|
||||
`;
|
||||
|
||||
const descriptionResult = await descriptionOrchestrator.run(descriptionTaskPrompt);
|
||||
@@ -83,7 +95,11 @@ Generate the description based on these files.
|
||||
descriptionResult.result.replace('```json', '').replace('```', ''),
|
||||
);
|
||||
|
||||
// Use the already gathered files for updates
|
||||
// Use ProjectContext to get file handles for writing
|
||||
const projectContext = new ProjectContext(this.projectDir);
|
||||
const files = await projectContext.gatherFiles();
|
||||
|
||||
// Update npmextra.json
|
||||
const npmextraJson = files.smartfilesNpmextraJSON;
|
||||
const npmextraJsonContent = JSON.parse(npmextraJson.contents.toString());
|
||||
|
||||
@@ -93,7 +109,7 @@ Generate the description based on these files.
|
||||
npmextraJson.contents = Buffer.from(JSON.stringify(npmextraJsonContent, null, 2));
|
||||
await npmextraJson.write();
|
||||
|
||||
// do the same with packageJson
|
||||
// Update package.json
|
||||
const packageJson = files.smartfilePackageJSON;
|
||||
const packageJsonContent = JSON.parse(packageJson.contents.toString());
|
||||
packageJsonContent.description = resultObject.description;
|
||||
|
||||
Reference in New Issue
Block a user