@aigne/doc-smith 0.9.8-alpha.2 → 0.9.8-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +43 -0
- package/README.md +94 -250
- package/aigne.yaml +2 -149
- package/doc-smith/SKILL.md +117 -0
- package/doc-smith/references/changeset_schema.md +118 -0
- package/doc-smith/references/document_structure_schema.md +139 -0
- package/doc-smith/references/document_update_guide.md +193 -0
- package/doc-smith/references/structure_confirmation_guide.md +133 -0
- package/doc-smith/references/structure_planning_guide.md +146 -0
- package/doc-smith/references/user_intent_guide.md +172 -0
- package/doc-smith.yaml +114 -0
- package/main-system-prompt.md +56 -0
- package/package.json +3 -69
- package/scripts/README.md +90 -0
- package/scripts/install.sh +86 -0
- package/scripts/uninstall.sh +52 -0
- package/CHANGELOG.md +0 -994
- package/LICENSE +0 -93
- package/agentic-agents/common/base-info.md +0 -53
- package/agentic-agents/common/planner.md +0 -168
- package/agentic-agents/common/worker.md +0 -93
- package/agentic-agents/create/index.yaml +0 -118
- package/agentic-agents/create/objective.md +0 -44
- package/agentic-agents/create/set-custom-prompt.mjs +0 -27
- package/agentic-agents/detail/index.yaml +0 -95
- package/agentic-agents/detail/objective.md +0 -9
- package/agentic-agents/detail/set-custom-prompt.mjs +0 -88
- package/agentic-agents/predict-resources/index.yaml +0 -44
- package/agentic-agents/predict-resources/instructions.md +0 -61
- package/agentic-agents/structure/design-rules.md +0 -39
- package/agentic-agents/structure/index.yaml +0 -86
- package/agentic-agents/structure/objective.md +0 -14
- package/agentic-agents/structure/review-criteria.md +0 -55
- package/agentic-agents/structure/set-custom-prompt.mjs +0 -78
- package/agentic-agents/utils/init-workspace-cache.mjs +0 -171
- package/agentic-agents/utils/load-base-sources.mjs +0 -20
- package/agentic-agents/workspace-cache-sharing-design.md +0 -671
- package/agents/chat/chat-system.md +0 -38
- package/agents/chat/index.mjs +0 -59
- package/agents/chat/skills/generate-document.yaml +0 -15
- package/agents/chat/skills/list-documents.mjs +0 -15
- package/agents/chat/skills/update-document.yaml +0 -24
- package/agents/clear/choose-contents.mjs +0 -192
- package/agents/clear/clear-auth-tokens.mjs +0 -88
- package/agents/clear/clear-deployment-config.mjs +0 -49
- package/agents/clear/clear-document-config.mjs +0 -36
- package/agents/clear/clear-document-structure.mjs +0 -102
- package/agents/clear/clear-generated-docs.mjs +0 -142
- package/agents/clear/clear-media-description.mjs +0 -129
- package/agents/clear/index.yaml +0 -26
- package/agents/create/analyze-diagram-type-llm.yaml +0 -160
- package/agents/create/analyze-diagram-type.mjs +0 -297
- package/agents/create/check-document-structure.yaml +0 -30
- package/agents/create/check-need-generate-structure.mjs +0 -105
- package/agents/create/document-structure-tools/add-document.mjs +0 -85
- package/agents/create/document-structure-tools/delete-document.mjs +0 -116
- package/agents/create/document-structure-tools/move-document.mjs +0 -109
- package/agents/create/document-structure-tools/update-document.mjs +0 -84
- package/agents/create/generate-diagram-image.yaml +0 -60
- package/agents/create/generate-structure.yaml +0 -117
- package/agents/create/index.yaml +0 -49
- package/agents/create/refine-document-structure.yaml +0 -12
- package/agents/create/replace-d2-with-image.mjs +0 -625
- package/agents/create/update-document-structure.yaml +0 -54
- package/agents/create/user-add-document/add-documents-to-structure.mjs +0 -90
- package/agents/create/user-add-document/find-documents-to-add-links.yaml +0 -47
- package/agents/create/user-add-document/index.yaml +0 -46
- package/agents/create/user-add-document/prepare-documents-to-translate.mjs +0 -22
- package/agents/create/user-add-document/print-add-document-summary.mjs +0 -63
- package/agents/create/user-add-document/review-documents-with-new-links.mjs +0 -110
- package/agents/create/user-remove-document/find-documents-with-invalid-links.mjs +0 -78
- package/agents/create/user-remove-document/index.yaml +0 -40
- package/agents/create/user-remove-document/prepare-documents-to-translate.mjs +0 -22
- package/agents/create/user-remove-document/print-remove-document-summary.mjs +0 -53
- package/agents/create/user-remove-document/remove-documents-from-structure.mjs +0 -99
- package/agents/create/user-remove-document/review-documents-with-invalid-links.mjs +0 -115
- package/agents/create/user-review-document-structure.mjs +0 -140
- package/agents/create/utils/init-current-content.mjs +0 -34
- package/agents/create/utils/merge-document-structures.mjs +0 -30
- package/agents/evaluate/code-snippet.mjs +0 -97
- package/agents/evaluate/document-structure.yaml +0 -67
- package/agents/evaluate/document.yaml +0 -82
- package/agents/evaluate/generate-report.mjs +0 -85
- package/agents/evaluate/index.yaml +0 -46
- package/agents/history/index.yaml +0 -6
- package/agents/history/view.mjs +0 -78
- package/agents/init/check.mjs +0 -16
- package/agents/init/index.mjs +0 -275
- package/agents/init/validate.mjs +0 -16
- package/agents/localize/choose-language.mjs +0 -107
- package/agents/localize/index.yaml +0 -58
- package/agents/localize/record-translation-history.mjs +0 -23
- package/agents/localize/translate-document.yaml +0 -24
- package/agents/localize/translate-multilingual.yaml +0 -51
- package/agents/media/batch-generate-media-description.yaml +0 -46
- package/agents/media/generate-media-description.yaml +0 -50
- package/agents/media/load-media-description.mjs +0 -256
- package/agents/prefs/index.mjs +0 -203
- package/agents/publish/index.yaml +0 -26
- package/agents/publish/publish-docs.mjs +0 -356
- package/agents/publish/translate-meta.mjs +0 -103
- package/agents/schema/document-structure-item.yaml +0 -26
- package/agents/schema/document-structure-refine-item.yaml +0 -23
- package/agents/schema/document-structure.yaml +0 -29
- package/agents/update/batch-generate-document.yaml +0 -27
- package/agents/update/batch-update-document.yaml +0 -7
- package/agents/update/check-diagram-flag.mjs +0 -116
- package/agents/update/check-document.mjs +0 -162
- package/agents/update/check-generate-diagram.mjs +0 -106
- package/agents/update/check-sync-image-flag.mjs +0 -55
- package/agents/update/check-update-is-single.mjs +0 -53
- package/agents/update/document-tools/update-document-content.mjs +0 -303
- package/agents/update/generate-diagram.yaml +0 -63
- package/agents/update/generate-document.yaml +0 -70
- package/agents/update/handle-document-update.yaml +0 -103
- package/agents/update/index.yaml +0 -79
- package/agents/update/pre-check-generate-diagram.yaml +0 -44
- package/agents/update/save-and-translate-document.mjs +0 -76
- package/agents/update/sync-images-and-exit.mjs +0 -148
- package/agents/update/update-document-detail.yaml +0 -71
- package/agents/update/update-single/update-single-document-detail.mjs +0 -280
- package/agents/update/update-single-document.yaml +0 -7
- package/agents/update/user-review-document.mjs +0 -272
- package/agents/utils/action-success.mjs +0 -16
- package/agents/utils/analyze-document-feedback-intent.yaml +0 -32
- package/agents/utils/analyze-feedback-intent.mjs +0 -136
- package/agents/utils/analyze-structure-feedback-intent.yaml +0 -29
- package/agents/utils/check-detail-result.mjs +0 -38
- package/agents/utils/check-feedback-refiner.mjs +0 -81
- package/agents/utils/choose-docs.mjs +0 -293
- package/agents/utils/document-icon-generate.yaml +0 -52
- package/agents/utils/document-title-streamline.yaml +0 -48
- package/agents/utils/ensure-document-icons.mjs +0 -129
- package/agents/utils/exit.mjs +0 -6
- package/agents/utils/feedback-refiner.yaml +0 -50
- package/agents/utils/find-item-by-path.mjs +0 -114
- package/agents/utils/find-user-preferences-by-path.mjs +0 -37
- package/agents/utils/format-document-structure.mjs +0 -35
- package/agents/utils/generate-document-or-skip.mjs +0 -41
- package/agents/utils/handle-diagram-operations.mjs +0 -263
- package/agents/utils/load-all-document-content.mjs +0 -30
- package/agents/utils/load-document-all-content.mjs +0 -84
- package/agents/utils/load-sources.mjs +0 -405
- package/agents/utils/map-reasoning-effort-level.mjs +0 -15
- package/agents/utils/post-generate.mjs +0 -144
- package/agents/utils/read-current-document-content.mjs +0 -46
- package/agents/utils/save-doc-translation.mjs +0 -61
- package/agents/utils/save-doc.mjs +0 -88
- package/agents/utils/save-output.mjs +0 -26
- package/agents/utils/save-sidebar.mjs +0 -51
- package/agents/utils/skip-if-content-exists.mjs +0 -27
- package/agents/utils/streamline-document-titles-if-needed.mjs +0 -88
- package/agents/utils/transform-detail-data-sources.mjs +0 -45
- package/agents/utils/update-branding.mjs +0 -84
- package/assets/report-template/report.html +0 -198
- package/docs-mcp/analyze-content-relevance.yaml +0 -50
- package/docs-mcp/analyze-docs-relevance.yaml +0 -59
- package/docs-mcp/docs-search.yaml +0 -42
- package/docs-mcp/get-docs-detail.mjs +0 -41
- package/docs-mcp/get-docs-structure.mjs +0 -16
- package/docs-mcp/read-doc-content.mjs +0 -119
- package/prompts/common/document/content-rules-core.md +0 -20
- package/prompts/common/document/markdown-syntax-rules.md +0 -65
- package/prompts/common/document/media-file-list-usage-rules.md +0 -18
- package/prompts/common/document/openapi-usage-rules.md +0 -189
- package/prompts/common/document/role-and-personality.md +0 -16
- package/prompts/common/document/user-preferences.md +0 -9
- package/prompts/common/document-structure/conflict-resolution-guidance.md +0 -16
- package/prompts/common/document-structure/document-icon-generate.md +0 -116
- package/prompts/common/document-structure/document-structure-rules.md +0 -43
- package/prompts/common/document-structure/document-title-streamline.md +0 -86
- package/prompts/common/document-structure/glossary.md +0 -7
- package/prompts/common/document-structure/intj-traits.md +0 -5
- package/prompts/common/document-structure/openapi-usage-rules.md +0 -28
- package/prompts/common/document-structure/output-constraints.md +0 -18
- package/prompts/common/document-structure/user-locale-rules.md +0 -10
- package/prompts/common/document-structure/user-preferences.md +0 -9
- package/prompts/detail/custom/admonition-usage-rules.md +0 -94
- package/prompts/detail/custom/code-block-usage-rules.md +0 -163
- package/prompts/detail/custom/custom-components/x-card-usage-rules.md +0 -63
- package/prompts/detail/custom/custom-components/x-cards-usage-rules.md +0 -83
- package/prompts/detail/custom/custom-components/x-field-desc-usage-rules.md +0 -120
- package/prompts/detail/custom/custom-components/x-field-group-usage-rules.md +0 -80
- package/prompts/detail/custom/custom-components/x-field-usage-rules.md +0 -189
- package/prompts/detail/custom/custom-components-usage-rules.md +0 -18
- package/prompts/detail/diagram/generate-image-system.md +0 -135
- package/prompts/detail/diagram/generate-image-user.md +0 -32
- package/prompts/detail/diagram/guide.md +0 -29
- package/prompts/detail/diagram/official-examples.md +0 -712
- package/prompts/detail/diagram/pre-check.md +0 -23
- package/prompts/detail/diagram/role-and-personality.md +0 -2
- package/prompts/detail/diagram/rules.md +0 -46
- package/prompts/detail/diagram/system-prompt.md +0 -1139
- package/prompts/detail/diagram/user-prompt.md +0 -43
- package/prompts/detail/generate/detail-example.md +0 -457
- package/prompts/detail/generate/document-rules.md +0 -45
- package/prompts/detail/generate/system-prompt.md +0 -61
- package/prompts/detail/generate/user-prompt.md +0 -99
- package/prompts/detail/jsx/rules.md +0 -6
- package/prompts/detail/update/system-prompt.md +0 -121
- package/prompts/detail/update/user-prompt.md +0 -41
- package/prompts/evaluate/document-structure.md +0 -93
- package/prompts/evaluate/document.md +0 -149
- package/prompts/media/media-description/system-prompt.md +0 -43
- package/prompts/media/media-description/user-prompt.md +0 -17
- package/prompts/structure/check-document-structure.md +0 -93
- package/prompts/structure/document-rules.md +0 -21
- package/prompts/structure/find-documents-to-add-links.md +0 -52
- package/prompts/structure/generate/system-prompt.md +0 -13
- package/prompts/structure/generate/user-prompt.md +0 -137
- package/prompts/structure/review/structure-review-system.md +0 -81
- package/prompts/structure/structure-example.md +0 -89
- package/prompts/structure/structure-getting-started.md +0 -10
- package/prompts/structure/update/system-prompt.md +0 -93
- package/prompts/structure/update/user-prompt.md +0 -43
- package/prompts/translate/admonition.md +0 -20
- package/prompts/translate/code-block.md +0 -33
- package/prompts/translate/glossary.md +0 -6
- package/prompts/translate/translate-document.md +0 -305
- package/prompts/utils/analyze-document-feedback-intent.md +0 -54
- package/prompts/utils/analyze-structure-feedback-intent.md +0 -43
- package/prompts/utils/feedback-refiner.md +0 -105
- package/types/document-schema.mjs +0 -55
- package/types/document-structure-schema.mjs +0 -261
- package/utils/auth-utils.mjs +0 -275
- package/utils/blocklet.mjs +0 -104
- package/utils/check-document-has-diagram.mjs +0 -95
- package/utils/conflict-detector.mjs +0 -149
- package/utils/constants/index.mjs +0 -620
- package/utils/constants/linter.mjs +0 -102
- package/utils/d2-utils.mjs +0 -198
- package/utils/debug.mjs +0 -3
- package/utils/delete-diagram-images.mjs +0 -99
- package/utils/deploy.mjs +0 -86
- package/utils/docs-finder-utils.mjs +0 -623
- package/utils/evaluate/report-utils.mjs +0 -132
- package/utils/extract-api.mjs +0 -32
- package/utils/file-utils.mjs +0 -960
- package/utils/history-utils.mjs +0 -203
- package/utils/icon-map.mjs +0 -26
- package/utils/image-compress.mjs +0 -75
- package/utils/kroki-utils.mjs +0 -173
- package/utils/linter/index.mjs +0 -50
- package/utils/load-config.mjs +0 -107
- package/utils/markdown/index.mjs +0 -26
- package/utils/markdown-checker.mjs +0 -694
- package/utils/mermaid-validator.mjs +0 -140
- package/utils/mermaid-worker-pool.mjs +0 -250
- package/utils/mermaid-worker.mjs +0 -233
- package/utils/openapi/index.mjs +0 -28
- package/utils/preferences-utils.mjs +0 -175
- package/utils/request.mjs +0 -10
- package/utils/store/index.mjs +0 -45
- package/utils/sync-diagram-to-translations.mjs +0 -262
- package/utils/upload-files.mjs +0 -231
- package/utils/utils.mjs +0 -1354
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { AIAgent } from "@aigne/core";
|
|
2
|
-
import { pick } from "@aigne/core/utils/type-utils.js";
|
|
3
|
-
import z from "zod";
|
|
4
|
-
import {
|
|
5
|
-
DIAGRAM_PLACEHOLDER,
|
|
6
|
-
replaceD2WithPlaceholder,
|
|
7
|
-
replaceDiagramsWithPlaceholder,
|
|
8
|
-
} from "../../../utils/d2-utils.mjs";
|
|
9
|
-
import { userContextAt } from "../../../utils/utils.mjs";
|
|
10
|
-
|
|
11
|
-
async function getIntentType(input, options) {
|
|
12
|
-
const instructions = `<role>
|
|
13
|
-
You are a feedback intent analyzer. Your task is to determine which type of content modifications are needed based on the user's feedback.
|
|
14
|
-
|
|
15
|
-
You must analyze the user's feedback and classify it into one of the following intent types:
|
|
16
|
-
- addDiagram: User wants to add a new diagram/image/chart
|
|
17
|
-
- deleteDiagram: User wants to remove/delete a diagram/image/chart
|
|
18
|
-
- updateDiagram: User wants to modify/update an existing diagram/image/chart
|
|
19
|
-
- updateDocument: User wants to update document content (text, sections, etc.) without diagram operations
|
|
20
|
-
</role>
|
|
21
|
-
|
|
22
|
-
<intent_classification_rules>
|
|
23
|
-
**deleteDiagram** - Use this when user explicitly wants to remove or delete a diagram/image/chart:
|
|
24
|
-
- Keywords: remove, delete, 删除, 移除, 去掉, 清除
|
|
25
|
-
- Combined with: diagram, image, picture, chart, graph, 图表, 图片, 图, 架构图
|
|
26
|
-
- Examples:
|
|
27
|
-
- "Remove the diagram"
|
|
28
|
-
- "Delete the image"
|
|
29
|
-
- "删除这张图片"
|
|
30
|
-
- "Remove the second diagram"
|
|
31
|
-
- "去掉架构图"
|
|
32
|
-
- "Remove image from page 3"
|
|
33
|
-
- "Delete the chart showing the flow"
|
|
34
|
-
|
|
35
|
-
**addDiagram** - Use this when user wants to add a new diagram:
|
|
36
|
-
- Keywords: add, create, insert, 添加, 创建, 插入
|
|
37
|
-
- Combined with: diagram, image, picture, chart, graph, 图表, 图片, 图
|
|
38
|
-
- Examples:
|
|
39
|
-
- "Add a diagram showing the architecture"
|
|
40
|
-
- "Create a flow chart"
|
|
41
|
-
- "添加一个架构图"
|
|
42
|
-
|
|
43
|
-
**updateDiagram** - Use this when user wants to modify an existing diagram:
|
|
44
|
-
- Keywords: update, modify, change, improve, 更新, 修改, 改进
|
|
45
|
-
- Combined with: diagram, image, picture, chart, graph, 图表, 图片, 图
|
|
46
|
-
- Examples:
|
|
47
|
-
- "Update the diagram to show the new process"
|
|
48
|
-
- "Modify the chart to include more details"
|
|
49
|
-
- "更新架构图"
|
|
50
|
-
|
|
51
|
-
**updateDocument** - Use this for all other content modifications:
|
|
52
|
-
- Text changes, section updates, content improvements
|
|
53
|
-
- No mention of diagrams/images/charts
|
|
54
|
-
- Examples:
|
|
55
|
-
- "Update the introduction section"
|
|
56
|
-
- "Fix the typo in paragraph 2"
|
|
57
|
-
- "Improve the explanation"
|
|
58
|
-
</intent_classification_rules>
|
|
59
|
-
|
|
60
|
-
<user_feedback>
|
|
61
|
-
{{feedback}}
|
|
62
|
-
</user_feedback>
|
|
63
|
-
|
|
64
|
-
<analysis_guidelines>
|
|
65
|
-
1. Pay close attention to action verbs (remove, delete, add, update, etc.)
|
|
66
|
-
2. Identify the target object (diagram, image, chart, or general content)
|
|
67
|
-
3. If feedback mentions removing/deleting a diagram/image/chart → deleteDiagram
|
|
68
|
-
4. If feedback mentions adding a diagram/image/chart → addDiagram
|
|
69
|
-
5. If feedback mentions updating a diagram/image/chart → updateDiagram
|
|
70
|
-
6. If feedback is about general content without diagram references → updateDocument
|
|
71
|
-
7. When in doubt, prioritize the most explicit action mentioned in the feedback
|
|
72
|
-
</analysis_guidelines>`;
|
|
73
|
-
const analyzeUpdateFeedbackIntentAgent = AIAgent.from({
|
|
74
|
-
name: "analyzeUpdateFeedbackIntent",
|
|
75
|
-
description:
|
|
76
|
-
"Analyze user feedback to determine if document are needed for content modifications",
|
|
77
|
-
task_render_mode: "hide",
|
|
78
|
-
instructions,
|
|
79
|
-
// TODO: can't set reasoningEffort
|
|
80
|
-
// modelOptions: {
|
|
81
|
-
// reasoningEffort: 1,
|
|
82
|
-
// },
|
|
83
|
-
inputSchema: z.object({
|
|
84
|
-
feedback: z.string().describe("User feedback for content modifications"),
|
|
85
|
-
}),
|
|
86
|
-
outputSchema: z.object({
|
|
87
|
-
intentType: z
|
|
88
|
-
.enum(["addDiagram", "deleteDiagram", "updateDiagram", "updateDocument"])
|
|
89
|
-
.describe(
|
|
90
|
-
"The primary type of user intention: one of addDiagram, deleteDiagram, updateDiagram, updateDocument",
|
|
91
|
-
),
|
|
92
|
-
}),
|
|
93
|
-
});
|
|
94
|
-
const { intentType } = await options.context.invoke(analyzeUpdateFeedbackIntentAgent, {
|
|
95
|
-
feedback: input.feedback,
|
|
96
|
-
});
|
|
97
|
-
return intentType;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async function saveDoc(input, options, { content, intentType }) {
|
|
101
|
-
const saveAgent = options.context?.agents?.["saveDoc"];
|
|
102
|
-
await options.context.invoke(saveAgent, {
|
|
103
|
-
...pick(input, ["path", "docsDir", "labels", "locale"]),
|
|
104
|
-
content,
|
|
105
|
-
intentType, // Pass intentType so saveDoc can handle translation sync
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async function addDiagram(input, options) {
|
|
110
|
-
const contentContext = userContextAt(options, `currentContents.${input.path}`);
|
|
111
|
-
const currentContent = contentContext.get();
|
|
112
|
-
const generateDiagramAgent = options.context.agents["checkGenerateDiagram"];
|
|
113
|
-
const generateDiagramResult = await options.context.invoke(generateDiagramAgent, {
|
|
114
|
-
...pick(input, ["locale", "path", "docsDir", "diagramming", "feedback"]),
|
|
115
|
-
documentContent: currentContent,
|
|
116
|
-
originalContent: currentContent,
|
|
117
|
-
});
|
|
118
|
-
const content = generateDiagramResult.content;
|
|
119
|
-
contentContext.set(content);
|
|
120
|
-
// Pass intentType to saveDoc so it can handle translation sync automatically
|
|
121
|
-
await saveDoc(input, options, { content, intentType: "addDiagram" });
|
|
122
|
-
return { content };
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function updateDiagram(input, options) {
|
|
126
|
-
const contentContext = userContextAt(options, `currentContents.${input.path}`);
|
|
127
|
-
const currentContent = contentContext.get();
|
|
128
|
-
let [content] = replaceD2WithPlaceholder({
|
|
129
|
-
content: currentContent,
|
|
130
|
-
});
|
|
131
|
-
const generateAgent = options.context?.agents?.["generateDiagram"];
|
|
132
|
-
const result = await options.context.invoke(generateAgent, {
|
|
133
|
-
documentContent: content,
|
|
134
|
-
locale: input.locale,
|
|
135
|
-
diagramming: input.diagramming || {},
|
|
136
|
-
feedback: input.feedback,
|
|
137
|
-
originalContent: currentContent, // Pass original content to find existing diagrams
|
|
138
|
-
path: input.path,
|
|
139
|
-
docsDir: input.docsDir,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// generateDiagram now returns { content } with image already inserted
|
|
143
|
-
// The image replaces DIAGRAM_PLACEHOLDER or D2 code blocks
|
|
144
|
-
if (result?.content) {
|
|
145
|
-
content = result.content;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
contentContext.set(content);
|
|
149
|
-
// Pass intentType to saveDoc so it can handle translation sync automatically
|
|
150
|
-
await saveDoc(input, options, { content, intentType: "updateDiagram" });
|
|
151
|
-
return { content };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async function deleteDiagram(input, options) {
|
|
155
|
-
const contentContext = userContextAt(options, `currentContents.${input.path}`);
|
|
156
|
-
const currentContent = contentContext.get();
|
|
157
|
-
|
|
158
|
-
// Extract diagram index from feedback if provided
|
|
159
|
-
// This allows deleting a specific diagram when multiple diagrams exist
|
|
160
|
-
let diagramIndex = input.diagramIndex;
|
|
161
|
-
if (diagramIndex === undefined && input.feedback) {
|
|
162
|
-
// Import extractDiagramIndexFromFeedback from replace-d2-with-image.mjs
|
|
163
|
-
const { extractDiagramIndexFromFeedback } = await import(
|
|
164
|
-
"../../create/replace-d2-with-image.mjs"
|
|
165
|
-
);
|
|
166
|
-
const extractedIndex = extractDiagramIndexFromFeedback(input.feedback);
|
|
167
|
-
if (extractedIndex !== null) {
|
|
168
|
-
diagramIndex = extractedIndex;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Replace all diagrams (D2 code blocks, generated images, Mermaid) with placeholder
|
|
173
|
-
// If diagramIndex is provided, only replace that specific diagram
|
|
174
|
-
// This ensures LLM can identify and remove the diagram regardless of its type
|
|
175
|
-
const documentContent = replaceDiagramsWithPlaceholder({
|
|
176
|
-
content: currentContent,
|
|
177
|
-
diagramIndex,
|
|
178
|
-
});
|
|
179
|
-
const instructions = `<role>
|
|
180
|
-
Your task is to remove ${DIAGRAM_PLACEHOLDER} and adjust the document context (based on the user's feedback) to make it easier to understand.
|
|
181
|
-
</role>
|
|
182
|
-
|
|
183
|
-
<document_content>
|
|
184
|
-
{{documentContent}}
|
|
185
|
-
</document_content>
|
|
186
|
-
|
|
187
|
-
<user_feedback>
|
|
188
|
-
{{feedback}}
|
|
189
|
-
</user_feedback>
|
|
190
|
-
|
|
191
|
-
<output_constraints>
|
|
192
|
-
- Do not provide any explanations; include only the document content itself
|
|
193
|
-
</output_constraints>`;
|
|
194
|
-
const deleteAgent = AIAgent.from({
|
|
195
|
-
name: "deleteDiagram",
|
|
196
|
-
description: "Remove a diagram from the document content",
|
|
197
|
-
task_render_mode: "hide",
|
|
198
|
-
instructions,
|
|
199
|
-
inputSchema: z.object({
|
|
200
|
-
documentContent: z.string().describe("Source content of the document"),
|
|
201
|
-
feedback: z.string().describe("User feedback for content modifications"),
|
|
202
|
-
}),
|
|
203
|
-
outputKey: "message",
|
|
204
|
-
});
|
|
205
|
-
const { message: content } = await options.context.invoke(deleteAgent, {
|
|
206
|
-
documentContent,
|
|
207
|
-
feedback: input.feedback,
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
// Delete associated diagram image files
|
|
211
|
-
if (input.docsDir) {
|
|
212
|
-
try {
|
|
213
|
-
const { deleteDiagramImages } = await import("../../../utils/delete-diagram-images.mjs");
|
|
214
|
-
const { deleted } = await deleteDiagramImages(currentContent, input.path, input.docsDir);
|
|
215
|
-
if (deleted > 0) {
|
|
216
|
-
console.log(`Deleted ${deleted} diagram image file(s) for ${input.path}`);
|
|
217
|
-
}
|
|
218
|
-
} catch (error) {
|
|
219
|
-
// Don't fail the operation if image deletion fails
|
|
220
|
-
console.warn(`Failed to delete diagram images: ${error.message}`);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
contentContext.set(content);
|
|
225
|
-
// Pass intentType to saveDoc so it can handle translation sync automatically
|
|
226
|
-
await saveDoc(input, options, { content, intentType: "deleteDiagram" });
|
|
227
|
-
|
|
228
|
-
return { content };
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
async function updateDocument(input, options) {
|
|
232
|
-
const contentContext = userContextAt(options, `currentContents.${input.path}`);
|
|
233
|
-
const currentContent = contentContext.get();
|
|
234
|
-
const updateAgent = options.context.agents["updateDocumentDetail"];
|
|
235
|
-
const updateResult = await options.context.invoke(updateAgent, {
|
|
236
|
-
...input,
|
|
237
|
-
originalContent: currentContent,
|
|
238
|
-
});
|
|
239
|
-
if (updateResult.message === "success") {
|
|
240
|
-
const updatedContent = contentContext.get();
|
|
241
|
-
|
|
242
|
-
contentContext.set(updatedContent);
|
|
243
|
-
await saveDoc(input, options, { content: updatedContent });
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
content: contentContext.get(),
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export default async function updateSingleDocumentDetail(input, options) {
|
|
251
|
-
// Use intentType from input if available (analyzed in parent flow),
|
|
252
|
-
// otherwise fall back to analyzing it here (for backward compatibility)
|
|
253
|
-
let intentType = input.intentType;
|
|
254
|
-
if (!intentType && input.feedback) {
|
|
255
|
-
intentType = await getIntentType(input, options);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// If intentType is still null or undefined, default to updateDocument
|
|
259
|
-
// This ensures that some operation is always performed, even if intent analysis failed
|
|
260
|
-
// or no explicit intent was provided
|
|
261
|
-
if (!intentType) {
|
|
262
|
-
intentType = "updateDocument";
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const fnMap = {
|
|
266
|
-
addDiagram,
|
|
267
|
-
updateDiagram,
|
|
268
|
-
deleteDiagram,
|
|
269
|
-
updateDocument,
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
if (fnMap[intentType]) {
|
|
273
|
-
const result = await fnMap[intentType](input, options);
|
|
274
|
-
return result;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// Fallback: if intentType is not in fnMap, default to updateDocument
|
|
278
|
-
console.warn(`Unknown intentType: ${intentType}, defaulting to updateDocument`);
|
|
279
|
-
return await updateDocument(input, options);
|
|
280
|
-
}
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { marked } from "marked";
|
|
2
|
-
import markedTerminal from "marked-terminal";
|
|
3
|
-
import { getActiveRulesForScope } from "../../utils/preferences-utils.mjs";
|
|
4
|
-
import { userContextAt } from "../../utils/utils.mjs";
|
|
5
|
-
|
|
6
|
-
function extractMarkdownHeadings(content) {
|
|
7
|
-
if (!content || typeof content !== "string") {
|
|
8
|
-
return [];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const headings = [];
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
// Use marked's lexer to tokenize the content
|
|
15
|
-
const tokens = marked.lexer(content);
|
|
16
|
-
|
|
17
|
-
// Extract heading tokens
|
|
18
|
-
function processTokens(tokenArray) {
|
|
19
|
-
for (const token of tokenArray) {
|
|
20
|
-
if (token.type === "heading") {
|
|
21
|
-
headings.push({
|
|
22
|
-
level: token.depth,
|
|
23
|
-
text: token.text.trim(),
|
|
24
|
-
prefix: " ".repeat(token.depth - 1) + "📄".repeat(1),
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
// Process nested tokens if they exist (for lists, block quotes, etc.)
|
|
28
|
-
if (token.tokens) {
|
|
29
|
-
processTokens(token.tokens);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
processTokens(tokens);
|
|
35
|
-
} catch (error) {
|
|
36
|
-
// If marked fails, fall back to regex but log the issue
|
|
37
|
-
console.warn(
|
|
38
|
-
"Failed to parse markdown with marked library, falling back to regex:",
|
|
39
|
-
error.message,
|
|
40
|
-
);
|
|
41
|
-
return extractMarkdownHeadingsFallback(content);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return headings;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Fallback function using the original regex approach
|
|
48
|
-
function extractMarkdownHeadingsFallback(content) {
|
|
49
|
-
const lines = content.split("\n");
|
|
50
|
-
const headings = [];
|
|
51
|
-
|
|
52
|
-
for (const line of lines) {
|
|
53
|
-
const match = line.match(/^(#{1,6})\s+(.+)$/);
|
|
54
|
-
if (match) {
|
|
55
|
-
const level = match[1].length;
|
|
56
|
-
const text = match[2].trim();
|
|
57
|
-
headings.push({
|
|
58
|
-
level,
|
|
59
|
-
text,
|
|
60
|
-
prefix: " ".repeat(level - 1) + "📄".repeat(1),
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return headings;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function printDocumentHeadings(content, title) {
|
|
69
|
-
console.log(`\n ${"-".repeat(50)}`);
|
|
70
|
-
console.log(` Current Document: ${title}`);
|
|
71
|
-
console.log(` ${"-".repeat(50)}`);
|
|
72
|
-
|
|
73
|
-
const headings = extractMarkdownHeadings(content);
|
|
74
|
-
|
|
75
|
-
if (headings.length === 0) {
|
|
76
|
-
console.log(" This document has no headings.");
|
|
77
|
-
} else {
|
|
78
|
-
headings.forEach((heading) => {
|
|
79
|
-
console.log(`${heading.prefix} ${heading.text} (H${heading.level})`);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
console.log();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async function showDocumentDetail(content, title) {
|
|
86
|
-
if (!content || typeof content !== "string" || content.trim().length === 0) {
|
|
87
|
-
console.log("There's no content to display.");
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
// Temporarily suppress console.error to hide language warnings
|
|
93
|
-
const originalError = console.error;
|
|
94
|
-
console.error = (message) => {
|
|
95
|
-
// Only suppress cli-highlight language warnings
|
|
96
|
-
if (
|
|
97
|
-
typeof message === "string" &&
|
|
98
|
-
message.toLowerCase().includes("Could not find the language")
|
|
99
|
-
) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
originalError(message);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
marked.setOptions({
|
|
106
|
-
renderer: new markedTerminal(),
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// FIXME: @zhanghan fix error "Could not find the language 'd2', did you forget to load/include a language module?"
|
|
110
|
-
const renderedMarkdown = marked(content);
|
|
111
|
-
|
|
112
|
-
// Restore original console.error
|
|
113
|
-
console.error = originalError;
|
|
114
|
-
|
|
115
|
-
console.log(`\nDocument: ${title || "Untitled Document"}`);
|
|
116
|
-
console.log("=".repeat(50));
|
|
117
|
-
console.log(renderedMarkdown);
|
|
118
|
-
} catch (_error) {
|
|
119
|
-
console.log("\nFalling back to plain text display (marked-terminal not available):\n");
|
|
120
|
-
console.log(`Document: ${title || "Untitled Document"}`);
|
|
121
|
-
console.log("=".repeat(50));
|
|
122
|
-
console.log(content);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export default async function userReviewDocument({ content, description, ...rest }, options) {
|
|
127
|
-
// Check if document content exists
|
|
128
|
-
if (!content || typeof content !== "string" || content.trim().length === 0) {
|
|
129
|
-
console.log("Please provide document content to review.");
|
|
130
|
-
return { content };
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const title = rest.documentStructure?.find((x) => x.path === rest.path)?.title;
|
|
134
|
-
|
|
135
|
-
// Print current document headings structure
|
|
136
|
-
if (!rest.isChat) {
|
|
137
|
-
printDocumentHeadings(content, title || "Untitled Document");
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Initialize shared context with current content using path
|
|
141
|
-
const contentContext = userContextAt(options, `currentContents.${rest.path}`);
|
|
142
|
-
contentContext.set(content);
|
|
143
|
-
|
|
144
|
-
const MAX_ITERATIONS = 100;
|
|
145
|
-
const feedbacks = [];
|
|
146
|
-
let iterationCount = 0;
|
|
147
|
-
|
|
148
|
-
let feedback = "";
|
|
149
|
-
|
|
150
|
-
while (iterationCount < MAX_ITERATIONS) {
|
|
151
|
-
feedback = "";
|
|
152
|
-
iterationCount++;
|
|
153
|
-
|
|
154
|
-
if (rest.isChat && rest.feedback) {
|
|
155
|
-
feedback = rest.feedback;
|
|
156
|
-
} else {
|
|
157
|
-
// Ask user what they want to do
|
|
158
|
-
const action = await options.prompts.select({
|
|
159
|
-
message: "What would you like to do next?",
|
|
160
|
-
choices: [
|
|
161
|
-
{
|
|
162
|
-
name: "View document",
|
|
163
|
-
value: "view",
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
name: "Give feedback",
|
|
167
|
-
value: "feedback",
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
name: "Done",
|
|
171
|
-
value: "finish",
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
if (action === "finish") {
|
|
177
|
-
break;
|
|
178
|
-
} else if (action === "view") {
|
|
179
|
-
await showDocumentDetail(contentContext.get(), title || "Untitled Document");
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Ask for feedback
|
|
183
|
-
feedback = await options.prompts.input({
|
|
184
|
-
message:
|
|
185
|
-
"How would you like to improve this document?\n" +
|
|
186
|
-
"Examples:\n" +
|
|
187
|
-
" • Add troubleshooting section for common errors\n" +
|
|
188
|
-
" • Simplify the explanation for beginners\n" +
|
|
189
|
-
" • Remove the outdated information about version 1.0\n\n" +
|
|
190
|
-
" Your feedback:",
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
// If no feedback, finish the loop
|
|
194
|
-
if (!feedback?.trim()) {
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
feedbacks.push(feedback.trim());
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Get the updateDocument agent
|
|
202
|
-
const updateAgent = options.context.agents["updateSingleDocumentDetail"];
|
|
203
|
-
if (!updateAgent) {
|
|
204
|
-
console.log(
|
|
205
|
-
"We can't process your feedback right now. The document update feature is temporarily unavailable.",
|
|
206
|
-
);
|
|
207
|
-
console.log("Please try again later or contact support if this continues.");
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Get user preferences
|
|
212
|
-
const contentRules = getActiveRulesForScope("document", [rest.path]);
|
|
213
|
-
const globalRules = getActiveRulesForScope("global");
|
|
214
|
-
const allApplicableRules = [...contentRules, ...globalRules];
|
|
215
|
-
const ruleTexts = allApplicableRules.map((rule) => rule.rule);
|
|
216
|
-
const userPreferences = ruleTexts.length > 0 ? ruleTexts.join("\n\n") : "";
|
|
217
|
-
|
|
218
|
-
try {
|
|
219
|
-
// Call updateDocument agent with feedback
|
|
220
|
-
const currentContent = contentContext.get();
|
|
221
|
-
const result = await options.context.invoke(updateAgent, {
|
|
222
|
-
...rest,
|
|
223
|
-
originalContent: currentContent,
|
|
224
|
-
feedback: feedback.trim(),
|
|
225
|
-
userPreferences,
|
|
226
|
-
title,
|
|
227
|
-
});
|
|
228
|
-
contentContext.set(result.content);
|
|
229
|
-
|
|
230
|
-
// Check if feedback should be saved as user preference
|
|
231
|
-
const feedbackRefinerAgent = options.context.agents["checkFeedbackRefiner"];
|
|
232
|
-
if (feedbackRefinerAgent) {
|
|
233
|
-
try {
|
|
234
|
-
await options.context.invoke(feedbackRefinerAgent, {
|
|
235
|
-
documentContentFeedback: feedback.trim(),
|
|
236
|
-
stage: "document_refine",
|
|
237
|
-
});
|
|
238
|
-
} catch (refinerError) {
|
|
239
|
-
console.warn("We couldn't save your feedback as a preference:", refinerError.message);
|
|
240
|
-
console.warn("Your feedback was applied, but we couldn't save it as a preference.");
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Print updated document headings structure
|
|
245
|
-
printDocumentHeadings(contentContext.get(), title || "Untitled Document");
|
|
246
|
-
|
|
247
|
-
if (rest.isChat) {
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
} catch (error) {
|
|
251
|
-
console.error("Error processing your feedback:");
|
|
252
|
-
console.error(`Type: ${error.name}`);
|
|
253
|
-
console.error(`Message: ${error.message}`);
|
|
254
|
-
if (error.stack) {
|
|
255
|
-
console.error(`Stack: ${error.stack}`);
|
|
256
|
-
}
|
|
257
|
-
console.log("\nPlease try rephrasing your feedback or continue with the current content.");
|
|
258
|
-
|
|
259
|
-
process.exit(0);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return {
|
|
264
|
-
title,
|
|
265
|
-
description,
|
|
266
|
-
...rest,
|
|
267
|
-
content: contentContext.get(),
|
|
268
|
-
feedback: feedbacks.join(". "),
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
userReviewDocument.taskTitle = "User review and modify document content";
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { shutdownMermaidWorkerPool } from "../../utils/mermaid-worker-pool.mjs";
|
|
2
|
-
|
|
3
|
-
export default async function actionSuccess({ action }) {
|
|
4
|
-
// Shutdown mermaid worker pool to ensure clean exit
|
|
5
|
-
try {
|
|
6
|
-
await shutdownMermaidWorkerPool();
|
|
7
|
-
} catch (error) {
|
|
8
|
-
console.warn("Failed to shutdown mermaid worker pool:", error.message);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
message: `${action}`,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
actionSuccess.task_render_mode = "hide";
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
name: analyzeDocumentFeedbackIntent
|
|
2
|
-
description: Analyze user feedback to determine if data sources are needed for content modifications
|
|
3
|
-
task_render_mode: hide
|
|
4
|
-
instructions:
|
|
5
|
-
url: ../../prompts/utils/analyze-document-feedback-intent.md
|
|
6
|
-
input_schema:
|
|
7
|
-
type: object
|
|
8
|
-
properties:
|
|
9
|
-
feedback:
|
|
10
|
-
type: string
|
|
11
|
-
description: User feedback for content modifications
|
|
12
|
-
required:
|
|
13
|
-
- feedback
|
|
14
|
-
output_schema:
|
|
15
|
-
type: object
|
|
16
|
-
properties:
|
|
17
|
-
needDataSources:
|
|
18
|
-
type: boolean
|
|
19
|
-
description: Whether data sources are needed - true for add/edit operations that need context, false for delete/move/reorder operations
|
|
20
|
-
intentType:
|
|
21
|
-
type: string
|
|
22
|
-
description: The primary type of user intention
|
|
23
|
-
reason:
|
|
24
|
-
type: string
|
|
25
|
-
description: Explanation of why data sources are or aren't needed
|
|
26
|
-
error:
|
|
27
|
-
type: boolean
|
|
28
|
-
description: If an error occurs during the analysis process
|
|
29
|
-
required:
|
|
30
|
-
- needDataSources
|
|
31
|
-
- intentType
|
|
32
|
-
- reason
|