@aigne/doc-smith 0.8.15-beta.15 → 0.8.15-beta.16

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.15-beta.16](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.15-beta.15...v0.8.15-beta.16) (2025-11-07)
4
+
5
+
6
+ ### Features
7
+
8
+ * support customize diagramming quantity ([#277](https://github.com/AIGNE-io/aigne-doc-smith/issues/277)) ([9d9fa6a](https://github.com/AIGNE-io/aigne-doc-smith/commit/9d9fa6a1f344c93df187f2dc502c5479e304e0f4))
9
+
3
10
  ## [0.8.15-beta.15](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.15-beta.14...v0.8.15-beta.15) (2025-11-07)
4
11
 
5
12
 
@@ -1,27 +1,82 @@
1
- const placeholder = "DIAGRAM_PLACEHOLDER";
1
+ const PLACEHOLDER = "DIAGRAM_PLACEHOLDER";
2
+ const DEFAULT_DIAGRAMMING_EFFORT = 5;
3
+ const MIN_DIAGRAMMING_EFFORT = 0;
4
+ const MAX_DIAGRAMMING_EFFORT = 10;
2
5
 
3
6
  export default async function checkGenerateDiagram(
4
- { needDiagram, documentContent, locale },
7
+ {
8
+ documentContent,
9
+ locale,
10
+ feedback,
11
+ detailFeedback,
12
+ originalContent,
13
+ path: docPath,
14
+ diagramming,
15
+ },
5
16
  options,
6
17
  ) {
7
- if (!needDiagram) {
8
- return {};
18
+ let content = documentContent;
19
+ let diagramSourceCode;
20
+ let skipGenerateDiagram = false;
21
+
22
+ const preCheckAgent = options.context?.agents?.["preCheckGenerateDiagram"];
23
+
24
+ const preCheckResult = await options.context.invoke(preCheckAgent, {
25
+ documentContent,
26
+ feedback,
27
+ detailFeedback,
28
+ previousGenerationContent: originalContent,
29
+ });
30
+
31
+ const totalScore = (preCheckResult.details || []).reduce((acc, curr) => acc + curr.score, 0);
32
+ if (![false, "false", "", undefined, null].includes(preCheckResult.content)) {
33
+ content = preCheckResult.content;
9
34
  }
10
35
 
11
- const generateAgent = options.context?.agents?.["generateDiagram"];
12
- let content = documentContent;
36
+ let diagrammingEffort = diagramming?.effort
37
+ ? Number(diagramming?.effort)
38
+ : DEFAULT_DIAGRAMMING_EFFORT;
13
39
 
14
- if (content.includes(placeholder)) {
40
+ if (Number.isNaN(diagrammingEffort)) {
41
+ diagrammingEffort = DEFAULT_DIAGRAMMING_EFFORT;
42
+ } else {
43
+ diagrammingEffort = Math.min(
44
+ Math.max(MIN_DIAGRAMMING_EFFORT, diagrammingEffort),
45
+ MAX_DIAGRAMMING_EFFORT,
46
+ );
47
+ }
48
+
49
+ if (totalScore <= diagrammingEffort) {
50
+ skipGenerateDiagram = true;
51
+ }
52
+
53
+ if (skipGenerateDiagram) {
54
+ content = documentContent;
55
+ } else {
15
56
  try {
16
- const { diagramSourceCode } = await options.context.invoke(generateAgent, {
17
- documentContent,
57
+ const generateAgent = options.context?.agents?.["generateDiagram"];
58
+ ({ diagramSourceCode } = await options.context.invoke(generateAgent, {
59
+ documentContent: content,
18
60
  locale,
19
- });
20
- content = content.replace(placeholder, diagramSourceCode);
61
+ }));
21
62
  } catch (error) {
22
- // FIXME: @zhanghan should regenerate document without diagram
23
- content = content.replace(placeholder, "");
24
- console.log(`⚠️ Skip generate any diagram: ${error.message}`);
63
+ diagramSourceCode = "";
64
+ skipGenerateDiagram = true;
65
+ console.log(`⚠️ Skip generate any diagram for ${docPath}: ${error.message}`);
66
+ }
67
+
68
+ if (diagramSourceCode && !skipGenerateDiagram) {
69
+ if (content.includes(PLACEHOLDER)) {
70
+ content = content.replace(PLACEHOLDER, diagramSourceCode);
71
+ } else {
72
+ const mergeAgent = options.context?.agents?.["mergeDiagramToDocument"];
73
+ ({ content } = await options.context.invoke(mergeAgent, {
74
+ diagramSourceCode,
75
+ content,
76
+ }));
77
+ }
78
+ } else {
79
+ content = documentContent;
25
80
  }
26
81
  }
27
82
 
@@ -46,19 +46,7 @@ input_schema:
46
46
  - rules
47
47
  - detailDataSource
48
48
  - originalDocumentStructure
49
- # output_key: content
50
- output_schema:
51
- type: object
52
- properties:
53
- content:
54
- type: string
55
- description: Document content
56
- needDiagram:
57
- type: boolean
58
- description: Does this document need to generate diagram?
59
- required:
60
- - content
61
- - detailDataSource
49
+ output_key: content
62
50
  afs:
63
51
  modules:
64
52
  - module: system-fs
@@ -0,0 +1,44 @@
1
+ name: preCheckGenerateDiagram
2
+ description: Pre-check for generating diagram
3
+ model:
4
+ reasoning_effort: 1
5
+ instructions:
6
+ url: ../../prompts/detail/d2-diagram/pre-check.md
7
+ input_schema:
8
+ type: object
9
+ properties:
10
+ documentContent:
11
+ type: string
12
+ description: Source content of the document
13
+ feedback:
14
+ type: string
15
+ description: User generation feedback
16
+ detailFeedback:
17
+ type: string
18
+ description: Current document detail feedback
19
+ previousGenerationContent:
20
+ type: string
21
+ description: Previous document content
22
+ required:
23
+ - documentContent
24
+ output_schema:
25
+ type: object
26
+ properties:
27
+ content:
28
+ type: string
29
+ description: Document content
30
+ details:
31
+ type: array
32
+ description: Detailed needDiagram score
33
+ items:
34
+ type: object
35
+ properties:
36
+ type:
37
+ type: string
38
+ score:
39
+ type: number
40
+ reason:
41
+ type: string
42
+ required:
43
+ - content
44
+
package/aigne.yaml CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env aigne
2
2
 
3
3
  model:
4
+ # model: aignehub/gpt-5
5
+ # model: aignehub/claude-sonnet-4-0
4
6
  model: aignehub/gemini-2.5-pro # reasoning_effort 128-32768
5
7
  # https://github.com/AIGNE-io/aigne-framework/blob/main/models/gemini/src/gemini-chat-model.ts#L115
6
8
  reasoning_effort:
@@ -101,6 +103,7 @@ agents:
101
103
  - ./agents/generate/merge-diagram.yaml
102
104
  - ./agents/update/generate-diagram.yaml
103
105
  - ./agents/update/check-generate-diagram.mjs
106
+ - ./agents/update/pre-check-generate-diagram.yaml
104
107
  cli:
105
108
  chat: ./agents/chat/index.yaml
106
109
  agents:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/doc-smith",
3
- "version": "0.8.15-beta.15",
3
+ "version": "0.8.15-beta.16",
4
4
  "description": "AI-driven documentation generation tool built on the AIGNE Framework",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,4 +1,4 @@
1
- <custom_components_usage>
1
+ <custom_components_usage_rules>
2
2
  When generating document details, you can use the following custom components at appropriate locations based on their descriptions and functionality to enhance document presentation:
3
3
 
4
4
  ## XCard: Individual link display card
@@ -48,11 +48,11 @@ Example 1: Inline Markdown formatting in card content
48
48
 
49
49
  Example 2: Code block inside card content
50
50
 
51
- ```md
51
+ ````md
52
52
  <x-card data-title="ctrl_break()" data-icon="lucide:keyboard">
53
53
  Creates a listener for "ctrl-break" events.
54
54
 
55
- \`\`\`rust
55
+ ```rust
56
56
  use tokio::signal::windows::ctrl_break;
57
57
 
58
58
  #[tokio::main]
@@ -62,10 +62,11 @@ stream.recv().await;
62
62
  println!("got ctrl-break");
63
63
  Ok(())
64
64
  }
65
- \`\`\`
66
- </x-card>
67
65
  ```
68
66
 
67
+ ````
68
+
69
+
69
70
  ## XCards: Multiple cards container
70
71
 
71
72
  Suitable for displaying multiple links using a card list format, providing a richer and more visually appealing presentation.
@@ -80,7 +81,7 @@ Suitable for displaying multiple links using a card list format, providing a ric
80
81
 
81
82
  ### Usage Rules
82
83
 
83
- - **Visual Consistency**: All <x-card> elements within the same <x-cards> must maintain visual consistency:
84
+ - **Visual Consistency**: All `<x-card>` elements within the same `<x-cards>` must maintain visual consistency:
84
85
  - It's recommended to always provide data-icon for each card.
85
86
  - Or all cards should have data-image.
86
87
  - Avoid mixing (some with icons, some with only images).
@@ -106,6 +107,18 @@ Example 2: Two-column cards with images
106
107
  </x-cards>
107
108
  ```
108
109
 
110
+ Example 3: Replace markdown format multiple links
111
+
112
+ ```md
113
+ For more detailed information on specific features, please refer to the following sections:
114
+
115
+ <x-cards data-columns="3">
116
+ <x-card data-title="Using Discussions" data-href="/discussions">Introduce how to use discussions</x-card>
117
+ <x-card data-title="Using the Blog" data-href="/blog">Introduce how to use the Blog</x-card>
118
+ <x-card data-title="Using Chat" data-href="/chat">Introduce how to use Chat</x-card>
119
+ </x-cards>
120
+ ```
121
+
109
122
  ### Bad Examples
110
123
 
111
124
  Example 1: Using a single-column layout (`data-columns="1"`) is not allowed
@@ -125,6 +138,15 @@ Example 2: Contains only one `<x-card>` (must include multiple cards)
125
138
  </x-cards>
126
139
  ```
127
140
 
141
+ Example 3: Markdown format multiple links
142
+
143
+ ```md
144
+ For more detailed information on specific features, please refer to the following sections:
145
+ - [Using Discussions](./discussions.md)
146
+ - [Using the Blog](./blog.md)
147
+ - [Using Chat](./chat.md)
148
+ ```
149
+
128
150
  ## XField: Structured data field
129
151
 
130
152
  Suitable for displaying API parameters, return values, context data, and any structured data with metadata in a clean, organized format. Supports nested structures for complex data types.
@@ -517,4 +539,4 @@ Example 6: Missing blank line before x-field-group (violates "Spacing Around" ru
517
539
  </x-field-group>
518
540
  ```
519
541
 
520
- </custom_components_usage>
542
+ </custom_components_usage_rules>
@@ -0,0 +1,23 @@
1
+ <document_content>
2
+ {{documentContent}}
3
+ </document_content>
4
+
5
+ {% if feedback %}
6
+ <feedback>
7
+ {{feedback}}
8
+ </feedback>
9
+ {% endif %}
10
+
11
+ {% if detailFeedback %}
12
+ <content_review_feedback>
13
+ {{ detailFeedback }}
14
+ </content_review_feedback>
15
+ {% endif %}
16
+
17
+ {% if previousGenerationContent %}
18
+ <previous_generation_content>
19
+ {{ previousGenerationContent }}
20
+ </previous_generation_content>
21
+ {% endif %}
22
+
23
+ {% include "./rules.md" %}
@@ -1,26 +1,44 @@
1
1
  <diagram_generation_rules>
2
- **Generation Workflow**
3
- 1. Use the current `<detail_data_source>`, `<content_review_feedback>`, and `<feedback>` to decide whether this document requires a diagram.
4
- 2. When a diagram is needed, call the `generateDiagram` tool to create it and insert the returned content at the most fitting location in the document.
5
- 3. Check whether the data sources include `<diagram_source_code>`. If not, remove any embedded diagram from the document.
6
-
7
- **Generation Result Usage**
8
- When `<diagram_source_code>` is available, insert it into the document exactly as returned without any edits.
9
-
10
- **Generation Requirements**
11
- 1. Diagram Triggers and Types: Call `generateDiagram` and select the most appropriate type when describing the following specific content
12
- - Architecture Diagram (High-Level)
13
- - **Trigger**: When the document provides a high-level overview of a system, project, or the overall documentation set.
14
- - **Content**: Must illustrate the main components, their relationships, and the overall structure.
15
- - Structural Diagram (Module-Level)
16
- - **Trigger**: When generating the introductory document for a major section or module.
17
- - **Content**: Must show the key sub-components, files, or core concepts within that specific module.
18
- - Process and Interaction Diagrams (Detailed)
19
- - **Trigger**: When the document describes a workflow, a sequence of events, user interactions, or data flow.
20
- - **Diagram Type Selection**:
21
- - **Flowchart**: Use for step-by-step processes, algorithms, or decision-making logic.
22
- - **Sequence Diagram**: Use for time-ordered interactions between different components or actors (e.g., API calls).
23
- 2. Constraints and Best Practices
24
- - **Quantity Limit**: Generate a maximum of **three** diagrams per document.
25
- - **Relevance**: Ensure every diagram **directly** illustrates a concept explained in the surrounding text. Avoid generating diagrams for simple concepts that are easily understood through text alone.
2
+
3
+ You must analyze the provided inputs to determine if a diagram is needed and where to insert a placeholder. You must not generate the diagram itself (e.g., no Mermaid, PlantUML, or other code). You are only deciding and placing the placeholder.
4
+
5
+ ## Inputs
6
+
7
+ - `<document_content>`: The main body of text to be evaluated.
8
+ - `<previous_generation_content>`: The content from the previous run, which may contain DIAGRAM_PLACEHOLDER.
9
+ - `<feedback>`: Specific user instructions for this run (e.g., "add a diagram," "remove the diagram").
10
+ - `<content_review_feedback>`: General automated or human feedback on the content.
11
+
12
+ ## Scoring conditions
13
+
14
+ - `add`: If `<feedback>` explicitly requests to add a diagram, ignore other conditions, +30000
15
+ - `remove`: If `<feedback>` explicitly requests to remove a diagram, ignore other conditions, -30000
16
+ - `previous-exists`: If `<previous_generation_content>` contains diagram, +21000
17
+ - `path-exclude`: If the document path or filename matches excluded patterns (e.g., `/faq/`, `CHANGELOG`, `release-notes`), -10000
18
+ - `less-words`: If document length <= 200 words AND less than 2 headings, -10000
19
+ - `overview`: If `<document_content>` provides a high-level overview, +3
20
+ - `architectural`: If `<document_content>` contains an architectural description (components/services/layers/modules), +3
21
+ - `workflow`: If `<document_content>` describes a workflow, sequence, user interactions, or data flow, +2
22
+ - `hierarchy`: If `<document_content>` describes a clear hierarchy (linked sub-docs / deeply nested sections), +1
23
+ - `introductory-major`: If `<document_content>` is an introductory page for a major section, +1
24
+
25
+ ## Output Requirements
26
+ - `details` is an array. Each element must include:
27
+ - `type`: matched scoring condition's type name
28
+ - `score`: matched scoring condition's score
29
+ - `reason`: text explaining why this scoring condition is matched
30
+ - `content`: `<document_content>` with placeholder inserted
31
+ - Identify the most logical insertion point in the `<document_content>`. (This is often after an introductory paragraph or before a list/section that the diagram will explain).
32
+ - Insert the exact placeholder string: DIAGRAM_PLACEHOLDER
33
+ - Crucially: Adjust the surrounding text to integrate the placeholder smoothly. Add a lead-in sentence.
34
+ - Good example: "The following diagram illustrates this data flow:"
35
+ - Good example: "This architecture is shown in the overview below:"
36
+ - Bad example: (Just inserting the placeholder with no context).
37
+ - Return the modified document content.
38
+ - Keep the original structure of the document, including page headings and hierarchy
39
+ - Only modify parts of the document text to improve the alignment between diagrams and their context
40
+ - The output must not include the `document_content` tag
41
+ - Do not provide any explanations; include only the document content itself
42
+
26
43
  </diagram_generation_rules>
44
+
@@ -12,26 +12,6 @@ Generate a d2 diagram that represents the following document content:
12
12
 
13
13
  </user_rules>
14
14
 
15
- <diagram_rules>
16
-
17
- 1. Diagram Triggers and Types: Select the most appropriate type when describing the following specific content
18
- - Architecture Diagram (High-Level)
19
- - **Trigger**: When the document provides a high-level overview of a system, project, or the overall documentation set.
20
- - **Content**: Must illustrate the main components, their relationships, and the overall structure.
21
- - Structural Diagram (Module-Level)
22
- - **Trigger**: When generating the introductory document for a major section or module.
23
- - **Content**: Must show the key sub-components, files, or core concepts within that specific module.
24
- - Process and Interaction Diagrams (Detailed)
25
- - **Trigger**: When the document describes a workflow, a sequence of events, user interactions, or data flow.
26
- - **Diagram Type Selection**:
27
- - **Flowchart**: Use for step-by-step processes, algorithms, or decision-making logic.
28
- - **Sequence Diagram**: Use for time-ordered interactions between different components or actors (e.g., API calls).
29
- 2. Constraints and Best Practices
30
- - **Keep it Simple**: Avoid overcomplicating the diagram.
31
- - **Relevance**: Ensure every diagram **directly** illustrates a concept explained in the surrounding text. Avoid generating diagrams for simple concepts that are easily understood through text alone.
32
-
33
- </diagram_rules>
34
-
35
15
  <document_content>
36
16
  {{documentContent}}
37
17
  </document_content>
@@ -37,14 +37,14 @@ Glossary of specialized terms. Please ensure correct spelling when using these t
37
37
  Documentation content generation rules:
38
38
  {% include "./document-rules.md" %}
39
39
 
40
- Custom component generation rules:
41
- {% include "../custom/custom-components.md" %}
40
+ {% include "../custom/custom-components-usage-rules.md" %}
42
41
 
43
42
  Custom code block generation rules:
44
43
  {% include "../custom/custom-code-block.md" %}
45
44
 
46
45
  {% include "../../common/document/media-file-list-usage-rules.md" %}
47
46
 
47
+
48
48
  </content_generation_rules>
49
49
 
50
50
 
@@ -7,12 +7,7 @@
7
7
 
8
8
  ** Output content in {{ locale }} language. **
9
9
 
10
- ** Don't generate any diagram in the document, give boolean value in `needDiagram` field & plan a placeholder in document content for diagram (use `DIAGRAM_PLACEHOLDER` as placeholder text). **
11
- - Use the current `<detail_data_source>`, `<content_review_feedback>`, and `<feedback>` to decide whether this document requires a diagram.
12
- - If `<feedback>` contains a request to add a diagram, set `needDiagram` to true.
13
- - If `<feedback>` contains a request to remove a diagram, set `needDiagram` to false.
14
10
 
15
- - **Necessary**: Generate diagrams only when necessary.
16
11
  </user_rules>
17
12
 
18
13
  {% set operation_type = "generating" %}
@@ -32,14 +32,15 @@ Glossary of specialized terms. Please ensure correct spelling when using these t
32
32
  Documentation content optimization rules:
33
33
  {% include "../generate/document-rules.md" %}
34
34
 
35
- Custom component optimization rules:
36
- {% include "../custom/custom-components.md" %}
35
+ {% include "../custom/custom-components-usage-rules.md" %}
37
36
 
38
37
  Custom code block optimization rules:
39
38
  {% include "../custom/custom-code-block.md" %}
40
39
 
41
40
  {% include "../../common/document/media-file-list-usage-rules.md" %}
42
41
 
42
+ {% include "../d2-diagram/rules.md" %}
43
+
43
44
  </content_optimization_rules>
44
45
 
45
46
 
@@ -11,9 +11,9 @@
11
11
  {% set operation_type = "optimizing" %}
12
12
  {% include "../../common/document/user-preferences.md" %}
13
13
 
14
- <original_page_content>
14
+ <original_document_content>
15
15
  {{originalContent}}
16
- </original_page_content>
16
+ </original_document_content>
17
17
 
18
18
  {% if needDataSources %}
19
19
  <detail_data_source>