@aigne/doc-smith 0.2.4 → 0.2.6

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -0
  3. package/agents/check-detail-result.mjs +15 -120
  4. package/agents/check-structure-plan.mjs +56 -7
  5. package/agents/detail-generator-and-translate.yaml +7 -1
  6. package/agents/detail-regenerator.yaml +6 -57
  7. package/agents/docs-generator.yaml +5 -61
  8. package/agents/find-item-by-path.mjs +63 -14
  9. package/agents/input-generator.mjs +31 -21
  10. package/agents/language-selector.mjs +101 -0
  11. package/agents/load-config.mjs +3 -3
  12. package/agents/load-sources.mjs +55 -40
  13. package/agents/publish-docs.mjs +44 -153
  14. package/agents/retranslate.yaml +74 -0
  15. package/agents/save-docs.mjs +12 -2
  16. package/agents/save-output.mjs +9 -3
  17. package/agents/save-single-doc.mjs +19 -0
  18. package/agents/structure-planning.yaml +6 -0
  19. package/agents/team-publish-docs.yaml +7 -7
  20. package/agents/translate.yaml +3 -0
  21. package/aigne.yaml +5 -1
  22. package/docs-mcp/docs-search.yaml +1 -1
  23. package/docs-mcp/get-docs-detail.mjs +1 -1
  24. package/docs-mcp/get-docs-structure.mjs +1 -1
  25. package/docs-mcp/read-doc-content.mjs +1 -1
  26. package/package.json +16 -7
  27. package/prompts/check-structure-planning-result.md +4 -7
  28. package/prompts/content-detail-generator.md +1 -2
  29. package/prompts/structure-planning.md +7 -2
  30. package/prompts/translator.md +4 -0
  31. package/tests/test-all-validation-cases.mjs +707 -0
  32. package/utils/constants.mjs +3 -2
  33. package/utils/markdown-checker.mjs +386 -0
  34. package/utils/mermaid-validator.mjs +158 -0
  35. package/utils/mermaid-worker-pool.mjs +254 -0
  36. package/utils/mermaid-worker.mjs +242 -0
  37. package/utils/utils.mjs +155 -44
@@ -1,6 +1,7 @@
1
1
  import { writeFile, readdir, unlink } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { getCurrentGitHead, saveGitHeadToConfig } from "../utils/utils.mjs";
4
+ import { shutdownMermaidWorkerPool } from "../utils/mermaid-worker-pool.mjs";
4
5
 
5
6
  /**
6
7
  * @param {Object} params
@@ -14,6 +15,7 @@ export default async function saveDocs({
14
15
  docsDir,
15
16
  translateLanguages = [],
16
17
  locale,
18
+ projectInfoMessage,
17
19
  }) {
18
20
  const results = [];
19
21
  // Save current git HEAD to config.yaml for change detection
@@ -47,8 +49,9 @@ export default async function saveDocs({
47
49
 
48
50
  const message = `## ✅ Documentation Generated Successfully!
49
51
 
50
- Successfully generated **${structurePlan.length}** documents and saved to: \`${docsDir}\`
51
-
52
+ Successfully generated **${structurePlan.length}** documents and saved to:
53
+ \`${docsDir}\`
54
+ ${projectInfoMessage || ""}
52
55
  ### 🚀 Next Steps
53
56
 
54
57
  1. Publish Documentation
@@ -78,6 +81,13 @@ export default async function saveDocs({
78
81
  ---
79
82
  `;
80
83
 
84
+ // Shutdown mermaid worker pool to ensure clean exit
85
+ try {
86
+ await shutdownMermaidWorkerPool();
87
+ } catch (error) {
88
+ console.warn("Failed to shutdown mermaid worker pool:", error.message);
89
+ }
90
+
81
91
  return {
82
92
  message,
83
93
  };
@@ -1,8 +1,12 @@
1
1
  import { promises as fs } from "node:fs";
2
2
  import { join } from "node:path";
3
3
 
4
- export default async function saveOutput({ savePath, fileName, saveKey, ...rest }) {
5
- console.log("saveOutput", savePath, fileName, saveKey, rest);
4
+ export default async function saveOutput({
5
+ savePath,
6
+ fileName,
7
+ saveKey,
8
+ ...rest
9
+ }) {
6
10
  if (!(saveKey in rest)) {
7
11
  console.warn(`saveKey "${saveKey}" not found in input, skip saving.`);
8
12
  return {
@@ -13,7 +17,9 @@ export default async function saveOutput({ savePath, fileName, saveKey, ...rest
13
17
 
14
18
  const value = rest[saveKey];
15
19
  const content =
16
- typeof value === "object" && value !== null ? JSON.stringify(value, null, 2) : String(value);
20
+ typeof value === "object" && value !== null
21
+ ? JSON.stringify(value, null, 2)
22
+ : String(value);
17
23
  await fs.mkdir(savePath, { recursive: true });
18
24
  const filePath = join(savePath, fileName);
19
25
  await fs.writeFile(filePath, content, "utf8");
@@ -1,4 +1,5 @@
1
1
  import { saveDocWithTranslations } from "../utils/utils.mjs";
2
+ import { shutdownMermaidWorkerPool } from "../utils/mermaid-worker-pool.mjs";
2
3
 
3
4
  export default async function saveSingleDoc({
4
5
  path,
@@ -7,6 +8,8 @@ export default async function saveSingleDoc({
7
8
  translates,
8
9
  labels,
9
10
  locale,
11
+ isTranslate = false,
12
+ isShowMessage = false,
10
13
  }) {
11
14
  const results = await saveDocWithTranslations({
12
15
  path,
@@ -15,6 +18,22 @@ export default async function saveSingleDoc({
15
18
  translates,
16
19
  labels,
17
20
  locale,
21
+ isTranslate,
18
22
  });
23
+
24
+ if (isShowMessage) {
25
+ // Shutdown mermaid worker pool to ensure clean exit
26
+ try {
27
+ await shutdownMermaidWorkerPool();
28
+ } catch (error) {
29
+ console.warn("Failed to shutdown mermaid worker pool:", error.message);
30
+ }
31
+
32
+ const message = isTranslate
33
+ ? `✅ Translation completed successfully`
34
+ : `✅ Document updated successfully`;
35
+ return { message };
36
+ }
37
+
19
38
  return {};
20
39
  }
@@ -36,6 +36,12 @@ input_schema:
36
36
  output_schema:
37
37
  type: object
38
38
  properties:
39
+ projectName:
40
+ type: string
41
+ description: 根据 DataSources 分析项目名称,注意是原始项目名称
42
+ projectDesc:
43
+ type: string
44
+ description: 根据 DataSources 分析生成当前项目描述,为原始项目生成描述,描述简洁,不超过 50 个单词
39
45
  structurePlan: ./schema/structure-plan.yaml
40
46
  structurePlanTree:
41
47
  type: string
@@ -10,10 +10,10 @@ skills:
10
10
  skipIfExists: true
11
11
  - load-config.mjs
12
12
  - publish-docs.mjs
13
- input_schema:
14
- type: object
15
- properties:
16
- config:
17
- type: string
18
- description: Path to the config file
19
- default: ./doc-smith/config.yaml
13
+ # input_schema:
14
+ # type: object
15
+ # properties:
16
+ # config:
17
+ # type: string
18
+ # description: Path to the config file
19
+ # default: ./.aigne/doc-smith/config.yaml
@@ -14,6 +14,9 @@ input_schema:
14
14
  glossary:
15
15
  type: string
16
16
  description: 术语表
17
+ feedback:
18
+ type: string
19
+ description: Feedback for translation improvement
17
20
  required:
18
21
  - language
19
22
  - content
package/aigne.yaml CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  chat_model:
4
4
  provider: google
5
- name: gemini-2.5-pro
5
+ # name: gemini-2.5-pro
6
+ name: gemini-2.5-flash
6
7
  temperature: 0.8
7
8
  agents:
8
9
  - ./agents/structure-planning.yaml
@@ -28,6 +29,8 @@ agents:
28
29
  - ./agents/load-config.mjs
29
30
  - ./agents/team-publish-docs.yaml
30
31
  - ./agents/find-item-by-path.mjs
32
+ - ./agents/retranslate.yaml
33
+ - ./agents/language-selector.mjs
31
34
  - ./docs-mcp/get-docs-structure.mjs
32
35
  - ./docs-mcp/get-docs-detail.mjs
33
36
  - ./docs-mcp/docs-search.yaml
@@ -40,6 +43,7 @@ cli:
40
43
  - ./agents/docs-generator.yaml
41
44
  - ./agents/detail-regenerator.yaml
42
45
  - ./agents/team-publish-docs.yaml
46
+ - ./agents/retranslate.yaml
43
47
  mcp_server:
44
48
  agents:
45
49
  - ./docs-mcp/get-docs-structure.mjs
@@ -18,7 +18,7 @@ input_schema:
18
18
  config:
19
19
  type: string
20
20
  description: Path to the config file
21
- default: ./doc-smith/config.yaml
21
+ default: ./.aigne/doc-smith/config.yaml
22
22
  output_schema:
23
23
  type: object
24
24
  properties:
@@ -1,7 +1,7 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
 
4
- const docsDir = path.join(process.cwd(), "doc-smith", "docs");
4
+ const docsDir = path.join(process.cwd(), "./.aigne/doc-smith", "docs");
5
5
 
6
6
  export default async function getDocDetail({ path: docPath }) {
7
7
  try {
@@ -3,7 +3,7 @@ import path from "node:path";
3
3
 
4
4
  const structureDir = path.join(
5
5
  process.cwd(),
6
- "doc-smith",
6
+ "./.aigne/doc-smith",
7
7
  "output",
8
8
  "structure-plan.json"
9
9
  );
@@ -1,7 +1,7 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
 
4
- const docsDir = path.join(process.cwd(), "doc-smith", "docs");
4
+ const docsDir = path.join(process.cwd(), "./.aigne/doc-smith", "docs");
5
5
 
6
6
  export default async function readDocContent({
7
7
  relevantDocPaths,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/doc-smith",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -12,17 +12,26 @@
12
12
  "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@aigne/anthropic": "^0.10.10",
16
- "@aigne/cli": "^1.31.0",
17
- "@aigne/core": "^1.46.0",
18
- "@aigne/gemini": "^0.8.14",
19
- "@aigne/openai": "^0.10.14",
20
- "@aigne/publish-docs": "^0.5.3",
15
+ "@aigne/anthropic": "^0.10.13",
16
+ "@aigne/cli": "^1.33.1",
17
+ "@aigne/core": "^1.48.0",
18
+ "@aigne/gemini": "^0.8.17",
19
+ "@aigne/openai": "^0.10.17",
20
+ "@aigne/publish-docs": "^0.5.4",
21
21
  "chalk": "^5.5.0",
22
+ "dompurify": "^3.2.6",
22
23
  "glob": "^11.0.3",
24
+ "jsdom": "^26.1.0",
25
+ "mermaid": "^11.9.0",
23
26
  "open": "^10.2.0",
27
+ "remark-gfm": "^4.0.1",
28
+ "remark-lint": "^10.0.1",
29
+ "remark-parse": "^11.0.0",
24
30
  "terminal-link": "^4.0.0",
25
31
  "ufo": "^1.6.1",
32
+ "unified": "^11.0.5",
33
+ "unist-util-visit": "^5.0.0",
34
+ "vfile": "^6.0.3",
26
35
  "yaml": "^2.8.0"
27
36
  },
28
37
  "scripts": {
@@ -16,15 +16,13 @@
16
16
  - **用户反馈**:
17
17
  ```
18
18
  {{ feedback }}
19
-
20
- 根据最新的 Data Sources 按需要更新节点的 sourceIds。
21
19
  ```
22
20
  </context>
23
21
 
24
22
  <goal>
25
- 你的主要目标是验证两条关键规则:
23
+ 你的主要目标是验证三条关键规则:
26
24
  1. **反馈的实现**:新的结构规划**必须**正确地实现用户反馈中要求的所有变更。
27
- 2. **无关节点的稳定性**:没有在用户反馈中被提及的节点 ** path 属性不能被修改 **。`path` 是关联现有内容的关键标识符,其稳定性至关重要。
25
+ 2. **无关节点的稳定性**:没有在用户反馈中被提及的节点 ** path、sourcesIds 属性不能被修改 **。`path`、`sourcesIds` 是关联现有内容的关键标识符,其稳定性至关重要。
28
26
  3. **数据有效性**: 所有 {{ nodeName }} 都有关联数据源,sourceIds 中都有值。
29
27
  </goal>
30
28
 
@@ -40,9 +38,8 @@
40
38
  1. **分析反馈**:仔细阅读并理解 `<context>` 中 用户反馈 提出的每一项变更要求。明确哪些节点是需要被修改、添加或删除的目标。
41
39
  2. **验证反馈的实现**:对比 `<context>` 中的 `structurePlan` 和 `originalStructurePlan`,确认所要求的变更是否已执行。例如,如果反馈是“移除‘示例’部分”,你必须检查该部分在 `structurePlan` 中是否已不存在。
42
40
  3. **验证无关节点的稳定性**:这是最关键的检查。遍历 `structurePlan` 中的所有节点。对于每一个在 `originalStructurePlan` 中也存在、但并未在反馈中被提及的节点:
43
- * **至关重要**:其 `path` 属性**必须**与 `originalStructurePlan` 中的完全相同。
44
- * 理想情况下,其他属性(如 `title`)也应保持稳定,除非这些变更是由某个被要求的变更直接导致的。
45
- 4. **`sourcesIds` 是允许变更的**,每次结构规划可以根据最新的 DataSources 变更依赖的数据源,sourceIds 不能为空。
41
+ * **至关重要**:其 `path`、`sourcesIds` 属性**必须**与 `originalStructurePlan` 中的完全相同。
42
+ * 理想情况下,其他属性(如 `title`、`description`)也应保持稳定,除非这些变更是由某个被要求的变更直接导致的,或者是 DataSource 变更导致。
46
43
  </rules>
47
44
 
48
45
  <output>
@@ -96,6 +96,5 @@ parentId: {{parentId}}
96
96
 
97
97
  1. 输内容为{{nodeName}}的详细文本。
98
98
  2. 直接输出{{nodeName}}内容,不要包含其他信息.
99
- 3. 如果无法生成内容,返回错误提示用户需要补充哪些内容。
100
- 4. 以用户语言 {{locale}} 输出
99
+ 3. 以用户语言 {{locale}} 输出
101
100
  </output_schema>
@@ -27,10 +27,15 @@
27
27
  {{originalStructurePlan}}
28
28
  </last_structure_plan>
29
29
 
30
+ <last_structure_plan_rule>
31
+ 如果提供了上一轮生成的结构规划(last_structure_plan),需要遵循以下规则:
32
+ 1. **反馈的实现**:新的结构规划**必须**正确地实现用户反馈中要求的所有变更。
33
+ 2. **无关节点的稳定性**:没有在用户反馈中被提及的节点 ** path、sourcesIds 属性不能被修改 **。`path`、`sourcesIds` 是关联现有内容的关键标识符,其稳定性至关重要。
34
+ 理想情况下,其他属性(如 `title`、`description`)也应保持稳定,除非这些变更是由某个被要求的变更直接导致的,或者是 DataSource 变更导致。
35
+ </last_structure_plan_rule>
36
+
30
37
  <structure_plan_feedback>
31
38
  {{ feedback }}
32
-
33
- 根据最新的 Data Sources 按需要更新节点的 sourceIds,如没有大的变化,可以不更新。
34
39
  </structure_plan_feedback>
35
40
 
36
41
  <review_structure_plan>
@@ -61,6 +61,10 @@
61
61
  {{content}}
62
62
  </content>
63
63
 
64
+ <translate_feedback>
65
+ {{ feedback }}
66
+ </translate_feedback>
67
+
64
68
  <review_feedback>
65
69
  {{ detailFeedback }}
66
70
  </review_feedback>