@khiem_enhance/ai-doc-agent 0.1.0 → 0.1.1
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/dist/cli.js +2 -1
- package/dist/commands/generate.js +10 -9
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,8 @@ program
|
|
|
10
10
|
.version("0.1.0");
|
|
11
11
|
program
|
|
12
12
|
.command("generate")
|
|
13
|
-
.option("--
|
|
13
|
+
.option("--only <part>", "architecture|modules", "architecture")
|
|
14
14
|
.option("--output <dir>", "Docs output directory", "docs")
|
|
15
|
+
.option("--since <commit>", "Only analyze changes since commit")
|
|
15
16
|
.action(generate_1.generateDocs);
|
|
16
17
|
program.parse();
|
|
@@ -12,34 +12,35 @@ const modules_1 = require("../analyzers/modules");
|
|
|
12
12
|
const markdownWriter_1 = require("../writers/markdownWriter");
|
|
13
13
|
const gitUtils_1 = require("../git/gitUtils");
|
|
14
14
|
const moduleDetector_1 = require("../scanner/moduleDetector");
|
|
15
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
15
16
|
async function generateDocs(options) {
|
|
16
17
|
const root = process.cwd();
|
|
17
18
|
const files = options.since
|
|
18
|
-
? (0, gitUtils_1.getChangedFiles)(options.since).map(f => path_1.default.join(root, f))
|
|
19
|
+
? (0, gitUtils_1.getChangedFiles)(options.since).map((f) => path_1.default.join(root, f))
|
|
19
20
|
: await (0, fileScanner_1.scanProject)(root);
|
|
20
21
|
// ---------- Architecture ----------
|
|
21
|
-
const tree = files
|
|
22
|
-
.map(f => path_1.default.relative(root, f))
|
|
23
|
-
.join("\n");
|
|
22
|
+
const tree = files.map((f) => path_1.default.relative(root, f)).join("\n");
|
|
24
23
|
const architectureSource = files
|
|
25
24
|
.slice(0, 25)
|
|
26
|
-
.map(f => `FILE: ${f}\n${(0, contentReader_1.readFile)(f)}`)
|
|
25
|
+
.map((f) => `FILE: ${f}\n${(0, contentReader_1.readFile)(f)}`)
|
|
27
26
|
.join("\n\n");
|
|
28
27
|
const architecture = await (0, architecture_1.generateArchitectureDoc)(tree, architectureSource);
|
|
29
28
|
(0, markdownWriter_1.writeDoc)(options.output, "architecture.md", architecture);
|
|
29
|
+
// ✅ Throttle để không chạm RPM ngay sau architecture
|
|
30
|
+
await sleep(22000);
|
|
30
31
|
// ---------- Modules ----------
|
|
31
32
|
const modules = (0, moduleDetector_1.detectModules)(files, root);
|
|
32
33
|
for (const [moduleName, moduleFiles] of Object.entries(modules)) {
|
|
33
|
-
const fileList = moduleFiles
|
|
34
|
-
.map(f => path_1.default.relative(root, f))
|
|
35
|
-
.join("\n");
|
|
34
|
+
const fileList = moduleFiles.map((f) => path_1.default.relative(root, f)).join("\n");
|
|
36
35
|
const source = moduleFiles
|
|
37
36
|
.slice(0, 20)
|
|
38
|
-
.map(f => `FILE: ${f}\n${(0, contentReader_1.readFile)(f)}`)
|
|
37
|
+
.map((f) => `FILE: ${f}\n${(0, contentReader_1.readFile)(f)}`)
|
|
39
38
|
.join("\n\n");
|
|
40
39
|
const doc = await (0, modules_1.generateModuleDocs)(moduleName, fileList, source);
|
|
41
40
|
(0, markdownWriter_1.writeDoc)(path_1.default.join(options.output, "modules"), `${moduleName}.md`, doc);
|
|
42
41
|
console.log(`📄 Module doc generated: ${moduleName}`);
|
|
42
|
+
// ✅ Throttle giữa các module để giữ < 3 request/min
|
|
43
|
+
await sleep(22000);
|
|
43
44
|
}
|
|
44
45
|
console.log("✅ Docs generation completed");
|
|
45
46
|
}
|