@actiondock/core 2.0.12 → 2.2.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 (192) hide show
  1. package/README.md +61 -30
  2. package/dist/app/app.d.ts +73 -0
  3. package/dist/app/app.js +700 -0
  4. package/dist/app/index.d.ts +2 -0
  5. package/dist/app/index.js +2 -0
  6. package/dist/app/types.d.ts +283 -0
  7. package/dist/app/types.js +1 -0
  8. package/dist/catalog/action-index.d.ts +1 -1
  9. package/dist/catalog/action-index.js +93 -0
  10. package/dist/catalog/action-resolver.d.ts +2 -2
  11. package/dist/catalog/action-resolver.js +95 -0
  12. package/dist/catalog/index.d.ts +5 -5
  13. package/dist/catalog/index.js +5 -0
  14. package/dist/catalog/location-registry.d.ts +5 -5
  15. package/dist/catalog/location-registry.js +138 -0
  16. package/dist/catalog/package-catalog.d.ts +2 -2
  17. package/dist/catalog/package-catalog.js +76 -0
  18. package/dist/catalog/types.d.ts +2 -2
  19. package/dist/catalog/types.js +1 -0
  20. package/dist/doctor/doctor.d.ts +2 -1
  21. package/dist/doctor/doctor.js +613 -0
  22. package/dist/doctor/index.d.ts +2 -2
  23. package/dist/doctor/index.js +2 -0
  24. package/dist/doctor/types.js +1 -0
  25. package/dist/errors.d.ts +122 -0
  26. package/dist/errors.js +123 -0
  27. package/dist/execution/index.d.ts +2 -2
  28. package/dist/execution/index.js +2 -0
  29. package/dist/execution/service.d.ts +46 -41
  30. package/dist/execution/service.js +633 -0
  31. package/dist/execution/types.d.ts +59 -2
  32. package/dist/execution/types.js +1 -0
  33. package/dist/export/index.d.ts +1 -1
  34. package/dist/export/index.js +1 -0
  35. package/dist/export/templates.d.ts +45 -7
  36. package/dist/export/templates.js +631 -0
  37. package/dist/filter/index.d.ts +1 -1
  38. package/dist/filter/index.js +1 -0
  39. package/dist/filter/intent.js +123 -0
  40. package/dist/host/host.d.ts +55 -0
  41. package/dist/host/host.js +740 -0
  42. package/dist/host/index.d.ts +2 -0
  43. package/dist/host/index.js +2 -0
  44. package/dist/host/types.d.ts +81 -0
  45. package/dist/host/types.js +1 -0
  46. package/dist/index.d.ts +21 -16
  47. package/dist/index.js +20 -8458
  48. package/dist/ipc/diagnostic.d.ts +65 -0
  49. package/dist/ipc/diagnostic.js +129 -0
  50. package/dist/ipc/host.d.ts +7 -0
  51. package/dist/ipc/host.js +93 -0
  52. package/dist/ipc/index.d.ts +4 -0
  53. package/dist/ipc/index.js +4 -0
  54. package/dist/ipc/target.d.ts +56 -0
  55. package/dist/ipc/target.js +297 -0
  56. package/dist/ipc/types.d.ts +42 -0
  57. package/dist/ipc/types.js +1 -0
  58. package/dist/platform/default.d.ts +32 -0
  59. package/dist/platform/default.js +40 -0
  60. package/dist/platform/index.d.ts +3 -0
  61. package/dist/platform/index.js +3 -0
  62. package/dist/platform/node-fs.d.ts +37 -0
  63. package/dist/platform/node-fs.js +81 -0
  64. package/dist/platform/types.d.ts +104 -0
  65. package/dist/platform/types.js +1 -0
  66. package/dist/profile/client.d.ts +58 -12
  67. package/dist/profile/client.js +467 -0
  68. package/dist/profile/index.d.ts +3 -3
  69. package/dist/profile/index.js +3 -0
  70. package/dist/profile/manager.d.ts +2 -2
  71. package/dist/profile/manager.js +294 -0
  72. package/dist/profile/types.d.ts +1 -1
  73. package/dist/profile/types.js +1 -0
  74. package/dist/project/closure.js +68 -0
  75. package/dist/project/digest.d.ts +29 -0
  76. package/dist/project/digest.js +324 -0
  77. package/dist/project/index.d.ts +10 -5
  78. package/dist/project/index.js +10 -0
  79. package/dist/project/init.d.ts +3 -4
  80. package/dist/project/init.js +175 -0
  81. package/dist/project/loader.d.ts +21 -27
  82. package/dist/project/loader.js +484 -0
  83. package/dist/project/lockfile.d.ts +55 -0
  84. package/dist/project/lockfile.js +175 -0
  85. package/dist/project/manifest.d.ts +6 -28
  86. package/dist/project/manifest.js +220 -0
  87. package/dist/project/resolver.d.ts +116 -0
  88. package/dist/project/resolver.js +376 -0
  89. package/dist/project/transactions.d.ts +103 -0
  90. package/dist/project/transactions.js +1203 -0
  91. package/dist/project/types-generator.d.ts +33 -0
  92. package/dist/project/types-generator.js +168 -0
  93. package/dist/project/types.d.ts +58 -82
  94. package/dist/project/types.js +1 -0
  95. package/dist/registry/index.d.ts +5 -2
  96. package/dist/registry/index.js +5 -0
  97. package/dist/registry/lock.d.ts +27 -0
  98. package/dist/registry/lock.js +93 -0
  99. package/dist/registry/registry.d.ts +32 -11
  100. package/dist/registry/registry.js +611 -0
  101. package/dist/registry/resolve.d.ts +62 -0
  102. package/dist/registry/resolve.js +195 -0
  103. package/dist/registry/scan.d.ts +38 -0
  104. package/dist/registry/scan.js +135 -0
  105. package/dist/registry/types.d.ts +1 -1
  106. package/dist/registry/types.js +1 -0
  107. package/dist/runtime/action-collection.d.ts +27 -0
  108. package/dist/runtime/action-collection.js +57 -0
  109. package/dist/runtime/clock.d.ts +0 -2
  110. package/dist/runtime/clock.js +17 -0
  111. package/dist/runtime/context.d.ts +16 -5
  112. package/dist/runtime/context.js +242 -0
  113. package/dist/runtime/env.d.ts +3 -1
  114. package/dist/runtime/env.js +159 -0
  115. package/dist/runtime/events.d.ts +46 -14
  116. package/dist/runtime/events.js +604 -0
  117. package/dist/runtime/execution-manager.d.ts +1 -1
  118. package/dist/runtime/execution-manager.js +66 -0
  119. package/dist/runtime/index.d.ts +10 -9
  120. package/dist/runtime/index.js +10 -0
  121. package/dist/runtime/module-loader.d.ts +0 -8
  122. package/dist/runtime/module-loader.js +16 -0
  123. package/dist/runtime/process.d.ts +2 -4
  124. package/dist/runtime/process.js +146 -0
  125. package/dist/runtime/runner.d.ts +117 -10
  126. package/dist/runtime/runner.js +984 -0
  127. package/dist/runtime/standalone.d.ts +68 -19
  128. package/dist/runtime/standalone.js +536 -0
  129. package/dist/schema/validator.js +122 -0
  130. package/dist/server/body.js +93 -0
  131. package/dist/server/index.d.ts +5 -6
  132. package/dist/server/index.js +5 -0
  133. package/dist/server/routes/actions.d.ts +2 -2
  134. package/dist/server/routes/actions.js +298 -0
  135. package/dist/server/routes/common.d.ts +28 -17
  136. package/dist/server/routes/common.js +104 -0
  137. package/dist/server/routes/config.d.ts +2 -1
  138. package/dist/server/routes/config.js +173 -0
  139. package/dist/server/routes/doctor.d.ts +2 -2
  140. package/dist/server/routes/doctor.js +63 -0
  141. package/dist/server/routes/health.d.ts +2 -2
  142. package/dist/server/routes/health.js +35 -0
  143. package/dist/server/routes/index.d.ts +9 -9
  144. package/dist/server/routes/index.js +9 -0
  145. package/dist/server/routes/info.d.ts +4 -2
  146. package/dist/server/routes/info.js +158 -0
  147. package/dist/server/routes/playbooks.d.ts +2 -2
  148. package/dist/server/routes/playbooks.js +134 -0
  149. package/dist/server/routes/runs.d.ts +2 -2
  150. package/dist/server/routes/runs.js +343 -0
  151. package/dist/server/routes/state.d.ts +2 -1
  152. package/dist/server/routes/state.js +169 -0
  153. package/dist/server/security.d.ts +11 -4
  154. package/dist/server/security.js +101 -0
  155. package/dist/server/server.d.ts +6 -6
  156. package/dist/server/server.js +355 -0
  157. package/dist/server/types.d.ts +27 -8
  158. package/dist/server/types.js +1 -0
  159. package/dist/storage/data-dir-lock.d.ts +119 -0
  160. package/dist/storage/data-dir-lock.js +1016 -0
  161. package/dist/storage/driver.d.ts +4 -10
  162. package/dist/storage/driver.js +59 -0
  163. package/dist/storage/index.d.ts +30 -10
  164. package/dist/storage/index.js +98 -0
  165. package/dist/storage/lazy.d.ts +8 -0
  166. package/dist/storage/lazy.js +44 -0
  167. package/dist/storage/mask.d.ts +12 -5
  168. package/dist/storage/mask.js +48 -0
  169. package/dist/storage/params.d.ts +13 -0
  170. package/dist/storage/params.js +32 -0
  171. package/dist/storage/sqlite.d.ts +19 -6
  172. package/dist/storage/sqlite.js +689 -0
  173. package/dist/storage/types.d.ts +57 -6
  174. package/dist/storage/types.js +14 -0
  175. package/dist/target/index.d.ts +4 -0
  176. package/dist/target/index.js +4 -0
  177. package/dist/target/local.d.ts +52 -0
  178. package/dist/target/local.js +343 -0
  179. package/dist/target/remote.d.ts +76 -0
  180. package/dist/target/remote.js +839 -0
  181. package/dist/target/target.d.ts +6 -0
  182. package/dist/target/target.js +35 -0
  183. package/dist/target/types.d.ts +246 -0
  184. package/dist/target/types.js +34 -0
  185. package/dist/utils/index.d.ts +22 -2
  186. package/dist/utils/index.js +180 -0
  187. package/dist/version.d.ts +1 -1
  188. package/dist/version.js +4 -0
  189. package/package.json +6 -7
  190. package/dist/build/index.d.ts +0 -1
  191. package/dist/build/templates.d.ts +0 -19
  192. package/dist/server/runtime-registry.d.ts +0 -78
@@ -0,0 +1,631 @@
1
+ import { basename } from "node:path";
2
+ function getCleanSkillMetadata(config) {
3
+ const cleanName = config.id.replace(/[^a-zA-Z0-9-_]/g, "-").toLowerCase();
4
+ const desc = config.description || `AI Agent skill for ${config.name} (${config.id})`;
5
+ return { cleanName, desc };
6
+ }
7
+ function renderActionListMarkdown(actions, options = {}) {
8
+ return actions
9
+ .map((a) => {
10
+ const aDesc = a.description ? ` - ${a.description}` : "";
11
+ const idLabel = options.packageId
12
+ ? `\`${options.packageId}/${a.id}\` (或 \`${a.id}\`)`
13
+ : `\`${a.id}\``;
14
+ const lines = [`- ${idLabel}${aDesc}`];
15
+ // 标注元数据解析
16
+ if (a.annotations && typeof a.annotations === "object") {
17
+ const annoList = [];
18
+ if (a.annotations.readOnly === true) {
19
+ annoList.push("只读操作");
20
+ }
21
+ if (a.annotations.destructive === true) {
22
+ annoList.push("破坏性操作(执行前须向用户确认)");
23
+ }
24
+ if (annoList.length > 0) {
25
+ lines.push(` - 属性标注: ${annoList.join(", ")}`);
26
+ }
27
+ }
28
+ // 输入参数模式解析
29
+ if (a.inputSchema &&
30
+ typeof a.inputSchema === "object" &&
31
+ a.inputSchema.properties) {
32
+ const props = a.inputSchema.properties;
33
+ const req = (a.inputSchema.required || []);
34
+ const propKeys = Object.keys(props);
35
+ if (propKeys.length > 0) {
36
+ lines.push(" - 输入参数:");
37
+ for (const k of propKeys) {
38
+ const p = props[k] || {};
39
+ const typeStr = p.type ? `\`${p.type}\`` : "`any`";
40
+ const reqStr = req.includes(k) ? ", 必填" : "";
41
+ const descStr = p.description ? `: ${p.description}` : "";
42
+ const defStr = p.default !== undefined
43
+ ? ` (默认值: \`${JSON.stringify(p.default)}\`)`
44
+ : "";
45
+ lines.push(` - \`${k}\` (${typeStr}${reqStr})${descStr}${defStr}`);
46
+ }
47
+ }
48
+ else {
49
+ lines.push(" - 输入参数: 无");
50
+ }
51
+ }
52
+ else {
53
+ lines.push(" - 输入参数: 无");
54
+ }
55
+ // 输出字段模式解析
56
+ if (a.outputSchema &&
57
+ typeof a.outputSchema === "object" &&
58
+ a.outputSchema.properties) {
59
+ const outProps = a.outputSchema.properties;
60
+ const outKeys = Object.keys(outProps);
61
+ if (outKeys.length > 0) {
62
+ lines.push(" - 输出字段:");
63
+ for (const k of outKeys) {
64
+ const p = outProps[k] || {};
65
+ const typeStr = p.type ? `\`${p.type}\`` : "`any`";
66
+ const descStr = p.description ? `: ${p.description}` : "";
67
+ lines.push(` - \`${k}\` (${typeStr})${descStr}`);
68
+ }
69
+ }
70
+ }
71
+ return lines.join("\n");
72
+ })
73
+ .join("\n\n");
74
+ }
75
+ function renderPlaybookSectionMarkdown(playbooks, playbooksDir = "playbooks") {
76
+ if (playbooks.length === 0)
77
+ return "";
78
+ const normalizedDir = playbooksDir.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+$/, "");
79
+ const list = playbooks
80
+ .map((p) => {
81
+ const rel = `./${normalizedDir}/${basename(p.filePath)}`;
82
+ return `- **${p.id}** (\`${rel}\`): ${p.description || "业务操作指南"}`;
83
+ })
84
+ .join("\n");
85
+ return `
86
+ ## 业务操作规程
87
+
88
+ > [!IMPORTANT]
89
+ > **规程优先准则**:当处理复合业务任务时,智能体必须优先检查是否存在匹配场景的 Playbook。若存在规程,必须优先查阅并严格遵循规程界定的步骤时序与校验逻辑推进,严禁无序拼凑调用底层 Action。
90
+
91
+ Playbook SOPs 为复杂业务任务提供逐步指导规程。详细规程请查阅对应文档:
92
+
93
+ ${list}
94
+ `;
95
+ }
96
+ export function generateSourceSkillMd(config, actions, playbooks) {
97
+ const { cleanName, desc } = getCleanSkillMetadata(config);
98
+ const pkgId = config.id;
99
+ const firstAction = actions[0]?.id || "sample.greet";
100
+ const playbookSection = renderPlaybookSectionMarkdown(playbooks, config.playbooksDir || "playbooks");
101
+ const actionListMd = renderActionListMarkdown(actions, { packageId: pkgId });
102
+ return `---
103
+ name: ${cleanName}
104
+ description: ${desc}
105
+ ---
106
+
107
+ # ${config.name} (${config.id})
108
+
109
+ ${desc}
110
+
111
+ ## ActionDock 运行时
112
+
113
+ 本技能为 **ActionDock 源码型技能包**。智能体可直接通过宿主环境中已安装的 ActionDock 命令行工具 \`ad\` 执行其中的 Action。
114
+
115
+ ### 注册与链接
116
+
117
+ 在初次调用或初始化时,将包含本 \`SKILL.md\` 的目录解析为 \`<skill_root>\` 并完成注册:
118
+
119
+ \`\`\`bash
120
+ ad link "<skill_root>"
121
+ \`\`\`
122
+
123
+ > \`ad link\` 天然具备幂等性,同一 Package 多次执行会直接更新路径,可安全重复调用。若初次运行提示依赖缺失,可在 \`<skill_root>\` 目录下执行 \`npm install --omit=dev\` 安装生产依赖。
124
+
125
+ ### 动作参数契约按需调阅
126
+
127
+ 在调用未知参数的 Action 前,可在终端执行命令按需查阅该 Action 的输入输出模式与详细说明:
128
+
129
+ \`\`\`bash
130
+ ad describe ${pkgId}/${firstAction}
131
+ \`\`\`
132
+
133
+ ### 执行 Action
134
+
135
+ 为避免多技能之间的 Action ID 命名冲突,建议统一使用带有 Package 前缀的完全限定 ID。
136
+
137
+ 推荐最佳实践:使用文件传递参数,杜绝终端引号转义问题:
138
+
139
+ \`\`\`bash
140
+ # 写入参数到临时文件并通过 --input-file 传递
141
+ cat << 'EOF' > /tmp/input.json
142
+ {
143
+ "param": "value"
144
+ }
145
+ EOF
146
+ ad run ${pkgId}/${firstAction} --input-file /tmp/input.json
147
+ \`\`\`
148
+
149
+ 亦可通过内联参数进行简易命令调用:
150
+
151
+ \`\`\`bash
152
+ ad run ${pkgId}/${firstAction} --input '{"param": "value"}'
153
+ \`\`\`
154
+
155
+ > **免注册本地执行**:
156
+ > 若工作目录已位于本技能根目录,亦可直接免 link 执行:
157
+ > \`\`\`bash
158
+ > cd <skill_root>
159
+ > ad run <action-id> --input-file /tmp/input.json
160
+ > \`\`\`
161
+
162
+ ### 结构化响应解析
163
+
164
+ 所有 Action 执行结果均在 \`stdout\` 输出标准格式的 JSON 信封:
165
+
166
+ \`\`\`json
167
+ // 执行成功响应 (ok 为 true)
168
+ {
169
+ "ok": true,
170
+ "runId": "01J...",
171
+ "data": { ... }
172
+ }
173
+
174
+ // 执行失败响应 (ok 为 false)
175
+ {
176
+ "ok": false,
177
+ "runId": "01J...",
178
+ "error": {
179
+ "code": "ACTION_EXECUTION_FAILED",
180
+ "message": "错误详细描述信息"
181
+ }
182
+ }
183
+ \`\`\`
184
+
185
+ - \`stdout\`:标准 JSON 信封结果。当 \`ok\` 为 \`true\` 时,从 \`data\` 提取业务返回值推进后续步骤;当 \`ok\` 为 \`false\` 时,从 \`error\` 提取错误码与信息以判定自愈策略或上报。
186
+ - \`stderr\`:执行日志与诊断跟踪信息。
187
+ ${playbookSection}
188
+ ---
189
+
190
+ ## Action 目录
191
+
192
+ ${actionListMd}
193
+
194
+ ---
195
+
196
+ ## 运行时配置与持久化状态
197
+
198
+ 如需检查或配置该 Package 的运行时参数与持久化数据:
199
+
200
+ \`\`\`bash
201
+ # 查看与设置配置项
202
+ ad config list --package ${pkgId}
203
+ ad config set KEY VALUE --package ${pkgId}
204
+
205
+ # 查看与检索状态数据
206
+ ad state list --package ${pkgId}
207
+ ad state get KEY --package ${pkgId}
208
+ \`\`\`
209
+
210
+ ---
211
+
212
+ ## 故障排查与环境安装指引(按需查阅)
213
+
214
+ > [!NOTE]
215
+ > **按需排查原则**:默认宿主环境中已预置 \`ad\` 命令行工具与 Node.js 运行环境。正常执行流程直接调用上述 Action 即可,**严禁在任务启动前盲目进行前置环境检查或体检**;仅在终端明确报错提示命令不存在(如 \`ad: command not found\`)或提示依赖缺失时,方可按本节指引安装初始化。
216
+
217
+ ### 命令行工具与环境依赖未就绪时的安装指引
218
+
219
+ 若宿主环境未安装 \`ad\` 命令行工具或依赖缺失,请依次按如下步骤完成安装:
220
+
221
+ - **环境要求**:Node.js 版本大于等于 24.12.0(执行 \`node -v\` 确认)。
222
+ - **全局安装 ActionDock 命令行工具**:
223
+ \`\`\`bash
224
+ npm install -g @actiondock/cli
225
+ \`\`\`
226
+ - **安装技能源码依赖**:
227
+ 若在技能目录内调用时提示模块缺失,在 \`<skill_root>\` 目录下安装生产依赖:
228
+ \`\`\`bash
229
+ cd "<skill_root>" && npm install --omit=dev
230
+ \`\`\`
231
+ - **验证工具就绪**:
232
+ \`\`\`bash
233
+ ad --version
234
+ \`\`\`
235
+ - **环境诊断与体检**:
236
+ 安装完成后若仍遇到异常,执行体检命令排查:
237
+ \`\`\`bash
238
+ ad doctor
239
+ \`\`\`
240
+ - **完成安装后重新链接本技能**:
241
+ \`\`\`bash
242
+ ad link "<skill_root>"
243
+ \`\`\`
244
+ `;
245
+ }
246
+ export function generateStandaloneSkillMd(config, actions, playbooks, binaryRelPath = "./bin/action-bin") {
247
+ const { cleanName, desc } = getCleanSkillMetadata(config);
248
+ const firstAction = actions[0]?.id || "sample.greet";
249
+ const playbookSection = renderPlaybookSectionMarkdown(playbooks, config.playbooksDir || "playbooks");
250
+ const actionListMd = renderActionListMarkdown(actions);
251
+ return `---
252
+ name: ${cleanName}
253
+ description: ${desc}
254
+ ---
255
+
256
+ # ${config.name} (${config.id})
257
+
258
+ ${desc}
259
+
260
+
261
+ ### 执行 Action
262
+
263
+ 推荐最佳实践:使用文件传递参数,杜绝终端引号转义问题:
264
+
265
+ \`\`\`bash
266
+ # 写入参数到临时文件并通过 --input-file 传递
267
+ cat << 'EOF' > /tmp/input.json
268
+ {
269
+ "param": "value"
270
+ }
271
+ EOF
272
+ ${binaryRelPath} run <action-id> --input-file /tmp/input.json
273
+ \`\`\`
274
+
275
+ 亦可通过内联参数进行简易命令调用:
276
+
277
+ \`\`\`bash
278
+ ${binaryRelPath} run ${firstAction} --input '{"param": "value"}'
279
+ \`\`\`
280
+
281
+ ### 结构化响应解析
282
+
283
+ 所有 Action 执行结果均在 \`stdout\` 输出标准格式的 JSON 结果:
284
+
285
+ \`\`\`json
286
+ // 执行成功响应 (ok 为 true)
287
+ {
288
+ "ok": true,
289
+ "runId": "01J...",
290
+ "data": { ... }
291
+ }
292
+
293
+ // 执行失败响应 (ok 为 false)
294
+ {
295
+ "ok": false,
296
+ "runId": "01J...",
297
+ "error": {
298
+ "code": "ACTION_EXECUTION_FAILED",
299
+ "message": "错误详细描述信息"
300
+ }
301
+ }
302
+ \`\`\`
303
+
304
+ - \`stdout\`:标准 JSON 结果信封。当 \`ok\` 为 \`true\` 时,从 \`data\` 提取业务数据;当 \`ok\` 为 \`false\` 时,从 \`error\` 读取错误原因以处理异常。
305
+ - \`stderr\`:执行日志与诊断信息。
306
+ ${playbookSection}
307
+ ---
308
+
309
+ ## Action 目录
310
+
311
+ ${actionListMd}
312
+
313
+ ---
314
+
315
+ ## 运行时配置与持久化状态
316
+
317
+ 程序会自动管理其 SQLite 数据库。如需检查或配置:
318
+
319
+ \`\`\`bash
320
+ # 查看与设置配置项
321
+ ${binaryRelPath} config list
322
+ ${binaryRelPath} config set KEY VALUE
323
+
324
+ # 查看与检索状态数据
325
+ ${binaryRelPath} state list
326
+ ${binaryRelPath} state get KEY
327
+ \`\`\`
328
+
329
+ ---
330
+
331
+ ## 故障排查与依赖自愈指引(按需查阅)
332
+
333
+ 若在宿主环境中执行时提示模块缺失,在技能根目录下安装生产依赖:
334
+
335
+ \`\`\`bash
336
+ npm install --omit=dev
337
+ \`\`\`
338
+ `;
339
+ }
340
+ export function generateSkillMd(config, actions, playbooks, optionsOrBinaryPath = "./bin/action-bin") {
341
+ if (typeof optionsOrBinaryPath === "string") {
342
+ return generateStandaloneSkillMd(config, actions, playbooks, optionsOrBinaryPath);
343
+ }
344
+ if (optionsOrBinaryPath.mode === "source") {
345
+ return generateSourceSkillMd(config, actions, playbooks);
346
+ }
347
+ return generateStandaloneSkillMd(config, actions, playbooks, optionsOrBinaryPath.binaryRelPath || "./bin/action-bin");
348
+ }
349
+ export const COMPOSITE_CUSTOM_SLOTS = [
350
+ "intro",
351
+ "after-init",
352
+ "after-describe",
353
+ "after-actions",
354
+ "after-playbooks",
355
+ "after-invoke",
356
+ "append",
357
+ ];
358
+ /** 工作区内约定俗成的复合技能自定义说明书文件名。 */
359
+ export const COMPOSITE_CUSTOM_DECLARATION_FILE = "SKILL.custom.md";
360
+ const CUSTOM_SLOT_MARKER_PATTERN = /^\s*<!--\s*actiondock:slot\s+([a-zA-Z][a-zA-Z0-9-]*)\s*-->\s*$/;
361
+ /**
362
+ * 解析自定义说明书正文:以 `<!-- actiondock:slot <name> -->` 标记行分段。
363
+ * 首个标记之前的内容归入 `append` 槽位;未知槽位名直接抛错,避免拼写错误被静默吞掉。
364
+ */
365
+ export function parseCustomSections(source) {
366
+ const sections = [];
367
+ let currentSlot = "append";
368
+ let buffer = [];
369
+ const flush = () => {
370
+ const content = buffer.join("\n").trim();
371
+ buffer = [];
372
+ if (content) {
373
+ sections.push({ slot: currentSlot, content });
374
+ }
375
+ };
376
+ for (const line of source.split(/\r?\n/)) {
377
+ const match = line.match(CUSTOM_SLOT_MARKER_PATTERN);
378
+ if (match) {
379
+ flush();
380
+ const slot = match[1];
381
+ if (!COMPOSITE_CUSTOM_SLOTS.includes(slot)) {
382
+ throw new Error(`Unknown ActionDock custom slot '${match[1]}'. Valid slots: ${COMPOSITE_CUSTOM_SLOTS.join(", ")}`);
383
+ }
384
+ currentSlot = slot;
385
+ continue;
386
+ }
387
+ buffer.push(line);
388
+ }
389
+ flush();
390
+ return sections;
391
+ }
392
+ /**
393
+ * 解析复合技能自定义说明书文件:支持 YAML frontmatter 中的 `description` 覆盖,
394
+ * 正文按槽位标记解析为自定义段落。
395
+ */
396
+ export function parseCustomSkillDeclaration(source) {
397
+ let body = source;
398
+ let description;
399
+ const frontmatter = source.match(/^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/);
400
+ if (frontmatter) {
401
+ body = source.slice(frontmatter[0].length);
402
+ const descLine = frontmatter[1].match(/^description:[ \t]*(.+?)[ \t]*$/m);
403
+ if (descLine) {
404
+ description = descLine[1].replace(/^["']|["']$/g, "");
405
+ }
406
+ }
407
+ return { description, sections: parseCustomSections(body) };
408
+ }
409
+ /**
410
+ * 生成多包聚合的复合模式 SKILL.md 文档。
411
+ */
412
+ export function generateCompositeSkillMd(bundleName, description, packages, options) {
413
+ const cleanName = bundleName.replace(/[^a-zA-Z0-9-_]/g, "-").toLowerCase();
414
+ const samplePkg = packages.find((p) => p.actions && p.actions.length > 0);
415
+ const sampleActionId = samplePkg
416
+ ? `${samplePkg.config.id}/${samplePkg.actions[0].id}`
417
+ : "sample.greet";
418
+ const actionSections = packages
419
+ .map((pkg) => {
420
+ const actList = pkg.actions
421
+ .map((a) => {
422
+ const desc = a.description ? `: ${a.description}` : "";
423
+ return `- \`${pkg.config.id}/${a.id}\`${desc}`;
424
+ })
425
+ .join("\n");
426
+ return `### ${pkg.config.name} (${pkg.config.id})\n${actList || "- 无可用 Action"}`;
427
+ })
428
+ .join("\n\n");
429
+ const playbookEntries = [];
430
+ const packagesBaseDir = options?.packagesBaseDir ?? "packages";
431
+ for (const pkg of packages) {
432
+ for (const pb of pkg.playbooks) {
433
+ const relPath = packagesBaseDir === "."
434
+ ? `./${pkg.packageDir}/playbooks/${basename(pb.filePath)}`
435
+ : `packages/${pkg.packageDir}/playbooks/${basename(pb.filePath)}`;
436
+ playbookEntries.push(`- [${pb.name || pb.id}](${relPath}): ${pb.description || "标准操作规程"}`);
437
+ }
438
+ }
439
+ const sIntro = `---
440
+ name: ${cleanName}
441
+ description: ${description}
442
+ ---
443
+
444
+ # ${bundleName} 复合技能套件
445
+
446
+ ${description}`;
447
+ const sInit = `## ActionDock 运行时初始化
448
+
449
+ 本技能为 **ActionDock 复合工作区技能包**,聚合了多个功能包。智能体在初次调用或初始化时,在当前技能根目录执行注册命令:
450
+
451
+ \`\`\`bash
452
+ ad link "<skill_root>"
453
+ \`\`\`
454
+
455
+ > \`ad link\` 会自动识别并注册工作区下的所有子包,使其中的 Action 随时可以通过完全限定标识调用。若初次运行提示依赖缺失,可在 \`<skill_root>\` 目录下执行 \`npm install --omit=dev\` 安装聚合依赖。`;
456
+ const sDescribe = `## 动作参数契约按需调阅
457
+
458
+ 为节省上下文开销,各 Action 的详细参数结构不静态内嵌在说明书中。在调用未知参数的 Action 前,可在终端执行命令查阅输入输出约束:
459
+
460
+ \`\`\`bash
461
+ ad describe ${sampleActionId}
462
+ \`\`\``;
463
+ const sActions = `## 可用 Action 工具清单
464
+
465
+ ${actionSections}
466
+
467
+ ---`;
468
+ const sPlaybooks = playbookEntries.length > 0
469
+ ? `## 推荐操作规程
470
+
471
+ 涉及多步骤或业务流程时,优先遵循以下原位规程:
472
+
473
+ ${playbookEntries.join("\n")}
474
+
475
+ ---`
476
+ : "";
477
+ const sInvoke = `## 标准调用命令
478
+
479
+ 推荐使用参数文件传递内容,杜绝终端引号转义问题:
480
+
481
+ \`\`\`bash
482
+ cat << 'EOF' > /tmp/input.json
483
+ {
484
+ "param": "value"
485
+ }
486
+ EOF
487
+ ad run ${sampleActionId} --input-file /tmp/input.json
488
+ \`\`\`
489
+
490
+ ### 结构化响应解析
491
+
492
+ 所有 Action 执行结果均在 \`stdout\` 输出标准格式的 JSON 信封:
493
+
494
+ \`\`\`json
495
+ // 执行成功响应 (ok 为 true)
496
+ {
497
+ "ok": true,
498
+ "runId": "01J...",
499
+ "data": { ... }
500
+ }
501
+
502
+ // 执行失败响应 (ok 为 false)
503
+ {
504
+ "ok": false,
505
+ "runId": "01J...",
506
+ "error": {
507
+ "code": "ACTION_EXECUTION_FAILED",
508
+ "message": "错误详细描述信息"
509
+ }
510
+ }
511
+ \`\`\``;
512
+ const sTroubleshooting = `---
513
+
514
+ ## 故障排查与环境安装指引(按需查阅)
515
+
516
+ > [!NOTE]
517
+ > **按需排查原则**:默认宿主环境中已预置 \`ad\` 命令行工具与 Node.js 运行环境。正常执行流程直接调用上述 Action 即可,**严禁在任务启动前盲目进行前置环境检查或体检**;仅在终端明确报错提示命令不存在(如 \`ad: command not found\`)或提示依赖缺失时,方可按本节指引安装初始化。
518
+
519
+ ### 命令行工具与环境依赖未就绪时的安装指引
520
+
521
+ 若宿主环境未安装 \`ad\` 命令行工具或依赖缺失,请依次按如下步骤完成安装:
522
+
523
+ - **环境要求**:Node.js 版本大于等于 24.12.0(执行 \`node -v\` 确认)。
524
+ - **全局安装 ActionDock 命令行工具**:
525
+ \`\`\`bash
526
+ npm install -g @actiondock/cli
527
+ \`\`\`
528
+ - **安装复合技能聚合依赖**:
529
+ 若在技能目录内调用时提示模块缺失,在 \`<skill_root>\` 目录下安装生产依赖:
530
+ \`\`\`bash
531
+ cd "<skill_root>" && npm install --omit=dev
532
+ \`\`\`
533
+ - **验证工具就绪**:
534
+ \`\`\`bash
535
+ ad --version
536
+ \`\`\`
537
+ - **环境诊断与体检**:
538
+ 安装完成后若仍遇到异常,执行体检命令排查:
539
+ \`\`\`bash
540
+ ad doctor
541
+ \`\`\`
542
+ - **完成安装后重新链接复合技能**:
543
+ \`\`\`bash
544
+ ad link "<skill_root>"
545
+ \`\`\``;
546
+ const parts = [
547
+ { slot: "intro", text: sIntro },
548
+ { slot: "after-init", text: sInit },
549
+ { slot: "after-describe", text: sDescribe },
550
+ { slot: "after-actions", text: sActions },
551
+ { slot: "after-playbooks", text: sPlaybooks },
552
+ { slot: "after-invoke", text: sInvoke },
553
+ { slot: "append", text: sTroubleshooting },
554
+ ];
555
+ // 自定义段落按文件顺序插入到对应槽位(倒序插入保证同槽位多段保持先后)
556
+ const customSections = options?.customSections ?? [];
557
+ for (const section of [...customSections].reverse()) {
558
+ const anchorIndex = parts.findIndex((p) => p.slot === section.slot);
559
+ parts.splice(anchorIndex + 1, 0, { slot: section.slot, text: section.content });
560
+ }
561
+ return (parts
562
+ .filter((p) => p.text.trim().length > 0)
563
+ .map((p) => p.text.trim())
564
+ .join("\n\n") + "\n");
565
+ }
566
+ export function generateSkillJson(config, actions, binaryNameOrOptions, target = "host", playbooksList = []) {
567
+ let mode = "source";
568
+ let executable;
569
+ let targetPlatform = target;
570
+ let playbooks = playbooksList;
571
+ if (typeof binaryNameOrOptions === "string") {
572
+ mode = "standalone";
573
+ executable = `./bin/${binaryNameOrOptions}`;
574
+ }
575
+ else if (binaryNameOrOptions && typeof binaryNameOrOptions === "object") {
576
+ mode = binaryNameOrOptions.mode || (binaryNameOrOptions.executable ? "standalone" : "source");
577
+ executable = binaryNameOrOptions.executable;
578
+ targetPlatform = binaryNameOrOptions.target || target;
579
+ if (binaryNameOrOptions.playbooks) {
580
+ playbooks = binaryNameOrOptions.playbooks;
581
+ }
582
+ }
583
+ const manifest = {
584
+ schemaVersion: "2.0.0",
585
+ packageId: config.id,
586
+ name: config.name,
587
+ version: config.version,
588
+ description: config.description,
589
+ mode,
590
+ };
591
+ if (mode === "standalone" && executable) {
592
+ manifest.target = targetPlatform;
593
+ manifest.executable = executable;
594
+ }
595
+ manifest.actions = actions.map((a) => {
596
+ const item = {
597
+ id: a.id,
598
+ };
599
+ if (a.entry) {
600
+ item.entry = a.entry;
601
+ }
602
+ if (a.description) {
603
+ item.description = a.description;
604
+ }
605
+ if (a.inputSchema !== undefined) {
606
+ item.inputSchema = a.inputSchema;
607
+ }
608
+ if (a.outputSchema !== undefined) {
609
+ item.outputSchema = a.outputSchema;
610
+ }
611
+ if (a.uses) {
612
+ item.uses = a.uses;
613
+ }
614
+ if (a.tags) {
615
+ item.tags = a.tags;
616
+ }
617
+ if (a.annotations) {
618
+ item.annotations = a.annotations;
619
+ }
620
+ return item;
621
+ });
622
+ if (playbooks && playbooks.length > 0) {
623
+ manifest.playbooks = playbooks.map((p) => ({
624
+ id: p.id,
625
+ description: p.description,
626
+ entry: `playbooks/${basename(p.filePath)}`,
627
+ }));
628
+ }
629
+ manifest.exportedAt = new Date().toISOString();
630
+ return JSON.stringify(manifest, null, 2) + "\n";
631
+ }
@@ -1 +1 @@
1
- export * from "./intent";
1
+ export * from "./intent.js";
@@ -0,0 +1 @@
1
+ export * from "./intent.js";