@aigne/doc-smith 0.9.8-alpha.3 → 0.9.8-alpha.4

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/CLAUDE.md +43 -0
  2. package/README.md +94 -250
  3. package/aigne.yaml +2 -149
  4. package/doc-smith/SKILL.md +117 -0
  5. package/doc-smith/references/changeset_schema.md +118 -0
  6. package/doc-smith/references/document_structure_schema.md +139 -0
  7. package/doc-smith/references/document_update_guide.md +193 -0
  8. package/doc-smith/references/structure_confirmation_guide.md +133 -0
  9. package/doc-smith/references/structure_planning_guide.md +146 -0
  10. package/doc-smith/references/user_intent_guide.md +172 -0
  11. package/doc-smith.yaml +114 -0
  12. package/main-system-prompt.md +56 -0
  13. package/package.json +3 -69
  14. package/scripts/README.md +90 -0
  15. package/scripts/install.sh +86 -0
  16. package/scripts/uninstall.sh +52 -0
  17. package/CHANGELOG.md +0 -994
  18. package/LICENSE +0 -93
  19. package/agentic-agents/common/base-info.md +0 -53
  20. package/agentic-agents/common/completer.md +0 -54
  21. package/agentic-agents/common/planner.md +0 -168
  22. package/agentic-agents/common/worker.md +0 -93
  23. package/agentic-agents/create/index.yaml +0 -129
  24. package/agentic-agents/create/objective.md +0 -44
  25. package/agentic-agents/create/set-custom-prompt.mjs +0 -27
  26. package/agentic-agents/detail/index.yaml +0 -95
  27. package/agentic-agents/detail/objective.md +0 -9
  28. package/agentic-agents/detail/set-custom-prompt.mjs +0 -88
  29. package/agentic-agents/predict-resources/index.yaml +0 -44
  30. package/agentic-agents/predict-resources/instructions.md +0 -61
  31. package/agentic-agents/structure/design-rules.md +0 -39
  32. package/agentic-agents/structure/index.yaml +0 -86
  33. package/agentic-agents/structure/objective.md +0 -14
  34. package/agentic-agents/structure/review-criteria.md +0 -55
  35. package/agentic-agents/structure/set-custom-prompt.mjs +0 -78
  36. package/agentic-agents/utils/init-workspace-cache.mjs +0 -171
  37. package/agentic-agents/utils/load-base-sources.mjs +0 -20
  38. package/agentic-agents/workspace-cache-sharing-design.md +0 -671
  39. package/agents/chat/chat-system.md +0 -38
  40. package/agents/chat/index.mjs +0 -59
  41. package/agents/chat/skills/generate-document.yaml +0 -15
  42. package/agents/chat/skills/list-documents.mjs +0 -15
  43. package/agents/chat/skills/update-document.yaml +0 -24
  44. package/agents/clear/choose-contents.mjs +0 -192
  45. package/agents/clear/clear-auth-tokens.mjs +0 -88
  46. package/agents/clear/clear-deployment-config.mjs +0 -49
  47. package/agents/clear/clear-document-config.mjs +0 -36
  48. package/agents/clear/clear-document-structure.mjs +0 -102
  49. package/agents/clear/clear-generated-docs.mjs +0 -142
  50. package/agents/clear/clear-media-description.mjs +0 -129
  51. package/agents/clear/index.yaml +0 -26
  52. package/agents/create/analyze-diagram-type-llm.yaml +0 -160
  53. package/agents/create/analyze-diagram-type.mjs +0 -297
  54. package/agents/create/check-document-structure.yaml +0 -30
  55. package/agents/create/check-need-generate-structure.mjs +0 -105
  56. package/agents/create/document-structure-tools/add-document.mjs +0 -85
  57. package/agents/create/document-structure-tools/delete-document.mjs +0 -116
  58. package/agents/create/document-structure-tools/move-document.mjs +0 -109
  59. package/agents/create/document-structure-tools/update-document.mjs +0 -84
  60. package/agents/create/generate-diagram-image.yaml +0 -60
  61. package/agents/create/generate-structure.yaml +0 -117
  62. package/agents/create/index.yaml +0 -49
  63. package/agents/create/refine-document-structure.yaml +0 -12
  64. package/agents/create/replace-d2-with-image.mjs +0 -625
  65. package/agents/create/update-document-structure.yaml +0 -54
  66. package/agents/create/user-add-document/add-documents-to-structure.mjs +0 -90
  67. package/agents/create/user-add-document/find-documents-to-add-links.yaml +0 -47
  68. package/agents/create/user-add-document/index.yaml +0 -46
  69. package/agents/create/user-add-document/prepare-documents-to-translate.mjs +0 -22
  70. package/agents/create/user-add-document/print-add-document-summary.mjs +0 -63
  71. package/agents/create/user-add-document/review-documents-with-new-links.mjs +0 -110
  72. package/agents/create/user-remove-document/find-documents-with-invalid-links.mjs +0 -78
  73. package/agents/create/user-remove-document/index.yaml +0 -40
  74. package/agents/create/user-remove-document/prepare-documents-to-translate.mjs +0 -22
  75. package/agents/create/user-remove-document/print-remove-document-summary.mjs +0 -53
  76. package/agents/create/user-remove-document/remove-documents-from-structure.mjs +0 -99
  77. package/agents/create/user-remove-document/review-documents-with-invalid-links.mjs +0 -115
  78. package/agents/create/user-review-document-structure.mjs +0 -140
  79. package/agents/create/utils/init-current-content.mjs +0 -34
  80. package/agents/create/utils/merge-document-structures.mjs +0 -30
  81. package/agents/evaluate/code-snippet.mjs +0 -97
  82. package/agents/evaluate/document-structure.yaml +0 -67
  83. package/agents/evaluate/document.yaml +0 -82
  84. package/agents/evaluate/generate-report.mjs +0 -85
  85. package/agents/evaluate/index.yaml +0 -46
  86. package/agents/history/index.yaml +0 -6
  87. package/agents/history/view.mjs +0 -78
  88. package/agents/init/check.mjs +0 -16
  89. package/agents/init/index.mjs +0 -275
  90. package/agents/init/validate.mjs +0 -16
  91. package/agents/localize/choose-language.mjs +0 -107
  92. package/agents/localize/index.yaml +0 -58
  93. package/agents/localize/record-translation-history.mjs +0 -23
  94. package/agents/localize/translate-document.yaml +0 -24
  95. package/agents/localize/translate-multilingual.yaml +0 -51
  96. package/agents/media/batch-generate-media-description.yaml +0 -46
  97. package/agents/media/generate-media-description.yaml +0 -50
  98. package/agents/media/load-media-description.mjs +0 -256
  99. package/agents/prefs/index.mjs +0 -203
  100. package/agents/publish/index.yaml +0 -26
  101. package/agents/publish/publish-docs.mjs +0 -356
  102. package/agents/publish/translate-meta.mjs +0 -103
  103. package/agents/schema/document-structure-item.yaml +0 -26
  104. package/agents/schema/document-structure-refine-item.yaml +0 -23
  105. package/agents/schema/document-structure.yaml +0 -29
  106. package/agents/update/batch-generate-document.yaml +0 -27
  107. package/agents/update/batch-update-document.yaml +0 -7
  108. package/agents/update/check-diagram-flag.mjs +0 -116
  109. package/agents/update/check-document.mjs +0 -162
  110. package/agents/update/check-generate-diagram.mjs +0 -106
  111. package/agents/update/check-sync-image-flag.mjs +0 -55
  112. package/agents/update/check-update-is-single.mjs +0 -53
  113. package/agents/update/document-tools/update-document-content.mjs +0 -303
  114. package/agents/update/generate-diagram.yaml +0 -63
  115. package/agents/update/generate-document.yaml +0 -70
  116. package/agents/update/handle-document-update.yaml +0 -103
  117. package/agents/update/index.yaml +0 -79
  118. package/agents/update/pre-check-generate-diagram.yaml +0 -44
  119. package/agents/update/save-and-translate-document.mjs +0 -76
  120. package/agents/update/sync-images-and-exit.mjs +0 -148
  121. package/agents/update/update-document-detail.yaml +0 -71
  122. package/agents/update/update-single/update-single-document-detail.mjs +0 -280
  123. package/agents/update/update-single-document.yaml +0 -7
  124. package/agents/update/user-review-document.mjs +0 -272
  125. package/agents/utils/action-success.mjs +0 -16
  126. package/agents/utils/analyze-document-feedback-intent.yaml +0 -32
  127. package/agents/utils/analyze-feedback-intent.mjs +0 -136
  128. package/agents/utils/analyze-structure-feedback-intent.yaml +0 -29
  129. package/agents/utils/check-detail-result.mjs +0 -38
  130. package/agents/utils/check-feedback-refiner.mjs +0 -81
  131. package/agents/utils/choose-docs.mjs +0 -293
  132. package/agents/utils/document-icon-generate.yaml +0 -52
  133. package/agents/utils/document-title-streamline.yaml +0 -48
  134. package/agents/utils/ensure-document-icons.mjs +0 -129
  135. package/agents/utils/exit.mjs +0 -6
  136. package/agents/utils/feedback-refiner.yaml +0 -50
  137. package/agents/utils/find-item-by-path.mjs +0 -114
  138. package/agents/utils/find-user-preferences-by-path.mjs +0 -37
  139. package/agents/utils/format-document-structure.mjs +0 -35
  140. package/agents/utils/generate-document-or-skip.mjs +0 -41
  141. package/agents/utils/handle-diagram-operations.mjs +0 -263
  142. package/agents/utils/load-all-document-content.mjs +0 -30
  143. package/agents/utils/load-document-all-content.mjs +0 -84
  144. package/agents/utils/load-sources.mjs +0 -405
  145. package/agents/utils/map-reasoning-effort-level.mjs +0 -15
  146. package/agents/utils/post-generate.mjs +0 -144
  147. package/agents/utils/read-current-document-content.mjs +0 -46
  148. package/agents/utils/save-doc-translation.mjs +0 -61
  149. package/agents/utils/save-doc.mjs +0 -88
  150. package/agents/utils/save-output.mjs +0 -26
  151. package/agents/utils/save-sidebar.mjs +0 -51
  152. package/agents/utils/skip-if-content-exists.mjs +0 -27
  153. package/agents/utils/streamline-document-titles-if-needed.mjs +0 -88
  154. package/agents/utils/transform-detail-data-sources.mjs +0 -45
  155. package/agents/utils/update-branding.mjs +0 -84
  156. package/assets/report-template/report.html +0 -198
  157. package/docs-mcp/analyze-content-relevance.yaml +0 -50
  158. package/docs-mcp/analyze-docs-relevance.yaml +0 -59
  159. package/docs-mcp/docs-search.yaml +0 -42
  160. package/docs-mcp/get-docs-detail.mjs +0 -41
  161. package/docs-mcp/get-docs-structure.mjs +0 -16
  162. package/docs-mcp/read-doc-content.mjs +0 -119
  163. package/prompts/common/document/content-rules-core.md +0 -20
  164. package/prompts/common/document/markdown-syntax-rules.md +0 -65
  165. package/prompts/common/document/media-file-list-usage-rules.md +0 -18
  166. package/prompts/common/document/openapi-usage-rules.md +0 -189
  167. package/prompts/common/document/role-and-personality.md +0 -16
  168. package/prompts/common/document/user-preferences.md +0 -9
  169. package/prompts/common/document-structure/conflict-resolution-guidance.md +0 -16
  170. package/prompts/common/document-structure/document-icon-generate.md +0 -116
  171. package/prompts/common/document-structure/document-structure-rules.md +0 -43
  172. package/prompts/common/document-structure/document-title-streamline.md +0 -86
  173. package/prompts/common/document-structure/glossary.md +0 -7
  174. package/prompts/common/document-structure/intj-traits.md +0 -5
  175. package/prompts/common/document-structure/openapi-usage-rules.md +0 -28
  176. package/prompts/common/document-structure/output-constraints.md +0 -18
  177. package/prompts/common/document-structure/user-locale-rules.md +0 -10
  178. package/prompts/common/document-structure/user-preferences.md +0 -9
  179. package/prompts/detail/custom/admonition-usage-rules.md +0 -94
  180. package/prompts/detail/custom/code-block-usage-rules.md +0 -163
  181. package/prompts/detail/custom/custom-components/x-card-usage-rules.md +0 -63
  182. package/prompts/detail/custom/custom-components/x-cards-usage-rules.md +0 -83
  183. package/prompts/detail/custom/custom-components/x-field-desc-usage-rules.md +0 -120
  184. package/prompts/detail/custom/custom-components/x-field-group-usage-rules.md +0 -80
  185. package/prompts/detail/custom/custom-components/x-field-usage-rules.md +0 -189
  186. package/prompts/detail/custom/custom-components-usage-rules.md +0 -18
  187. package/prompts/detail/diagram/generate-image-system.md +0 -135
  188. package/prompts/detail/diagram/generate-image-user.md +0 -32
  189. package/prompts/detail/diagram/guide.md +0 -29
  190. package/prompts/detail/diagram/official-examples.md +0 -712
  191. package/prompts/detail/diagram/pre-check.md +0 -23
  192. package/prompts/detail/diagram/role-and-personality.md +0 -2
  193. package/prompts/detail/diagram/rules.md +0 -46
  194. package/prompts/detail/diagram/system-prompt.md +0 -1139
  195. package/prompts/detail/diagram/user-prompt.md +0 -43
  196. package/prompts/detail/generate/detail-example.md +0 -457
  197. package/prompts/detail/generate/document-rules.md +0 -45
  198. package/prompts/detail/generate/system-prompt.md +0 -61
  199. package/prompts/detail/generate/user-prompt.md +0 -99
  200. package/prompts/detail/jsx/rules.md +0 -6
  201. package/prompts/detail/update/system-prompt.md +0 -121
  202. package/prompts/detail/update/user-prompt.md +0 -41
  203. package/prompts/evaluate/document-structure.md +0 -93
  204. package/prompts/evaluate/document.md +0 -149
  205. package/prompts/media/media-description/system-prompt.md +0 -43
  206. package/prompts/media/media-description/user-prompt.md +0 -17
  207. package/prompts/structure/check-document-structure.md +0 -93
  208. package/prompts/structure/document-rules.md +0 -21
  209. package/prompts/structure/find-documents-to-add-links.md +0 -52
  210. package/prompts/structure/generate/system-prompt.md +0 -13
  211. package/prompts/structure/generate/user-prompt.md +0 -137
  212. package/prompts/structure/review/structure-review-system.md +0 -81
  213. package/prompts/structure/structure-example.md +0 -89
  214. package/prompts/structure/structure-getting-started.md +0 -10
  215. package/prompts/structure/update/system-prompt.md +0 -93
  216. package/prompts/structure/update/user-prompt.md +0 -43
  217. package/prompts/translate/admonition.md +0 -20
  218. package/prompts/translate/code-block.md +0 -33
  219. package/prompts/translate/glossary.md +0 -6
  220. package/prompts/translate/translate-document.md +0 -305
  221. package/prompts/utils/analyze-document-feedback-intent.md +0 -54
  222. package/prompts/utils/analyze-structure-feedback-intent.md +0 -43
  223. package/prompts/utils/feedback-refiner.md +0 -105
  224. package/types/document-schema.mjs +0 -55
  225. package/types/document-structure-schema.mjs +0 -261
  226. package/utils/auth-utils.mjs +0 -275
  227. package/utils/blocklet.mjs +0 -104
  228. package/utils/check-document-has-diagram.mjs +0 -95
  229. package/utils/conflict-detector.mjs +0 -149
  230. package/utils/constants/index.mjs +0 -620
  231. package/utils/constants/linter.mjs +0 -102
  232. package/utils/d2-utils.mjs +0 -198
  233. package/utils/debug.mjs +0 -3
  234. package/utils/delete-diagram-images.mjs +0 -99
  235. package/utils/deploy.mjs +0 -86
  236. package/utils/docs-finder-utils.mjs +0 -623
  237. package/utils/evaluate/report-utils.mjs +0 -132
  238. package/utils/extract-api.mjs +0 -32
  239. package/utils/file-utils.mjs +0 -960
  240. package/utils/history-utils.mjs +0 -203
  241. package/utils/icon-map.mjs +0 -26
  242. package/utils/image-compress.mjs +0 -75
  243. package/utils/kroki-utils.mjs +0 -173
  244. package/utils/linter/index.mjs +0 -50
  245. package/utils/load-config.mjs +0 -107
  246. package/utils/markdown/index.mjs +0 -26
  247. package/utils/markdown-checker.mjs +0 -694
  248. package/utils/mermaid-validator.mjs +0 -140
  249. package/utils/mermaid-worker-pool.mjs +0 -250
  250. package/utils/mermaid-worker.mjs +0 -233
  251. package/utils/openapi/index.mjs +0 -28
  252. package/utils/preferences-utils.mjs +0 -175
  253. package/utils/request.mjs +0 -10
  254. package/utils/store/index.mjs +0 -45
  255. package/utils/sync-diagram-to-translations.mjs +0 -262
  256. package/utils/upload-files.mjs +0 -231
  257. package/utils/utils.mjs +0 -1354
@@ -1,162 +0,0 @@
1
- import { access, readFile } from "node:fs/promises";
2
- import { dirname, join } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { TeamAgent } from "@aigne/core";
5
- import fs from "fs-extra";
6
- import pMap from "p-map";
7
-
8
- import { getFileName } from "../../utils/utils.mjs";
9
- import checkDetailResult from "../utils/check-detail-result.mjs";
10
-
11
- // Get current script directory
12
- const __dirname = dirname(fileURLToPath(import.meta.url));
13
-
14
- export default async function checkDocument(
15
- {
16
- path,
17
- docsDir,
18
- sourceIds,
19
- originalDocumentStructure,
20
- documentStructure,
21
- modifiedFiles,
22
- forceRegenerate,
23
- locale,
24
- translates = [],
25
- ...rest
26
- },
27
- options,
28
- ) {
29
- // Check if the detail file already exists
30
- const fileFullName = getFileName(path, locale);
31
- const filePath = join(docsDir, fileFullName);
32
- let detailGenerated = true;
33
- let fileContent = null;
34
- try {
35
- await access(filePath);
36
- // If file exists, read its content for validation
37
- fileContent = await readFile(filePath, "utf8");
38
- } catch {
39
- detailGenerated = false;
40
- }
41
-
42
- // Check if sourceIds have changed by comparing with original documentation structure
43
- let sourceIdsChanged = false;
44
- if (originalDocumentStructure && sourceIds) {
45
- // Find the original node in the documentation structure
46
- const originalNode = originalDocumentStructure.find((node) => node.path === path);
47
-
48
- if (originalNode?.sourceIds) {
49
- const originalSourceIds = originalNode.sourceIds;
50
- const currentSourceIds = sourceIds;
51
-
52
- // Compare arrays (order doesn't matter, but content does)
53
- if (originalSourceIds.length !== currentSourceIds.length) {
54
- sourceIdsChanged = true;
55
- } else {
56
- // Check if any sourceId is different
57
- const originalSet = new Set(originalSourceIds);
58
- const currentSet = new Set(currentSourceIds);
59
-
60
- if (originalSet.size !== currentSet.size) {
61
- sourceIdsChanged = true;
62
- } else {
63
- // Check if any element is different
64
- for (const sourceId of originalSourceIds) {
65
- if (!currentSet.has(sourceId)) {
66
- sourceIdsChanged = true;
67
- break;
68
- }
69
- }
70
- }
71
- }
72
- }
73
- }
74
-
75
- // If file exists, check content validation
76
- let contentValidationFailed = false;
77
- let validationResult = {};
78
- if (detailGenerated && fileContent && documentStructure) {
79
- validationResult = await checkDetailResult({
80
- documentStructure,
81
- reviewContent: fileContent,
82
- docsDir,
83
- });
84
-
85
- if (!validationResult.isApproved) {
86
- contentValidationFailed = true;
87
- }
88
- }
89
- const translateList = Array.isArray(translates) ? translates : [];
90
- const languages = translateList.map((x) => x.language);
91
- const lackLanguages = new Set(languages);
92
- const skills = [];
93
-
94
- // If file exists, sourceIds haven't changed, source files haven't changed, and content validation passes, no need to regenerate
95
- if (detailGenerated && !sourceIdsChanged && !contentValidationFailed && !forceRegenerate) {
96
- await pMap(
97
- languages,
98
- async (x) => {
99
- const languageFileName = getFileName(path, x);
100
- const languageFilePath = join(docsDir, languageFileName);
101
- if (await fs.exists(languageFilePath)) {
102
- lackLanguages.delete(x);
103
- }
104
- },
105
- { concurrency: 5 },
106
- );
107
- if (lackLanguages.size === 0) {
108
- return {
109
- path,
110
- docsDir,
111
- ...rest,
112
- detailGenerated: true,
113
- };
114
- }
115
- // translations during generation don't need feedback, content is satisfactory
116
- rest.content = fileContent;
117
- } else {
118
- skills.push(options.context.agents["handleDocumentUpdate"]);
119
- }
120
-
121
- skills.push(options.context.agents["translateMultilingual"]);
122
-
123
- const teamAgent = TeamAgent.from({
124
- name: "generateDocument",
125
- skills,
126
- });
127
- let openAPISpec = null;
128
-
129
- if (options.context?.userContext?.openAPISpec?.sourceId) {
130
- const matchingDocument = originalDocumentStructure.find((item) => {
131
- if (item.path === path) {
132
- return item.sourceIds.find((x) => x === options.context.userContext.openAPISpec.sourceId);
133
- }
134
- return false;
135
- });
136
- if (matchingDocument) {
137
- openAPISpec = options.context.userContext.openAPISpec;
138
- }
139
- }
140
-
141
- const result = await options.context.invoke(teamAgent, {
142
- ...rest,
143
- translates: translateList.filter((x) => lackLanguages.has(x.language)),
144
- locale,
145
- docsDir,
146
- path,
147
- sourceIds,
148
- originalDocumentStructure,
149
- documentStructure,
150
- detailFeedback: contentValidationFailed ? validationResult.detailFeedback : "",
151
- openAPISpec,
152
- });
153
-
154
- return {
155
- path,
156
- docsDir,
157
- ...rest,
158
- result,
159
- };
160
- }
161
-
162
- checkDocument.taskTitle = "Check if '{{ title }}' needs generate or update";
@@ -1,106 +0,0 @@
1
- import { hasDiagramContent } from "../../utils/check-document-has-diagram.mjs";
2
-
3
- const DEFAULT_DIAGRAMMING_EFFORT = 5;
4
- const MIN_DIAGRAMMING_EFFORT = 0;
5
- const MAX_DIAGRAMMING_EFFORT = 10;
6
-
7
- export default async function checkGenerateDiagram(
8
- {
9
- documentContent,
10
- locale,
11
- feedback,
12
- detailFeedback,
13
- originalContent,
14
- diagramming,
15
- path,
16
- docsDir,
17
- shouldUpdateDiagrams,
18
- },
19
- options,
20
- ) {
21
- let content = documentContent;
22
- let skipGenerateDiagram = false;
23
-
24
- // If --diagram flag is set and document already has d2 code blocks,
25
- // skip preCheck and directly replace existing diagrams
26
- // This is because when using --diagram/--diagram-all, the user explicitly wants to update diagrams,
27
- // so we should skip the "do we need to generate diagram" check and directly proceed to replacement
28
- const hasExistingDiagrams = originalContent && hasDiagramContent(originalContent);
29
-
30
- // Skip preCheck if:
31
- // 1. Using --diagram/--diagram-all flag (shouldUpdateDiagrams === true) AND
32
- // 2. Document already has d2 code blocks (hasExistingDiagrams === true)
33
- // This means user explicitly wants to update existing diagrams, no need to check if diagram is needed
34
- const shouldSkipPreCheck = shouldUpdateDiagrams === true && hasExistingDiagrams;
35
-
36
- let preCheckResult = { details: [], content: null };
37
- if (!shouldSkipPreCheck) {
38
- const preCheckAgent = options.context?.agents?.["preCheckGenerateDiagram"];
39
-
40
- preCheckResult = await options.context.invoke(preCheckAgent, {
41
- documentContent,
42
- feedback,
43
- detailFeedback,
44
- previousGenerationContent: originalContent,
45
- });
46
- }
47
-
48
- const totalScore = (preCheckResult.details || []).reduce((acc, curr) => acc + curr.score, 0);
49
- if (![false, "false", "", undefined, null].includes(preCheckResult.content)) {
50
- content = preCheckResult.content;
51
- }
52
-
53
- let diagrammingEffort = diagramming?.effort
54
- ? Number(diagramming?.effort)
55
- : DEFAULT_DIAGRAMMING_EFFORT;
56
-
57
- if (Number.isNaN(diagrammingEffort)) {
58
- diagrammingEffort = DEFAULT_DIAGRAMMING_EFFORT;
59
- } else {
60
- diagrammingEffort = Math.min(
61
- Math.max(MIN_DIAGRAMMING_EFFORT, diagrammingEffort),
62
- MAX_DIAGRAMMING_EFFORT,
63
- );
64
- }
65
-
66
- // If we skipped preCheck because document has existing diagrams and --diagram flag is set,
67
- // we should NOT skip generating diagram (we need to replace existing ones)
68
- if (shouldSkipPreCheck) {
69
- skipGenerateDiagram = false;
70
- } else if (totalScore <= diagrammingEffort) {
71
- skipGenerateDiagram = true;
72
- }
73
-
74
- if (skipGenerateDiagram) {
75
- content = documentContent;
76
- } else {
77
- try {
78
- const generateAgent = options.context?.agents?.["generateDiagram"];
79
- const result = await options.context.invoke(generateAgent, {
80
- documentContent: content,
81
- locale,
82
- diagramming: diagramming || {},
83
- feedback: feedback || "",
84
- originalContent: originalContent || documentContent,
85
- path,
86
- docsDir,
87
- });
88
-
89
- // generateDiagram now returns { content } with image already inserted
90
- // The image replaces DIAGRAM_PLACEHOLDER or D2 code blocks
91
- if (result?.content) {
92
- content = result.content;
93
- } else {
94
- // Fallback: if no content returned, use original document content
95
- content = documentContent;
96
- }
97
- } catch (error) {
98
- skipGenerateDiagram = true;
99
- console.log(`⚠️ Skip generate any diagram: ${error.message}`);
100
- // On error, return original document content
101
- content = documentContent;
102
- }
103
- }
104
-
105
- return { content };
106
- }
@@ -1,55 +0,0 @@
1
- /**
2
- * Check if --diagram-sync flag is set via command line arguments or environment variable
3
- * Returns the flag value and passes through all input
4
- *
5
- * --diagram-sync: Auto-select all documents with banana images and sync to translations
6
- */
7
- export default function checkSyncImageFlag(input) {
8
- let shouldSyncImages = false;
9
-
10
- // Check command line arguments first (highest priority)
11
- if (process.argv) {
12
- const hasSyncImageFlag = process.argv.some((arg) => arg === "--diagram-sync" || arg === "-ds");
13
- if (hasSyncImageFlag) {
14
- shouldSyncImages = true;
15
- }
16
- }
17
-
18
- // Check input parameter
19
- if (input["diagram-sync"] === true || input.diagramSync === true) {
20
- shouldSyncImages = true;
21
- }
22
-
23
- // Check environment variable
24
- if (process.env.DOC_SMITH_SYNC_IMAGES === "true" || process.env.DOC_SMITH_SYNC_IMAGES === "1") {
25
- shouldSyncImages = true;
26
- }
27
-
28
- // Return all input plus the flag
29
- return {
30
- ...input,
31
- shouldSyncImages,
32
- };
33
- }
34
-
35
- checkSyncImageFlag.input_schema = {
36
- type: "object",
37
- properties: {
38
- "diagram-sync": {
39
- type: ["boolean", "string"],
40
- description:
41
- "Flag to sync images to translations (can also use --diagram-sync CLI arg or DOC_SMITH_SYNC_IMAGES env var)",
42
- },
43
- },
44
- };
45
-
46
- checkSyncImageFlag.output_schema = {
47
- type: "object",
48
- properties: {
49
- shouldSyncImages: {
50
- type: "boolean",
51
- description: "Whether to sync images to translations",
52
- },
53
- },
54
- required: ["shouldSyncImages"],
55
- };
@@ -1,53 +0,0 @@
1
- export default async function checkUpdateIsSingle({ selectedDocs, ...rest }, options) {
2
- if (!selectedDocs || !Array.isArray(selectedDocs)) {
3
- throw new Error("A list of documents to update must be provided.");
4
- }
5
-
6
- if (selectedDocs.length === 0) {
7
- throw new Error("You must select at least one document to update.");
8
- }
9
-
10
- let targetAgent;
11
- let agentName;
12
-
13
- if (selectedDocs.length === 1 && !rest.reset) {
14
- // Single doc update without reset
15
- agentName = "updateSingleDocument";
16
- targetAgent = options.context.agents["updateSingleDocument"];
17
- } else {
18
- agentName = "batchUpdateDocument";
19
- targetAgent = options.context.agents["batchUpdateDocument"];
20
- }
21
-
22
- if (!targetAgent) {
23
- throw new Error(`Sorry, I can't seem to find the "${agentName}" agent.`);
24
- }
25
-
26
- try {
27
- const result = await options.context.invoke(targetAgent, {
28
- selectedDocs,
29
- ...rest,
30
- });
31
-
32
- // For batch updates, preserve selectedDocs and other context for save-and-translate-document
33
- // batchUpdateDocument returns an array of results, but save-and-translate-document needs selectedDocs
34
- if (agentName === "batchUpdateDocument") {
35
- return {
36
- ...rest,
37
- selectedDocs, // Preserve selectedDocs for save-and-translate-document.mjs
38
- result, // Include the batch update results
39
- };
40
- }
41
-
42
- // For single document updates, return result as-is
43
- return result;
44
- } catch (error) {
45
- console.error(
46
- `Sorry, I encountered an error while trying to run the ${agentName} agent:`,
47
- error.message,
48
- );
49
- throw error;
50
- }
51
- }
52
-
53
- checkUpdateIsSingle.taskTitle = "Check document count and route to appropriate update agent";
@@ -1,303 +0,0 @@
1
- import { applyPatch } from "diff";
2
- import {
3
- getUpdateDocumentContentInputJsonSchema,
4
- getUpdateDocumentContentOutputJsonSchema,
5
- validateUpdateDocumentContentInput,
6
- } from "../../../types/document-schema.mjs";
7
- import { userContextAt } from "../../../utils/utils.mjs";
8
-
9
- export default async function updateDocumentContent(input, options) {
10
- // Validate input using Zod schema
11
- const validation = validateUpdateDocumentContentInput(input);
12
- if (!validation.success) {
13
- return {
14
- success: false,
15
- error: { message: validation.error },
16
- };
17
- }
18
-
19
- const { diffPatch, path } = validation.data;
20
-
21
- // Get originalContent from shared context using path, fallback to input
22
- const contentContext = userContextAt(options, `currentContents.${path}`);
23
- let originalContent = contentContext.get();
24
-
25
- if (!originalContent) {
26
- originalContent = input.originalContent;
27
- }
28
-
29
- try {
30
- // Parse and validate diff patch
31
- const parsedDiff = parseDiffPatch(diffPatch);
32
- if (!parsedDiff.success) {
33
- return {
34
- success: false,
35
- error: { message: parsedDiff.error },
36
- };
37
- }
38
-
39
- // Check and fix line number issues
40
- const fixedDiff = fixLineNumberIssues(originalContent, parsedDiff.hunks);
41
- if (!fixedDiff.success) {
42
- return {
43
- success: false,
44
- error: { message: fixedDiff.error },
45
- };
46
- }
47
-
48
- // Reconstruct the fixed diff patch
49
- const fixedPatch = reconstructDiffPatch(fixedDiff.hunks);
50
-
51
- // Apply the diff patch using the diff library
52
- const result = applyPatch(originalContent, fixedPatch);
53
-
54
- if (result === false) {
55
- return {
56
- success: false,
57
- error: { message: "Failed to apply patch" },
58
- };
59
- }
60
-
61
- // Update shared context with new content using path
62
- contentContext.set(result);
63
-
64
- return {
65
- success: true,
66
- updatedContent: `<page_content>
67
- ${result}
68
- </page_content>`,
69
- message:
70
- "Document content updated successfully.\nCheck if updatedContent meets user feedback, if so, just return 'success'.",
71
- };
72
- } catch (error) {
73
- return {
74
- success: false,
75
- error: { message: error.message },
76
- };
77
- }
78
- }
79
-
80
- function parseDiffPatch(diffPatch) {
81
- try {
82
- const hunks = [];
83
- const lines = diffPatch.split("\n");
84
- let currentHunk = null;
85
-
86
- for (let i = 0; i < lines.length; i++) {
87
- const line = lines[i];
88
-
89
- // Parse hunk header: @@ -oldStart,oldCount +newStart,newCount @@
90
- const hunkMatch = line.match(/^@@\s+-(\d+)(?:,(\d+))?\s+\+(\d+)(?:,(\d+))?\s+@@/);
91
- if (hunkMatch) {
92
- if (currentHunk) {
93
- hunks.push(currentHunk);
94
- }
95
- currentHunk = {
96
- oldStart: parseInt(hunkMatch[1], 10),
97
- oldCount: parseInt(hunkMatch[2], 10) || 1,
98
- newStart: parseInt(hunkMatch[3], 10),
99
- newCount: parseInt(hunkMatch[4], 10) || 1,
100
- changes: [],
101
- };
102
- continue;
103
- }
104
-
105
- // Parse changes
106
- if (currentHunk && line.length > 0) {
107
- const changeType = line[0];
108
- const content = line.slice(1);
109
-
110
- if (changeType === "-") {
111
- currentHunk.changes.push({ type: "remove", content });
112
- } else if (changeType === "+") {
113
- currentHunk.changes.push({ type: "add", content });
114
- } else if (changeType === " ") {
115
- currentHunk.changes.push({ type: "context", content });
116
- }
117
- }
118
- }
119
-
120
- if (currentHunk) {
121
- hunks.push(currentHunk);
122
- }
123
-
124
- if (hunks.length === 0) {
125
- return { success: false, error: "No valid hunks found in diff" };
126
- }
127
-
128
- return { success: true, hunks };
129
- } catch (error) {
130
- return { success: false, error: `Failed to parse diff: ${error.message}` };
131
- }
132
- }
133
-
134
- function fixLineNumberIssues(originalContent, hunks) {
135
- try {
136
- const originalLines = originalContent.split("\n");
137
- const fixedHunks = [];
138
-
139
- for (const hunk of hunks) {
140
- // Extract context and removed lines to find best match
141
- const contextAndRemoved = hunk.changes
142
- .filter((change) => change.type === "context" || change.type === "remove")
143
- .map((change) => change.content);
144
-
145
- if (contextAndRemoved.length === 0) {
146
- // No context to match against, keep original
147
- fixedHunks.push(hunk);
148
- continue;
149
- }
150
-
151
- // Find best matching position in original content
152
- const bestMatch = findBestMatch(originalLines, contextAndRemoved, hunk.oldStart - 1);
153
-
154
- if (bestMatch.found) {
155
- const fixedHunk = {
156
- ...hunk,
157
- oldStart: bestMatch.position + 1,
158
- newStart: bestMatch.position + 1,
159
- // Fix line counts based on actual changes
160
- oldCount: calculateOldCount(hunk.changes),
161
- newCount: calculateNewCount(hunk.changes),
162
- };
163
- fixedHunks.push(fixedHunk);
164
- } else {
165
- // Try fuzzy matching
166
- const fuzzyMatch = findFuzzyMatch(originalLines, contextAndRemoved);
167
- if (fuzzyMatch.found) {
168
- const fixedHunk = {
169
- ...hunk,
170
- oldStart: fuzzyMatch.position + 1,
171
- newStart: fuzzyMatch.position + 1,
172
- // Fix line counts based on actual changes
173
- oldCount: calculateOldCount(hunk.changes),
174
- newCount: calculateNewCount(hunk.changes),
175
- };
176
- fixedHunks.push(fixedHunk);
177
- } else {
178
- return {
179
- success: false,
180
- error: `Cannot find matching context for hunk at line ${hunk.oldStart}`,
181
- };
182
- }
183
- }
184
- }
185
-
186
- return { success: true, hunks: fixedHunks };
187
- } catch (error) {
188
- return { success: false, error: `Failed to fix line numbers: ${error.message}` };
189
- }
190
- }
191
-
192
- function findBestMatch(originalLines, targetLines, startPosition) {
193
- // Try exact match at expected position first
194
- if (startPosition >= 0 && startPosition + targetLines.length <= originalLines.length) {
195
- let matches = 0;
196
- for (let i = 0; i < targetLines.length; i++) {
197
- if (originalLines[startPosition + i] === targetLines[i]) {
198
- matches++;
199
- }
200
- }
201
-
202
- if (matches === targetLines.length) {
203
- return { found: true, position: startPosition };
204
- }
205
- }
206
-
207
- // Try nearby positions (within 10 lines)
208
- const NEARBY_SEARCH_RANGE = 10; // Maximum number of lines to search before/after expected position
209
- for (let offset = 1; offset <= NEARBY_SEARCH_RANGE; offset++) {
210
- // Try before
211
- const beforePos = startPosition - offset;
212
- if (beforePos >= 0 && beforePos + targetLines.length <= originalLines.length) {
213
- let matches = 0;
214
- for (let i = 0; i < targetLines.length; i++) {
215
- if (originalLines[beforePos + i] === targetLines[i]) {
216
- matches++;
217
- }
218
- }
219
- if (matches === targetLines.length) {
220
- return { found: true, position: beforePos };
221
- }
222
- }
223
-
224
- // Try after
225
- const afterPos = startPosition + offset;
226
- if (afterPos >= 0 && afterPos + targetLines.length <= originalLines.length) {
227
- let matches = 0;
228
- for (let i = 0; i < targetLines.length; i++) {
229
- if (originalLines[afterPos + i] === targetLines[i]) {
230
- matches++;
231
- }
232
- }
233
- if (matches === targetLines.length) {
234
- return { found: true, position: afterPos };
235
- }
236
- }
237
- }
238
-
239
- return { found: false };
240
- }
241
-
242
- function findFuzzyMatch(originalLines, targetLines) {
243
- // Find the best partial match
244
- let bestMatch = { found: false, position: 0, score: 0 };
245
-
246
- for (let pos = 0; pos <= originalLines.length - targetLines.length; pos++) {
247
- let matches = 0;
248
- for (let i = 0; i < targetLines.length; i++) {
249
- if (originalLines[pos + i] === targetLines[i]) {
250
- matches++;
251
- }
252
- }
253
-
254
- const score = matches / targetLines.length;
255
- const FUZZY_MATCH_THRESHOLD = 0.7; // 70% similarity threshold for fuzzy matching
256
- if (score > bestMatch.score && score >= FUZZY_MATCH_THRESHOLD) {
257
- bestMatch = { found: true, position: pos, score };
258
- }
259
- }
260
-
261
- return bestMatch;
262
- }
263
-
264
- function calculateOldCount(changes) {
265
- const contextCount = changes.filter((c) => c.type === "context").length;
266
- const removeCount = changes.filter((c) => c.type === "remove").length;
267
- return contextCount + removeCount;
268
- }
269
-
270
- function calculateNewCount(changes) {
271
- const contextCount = changes.filter((c) => c.type === "context").length;
272
- const addCount = changes.filter((c) => c.type === "add").length;
273
- return contextCount + addCount;
274
- }
275
-
276
- function reconstructDiffPatch(hunks) {
277
- let patchContent = "";
278
-
279
- for (const hunk of hunks) {
280
- // Add hunk header
281
- const oldRange = hunk.oldCount === 1 ? hunk.oldStart : `${hunk.oldStart},${hunk.oldCount}`;
282
- const newRange = hunk.newCount === 1 ? hunk.newStart : `${hunk.newStart},${hunk.newCount}`;
283
- patchContent += `@@ -${oldRange} +${newRange} @@\n`;
284
-
285
- // Add changes
286
- for (const change of hunk.changes) {
287
- if (change.type === "context") {
288
- patchContent += ` ${change.content}\n`;
289
- } else if (change.type === "remove") {
290
- patchContent += `-${change.content}\n`;
291
- } else if (change.type === "add") {
292
- patchContent += `+${change.content}\n`;
293
- }
294
- }
295
- }
296
-
297
- return patchContent;
298
- }
299
-
300
- updateDocumentContent.inputSchema = getUpdateDocumentContentInputJsonSchema();
301
- updateDocumentContent.outputSchema = getUpdateDocumentContentOutputJsonSchema();
302
-
303
- updateDocumentContent.description = "Apply diff patch to update markdown document content";