@aigne/doc-smith 0.8.11-beta → 0.8.11-beta.2

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 (257) hide show
  1. package/.aigne/doc-smith/config.yaml +2 -0
  2. package/.aigne/doc-smith/output/structure-plan.json +3 -3
  3. package/.aigne/doc-smith/upload-cache.yaml +252 -0
  4. package/.github/workflows/publish-docs.yml +67 -0
  5. package/.release-please-manifest.json +1 -1
  6. package/CHANGELOG.md +22 -0
  7. package/README.md +45 -115
  8. package/agents/clear/choose-contents.mjs +170 -0
  9. package/agents/clear/clear-auth-tokens.mjs +111 -0
  10. package/agents/clear/clear-document-config.mjs +39 -0
  11. package/agents/clear/clear-document-structure.mjs +106 -0
  12. package/agents/clear/clear-generated-docs.mjs +51 -0
  13. package/agents/clear/index.yaml +23 -0
  14. package/agents/evaluate/code-snippet.mjs +93 -0
  15. package/agents/evaluate/document-structure.yaml +70 -0
  16. package/agents/evaluate/document.yaml +79 -0
  17. package/agents/evaluate/generate-report.mjs +78 -0
  18. package/agents/evaluate/index.yaml +39 -0
  19. package/agents/generate/document-structure-tools/add-document.mjs +56 -0
  20. package/agents/generate/document-structure-tools/delete-document.mjs +49 -0
  21. package/agents/generate/document-structure-tools/move-document.mjs +82 -0
  22. package/agents/generate/document-structure-tools/update-document.mjs +50 -0
  23. package/agents/generate/generate-structure.yaml +1 -1
  24. package/agents/generate/update-document-structure.yaml +42 -0
  25. package/agents/generate/user-review-document-structure.mjs +6 -4
  26. package/agents/init/index.mjs +1 -1
  27. package/agents/publish/publish-docs.mjs +12 -3
  28. package/agents/translate/choose-language.mjs +1 -1
  29. package/agents/update/batch-update-document.yaml +7 -0
  30. package/agents/update/check-update-is-single.mjs +38 -0
  31. package/agents/update/document-tools/update-document-content.mjs +293 -0
  32. package/agents/update/index.yaml +4 -10
  33. package/agents/update/update-document-detail.yaml +52 -0
  34. package/agents/update/update-single-document.yaml +15 -0
  35. package/agents/update/user-review-document.mjs +248 -0
  36. package/agents/utils/choose-docs.mjs +4 -2
  37. package/agents/utils/format-document-structure.mjs +12 -2
  38. package/agents/utils/load-document-all-content.mjs +84 -0
  39. package/agents/utils/load-sources.mjs +4 -1
  40. package/aigne.yaml +59 -20
  41. package/assets/report-template/report.html +198 -0
  42. package/biome.json +14 -2
  43. package/docs/advanced-how-it-works.ja.md +101 -0
  44. package/docs/advanced-how-it-works.zh-TW.md +101 -0
  45. package/docs/advanced-how-it-works.zh.md +20 -20
  46. package/docs/advanced-quality-assurance.ja.md +96 -0
  47. package/docs/advanced-quality-assurance.zh-TW.md +96 -0
  48. package/docs/advanced-quality-assurance.zh.md +18 -18
  49. package/docs/advanced.ja.md +16 -0
  50. package/docs/advanced.zh-TW.md +16 -0
  51. package/docs/advanced.zh.md +4 -4
  52. package/docs/changelog.ja.md +309 -0
  53. package/docs/changelog.zh-TW.md +309 -0
  54. package/docs/changelog.zh.md +23 -23
  55. package/docs/cli-reference.ja.md +210 -0
  56. package/docs/cli-reference.zh-TW.md +210 -0
  57. package/docs/cli-reference.zh.md +21 -21
  58. package/docs/configuration-interactive-setup.ja.md +135 -0
  59. package/docs/configuration-interactive-setup.zh-TW.md +135 -0
  60. package/docs/configuration-interactive-setup.zh.md +29 -29
  61. package/docs/configuration-language-support.ja.md +94 -0
  62. package/docs/configuration-language-support.zh-TW.md +94 -0
  63. package/docs/configuration-language-support.zh.md +13 -13
  64. package/docs/configuration-llm-setup.ja.md +54 -0
  65. package/docs/configuration-llm-setup.zh-TW.md +54 -0
  66. package/docs/configuration-llm-setup.zh.md +12 -12
  67. package/docs/configuration-preferences.ja.md +129 -0
  68. package/docs/configuration-preferences.zh-TW.md +129 -0
  69. package/docs/configuration-preferences.zh.md +36 -36
  70. package/docs/configuration.ja.md +172 -0
  71. package/docs/configuration.zh-TW.md +172 -0
  72. package/docs/configuration.zh.md +49 -49
  73. package/docs/features-generate-documentation.ja.md +101 -0
  74. package/docs/features-generate-documentation.zh-TW.md +101 -0
  75. package/docs/features-generate-documentation.zh.md +17 -17
  76. package/docs/features-publish-your-docs.ja.md +107 -0
  77. package/docs/features-publish-your-docs.zh-TW.md +107 -0
  78. package/docs/features-publish-your-docs.zh.md +22 -22
  79. package/docs/features-translate-documentation.ja.md +79 -0
  80. package/docs/features-translate-documentation.zh-TW.md +79 -0
  81. package/docs/features-translate-documentation.zh.md +12 -12
  82. package/docs/features-update-and-refine.ja.md +138 -0
  83. package/docs/features-update-and-refine.zh-TW.md +138 -0
  84. package/docs/features-update-and-refine.zh.md +21 -21
  85. package/docs/features.ja.md +52 -0
  86. package/docs/features.zh-TW.md +52 -0
  87. package/docs/features.zh.md +8 -8
  88. package/docs/getting-started.ja.md +123 -0
  89. package/docs/getting-started.zh-TW.md +123 -0
  90. package/docs/getting-started.zh.md +24 -24
  91. package/docs/overview.ja.md +30 -0
  92. package/docs/overview.zh-TW.md +30 -0
  93. package/docs/overview.zh.md +8 -8
  94. package/package.json +19 -11
  95. package/prompts/common/document/content-rules-core.md +19 -0
  96. package/prompts/common/document/media-handling-rules.md +9 -0
  97. package/prompts/common/document/role-and-personality.md +15 -0
  98. package/prompts/common/document/user-preferences.md +9 -0
  99. package/prompts/common/document-structure/conflict-resolution-guidance.md +16 -0
  100. package/prompts/common/document-structure/document-structure-rules.md +45 -0
  101. package/prompts/common/document-structure/glossary.md +7 -0
  102. package/prompts/common/document-structure/intj-traits.md +5 -0
  103. package/prompts/common/document-structure/output-constraints.md +9 -0
  104. package/prompts/common/document-structure/user-locale-rules.md +10 -0
  105. package/prompts/common/document-structure/user-preferences.md +9 -0
  106. package/prompts/detail/custom/custom-components.md +9 -1
  107. package/prompts/detail/document-rules.md +6 -6
  108. package/prompts/detail/generate-document.md +5 -45
  109. package/prompts/detail/update-document.md +145 -0
  110. package/prompts/evaluate/document-structure.md +94 -0
  111. package/prompts/evaluate/document.md +149 -0
  112. package/prompts/structure/document-rules.md +1 -1
  113. package/prompts/structure/generate-structure-system.md +74 -0
  114. package/prompts/structure/generate-structure-user.md +41 -0
  115. package/prompts/structure/update-document-structure.md +118 -0
  116. package/prompts/translate/translate-document.md +1 -1
  117. package/prompts/utils/feedback-refiner.md +3 -3
  118. package/release-please-config.json +1 -7
  119. package/tests/agents/clear/choose-contents.test.mjs +280 -0
  120. package/tests/agents/clear/clear-auth-tokens.test.mjs +268 -0
  121. package/tests/agents/clear/clear-document-config.test.mjs +167 -0
  122. package/tests/agents/clear/clear-document-structure.test.mjs +374 -0
  123. package/tests/agents/clear/clear-generated-docs.test.mjs +222 -0
  124. package/tests/agents/evaluate/code-snippet.test.mjs +163 -0
  125. package/tests/agents/evaluate/fixtures/api-services.md +87 -0
  126. package/tests/agents/evaluate/fixtures/js-sdk.md +94 -0
  127. package/tests/agents/evaluate/generate-report.test.mjs +312 -0
  128. package/tests/agents/generate/check-document-structure.test.mjs +0 -6
  129. package/tests/agents/generate/document-structure-tools/add-document.test.mjs +449 -0
  130. package/tests/agents/generate/document-structure-tools/delete-document.test.mjs +410 -0
  131. package/tests/agents/generate/document-structure-tools/move-document.test.mjs +476 -0
  132. package/tests/agents/generate/document-structure-tools/update-document.test.mjs +548 -0
  133. package/tests/agents/generate/generate-structure.test.mjs +0 -6
  134. package/tests/agents/generate/user-review-document-structure.test.mjs +9 -9
  135. package/tests/agents/publish/publish-docs.test.mjs +2 -2
  136. package/tests/agents/update/check-update-is-single.test.mjs +300 -0
  137. package/tests/agents/update/document-tools/update-document-content.test.mjs +326 -0
  138. package/tests/agents/update/user-review-document.test.mjs +561 -0
  139. package/tests/agents/utils/format-document-structure.test.mjs +100 -0
  140. package/tests/utils/auth-utils.test.mjs +239 -1
  141. package/tests/utils/blocklet.test.mjs +9 -7
  142. package/tests/utils/constants.test.mjs +1 -1
  143. package/tests/utils/d2-utils.test.mjs +1 -1
  144. package/tests/utils/deploy.test.mjs +310 -366
  145. package/tests/utils/kroki-utils.test.mjs +2 -15
  146. package/tests/utils/linter/fixtures/css/keyword-error.css +1 -0
  147. package/tests/utils/linter/fixtures/css/missing-semicolon.css +1 -0
  148. package/tests/utils/linter/fixtures/css/syntax-error.css +1 -0
  149. package/tests/utils/linter/fixtures/css/undeclare-variable.css +1 -0
  150. package/tests/utils/linter/fixtures/css/unused-variable.css +2 -0
  151. package/tests/utils/linter/fixtures/css/valid-code.css +1 -0
  152. package/tests/utils/linter/fixtures/dockerfile/keyword-error.dockerfile +1 -0
  153. package/tests/utils/linter/fixtures/dockerfile/missing-semicolon.dockerfile +2 -0
  154. package/tests/utils/linter/fixtures/dockerfile/syntax-error.dockerfile +2 -0
  155. package/tests/utils/linter/fixtures/dockerfile/undeclare-variable.dockerfile +1 -0
  156. package/tests/utils/linter/fixtures/dockerfile/unused-variable.dockerfile +1 -0
  157. package/tests/utils/linter/fixtures/dockerfile/valid-code.dockerfile +2 -0
  158. package/tests/utils/linter/fixtures/go/keyword-error.go +5 -0
  159. package/tests/utils/linter/fixtures/go/missing-semicolon.go +5 -0
  160. package/tests/utils/linter/fixtures/go/syntax-error.go +6 -0
  161. package/tests/utils/linter/fixtures/go/undeclare-variable.go +5 -0
  162. package/tests/utils/linter/fixtures/go/unused-variable.go +5 -0
  163. package/tests/utils/linter/fixtures/go/valid-code.go +7 -0
  164. package/tests/utils/linter/fixtures/js/keyword-error.js +3 -0
  165. package/tests/utils/linter/fixtures/js/missing-semicolon.js +6 -0
  166. package/tests/utils/linter/fixtures/js/syntax-error.js +4 -0
  167. package/tests/utils/linter/fixtures/js/undeclare-variable.js +3 -0
  168. package/tests/utils/linter/fixtures/js/unused-variable.js +7 -0
  169. package/tests/utils/linter/fixtures/js/valid-code.js +15 -0
  170. package/tests/utils/linter/fixtures/json/keyword-error.json +1 -0
  171. package/tests/utils/linter/fixtures/json/missing-semicolon.json +1 -0
  172. package/tests/utils/linter/fixtures/json/syntax-error.json +1 -0
  173. package/tests/utils/linter/fixtures/json/undeclare-variable.json +1 -0
  174. package/tests/utils/linter/fixtures/json/unused-variable.json +1 -0
  175. package/tests/utils/linter/fixtures/json/valid-code.json +1 -0
  176. package/tests/utils/linter/fixtures/jsx/keyword-error.jsx +5 -0
  177. package/tests/utils/linter/fixtures/jsx/missing-semicolon.jsx +5 -0
  178. package/tests/utils/linter/fixtures/jsx/syntax-error.jsx +5 -0
  179. package/tests/utils/linter/fixtures/jsx/undeclare-variable.jsx +5 -0
  180. package/tests/utils/linter/fixtures/jsx/unused-variable.jsx +4 -0
  181. package/tests/utils/linter/fixtures/jsx/valid-code.jsx +5 -0
  182. package/tests/utils/linter/fixtures/python/keyword-error.py +3 -0
  183. package/tests/utils/linter/fixtures/python/missing-semicolon.py +2 -0
  184. package/tests/utils/linter/fixtures/python/syntax-error.py +3 -0
  185. package/tests/utils/linter/fixtures/python/undeclare-variable.py +3 -0
  186. package/tests/utils/linter/fixtures/python/unused-variable.py +6 -0
  187. package/tests/utils/linter/fixtures/python/valid-code.py +12 -0
  188. package/tests/utils/linter/fixtures/ruby/keyword-error.rb +2 -0
  189. package/tests/utils/linter/fixtures/ruby/missing-semicolon.rb +1 -0
  190. package/tests/utils/linter/fixtures/ruby/syntax-error.rb +2 -0
  191. package/tests/utils/linter/fixtures/ruby/undeclare-variable.rb +1 -0
  192. package/tests/utils/linter/fixtures/ruby/unused-variable.rb +2 -0
  193. package/tests/utils/linter/fixtures/ruby/valid-code.rb +1 -0
  194. package/tests/utils/linter/fixtures/sass/keyword-error.sass +2 -0
  195. package/tests/utils/linter/fixtures/sass/missing-semicolon.sass +3 -0
  196. package/tests/utils/linter/fixtures/sass/syntax-error.sass +3 -0
  197. package/tests/utils/linter/fixtures/sass/undeclare-variable.sass +2 -0
  198. package/tests/utils/linter/fixtures/sass/unused-variable.sass +4 -0
  199. package/tests/utils/linter/fixtures/sass/valid-code.sass +2 -0
  200. package/tests/utils/linter/fixtures/scss/keyword-error.scss +1 -0
  201. package/tests/utils/linter/fixtures/scss/missing-semicolon.scss +1 -0
  202. package/tests/utils/linter/fixtures/scss/syntax-error.scss +1 -0
  203. package/tests/utils/linter/fixtures/scss/undeclare-variable.scss +1 -0
  204. package/tests/utils/linter/fixtures/scss/unused-variable.scss +2 -0
  205. package/tests/utils/linter/fixtures/scss/valid-code.scss +1 -0
  206. package/tests/utils/linter/fixtures/shell/keyword-error.sh +5 -0
  207. package/tests/utils/linter/fixtures/shell/missing-semicolon.sh +3 -0
  208. package/tests/utils/linter/fixtures/shell/syntax-error.sh +4 -0
  209. package/tests/utils/linter/fixtures/shell/undeclare-variable.sh +3 -0
  210. package/tests/utils/linter/fixtures/shell/unused-variable.sh +4 -0
  211. package/tests/utils/linter/fixtures/shell/valid-code.sh +3 -0
  212. package/tests/utils/linter/fixtures/ts/keyword-error.ts +1 -0
  213. package/tests/utils/linter/fixtures/ts/missing-semicolon.ts +1 -0
  214. package/tests/utils/linter/fixtures/ts/syntax-error.ts +1 -0
  215. package/tests/utils/linter/fixtures/ts/undeclare-variable.ts +1 -0
  216. package/tests/utils/linter/fixtures/ts/unused-variable.ts +3 -0
  217. package/tests/utils/linter/fixtures/ts/valid-code.ts +3 -0
  218. package/tests/utils/linter/fixtures/tsx/keyword-error.tsx +5 -0
  219. package/tests/utils/linter/fixtures/tsx/missing-semicolon.tsx +5 -0
  220. package/tests/utils/linter/fixtures/tsx/syntax-error.tsx +5 -0
  221. package/tests/utils/linter/fixtures/tsx/undeclare-variable.tsx +6 -0
  222. package/tests/utils/linter/fixtures/tsx/unused-variable.tsx +6 -0
  223. package/tests/utils/linter/fixtures/tsx/valid-code.tsx +5 -0
  224. package/tests/utils/linter/fixtures/vue/keyword-error.vue +6 -0
  225. package/tests/utils/linter/fixtures/vue/missing-semicolon.vue +6 -0
  226. package/tests/utils/linter/fixtures/vue/syntax-error.vue +6 -0
  227. package/tests/utils/linter/fixtures/vue/undeclare-variable.vue +6 -0
  228. package/tests/utils/linter/fixtures/vue/unused-variable.vue +7 -0
  229. package/tests/utils/linter/fixtures/vue/valid-code.vue +6 -0
  230. package/tests/utils/linter/fixtures/yaml/keyword-error.yml +1 -0
  231. package/tests/utils/linter/fixtures/yaml/missing-semicolon.yml +2 -0
  232. package/tests/utils/linter/fixtures/yaml/syntax-error.yml +1 -0
  233. package/tests/utils/linter/fixtures/yaml/undeclare-variable.yml +1 -0
  234. package/tests/utils/linter/fixtures/yaml/unused-variable.yml +2 -0
  235. package/tests/utils/linter/fixtures/yaml/valid-code.yml +3 -0
  236. package/tests/utils/linter/index.test.mjs +440 -0
  237. package/tests/utils/linter/scan-results.mjs +42 -0
  238. package/tests/utils/markdown/index.test.mjs +478 -0
  239. package/tests/utils/mermaid-validator.test.mjs +2 -2
  240. package/tests/utils/utils.test.mjs +3 -1
  241. package/types/document-schema.mjs +54 -0
  242. package/types/document-structure-schema.mjs +244 -0
  243. package/utils/auth-utils.mjs +131 -6
  244. package/utils/conflict-detector.mjs +5 -1
  245. package/utils/{constants.mjs → constants/index.mjs} +109 -0
  246. package/utils/constants/linter.mjs +102 -0
  247. package/utils/d2-utils.mjs +2 -4
  248. package/utils/debug.mjs +3 -0
  249. package/utils/deploy.mjs +81 -385
  250. package/utils/evaluate/report-utils.mjs +131 -0
  251. package/utils/file-utils.mjs +36 -1
  252. package/utils/kroki-utils.mjs +1 -1
  253. package/utils/linter/index.mjs +50 -0
  254. package/utils/markdown/index.mjs +26 -0
  255. package/utils/markdown-checker.mjs +1 -1
  256. package/utils/utils.mjs +19 -7
  257. package/prompts/structure/generate-structure.md +0 -161
@@ -0,0 +1,82 @@
1
+ import {
2
+ getMoveDocumentInputJsonSchema,
3
+ getMoveDocumentOutputJsonSchema,
4
+ validateMoveDocumentInput,
5
+ } from "../../../types/document-structure-schema.mjs";
6
+
7
+ export default async function moveDocument(input) {
8
+ // Validate input using Zod schema
9
+ const validation = validateMoveDocumentInput(input);
10
+ if (!validation.success) {
11
+ console.log(`Error: Cannot move document - ${validation.error}`);
12
+ return { documentStructure: input.documentStructure };
13
+ }
14
+
15
+ const { documentStructure, path, newParentId } = validation.data;
16
+
17
+ // Find the document to move
18
+ const documentIndex = documentStructure.findIndex((item) => item.path === path);
19
+ if (documentIndex === -1) {
20
+ console.log(
21
+ `Error: Cannot move document - Document '${path}' does not exist. Please select an existing document to move.`,
22
+ );
23
+ return { documentStructure };
24
+ }
25
+
26
+ const documentToMove = documentStructure[documentIndex];
27
+
28
+ // Validate new parent exists if newParentId is provided
29
+ if (
30
+ newParentId !== null &&
31
+ newParentId !== undefined &&
32
+ newParentId !== "null" &&
33
+ newParentId !== ""
34
+ ) {
35
+ const newParentExists = documentStructure.some((item) => item.path === newParentId);
36
+ if (!newParentExists) {
37
+ console.log(
38
+ `Error: Cannot move document - Target parent document '${newParentId}' does not exist. Please select an existing parent document.`,
39
+ );
40
+ return { documentStructure };
41
+ }
42
+
43
+ // Check for circular dependency: the new parent cannot be a descendant of the document being moved
44
+ const isDescendant = (parentPath, childPath) => {
45
+ const children = documentStructure.filter((item) => item.parentId === parentPath);
46
+ for (const child of children) {
47
+ if (child.path === childPath || isDescendant(child.path, childPath)) {
48
+ return true;
49
+ }
50
+ }
51
+ return false;
52
+ };
53
+
54
+ if (isDescendant(path, newParentId)) {
55
+ console.log(
56
+ `Error: Cannot move document - Moving '${path}' under '${newParentId}' would create an invalid hierarchy. Please select a parent that is not nested under the document being moved.`,
57
+ );
58
+ return { documentStructure };
59
+ }
60
+ }
61
+
62
+ // Create updated document object with new parent
63
+ const updatedDocument = {
64
+ ...documentToMove,
65
+ parentId: newParentId || null,
66
+ };
67
+
68
+ // Update the document structure
69
+ const updatedStructure = [...documentStructure];
70
+ updatedStructure[documentIndex] = updatedDocument;
71
+
72
+ return {
73
+ documentStructure: updatedStructure,
74
+ originalDocument: documentToMove,
75
+ updatedDocument,
76
+ };
77
+ }
78
+
79
+ moveDocument.taskTitle = "Move document";
80
+ moveDocument.description = "Move a document to a different parent in the document structure";
81
+ moveDocument.inputSchema = getMoveDocumentInputJsonSchema();
82
+ moveDocument.outputSchema = getMoveDocumentOutputJsonSchema();
@@ -0,0 +1,50 @@
1
+ import {
2
+ getUpdateDocumentInputJsonSchema,
3
+ getUpdateDocumentOutputJsonSchema,
4
+ validateUpdateDocumentInput,
5
+ } from "../../../types/document-structure-schema.mjs";
6
+
7
+ export default async function updateDocument(input) {
8
+ // Validate input using Zod schema
9
+ const validation = validateUpdateDocumentInput(input);
10
+ if (!validation.success) {
11
+ console.log(`⚠️ Cannot update document: ${validation.error}`);
12
+ return { documentStructure: input.documentStructure };
13
+ }
14
+
15
+ const { documentStructure, path, title, description, sourceIds } = validation.data;
16
+
17
+ // Find the document to update
18
+ const documentIndex = documentStructure.findIndex((item) => item.path === path);
19
+ if (documentIndex === -1) {
20
+ console.log(
21
+ `⚠️ Cannot update document: Document '${path}' does not exist. Choose an existing document to update.`,
22
+ );
23
+ return { documentStructure };
24
+ }
25
+
26
+ const originalDocument = documentStructure[documentIndex];
27
+
28
+ // Create updated document object
29
+ const updatedDocument = {
30
+ ...originalDocument,
31
+ ...(title !== undefined && { title }),
32
+ ...(description !== undefined && { description }),
33
+ ...(sourceIds !== undefined && { sourceIds: [...sourceIds] }), // Create a copy of the array
34
+ };
35
+
36
+ // Update the document structure
37
+ const updatedStructure = [...documentStructure];
38
+ updatedStructure[documentIndex] = updatedDocument;
39
+
40
+ return {
41
+ documentStructure: updatedStructure,
42
+ originalDocument,
43
+ updatedDocument,
44
+ };
45
+ }
46
+
47
+ updateDocument.taskTitle = "Update document";
48
+ updateDocument.description = "Update properties of an existing document in the document structure";
49
+ updateDocument.inputSchema = getUpdateDocumentInputJsonSchema();
50
+ updateDocument.outputSchema = getUpdateDocumentOutputJsonSchema();
@@ -1,7 +1,7 @@
1
1
  name: generateStructure
2
2
  description: Generate the structure and organization of your documentation
3
3
  instructions:
4
- url: ../../prompts/structure/generate-structure.md
4
+ url: ../../prompts/structure/generate-structure-system.md
5
5
  input_schema:
6
6
  type: object
7
7
  properties:
@@ -0,0 +1,42 @@
1
+ type: ai
2
+ name: updateDocumentStructure
3
+ description: Update document structure based on user feedback and intentions using structure modification tools
4
+ instructions:
5
+ url: ../../prompts/structure/update-document-structure.md
6
+ input_schema:
7
+ type: object
8
+ properties:
9
+ documentStructure: ../schema/document-structure.yaml
10
+ rules:
11
+ type: string
12
+ description: User configuration rules
13
+ locale:
14
+ type: string
15
+ description: User language, e.g. zh, en
16
+ datasources:
17
+ type: string
18
+ description: Context for document structure
19
+ glossary:
20
+ type: string
21
+ description: Glossary of terms
22
+ feedback:
23
+ type: string
24
+ description: User feedback for structure modifications
25
+ userPreferences:
26
+ type: string
27
+ description: Your saved preferences for structure and documentation style
28
+ required:
29
+ - documentStructure
30
+ - feedback
31
+ output_schema:
32
+ type: object
33
+ properties:
34
+ documentStructure: ../schema/document-structure.yaml
35
+ operationSummary:
36
+ type: string
37
+ description: Summary of the operations performed on the document structure
38
+ skills:
39
+ - ./document-structure-tools/add-document.mjs
40
+ - ./document-structure-tools/delete-document.mjs
41
+ - ./document-structure-tools/update-document.mjs
42
+ - ./document-structure-tools/move-document.mjs
@@ -56,7 +56,9 @@ function printDocumentStructure(structure) {
56
56
  if (rootNodes.length === 0) {
57
57
  console.log(" No document structure found.");
58
58
  } else {
59
- rootNodes.forEach((node) => printNode(node));
59
+ rootNodes.forEach((node) => {
60
+ printNode(node);
61
+ });
60
62
  }
61
63
  console.log();
62
64
  }
@@ -112,10 +114,10 @@ export default async function userReviewDocumentStructure({ documentStructure, .
112
114
  }
113
115
 
114
116
  // Get the refineDocumentStructure agent
115
- const refineAgent = options.context.agents["refineDocumentStructure"];
117
+ const refineAgent = options.context.agents["updateDocumentStructure"];
116
118
  if (!refineAgent) {
117
119
  console.log(
118
- "Unable to process your feedback - the structure refinement feature is unavailable.",
120
+ "Unable to process your feedback - the document structure update feature is unavailable.",
119
121
  );
120
122
  console.log("Please try again later or contact support if this continues.");
121
123
  break;
@@ -133,7 +135,7 @@ export default async function userReviewDocumentStructure({ documentStructure, .
133
135
  const result = await options.context.invoke(refineAgent, {
134
136
  ...rest,
135
137
  feedback: feedback.trim(),
136
- originalDocumentStructure: currentStructure,
138
+ documentStructure: currentStructure,
137
139
  userPreferences,
138
140
  });
139
141
 
@@ -11,7 +11,7 @@ import {
11
11
  READER_KNOWLEDGE_LEVELS,
12
12
  SUPPORTED_LANGUAGES,
13
13
  TARGET_AUDIENCES,
14
- } from "../../utils/constants.mjs";
14
+ } from "../../utils/constants/index.mjs";
15
15
  import loadConfig from "../../utils/load-config.mjs";
16
16
  import {
17
17
  detectSystemLanguage,
@@ -5,7 +5,7 @@ import chalk from "chalk";
5
5
  import fs from "fs-extra";
6
6
 
7
7
  import { getAccessToken } from "../../utils/auth-utils.mjs";
8
- import { DISCUSS_KIT_STORE_URL, TMP_DIR, TMP_DOCS_DIR } from "../../utils/constants.mjs";
8
+ import { DISCUSS_KIT_STORE_URL, TMP_DIR, TMP_DOCS_DIR } from "../../utils/constants/index.mjs";
9
9
  import { beforePublishHook, ensureTmpDir } from "../../utils/d2-utils.mjs";
10
10
  import { deploy } from "../../utils/deploy.mjs";
11
11
  import { getGithubRepoUrl, loadConfigFromFile, saveValueToConfig } from "../../utils/utils.mjs";
@@ -153,7 +153,11 @@ export default async function publishDocs(
153
153
  let message;
154
154
 
155
155
  try {
156
- const { success, boardId: newBoardId } = await publishDocsFn({
156
+ const {
157
+ success,
158
+ boardId: newBoardId,
159
+ error,
160
+ } = await publishDocsFn({
157
161
  sidebarPath,
158
162
  accessToken,
159
163
  appUrl,
@@ -179,7 +183,12 @@ export default async function publishDocs(
179
183
  if (boardId !== newBoardId) {
180
184
  await saveValueToConfig("boardId", newBoardId);
181
185
  }
182
- message = `✅ Documentation Published Successfully!`;
186
+ message = `✅ Documentation published successfully!`;
187
+ } else {
188
+ // If the error is 401 or 403, it means the access token is invalid
189
+ if (error?.includes("401") || error?.includes("403")) {
190
+ message = `❌ Publishing failed: you don’t have valid authorization.\n Run ${chalk.cyan("aigne doc clear")} to reset it, then publish again.`;
191
+ }
183
192
  }
184
193
  } catch (error) {
185
194
  message = `❌ Failed to publish docs: ${error.message}`;
@@ -1,4 +1,4 @@
1
- import { SUPPORTED_LANGUAGES } from "../../utils/constants.mjs";
1
+ import { SUPPORTED_LANGUAGES } from "../../utils/constants/index.mjs";
2
2
  import { loadConfigFromFile, saveValueToConfig } from "../../utils/utils.mjs";
3
3
 
4
4
  /**
@@ -0,0 +1,7 @@
1
+
2
+ type: team
3
+ name: batchUpdateDocument
4
+ skills:
5
+ - ../update/generate-and-translate-document.yaml
6
+ iterate_on: selectedDocs
7
+ concurrency: 5
@@ -0,0 +1,38 @@
1
+ export default async function checkUpdateIsSingle({ selectedDocs, ...rest }, options) {
2
+ if (!selectedDocs || !Array.isArray(selectedDocs)) {
3
+ throw new Error("selectedDocs must be provided as an array");
4
+ }
5
+
6
+ if (selectedDocs.length === 0) {
7
+ throw new Error("selectedDocs cannot be empty");
8
+ }
9
+
10
+ let targetAgent;
11
+ let agentName;
12
+
13
+ if (selectedDocs.length === 1) {
14
+ agentName = "updateSingleDocument";
15
+ targetAgent = options.context.agents["updateSingleDocument"];
16
+ } else {
17
+ agentName = "batchUpdateDocument";
18
+ targetAgent = options.context.agents["batchUpdateDocument"];
19
+ }
20
+
21
+ if (!targetAgent) {
22
+ throw new Error(`Agent "${agentName}" is not available`);
23
+ }
24
+
25
+ try {
26
+ const result = await options.context.invoke(targetAgent, {
27
+ selectedDocs,
28
+ ...rest,
29
+ });
30
+
31
+ return result;
32
+ } catch (error) {
33
+ console.error(`Error invoking ${agentName}:`, error.message);
34
+ throw error;
35
+ }
36
+ }
37
+
38
+ checkUpdateIsSingle.taskTitle = "Check document count and route to appropriate update agent";
@@ -0,0 +1,293 @@
1
+ import { applyPatch } from "diff";
2
+ import {
3
+ getUpdateDocumentContentInputJsonSchema,
4
+ getUpdateDocumentContentOutputJsonSchema,
5
+ validateUpdateDocumentContentInput,
6
+ } from "../../../types/document-schema.mjs";
7
+
8
+ export default async function updateDocumentContent(input) {
9
+ // Validate input using Zod schema
10
+ const validation = validateUpdateDocumentContentInput(input);
11
+ if (!validation.success) {
12
+ return {
13
+ success: false,
14
+ error: validation.error,
15
+ message: "Invalid input parameters",
16
+ };
17
+ }
18
+
19
+ const { originalContent, diffPatch } = validation.data;
20
+
21
+ try {
22
+ // Parse and validate diff patch
23
+ const parsedDiff = parseDiffPatch(diffPatch);
24
+ if (!parsedDiff.success) {
25
+ return {
26
+ success: false,
27
+ error: parsedDiff.error,
28
+ message: "Invalid diff format: No valid hunks found or parsing failed",
29
+ };
30
+ }
31
+
32
+ // Check and fix line number issues
33
+ const fixedDiff = fixLineNumberIssues(originalContent, parsedDiff.hunks);
34
+ if (!fixedDiff.success) {
35
+ return {
36
+ success: false,
37
+ error: fixedDiff.error,
38
+ message: "Cannot fix diff line number issues",
39
+ };
40
+ }
41
+
42
+ // Reconstruct the fixed diff patch
43
+ const fixedPatch = reconstructDiffPatch(fixedDiff.hunks);
44
+
45
+ // Apply the diff patch using the diff library
46
+ const result = applyPatch(originalContent, fixedPatch);
47
+
48
+ if (result === false) {
49
+ return {
50
+ success: false,
51
+ error: "Failed to apply patch",
52
+ message: "Diff patch could not be applied",
53
+ };
54
+ }
55
+
56
+ return {
57
+ success: true,
58
+ updatedContent: result,
59
+ message: "Document content updated successfully",
60
+ };
61
+ } catch (error) {
62
+ return {
63
+ success: false,
64
+ error: error.message,
65
+ message: "Failed to update document content",
66
+ };
67
+ }
68
+ }
69
+
70
+ function parseDiffPatch(diffPatch) {
71
+ try {
72
+ const hunks = [];
73
+ const lines = diffPatch.split("\n");
74
+ let currentHunk = null;
75
+
76
+ for (let i = 0; i < lines.length; i++) {
77
+ const line = lines[i];
78
+
79
+ // Parse hunk header: @@ -oldStart,oldCount +newStart,newCount @@
80
+ const hunkMatch = line.match(/^@@\s+-(\d+)(?:,(\d+))?\s+\+(\d+)(?:,(\d+))?\s+@@/);
81
+ if (hunkMatch) {
82
+ if (currentHunk) {
83
+ hunks.push(currentHunk);
84
+ }
85
+ currentHunk = {
86
+ oldStart: parseInt(hunkMatch[1], 10),
87
+ oldCount: parseInt(hunkMatch[2], 10) || 1,
88
+ newStart: parseInt(hunkMatch[3], 10),
89
+ newCount: parseInt(hunkMatch[4], 10) || 1,
90
+ changes: [],
91
+ };
92
+ continue;
93
+ }
94
+
95
+ // Parse changes
96
+ if (currentHunk && line.length > 0) {
97
+ const changeType = line[0];
98
+ const content = line.slice(1);
99
+
100
+ if (changeType === "-") {
101
+ currentHunk.changes.push({ type: "remove", content });
102
+ } else if (changeType === "+") {
103
+ currentHunk.changes.push({ type: "add", content });
104
+ } else if (changeType === " ") {
105
+ currentHunk.changes.push({ type: "context", content });
106
+ }
107
+ }
108
+ }
109
+
110
+ if (currentHunk) {
111
+ hunks.push(currentHunk);
112
+ }
113
+
114
+ if (hunks.length === 0) {
115
+ return { success: false, error: "No valid hunks found in diff" };
116
+ }
117
+
118
+ return { success: true, hunks };
119
+ } catch (error) {
120
+ return { success: false, error: `Failed to parse diff: ${error.message}` };
121
+ }
122
+ }
123
+
124
+ function fixLineNumberIssues(originalContent, hunks) {
125
+ try {
126
+ const originalLines = originalContent.split("\n");
127
+ const fixedHunks = [];
128
+
129
+ for (const hunk of hunks) {
130
+ // Extract context and removed lines to find best match
131
+ const contextAndRemoved = hunk.changes
132
+ .filter((change) => change.type === "context" || change.type === "remove")
133
+ .map((change) => change.content);
134
+
135
+ if (contextAndRemoved.length === 0) {
136
+ // No context to match against, keep original
137
+ fixedHunks.push(hunk);
138
+ continue;
139
+ }
140
+
141
+ // Find best matching position in original content
142
+ const bestMatch = findBestMatch(originalLines, contextAndRemoved, hunk.oldStart - 1);
143
+
144
+ if (bestMatch.found) {
145
+ const fixedHunk = {
146
+ ...hunk,
147
+ oldStart: bestMatch.position + 1,
148
+ newStart: bestMatch.position + 1,
149
+ // Fix line counts based on actual changes
150
+ oldCount: calculateOldCount(hunk.changes),
151
+ newCount: calculateNewCount(hunk.changes),
152
+ };
153
+ fixedHunks.push(fixedHunk);
154
+ } else {
155
+ // Try fuzzy matching
156
+ const fuzzyMatch = findFuzzyMatch(originalLines, contextAndRemoved);
157
+ if (fuzzyMatch.found) {
158
+ const fixedHunk = {
159
+ ...hunk,
160
+ oldStart: fuzzyMatch.position + 1,
161
+ newStart: fuzzyMatch.position + 1,
162
+ // Fix line counts based on actual changes
163
+ oldCount: calculateOldCount(hunk.changes),
164
+ newCount: calculateNewCount(hunk.changes),
165
+ };
166
+ fixedHunks.push(fixedHunk);
167
+ } else {
168
+ return {
169
+ success: false,
170
+ error: `Cannot find matching context for hunk at line ${hunk.oldStart}`,
171
+ };
172
+ }
173
+ }
174
+ }
175
+
176
+ return { success: true, hunks: fixedHunks };
177
+ } catch (error) {
178
+ return { success: false, error: `Failed to fix line numbers: ${error.message}` };
179
+ }
180
+ }
181
+
182
+ function findBestMatch(originalLines, targetLines, startPosition) {
183
+ // Try exact match at expected position first
184
+ if (startPosition >= 0 && startPosition + targetLines.length <= originalLines.length) {
185
+ let matches = 0;
186
+ for (let i = 0; i < targetLines.length; i++) {
187
+ if (originalLines[startPosition + i] === targetLines[i]) {
188
+ matches++;
189
+ }
190
+ }
191
+
192
+ if (matches === targetLines.length) {
193
+ return { found: true, position: startPosition };
194
+ }
195
+ }
196
+
197
+ // Try nearby positions (within 10 lines)
198
+ const NEARBY_SEARCH_RANGE = 10; // Maximum number of lines to search before/after expected position
199
+ for (let offset = 1; offset <= NEARBY_SEARCH_RANGE; offset++) {
200
+ // Try before
201
+ const beforePos = startPosition - offset;
202
+ if (beforePos >= 0 && beforePos + targetLines.length <= originalLines.length) {
203
+ let matches = 0;
204
+ for (let i = 0; i < targetLines.length; i++) {
205
+ if (originalLines[beforePos + i] === targetLines[i]) {
206
+ matches++;
207
+ }
208
+ }
209
+ if (matches === targetLines.length) {
210
+ return { found: true, position: beforePos };
211
+ }
212
+ }
213
+
214
+ // Try after
215
+ const afterPos = startPosition + offset;
216
+ if (afterPos >= 0 && afterPos + targetLines.length <= originalLines.length) {
217
+ let matches = 0;
218
+ for (let i = 0; i < targetLines.length; i++) {
219
+ if (originalLines[afterPos + i] === targetLines[i]) {
220
+ matches++;
221
+ }
222
+ }
223
+ if (matches === targetLines.length) {
224
+ return { found: true, position: afterPos };
225
+ }
226
+ }
227
+ }
228
+
229
+ return { found: false };
230
+ }
231
+
232
+ function findFuzzyMatch(originalLines, targetLines) {
233
+ // Find the best partial match
234
+ let bestMatch = { found: false, position: 0, score: 0 };
235
+
236
+ for (let pos = 0; pos <= originalLines.length - targetLines.length; pos++) {
237
+ let matches = 0;
238
+ for (let i = 0; i < targetLines.length; i++) {
239
+ if (originalLines[pos + i] === targetLines[i]) {
240
+ matches++;
241
+ }
242
+ }
243
+
244
+ const score = matches / targetLines.length;
245
+ const FUZZY_MATCH_THRESHOLD = 0.7; // 70% similarity threshold for fuzzy matching
246
+ if (score > bestMatch.score && score >= FUZZY_MATCH_THRESHOLD) {
247
+ bestMatch = { found: true, position: pos, score };
248
+ }
249
+ }
250
+
251
+ return bestMatch;
252
+ }
253
+
254
+ function calculateOldCount(changes) {
255
+ const contextCount = changes.filter((c) => c.type === "context").length;
256
+ const removeCount = changes.filter((c) => c.type === "remove").length;
257
+ return contextCount + removeCount;
258
+ }
259
+
260
+ function calculateNewCount(changes) {
261
+ const contextCount = changes.filter((c) => c.type === "context").length;
262
+ const addCount = changes.filter((c) => c.type === "add").length;
263
+ return contextCount + addCount;
264
+ }
265
+
266
+ function reconstructDiffPatch(hunks) {
267
+ let patchContent = "";
268
+
269
+ for (const hunk of hunks) {
270
+ // Add hunk header
271
+ const oldRange = hunk.oldCount === 1 ? hunk.oldStart : `${hunk.oldStart},${hunk.oldCount}`;
272
+ const newRange = hunk.newCount === 1 ? hunk.newStart : `${hunk.newStart},${hunk.newCount}`;
273
+ patchContent += `@@ -${oldRange} +${newRange} @@\n`;
274
+
275
+ // Add changes
276
+ for (const change of hunk.changes) {
277
+ if (change.type === "context") {
278
+ patchContent += ` ${change.content}\n`;
279
+ } else if (change.type === "remove") {
280
+ patchContent += `-${change.content}\n`;
281
+ } else if (change.type === "add") {
282
+ patchContent += `+${change.content}\n`;
283
+ }
284
+ }
285
+ }
286
+
287
+ return patchContent;
288
+ }
289
+
290
+ updateDocumentContent.inputSchema = getUpdateDocumentContentInputJsonSchema();
291
+ updateDocumentContent.outputSchema = getUpdateDocumentContentOutputJsonSchema();
292
+
293
+ updateDocumentContent.description = "Apply diff patch to update markdown document content";
@@ -25,17 +25,11 @@ skills:
25
25
  })
26
26
  }
27
27
  ])
28
- - ../utils/choose-docs.mjs
29
- - ../utils/format-document-structure.mjs
30
- - type: team
31
- name: batchUpdateDocument
32
- skills:
33
- - ../update/generate-and-translate-document.yaml
34
- iterate_on: selectedDocs
35
- concurrency: 3
36
- - url: ../utils/check-feedback-refiner.mjs
28
+ - url: ../utils/choose-docs.mjs
37
29
  default_input:
38
- stage: document_refine
30
+ requiredFeedback: false
31
+ - ../utils/format-document-structure.mjs
32
+ - ../update/check-update-is-single.mjs
39
33
  - url: ../utils/action-success.mjs
40
34
  default_input:
41
35
  action: "✅ Documents updated successfully"
@@ -0,0 +1,52 @@
1
+ type: ai
2
+ name: updateDocumentDetail
3
+ description: Update and optimize document content based on user feedback using diff patches
4
+ instructions:
5
+ url: ../../prompts/detail/update-document.md
6
+ input_schema:
7
+ type: object
8
+ properties:
9
+ originalContent:
10
+ type: string
11
+ description: Original markdown content to be updated
12
+ feedback:
13
+ type: string
14
+ description: User feedback for content improvements
15
+ rules:
16
+ type: string
17
+ description: User configuration rules
18
+ locale:
19
+ type: string
20
+ description: User language, e.g. zh, en
21
+ datasources:
22
+ type: string
23
+ description: Context for document content
24
+ glossary:
25
+ type: string
26
+ description: Glossary of terms
27
+ userPreferences:
28
+ type: string
29
+ description: User's saved preferences for content and documentation style
30
+ targetAudience:
31
+ type: string
32
+ description: Target audience for the documentation
33
+ title:
34
+ type: string
35
+ description: Document title
36
+ description:
37
+ type: string
38
+ description: Document description
39
+ required:
40
+ - originalContent
41
+ - feedback
42
+ output_schema:
43
+ type: object
44
+ properties:
45
+ updatedContent:
46
+ type: string
47
+ description: Final updated markdown content after applying modifications
48
+ operationSummary:
49
+ type: string
50
+ description: Summary of the operations performed on the document content
51
+ skills:
52
+ - ./document-tools/update-document-content.mjs