-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhanced Documentation and Utility Script Addition (#48)
## Documentation Enhancement and Script Development for AgenticJS - **Node.js Script Development:** Created a Node.js script designed to automatically generate a markdown document detailing the structure and codebase of the AgenticJS library. This script facilitates easy navigation and understanding of the library’s layout for developers. - **Added Detailed Comments:** Introduced comprehensive comments across all utility files, agents, and stores. These comments elucidate the purpose, usage, and functionality of each component within the AgenticJS library, enhancing the documentation's clarity and usefulness for both current and future developers.
- Loading branch information
Showing
20 changed files
with
294 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ | |
"test:unit:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --verbose --testPathPattern='tests/unit'", | ||
"play:react": "cd playground/react && npm run dev", | ||
"play:sb": "cd playground/react && npm run storybook", | ||
"play:node": "cd playground/nodejs && node index.js" | ||
"play:node": "cd playground/nodejs && node index.js", | ||
"code-snapshot": "node xscripts/codeSnapshot.js" | ||
}, | ||
"packageManager": "[email protected]", | ||
"repository": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
/** | ||
* Agent Exports Centralization. | ||
* | ||
* This file serves as the central export point for all agent-related classes within the AgenticJS library. By consolidating | ||
* agent exports here, it simplifies the import process for external files and maintains a clean and organized code structure. | ||
* This setup enhances modularity and reusability of agent components. | ||
* | ||
* Usage: | ||
* Import agent classes from this file to access and utilize different types of agents across the library. This centralization | ||
* aids in maintaining consistency and ease of updates to the agent architecture. | ||
*/ | ||
|
||
export * from './baseAgent'; | ||
export * from './reactChampionAgent'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
/** | ||
* Store Modules Centralization. | ||
* | ||
* This file acts as the central export point for all state management store modules within the AgenticJS library. It consolidates | ||
* the exports of various stores such as agentStore, taskStore, and teamStore, facilitating easier and more organized access across | ||
* the library. This centralization supports modular architecture and enhances maintainability by grouping all store-related | ||
* exports in one place. | ||
* | ||
* Usage: | ||
* Import store modules from this file to access and manage the application's state related to agents, tasks, and teams efficiently. | ||
* This setup ensures that updates and changes to store configurations are propagated consistently throughout the application. | ||
*/ | ||
|
||
export * from './teamStore'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const util = require('util'); | ||
|
||
const readdir = util.promisify(fs.readdir); | ||
const readFile = util.promisify(fs.readFile); | ||
const writeFile = util.promisify(fs.writeFile); | ||
const stat = util.promisify(fs.stat); | ||
|
||
const INSTRUCTIONS_PROMPT = `This markdown document provides a comprehensive snapshot of the entire codebase for the AgenticJS library. It is designed to facilitate easy understanding and navigation of the library's structure and contents for both developers and automated systems. | ||
**Directory Structure** | ||
The 'Directory Structure' section visually represents the hierarchical arrangement of all files and directories within the AgenticJS project. This tree-like structure helps in quickly locating files and understanding the organizational layout of the project. | ||
**File Contents** | ||
Following the directory structure, the 'File Contents' section includes detailed listings of each JavaScript file within the AgenticJS library. Each file entry is prefixed with its relative path from the base directory, ensuring clear context and easy access. The content of each file is enclosed in code blocks, formatted for JavaScript, providing exact details of the code written in the library`; | ||
|
||
|
||
const baseDirectory = './src'; // Adjust the base directory as needed | ||
const outputFilePath = './output.md'; | ||
|
||
// Function to recursively get all file paths | ||
async function getFiles(dir) { | ||
const subdirs = await readdir(dir); | ||
const files = await Promise.all(subdirs.map(async (subdir) => { | ||
const res = path.resolve(dir, subdir); | ||
return (await stat(res)).isDirectory() ? getFiles(res) : res; | ||
})); | ||
return files.reduce((a, f) => a.concat(f), []); | ||
} | ||
|
||
// Function to generate directory tree structure | ||
async function generateDirStructure(dir, prefix = '') { | ||
const dirContents = await readdir(dir, { withFileTypes: true }); | ||
let structure = ''; | ||
for (const dirent of dirContents) { | ||
const filePath = path.resolve(dir, dirent.name); | ||
if (dirent.isDirectory()) { | ||
structure += `${prefix}└── ${dirent.name}\n`; | ||
structure += await generateDirStructure(filePath, `${prefix} `); | ||
} else if (!dirent.name.startsWith('_DONTUSE')) { | ||
structure += `${prefix}└── ${dirent.name}\n`; | ||
} | ||
} | ||
return structure; | ||
} | ||
|
||
// Function to create the markdown document | ||
async function createMarkdownFile(files, dirStructure) { | ||
let markdownContent = `# Code Snapshot for AgenticJS\n\n`; | ||
markdownContent += `${INSTRUCTIONS_PROMPT} \n\n`; | ||
markdownContent += `## Directory Structure\n\n\`\`\`\n${dirStructure}\`\`\`\n\n`; | ||
markdownContent += `## File Contents\n\n`; | ||
for (const file of files) { | ||
const fileName = path.basename(file); | ||
if (path.extname(file) === '.js' && !fileName.startsWith('_DONTUSE')) { | ||
|
||
let relativePath = path.relative(baseDirectory, file); | ||
relativePath = path.normalize(relativePath).replace(/\\/g, '/'); // Normalize and replace backslashes | ||
relativePath = `./src/${relativePath}`; // Prepend with ./src/ | ||
|
||
// // Normalize the path here before printing | ||
// let relativePath = path.relative(path.resolve(__dirname, baseDirectory), file); | ||
// // relativePath = `./${relativePath}`; // Ensures path starts with ./ | ||
// relativePath = `./src/${relativePath}`; // Ensures path starts with ./src/ | ||
// relativePath = relativePath.replace(/\\/g, '/'); // Normalize Windows paths | ||
|
||
const content = await readFile(file, 'utf8'); | ||
markdownContent += `### ${relativePath}\n\n`; | ||
markdownContent += "```js\n"; | ||
markdownContent += `//--------------------------------------------\n`; | ||
markdownContent += `// File: ${relativePath}\n`; | ||
markdownContent += `//--------------------------------------------\n\n`; | ||
markdownContent += `${content}\n`; | ||
markdownContent += "```\n\n"; | ||
} | ||
} | ||
await writeFile(outputFilePath, markdownContent, 'utf8'); | ||
} | ||
|
||
// Main function to execute the script | ||
async function main() { | ||
const files = await getFiles(baseDirectory); | ||
const dirStructure = await generateDirStructure(baseDirectory); | ||
await createMarkdownFile(files, dirStructure); | ||
} | ||
|
||
main().catch(err => console.error(err)); |