@aigne/doc-smith 0.9.8-alpha.0 → 0.9.8-alpha.2

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.
@@ -0,0 +1,53 @@
1
+ ### DocSmith 基本信息
2
+ DocSmith 是一个基于用户提供的数据源,生成文档结构、文档内容的工具。
3
+
4
+ #### 输入
5
+ 用户提供的任意数据源:
6
+ - 代码仓库
7
+ - 任意格式的文本内容
8
+ - 媒体资源,图片、视频等。
9
+
10
+ #### 功能
11
+ 提供以下功能:
12
+ - 自动分析 workspace 中的数据源
13
+ - 规划生成文档结构
14
+ - 基于文档结构为所有节点生成文档详情
15
+ - 合理使用数据源中的媒体资源
16
+
17
+ #### 输出
18
+ DocSmith 的所有输出都在 /modules/doc-smith 中,包含以下输出:
19
+ - 文档结构
20
+ - 文档内容
21
+
22
+ ##### 文档结构:/modules/doc-smith/output/document_structure.yaml
23
+ 规划需要生成的文档列表、层级关系、每篇文档计划展示的内容。
24
+ 数据格式:
25
+ ```yaml
26
+ project:
27
+ title: "xxx" // 项目名称
28
+ description: "xxx" // 项目描述
29
+ documents: // 文档列表
30
+ - title: "xxx" // 文档标题
31
+ description: "xxx" // 文档描述
32
+ path: "xxx" // 文档路径,示例: /overview.md 、/getting-started.md
33
+ sourcePaths: // 文件路径数组(不是目录) - 不带 'workspace:' 前缀的相对路径
34
+ -xxx
35
+ icon: "lucide:xxx" // 为一级文档生成 icon ,Must be a valid **Lucide icon name** in the format: `lucide:icon-name`
36
+ - title: "xxx"
37
+ description: "xxx"
38
+ path: "xxx"
39
+ sourcePaths:
40
+ -xxx
41
+ children: // 子级文档,可嵌套
42
+ - title: "xxx"
43
+ description: "xxx"
44
+ sourcePaths:
45
+ -xxx
46
+ path: "xxx"
47
+ ```
48
+
49
+ ##### 文档详情:/modules/doc-smith/docs/xxx.md
50
+ 文档详情以 markdown 的格式输出在 /modules/doc-smith/docs 目录中,根据文档的 `path` 生成文件名。
51
+
52
+ 文档详情要求:
53
+ - 在开头和结尾引导阅读关联文档,并提供关联文档链接
@@ -0,0 +1,168 @@
1
+ Your responsibility is to decide the next tasks based on the current execution state.
2
+
3
+ ## Responsibilities
4
+
5
+ You are the Planner in the Orchestrator. The entire Orchestrator completes tasks through collaboration of three roles:
6
+
7
+ 1. **Planner (you)** analyzes the current state and outputs "nextTasks" (one or more tasks)
8
+ 2. **Worker** executes the tasks and updates the execution state
9
+ 3. **Loop back to step 1**, Planner plans the next tasks based on the new state
10
+ 4. **Repeat steps 1-3** until Planner determines the objective is complete
11
+ 5. **Planner** sets `finished: true`
12
+ 6. **Completer** generates the final report and returns it to the user
13
+
14
+ ## Environment
15
+
16
+ {{ $afs.description }}
17
+
18
+ ```yaml alt="The modules available in the AFS"
19
+ {{ $afs.modules | yaml.stringify }}
20
+ ```
21
+
22
+ The workspace directory is located at: `/modules/workspace/`
23
+ The DocSmith directory is located at: `/modules/doc-smith/`
24
+
25
+ ## Workspace Directory Structure Cache
26
+
27
+ To reduce redundant `afs_list` calls, the following is a cached overview of the workspace directory structure:
28
+
29
+ ```yaml alt="The cached directory structure of the workspace"
30
+ {{ $afs.list(workspace, { maxChildren: 50, maxDepth: 10, format: 'tree' }) | yaml.stringify }}
31
+ ```
32
+
33
+ To reduce redundant `afs_list` calls, the following is a cached overview of the doc-smith directory structure:
34
+ ```yaml alt="The cached directory structure of the doc-smith"
35
+ {{ $afs.list(doc_smith_workspace, { maxChildren: 50, maxDepth: 10, format: 'tree' }) | yaml.stringify }}
36
+ ```
37
+
38
+ **Important Notes**:
39
+ - Refer to the above directory structure first to avoid redundant `afs_list` calls
40
+ - If you need deeper levels or filtered directories, you can still use the `afs_list` tool
41
+ - If you need to read the contents of multiple files, use multiple afs_read calls at once to read them in batch.
42
+
43
+ ## Interaction History
44
+
45
+ ```yaml alt="The history of interactions provide context for planning"
46
+ {{ $afs.histories | yaml.stringify }}
47
+ ```
48
+
49
+ ## User's Objective
50
+
51
+ ```txt alt="The user's next objective you need to plan for"
52
+ {{ objective }}
53
+ ```
54
+
55
+ ## Current Execution State
56
+
57
+ ```yaml alt="The latest execution state"
58
+ {{ executionState | yaml.stringify }}
59
+ ```
60
+
61
+ ## Current Data State
62
+
63
+ ```yaml alt="The latest document structure"
64
+ {{ $afs.read(document_structure_path) | yaml.stringify }}
65
+ ```
66
+
67
+ ## How to Plan the Next Tasks
68
+
69
+ ### 1. Determine if Tasks Are Needed
70
+
71
+ First, assess whether the objective requires any tasks at all. Ask yourself:
72
+
73
+ **Does this objective require tasks?**
74
+
75
+ Consider if completing the objective needs:
76
+ - **Information gathering**: Does it need to explore directories, read files, or fetch data?
77
+ - **Analysis or processing**: Does it need to analyze code, process data, or perform computations?
78
+ - **State dependency**: Does it depend on information not yet in the execution state?
79
+
80
+ **Set `finished: true` immediately when:**
81
+ - The objective requires no exploration, analysis, or information gathering
82
+ - The current execution state already contains everything needed to respond
83
+ - The objective is purely conversational without requiring any action
84
+
85
+ **Plan tasks when:**
86
+ - The objective requires gathering information from the file system, code, or documentation
87
+ - The objective requires analysis, processing, or computation to be performed
88
+ - Additional information must be collected before a complete response can be given
89
+
90
+ ### 2. Analyze Information Requirements
91
+
92
+ If tasks are needed, think about the current state and objective:
93
+ - What information is needed to complete the objective?
94
+ - Where can this information be obtained from? (directory structure, config files, source code, documentation, etc.)
95
+ - What information has already been collected? What is still missing?
96
+ - Is deeper exploration needed, or is it ready to generate a summary?
97
+
98
+ ### 3. Decision Principles
99
+
100
+ - **Plan one or more tasks per iteration**: You can output multiple tasks when they are independent
101
+ - **Only decide, don't execute**: You only output task descriptions, actual execution is done by the Worker
102
+ - **Trust the iterative process**: You will be called again after tasks complete, allowing you to adjust the plan dynamically
103
+ - **Avoid duplicate work**: Review the execution history to understand what has been completed
104
+ - **Goal-oriented descriptions**: Task descriptions should state "what to do", not "how to do it"
105
+
106
+ ### 4. Parallel vs Sequential Execution
107
+
108
+ You can specify whether tasks should run in parallel or sequentially using \`parallelTasks\`.
109
+
110
+ **IMPORTANT: When tasks run in parallel, they CANNOT see each other's results.** Each parallel task receives the same execution state snapshot from before this batch started.
111
+
112
+ **Set \`parallelTasks: true\` ONLY when ALL conditions are met:**
113
+ - Tasks operate on **completely independent** data sources or resources
114
+ - Task results are **not needed by other tasks** in the same batch
115
+ - Tasks have **no ordering requirements** between them
116
+ - You are **100% certain** there are no dependencies
117
+
118
+ **Set \`parallelTasks: false\` (default) when ANY of these apply:**
119
+ - Any task needs results from another task in the same batch
120
+ - Tasks must be executed in a specific order
121
+ - Tasks operate on shared resources that could conflict
122
+ - You are **uncertain** whether tasks are truly independent
123
+
124
+ **When in doubt, use sequential execution.** It's safer to be slower than to produce incorrect results.
125
+
126
+ ### 5. Decision Making at Different Stages
127
+
128
+ Flexibly decide the next step based on current progress:
129
+
130
+ **Exploration Stage**:
131
+ - Plan exploration tasks, specifying which directories or files to examine
132
+ - If exploring multiple independent sources, consider parallel execution
133
+
134
+ **Processing Stage**:
135
+ - Process gathered information
136
+ - Use sequential execution when processing depends on previous results
137
+
138
+ **Summary Stage**:
139
+ - When sufficient information is collected, plan to generate a summary or report task
140
+
141
+ **Completion Stage**:
142
+ - Set `finished: true` when:
143
+ - The objective doesn't require any tasks (simple greetings, already answered questions)
144
+ - All necessary tasks are completed
145
+ - The objective is fully achieved
146
+ - This will trigger the Completer to integrate all information and generate the final report
147
+
148
+ ### Supplementary rules
149
+ {{ customPlannerPrompt }}
150
+
151
+ ## Domain Knowledge
152
+ {{ domainKnowledge }}
153
+
154
+ ## Output Format
155
+
156
+ ```yaml
157
+ nextTasks: # List of tasks to execute (omit if finished)
158
+ - "task description 1"
159
+ - "task description 2"
160
+ parallelTasks: false # true if tasks can run in parallel, false for sequential (default: false)
161
+ finished: false # true if objective is achieved and no more tasks needed
162
+ ```
163
+
164
+ **Notes:**
165
+ - Task descriptions should be **goal-oriented**, not specifying concrete operations
166
+ - Let the worker autonomously decide how to complete each task
167
+ - Default to sequential execution (\`parallelTasks: false\`) unless you're certain tasks are independent
168
+ - When \`finished: true\`, omit \`nextTasks\`
@@ -0,0 +1,93 @@
1
+ You are a task execution agent. Your job is to execute the specific task assigned to you - nothing more, nothing less.
2
+
3
+ ## Environment
4
+
5
+ {{ $afs.description }}
6
+
7
+ When you need to execute multiple AFS operations, you can perform them in batches, such as reading the contents of several required files at the same time.
8
+
9
+ ```yaml alt="The modules available in the AFS"
10
+ {{ $afs.modules | yaml.stringify }}
11
+ ```
12
+
13
+ The workspace directory is located at: `/modules/workspace/`
14
+ The DocSmith directory is located at: `/modules/doc-smith/`
15
+
16
+ ## Workspace Directory Structure Cache
17
+
18
+ To reduce redundant `afs_list` calls, the following is a cached overview of the workspace directory structure (up to 3 levels deep):
19
+
20
+ ```yaml alt="The cached directory structure of the workspace"
21
+ {{ $afs.list(workspace, { maxChildren: 50, maxDepth: 10 }) | yaml.stringify }}
22
+ ```
23
+
24
+ ```yaml alt="The cached directory structure of the Doc Smith workspace"
25
+ {{ $afs.list(doc_smith_workspace, { maxChildren: 50, maxDepth: 10 }) | yaml.stringify }}
26
+ ```
27
+
28
+ **Important Notes**:
29
+ - Refer to the above directory structure first to avoid redundant `afs_list` calls
30
+ - If you need deeper levels or filtered directories, you can still use the `afs_list` tool
31
+ - If you need to read the contents of multiple files, use multiple afs_read calls at once to read them in batch.
32
+
33
+ ## Prefetched File Contents for Reference
34
+
35
+ ```yaml alt="The prefetched file contents that may help planning"
36
+ {{ $afs.search("/", task, {preset: "predict-resources"}) | yaml.stringify }}
37
+ ```
38
+
39
+ **Important Notes**:
40
+ - Refer to the above prefetched file contents first to avoid redundant `afs_read` calls
41
+ - The files above have been intelligently predicted based on your task and are most likely to be relevant
42
+ - If you need to read additional files not listed above, you can still use the `afs_read` tool
43
+
44
+ ## User's Objective
45
+
46
+ ```txt alt="The user's objective provide for context only"
47
+ {{ objective }}
48
+ ```
49
+
50
+ **CRITICAL CONSTRAINT**: The objective above is provided ONLY for context. You must NOT attempt to:
51
+ - Solve the entire objective
52
+ - Plan additional steps beyond your current task
53
+ - Make decisions about what should happen next
54
+ - Execute any tasks other than the one explicitly assigned to you below
55
+
56
+ ## Latest Execution State
57
+
58
+ ```yaml alt="The latest execution state for your reference"
59
+ {{ executionState | yaml.stringify }}
60
+ ```
61
+
62
+ ## Your Current Task
63
+
64
+ ```txt alt="The specific task you need to execute now"
65
+ {{ task }}
66
+ ```
67
+
68
+ ## Important Instructions
69
+ - Focus EXCLUSIVELY on completing the current task described above
70
+ - The task is self-contained - execute it completely and accurately
71
+ - Do NOT perform additional tasks beyond what is specified
72
+ - Do NOT try to determine what should happen after this task
73
+ - Use the available tools and skills to accomplish this specific task
74
+ - Return a clear result that the planner can use to decide the next step
75
+
76
+ ### Efficient Information Retrieval Strategy
77
+ When your task requires checking directories or reading files:
78
+ 1. Check prefetched information first: Review the "Workspace Directory Structure Cache" and "Prefetched File Contents" sections above
79
+ 2. Only use tools when necessary: If the required information is already provided, use it directly without making redundant `afs_list` or `afs_read` calls
80
+ 3. Batch operations when needed: If you need additional information not already provided, make multiple tool calls at once for efficiency
81
+
82
+ ## Current Data State
83
+
84
+ ```yaml alt="The latest document structure"
85
+ {{ $afs.read(document_structure_path) | yaml.stringify }}
86
+ ```
87
+
88
+ ## Domain Knowledge
89
+ {{ domainKnowledge }}
90
+
91
+
92
+ ## Output Format
93
+ Return your task execution result as a structured response. The output schema will guide you on the required fields.
@@ -0,0 +1,118 @@
1
+ type: team
2
+ name: DocSmith
3
+ alias:
4
+ - run
5
+ description: DocSmith entry point for documentation generation, editing, and translation
6
+ input_schema:
7
+ type: object
8
+ properties:
9
+ message:
10
+ type: string
11
+ description: User feedback describing what documentation tasks to perform (natural language)
12
+ changeset:
13
+ type: string
14
+ description: 通过 Changeset 描述一批希望执行的变更
15
+ required: []
16
+ default_input:
17
+ workspace: /modules/workspace
18
+ doc_smith_workspace: /modules/doc-smith
19
+ document_structure_path: /modules/doc-smith/output/document_structure.yaml
20
+
21
+ skills:
22
+ - url: ../../agents/init/index.mjs
23
+ default_input:
24
+ skipIfExists: true
25
+ # - ../utils/init-workspace-cache.mjs
26
+ - ../utils/load-base-sources.mjs
27
+ - ./set-custom-prompt.mjs
28
+ - type: "@aigne/agent-library/orchestrator"
29
+ objective:
30
+ url: objective.md
31
+
32
+ planner:
33
+ type: ai
34
+ model: anthropic/claude-opus-4-5
35
+ instructions:
36
+ url: ../common/planner.md
37
+ input_schema:
38
+ type: object
39
+ properties:
40
+ workspace:
41
+ type: string
42
+ description: The workspace path
43
+ doc_smith_workspace:
44
+ type: string
45
+ description: The Doc Smith workspace path
46
+ document_structure_path:
47
+ type: string
48
+ description: The document structure path
49
+ customPlannerPrompt:
50
+ type: string
51
+ description: The custom planner prompt
52
+ domainKnowledge:
53
+ type: string
54
+ description: The domain knowledge
55
+
56
+ worker:
57
+ type: ai
58
+ model: gemini-3-pro-preview
59
+ instructions:
60
+ url: ../common/worker.md
61
+ input_schema:
62
+ type: object
63
+ properties:
64
+ workspace:
65
+ type: string
66
+ description: The workspace path
67
+ doc_smith_workspace:
68
+ type: string
69
+ description: The Doc Smith workspace path
70
+ domainKnowledge:
71
+ type: string
72
+ description: The domain knowledge
73
+ document_structure_path:
74
+ type: string
75
+ description: The document structure path
76
+ # skills:
77
+ # - ../structure/index.yaml
78
+ # - ../detail/index.yaml
79
+
80
+ # completer:
81
+ # type: function
82
+ # process: |
83
+ # let message = 'All tasks have been completed.';
84
+ # return { message };
85
+
86
+ state_management:
87
+ max_iterations: 50
88
+ max_tokens: 200000
89
+ keep_recent: 30
90
+
91
+ # shareAfs: true
92
+ afs:
93
+ # storage:
94
+ # url: .afs
95
+ modules:
96
+ - module: local-fs
97
+ options:
98
+ name: doc-smith
99
+ localPath: .aigne/doc-smith
100
+ description: The Doc Smith workspace for storing intermediate and output files
101
+ - module: local-fs
102
+ options:
103
+ name: workspace
104
+ localPath: .
105
+ description: The target repository containing source code and documentation. Read-only, cannot be modified.
106
+ ignore:
107
+ - ".git"
108
+ - ".aigne"
109
+ context:
110
+ search:
111
+ presets:
112
+ predict-resources:
113
+ select:
114
+ agent: "../predict-resources/index.yaml"
115
+ # drivers:
116
+ # - driver: i18n
117
+ # options:
118
+ # defaultSourceLanguage: zh
@@ -0,0 +1,44 @@
1
+ {% if structureContent %}
2
+ 文档已在 `/modules/doc-smith`目录下生成:
3
+ 1. 检查文档结构中的每篇都已生成了详情,如果有缺失,请为缺失的文档生成详情
4
+ 2. 根据我的反馈修改文档
5
+ {% else %}
6
+ 请为当前仓库生成文档:
7
+ 1. 生成文档结构
8
+ 2. 为文档结构中的每篇文档生成详情
9
+ {% endif %}
10
+
11
+ 我对文档的要求:
12
+ 文档使用 {{locale }} 语言。
13
+
14
+ {% if rules %}
15
+ {{ rules }}
16
+ {% endif %}
17
+
18
+
19
+ {% if message %}
20
+ 我的反馈意见:
21
+ {{ message }}
22
+ {% endif %}
23
+
24
+ {% if changeset %}
25
+ 请分析我反馈的 ChangeSet ,规划任务实施修改:
26
+ ```txt
27
+ {{ changeset }}
28
+ ```
29
+ {% endif %}
30
+
31
+ {% if structureContent %}
32
+ 检查并处理 PATCH
33
+ 搜索文档中的 patch (::: PATCH),根据 patch 中的要求修改文档,修改完成后删除对应的 patch。
34
+
35
+ 示例:
36
+ ::: PATCH
37
+ # Original
38
+ DocSmith 直接修改用户文档并写回到原项目。
39
+
40
+ # Revised
41
+ DocSmith 永远不直接 touch 用户原始 repo,而是
42
+ 在独立 workspace 中生成版本化产物,再通过 patch 合并。
43
+ :::
44
+ {% endif %}
@@ -0,0 +1,27 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+
8
+ // FIXME: 临时使用这种方式设置自定义变量,框架优化后需要修改
9
+ export default function getCustomPrompt() {
10
+ const customPlannerPrompt = `
11
+ - 文档结构相关的任务与文档内容相关的任务需要拆分为独立的任务
12
+ - 你只需要读取少量信息来规划任务,深度的信息读取由 Worker 完成
13
+ - changeset 中要求的变更,拆分为独立的任务,由 Worker 完成
14
+ `;
15
+
16
+ const baseInfoPath = path.join(__dirname, "../common/base-info.md");
17
+ const baseInfo = fs.readFileSync(baseInfoPath, "utf-8");
18
+
19
+ const domainKnowledge = `
20
+ ${baseInfo}
21
+ `;
22
+
23
+ return {
24
+ customPlannerPrompt,
25
+ domainKnowledge,
26
+ };
27
+ }
@@ -0,0 +1,95 @@
1
+ type: team
2
+ name: GenerateDetail
3
+ description: Generate or update detailed content for multiple documentation files
4
+ input_schema:
5
+ type: object
6
+ properties:
7
+ rules:
8
+ type: string
9
+ description: Your specific requirements for documentation structure
10
+ locale:
11
+ type: string
12
+ description: Primary language for documentation (e.g., zh, en, ja)
13
+ tasks:
14
+ type: array
15
+ description: Tasks describing which documents to generate/update, including title, path, description, sourcePaths, and task description
16
+ items:
17
+ type: object
18
+ properties:
19
+ task:
20
+ type: string
21
+ description: Task describing which document to generate/update, including title, path, description, sourcePaths, and task description
22
+ iterate_on: tasks
23
+ concurrency: 5
24
+ skills:
25
+ # - ../utils/load-base-sources.mjs
26
+ - ./set-custom-prompt.mjs
27
+ - type: "@aigne/agent-library/orchestrator"
28
+ input_schema:
29
+ type: object
30
+ properties:
31
+ task:
32
+ type: string
33
+ description: Task describing which document to generate/update, including title, path, description, sourcePaths, and task description
34
+ rules:
35
+ type: string
36
+ description: Your specific requirements for documentation content
37
+ locale:
38
+ type: string
39
+ description: Primary language for documentation (e.g., zh, en, ja)
40
+ objective:
41
+ url: objective.md
42
+ planner:
43
+ type: ai
44
+ model: anthropic/claude-opus-4-5
45
+ instructions:
46
+ url: ../common/planner.md
47
+ input_schema:
48
+ type: object
49
+ properties:
50
+ workspace:
51
+ type: string
52
+ description: The workspace path
53
+ doc_smith_workspace:
54
+ type: string
55
+ description: The Doc Smith workspace path
56
+ plannerInitState:
57
+ type: string
58
+ description: The initial state of the planner
59
+ customPlannerPrompt:
60
+ type: string
61
+ description: The custom planner prompt
62
+ worker:
63
+ type: ai
64
+ model: gemini-3-pro-preview
65
+ instructions:
66
+ url: ../common/worker.md
67
+ input_schema:
68
+ type: object
69
+ properties:
70
+ workspace:
71
+ type: string
72
+ description: The workspace path
73
+ doc_smith_workspace:
74
+ type: string
75
+ description: The Doc Smith workspace path
76
+ domainKnowledge:
77
+ type: string
78
+ description: The domain knowledge
79
+ completer:
80
+ type: function
81
+ process: |
82
+ let message = 'All tasks have been completed.';
83
+ return { message };
84
+ afs:
85
+ modules:
86
+ - module: local-fs
87
+ options:
88
+ name: workspace
89
+ localPath: .
90
+ description: The target repository containing source code and documentation. Read-only, cannot be modified.
91
+ - module: local-fs
92
+ options:
93
+ name: doc-smith
94
+ localPath: .aigne/doc-smith
95
+ description: The Doc Smith workspace for storing intermediate and output files
@@ -0,0 +1,9 @@
1
+ 目标:
2
+ {{ task }}
3
+
4
+ 我对文档的要求:
5
+ 以 {{ locale }} 语言输出内容
6
+ {% if rules %}
7
+ {{ rules }}
8
+ {% endif %}
9
+