@actiondock/core 2.5.1 → 2.7.0

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 (175) hide show
  1. package/dist/app/app.d.ts +14 -1
  2. package/dist/app/app.js +88 -222
  3. package/dist/app/static-index.d.ts +39 -0
  4. package/dist/app/static-index.js +164 -0
  5. package/dist/app/types.d.ts +5 -0
  6. package/dist/catalog/action-index.js +6 -4
  7. package/dist/catalog/package-catalog.js +2 -1
  8. package/dist/doctor/checks/index.d.ts +5 -0
  9. package/dist/doctor/checks/index.js +5 -0
  10. package/dist/doctor/checks/project-locate.d.ts +6 -0
  11. package/dist/doctor/checks/project-locate.js +36 -0
  12. package/dist/doctor/checks/project.d.ts +6 -0
  13. package/dist/doctor/checks/project.js +383 -0
  14. package/dist/doctor/checks/registry.d.ts +13 -0
  15. package/dist/doctor/checks/registry.js +207 -0
  16. package/dist/doctor/checks/runtime.d.ts +13 -0
  17. package/dist/doctor/checks/runtime.js +90 -0
  18. package/dist/doctor/checks/storage.d.ts +5 -0
  19. package/dist/doctor/checks/storage.js +34 -0
  20. package/dist/doctor/context.d.ts +35 -0
  21. package/dist/doctor/context.js +11 -0
  22. package/dist/doctor/doctor.d.ts +5 -0
  23. package/dist/doctor/doctor.js +33 -602
  24. package/dist/errors.d.ts +22 -0
  25. package/dist/errors.js +22 -0
  26. package/dist/execution/service.js +14 -9
  27. package/dist/export/templates.js +42 -30
  28. package/dist/host/host.d.ts +33 -0
  29. package/dist/host/host.js +222 -362
  30. package/dist/host/routing.d.ts +92 -0
  31. package/dist/host/routing.js +238 -0
  32. package/dist/host/types.d.ts +8 -0
  33. package/dist/index.d.ts +3 -1
  34. package/dist/index.js +3 -1
  35. package/dist/input/advice.d.ts +100 -0
  36. package/dist/input/advice.js +767 -0
  37. package/dist/input/describe.d.ts +106 -0
  38. package/dist/input/describe.js +176 -0
  39. package/dist/input/file-input.d.ts +54 -0
  40. package/dist/input/file-input.js +124 -0
  41. package/dist/input/flat-decode.d.ts +11 -0
  42. package/dist/input/flat-decode.js +13 -0
  43. package/dist/input/flat-errors.d.ts +72 -0
  44. package/dist/input/flat-errors.js +87 -0
  45. package/dist/input/flat-materializer.d.ts +29 -0
  46. package/dist/input/flat-materializer.js +179 -0
  47. package/dist/input/flat-parser.d.ts +50 -0
  48. package/dist/input/flat-parser.js +169 -0
  49. package/dist/input/flat-predicates.d.ts +34 -0
  50. package/dist/input/flat-predicates.js +50 -0
  51. package/dist/input/index.d.ts +14 -0
  52. package/dist/input/index.js +14 -0
  53. package/dist/input/input-resolver.d.ts +63 -0
  54. package/dist/input/input-resolver.js +254 -0
  55. package/dist/input/json-depth-scanner.d.ts +17 -0
  56. package/dist/input/json-depth-scanner.js +49 -0
  57. package/dist/input/metadata.d.ts +99 -0
  58. package/dist/input/metadata.js +99 -0
  59. package/dist/input/stdin-input.d.ts +26 -0
  60. package/dist/input/stdin-input.js +125 -0
  61. package/dist/input/utf8.d.ts +19 -0
  62. package/dist/input/utf8.js +36 -0
  63. package/dist/input/validation-mapper.d.ts +27 -0
  64. package/dist/input/validation-mapper.js +144 -0
  65. package/dist/ipc/host.js +38 -0
  66. package/dist/json/index.d.ts +1 -0
  67. package/dist/json/index.js +1 -0
  68. package/dist/json/value-validator.d.ts +88 -0
  69. package/dist/json/value-validator.js +330 -0
  70. package/dist/platform/types.d.ts +7 -0
  71. package/dist/process/control-arbiter.d.ts +107 -0
  72. package/dist/process/control-arbiter.js +251 -0
  73. package/dist/process/diagnostics-sink.d.ts +26 -0
  74. package/dist/process/diagnostics-sink.js +35 -0
  75. package/dist/process/index.d.ts +7 -0
  76. package/dist/process/index.js +7 -0
  77. package/dist/process/input-dispatcher.d.ts +88 -0
  78. package/dist/process/input-dispatcher.js +240 -0
  79. package/dist/process/managed-record.d.ts +78 -0
  80. package/dist/process/managed-record.js +1 -0
  81. package/dist/process/process-manager.d.ts +15 -56
  82. package/dist/process/process-manager.js +119 -707
  83. package/dist/process/reservation-table.d.ts +39 -0
  84. package/dist/process/reservation-table.js +80 -0
  85. package/dist/process/run-executor.d.ts +16 -0
  86. package/dist/process/run-executor.js +155 -0
  87. package/dist/process/terminal-output-cache.d.ts +66 -0
  88. package/dist/process/terminal-output-cache.js +132 -0
  89. package/dist/profile/client-actions.d.ts +56 -0
  90. package/dist/profile/client-actions.js +215 -0
  91. package/dist/profile/client-config.d.ts +20 -0
  92. package/dist/profile/client-config.js +51 -0
  93. package/dist/profile/client-health.d.ts +14 -0
  94. package/dist/profile/client-health.js +69 -0
  95. package/dist/profile/client-playbooks.d.ts +19 -0
  96. package/dist/profile/client-playbooks.js +36 -0
  97. package/dist/profile/client-query.d.ts +30 -0
  98. package/dist/profile/client-query.js +70 -0
  99. package/dist/profile/client-runs.d.ts +42 -0
  100. package/dist/profile/client-runs.js +58 -0
  101. package/dist/profile/client-state.d.ts +56 -0
  102. package/dist/profile/client-state.js +83 -0
  103. package/dist/profile/client-transport.d.ts +61 -0
  104. package/dist/profile/client-transport.js +156 -0
  105. package/dist/profile/client.d.ts +23 -142
  106. package/dist/profile/client.js +28 -588
  107. package/dist/profile/manager.js +1 -1
  108. package/dist/project/closure.d.ts +4 -4
  109. package/dist/project/closure.js +11 -5
  110. package/dist/project/init.js +2 -2
  111. package/dist/project/loader.d.ts +0 -25
  112. package/dist/project/loader.js +1 -154
  113. package/dist/project/transactions.d.ts +12 -14
  114. package/dist/project/transactions.js +60 -836
  115. package/dist/registry/registry.js +6 -4
  116. package/dist/registry/resolve.js +1 -1
  117. package/dist/runtime/action-registry.d.ts +45 -0
  118. package/dist/runtime/action-registry.js +108 -0
  119. package/dist/runtime/clock.d.ts +5 -17
  120. package/dist/runtime/clock.js +5 -15
  121. package/dist/runtime/context.d.ts +3 -0
  122. package/dist/runtime/context.js +17 -56
  123. package/dist/runtime/index.d.ts +3 -0
  124. package/dist/runtime/index.js +3 -0
  125. package/dist/runtime/package-runner-factory.d.ts +82 -0
  126. package/dist/runtime/package-runner-factory.js +186 -0
  127. package/dist/runtime/run-persistence.d.ts +85 -0
  128. package/dist/runtime/run-persistence.js +111 -0
  129. package/dist/runtime/runner.d.ts +25 -45
  130. package/dist/runtime/runner.js +130 -354
  131. package/dist/runtime/standalone.d.ts +25 -2
  132. package/dist/runtime/standalone.js +305 -87
  133. package/dist/schema/index.d.ts +1 -0
  134. package/dist/schema/index.js +1 -0
  135. package/dist/schema/validator.d.ts +10 -0
  136. package/dist/schema/validator.js +48 -54
  137. package/dist/server/dispatcher.d.ts +8 -3
  138. package/dist/server/dispatcher.js +16 -40
  139. package/dist/server/routes/runs.js +6 -4
  140. package/dist/server/security.d.ts +1 -7
  141. package/dist/server/security.js +2 -13
  142. package/dist/storage/clock.d.ts +25 -0
  143. package/dist/storage/clock.js +23 -0
  144. package/dist/storage/data-dir-lock.d.ts +3 -36
  145. package/dist/storage/data-dir-lock.js +48 -881
  146. package/dist/storage/index.d.ts +8 -1
  147. package/dist/storage/index.js +8 -2
  148. package/dist/storage/lazy.js +1 -0
  149. package/dist/storage/lock-core.d.ts +162 -0
  150. package/dist/storage/lock-core.js +885 -0
  151. package/dist/storage/sqlite.d.ts +19 -6
  152. package/dist/storage/sqlite.js +81 -89
  153. package/dist/storage/types.d.ts +27 -5
  154. package/dist/storage/types.js +21 -0
  155. package/dist/storage/utils.d.ts +22 -0
  156. package/dist/storage/utils.js +34 -0
  157. package/dist/target/local.d.ts +1 -0
  158. package/dist/target/local.js +23 -17
  159. package/dist/target/remote-errors.d.ts +21 -0
  160. package/dist/target/remote-errors.js +51 -0
  161. package/dist/target/remote-polling.d.ts +35 -0
  162. package/dist/target/remote-polling.js +104 -0
  163. package/dist/target/remote.d.ts +4 -0
  164. package/dist/target/remote.js +108 -301
  165. package/dist/target/sse-parser.d.ts +35 -0
  166. package/dist/target/sse-parser.js +163 -0
  167. package/dist/target/target.js +2 -0
  168. package/dist/target/types.d.ts +6 -0
  169. package/dist/utils/index.d.ts +1 -0
  170. package/dist/utils/index.js +1 -0
  171. package/dist/utils/net.d.ts +10 -0
  172. package/dist/utils/net.js +16 -0
  173. package/dist/version.d.ts +1 -1
  174. package/dist/version.js +1 -1
  175. package/package.json +2 -2
package/dist/errors.js CHANGED
@@ -61,6 +61,8 @@ export const EXECUTION_ABORTED = "EXECUTION_ABORTED";
61
61
  export const TIMEOUT = "TIMEOUT";
62
62
  /** 远程服务器网络连接失败 */
63
63
  export const NETWORK_ERROR = "NETWORK_ERROR";
64
+ /** 远程事件流全部候选路由均不可用 */
65
+ export const REMOTE_STREAM_UNAVAILABLE = "REMOTE_STREAM_UNAVAILABLE";
64
66
  /** 远程目标未启用管理接口能力 */
65
67
  export const CAPABILITY_UNAVAILABLE = "CAPABILITY_UNAVAILABLE";
66
68
  /** 远程状态键不存在 */
@@ -151,6 +153,26 @@ export const QUEUE_FULL = "QUEUE_FULL";
151
153
  export const QUOTA_EXCEEDED = "QUOTA_EXCEEDED";
152
154
  /** 输入通道已关闭拒绝继续写入 */
153
155
  export const INPUT_CLOSED = "INPUT_CLOSED";
156
+ /** 扁平入参赋值表达式格式非法 */
157
+ export const INVALID_FLAT_ARGUMENT = "INVALID_FLAT_ARGUMENT";
158
+ /** 完整 JSON 文档解析失败 */
159
+ export const INVALID_JSON = "INVALID_JSON";
160
+ /** JSON 字面量解析失败或包含非有限数值 */
161
+ export const INVALID_JSON_LITERAL = "INVALID_JSON_LITERAL";
162
+ /** 扁平入参路径冲突 */
163
+ export const INPUT_PATH_CONFLICT = "INPUT_PATH_CONFLICT";
164
+ /** 扁平入参超出安全阈值上限 */
165
+ export const FLAT_INPUT_LIMIT_EXCEEDED = "FLAT_INPUT_LIMIT_EXCEEDED";
166
+ /** 输入数据超出上限(字节大小、嵌套深度等) */
167
+ export const INPUT_LIMIT_EXCEEDED = "INPUT_LIMIT_EXCEEDED";
168
+ /** 输入违反 ActionDock 安全策略(如包含全局禁止属性) */
169
+ export const INPUT_POLICY_VIOLATION = "INPUT_POLICY_VIOLATION";
170
+ /** 输入源互斥冲突 */
171
+ export const INPUT_CONFLICT = "INPUT_CONFLICT";
172
+ /** 输入文件不存在 */
173
+ export const INPUT_FILE_NOT_FOUND = "INPUT_FILE_NOT_FOUND";
174
+ /** 输入文件或流读取失败 */
175
+ export const INPUT_FILE_READ_FAILED = "INPUT_FILE_READ_FAILED";
154
176
  /**
155
177
  * 进程领域结构化异常类。
156
178
  */
@@ -3,7 +3,8 @@ import { ActionResolver } from "../catalog/action-resolver.js";
3
3
  import { computeDigest } from "../project/digest.js";
4
4
  import { InMemoryEventSink } from "../runtime/events.js";
5
5
  import { ActionRunner } from "../runtime/runner.js";
6
- import { ACTION_CANCELLED, ACTION_NOT_FOUND, ACTION_TIMEOUT, EXECUTION_FAILED, IDEMPOTENCY_CONFLICT, RUN_REPOSITORY_UNAVAILABLE, UNHANDLED_EXECUTION_ERROR, describeActionLoadFailure, } from "../errors.js";
6
+ import { ACTION_NOT_FOUND, EXECUTION_FAILED, IDEMPOTENCY_CONFLICT, RUN_REPOSITORY_UNAVAILABLE, UNHANDLED_EXECUTION_ERROR, describeActionLoadFailure, } from "../errors.js";
7
+ import { resultStatusToRunStatus } from "../storage/types.js";
7
8
  /**
8
9
  * 统一执行协调服务实现。
9
10
  */
@@ -49,6 +50,8 @@ export class DefaultExecutionService {
49
50
  options.platform.storage.createStorage(this.packageId, {
50
51
  projectRoot: options.projectRoot,
51
52
  customHome: options.customHome,
53
+ // 执行服务属于数据目录持有者主路径,打开时收割遗留孤儿运行
54
+ recoverOrphans: true,
52
55
  });
53
56
  }
54
57
  else {
@@ -60,7 +63,8 @@ export class DefaultExecutionService {
60
63
  this.storage = options.storage;
61
64
  }
62
65
  const globalStorage = options.platform
63
- ? (options.globalStorage ?? options.platform.storage.createGlobalStorage({ customHome: options.customHome }))
66
+ ? (options.globalStorage ??
67
+ options.platform.storage.createGlobalStorage({ customHome: options.customHome, recoverOrphans: true }))
64
68
  : options.globalStorage;
65
69
  this.ownsStorage = !options.storage;
66
70
  this.ownsGlobalStorage = !options.globalStorage && !!options.platform;
@@ -533,13 +537,7 @@ export class DefaultExecutionService {
533
537
  watchHandleCompletion(handle, activeItem, bridge) {
534
538
  handle.result
535
539
  .then((result) => {
536
- const finalStatus = result.ok
537
- ? "success"
538
- : result.error?.code === ACTION_TIMEOUT
539
- ? "timed_out"
540
- : result.error?.code === ACTION_CANCELLED
541
- ? "cancelled"
542
- : "failed";
540
+ const finalStatus = resultStatusToRunStatus(result.ok, result.ok ? undefined : result.error?.code);
543
541
  activeItem.status = finalStatus;
544
542
  bridge.emitEvent({ type: "status", status: finalStatus });
545
543
  bridge.emitEvent({ type: "finish", result });
@@ -633,6 +631,13 @@ export class DefaultExecutionService {
633
631
  }
634
632
  }
635
633
  this.activeRuns.clear();
634
+ // 级联释放跨包子包 Runner 及其独立创建的存储连接(幂等,异常不阻断后续释放)
635
+ try {
636
+ await this._runner.dispose();
637
+ }
638
+ catch {
639
+ // 子包释放异常已在 dispose 内部隔离,此处仅需保障主流程继续
640
+ }
636
641
  if (this.ownsStorage && this.storage && typeof this.storage.close === "function") {
637
642
  await this.storage.close();
638
643
  }
@@ -124,7 +124,7 @@ ad link "<skill_root>"
124
124
 
125
125
  ### 动作参数契约按需调阅
126
126
 
127
- 在调用未知参数的 Action 前,可在终端执行命令按需查阅该 Action 的输入输出模式与详细说明:
127
+ 在调用未知参数的 Action 前,可在终端执行命令查阅该 Action 的输入输出模式与详细说明:
128
128
 
129
129
  \`\`\`bash
130
130
  ad describe ${pkgId}/${firstAction}
@@ -134,29 +134,28 @@ ad describe ${pkgId}/${firstAction}
134
134
 
135
135
  为避免多技能之间的 Action ID 命名冲突,建议统一使用带有 Package 前缀的完全限定 ID。
136
136
 
137
- 推荐最佳实践:使用文件传递参数,杜绝终端引号转义问题:
137
+ 推荐在执行前调用 describe 命令调阅确切参数契约:
138
138
 
139
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
140
+ # 调阅参数契约与建议赋值样例
141
+ ad describe ${pkgId}/${firstAction}
147
142
  \`\`\`
148
143
 
149
- 亦可通过内联参数进行简易命令调用:
144
+ 调用语法格式:
145
+ ad run ${pkgId}/${firstAction} --json -- ASSIGNMENT...
146
+ (其中 ASSIGNMENT 根据 ad describe ${pkgId}/${firstAction} 查阅的参数契约提供)
147
+
148
+ 将参数写入 JSON 文件并通过 --input-file 传递:
150
149
 
151
150
  \`\`\`bash
152
- ad run ${pkgId}/${firstAction} --input '{"param": "value"}'
151
+ ad run ${pkgId}/${firstAction} --json --input-file input.json
153
152
  \`\`\`
154
153
 
155
- > **免注册本地执行**:
154
+ > 免注册本地执行:
156
155
  > 若工作目录已位于本技能根目录,亦可直接免 link 执行:
157
156
  > \`\`\`bash
158
157
  > cd <skill_root>
159
- > ad run <action-id> --input-file /tmp/input.json
158
+ > ad run ${firstAction} --json
160
159
  > \`\`\`
161
160
 
162
161
  ### 结构化响应解析
@@ -258,24 +257,31 @@ description: ${desc}
258
257
  ${desc}
259
258
 
260
259
 
260
+ ### 动作参数契约按需调阅
261
+
262
+ 在调用未知参数的 Action 前,可在终端执行命令查阅该 Action 的输入输出模式与详细说明:
263
+
264
+ \`\`\`bash
265
+ ${binaryRelPath} describe ${firstAction}
266
+ \`\`\`
267
+
261
268
  ### 执行 Action
262
269
 
263
- 推荐最佳实践:使用文件传递参数,杜绝终端引号转义问题:
270
+ 推荐在执行前调用 describe 命令调阅确切参数契约:
264
271
 
265
272
  \`\`\`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
+ ${binaryRelPath} describe ${firstAction}
273
275
  \`\`\`
274
276
 
275
- 亦可通过内联参数进行简易命令调用:
277
+ 调用语法格式:
278
+ ${binaryRelPath} run ${firstAction} --json -- ASSIGNMENT...
279
+ (其中 ASSIGNMENT 根据 ${binaryRelPath} describe ${firstAction} 查阅的参数契约提供)
280
+
281
+ 将参数写入 JSON 文件并通过 --input-file 传递:
276
282
 
277
283
  \`\`\`bash
278
- ${binaryRelPath} run ${firstAction} --input '{"param": "value"}'
284
+ ${binaryRelPath} run ${firstAction} --json --input-file input.json
279
285
  \`\`\`
280
286
 
281
287
  ### 结构化响应解析
@@ -466,16 +472,22 @@ ${playbookEntries.join("\n")}
466
472
  ---`
467
473
  : "";
468
474
  const sInvoke = `## 标准调用命令
475
+
476
+ 推荐在执行前调用 describe 命令调阅确切参数契约:
469
477
 
470
- 推荐使用参数文件传递内容,杜绝终端引号转义问题:
478
+ \`\`\`bash
479
+ # 调阅参数契约与建议赋值样例
480
+ ad describe ${sampleActionId}
481
+ \`\`\`
471
482
 
483
+ 调用语法格式:
484
+ ad run ${sampleActionId} --json -- ASSIGNMENT...
485
+ (其中 ASSIGNMENT 根据 ad describe ${sampleActionId} 查阅的参数契约提供)
486
+
487
+ 将参数写入 JSON 文件并通过 --input-file 传递:
488
+
472
489
  \`\`\`bash
473
- cat << 'EOF' > /tmp/input.json
474
- {
475
- "param": "value"
476
- }
477
- EOF
478
- ad run ${sampleActionId} --input-file /tmp/input.json
490
+ ad run ${sampleActionId} --json --input-file input.json
479
491
  \`\`\`
480
492
 
481
493
  ### 结构化响应解析
@@ -8,6 +8,7 @@ import type { ActionDockHost, ActionDockHostOptions } from "./types.js";
8
8
  */
9
9
  export declare class DefaultActionDockHost implements ActionDockHost {
10
10
  readonly hostSessionId: string;
11
+ readonly options: ActionDockHostOptions;
11
12
  private apps;
12
13
  private readonly internallyCreatedApps;
13
14
  private activeSubRunsPerRoot;
@@ -19,11 +20,43 @@ export declare class DefaultActionDockHost implements ActionDockHost {
19
20
  private isClosed;
20
21
  private dataDirLock?;
21
22
  private failedLinkedPackages;
23
+ private failedAutoLoad?;
24
+ /** 透传给内部创建 App 的存储收割开关(Host 默认持有者身份,显式可关) */
25
+ private recoverOrphans;
22
26
  constructor(options?: ActionDockHostOptions);
27
+ /**
28
+ * 阶段函数:注册显式传入的 packages 列表(现成 App 实例或 AppOptions 配置)。
29
+ */
30
+ private registerExplicitPackages;
31
+ /**
32
+ * 阶段函数:自动加载当前工程并注册依赖闭包内的全部包。
33
+ *
34
+ * 失败语义区分场景:
35
+ * - 显式传入 projectRoot 时,任何解析失败(损坏 actiondock.json、文件系统错误等)
36
+ * 必须向上抛出,由调用方感知,严禁吞没;
37
+ * - 自动探测场景(未传 projectRoot,由 findProjectRoot 发现)失败时记录实例诊断
38
+ * failedAutoLoad 并在创建时输出单行告警,保持宿主其余能力可用但绝不无声。
39
+ */
40
+ private loadCurrentProject;
41
+ /**
42
+ * 阶段函数:扫描全局注册表中已软链接的外部包并注册至 Host。
43
+ * 加载失败的链接包记录至 failedLinkedPackages 诊断并在调阅时透传精准失败原因。
44
+ */
45
+ private registerLinkedPackages;
23
46
  private resolvePackageContext;
24
47
  private bindApp;
48
+ /** 路由可见性上下文(公开包集合与依赖解析器) */
49
+ private visibility;
25
50
  getApp(packageId: string): ActionDockApp | undefined;
26
51
  listApps(): ActionDockApp[];
52
+ /**
53
+ * 获取自动加载工程的失败诊断信息。
54
+ * 仅自动探测场景会记录此诊断;显式传入 projectRoot 的加载失败会直接抛出,不产生此诊断。
55
+ */
56
+ getAutoLoadFailure(): {
57
+ projectRoot: string;
58
+ error: string;
59
+ } | undefined;
27
60
  private registerAppInternal;
28
61
  registerApp(app: ActionDockApp): void;
29
62
  info(): Promise<PackageInfo[]>;