@aigne/doc-smith 0.9.7 → 0.9.8-alpha.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 (80) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/agentic-agents/common/base-info.md +50 -0
  3. package/agentic-agents/common/planner.md +115 -0
  4. package/agentic-agents/common/worker.md +51 -0
  5. package/agentic-agents/create/index.yaml +79 -0
  6. package/agentic-agents/create/objective.md +44 -0
  7. package/agentic-agents/create/set-custom-prompt.mjs +43 -0
  8. package/agentic-agents/detail/index.yaml +82 -0
  9. package/agentic-agents/detail/objective.md +9 -0
  10. package/agentic-agents/detail/set-custom-prompt.mjs +88 -0
  11. package/agentic-agents/structure/design-rules.md +39 -0
  12. package/agentic-agents/structure/index.yaml +63 -0
  13. package/agentic-agents/structure/objective.md +14 -0
  14. package/agentic-agents/structure/review-criteria.md +55 -0
  15. package/agentic-agents/structure/set-custom-prompt.mjs +78 -0
  16. package/agentic-agents/utils/load-base-sources.mjs +96 -0
  17. package/agents/create/analyze-diagram-type-llm.yaml +160 -0
  18. package/agents/create/analyze-diagram-type.mjs +297 -0
  19. package/agents/create/check-need-generate-structure.mjs +1 -34
  20. package/agents/create/generate-diagram-image.yaml +60 -0
  21. package/agents/create/index.yaml +9 -5
  22. package/agents/create/replace-d2-with-image.mjs +625 -0
  23. package/agents/create/user-review-document-structure.mjs +8 -7
  24. package/agents/create/utils/init-current-content.mjs +5 -9
  25. package/agents/evaluate/document.yaml +6 -0
  26. package/agents/evaluate/index.yaml +1 -0
  27. package/agents/init/index.mjs +36 -388
  28. package/agents/localize/index.yaml +4 -4
  29. package/agents/media/batch-generate-media-description.yaml +2 -0
  30. package/agents/media/generate-media-description.yaml +3 -0
  31. package/agents/media/load-media-description.mjs +44 -15
  32. package/agents/publish/index.yaml +1 -0
  33. package/agents/publish/publish-docs.mjs +1 -4
  34. package/agents/update/check-diagram-flag.mjs +116 -0
  35. package/agents/update/check-document.mjs +0 -1
  36. package/agents/update/check-generate-diagram.mjs +48 -30
  37. package/agents/update/check-sync-image-flag.mjs +55 -0
  38. package/agents/update/check-update-is-single.mjs +11 -0
  39. package/agents/update/generate-diagram.yaml +43 -9
  40. package/agents/update/generate-document.yaml +9 -0
  41. package/agents/update/handle-document-update.yaml +10 -8
  42. package/agents/update/index.yaml +25 -7
  43. package/agents/update/sync-images-and-exit.mjs +148 -0
  44. package/agents/update/update-single/update-single-document-detail.mjs +131 -17
  45. package/agents/utils/analyze-feedback-intent.mjs +136 -0
  46. package/agents/utils/choose-docs.mjs +185 -40
  47. package/agents/utils/generate-document-or-skip.mjs +41 -0
  48. package/agents/utils/handle-diagram-operations.mjs +263 -0
  49. package/agents/utils/load-all-document-content.mjs +30 -0
  50. package/agents/utils/load-sources.mjs +2 -2
  51. package/agents/utils/post-generate.mjs +14 -3
  52. package/agents/utils/read-current-document-content.mjs +46 -0
  53. package/agents/utils/save-doc-translation.mjs +34 -0
  54. package/agents/utils/save-doc.mjs +42 -0
  55. package/agents/utils/save-sidebar.mjs +19 -6
  56. package/agents/utils/skip-if-content-exists.mjs +27 -0
  57. package/aigne.yaml +15 -3
  58. package/assets/report-template/report.html +17 -17
  59. package/docs-mcp/read-doc-content.mjs +30 -1
  60. package/package.json +9 -7
  61. package/prompts/detail/diagram/generate-image-system.md +135 -0
  62. package/prompts/detail/diagram/generate-image-user.md +32 -0
  63. package/prompts/detail/generate/user-prompt.md +27 -13
  64. package/prompts/evaluate/document.md +23 -10
  65. package/prompts/media/media-description/system-prompt.md +10 -2
  66. package/prompts/media/media-description/user-prompt.md +9 -0
  67. package/utils/check-document-has-diagram.mjs +95 -0
  68. package/utils/constants/index.mjs +46 -0
  69. package/utils/d2-utils.mjs +119 -178
  70. package/utils/delete-diagram-images.mjs +99 -0
  71. package/utils/docs-finder-utils.mjs +133 -25
  72. package/utils/image-compress.mjs +75 -0
  73. package/utils/kroki-utils.mjs +2 -3
  74. package/utils/load-config.mjs +29 -0
  75. package/utils/sync-diagram-to-translations.mjs +262 -0
  76. package/utils/utils.mjs +24 -0
  77. package/agents/create/check-diagram.mjs +0 -40
  78. package/agents/create/draw-diagram.yaml +0 -27
  79. package/agents/create/merge-diagram.yaml +0 -39
  80. package/agents/create/wrap-diagram-code.mjs +0 -35
@@ -0,0 +1,297 @@
1
+ import { DIAGRAM_STYLES } from "../../utils/constants/index.mjs";
2
+
3
+ const DEFAULT_DIAGRAM_STYLE = "modern";
4
+ const DEFAULT_DIAGRAM_TYPE = "flowchart";
5
+
6
+ // Type-specific content requirements
7
+ const TYPE_REQUIREMENTS = {
8
+ architecture: `- Accurately represent the system architecture, components, services, and their relationships
9
+ - Show clear component boundaries and service interactions
10
+ - Include all key architectural elements (layers, modules, services, databases, APIs)
11
+ - Display data flow and communication patterns between components
12
+ - Use clear labels for each component and connection`,
13
+ flowchart: `- Accurately represent the process flow, steps, decisions, and workflow
14
+ - Show clear step-by-step progression with decision points
15
+ - Use standard flowchart symbols: rectangles for processes, diamonds for decisions, arrows for flows
16
+ - Include all key steps and decision branches
17
+ - Maintain logical flow direction (top-to-bottom or left-to-right)`,
18
+ guide: `- Show user journey, tutorial flow, or guided process
19
+ - Display clear progression from start to completion
20
+ - Include key milestones, checkpoints, or decision points
21
+ - Use clear visual cues to guide the viewer through the process
22
+ - Make it easy to follow and understand the path`,
23
+ intro: `- Provide a high-level overview or conceptual explanation
24
+ - Show main concepts, relationships, and key ideas
25
+ - Use clear visual hierarchy to emphasize important elements
26
+ - Make it accessible and easy to understand for newcomers
27
+ - Focus on big picture rather than detailed implementation`,
28
+ sequence: `- Show interactions over time between components or actors
29
+ - Display clear message flow and timing
30
+ - Include all participating entities and their interactions
31
+ - Show chronological order of events
32
+ - Use clear labels for messages and interactions`,
33
+ network: `- Show network structure, nodes, and connections
34
+ - Display routing paths and network topology
35
+ - Include all network components (routers, switches, servers, clients)
36
+ - Show connection types and data flow directions
37
+ - Use clear labels for network elements`,
38
+ };
39
+
40
+ // Style-specific requirements
41
+ const STYLE_REQUIREMENTS = {
42
+ modern: `- Modern, clean, professional diagram style
43
+ - Contemporary design elements with smooth lines
44
+ - Professional color scheme suitable for technical documentation
45
+ - Clear visual hierarchy and readable text
46
+ - Sleek and polished appearance`,
47
+ standard: `- Standard flowchart style with traditional symbols
48
+ - Conventional formatting and clear structure
49
+ - Rectangles for processes, diamonds for decisions, arrows for flows
50
+ - Clear, readable text labels
51
+ - Professional and familiar appearance`,
52
+ "hand-drawn": `- Hand-drawn, sketch-like style with natural, organic lines
53
+ - Slightly imperfect shapes for a casual, approachable appearance
54
+ - Natural line variations and hand-drawn aesthetics
55
+ - Friendly and informal visual style
56
+ - Avoid perfect geometric shapes`,
57
+ anthropomorphic: `- Anthropomorphic style with personified elements
58
+ - Vivid and lively imagery with characters or objects having human-like features
59
+ - Engaging and memorable visual elements
60
+ - Creative and expressive design
61
+ - Make abstract concepts more relatable through personification`,
62
+ flat: `- Flat design style with no shadows, gradients, or 3D effects
63
+ - Clean geometric shapes with bold colors
64
+ - Minimalist aesthetics with simple, flat surfaces
65
+ - Modern and clean appearance
66
+ - Avoid depth and dimensionality`,
67
+ minimalist: `- Minimalist style with the fewest possible elements
68
+ - Maximum clarity with simple shapes
69
+ - Ample white space and essential information only
70
+ - Clean and uncluttered appearance
71
+ - Focus on core message without distractions`,
72
+ "3d": `- 3D style with three-dimensional effects and perspective
73
+ - Depth, shadows, and realistic spatial relationships
74
+ - Three-dimensional appearance with volume and dimension
75
+ - Professional and modern 3D rendering
76
+ - Clear depth cues and perspective`,
77
+ };
78
+
79
+ /**
80
+ * Analyze document content to determine diagram type and select appropriate style
81
+ * Uses LLM analysis to determine diagram type and style
82
+ * Supports extracting style and type preferences from user feedback
83
+ */
84
+ export default async function analyzeDiagramType(
85
+ {
86
+ documentContent,
87
+ availableStyles = [],
88
+ defaultStyle,
89
+ diagramming,
90
+ locale = "en",
91
+ feedback = "",
92
+ },
93
+ options,
94
+ ) {
95
+ // Extract defaultStyle from diagramming object if not provided directly
96
+ if (!defaultStyle && diagramming?.style) {
97
+ defaultStyle = diagramming.style;
98
+ }
99
+
100
+ // Step 1: Use LLM to analyze and make final decision (LLM will analyze feedback directly)
101
+ const llmAgent = options.context?.agents?.["analyzeDiagramTypeLLM"];
102
+ let llmResult = null;
103
+
104
+ if (llmAgent) {
105
+ try {
106
+ // Build styleDescriptions object for template
107
+ // Include predefined styles as reference, but allow LLM to use any style
108
+ const styleDescriptions = {};
109
+ const stylesToUse =
110
+ availableStyles.length > 0 ? availableStyles : Object.keys(DIAGRAM_STYLES);
111
+ for (const style of stylesToUse) {
112
+ if (DIAGRAM_STYLES[style]) {
113
+ styleDescriptions[style] =
114
+ DIAGRAM_STYLES[style].description || DIAGRAM_STYLES[style].name;
115
+ }
116
+ }
117
+ // Also include all predefined styles as reference even if not in availableStyles
118
+ // This helps LLM understand common style options but doesn't restrict it
119
+ for (const [style, styleInfo] of Object.entries(DIAGRAM_STYLES)) {
120
+ if (!styleDescriptions[style]) {
121
+ styleDescriptions[style] = styleInfo.description || styleInfo.name;
122
+ }
123
+ }
124
+
125
+ const llmInput = {
126
+ documentContent,
127
+ availableStyles: stylesToUse,
128
+ styleDescriptions,
129
+ locale,
130
+ feedback: feedback || "",
131
+ defaultStyle: defaultStyle || null,
132
+ };
133
+
134
+ llmResult = await options.context.invoke(llmAgent, llmInput);
135
+ } catch (error) {
136
+ console.warn(`⚠️ LLM analysis failed: ${error.message}`);
137
+ }
138
+ }
139
+
140
+ // Step 2: Determine diagram type
141
+ // Priority: LLM result (which already analyzed feedback) > default
142
+ const diagramType = llmResult?.diagramType || DEFAULT_DIAGRAM_TYPE;
143
+
144
+ // Step 3: Select style
145
+ // Trust LLM to always return a valid style (required in output_schema)
146
+ // LLM can return any style name, not limited to predefined styles
147
+ // Only use fallback if LLM completely failed
148
+ const diagramStyle = llmResult?.diagramStyle || defaultStyle || DEFAULT_DIAGRAM_STYLE;
149
+
150
+ // Note: We allow any style name from LLM, even if not in availableStyles
151
+ // This enables creative styles beyond predefined ones (e.g., 'watercolor', 'cyberpunk', 'isometric')
152
+ // If availableStyles is provided and not empty, it serves as a preference guide, not a strict restriction
153
+
154
+ // Step 4: Generate prompt requirements for image generation
155
+ const diagramTypeRequirements =
156
+ TYPE_REQUIREMENTS[diagramType] || TYPE_REQUIREMENTS[DEFAULT_DIAGRAM_TYPE];
157
+ const diagramStyleRequirements =
158
+ STYLE_REQUIREMENTS[diagramStyle] || STYLE_REQUIREMENTS[DEFAULT_DIAGRAM_STYLE];
159
+
160
+ // Generate negative prompt exclusions based on style
161
+ let negativePromptExclusions = "";
162
+ if (diagramStyle !== "anthropomorphic") {
163
+ negativePromptExclusions += ", anthropomorphic";
164
+ }
165
+ if (diagramStyle !== "hand-drawn") {
166
+ negativePromptExclusions += ", hand-drawn, sketch";
167
+ }
168
+
169
+ // Step 5: Extract document summary from LLM result
170
+ // The LLM creates a concise summary focusing on key elements for diagram generation
171
+ // This ensures both the analysis model and image generation model have consistent understanding
172
+ const documentSummary = llmResult?.documentSummary || documentContent;
173
+
174
+ // If LLM didn't provide a summary (fallback), use original content
175
+ // But prefer the LLM-generated summary as it's focused and aligned with the analysis
176
+
177
+ // Step 6: Determine aspect ratio from LLM result
178
+ // The LLM analyzes the content structure and recommends the best aspect ratio
179
+ // We trust the LLM's judgment as it has analyzed the actual content
180
+ // If LLM doesn't provide aspectRatio (shouldn't happen, but fallback for safety), use 4:3 as safe default
181
+ let aspectRatio = llmResult?.aspectRatio || "4:3";
182
+
183
+ // Validate that the aspectRatio is one of the supported values
184
+ const supportedRatios = ["1:1", "5:4", "4:3", "3:2", "16:9", "21:9"];
185
+ if (!supportedRatios.includes(aspectRatio)) {
186
+ console.warn(`Invalid aspectRatio "${aspectRatio}" from LLM, falling back to "4:3"`);
187
+ aspectRatio = "4:3";
188
+ }
189
+
190
+ // Step 7: Return document content and summary for image generation
191
+ return {
192
+ diagramType,
193
+ diagramStyle,
194
+ aspectRatio,
195
+ documentContent, // The full document content (kept for backward compatibility and additional context)
196
+ documentSummary, // The concise summary generated by LLM, focused on key elements for diagram generation
197
+ diagramTypeRequirements,
198
+ diagramStyleRequirements,
199
+ negativePromptExclusions,
200
+ };
201
+ }
202
+
203
+ analyzeDiagramType.input_schema = {
204
+ type: "object",
205
+ properties: {
206
+ documentContent: {
207
+ type: "string",
208
+ description: "The document content to analyze for diagram type and style selection",
209
+ },
210
+ availableStyles: {
211
+ type: "array",
212
+ description:
213
+ "List of available diagram styles configured by user (optional restriction). If empty, any style is allowed.",
214
+ items: {
215
+ type: "string",
216
+ },
217
+ },
218
+ defaultStyle: {
219
+ type: "string",
220
+ description:
221
+ "Default diagram style to use when no style is specified in feedback. Can be any style name, not limited to predefined styles.",
222
+ },
223
+ diagramming: {
224
+ type: "object",
225
+ description: "Diagramming configuration object (alternative way to pass style)",
226
+ properties: {
227
+ style: {
228
+ type: "string",
229
+ description: "Default diagram style",
230
+ },
231
+ },
232
+ },
233
+ locale: {
234
+ type: "string",
235
+ description: "Language for analysis",
236
+ default: "en",
237
+ },
238
+ feedback: {
239
+ type: "string",
240
+ description:
241
+ "User feedback that may contain style or type preferences (e.g., 'use anthropomorphic style', 'create architecture diagram')",
242
+ default: "",
243
+ },
244
+ },
245
+ required: ["documentContent"],
246
+ };
247
+
248
+ analyzeDiagramType.output_schema = {
249
+ type: "object",
250
+ properties: {
251
+ diagramType: {
252
+ type: "string",
253
+ description: "The detected diagram type",
254
+ },
255
+ diagramStyle: {
256
+ type: "string",
257
+ description: "The selected diagram style",
258
+ },
259
+ diagramTypeRequirements: {
260
+ type: "string",
261
+ description: "Content requirements for the diagram type",
262
+ },
263
+ diagramStyleRequirements: {
264
+ type: "string",
265
+ description: "Style requirements for the diagram style",
266
+ },
267
+ negativePromptExclusions: {
268
+ type: "string",
269
+ description: "Additional negative prompt exclusions based on style",
270
+ },
271
+ aspectRatio: {
272
+ type: "string",
273
+ description: "Aspect ratio for the diagram (must match content flow direction)",
274
+ enum: ["1:1", "5:4", "4:3", "3:2", "16:9", "21:9"],
275
+ },
276
+ documentContent: {
277
+ type: "string",
278
+ description:
279
+ "The full document content (kept for backward compatibility and additional context)",
280
+ },
281
+ documentSummary: {
282
+ type: "string",
283
+ description:
284
+ "A concise summary of the document content focusing on key elements needed for diagram generation. This summary is generated by the analysis LLM to ensure consistent understanding between analysis and image generation models.",
285
+ },
286
+ },
287
+ required: [
288
+ "diagramType",
289
+ "diagramStyle",
290
+ "aspectRatio",
291
+ "documentSummary",
292
+ "diagramTypeRequirements",
293
+ "diagramStyleRequirements",
294
+ "negativePromptExclusions",
295
+ "documentContent",
296
+ ],
297
+ };
@@ -1,4 +1,3 @@
1
- import chalk from "chalk";
2
1
  import { getActiveRulesForScope } from "../../utils/preferences-utils.mjs";
3
2
  import { getProjectInfo, loadConfigFromFile, saveValueToConfig } from "../../utils/utils.mjs";
4
3
  import streamlineDocumentTitlesIfNeeded from "../utils/streamline-document-titles-if-needed.mjs";
@@ -7,38 +6,6 @@ export default async function checkNeedGenerateStructure(
7
6
  { originalDocumentStructure, forceRegenerate, ...rest },
8
7
  options,
9
8
  ) {
10
- // Check if originalDocumentStructure is empty and prompt user
11
- if (!originalDocumentStructure) {
12
- const choice = await options.prompts.select({
13
- message: "Project configured. Generate documentation structure now?",
14
- choices: [
15
- {
16
- name: "Yes, generate now",
17
- value: "generate",
18
- },
19
- {
20
- name: "No, review configuration first",
21
- value: "later",
22
- },
23
- ],
24
- });
25
-
26
- if (choice === "later") {
27
- console.log(`\nConfiguration file: ${chalk.cyan("./.aigne/doc-smith/config.yaml")}`);
28
- console.log("Review and edit your configuration, then run `aigne doc create` to continue.");
29
-
30
- // In test environment, return a special result instead of exiting
31
- if (process.env.NODE_ENV === "test") {
32
- return {
33
- userDeferred: true,
34
- documentStructure: null,
35
- };
36
- }
37
-
38
- process.exit(0);
39
- }
40
- }
41
-
42
9
  let finalFeedback = "";
43
10
 
44
11
  // User requested regeneration
@@ -54,7 +21,7 @@ export default async function checkNeedGenerateStructure(
54
21
  };
55
22
  }
56
23
 
57
- const generateStructureAgent = options.context.agents["generateStructure"];
24
+ const generateStructureAgent = options.context.agents["generateStructureExp"];
58
25
 
59
26
  const structureRules = getActiveRulesForScope("structure", []);
60
27
  const globalRules = getActiveRulesForScope("global", []);
@@ -0,0 +1,60 @@
1
+ type: image
2
+ name: generateDiagramImage
3
+ image_model:
4
+ model: google/gemini-3-pro-image-preview
5
+ # The cues that come with thought patterns are actually not obvious
6
+ # thinkingConfig:
7
+ # includeThoughts: true
8
+ # responseModalities:
9
+ # - 'TEXT'
10
+ # - 'IMAGE'
11
+ imageConfig:
12
+ imageSize:
13
+ $get: size
14
+ aspectRatio:
15
+ $get: ratio
16
+
17
+ instructions:
18
+ - role: system
19
+ url: ../../prompts/detail/diagram/generate-image-system.md
20
+ - role: user
21
+ url: ../../prompts/detail/diagram/generate-image-user.md
22
+
23
+ input_schema:
24
+ type: object
25
+ properties:
26
+ documentContent:
27
+ type: string
28
+ description: The full original document content
29
+ documentSummary:
30
+ type: string
31
+ description: A comprehensive summary of the document content for diagram generation (preferred over documentContent if available)
32
+ diagramType:
33
+ type: string
34
+ description: The type of diagram to generate (architecture, flowchart, guide, intro, sequence, network)
35
+ diagramStyle:
36
+ type: string
37
+ description: The visual style for the diagram (modern, standard, hand-drawn, anthropomorphic, flat, minimalist, 3d)
38
+ locale:
39
+ type: string
40
+ description: Language for diagram labels
41
+ default: en
42
+ size:
43
+ type: string
44
+ description: Size of the generated image (e.g., "1K", "2K")
45
+ default: "1K"
46
+ ratio:
47
+ type: string
48
+ description: Aspect ratio of the generated image (must match content flow direction)
49
+ enum: ["1:1", "5:4", "4:3", "3:2", "16:9", "21:9"]
50
+ aspectRatio:
51
+ type: string
52
+ description: Aspect ratio of the generated image (alias for ratio, used in prompt templates)
53
+ enum: ["1:1", "5:4", "4:3", "3:2", "16:9", "21:9"]
54
+ required:
55
+ - documentContent
56
+ - diagramType
57
+ - diagramStyle
58
+ - ratio
59
+ include_input_in_output: true
60
+
@@ -8,6 +8,7 @@ skills:
8
8
  - url: ../init/index.mjs
9
9
  default_input:
10
10
  skipIfExists: true
11
+ # - ../../agentic-agents/structure/index.yaml
11
12
  - ../utils/load-sources.mjs
12
13
  - ./check-need-generate-structure.mjs
13
14
  - url: ../utils/save-output.mjs
@@ -36,10 +37,13 @@ skills:
36
37
  input_schema:
37
38
  type: object
38
39
  properties:
39
- glossary:
40
+ feedback:
40
41
  type: string
41
- description: Glossary file for consistent terminology (use @filename.md)
42
- forceRegenerate:
43
- type: boolean
44
- description: Rebuild all documentation from scratch
42
+ description: User feedback describing what documentation tasks to perform (natural language)
43
+ # glossary:
44
+ # type: string
45
+ # description: Glossary file for consistent terminology (use @filename.md)
46
+ # forceRegenerate:
47
+ # type: boolean
48
+ # description: Rebuild all documentation from scratch
45
49
  mode: sequential