Skip to content

Commit

Permalink
fix mistakes, update with cleaner script
Browse files Browse the repository at this point in the history
  • Loading branch information
madjin committed Jan 2, 2025
1 parent 3b33f2f commit 817b0ae
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 22 deletions.
3 changes: 1 addition & 2 deletions packages/core/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class MemoryCacheAdapter implements ICacheAdapter {
* Class representing a file system cache adapter.
* Implements the ICacheAdapter interface.
*/
**/

export class FsCacheAdapter implements ICacheAdapter {
/**
* Constructor for creating an instance with a specified data directory.
Expand Down Expand Up @@ -172,7 +172,6 @@ export class DbCacheAdapter implements ICacheAdapter {
/**
* A class representing a Cache Manager.
*/
**/
export class CacheManager<CacheAdapter extends ICacheAdapter = ICacheAdapter>
implements ICacheManager
{
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/database/CircuitBreaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export type CircuitBreakerState = "CLOSED" | "OPEN" | "HALF_OPEN";
* Represents a Circuit Breaker that can monitor the status of a system and prevent overload.
* @class
*/
*/
export class CircuitBreaker {
private state: CircuitBreakerState = "CLOSED";
private failureCount: number = 0;
Expand Down Expand Up @@ -75,7 +74,6 @@ export class CircuitBreaker {
/**
* Increments the failure count and updates the last failure time.
* If the failure count exceeds the failure threshold, changes the state to "OPEN".
*/
*/
private handleFailure(): void {
this.failureCount++;
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*
* @class
*/
*/
class ElizaLogger {
/**
* Constructor for ElizaLogger class.
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const defaultMatchCount = 10;
* MemoryManager class responsible for managing memories in the database.
* @implements {IMemoryManager}
*/
**/
export class MemoryManager implements IMemoryManager {
/**
* The AgentRuntime instance associated with this manager.
Expand Down
79 changes: 79 additions & 0 deletions scripts/jsdoc-automation/src/JsDocCleaner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Utility class for cleaning and validating JSDoc comments.
*/
export class JsDocCleaner {
/**
* Processes and cleans a JSDoc comment to ensure proper formatting.
*
* @param {string} comment - The JSDoc comment to clean.
* @returns {string} The cleaned JSDoc comment.
*/
public static clean(comment: string): string {
// Remove any empty lines at start/end
let cleaned = comment.trim();

// Ensure comment starts with /**
if (!cleaned.startsWith('/**')) {
cleaned = '/**' + cleaned.replace(/^\/\*+/, '');
}

// Fix common artifacts:
// 1. Multiple closing patterns
cleaned = cleaned.replace(/\*+\s*\*+\s*\/$/, '*/');
cleaned = cleaned.replace(/\*+\s*\/$/, '*/');

// 2. Fix improper closing
if (!cleaned.endsWith('*/')) {
cleaned = cleaned + ' */';
}

// 3. Fix spacing in content
cleaned = cleaned.split('\n').map((line, index) => {
// First line should just have /**
if (index === 0) {
return '/**';
}

// Clean up any extra asterisks in the content
line = line.trim().replace(/^\*+\s*/, ' * ');

// Ensure there's a space after the asterisk if it's a content line
if (line.startsWith(' *') && !line.startsWith(' * ')) {
line = ' * ' + line.substring(2).trimStart();
}

return line;
}).join('\n');

// 4. Fix final spacing
cleaned = cleaned.replace(/\s*\*\//, '\n */');

// Validate basic structure
const isValid =
cleaned.startsWith('/**') &&
cleaned.endsWith('*/') &&
cleaned.includes('\n');

if (!isValid) {
// If validation fails, create a minimal valid structure
cleaned = '/**\n * ' + cleaned.replace(/\/\*+|\*+\//g, '').trim() + '\n */';
}

return cleaned;
}

/**
* Validates if a JSDoc comment has proper structure.
*
* @param {string} comment - The JSDoc comment to validate.
* @returns {boolean} True if the comment has valid structure.
*/
public static isValid(comment: string): boolean {
return (
comment.startsWith('/**') &&
comment.endsWith('*/') &&
comment.includes('\n') &&
!comment.includes('**/')
);
}
}
23 changes: 7 additions & 16 deletions scripts/jsdoc-automation/src/JsDocGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AIService } from './AIService.js';
import { ASTQueueItem } from './types/index.js';
import { JsDocCleaner } from './JsDocCleaner.js';

/**
* A class that generates JSDoc comments for code snippets and classes.
Expand All @@ -9,7 +10,7 @@ export class JsDocGenerator {
* Constructor for a class that takes in an AIService instance.
* @param {AIService} aiService - The AIService instance to be injected into the class.
*/
constructor(public aiService: AIService) { }
constructor(public aiService: AIService) {}

/**
* Generates a comment based on the given ASTQueueItem.
Expand All @@ -20,7 +21,7 @@ export class JsDocGenerator {
public async generateComment(queueItem: ASTQueueItem): Promise<string> {
const prompt = this.buildPrompt(queueItem);
const comment = await this.aiService.generateComment(prompt);
return comment;
return JsDocCleaner.clean(comment);
}

/**
Expand All @@ -29,37 +30,27 @@ export class JsDocGenerator {
* @param {ASTQueueItem} queueItem - The ASTQueueItem to generate the comment for.
* @returns {Promise<string>} The generated comment for the class.
*/
public async generateClassComment(
queueItem: ASTQueueItem,
): Promise<string> {
public async generateClassComment(queueItem: ASTQueueItem): Promise<string> {
const prompt = this.buildClassPrompt(queueItem);
const comment = await this.aiService.generateComment(prompt);
return comment;
return JsDocCleaner.clean(comment);
}

/**
* Builds a prompt with the JSDoc comment for the provided ASTQueueItem code.
*
* @param {ASTQueueItem} queueItem The ASTQueueItem object containing the code to extract the JSDoc comment from.
* @returns {string} The JSDoc comment extracted from the code provided in the ASTQueueItem object.
*/
private buildPrompt(queueItem: ASTQueueItem): string {
return `Generate JSDoc comment for the following code:
\`\`\`typescript
${queueItem.code}
\`\`\`
Only return the JSDoc comment, not the code itself.
Only return the JSDoc comment with proper formatting, not the code itself.
`;
}

private buildClassPrompt(
queueItem: ASTQueueItem,
): string {
return `Generate JSDoc comment for the following Class:
Class name: ${queueItem.code.match(/class (\w+)/)?.[1]}
Only return the JSDoc for the Class itself, not the methods or anything in the class.
Expand All @@ -74,4 +65,4 @@ export class JsDocGenerator {
\`\`\`
`;
}
}
}

0 comments on commit 817b0ae

Please sign in to comment.