@aigne/doc-smith 0.9.10 → 0.9.11-beta

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 (308) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +189 -219
  3. package/README.zh.md +270 -0
  4. package/agents/bash-executor/index.mjs +347 -0
  5. package/agents/clear/ai/intent.md +142 -0
  6. package/agents/clear/choose-contents.mjs +13 -65
  7. package/agents/clear/clear-auth-tokens.mjs +17 -21
  8. package/agents/clear/clear-deployment-config.mjs +33 -24
  9. package/agents/clear/index.yaml +1 -9
  10. package/agents/content-checker/ai/intent.md +209 -0
  11. package/agents/content-checker/clean-invalid-docs.mjs +254 -0
  12. package/agents/content-checker/index.mjs +191 -0
  13. package/agents/content-checker/validate-content.mjs +983 -0
  14. package/agents/generate-images/generate-image.yaml +75 -0
  15. package/agents/generate-images/generate-summary.mjs +213 -0
  16. package/agents/generate-images/index.yaml +39 -0
  17. package/agents/generate-images/prepare-generation.mjs +286 -0
  18. package/agents/generate-images/prepare-image-generation.mjs +130 -0
  19. package/{prompts/detail/diagram/generate-image-system.md → agents/generate-images/prompts/system.md} +22 -56
  20. package/agents/generate-images/prompts/user.md +85 -0
  21. package/agents/generate-images/save-image-result.mjs +247 -0
  22. package/agents/generate-images/scan-image-slots.mjs +247 -0
  23. package/agents/localize/index.yaml +19 -42
  24. package/{prompts/translate → agents/localize/prompts}/translate-document.md +0 -139
  25. package/agents/localize/translate-documents/generate-summary.mjs +163 -0
  26. package/agents/localize/translate-documents/load-glossary.mjs +52 -0
  27. package/agents/localize/translate-documents/prepare-translation.mjs +249 -0
  28. package/agents/localize/translate-documents/save-translation.mjs +171 -0
  29. package/agents/localize/translate-documents/translate-document-to-language.mjs +209 -0
  30. package/agents/localize/translate-documents/translate-document.yaml +23 -0
  31. package/agents/localize/translate-documents/translate-to-languages.yaml +10 -0
  32. package/agents/localize/translate-images/check-image-translation.mjs +225 -0
  33. package/agents/localize/translate-images/detect-text/detect-and-update-shared.mjs +148 -0
  34. package/agents/localize/translate-images/detect-text/detect-image-text.yaml +44 -0
  35. package/agents/localize/translate-images/detect-text/detect-images-text.yaml +21 -0
  36. package/agents/localize/translate-images/detect-text/prompts/detect-image-text-system.md +43 -0
  37. package/agents/localize/translate-images/detect-text/prompts/detect-image-text-user.md +14 -0
  38. package/agents/localize/translate-images/detect-text/save-text-detection.mjs +105 -0
  39. package/agents/localize/translate-images/prepare-image-input.mjs +124 -0
  40. package/agents/localize/translate-images/save-image-translation.mjs +172 -0
  41. package/agents/localize/translate-images/scan-doc-images.mjs +165 -0
  42. package/agents/localize/translate-images/translate-doc-images.yaml +24 -0
  43. package/agents/localize/{translate-diagram.yaml → translate-images/translate-image.yaml} +25 -14
  44. package/agents/publish/ai/intent.md +182 -0
  45. package/agents/publish/check.mjs +107 -0
  46. package/agents/publish/index.yaml +9 -14
  47. package/agents/publish/publish-docs.mjs +81 -61
  48. package/agents/publish/translate-meta.mjs +79 -58
  49. package/agents/save-document/index.mjs +260 -0
  50. package/agents/structure-checker/index.mjs +307 -0
  51. package/agents/structure-checker/validate-structure.mjs +477 -0
  52. package/agents/update-image/analyze-feedback.yaml +37 -0
  53. package/agents/update-image/index.yaml +78 -0
  54. package/agents/update-image/load-existing-image.mjs +211 -0
  55. package/agents/update-image/prompts/analyze-feedback-system.md +43 -0
  56. package/agents/update-image/prompts/analyze-feedback-user.md +15 -0
  57. package/aigne.yaml +26 -139
  58. package/package.json +16 -48
  59. package/scripts/README.md +90 -0
  60. package/scripts/install.sh +86 -0
  61. package/scripts/uninstall.sh +52 -0
  62. package/skills/doc-smith/SKILL.md +285 -0
  63. package/skills/doc-smith/ai/intent/sources-improve.md +290 -0
  64. package/skills/doc-smith/references/changeset-guide.md +171 -0
  65. package/skills/doc-smith/references/document-content-guide.md +214 -0
  66. package/skills/doc-smith/references/document-structure-schema.md +138 -0
  67. package/skills/doc-smith/references/patch-guide.md +96 -0
  68. package/skills/doc-smith/references/structure-confirmation-guide.md +133 -0
  69. package/skills/doc-smith/references/structure-planning-guide.md +149 -0
  70. package/skills/doc-smith/references/update-workflow.md +108 -0
  71. package/skills/doc-smith/references/user-intent-guide.md +175 -0
  72. package/skills/doc-smith/references/workspace-initialization.md +376 -0
  73. package/skills/doc-smith-docs-detail/SKILL.md +356 -0
  74. package/skills/doc-smith-docs-detail/ai/intent.md +271 -0
  75. package/skills-entry/doc-smith/ai/intent.md +260 -0
  76. package/skills-entry/doc-smith/index.mjs +66 -0
  77. package/skills-entry/doc-smith/prompt.md +57 -0
  78. package/skills-entry/doc-smith/utils.mjs +27 -0
  79. package/skills-entry/doc-smith-docs-detail/batch.yaml +56 -0
  80. package/skills-entry/doc-smith-docs-detail/index.mjs +95 -0
  81. package/skills-entry/doc-smith-docs-detail/prompt.md +64 -0
  82. package/utils/afs-factory.mjs +183 -0
  83. package/utils/agent-constants.mjs +97 -0
  84. package/utils/{auth-utils.mjs → auth.mjs} +6 -9
  85. package/{agents/utils/update-branding.mjs → utils/branding.mjs} +3 -4
  86. package/utils/config.mjs +261 -0
  87. package/utils/constants.mjs +32 -0
  88. package/utils/deploy.mjs +3 -3
  89. package/utils/docs-converter.mjs +454 -0
  90. package/utils/docs.mjs +212 -0
  91. package/utils/document-paths.mjs +172 -0
  92. package/utils/files.mjs +74 -0
  93. package/utils/git.mjs +65 -0
  94. package/utils/{blocklet.mjs → http.mjs} +18 -0
  95. package/utils/image-slots.mjs +57 -0
  96. package/utils/image-utils.mjs +114 -0
  97. package/utils/project.mjs +95 -0
  98. package/utils/sources-path-resolver.mjs +76 -0
  99. package/utils/{upload-files.mjs → upload.mjs} +3 -3
  100. package/utils/workspace.mjs +371 -0
  101. package/agents/chat/chat-system.md +0 -38
  102. package/agents/chat/index.mjs +0 -59
  103. package/agents/chat/skills/generate-document.yaml +0 -15
  104. package/agents/chat/skills/list-documents.mjs +0 -15
  105. package/agents/chat/skills/update-document.yaml +0 -24
  106. package/agents/clear/clear-document-config.mjs +0 -36
  107. package/agents/clear/clear-document-structure.mjs +0 -102
  108. package/agents/clear/clear-generated-docs.mjs +0 -142
  109. package/agents/clear/clear-media-description.mjs +0 -129
  110. package/agents/create/aggregate-document-structure.mjs +0 -21
  111. package/agents/create/analyze-diagram-type-llm.yaml +0 -159
  112. package/agents/create/analyze-diagram-type.mjs +0 -455
  113. package/agents/create/check-document-structure.yaml +0 -30
  114. package/agents/create/check-need-generate-structure.mjs +0 -138
  115. package/agents/create/document-structure-tools/add-document.mjs +0 -85
  116. package/agents/create/document-structure-tools/delete-document.mjs +0 -116
  117. package/agents/create/document-structure-tools/move-document.mjs +0 -109
  118. package/agents/create/document-structure-tools/update-document.mjs +0 -84
  119. package/agents/create/generate-diagram-image.yaml +0 -91
  120. package/agents/create/generate-structure.yaml +0 -106
  121. package/agents/create/index.yaml +0 -45
  122. package/agents/create/refine-document-structure.yaml +0 -12
  123. package/agents/create/replace-d2-with-image.mjs +0 -610
  124. package/agents/create/update-document-structure.yaml +0 -54
  125. package/agents/create/user-add-document/add-documents-to-structure.mjs +0 -90
  126. package/agents/create/user-add-document/find-documents-to-add-links.yaml +0 -47
  127. package/agents/create/user-add-document/index.yaml +0 -46
  128. package/agents/create/user-add-document/prepare-documents-to-translate.mjs +0 -22
  129. package/agents/create/user-add-document/print-add-document-summary.mjs +0 -63
  130. package/agents/create/user-add-document/review-documents-with-new-links.mjs +0 -110
  131. package/agents/create/user-remove-document/find-documents-with-invalid-links.mjs +0 -78
  132. package/agents/create/user-remove-document/index.yaml +0 -40
  133. package/agents/create/user-remove-document/prepare-documents-to-translate.mjs +0 -22
  134. package/agents/create/user-remove-document/print-remove-document-summary.mjs +0 -53
  135. package/agents/create/user-remove-document/remove-documents-from-structure.mjs +0 -99
  136. package/agents/create/user-remove-document/review-documents-with-invalid-links.mjs +0 -115
  137. package/agents/create/user-review-document-structure.mjs +0 -139
  138. package/agents/create/utils/init-current-content.mjs +0 -34
  139. package/agents/create/utils/merge-document-structures.mjs +0 -36
  140. package/agents/evaluate/code-snippet.mjs +0 -97
  141. package/agents/evaluate/document-structure.yaml +0 -67
  142. package/agents/evaluate/document.yaml +0 -82
  143. package/agents/evaluate/generate-report.mjs +0 -85
  144. package/agents/evaluate/index.yaml +0 -46
  145. package/agents/history/index.yaml +0 -6
  146. package/agents/history/view.mjs +0 -78
  147. package/agents/init/check.mjs +0 -16
  148. package/agents/init/index.mjs +0 -643
  149. package/agents/init/validate.mjs +0 -16
  150. package/agents/localize/choose-language.mjs +0 -107
  151. package/agents/localize/record-translation-history.mjs +0 -23
  152. package/agents/localize/save-doc-translation-or-skip.mjs +0 -18
  153. package/agents/localize/set-review-content.mjs +0 -58
  154. package/agents/localize/translate-document-wrapper.mjs +0 -34
  155. package/agents/localize/translate-document.yaml +0 -24
  156. package/agents/localize/translate-multilingual.yaml +0 -57
  157. package/agents/localize/translate-or-skip-diagram.mjs +0 -52
  158. package/agents/media/batch-generate-media-description.yaml +0 -46
  159. package/agents/media/generate-media-description.yaml +0 -50
  160. package/agents/media/load-media-description.mjs +0 -454
  161. package/agents/prefs/index.mjs +0 -203
  162. package/agents/schema/document-structure-item.yaml +0 -26
  163. package/agents/schema/document-structure-refine-item.yaml +0 -23
  164. package/agents/schema/document-structure.yaml +0 -29
  165. package/agents/update/batch-generate-document.yaml +0 -27
  166. package/agents/update/batch-update-document.yaml +0 -7
  167. package/agents/update/check-diagram-flag.mjs +0 -116
  168. package/agents/update/check-document.mjs +0 -162
  169. package/agents/update/check-generate-diagram.mjs +0 -106
  170. package/agents/update/check-update-is-single.mjs +0 -53
  171. package/agents/update/document-tools/update-document-content.mjs +0 -303
  172. package/agents/update/generate-diagram.yaml +0 -80
  173. package/agents/update/generate-document.yaml +0 -70
  174. package/agents/update/handle-document-update.yaml +0 -103
  175. package/agents/update/index.yaml +0 -69
  176. package/agents/update/pre-check-generate-diagram.yaml +0 -44
  177. package/agents/update/save-and-translate-document.mjs +0 -80
  178. package/agents/update/update-document-detail.yaml +0 -71
  179. package/agents/update/update-single/update-single-document-detail.mjs +0 -322
  180. package/agents/update/update-single-document.yaml +0 -7
  181. package/agents/update/user-review-document.mjs +0 -272
  182. package/agents/utils/action-success.mjs +0 -16
  183. package/agents/utils/analyze-document-feedback-intent.yaml +0 -32
  184. package/agents/utils/analyze-feedback-intent.mjs +0 -253
  185. package/agents/utils/analyze-structure-feedback-intent.yaml +0 -29
  186. package/agents/utils/check-detail-result.mjs +0 -51
  187. package/agents/utils/check-feedback-refiner.mjs +0 -81
  188. package/agents/utils/choose-docs.mjs +0 -251
  189. package/agents/utils/document-icon-generate.yaml +0 -52
  190. package/agents/utils/document-title-streamline.yaml +0 -48
  191. package/agents/utils/ensure-document-icons.mjs +0 -129
  192. package/agents/utils/exit.mjs +0 -6
  193. package/agents/utils/feedback-refiner.yaml +0 -50
  194. package/agents/utils/find-item-by-path.mjs +0 -114
  195. package/agents/utils/find-user-preferences-by-path.mjs +0 -37
  196. package/agents/utils/format-document-structure.mjs +0 -35
  197. package/agents/utils/generate-document-or-skip.mjs +0 -41
  198. package/agents/utils/handle-diagram-operations.mjs +0 -263
  199. package/agents/utils/load-all-document-content.mjs +0 -30
  200. package/agents/utils/load-document-all-content.mjs +0 -96
  201. package/agents/utils/load-sources.mjs +0 -405
  202. package/agents/utils/map-reasoning-effort-level.mjs +0 -15
  203. package/agents/utils/post-generate.mjs +0 -133
  204. package/agents/utils/read-current-document-content.mjs +0 -46
  205. package/agents/utils/save-doc-translation.mjs +0 -30
  206. package/agents/utils/save-doc.mjs +0 -54
  207. package/agents/utils/save-output.mjs +0 -26
  208. package/agents/utils/save-sidebar.mjs +0 -38
  209. package/agents/utils/skip-if-content-exists.mjs +0 -27
  210. package/agents/utils/streamline-document-titles-if-needed.mjs +0 -88
  211. package/agents/utils/transform-detail-data-sources.mjs +0 -45
  212. package/assets/report-template/report.html +0 -198
  213. package/docs-mcp/analyze-content-relevance.yaml +0 -50
  214. package/docs-mcp/analyze-docs-relevance.yaml +0 -59
  215. package/docs-mcp/docs-search.yaml +0 -42
  216. package/docs-mcp/get-docs-detail.mjs +0 -41
  217. package/docs-mcp/get-docs-structure.mjs +0 -16
  218. package/docs-mcp/read-doc-content.mjs +0 -119
  219. package/prompts/common/document/content-rules-core.md +0 -20
  220. package/prompts/common/document/markdown-syntax-rules.md +0 -65
  221. package/prompts/common/document/media-file-list-usage-rules.md +0 -18
  222. package/prompts/common/document/openapi-usage-rules.md +0 -189
  223. package/prompts/common/document/role-and-personality.md +0 -16
  224. package/prompts/common/document/user-preferences.md +0 -9
  225. package/prompts/common/document-structure/conflict-resolution-guidance.md +0 -16
  226. package/prompts/common/document-structure/document-icon-generate.md +0 -116
  227. package/prompts/common/document-structure/document-structure-rules.md +0 -43
  228. package/prompts/common/document-structure/document-title-streamline.md +0 -86
  229. package/prompts/common/document-structure/glossary.md +0 -7
  230. package/prompts/common/document-structure/intj-traits.md +0 -5
  231. package/prompts/common/document-structure/openapi-usage-rules.md +0 -28
  232. package/prompts/common/document-structure/output-constraints.md +0 -18
  233. package/prompts/common/document-structure/user-locale-rules.md +0 -10
  234. package/prompts/common/document-structure/user-preferences.md +0 -9
  235. package/prompts/detail/custom/admonition-usage-rules.md +0 -94
  236. package/prompts/detail/custom/code-block-usage-rules.md +0 -163
  237. package/prompts/detail/custom/custom-components/x-card-usage-rules.md +0 -63
  238. package/prompts/detail/custom/custom-components/x-cards-usage-rules.md +0 -83
  239. package/prompts/detail/custom/custom-components/x-field-desc-usage-rules.md +0 -120
  240. package/prompts/detail/custom/custom-components/x-field-group-usage-rules.md +0 -80
  241. package/prompts/detail/custom/custom-components/x-field-usage-rules.md +0 -189
  242. package/prompts/detail/custom/custom-components-usage-rules.md +0 -18
  243. package/prompts/detail/diagram/generate-image-user.md +0 -81
  244. package/prompts/detail/diagram/guide.md +0 -29
  245. package/prompts/detail/diagram/official-examples.md +0 -712
  246. package/prompts/detail/diagram/pre-check.md +0 -23
  247. package/prompts/detail/diagram/role-and-personality.md +0 -2
  248. package/prompts/detail/diagram/rules.md +0 -46
  249. package/prompts/detail/diagram/system-prompt.md +0 -1139
  250. package/prompts/detail/diagram/user-prompt.md +0 -43
  251. package/prompts/detail/generate/detail-example.md +0 -457
  252. package/prompts/detail/generate/document-rules.md +0 -45
  253. package/prompts/detail/generate/system-prompt.md +0 -61
  254. package/prompts/detail/generate/user-prompt.md +0 -99
  255. package/prompts/detail/jsx/rules.md +0 -6
  256. package/prompts/detail/update/system-prompt.md +0 -121
  257. package/prompts/detail/update/user-prompt.md +0 -41
  258. package/prompts/evaluate/document-structure.md +0 -93
  259. package/prompts/evaluate/document.md +0 -149
  260. package/prompts/media/media-description/system-prompt.md +0 -43
  261. package/prompts/media/media-description/user-prompt.md +0 -17
  262. package/prompts/structure/check-document-structure.md +0 -93
  263. package/prompts/structure/document-rules.md +0 -21
  264. package/prompts/structure/find-documents-to-add-links.md +0 -52
  265. package/prompts/structure/generate/system-prompt.md +0 -13
  266. package/prompts/structure/generate/user-prompt.md +0 -137
  267. package/prompts/structure/review/structure-review-system.md +0 -81
  268. package/prompts/structure/structure-example.md +0 -89
  269. package/prompts/structure/structure-getting-started.md +0 -10
  270. package/prompts/structure/update/system-prompt.md +0 -93
  271. package/prompts/structure/update/user-prompt.md +0 -43
  272. package/prompts/translate/admonition.md +0 -20
  273. package/prompts/translate/code-block.md +0 -33
  274. package/prompts/utils/analyze-document-feedback-intent.md +0 -54
  275. package/prompts/utils/analyze-structure-feedback-intent.md +0 -43
  276. package/prompts/utils/feedback-refiner.md +0 -105
  277. package/types/document-schema.mjs +0 -55
  278. package/types/document-structure-schema.mjs +0 -261
  279. package/utils/check-document-has-diagram.mjs +0 -95
  280. package/utils/conflict-detector.mjs +0 -149
  281. package/utils/constants/index.mjs +0 -620
  282. package/utils/constants/linter.mjs +0 -102
  283. package/utils/d2-utils.mjs +0 -205
  284. package/utils/debug.mjs +0 -3
  285. package/utils/delete-diagram-images.mjs +0 -99
  286. package/utils/diagram-version-utils.mjs +0 -14
  287. package/utils/docs-finder-utils.mjs +0 -548
  288. package/utils/evaluate/report-utils.mjs +0 -132
  289. package/utils/extract-api.mjs +0 -32
  290. package/utils/file-utils.mjs +0 -960
  291. package/utils/history-utils.mjs +0 -203
  292. package/utils/icon-map.mjs +0 -26
  293. package/utils/image-compress.mjs +0 -154
  294. package/utils/kroki-utils.mjs +0 -173
  295. package/utils/linter/index.mjs +0 -50
  296. package/utils/load-config.mjs +0 -78
  297. package/utils/markdown/index.mjs +0 -26
  298. package/utils/markdown-checker.mjs +0 -694
  299. package/utils/mermaid-validator.mjs +0 -140
  300. package/utils/mermaid-worker-pool.mjs +0 -250
  301. package/utils/mermaid-worker.mjs +0 -233
  302. package/utils/openapi/index.mjs +0 -28
  303. package/utils/preferences-utils.mjs +0 -175
  304. package/utils/request.mjs +0 -10
  305. package/utils/sync-diagram-to-translations.mjs +0 -272
  306. package/utils/translate-diagram-images.mjs +0 -807
  307. package/utils/utils.mjs +0 -1354
  308. /package/{prompts/translate → agents/localize/prompts}/glossary.md +0 -0
@@ -0,0 +1,371 @@
1
+ import { existsSync } from "node:fs";
2
+ import { access, readFile, mkdir, writeFile, appendFile } from "node:fs/promises";
3
+ import { constants } from "node:fs";
4
+ import { exec } from "node:child_process";
5
+ import { promisify } from "node:util";
6
+ import { join } from "node:path";
7
+ import { parse as yamlParse, stringify as yamlStringify } from "yaml";
8
+
9
+ const execAsync = promisify(exec);
10
+
11
+ /**
12
+ * Workspace mode constants
13
+ */
14
+ export const WORKSPACE_MODES = {
15
+ PROJECT: "project",
16
+ STANDALONE: "standalone",
17
+ };
18
+
19
+ /**
20
+ * Directory structure constants
21
+ */
22
+ export const AIGNE_DIR = ".aigne";
23
+ export const DOC_SMITH_DIR = ".aigne/doc-smith";
24
+ export const SOURCES_DIR = "sources";
25
+ export const WORKSPACE_SUBDIRS = ["intent", "planning", "docs"];
26
+
27
+ /**
28
+ * .gitignore content for doc-smith workspace
29
+ */
30
+ export const GITIGNORE_CONTENT = `\
31
+ # Ignore sources directory
32
+ sources/
33
+
34
+ # Ignore temporary files
35
+ .tmp/
36
+ .temp/
37
+ temp/
38
+ `;
39
+
40
+ /**
41
+ * Check if path exists
42
+ * @param {string} path - Path
43
+ * @returns {Promise<boolean>}
44
+ */
45
+ export async function pathExists(path) {
46
+ try {
47
+ await access(path, constants.F_OK);
48
+ return true;
49
+ } catch {
50
+ return false;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Check if path exists (synchronous version)
56
+ * @param {string} path - Path
57
+ * @returns {boolean}
58
+ */
59
+ export function pathExistsSync(path) {
60
+ return existsSync(path);
61
+ }
62
+
63
+ /**
64
+ * Check if inside a git repository (supports subdirectories)
65
+ * @param {string} cwd - Working directory
66
+ * @returns {Promise<boolean>}
67
+ */
68
+ export async function isGitRepo(cwd = ".") {
69
+ const result = await gitExec("rev-parse --is-inside-work-tree", cwd);
70
+ return result.success && result.output === "true";
71
+ }
72
+
73
+ /**
74
+ * Execute git command
75
+ * @param {string} command - git command (without git prefix)
76
+ * @param {string} cwd - Working directory
77
+ * @returns {Promise<{success: boolean, output?: string, error?: string}>}
78
+ */
79
+ export async function gitExec(command, cwd = ".") {
80
+ try {
81
+ const { stdout } = await execAsync(`git ${command}`, { cwd });
82
+ return { success: true, output: stdout.trim() };
83
+ } catch (error) {
84
+ return { success: false, error: error.message };
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Get git repository info (url, branch, commit)
90
+ * @param {string} cwd - Working directory
91
+ * @returns {Promise<{ url: string, branch: string, commit: string }>}
92
+ */
93
+ export async function getGitInfo(cwd = ".") {
94
+ // Get remote repository URL (prefer origin)
95
+ let url = "";
96
+ const urlResult = await gitExec("remote get-url origin", cwd);
97
+ if (urlResult.success) {
98
+ url = urlResult.output;
99
+ } else {
100
+ // Try to get the first available remote
101
+ const remotesResult = await gitExec("remote", cwd);
102
+ if (remotesResult.success && remotesResult.output) {
103
+ const firstRemote = remotesResult.output.split("\n")[0];
104
+ const fallbackResult = await gitExec(`remote get-url ${firstRemote}`, cwd);
105
+ if (fallbackResult.success) {
106
+ url = fallbackResult.output;
107
+ }
108
+ }
109
+ }
110
+
111
+ // Get current branch name
112
+ let branch = "";
113
+ const branchResult = await gitExec("branch --show-current", cwd);
114
+ if (branchResult.success) {
115
+ branch = branchResult.output;
116
+ }
117
+
118
+ // Get current commit hash (short format)
119
+ let commit = "";
120
+ const commitResult = await gitExec("rev-parse --short HEAD", cwd);
121
+ if (commitResult.success) {
122
+ commit = commitResult.output;
123
+ }
124
+
125
+ return { url, branch, commit };
126
+ }
127
+
128
+ /**
129
+ * Get git repository root directory
130
+ * @param {string} cwd - Starting directory
131
+ * @returns {Promise<string | null>}
132
+ */
133
+ export async function getGitRoot(cwd = ".") {
134
+ const result = await gitExec("rev-parse --show-toplevel", cwd);
135
+ if (result.success) {
136
+ return result.output;
137
+ }
138
+ return null;
139
+ }
140
+
141
+ /**
142
+ * Add ignore rule to .gitignore (if not exists)
143
+ * @param {string} gitRoot - Git repository root directory
144
+ * @param {string} pattern - Pattern to ignore
145
+ * @returns {Promise<boolean>} Whether addition was successful
146
+ */
147
+ export async function addToGitignore(gitRoot, pattern) {
148
+ const gitignorePath = join(gitRoot, ".gitignore");
149
+
150
+ try {
151
+ // Check if .gitignore exists
152
+ if (await pathExists(gitignorePath)) {
153
+ // Read existing content, check if pattern already exists
154
+ const content = await readFile(gitignorePath, "utf8");
155
+ if (content.includes(pattern)) {
156
+ return true; // Already exists, no need to add
157
+ }
158
+ // Append to end of file (ensure newline)
159
+ const prefix = content.endsWith("\n") ? "" : "\n";
160
+ await appendFile(gitignorePath, `${prefix}${pattern}\n`, "utf8");
161
+ } else {
162
+ // Create new .gitignore
163
+ await writeFile(gitignorePath, `${pattern}\n`, "utf8");
164
+ }
165
+ return true;
166
+ } catch {
167
+ return false;
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Detect workspace mode (synchronous version)
173
+ * Used for scenarios requiring synchronous judgment at module load time
174
+ * @returns {{ mode: string, workspaceBase: string }}
175
+ */
176
+ export function detectWorkspaceModeSync() {
177
+ const cwd = process.cwd();
178
+ const projectConfigPath = join(cwd, DOC_SMITH_DIR, "config.yaml");
179
+
180
+ if (existsSync(projectConfigPath)) {
181
+ return {
182
+ mode: WORKSPACE_MODES.PROJECT,
183
+ workspaceBase: join(cwd, DOC_SMITH_DIR),
184
+ };
185
+ }
186
+
187
+ return {
188
+ mode: WORKSPACE_MODES.STANDALONE,
189
+ workspaceBase: cwd,
190
+ };
191
+ }
192
+
193
+ /**
194
+ * Detect workspace mode (asynchronous version)
195
+ * @returns {Promise<{ mode: string, configPath: string, workspacePath: string } | null>}
196
+ */
197
+ export async function detectWorkspaceMode() {
198
+ const configInDocSmith = join(DOC_SMITH_DIR, "config.yaml");
199
+ const configInRoot = "config.yaml";
200
+
201
+ if (await pathExists(configInDocSmith)) {
202
+ return {
203
+ mode: WORKSPACE_MODES.PROJECT,
204
+ configPath: configInDocSmith,
205
+ workspacePath: `./${DOC_SMITH_DIR}`,
206
+ };
207
+ }
208
+
209
+ if (await pathExists(configInRoot)) {
210
+ return {
211
+ mode: WORKSPACE_MODES.STANDALONE,
212
+ configPath: configInRoot,
213
+ workspacePath: ".",
214
+ };
215
+ }
216
+
217
+ return null;
218
+ }
219
+
220
+ /**
221
+ * Load and parse config.yaml
222
+ * @param {string} configPath - Config file path
223
+ * @returns {Promise<Object | null>}
224
+ */
225
+ export async function loadConfig(configPath) {
226
+ try {
227
+ const content = await readFile(configPath, "utf8");
228
+ return yamlParse(content);
229
+ } catch {
230
+ return null;
231
+ }
232
+ }
233
+
234
+ /**
235
+ * Generate config.yaml content
236
+ * @param {{ mode: string, sources: Array }} options - Configuration options
237
+ * @returns {string}
238
+ */
239
+ export function generateConfig(options) {
240
+ const { mode, sources } = options;
241
+ return yamlStringify({ mode, sources });
242
+ }
243
+
244
+ /**
245
+ * Create directory structure
246
+ * @param {string} baseDir - Base directory
247
+ * @param {boolean} includeSources - Whether to create sources directory
248
+ */
249
+ export async function createDirectoryStructure(baseDir, includeSources = false) {
250
+ await mkdir(baseDir, { recursive: true });
251
+
252
+ for (const dir of WORKSPACE_SUBDIRS) {
253
+ await mkdir(join(baseDir, dir), { recursive: true });
254
+ }
255
+
256
+ if (includeSources) {
257
+ await mkdir(join(baseDir, SOURCES_DIR), { recursive: true });
258
+ }
259
+ }
260
+
261
+ /**
262
+ * Initialize project mode workspace
263
+ * Create .aigne/doc-smith/ directory structure under project root
264
+ * @returns {Promise<{ mode: string, configPath: string, workspacePath: string }>}
265
+ */
266
+ export async function initProjectMode() {
267
+ console.log("\n📂 Initializing doc-smith workspace...\n");
268
+
269
+ // Create .aigne/doc-smith directory
270
+ await mkdir(DOC_SMITH_DIR, { recursive: true });
271
+
272
+ // Initialize git in .aigne/doc-smith
273
+ await gitExec("init", DOC_SMITH_DIR);
274
+
275
+ // Create directory structure
276
+ await createDirectoryStructure(DOC_SMITH_DIR);
277
+
278
+ // Create .gitignore
279
+ await writeFile(join(DOC_SMITH_DIR, ".gitignore"), GITIGNORE_CONTENT, "utf8");
280
+
281
+ // Get project git info
282
+ const gitInfo = await getGitInfo(".");
283
+
284
+ // Generate config.yaml (include git info, consistent with git-clone format)
285
+ const sourceConfig = {
286
+ type: "local-path",
287
+ path: "../../",
288
+ };
289
+
290
+ // Add git info at root level (consistent with git-clone format)
291
+ if (gitInfo.url) sourceConfig.url = gitInfo.url;
292
+ if (gitInfo.branch) sourceConfig.branch = gitInfo.branch;
293
+ if (gitInfo.commit) sourceConfig.commit = gitInfo.commit;
294
+
295
+ const configContent = generateConfig({
296
+ mode: WORKSPACE_MODES.PROJECT,
297
+ sources: [sourceConfig],
298
+ });
299
+ await writeFile(join(DOC_SMITH_DIR, "config.yaml"), configContent, "utf8");
300
+
301
+ // Create initial commit in doc-smith repo
302
+ await gitExec("add .", DOC_SMITH_DIR);
303
+ const commitResult = await gitExec(
304
+ 'commit -m "Initial commit: doc-smith workspace"',
305
+ DOC_SMITH_DIR,
306
+ );
307
+ if (commitResult.success) {
308
+ console.log(`✅ Created initial commit in ${DOC_SMITH_DIR}`);
309
+ }
310
+
311
+ console.log("✅ Workspace initialized successfully!\n");
312
+
313
+ return {
314
+ mode: WORKSPACE_MODES.PROJECT,
315
+ configPath: join(DOC_SMITH_DIR, "config.yaml"),
316
+ workspacePath: `./${DOC_SMITH_DIR}`,
317
+ };
318
+ }
319
+
320
+ /**
321
+ * Initialize standalone mode workspace
322
+ * Create workspace structure in current directory
323
+ * @returns {Promise<{ mode: string, configPath: string, workspacePath: string }>}
324
+ */
325
+ export async function initStandaloneMode() {
326
+ console.log("\n📂 Initializing doc-smith workspace...\n");
327
+
328
+ // Initialize git in current directory
329
+ await gitExec("init");
330
+
331
+ // Create .gitignore
332
+ await writeFile(".gitignore", GITIGNORE_CONTENT, "utf8");
333
+
334
+ // Create directory structure (including sources/)
335
+ await createDirectoryStructure(".", true);
336
+
337
+ // Generate config.yaml (sources empty, to be added during conversation)
338
+ const configContent = generateConfig({
339
+ mode: WORKSPACE_MODES.STANDALONE,
340
+ sources: [],
341
+ });
342
+ await writeFile("config.yaml", configContent, "utf8");
343
+
344
+ console.log("✅ Workspace initialized successfully!\n");
345
+
346
+ return {
347
+ mode: WORKSPACE_MODES.STANDALONE,
348
+ configPath: "config.yaml",
349
+ workspacePath: ".",
350
+ };
351
+ }
352
+
353
+ /**
354
+ * Detect directory state and initialize workspace when needed
355
+ * @returns {Promise<{ mode: string, configPath: string, workspacePath: string }>}
356
+ */
357
+ export async function detectAndInitialize() {
358
+ // Check if already initialized
359
+ const existing = await detectWorkspaceMode();
360
+ if (existing) {
361
+ return existing;
362
+ }
363
+
364
+ // Check if inside git repository (project mode)
365
+ if (await isGitRepo()) {
366
+ return await initProjectMode();
367
+ }
368
+
369
+ // Otherwise, initialize as standalone mode
370
+ return await initStandaloneMode();
371
+ }
@@ -1,38 +0,0 @@
1
- You are a professional document generation assistant that helps users create, modify, and manage documentation through interactive chat. Your primary role is to understand user requirements and intelligently call upon various specialized skills to complete documentation tasks efficiently.
2
-
3
- Core Capabilities:
4
- - Generate comprehensive documentation from user inputs and specifications
5
- - Regenerate and refine document details based on feedback
6
- - Translate and localize documentation content
7
- - Publish and manage team documentation workflows
8
- - Provide interactive guidance throughout the document creation process
9
-
10
- Interaction Guidelines:
11
- - Engage users in a professional yet friendly manner
12
- - Ask clarifying questions to understand specific documentation needs
13
- - Suggest appropriate skills and workflows based on user requests
14
- - Provide clear explanations of available capabilities and processes
15
- - Maintain context throughout multi-step documentation tasks
16
- - Offer proactive suggestions for improving document quality and structure
17
-
18
- <skill_usage>
19
- - afs_xxx skills: AFS(AIGNE File System) skills provide capabilities to explore, read, write and manage files and virtual modules within the AIGNE environment.
20
- You can use these skills to access source files and other resources needed for documentation tasks.
21
- - listDocuments: This skill lists all available documentation files in the system.
22
- You can use this skill to get an overview of existing documents before creating or modifying documentation. for documentation tasks,
23
- you should use this skill rather than afs_read to list documentation files.
24
- - generateDocument: This skill generates new documentation or updates existing documents structure based on user inputs and specifications,
25
- You can use this skill to create comprehensive documents from scratch or based on existing templates or update document structure as per user requirements.
26
- - updateDocument: This skill updates existing documentation content with new information or revisions provided by the user.
27
- You can use this skill to refine and enhance documents content based on feedback or additional details.
28
- - publish: This skill publishes completed documentation to an online website to make it accessible to the intended audience.
29
- You can use this skill to manage the publication process and ensure documents are properly formatted and available.
30
- - translate: This skill translates documentation content into different languages for localization purposes.
31
- You can use this skill to adapt documents for diverse audiences by providing translations in the required languages.
32
- </skill_usage>
33
-
34
- <output_requirements>
35
- - respect tools results and do not fabricate information, use tools results to answer user questions whenever possible
36
- - Use markdown format for all responses
37
- - Respond in the same language as the user
38
- </output_requirements>
@@ -1,59 +0,0 @@
1
- import { mkdir, readFile } from "node:fs/promises";
2
- import { parse } from "yaml";
3
-
4
- await mkdir(".aigne/doc-smith", { recursive: true });
5
- const config = await readFile(".aigne/doc-smith/config.yaml", "utf-8")
6
- .then((raw) => parse(raw))
7
- .catch(() => null);
8
-
9
- const docsDir = config?.docsDir || ".aigne/doc-smith/docs";
10
- await mkdir(docsDir, { recursive: true });
11
-
12
- export default {
13
- type: "ai",
14
- name: "chat",
15
- description: "Start interactive document generation assistant",
16
- instructions: {
17
- url: "./chat-system.md",
18
- },
19
- input_key: "message",
20
- afs: {
21
- modules: [
22
- {
23
- module: "history",
24
- options: {
25
- storage: {
26
- url: "file:.aigne/doc-smith/.local/afs-storage.sqlite3",
27
- },
28
- },
29
- },
30
- {
31
- module: "system-fs",
32
- options: {
33
- name: "source",
34
- localPath: ".",
35
- description: "Project root directory for document generation",
36
- },
37
- },
38
- {
39
- module: "system-fs",
40
- options: {
41
- name: "docs",
42
- localPath: docsDir,
43
- description: "Generated documentation files directory",
44
- },
45
- },
46
- ],
47
- },
48
- afs_config: {
49
- inject_history: true,
50
- },
51
- skills: [
52
- "./skills/list-documents.mjs",
53
- "./skills/generate-document.yaml",
54
- "./skills/update-document.yaml",
55
- "../publish/index.yaml",
56
- "../localize/index.yaml",
57
- "../utils/exit.mjs",
58
- ],
59
- };
@@ -1,15 +0,0 @@
1
- type: team
2
- name: generateDocument
3
- description: Generate complete documentation for your project, or update/delete existing documents or structure based on user feedback
4
- input_schema:
5
- type: object
6
- properties:
7
- feedback:
8
- type: string
9
- description: How to generate or update the document content
10
- required:
11
- - feedback
12
- skills:
13
- - url: ../../create/index.yaml
14
- default_input:
15
- isChat: true
@@ -1,15 +0,0 @@
1
- import { getMainLanguageFiles } from "../../../utils/docs-finder-utils.mjs";
2
- import init from "../../init/index.mjs";
3
-
4
- export default async function listDocuments(_, options) {
5
- const config = await init({ checkOnly: true }, options);
6
-
7
- // Get all main language .md files in docsDir
8
- const mainLanguageFiles = await getMainLanguageFiles(config.docsDir, config.locale);
9
-
10
- return {
11
- documents: mainLanguageFiles,
12
- };
13
- }
14
-
15
- listDocuments.description = "List all available documentation files";
@@ -1,24 +0,0 @@
1
- type: team
2
- name: updateDocument
3
- description: Update a existing document based on user feedback
4
- input_schema:
5
- type: object
6
- properties:
7
- docs:
8
- type: array
9
- items:
10
- type: string
11
- description: Documents to update, must from listDocuments output
12
- feedback:
13
- type: string
14
- description: Tell us what to change in this content
15
- reset:
16
- type: boolean
17
- description: Regenerate the document from scratch, ignoring previous versions
18
- required:
19
- - docs
20
- - feedback
21
- skills:
22
- - url: ../../update/index.yaml
23
- default_input:
24
- isChat: true
@@ -1,36 +0,0 @@
1
- import { rm } from "node:fs/promises";
2
- import { pathExists, toDisplayPath, getConfigFilePath } from "../../utils/file-utils.mjs";
3
-
4
- export default async function clearDocumentConfig({ workDir }) {
5
- const documentConfigPath = getConfigFilePath(workDir);
6
- const displayPath = toDisplayPath(documentConfigPath);
7
-
8
- try {
9
- const existed = await pathExists(documentConfigPath);
10
- await rm(documentConfigPath, { recursive: true, force: true });
11
-
12
- const message = existed
13
- ? `⚙️ Cleared document configuration (${displayPath})`
14
- : `⚙️ Document configuration already empty (${displayPath})`;
15
-
16
- const suggestions = existed
17
- ? ["Run `aigne doc init` to generate a fresh configuration file."]
18
- : [];
19
-
20
- return {
21
- message,
22
- cleared: existed,
23
- path: displayPath,
24
- suggestions,
25
- };
26
- } catch (error) {
27
- return {
28
- message: `⚠️ Failed to clear document configuration: ${error.message}`,
29
- error: true,
30
- path: displayPath,
31
- };
32
- }
33
- }
34
-
35
- clearDocumentConfig.taskTitle = "Clear document configuration";
36
- clearDocumentConfig.description = "Clear the document configuration file";
@@ -1,102 +0,0 @@
1
- import { rm } from "node:fs/promises";
2
- import { pathExists, toDisplayPath, getStructurePlanPath } from "../../utils/file-utils.mjs";
3
-
4
- export default async function clearDocumentStructure(input = {}, _options = {}) {
5
- const { docsDir, workDir } = input;
6
-
7
- const structurePlanPath = getStructurePlanPath(workDir);
8
-
9
- const results = [];
10
- let hasError = false;
11
-
12
- // Clear structure-plan.json
13
- try {
14
- const structureExists = await pathExists(structurePlanPath);
15
- await rm(structurePlanPath, { force: true });
16
-
17
- const structureDisplayPath = toDisplayPath(structurePlanPath);
18
- const structureMessage = structureExists
19
- ? `✔ Cleared documentation structure (${structureDisplayPath})`
20
- : `• Documentation structure already empty (${structureDisplayPath})`;
21
-
22
- results.push({
23
- type: "structure",
24
- cleared: structureExists,
25
- message: structureMessage,
26
- });
27
- } catch (error) {
28
- hasError = true;
29
- results.push({
30
- type: "structure",
31
- error: true,
32
- message: `✗ Failed to clear documentation structure: ${error.message}`,
33
- });
34
- }
35
-
36
- // Clear documents directory if provided
37
- if (docsDir) {
38
- try {
39
- const docsExists = await pathExists(docsDir);
40
- await rm(docsDir, { recursive: true, force: true });
41
-
42
- const docsDisplayPath = toDisplayPath(docsDir);
43
- const docsMessage = docsExists
44
- ? `✔ Cleared documents directory (${docsDisplayPath})`
45
- : `• Documents directory already empty (${docsDisplayPath})`;
46
-
47
- results.push({
48
- type: "documents",
49
- cleared: docsExists,
50
- message: docsMessage,
51
- });
52
- } catch (error) {
53
- hasError = true;
54
- results.push({
55
- type: "documents",
56
- error: true,
57
- message: `✗ Failed to clear documents directory: ${error.message}`,
58
- });
59
- }
60
- }
61
-
62
- // Prepare summary message
63
- const clearedItems = results.filter((r) => r.cleared).length;
64
- const errorItems = results.filter((r) => r.error).length;
65
-
66
- let header;
67
- if (errorItems > 0) {
68
- header = "⚠️ Documentation Structure cleanup finished with some issues.";
69
- } else if (clearedItems > 0) {
70
- header = "📖 Documentation Structure cleared successfully!";
71
- } else {
72
- header = "📖 Documentation Structure already empty.";
73
- }
74
-
75
- const detailLines = results.map((item) => ` ${item.message}`).join("\n");
76
- const message = [header, "", detailLines].filter(Boolean).join("\n");
77
-
78
- return {
79
- message,
80
- results,
81
- hasError,
82
- clearedCount: clearedItems,
83
- };
84
- }
85
-
86
- clearDocumentStructure.input_schema = {
87
- type: "object",
88
- properties: {
89
- docsDir: {
90
- type: "string",
91
- description: "The documents directory to clear (optional)",
92
- },
93
- workDir: {
94
- type: "string",
95
- description: "The working directory (defaults to current directory)",
96
- },
97
- },
98
- };
99
-
100
- clearDocumentStructure.taskTitle = "Clear documentation structure and all generated documents";
101
- clearDocumentStructure.description =
102
- "Clear the documentation structure (structure-plan.json) and optionally the documents directory";