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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/agents/chat/chat-system.md +32 -0
  3. package/agents/chat/index.yaml +14 -22
  4. package/agents/chat/skills/generate-document.yaml +15 -0
  5. package/agents/chat/skills/update-document.yaml +24 -0
  6. package/agents/evaluate/generate-report.mjs +7 -0
  7. package/agents/evaluate/index.yaml +6 -0
  8. package/agents/generate/check-need-generate-structure.mjs +12 -4
  9. package/agents/generate/document-structure-tools/add-document.mjs +9 -1
  10. package/agents/generate/document-structure-tools/update-document.mjs +18 -0
  11. package/agents/generate/draw-diagram.yaml +2 -2
  12. package/agents/generate/generate-structure.yaml +3 -2
  13. package/agents/generate/user-review-document-structure.mjs +44 -29
  14. package/agents/init/index.mjs +6 -4
  15. package/agents/media/load-media-description.mjs +2 -1
  16. package/agents/schema/document-structure-item.yaml +3 -0
  17. package/agents/schema/document-structure-refine-item.yaml +3 -0
  18. package/agents/schema/document-structure.yaml +3 -0
  19. package/agents/update/pre-check-generate-diagram.yaml +1 -1
  20. package/agents/update/user-review-document.mjs +56 -42
  21. package/agents/utils/document-icon-generate.yaml +52 -0
  22. package/agents/utils/document-title-streamline.yaml +48 -0
  23. package/agents/utils/generate-document-icon-if-needed.mjs +93 -0
  24. package/agents/utils/list-docs.mjs +15 -0
  25. package/agents/utils/streamline-document-titles-if-needed.mjs +88 -0
  26. package/aigne.yaml +7 -1
  27. package/package.json +4 -7
  28. package/prompts/common/document/media-file-list-usage-rules.md +8 -2
  29. package/prompts/common/document/openapi-usage-rules.md +174 -21
  30. package/prompts/common/document-structure/document-icon-generate.md +116 -0
  31. package/prompts/common/document-structure/document-structure-rules.md +8 -3
  32. package/prompts/common/document-structure/document-title-streamline.md +86 -0
  33. package/prompts/common/document-structure/openapi-usage-rules.md +28 -0
  34. package/prompts/common/document-structure/output-constraints.md +9 -0
  35. package/prompts/detail/custom/{custom-code-block.md → code-block-usage-rules.md} +43 -16
  36. package/prompts/detail/custom/custom-components/x-card-usage-rules.md +62 -0
  37. package/prompts/detail/custom/custom-components/x-cards-usage-rules.md +75 -0
  38. package/prompts/detail/custom/custom-components/x-field-desc-usage-rules.md +86 -0
  39. package/prompts/detail/custom/custom-components/x-field-group-usage-rules.md +95 -0
  40. package/prompts/detail/custom/custom-components/x-field-usage-rules.md +189 -0
  41. package/prompts/detail/custom/custom-components-usage-rules.md +10 -534
  42. package/prompts/detail/{d2-diagram → diagram}/rules.md +5 -3
  43. package/prompts/detail/generate/document-rules.md +6 -0
  44. package/prompts/detail/generate/system-prompt.md +3 -2
  45. package/prompts/detail/generate/user-prompt.md +7 -1
  46. package/prompts/detail/update/system-prompt.md +3 -3
  47. package/prompts/structure/generate/system-prompt.md +2 -5
  48. package/prompts/structure/generate/user-prompt.md +14 -39
  49. package/types/document-structure-schema.mjs +1 -0
  50. package/utils/evaluate/report-utils.mjs +7 -3
  51. package/agents/utils/docs-fs-actor.yaml +0 -27
  52. package/agents/utils/fs.mjs +0 -60
  53. /package/prompts/detail/{d2-diagram → diagram}/guide.md +0 -0
  54. /package/prompts/detail/{d2-diagram → diagram}/official-examples.md +0 -0
  55. /package/prompts/detail/{d2-diagram → diagram}/pre-check.md +0 -0
  56. /package/prompts/detail/{d2-diagram → diagram}/role-and-personality.md +0 -0
  57. /package/prompts/detail/{d2-diagram → diagram}/system-prompt.md +0 -0
  58. /package/prompts/detail/{d2-diagram → diagram}/user-prompt.md +0 -0
@@ -132,7 +132,9 @@ export default async function userReviewDocument({ content, description, ...rest
132
132
  const title = rest.documentStructure?.find((x) => x.path === rest.path)?.title;
133
133
 
134
134
  // Print current document headings structure
135
- printDocumentHeadings(content, title || "Untitled Document");
135
+ if (!rest.isChat) {
136
+ printDocumentHeadings(content, title || "Untitled Document");
137
+ }
136
138
 
137
139
  // Initialize shared context with current content
138
140
  options.context.userContext.currentContent = content;
@@ -140,54 +142,62 @@ export default async function userReviewDocument({ content, description, ...rest
140
142
  const MAX_ITERATIONS = 100;
141
143
  const feedbacks = [];
142
144
  let iterationCount = 0;
145
+
146
+ let feedback = "";
147
+
143
148
  while (iterationCount < MAX_ITERATIONS) {
149
+ feedback = "";
144
150
  iterationCount++;
145
151
 
146
- // Ask user what they want to do
147
- const action = await options.prompts.select({
148
- message: "What would you like to do next?",
149
- choices: [
150
- {
151
- name: "View document",
152
- value: "view",
153
- },
154
- {
155
- name: "Give feedback",
156
- value: "feedback",
157
- },
158
- {
159
- name: "Done",
160
- value: "finish",
161
- },
162
- ],
163
- });
152
+ if (rest.isChat && rest.feedback) {
153
+ feedback = rest.feedback;
154
+ } else {
155
+ // Ask user what they want to do
156
+ const action = await options.prompts.select({
157
+ message: "What would you like to do next?",
158
+ choices: [
159
+ {
160
+ name: "View document",
161
+ value: "view",
162
+ },
163
+ {
164
+ name: "Give feedback",
165
+ value: "feedback",
166
+ },
167
+ {
168
+ name: "Done",
169
+ value: "finish",
170
+ },
171
+ ],
172
+ });
164
173
 
165
- if (action === "finish") {
166
- break;
167
- } else if (action === "view") {
168
- await showDocumentDetail(
169
- options.context.userContext.currentContent,
170
- title || "Untitled Document",
171
- );
172
- }
174
+ if (action === "finish") {
175
+ break;
176
+ } else if (action === "view") {
177
+ await showDocumentDetail(
178
+ options.context.userContext.currentContent,
179
+ title || "Untitled Document",
180
+ );
181
+ }
173
182
 
174
- // Ask for feedback
175
- const feedback = await options.prompts.input({
176
- message:
177
- "How would you like to improve this document?\n" +
178
- "Examples:\n" +
179
- " • Add troubleshooting section for common errors\n" +
180
- " • Simplify the explanation for beginners\n" +
181
- " • Remove the outdated information about version 1.0\n\n" +
182
- " Your feedback:",
183
- });
183
+ // Ask for feedback
184
+ feedback = await options.prompts.input({
185
+ message:
186
+ "How would you like to improve this document?\n" +
187
+ "Examples:\n" +
188
+ " • Add troubleshooting section for common errors\n" +
189
+ " • Simplify the explanation for beginners\n" +
190
+ " • Remove the outdated information about version 1.0\n\n" +
191
+ " Your feedback:",
192
+ });
184
193
 
185
- // If no feedback, finish the loop
186
- if (!feedback?.trim()) {
187
- break;
188
- }
194
+ // If no feedback, finish the loop
195
+ if (!feedback?.trim()) {
196
+ break;
197
+ }
189
198
 
190
- feedbacks.push(feedback.trim());
199
+ feedbacks.push(feedback.trim());
200
+ }
191
201
 
192
202
  // Get the updateDocument agent
193
203
  const updateAgent = options.context.agents["handleDocumentUpdate"];
@@ -236,6 +246,10 @@ export default async function userReviewDocument({ content, description, ...rest
236
246
  options.context.userContext.currentContent,
237
247
  title || "Untitled Document",
238
248
  );
249
+
250
+ if (rest.isChat) {
251
+ break;
252
+ }
239
253
  } catch (error) {
240
254
  console.error("Error processing your feedback:");
241
255
  console.error(`Type: ${error.name}`);
@@ -0,0 +1,52 @@
1
+ name: documentIconGenerate
2
+ description: Generate appropriate Iconify icon names for document structure root nodes based on their title and description
3
+ model:
4
+ reasoning_effort: low
5
+ task_render_mode: hide
6
+ instructions:
7
+ url: ../../prompts/common/document-structure/document-icon-generate.md
8
+ input_schema:
9
+ type: object
10
+ properties:
11
+ documentList:
12
+ type: array
13
+ items:
14
+ type: object
15
+ properties:
16
+ path:
17
+ type: string
18
+ description: Document path for mapping purposes
19
+ title:
20
+ type: string
21
+ description: Document title to analyze for icon selection
22
+ description:
23
+ type: string
24
+ description: Document description to analyze for icon selection
25
+ required:
26
+ - path
27
+ - title
28
+ - description
29
+ description: List of root-level document items (parentId is null) that need icons generated
30
+ required:
31
+ - documentList
32
+ output_schema:
33
+ type: object
34
+ properties:
35
+ documentList:
36
+ type: array
37
+ items:
38
+ type: object
39
+ properties:
40
+ path:
41
+ type: string
42
+ description: Document path (same as input for mapping)
43
+ icon:
44
+ type: string
45
+ description: Iconify icon name in the format collection:icon-name (e.g., lucide:book)
46
+ required:
47
+ - path
48
+ - icon
49
+ description: List of document items with generated Iconify icon names
50
+ required:
51
+ - documentList
52
+
@@ -0,0 +1,48 @@
1
+ name: documentTitleStreamline
2
+ description: Streamline document titles by shortening them while preserving meaning for better sidebar navigation
3
+ model:
4
+ reasoning_effort: low
5
+ task_render_mode: hide
6
+ instructions:
7
+ url: ../../prompts/common/document-structure/document-title-streamline.md
8
+ input_schema:
9
+ type: object
10
+ properties:
11
+ documentList:
12
+ type: array
13
+ items:
14
+ type: object
15
+ properties:
16
+ path:
17
+ type: string
18
+ description: Document path for mapping purposes
19
+ title:
20
+ type: string
21
+ description: Document title to streamline
22
+ required:
23
+ - path
24
+ - title
25
+ description: List of document items with titles to streamline
26
+ required:
27
+ - documentList
28
+ output_schema:
29
+ type: object
30
+ properties:
31
+ documentList:
32
+ type: array
33
+ items:
34
+ type: object
35
+ properties:
36
+ path:
37
+ type: string
38
+ description: Document path (same as input for mapping)
39
+ title:
40
+ type: string
41
+ description: Streamlined document title (max 24 characters for English, 12 characters for character-based languages)
42
+ required:
43
+ - path
44
+ - title
45
+ description: List of streamlined document items with shortened titles
46
+ required:
47
+ - documentList
48
+
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Generate icons for root-level document structure items if they don't have one or if title/description changed
3
+ * Reusable function for generating document icons in various contexts
4
+ * Can be called as a standalone function with { documentStructure, originalItems? } or as a function skill with (input, options)
5
+ * @param {Object|Array} inputOrParams - Either input from previous step (with documentStructure) or params object with documentStructure and optional originalItems
6
+ * @param {Object} options - Agent options with context
7
+ * @param {Array<{path: string, title?: string, description?: string}>} [inputOrParams.originalItems] - Original items for comparison (optional, used to detect title/description changes)
8
+ * @returns {Promise<Object>} - Returns input unchanged (modifies documentStructure in place)
9
+ */
10
+ export default async function generateDocumentIconIfNeeded(inputOrParams, options) {
11
+ // Handle both calling patterns:
12
+ // 1. As function skill: (input, options) where input.documentStructure exists
13
+ // 2. As standalone function: ({ documentStructure, originalItems? }, options)
14
+ const documentStructure =
15
+ inputOrParams?.documentStructure || (Array.isArray(inputOrParams) ? inputOrParams : null);
16
+ const originalItems = inputOrParams?.originalItems || [];
17
+
18
+ if (!documentStructure || !Array.isArray(documentStructure)) {
19
+ // Return input unchanged if no documentStructure to process
20
+ return inputOrParams || {};
21
+ }
22
+
23
+ // Create a map of original items by path for quick lookup
24
+ const originalItemsMap = new Map(
25
+ originalItems.map((item) => [item.path, { title: item.title, description: item.description }]),
26
+ );
27
+
28
+ // Filter root-level items that need icon generation or update
29
+ const itemsNeedingIcon = documentStructure.filter((item) => {
30
+ // Only process root-level items (parentId is null, undefined, or empty string)
31
+ const isRootLevel = !item.parentId || item.parentId === "null" || item.parentId === "";
32
+ if (!isRootLevel) return false;
33
+
34
+ // Must have title and description for icon generation
35
+ if (!item.title || !item.description) return false;
36
+
37
+ // Check if icon is missing
38
+ const hasNoIcon = !item.icon;
39
+
40
+ // Check if title or description changed (if original item exists)
41
+ const originalItem = originalItemsMap.get(item.path);
42
+ const titleChanged = originalItem && originalItem.title !== item.title;
43
+ const descriptionChanged = originalItem && originalItem.description !== item.description;
44
+ const contentChanged = titleChanged || descriptionChanged;
45
+
46
+ // Generate/update icon if: missing icon OR content changed
47
+ return hasNoIcon || contentChanged;
48
+ });
49
+
50
+ if (itemsNeedingIcon.length === 0) {
51
+ return;
52
+ }
53
+
54
+ const documentList = itemsNeedingIcon.map((item) => ({
55
+ path: item.path,
56
+ title: item.title,
57
+ description: item.description,
58
+ }));
59
+
60
+ const iconAgent = options?.context?.agents?.["documentIconGenerate"];
61
+ if (!iconAgent) {
62
+ console.warn("⚠️ documentIconGenerate agent not found. Skipping icon generation.");
63
+ return;
64
+ }
65
+
66
+ try {
67
+ const iconResult = await options.context.invoke(iconAgent, {
68
+ documentList,
69
+ });
70
+
71
+ // Update the document items with generated icons using path as the key
72
+ if (iconResult.documentList && Array.isArray(iconResult.documentList)) {
73
+ const iconMap = new Map(iconResult.documentList.map((item) => [item.path, item]));
74
+
75
+ for (const item of documentStructure) {
76
+ const iconData = iconMap.get(item.path);
77
+ if (iconData?.icon) {
78
+ item.icon = iconData.icon;
79
+ }
80
+ }
81
+ }
82
+ } catch (error) {
83
+ console.warn("⚠️ Failed to generate document icons:", error.message);
84
+ console.warn("Continuing without icons.");
85
+ }
86
+
87
+ // Return input unchanged (documentStructure is modified in place)
88
+ return inputOrParams || {};
89
+ }
90
+
91
+ generateDocumentIconIfNeeded.taskTitle = "Generate document icons if needed";
92
+ generateDocumentIconIfNeeded.description =
93
+ "Generate appropriate Lucide icons for root-level document structure items based on their title and description, or update icon if title/description changed";
@@ -0,0 +1,15 @@
1
+ import { getMainLanguageFiles } from "../../utils/docs-finder-utils.mjs";
2
+ import init from "../init/index.mjs";
3
+
4
+ export default async function listDocs(_, 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
+ listDocs.description = "List all available documentation files";
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Check if a string contains character-based language characters (Chinese, Japanese, Korean, etc.)
3
+ * @param {string} str - String to check
4
+ * @returns {boolean} - True if string contains character-based language characters
5
+ */
6
+ function isCharacterBasedLanguage(str) {
7
+ if (!str) return false;
8
+ // Check for Chinese, Japanese, Korean, and other character-based languages
9
+ // Chinese: \u4e00-\u9fff (CJK Unified Ideographs)
10
+ // Japanese: \u3040-\u309f (Hiragana), \u30a0-\u30ff (Katakana)
11
+ // Korean: \uac00-\ud7a3 (Hangul Syllables)
12
+ // Thai: \u0e00-\u0e7f
13
+ // Arabic: \u0600-\u06ff
14
+ const characterBasedPattern =
15
+ /[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7a3\u0e00-\u0e7f\u0600-\u06ff]/;
16
+ return characterBasedPattern.test(str);
17
+ }
18
+
19
+ /**
20
+ * Get character limit based on language type
21
+ * @param {string} title - Title to check
22
+ * @returns {number} - Character limit (24 for English, 12 for character-based languages)
23
+ */
24
+ function getCharacterLimit(title) {
25
+ return isCharacterBasedLanguage(title) ? 12 : 24;
26
+ }
27
+
28
+ /**
29
+ * Streamline document titles if they exceed length limits
30
+ * Reusable function for streamlining document titles in various contexts
31
+ * @param {Object} params
32
+ * @param {Array<{title: string, path: string}>} params.documentStructure - Document structure array
33
+ * @param {Object} options - Agent options with context
34
+ * @returns {Promise<void>} - Modifies documentStructure in place
35
+ */
36
+ export default async function streamlineDocumentTitlesIfNeeded({ documentStructure }, options) {
37
+ if (!documentStructure || !Array.isArray(documentStructure)) {
38
+ return;
39
+ }
40
+
41
+ // Filter items that need streamlining based on character count and language type
42
+ // English: > 24 characters, Character-based languages (Chinese, Japanese, etc.): > 12 characters
43
+ const itemsNeedingStreamline = documentStructure.filter((item) => {
44
+ if (!item.title) return false;
45
+ const limit = getCharacterLimit(item.title);
46
+ return item.title.length > limit;
47
+ });
48
+
49
+ if (itemsNeedingStreamline.length === 0) {
50
+ return;
51
+ }
52
+
53
+ const documentList = itemsNeedingStreamline.map((item) => ({
54
+ path: item.path,
55
+ title: item.title,
56
+ }));
57
+
58
+ const streamlineAgent = options?.context?.agents?.["documentTitleStreamline"];
59
+ if (!streamlineAgent) {
60
+ console.warn("⚠️ documentTitleStreamline agent not found. Skipping title streamlining.");
61
+ return;
62
+ }
63
+
64
+ try {
65
+ const streamlineResult = await options.context.invoke(streamlineAgent, {
66
+ documentList,
67
+ });
68
+
69
+ // Update the document items with streamlined titles using path as the key
70
+ if (streamlineResult.documentList && Array.isArray(streamlineResult.documentList)) {
71
+ const streamlineMap = new Map(streamlineResult.documentList.map((item) => [item.path, item]));
72
+
73
+ for (const item of documentStructure) {
74
+ const streamlined = streamlineMap.get(item.path);
75
+ if (streamlined) {
76
+ item.title = streamlined.title;
77
+ }
78
+ }
79
+ }
80
+ } catch (error) {
81
+ console.warn("⚠️ Failed to streamline document titles:", error.message);
82
+ console.warn("Continuing with original titles.");
83
+ }
84
+ }
85
+
86
+ streamlineDocumentTitlesIfNeeded.taskTitle = "Streamline document titles if needed";
87
+ streamlineDocumentTitlesIfNeeded.description =
88
+ "Shorten document titles that exceed length limits to make sidebar navigation less crowded";
package/aigne.yaml CHANGED
@@ -3,7 +3,7 @@
3
3
  model:
4
4
  # model: aignehub/gpt-5
5
5
  # model: aignehub/claude-sonnet-4-0
6
- model: aignehub/gemini-2.5-pro # reasoning_effort 128-32768
6
+ model: google/gemini-2.5-pro # reasoning_effort 128-32768
7
7
  # https://github.com/AIGNE-io/aigne-framework/blob/main/models/gemini/src/gemini-chat-model.ts#L115
8
8
  reasoning_effort:
9
9
  $get: reasoningEffort
@@ -79,6 +79,12 @@ agents:
79
79
  - ./agents/utils/check-feedback-refiner.mjs
80
80
  - ./agents/utils/feedback-refiner.yaml
81
81
  - ./agents/utils/analyze-feedback-intent.yaml
82
+ - ./agents/utils/list-docs.mjs
83
+
84
+ - ./agents/utils/document-title-streamline.yaml
85
+ - ./agents/utils/streamline-document-titles-if-needed.mjs
86
+ - ./agents/utils/document-icon-generate.yaml
87
+ - ./agents/utils/generate-document-icon-if-needed.mjs
82
88
 
83
89
  # User Preferences & Chat
84
90
  - ./agents/prefs/index.mjs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/doc-smith",
3
- "version": "0.8.15",
3
+ "version": "0.8.16-beta.1",
4
4
  "description": "AI-driven documentation generation tool built on the AIGNE Framework",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -24,25 +24,22 @@
24
24
  "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
25
25
  "license": "Elastic-2.0",
26
26
  "dependencies": {
27
- "@aigne/aigne-hub": "^0.10.5-beta.3",
28
- "@aigne/anthropic": "^0.14.5-beta.3",
29
27
  "@aigne/cli": "^1.53.1-beta.4",
30
28
  "@aigne/core": "^1.65.1-beta.3",
31
- "@aigne/gemini": "^0.14.5-beta.3",
32
- "@aigne/openai": "^0.16.5-beta.3",
33
29
  "@aigne/publish-docs": "^0.12.1",
34
30
  "@blocklet/payment-broker-client": "^1.22.8",
35
31
  "@terrastruct/d2": "^0.1.33",
36
32
  "chalk": "^5.5.0",
37
- "cli-highlight": "^2.1.11",
38
33
  "debug": "^4.4.1",
39
34
  "diff": "^8.0.2",
40
35
  "dompurify": "^3.2.6",
36
+ "fast-deep-equal": "^3.1.3",
41
37
  "file-type": "^21.0.0",
42
38
  "fs-extra": "^11.3.1",
43
39
  "glob": "^11.0.3",
44
40
  "gpt-tokenizer": "^3.2.0",
45
41
  "image-size": "^2.0.2",
42
+ "is-in-ci": "^2.0.0",
46
43
  "isbinaryfile": "^5.0.6",
47
44
  "jsdom": "^26.1.0",
48
45
  "marked": "^15.0.12",
@@ -56,7 +53,7 @@
56
53
  "remark-gfm": "^4.0.1",
57
54
  "remark-lint": "^10.0.1",
58
55
  "remark-parse": "^11.0.0",
59
- "terminal-link": "^4.0.0",
56
+ "terminal-link": "^5.0.0",
60
57
  "typescript": "^5.9.3",
61
58
  "ufo": "^1.6.1",
62
59
  "unified": "^11.0.5",
@@ -1,12 +1,18 @@
1
1
  <media_file_list_usage_rules>
2
2
 
3
- **Usage Workflow**
3
+ ## Media File List Usage Rules
4
+
5
+ You must use the provided `<media_file_list>` data to determine which media files to use and where to insert them.
6
+
7
+ ### Usage Workflow
8
+
4
9
  1. Read the `<media_file_list>` data and take note of each file's `path` and `description` as references.
5
10
  2. Combine those descriptions with the current document's content to decide which images should be used and where they should be inserted.
6
11
  3. Confirm that every inserted image path comes from `<media_file_list>`. If a path is missing from that list, replace it with one that is included.
7
12
 
8
- **Usage Requirements**
13
+ ### Usage Requirements
9
14
  - Insert images with Markdown syntax: `![Descriptive alt text](<path-from-media_file_list>)`.
10
15
  - Never invent, reinterpret, fabricate, normalize, or rewrite any media file path under any circumstances.
16
+ - After inserting a media file, update the surrounding document text to introduce, reference, or describe the media, so the media is properly integrated and its purpose is clear to readers.
11
17
 
12
18
  </media_file_list_usage_rules>