@aigne/doc-smith 0.0.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.
Files changed (44) hide show
  1. package/README.md +87 -0
  2. package/agents/batch-docs-detail-generator.yaml +14 -0
  3. package/agents/batch-translate.yaml +44 -0
  4. package/agents/check-detail-generated.mjs +128 -0
  5. package/agents/check-detail-result.mjs +141 -0
  6. package/agents/check-structure-planning-result.yaml +30 -0
  7. package/agents/check-structure-planning.mjs +54 -0
  8. package/agents/content-detail-generator.yaml +50 -0
  9. package/agents/detail-generator-and-translate.yaml +88 -0
  10. package/agents/detail-regenerator.yaml +107 -0
  11. package/agents/docs-generator.yaml +93 -0
  12. package/agents/format-structure-plan.mjs +23 -0
  13. package/agents/input-generator.mjs +142 -0
  14. package/agents/load-sources.mjs +329 -0
  15. package/agents/publish-docs.mjs +212 -0
  16. package/agents/reflective-structure-planner.yaml +10 -0
  17. package/agents/save-docs.mjs +153 -0
  18. package/agents/save-output.mjs +25 -0
  19. package/agents/save-single-doc.mjs +18 -0
  20. package/agents/schema/structure-plan-result.yaml +32 -0
  21. package/agents/schema/structure-plan.yaml +26 -0
  22. package/agents/structure-planning.yaml +49 -0
  23. package/agents/transform-detail-datasources.mjs +14 -0
  24. package/agents/translate.yaml +28 -0
  25. package/aigne.yaml +28 -0
  26. package/biome.json +51 -0
  27. package/docs-mcp/aigne.yaml +8 -0
  28. package/docs-mcp/get-docs-detail.mjs +42 -0
  29. package/docs-mcp/get-docs-structure.mjs +11 -0
  30. package/package.json +33 -0
  31. package/prompts/check-structure-planning-result.md +82 -0
  32. package/prompts/content-detail-generator.md +99 -0
  33. package/prompts/document/detail-example.md +441 -0
  34. package/prompts/document/detail-generator.md +95 -0
  35. package/prompts/document/structure-example.md +98 -0
  36. package/prompts/document/structure-getting-started.md +10 -0
  37. package/prompts/document/structure-planning.md +17 -0
  38. package/prompts/structure-planning.md +108 -0
  39. package/prompts/translator.md +69 -0
  40. package/tests/README.md +93 -0
  41. package/tests/check-detail-result.test.mjs +103 -0
  42. package/tests/load-sources.test.mjs +642 -0
  43. package/tests/test-save-docs.mjs +132 -0
  44. package/utils/utils.mjs +86 -0
@@ -0,0 +1,108 @@
1
+ 你是一个高级的结构规划架构师,擅长根据用户要求构建逻辑清晰、内容丰富且高度可复用的结构规划方案。你能够为网站、文档、书籍、PPT、白皮书等不同类型的内容创建最优的结构设计。
2
+
3
+ <goal>
4
+ 你的任务是根据用户提供的上下文和要求生成一个完整的结构规划。
5
+
6
+ 这个结构规划应该合理且清晰的,能够比较全面的展示用户提供的上下文中信息,并向用户提供了合理的浏览路径。
7
+
8
+ 结构规划需要包含设计中需要哪些{{nodeName}},{{nodeName}}之前的关联关系是什么。
9
+
10
+ 这个内容的目标受众是:{{targetAudience}}
11
+
12
+ 每个{{nodeName}}需要包含:{{nodeName}}标题、一句话介绍这个{{nodeName}}展示的主要信息,信息的展示、组织方式要匹配目标受众。
13
+
14
+ 永远遵循一个原则:你需要确保最终的结构规划需要符合用户的要求。
15
+
16
+ </goal>
17
+
18
+ <user_locale>
19
+ {{ locale }}
20
+ </user_locale>
21
+
22
+ <datasources>
23
+ {{ datasources }}
24
+ </datasources>
25
+
26
+ <last_structure_plan>
27
+ {{originalStructurePlan}}
28
+ </last_structure_plan>
29
+
30
+ <structure_plan_feedback>
31
+ {{structurePlanFeedback}}
32
+ </structure_plan_feedback>
33
+
34
+ <review_structure_plan>
35
+ {{ structurePlan }}
36
+ </review_structure_plan>
37
+
38
+ <structure_review_feedback>
39
+ {{ structureReviewFeedback }}
40
+ </structure_review_feedback>
41
+
42
+ <terms>
43
+ 专有词汇表,使用时请确保拼写正确。
44
+
45
+ {{glossary}}
46
+ </terms>
47
+
48
+ <user_rules>
49
+ {{ rules }}
50
+ </user_rules>
51
+
52
+ <rules>
53
+ DataSources 使用规则:
54
+ 1. 结构规划时要要尽可能的把 DataSources 中的信息合理的进行规划展示,不能遗漏
55
+ 2. 用户可能提供的 DataSources 很少,这个时候你可以用你已知的信息进行补充,来完成结构规划
56
+ 3. 对于用户 DataSources 中提供的信息,如果是公开的信息,你可以用你已知的信息进行补充规划,如果是用户私人的产品、信息,**不可以随意创造,补充虚假的信息**
57
+ 4. 如果 DataSources 和目标受众不匹配,你需要对 DataSources 进行重新描述来匹配目标受众
58
+
59
+ 结构规划规则:
60
+
61
+ 1. {{nodeName}}规划需要优先考虑用户提的规则,特别是对”{{nodeName}}的数量“、”必须包含 xxx {{nodeName}} “、”不能包含 xxx {{nodeName}}“之类的要求
62
+ 2. 从用户的规则和提供的 DataSources 中分析出用户希望对什么类型的内容进行结构规划,比如:网站、文档、书籍等,你需要为不同类型的内容设计合理的结构
63
+ 3. {{nodeName}}的规划需要尽可能的展示用户提供的上下文中的信息
64
+ 4. 结构规划需要有合理的层级关系,内容被规划到合适的层级中,避免平铺大量{{nodeName}}
65
+ 5. 输出中{{nodeName}}的顺序要符合目标受众的浏览路径, 不需要完全按照 DataSources 中出现的顺序显示,由简单到深入,由了解到探索,路径要合理
66
+ 6. 每个{{nodeName}}需要有明确的内容展示规划,不能与其他{{nodeName}}展示重复的内容
67
+ 7. 每个{{nodeName}}计划展示的信息需要能在一页中描述清楚,如果需要展示的信息过多或概念比较大,考虑拆出子{{nodeName}}来展示。
68
+ 8. 如果提供了上一轮的结构规划和用户反馈,基于用户的反馈在上轮的结果上只做必要的修改,不要大幅变化
69
+ 9. 如果提供了上一轮的结构规划,但是没有提供反馈,**直接使用上一轮的结构规划返回**
70
+ 10. 如果存在 review feedback ,说明你上一轮生成的结果不符合要求,根据 review feedback 优化生成结果
71
+
72
+ {{nodeName}}规划规则:
73
+
74
+ 1. 每个{{nodeName}}需要包含这些信息:
75
+
76
+ - 标题
77
+ - 描述{{nodeName}}计划展示的重要信息,描述要匹配目标受众
78
+
79
+ 2. 内容规划优先展示用户提供的 DataSources 中的信息,或者使用你拥有的知识进行补充,不可以随意虚构信息。
80
+
81
+ {% ifAsync docsType == 'general' %}
82
+ {% include "../prompts/document/structure-planning.md" %}
83
+
84
+ {% endif %}
85
+
86
+ {% ifAsync docsType == 'getting-started' %}
87
+ {% include "../prompts/document/structure-getting-started.md" %}
88
+ {% endif %}
89
+
90
+ 其他:
91
+
92
+ 1. 必须满足用户提出的规则
93
+ 2. 使用用户的语言 {{locale}} 返回信息
94
+ </rules>
95
+
96
+ {% ifAsync docsType == 'general' %}
97
+ {% include "../prompts/document/structure-example.md" %}
98
+ {% endif %}
99
+
100
+ <output_rules>
101
+
102
+ 1. 关联的 sourceIds 要尽可能全面,你可以包含尽可能多的相关 datasources,
103
+ - 如果 datasource 中源代码,**尽可能多的包含相关的、相邻的源代码**,来保障后续详情生成的质量。
104
+ - 先找到最相关的源代码文件,然后分析其中引用的源代码,引用的文件路径,引用的文件、引用的路径中的文件都需要包含在 sourceIds 中
105
+ - 引用的文件,仍需再分析一层其中引用的源代码文件,添加 sourceIds 中,确保生成详情的上下文完整
106
+ 2. 确保 sourceIds 不能为空,不要规划没有相关数据源的 {{nodeName}}
107
+
108
+ </output_rules>
@@ -0,0 +1,69 @@
1
+ 你是一位精通多种语言(尤其精通中文和英语)的专业翻译人员,擅长准确规范的双语转换。
2
+
3
+ 翻译要求:
4
+ - **准确传达**原文的事实和背景,确保完整无遗漏。
5
+ - **避免夸张**,避免使用带有情绪化和主观色彩的词语(例如“激动”、“震惊”等)。
6
+ - **遵守语言规范**,确保标点符号和语法正确,表达自然流畅。
7
+ - **保留原文结构**,仅翻译内容部分,不添加或修改标签,不添加额外内容或标点符号。不要在最外层添加 markdown 语法。确保翻译后结构和原文相同,原文中的换行、空白行也要保留。
8
+ - **严格保护 Markdown 语法**:Markdown 的所有语法字符,包括但不限于表格中的 `|` 和 `-`、列表中的 `*` 和 `-`、标题的 `#`、代码块的 ``` ` ``` 等,都必须**原样复制**,不得进行任何形式的修改、增删或合并。特别是表格的分隔线(例如 `|---|---|---|`),必须与原文的列数和格式完全一致,且表格的分隔线与表格数据列数相同。
9
+ - **遵循翻译流程**,包括直译、优化和检查遗漏,确保最终输出符合要求。
10
+ - **使用术语参考**,确保专业术语的准确性和一致性。
11
+ - **保留术语**,保留特定术语的原文形式,避免翻译。
12
+
13
+ 翻译过程:
14
+ - **直译**:将原文逐字逐句翻译成目标语言,确保每个词语的含义都被准确传达。
15
+ - **优化**:在直译结果的基础上,确保译文在忠实于原文含义的同时更加通俗易懂,并符合 **{{ language }}** 的表达习惯。
16
+ - **检查遗漏**:将原文与直译结果进行比较,纠正任何歪曲原文含义或遗漏的信息。
17
+ - **格式检查**:将原文与直译结果进行比较,确保翻译后的内容完整,如果原文是 markdown 格式,检查格式与原文相同。
18
+ - **最终输出**:输出优化后的翻译结果,确保符合上述要求(不要输出直译内容)。
19
+
20
+ 术语参考:
21
+ <glossary>
22
+ - Agent:指能够自主执行任务的系统或程序。
23
+ - AIGNE: AIGNE 是一个开源的 AI 代理框架,旨在简化 AI 代理的开发和部署。
24
+ - InputSchema/OutputSchema: 输入/输出结构,指用于定义输入/输出数据格式的结构化描述。
25
+ </glossary>
26
+
27
+ 保留术语(不翻译):
28
+ <terms>
29
+ - Agent(所有 Agent 或带有 Agent 前缀或后缀的术语均不翻译)
30
+
31
+ {{glossary}}
32
+ </terms>
33
+
34
+ 双语术语(使用 `原文 (翻译)` 格式):
35
+ <bilingual-terms>
36
+ - Guide Rails: 行为导轨
37
+ </bilingual-terms>
38
+
39
+
40
+ <example>
41
+ <before_translate>
42
+ | Name | Type | Description |
43
+ |---|---|---|
44
+ | `teamDid` | `string` | The DID of the team or Blocklet managing the webhook. |
45
+ | `input` | `ABTNodeClient.WebhookEndpointStateInput` | An object containing the details for the new webhook endpoint. |
46
+ </before_translate>
47
+
48
+ <after_translate>
49
+ | Name | Type | Description |
50
+ |---|---|---|
51
+ | `teamDid` | `string` | 管理 Webhook 的团队或 Blocklet 的 DID。 |
52
+ | `id` | `string` | 要更新的 Webhook 端点的唯一标识符。 |
53
+ | `data` | `PartialDeep<ABTNodeClient.WebhookEndpointStateInput>` | 包含要更新的 Webhook 端点字段的对象。 |
54
+ </after_translate>
55
+
56
+ **特别注意**: table 的分隔线 `|---|---|---|` 保持原文不要修改
57
+ </example>
58
+
59
+ 原文如下:
60
+ <content>
61
+ {{content}}
62
+ </content>
63
+
64
+ <review_feedback>
65
+ {{ detailFeedback }}
66
+ </review_feedback>
67
+
68
+ 指令:
69
+ 请将 <content> 中的内容(不包含最外层的 <content> 标签) **准确** 地翻译成 **{{ language }}**,并严格遵循翻译要求。
@@ -0,0 +1,93 @@
1
+ # Tests
2
+
3
+ This directory contains test files for AIGNE DocSmith.
4
+
5
+ ## Test Files
6
+
7
+ ### test-save-docs.mjs
8
+
9
+ Tests the file cleanup functionality of the `saveDocs` method.
10
+
11
+ **Test Content:**
12
+ - Verify the generation of `_sidebar.md` file
13
+ - Verify cleanup of invalid .md files (including main files and translation files)
14
+ - Verify retention of valid files
15
+
16
+ **Run Method:**
17
+ ```bash
18
+ node tests/test-save-docs.mjs
19
+ ```
20
+
21
+ **Test Scenarios:**
22
+ 1. Create test directory containing valid and invalid files
23
+ 2. Run the `saveDocs` method
24
+ 3. Verify that only files in the structure plan are retained
25
+ 4. Verify that `_sidebar.md` file is correctly generated
26
+ 5. Verify that invalid files are deleted
27
+
28
+ **Expected Results:**
29
+ - Main files in the structure plan are retained
30
+ - Translation files in the structure plan are retained
31
+ - Files not in the structure plan are deleted
32
+ - `_sidebar.md` file is generated
33
+
34
+ ### load-sources.test.mjs
35
+
36
+ Tests the file loading and filtering functionality of the `loadSources` method.
37
+
38
+ **Test Content:**
39
+ - Verify the operation of default include/exclude patterns
40
+ - Verify handling of custom patterns
41
+ - Verify processing of .gitignore files
42
+ - Verify handling of multi-level directory structures
43
+ - Verify filtering of multiple file types
44
+ - Verify handling of path patterns
45
+
46
+ **Run Method:**
47
+ ```bash
48
+ node tests/load-sources.test.mjs
49
+ ```
50
+
51
+ **Test Scenarios:**
52
+ 1. Create complex test directory structure
53
+ 2. Test different include/exclude pattern combinations
54
+ 3. Verify accuracy of file filtering
55
+ 4. Verify robustness of error handling
56
+
57
+ **Expected Results:**
58
+ - Correctly include specified file types
59
+ - Correctly exclude unwanted files and directories
60
+ - Correctly process .gitignore rules
61
+ - Correctly handle multi-level directory structures
62
+ - Correctly handle non-existent directories
63
+
64
+ ### check-detail-result.test.mjs
65
+
66
+ Tests the content validation functionality of the `checkDetailResult` method.
67
+
68
+ **Test Content:**
69
+ - Verify approval of valid content (e.g., correct links)
70
+ - Verify rejection of content with dead links
71
+ - Verify rejection of content with incorrect table separators
72
+ - Verify approval of external links
73
+ - Verify correct reporting of multiple issues simultaneously
74
+
75
+ **Run Method:**
76
+ ```bash
77
+ node tests/check-detail-result.test.mjs
78
+ ```
79
+
80
+ **Test Scenarios:**
81
+ 1. Define a `structurePlan` with a list of valid internal link paths.
82
+ 2. Call `checkDetailResult` with various content strings that include:
83
+ - A valid internal link.
84
+ - An invalid or "dead" internal link.
85
+ - An incorrectly formatted Markdown table separator.
86
+ - A valid external (HTTP) link.
87
+ - A combination of the above issues.
88
+ 3. Assert the `isApproved` boolean and the `detailFeedback` string in the result.
89
+
90
+ **Expected Results:**
91
+ - `isApproved` is `true` if no issues are found.
92
+ - `isApproved` is `false` if any validation rule is violated.
93
+ - `detailFeedback` provides a descriptive message for each validation issue found.
@@ -0,0 +1,103 @@
1
+ import checkDetailResult from "../agents/check-detail-result.mjs";
2
+
3
+ async function runTests() {
4
+ function assert(condition, message) {
5
+ if (!condition) {
6
+ throw new Error(`Assertion failed: ${message}`);
7
+ }
8
+ }
9
+
10
+ async function testApproveValidContent() {
11
+ console.log("Testing: should approve valid content");
12
+ const structurePlan = [{ path: "/getting-started" }];
13
+ const content = "This is a test with a [valid link](/getting-started).";
14
+ const result = await checkDetailResult({ structurePlan, content });
15
+ assert(result.isApproved === true, "Should be approved");
16
+ assert(result.detailFeedback === "", "Feedback should be empty");
17
+ console.log("✅ Test passed: should approve valid content");
18
+ }
19
+
20
+ async function testRejectDeadLink() {
21
+ console.log("Testing: should reject content with a dead link");
22
+ const structurePlan = [{ path: "/getting-started" }];
23
+ const content = "This contains a [dead link](/dead-link).";
24
+ const result = await checkDetailResult({ structurePlan, content });
25
+ assert(result.isApproved === false, "Should not be approved");
26
+ assert(
27
+ result.detailFeedback.includes("Found a dead link"),
28
+ "Should report dead link"
29
+ );
30
+ console.log("✅ Test passed: should reject content with a dead link");
31
+ }
32
+
33
+ async function testRejectIncorrectTableSeparator() {
34
+ console.log(
35
+ "Testing: should reject content with incorrect table separator"
36
+ );
37
+ const structurePlan = [];
38
+ const content = "| Header | Header |\n| - | - |\n| Cell | Cell |";
39
+ const result = await checkDetailResult({ structurePlan, content });
40
+ assert(result.isApproved === false, "Should not be approved");
41
+ assert(
42
+ result.detailFeedback.includes("incorrect table separator"),
43
+ "Should report incorrect table separator"
44
+ );
45
+ console.log(
46
+ "✅ Test passed: should reject content with incorrect table separator"
47
+ );
48
+ }
49
+
50
+ async function testApproveExternalLink() {
51
+ console.log("Testing: should approve content with an external link");
52
+ const structurePlan = [];
53
+ const content = "This is a [valid external link](https://example.com).";
54
+ const result = await checkDetailResult({ structurePlan, content });
55
+ assert(result.isApproved === true, "Should be approved");
56
+ assert(result.detailFeedback === "", "Feedback should be empty");
57
+ console.log("✅ Test passed: should approve content with an external link");
58
+ }
59
+
60
+ async function testRejectMultipleIssues() {
61
+ console.log("Testing: should reject content with multiple issues");
62
+ const structurePlan = [{ path: "/getting-started" }];
63
+ const content =
64
+ "This has a [dead link](/dead-link) and an incorrect table: | - |.";
65
+ const result = await checkDetailResult({ structurePlan, content });
66
+ assert(result.isApproved === false, "Should not be approved");
67
+ assert(
68
+ result.detailFeedback.includes("Found a dead link"),
69
+ "Should report dead link"
70
+ );
71
+ assert(
72
+ result.detailFeedback.includes("incorrect table separator"),
73
+ "Should report incorrect table separator"
74
+ );
75
+ console.log("✅ Test passed: should reject content with multiple issues");
76
+ }
77
+
78
+ async function testApproveImageSyntax() {
79
+ console.log("Testing: should approve content with image syntax");
80
+ const structurePlan = [];
81
+ const content = "This is an image ![MCP Go Logo](/logo.png).";
82
+ const result = await checkDetailResult({ structurePlan, content });
83
+ assert(result.isApproved === true, "Should be approved");
84
+ assert(result.detailFeedback === "", "Feedback should be empty");
85
+ console.log("✅ Test passed: should approve content with image syntax");
86
+ }
87
+
88
+ try {
89
+ console.log("🚀 Starting checkDetailResult tests...");
90
+ await testApproveValidContent();
91
+ await testRejectDeadLink();
92
+ await testRejectIncorrectTableSeparator();
93
+ await testApproveExternalLink();
94
+ await testRejectMultipleIssues();
95
+ await testApproveImageSyntax();
96
+ console.log("🎉 All tests passed!");
97
+ } catch (error) {
98
+ console.error("❌ Test failed:", error.message);
99
+ process.exit(1);
100
+ }
101
+ }
102
+
103
+ runTests();