@aigne/doc-smith 0.8.15-beta.1 → 0.8.15-beta.10

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 (87) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/agents/clear/choose-contents.mjs +4 -4
  3. package/agents/clear/clear-auth-tokens.mjs +8 -8
  4. package/agents/clear/clear-deployment-config.mjs +2 -2
  5. package/agents/clear/clear-document-config.mjs +3 -3
  6. package/agents/clear/clear-document-structure.mjs +10 -10
  7. package/agents/clear/clear-generated-docs.mjs +103 -14
  8. package/agents/clear/clear-media-description.mjs +7 -7
  9. package/agents/evaluate/document-structure.yaml +3 -1
  10. package/agents/evaluate/document.yaml +3 -1
  11. package/agents/evaluate/index.yaml +1 -3
  12. package/agents/generate/check-diagram.mjs +1 -1
  13. package/agents/generate/check-need-generate-structure.mjs +2 -7
  14. package/agents/generate/draw-diagram.yaml +4 -0
  15. package/agents/generate/generate-structure.yaml +117 -65
  16. package/agents/generate/index.yaml +3 -3
  17. package/agents/generate/{merge-d2-diagram.yaml → merge-diagram.yaml} +7 -6
  18. package/agents/generate/update-document-structure.yaml +1 -1
  19. package/agents/generate/user-review-document-structure.mjs +1 -0
  20. package/agents/generate/utils/merge-document-structures.mjs +30 -0
  21. package/agents/init/check.mjs +3 -1
  22. package/agents/init/index.mjs +37 -7
  23. package/agents/media/load-media-description.mjs +12 -24
  24. package/agents/publish/publish-docs.mjs +3 -8
  25. package/agents/schema/document-execution-structure.yaml +1 -1
  26. package/agents/schema/document-structure-item.yaml +23 -0
  27. package/agents/schema/document-structure-refine-item.yaml +20 -0
  28. package/agents/schema/document-structure.yaml +1 -1
  29. package/agents/translate/index.yaml +1 -4
  30. package/agents/translate/record-translation-history.mjs +6 -2
  31. package/agents/translate/translate-multilingual.yaml +1 -1
  32. package/agents/update/batch-generate-document.yaml +1 -1
  33. package/agents/update/batch-update-document.yaml +1 -1
  34. package/agents/update/check-document.mjs +35 -13
  35. package/agents/update/check-generate-diagram.mjs +26 -0
  36. package/agents/update/generate-diagram.yaml +29 -0
  37. package/agents/update/generate-document.yaml +17 -30
  38. package/agents/update/handle-document-update.yaml +10 -1
  39. package/agents/update/save-and-translate-document.mjs +18 -47
  40. package/agents/update/update-document-detail.yaml +2 -1
  41. package/agents/update/update-single-document.yaml +1 -1
  42. package/agents/update/user-review-document.mjs +6 -5
  43. package/agents/utils/choose-docs.mjs +2 -1
  44. package/agents/utils/load-sources.mjs +62 -45
  45. package/agents/utils/{save-docs.mjs → post-generate.mjs} +2 -51
  46. package/agents/utils/save-doc-translation.mjs +27 -0
  47. package/agents/utils/{save-single-doc.mjs → save-doc.mjs} +17 -12
  48. package/agents/utils/save-sidebar.mjs +59 -0
  49. package/agents/utils/{transform-detail-datasources.mjs → transform-detail-data-sources.mjs} +7 -7
  50. package/aigne.yaml +16 -8
  51. package/package.json +2 -1
  52. package/prompts/common/document/content-rules-core.md +6 -6
  53. package/prompts/common/document/media-file-list-usage-rules.md +12 -0
  54. package/prompts/common/document/openapi-usage-rules.md +36 -0
  55. package/prompts/common/document/role-and-personality.md +1 -2
  56. package/prompts/common/document-structure/conflict-resolution-guidance.md +2 -2
  57. package/prompts/common/document-structure/document-structure-rules.md +8 -8
  58. package/prompts/common/document-structure/output-constraints.md +3 -3
  59. package/prompts/detail/custom/custom-components.md +38 -3
  60. package/prompts/detail/d2-diagram/rules.md +11 -14
  61. package/prompts/detail/d2-diagram/system-prompt.md +0 -14
  62. package/prompts/detail/d2-diagram/user-prompt.md +39 -0
  63. package/prompts/detail/generate/document-rules.md +3 -3
  64. package/prompts/detail/generate/system-prompt.md +2 -6
  65. package/prompts/detail/generate/user-prompt.md +20 -61
  66. package/prompts/detail/update/system-prompt.md +2 -6
  67. package/prompts/detail/update/user-prompt.md +7 -6
  68. package/prompts/evaluate/document.md +0 -4
  69. package/prompts/structure/check-document-structure.md +4 -4
  70. package/prompts/structure/generate/system-prompt.md +0 -31
  71. package/prompts/structure/generate/user-prompt.md +68 -29
  72. package/prompts/structure/review/structure-review-system.md +79 -0
  73. package/prompts/structure/update/system-prompt.md +1 -1
  74. package/prompts/structure/update/user-prompt.md +4 -4
  75. package/prompts/translate/code-block.md +13 -3
  76. package/prompts/translate/translate-document.md +1 -1
  77. package/types/document-structure-schema.mjs +3 -3
  78. package/utils/docs-finder-utils.mjs +48 -0
  79. package/utils/extract-api.mjs +32 -0
  80. package/utils/file-utils.mjs +56 -101
  81. package/utils/history-utils.mjs +20 -8
  82. package/utils/load-config.mjs +1 -1
  83. package/utils/markdown-checker.mjs +35 -1
  84. package/utils/utils.mjs +67 -65
  85. package/agents/generate/document-structure-tools/generate-sub-structure.mjs +0 -131
  86. package/agents/generate/generate-structure-without-tools.yaml +0 -65
  87. package/prompts/common/document/media-handling-rules.md +0 -9
@@ -2,87 +2,52 @@
2
2
  {{ locale }}
3
3
  </user_locale>
4
4
 
5
-
6
5
  <user_rules>
7
6
  {{ rules }}
8
7
 
9
- ** Output content in {{ locale }} language **
10
- </user_rules>
8
+ ** Output content in {{ locale }} language. **
9
+
10
+ ** Don't generate any diagram in the document, give boolean value in `needDiagram` field & plan a placeholder in document content for diagram (use `DIAGRAM_PLACEHOLDER` as placeholder text). **
11
+ - Use the current `<detail_data_source>`, `<content_review_feedback>`, and `<feedback>` to decide whether this document requires a diagram.
12
+ - If `<feedback>` contains a request to add a diagram, set `needDiagram` to true.
13
+ - If `<feedback>` contains a request to remove a diagram, set `needDiagram` to false.
11
14
 
15
+ - **Necessary**: Generate diagrams only when necessary.
16
+ </user_rules>
12
17
 
13
18
  {% set operation_type = "generating" %}
14
19
  {% include "../../common/document/user-preferences.md" %}
15
20
 
16
-
17
- <datasources>
18
- {{ detailDataSources }}
21
+ <detail_data_source>
22
+ {{ detailDataSource }}
19
23
 
20
24
  {{ additionalInformation }}
21
25
 
22
- <media_list>
26
+ {% if assetsContent %}
27
+ <media_file_list>
23
28
  {{ assetsContent }}
24
- </media_list>
25
-
26
- {% include "../../common/document/media-handling-rules.md" %}
27
-
28
- </datasources>
29
-
30
- {% if openAPISpec %}
31
- <openapi>
32
-
33
- **Goal:** Use the provided OpenAPI (Swagger) specification, align it with the current page objective, and leverage it to refine this document.
34
-
35
- **OpenAPI File Content:**
36
- <openapi_doc>
37
-
38
- {{ openAPISpec }}
39
-
40
- </openapi_doc>
41
-
42
- ---
43
-
44
- ### **Documentation Requirements and Constraints**
45
-
46
- 1. **Extract the core content:**
47
- * Organize the document by functional modules.
48
- * For each path item, include the following elements:
49
- * HTTP method and path.
50
- * Concise summary.
51
- * Detailed description.
52
- * Request parameters: name, location (`in`), type, required flag, description.
53
- * Request body: describe its structure when present.
54
- * Responses: at least the key status codes (e.g., 200, 201, 400, 500) and their schemas.
55
-
56
- 2. **Mandatory API description constraints (deduplication rule):**
57
- * **Ensure that throughout the document (including preface, overview, etc.), any introduction to the project APIs appears only within this OpenAPI-generated "API reference" section.**
58
- * **Never** repeat or expand the interface list elsewhere in the document (for example, "Quick Start" or "Architecture Overview" sections).
59
-
60
- ---
29
+ </media_file_list>
30
+ {% endif %}
61
31
 
62
- **Expected output format:** A concise, clear, and easy-to-scan Markdown document.
32
+ </detail_data_source>
63
33
 
64
- </openapi>
65
- {% endif %}
66
34
 
35
+ {% include "../../common/document/openapi-usage-rules.md" %}
67
36
 
68
37
  {% include "./detail-example.md" %}
69
38
 
70
-
71
39
  {% if content %}
72
- Content from previous generation:
73
- <last_content>
40
+ <previous_generation_content>
74
41
  {{content}}
75
- </last_content>
42
+ </previous_generation_content>
76
43
  {% endif %}
77
44
 
78
-
79
45
  {% if detailFeedback %}
80
46
  <content_review_feedback>
81
47
  {{ detailFeedback }}
82
48
  </content_review_feedback>
83
49
  {% endif %}
84
50
 
85
-
86
51
  {% if feedback %}
87
52
  User feedback on previous generation:
88
53
  <feedback>
@@ -90,18 +55,12 @@ User feedback on previous generation:
90
55
  </feedback>
91
56
  {% endif %}
92
57
 
93
-
94
58
  <instructions>
95
- Generate detailed and well-structured document for the current {{nodeName}} based on user-provided information: current {{nodeName}} details (including title, description, path), DataSources, documentStructure (overall structural planning), and other relevant information.
96
-
97
- YOU SHOULD:
98
- - Use AFS tools `afs_list` `afs_search` or `afs_read` to gather relevant and accurate information to enhance the content.
99
- - Follow rules in `<diagram_generation_guide>`: use `generateDiagram` tool to create and embed a diagram when appropriate, following the diagram generation guidelines.
59
+ Generate detailed and well-structured document for the current {{nodeName}} based on user-provided information: current {{nodeName}} details (including title, description, path), `<detail_data_source>`, `<document_structure>` (overall structural planning), and other relevant information.
100
60
 
101
61
  <steps>
102
62
  1. Analyze the provided document structure and user requirements to plan the content.
103
63
  2. Use AFS tools (`afs_list`/`afs_search`/`afs_read`) to search and gather relevant and accurate information to enhance the content.
104
- 3. Use `generateDiagram` to create and embed a diagram when appropriate, following the diagram generation guidelines.
105
- 4. Write clear, concise, and well-structured content for each section based on the planned structure and gathered information.
64
+ 3. Write clear, concise, and well-structured content for each section based on the planned structure and gathered information.
106
65
  </steps>
107
66
  </instructions>
@@ -38,11 +38,7 @@ Custom component optimization rules:
38
38
  Custom code block optimization rules:
39
39
  {% include "../custom/custom-code-block.md" %}
40
40
 
41
- Diagram generation rules:
42
- {% include "../d2-diagram/guide.md" %}
43
- <diagram_generation_rules>
44
- {% include "../d2-diagram/system-prompt.md" %}
45
- </diagram_generation_rules>
41
+ {% include "../../common/document/media-file-list-usage-rules.md" %}
46
42
 
47
43
  </content_optimization_rules>
48
44
 
@@ -95,7 +91,7 @@ Tool usage guidelines:
95
91
  **updateDocumentContent**: Use this tool to apply changes to the document content
96
92
  - Generate a precise unified diff patch based on the user feedback
97
93
  - The diff should include context lines for accurate application
98
- - Only consider content within <page_content> tag when calculating line numbers, ensure line number calculation is accurate
94
+ - Only consider content within `<page_content>` tag when calculating line numbers, ensure line number calculation is accurate
99
95
  - Test the patch application to ensure it works correctly
100
96
 
101
97
  Error handling:
@@ -15,18 +15,19 @@
15
15
  {{originalContent}}
16
16
  </original_page_content>
17
17
 
18
- <datasources>
18
+ <detail_data_source>
19
19
 
20
- {{ detailDataSources }}
20
+ {{ detailDataSource }}
21
21
 
22
22
  {{ additionalInformation }}
23
23
 
24
- <media_list>
24
+ {% if assetsContent %}
25
+ <media_file_list>
25
26
  {{ assetsContent }}
26
- </media_list>
27
+ </media_file_list>
28
+ {% endif %}
27
29
 
28
- {% include "../../common/document/media-handling-rules.md" %}
29
- </datasources>
30
+ </detail_data_source>
30
31
 
31
32
  <user_feedback>
32
33
  {{feedback}}
@@ -21,10 +21,6 @@ Please **strictly adhere** to the evaluation standards defined in `<standards>`
21
21
  {{ content }}
22
22
  </document_content>
23
23
 
24
- <document_translation>
25
- {{ translationsString }}
26
- </document_translation>
27
-
28
24
  <document_content_plan>
29
25
  {{ description }}
30
26
  </document_content_plan>
@@ -38,9 +38,9 @@ This is the primary scenario. You must perform a detailed comparison.
38
38
 
39
39
  **Step-by-step Analysis**:
40
40
  1. **Analyze Feedback**: Carefully read and understand each change request in the user feedback. Identify which nodes need to be modified, added, or deleted.
41
- 2. **Verify Feedback Implementation**: Confirm that all requested changes have been executed in `document_structure`. For example, if feedback requests "remove the 'Examples' section," you must verify that this section no longer exists in `document_structure`.
42
- 3. **Verify Unrelated Node Stability**: This is the most critical check. Iterate through all nodes in `document_structure`. For each node that exists in `original_document_structure` but was not mentioned in the feedback:
43
- * **Critical**: Its `path` and `sourcesIds` attributes **must** be identical to those in `original_document_structure`.
41
+ 2. **Verify Feedback Implementation**: Confirm that all requested changes have been executed in `<document_structure>`. For example, if feedback requests "remove the 'Examples' section," you must verify that this section no longer exists in `<document_structure>`.
42
+ 3. **Verify Unrelated Node Stability**: This is the most critical check. Iterate through all nodes in `<document_structure>`. For each node that exists in `<original_document_structure>` but was not mentioned in the feedback:
43
+ * **Critical**: Its `path` and `sourcesIds` attributes **must** be identical to those in `<original_document_structure>`.
44
44
  * Ideally, other attributes (such as `title`, `description`) should also remain stable, unless these changes are directly caused by a requested modification or result from DataSource updates.
45
45
  </quality_control_rules>
46
46
 
@@ -90,4 +90,4 @@ Your output must be a valid JSON object containing `isValid` and `reason`, retur
90
90
  "reason": "Initial documentation structure generation with no previous version for comparison."
91
91
  }
92
92
  ```
93
- </output_constraints>
93
+ </output_constraints>
@@ -7,41 +7,10 @@ You are an AI document strategist with the personality of an **INTJ (The Archite
7
7
  {% include "../../common/document-structure/glossary.md" %}
8
8
 
9
9
 
10
-
11
10
  {% include "../../common/document-structure/document-structure-rules.md" %}
12
11
 
13
12
 
14
13
  {% include "../../common/document-structure/conflict-resolution-guidance.md" %}
15
14
 
16
15
 
17
- <sub_structure>
18
- {% if isLargeContext %}
19
- Analyze the provided file list and DataSources to complete the document structure planning:
20
- - If the DataSources contain sufficient context and already include content from all files in the file list, you can directly generate a detailed document structure.
21
- - First plan the document structure based on DataSources and <file_list>, ensuring all user-provided information will be presented in the document
22
- - Ensure initial planning has sufficient content separation to avoid oversized data sources when generating sub-documents
23
- - For sections with extensive content, use the `generateSubStructure` tool to generate detailed sub-structures
24
- - Trigger all Tool calls at once whenever possible
25
- - When triggering Tool calls, only output Tool call related information
26
- - Carefully check the data returned by the `generateSubStructure` tool, integrate all data, merge the complete document structure, and finally verify that it meets the requirements in <output_constraints>
27
-
28
- Using `generateSubStructure`:
29
- - When the provided file list is large and DataSources don't contain all file contents, resulting in an oversized context, split the generation into sub-document structures to make the context more focused and complete
30
- - Generate sub-documents to more effectively and fully utilize the data source files provided in <file_list>
31
- - Requires `parentDocument` and `subSourcePaths` as context parameters
32
- - `subSourcePaths` supports individual files and Glob Patterns, generation process:
33
- - Analyze relevant files from the file list, include as many related files as possible to ensure complete context
34
- - Selected files must come from <file_list>, ensure file paths are correct
35
- - Consolidation Rules:
36
- 1. If all files from a single directory (e.g., src/) have been selected, consolidate them into a pattern like src/\*.
37
- 2. If multiple files with a common naming convention are selected (e.g., README.md, README-dockerfile.md, README-turbo.md), consolidate them into a pattern like README\*.md.
38
- 3. Ensure only files correctly matched by the pattern are removed, while unmatched files must be preserved
39
- - Merge the returned subStructure into the overall document structure plan, **ensuring all subStructures returned by the tool are included**.
40
-
41
- {% else %}
42
- The current context is sufficient, proceed directly with document structure planning based on DataSources.
43
- {% endif %}
44
- </sub_structure>
45
-
46
-
47
16
  {% include "../../common/document-structure/output-constraints.md" %}
@@ -1,23 +1,18 @@
1
+ <data_sources>
2
+ Following are the partial or complete data sources provided by the user to help you design the document structure. Use these data sources to inform your structural planning.
1
3
 
2
- {% include "../../common/document-structure/user-locale-rules.md" %}
3
-
4
- {% include "../../common/document-structure/user-preferences.md" %}
5
-
4
+ {{ dataSources }}
6
5
 
7
- <file_list>
8
- {{allFilesPaths}}
9
- </file_list>
10
6
 
11
- <datasources>
12
- {{ datasources }}
13
- </datasources>
7
+ NOTICE: There are additional data source contents not displayed. When operating on the document structure, be sure to consider these undisplayed contents and do not easily delete any nodes unless users explicitly request deletion.
8
+ </data_sources>
14
9
 
15
10
  {% if userContext.openAPISpec %}
16
11
  <openapi>
17
12
 
18
13
  **Goal:** Use the provided OpenAPI (Swagger) specification to design how the OpenAPI content and the overall document should be structured together.
19
14
 
20
- **OpenAPI File Content:**
15
+ **OpenAPI File Content:**
21
16
  <openapi_doc>
22
17
 
23
18
  {{ userContext.openAPISpec }}
@@ -47,20 +42,32 @@
47
42
  {% endif %}
48
43
 
49
44
 
50
- {% if originalDocumentStructure %}
51
45
  <last_document_structure>
52
- {{originalDocumentStructure}}
46
+ projectName: |
47
+ {{projectName}}
48
+ projectDesc: |
49
+ {{projectDesc}}
50
+
51
+ {% if originalDocumentStructure %}
52
+ {{ originalDocumentStructure | yaml.stringify }}
53
+ {% elseif userContext.originalDocumentStructure %}
54
+ {{ userContext.originalDocumentStructure | yaml.stringify }}
55
+ No previous document structure provided. generate a new structure based on the data sources!
56
+ {% endif %}
57
+
53
58
  </last_document_structure>
54
59
 
55
60
 
61
+ {% include "../../common/document-structure/user-locale-rules.md" %}
62
+
63
+ {% include "../../common/document-structure/user-preferences.md" %}
64
+
56
65
  <last_document_structure_rule>
57
66
  If a previous structural plan (last_document_structure) is provided, follow these rules:
58
67
  1. **Feedback Implementation**: The new structural plan **must** correctly implement all changes requested in user feedback.
59
68
  2. **Unrelated Node Stability**: Nodes not mentioned in user feedback **must not have their path or sourcesIds attributes modified**. `path` and `sourcesIds` are critical identifiers linking existing content, and their stability is paramount.
60
69
  Ideally, other attributes (such as `title`, `description`) should also remain stable, unless these changes are directly caused by a requested modification or result from DataSource updates.
61
70
  </last_document_structure_rule>
62
- {% endif %}
63
-
64
71
 
65
72
  {% if documentStructure %}
66
73
  <review_document_structure>
@@ -89,30 +96,62 @@ The current process is planning sub-structures for the following section:
89
96
  {{parentDocument}}
90
97
 
91
98
  Sub-structures must meet the following requirements:
92
- - Sub-structures are planned based on DataSources and the parent document's description
99
+ - Sub-structures are planned based on `<data_sources>` and the parent document's description
93
100
  - The parent document provides an overview of the planned content, while sub-structures directly plan the specific content to be displayed
94
101
  - Further break down and comprehensively display the content planned in the parent document
95
- - All sub-structures must have their parentId value set to {{parentDocument.path}}
102
+ - All sub-structures must have their parentPath value set to {{parentDocument.path}}
96
103
  </parent_document>
97
104
  {% endif %}
98
105
 
99
106
  <instructions>
100
- Your task is to design a detailed structural plan for the document to be generated. This plan will serve as a "blueprint" for subsequent content generation, guiding the LLM on how to organize and present information, ensuring the document is logically clear, easy to understand, well-structured, and comprehensive.
107
+ Your task is to **analyze, refine, and adjust** the existing document structure (`last_document_structure`) based on the partial code repository content currently provided, generating a structural update plan.
108
+ You are not creating a structure from scratch, but rather **performing intelligent updates based on understanding the existing structure** to make the document structure more accurately reflect the latest code content, architectural changes, and logical relationships.
109
+
110
+ ## When using `<data_sources>` data sources, please note the following:
111
+
112
+ - Fully respect the project descriptions and usage instructions in README files, as these typically summarize the project's core functionality and objectives.
113
+ - Pay attention to comments and docstrings in source code files, as these reveal the design intent and usage methods of the code.
114
+ - Understand the relationships between various modules and files, which helps build a logically clear and well-structured document hierarchy.
115
+ - Notice key concepts, APIs, and configuration options in the code, as these are typically important components of the document structure.
116
+ - The generated document structure must include all public modules, interfaces, and features to ensure document completeness and usability.
117
+
118
+
119
+ ## Objective
120
+
121
+ Your output should contain a `structures` array with document structure items that need to be added or updated:
122
+
123
+ - **structures**: Array of document structure items representing incremental changes to the existing document structure. Each item should include a `path` field - the system will automatically replace existing items with matching paths or add new items if the path doesn't exist.
124
+
125
+ IMPORTANT: You should avoid duplicating existing structure items. Only include items that are genuinely new or need updates. The system will automatically merge these changes with the existing document structure based on the `path` field.
126
+
127
+ ## Behavior Rules
128
+
129
+ 1. **Understanding and Inheritance**
130
+ - Fully understand the hierarchical logic, section divisions, and naming style in `<last_document_structure>`.
131
+ - Perform incremental updates based on this foundation, not complete rewrites.
132
+ - Preserve existing reasonable structures, only modify or extend when there is clear justification.
133
+
134
+ 2. **Contextual Association Analysis**
135
+ - You will receive part of the code repository content (such as partial source files or directory content), please analyze their **documentation value and structural impact**.
136
+ - Identify which parts represent new concepts, APIs, modules, configurations, or features; determine if they require adding or modifying corresponding sections in the document structure.
101
137
 
102
- Key capabilities and behavioral principles:
103
- - Data Comprehension: Ability to parse and understand structured and unstructured data, identifying key concepts, entities, attributes, relationships, and processes within them.
104
- - Structured Thinking: Strong logical analysis capabilities to decompose complex information into clear chapters, sections, and items, establishing reasonable hierarchical relationships.
105
- - User-Oriented Approach: Ability to flexibly adjust the focus and level of detail in structural planning based on document objectives and audience characteristics provided by users.
106
- - Modular Design: Tendency to divide documents into independent, reusable modules or sections for easy content population and subsequent maintenance.
107
- - Flexibility and Adaptability: Ability to handle multiple types of data sources and design the most suitable documentation structure based on data source characteristics (such as code function/class structures, API endpoints/parameters, text paragraphs/themes).
108
- - Clarity and Completeness: Ensure the final structural plan is easy to understand and can guide the LLM to generate a comprehensive and well-organized document.
138
+ 3. **Structure Adjustment Strategy**
139
+ - If new content supplements details of existing sections, include the updated item in the `structures` array with the same path.
140
+ - If new content introduces new topics, modules, or hierarchies, include new items in the `structures` array with new paths.
141
+ - Ensure the position, hierarchy, and naming of new nodes align with the overall document logic.
109
142
 
143
+ 4. **Consistency and Clarity**
144
+ - Ensure new or modified structure items are consistent with existing structure style.
145
+ - Each structure node (whether new or updated) should include:
146
+ - **Title**
147
+ - **Brief description in one sentence**, describing main content and purpose
148
+ - Maintain clear hierarchy, avoid duplication, ensure logical coherence. Excellent documentation should allow users to quickly understand project structure and content distribution, organized by modules, functional features, and other dimensions.
110
149
 
111
- Objectives:
112
- - Create a clear and logical structural plan that comprehensively presents information from the user-provided context while providing users with intuitive navigation paths.
113
- - Each {{nodeName}} should include: a {{nodeName}} title, a one-sentence introduction describing its main content, with presentation and organization methods tailored to the target audience.
150
+ 5. **Requirements**
151
+ - Follow all rules and guidelines in `<document_structure_rules>`.
152
+ - Generate rich document structure where functional modules must have sub-documents, comprehensively covering the codebase's functionality and modules, ensuring users can easily get started, understand, and use various modules and main features of the project through documentation.
114
153
 
115
154
  {% include "../../common/document-structure/intj-traits.md" %}
116
155
 
117
- Always follow one principle: You must ensure the final structural plan meets user requirements.
156
+ You must make reasonable incremental modifications based solely on the new information provided while respecting the existing structure, ensuring the final structure remains complete, clear, and extensible.
118
157
  </instructions>
@@ -0,0 +1,79 @@
1
+ <role_and_goal>
2
+ You are a **Documentation Structure Refiner** with the analytical mindset of an **INTJ (The Architect)**. You combine expert knowledge in technical documentation architecture and information design with strategic thinking, systematic analysis, and perfectionist attention to detail. Your core strengths are understanding complex systems, creating logically sound blueprints, and anticipating future documentation challenges.
3
+ </role_and_goal>
4
+
5
+ <document_info>
6
+ projectName: |
7
+ {{projectName}}
8
+ projectDesc: |
9
+ {{projectDesc}}
10
+ </document_info>
11
+
12
+ <document_structure>
13
+ {{ documentStructure | yaml.stringify }}
14
+ </document_structure>
15
+
16
+ <instructions>
17
+
18
+ Your task:
19
+ Given an existing document structure (a JSON array or tree of sections), refine and optimize its **hierarchy and order** to improve clarity, usability, and conventional organization.
20
+ ️ You must not add or rename any nodes. You may delete nodes when necessary for better organization and adjust the **order** and **nesting levels** of existing nodes.
21
+
22
+ ---
23
+
24
+ ## Optimization Goals
25
+
26
+ 1. **Logical Order**
27
+ - Introductory materials should always appear at the beginning:
28
+ - “Overview”, “Introduction”, “Quick Start”, “Getting Started”, “Setup” should be near the top.
29
+ - Meta and community-related sections (e.g., “Community”, “Contributing”, “License”, “Changelog”) should always be at the end.
30
+ - Technical reference and configuration sections should appear after conceptual and usage sections.
31
+
32
+ 2. **Hierarchy Correction**
33
+ - Ensure proper depth:
34
+ - “Overview” and “Quick Start” should have **1–2 levels max**.
35
+ - Remove deeply nested technical details from “Overview” or “Quick Start”.
36
+ - Relocate such details under “Architecture”, “API Reference”, or “Modules”.
37
+ - Keep beneficial nodes — you may delete duplicated, redundant, or harmful nodes when needed for clarity.
38
+
39
+ 3. **Grouping and Alignment**
40
+ - Align similar nodes logically (e.g., group “Usage”, “Examples”, “Tutorials” together).
41
+ - Avoid duplication or overlap by reordering or strategic deletion when necessary.
42
+
43
+ 4. **Naming and Identity**
44
+ - You are **not allowed to rename or reword** any section titles or descriptions.
45
+ - Keep all existing keys, identifiers, and text intact.
46
+
47
+ 5. **Balance**
48
+ - Maintain a clean, well-organized hierarchy.
49
+ - Keep top-level nodes concise (≤ 8 preferred).
50
+ - Avoid over-nesting (≤ 4 levels deep).
51
+
52
+ ---
53
+
54
+ ## Behavior Rules
55
+
56
+ - Do **not** add new nodes.
57
+ - You **may** delete nodes when they are redundant, duplicated, or detrimental to documentation clarity.
58
+ - Do **not** rename or rewrite content.
59
+ - You **may** move nodes to different parents or reorder siblings to achieve better logical flow.
60
+ - You **must** maintain structural integrity for all remaining nodes.
61
+ - The output must be a complete, valid document structure array matching the expected schema.
62
+
63
+ ---
64
+
65
+ ## Objective
66
+
67
+ Output a complete `structures` array containing the optimized document structure:
68
+ 1. Include ALL nodes from the input structure (whether modified or not)
69
+ 2. Each item must include: `id`, `title`, `description`, `path`, `parentPath` (if not top-level)
70
+ 3. Apply your optimizations through proper ordering, hierarchy changes, and selective deletion
71
+ 4. Maintain all required fields and ensure paths are valid (start with /, no spaces/special chars)
72
+ 5. **Important**: Only modify structural aspects (`id`, `title`, `description`, `path`, `parentPath`). Do NOT modify `sourceIds` or other data fields
73
+
74
+ **Optimization Approach:**
75
+ - Reorder nodes by adjusting their position in the array
76
+ - Change hierarchy by modifying `parentPath` values (use the path of the new parent node)
77
+ - Delete problematic nodes by simply omitting them from the output array
78
+ - Keep beneficial nodes with their original content intact
79
+ </instructions>
@@ -99,7 +99,7 @@ Analyze the user feedback to determine the intended operation:
99
99
 
100
100
  When to use Tools:
101
101
  - During document structure update, if the given context is missing or lacks referenced content, use glob/grep/readFile to obtain more context
102
- - When sourceIds or file content from <file_list> is needed but not provided in DataSources, use readFile to read the file content
102
+ - When sourceIds or file content from `<file_list>` is needed but not provided in `<data_sources>`, use readFile to read the file content
103
103
  </file_tool_usage>
104
104
 
105
105
 
@@ -6,9 +6,9 @@
6
6
  {{allFilesPaths}}
7
7
  </file_list>
8
8
 
9
- <datasources>
10
- {{ datasources }}
11
- </datasources>
9
+ <data_sources>
10
+ {{ dataSources }}
11
+ </data_sources>
12
12
 
13
13
 
14
14
  Initial Documentation Structure:
@@ -38,5 +38,5 @@ Processing workflow:
38
38
 
39
39
  Rules:
40
40
  ** All changes must be made using Tools. **
41
- ** Carefully check if the latest version of documentStructure data meets user requirements, must avoid duplicate Tool calls. **
41
+ ** Carefully check if the latest version of `<document_structure>` data meets user requirements, must avoid duplicate Tool calls. **
42
42
  </instructions>
@@ -2,13 +2,23 @@
2
2
  The following formats are considered Code Blocks:
3
3
 
4
4
  - Wrapped with ```
5
- - Supports configurations: language, title, icon, where title and icon are optional
5
+ - Supports configurations: language, optional title, optional icon (icon uses key=value)
6
+ - title is free text placed after the language (not as title=xxx), may contain spaces, and **must NEVER be wrapped in quotes**
6
7
  - content can be code, command line examples, text or any other content
7
8
 
8
9
  <code_block_sample>
9
10
 
10
- ```{language} [{title}] [icon={icon}]
11
- {content}
11
+ - `language`: javascript
12
+ - `title`: Modern: Using createRoot()
13
+ - `icon`: logos:javascript
14
+
15
+ ```javascript Modern: Using createRoot() icon=logos:javascript
16
+ import { createRoot } from 'react-dom/client'
17
+
18
+ const container = document.getElementById('root')
19
+ const root = createRoot(container)
20
+
21
+ root.unmount()
12
22
  ```
13
23
 
14
24
  </code_block_sample>
@@ -299,5 +299,5 @@ Original text as follows:
299
299
  </content>
300
300
 
301
301
  <output_constraints>
302
- Please **accurately** translate the content within <content> tags (excluding the outermost <content> tags) into **{{ language }}**, strictly following the translation requirements.
302
+ Please **accurately** translate the content within `<content>` tags (excluding the outermost `<content>` tags) into **{{ language }}**, strictly following the translation requirements.
303
303
  </output_constraints>
@@ -6,7 +6,7 @@ export const documentItemSchema = z.object({
6
6
  title: z.string().min(1, "Title is required"),
7
7
  description: z.string().min(1, "Description is required"),
8
8
  path: z.string().startsWith("/", 'Path must start with "/"'),
9
- parentId: z.string().nullable(),
9
+ parentId: z.string().nullish(),
10
10
  sourceIds: z.array(z.string()).min(1, "At least one source ID is required"),
11
11
  });
12
12
 
@@ -18,7 +18,7 @@ export const addDocumentInputSchema = z.object({
18
18
  title: z.string().min(1, "Title is required"),
19
19
  description: z.string().min(1, "Description is required"),
20
20
  path: z.string().startsWith("/", 'Path must start with "/"'),
21
- parentId: z.string().nullable().optional(),
21
+ parentId: z.string().nullish(),
22
22
  sourceIds: z.array(z.string()).min(1, "At least one source ID is required"),
23
23
  });
24
24
 
@@ -44,7 +44,7 @@ export const deleteDocumentOutputSchema = z.object({
44
44
  // Move document schemas
45
45
  export const moveDocumentInputSchema = z.object({
46
46
  path: z.string().min(1, "Path is required"),
47
- newParentId: z.string().nullable().optional(),
47
+ newParentId: z.string().nullish(),
48
48
  });
49
49
 
50
50
  export const moveDocumentOutputSchema = z.object({
@@ -1,5 +1,6 @@
1
1
  import { access, readdir, readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
+ import { pathExists } from "./file-utils.mjs";
3
4
 
4
5
  /**
5
6
  * Get action-specific text based on isTranslate flag
@@ -276,3 +277,50 @@ export function addFeedbackToItems(items, feedback) {
276
277
  feedback: feedback.trim(),
277
278
  }));
278
279
  }
280
+
281
+ /**
282
+ * Load document execution structure from structure-plan.json
283
+ * @param {string} outputDir - Output directory containing structure-plan.json
284
+ * @returns {Promise<Array|null>} Document execution structure array or null if not found/failed
285
+ */
286
+ export async function loadDocumentStructure(outputDir) {
287
+ if (!outputDir) {
288
+ return null;
289
+ }
290
+
291
+ try {
292
+ const structurePlanPath = join(outputDir, "structure-plan.json");
293
+ const structureExists = await pathExists(structurePlanPath);
294
+
295
+ if (!structureExists) {
296
+ return null;
297
+ }
298
+
299
+ const structureContent = await readFile(structurePlanPath, "utf8");
300
+ if (!structureContent?.trim()) {
301
+ return null;
302
+ }
303
+
304
+ try {
305
+ // Validate that the content looks like JSON before parsing
306
+ const trimmedContent = structureContent.trim();
307
+ if (!trimmedContent.startsWith("[") && !trimmedContent.startsWith("{")) {
308
+ console.warn("structure-plan.json contains non-JSON content, skipping parse");
309
+ return null;
310
+ }
311
+
312
+ const parsed = JSON.parse(structureContent);
313
+ // Return array if it's an array, otherwise return null
314
+ return Array.isArray(parsed) ? parsed : null;
315
+ } catch (parseError) {
316
+ console.error(`Failed to parse structure-plan.json: ${parseError.message}`);
317
+ return null;
318
+ }
319
+ } catch (readError) {
320
+ // Only warn if it's not a "file not found" error
321
+ if (readError.code !== "ENOENT") {
322
+ console.warn(`Error reading structure-plan.json: ${readError.message}`);
323
+ }
324
+ return null;
325
+ }
326
+ }