@actiondock/core 2.10.0 → 2.11.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 (252) hide show
  1. package/README.md +1 -2
  2. package/dist/catalog/action-catalog.js +3 -33
  3. package/dist/catalog/discovery.d.ts +0 -3
  4. package/dist/catalog/discovery.js +4 -4
  5. package/dist/catalog/graph.d.ts +0 -4
  6. package/dist/catalog/graph.js +8 -14
  7. package/dist/{profile/client-actions.d.ts → client/actions.d.ts} +1 -1
  8. package/dist/{profile/client-actions.js → client/actions.js} +2 -8
  9. package/dist/{profile/client-config.d.ts → client/config.d.ts} +1 -1
  10. package/dist/{profile/client-config.js → client/config.js} +1 -1
  11. package/dist/client/dispatcher.d.ts +4 -0
  12. package/dist/client/dispatcher.js +21 -0
  13. package/dist/client/health.d.ts +38 -0
  14. package/dist/{profile/client-health.js → client/health.js} +9 -6
  15. package/dist/client/index.d.ts +16 -0
  16. package/dist/client/index.js +20 -0
  17. package/dist/{profile/client-playbooks.d.ts → client/playbooks.d.ts} +1 -1
  18. package/dist/{profile/client-playbooks.js → client/playbooks.js} +1 -1
  19. package/dist/{profile/client-runs.d.ts → client/runs.d.ts} +4 -2
  20. package/dist/{profile/client-runs.js → client/runs.js} +7 -1
  21. package/dist/{profile/client-state.d.ts → client/state.d.ts} +1 -1
  22. package/dist/{profile/client-state.js → client/state.js} +1 -1
  23. package/dist/{profile/client-transport.d.ts → client/transport.d.ts} +29 -10
  24. package/dist/{profile/client-transport.js → client/transport.js} +125 -35
  25. package/dist/doctor/checks/index.d.ts +1 -1
  26. package/dist/doctor/checks/index.js +1 -1
  27. package/dist/doctor/checks/project.js +20 -88
  28. package/dist/doctor/checks/runtime.d.ts +0 -4
  29. package/dist/doctor/checks/runtime.js +0 -28
  30. package/dist/doctor/doctor.js +1 -2
  31. package/dist/errors.d.ts +53 -3
  32. package/dist/errors.js +53 -3
  33. package/dist/execution/service.d.ts +55 -37
  34. package/dist/execution/service.js +601 -212
  35. package/dist/execution/types.d.ts +24 -5
  36. package/dist/host/host.d.ts +42 -22
  37. package/dist/host/host.js +562 -149
  38. package/dist/host/routing.js +6 -6
  39. package/dist/host/types.d.ts +25 -13
  40. package/dist/index.d.ts +9 -4
  41. package/dist/index.js +5 -2
  42. package/dist/input/advice.d.ts +0 -44
  43. package/dist/input/advice.js +7 -141
  44. package/dist/input/flat-materializer.js +1 -1
  45. package/dist/input/flat-parser.js +1 -1
  46. package/dist/input/index.d.ts +0 -1
  47. package/dist/input/index.js +0 -1
  48. package/dist/input/input-resolver.js +1 -1
  49. package/dist/input/validation-mapper.d.ts +1 -1
  50. package/dist/ipc/diagnostic.d.ts +8 -21
  51. package/dist/ipc/diagnostic.js +24 -57
  52. package/dist/ipc/host.js +21 -7
  53. package/dist/ipc/service.d.ts +14 -0
  54. package/dist/ipc/service.js +132 -26
  55. package/dist/ipc/types.d.ts +0 -4
  56. package/dist/package/index.d.ts +4 -5
  57. package/dist/package/index.js +1 -2
  58. package/dist/package/runtime.d.ts +94 -23
  59. package/dist/package/runtime.js +628 -274
  60. package/dist/package/static-index.d.ts +3 -6
  61. package/dist/package/static-index.js +11 -40
  62. package/dist/package/types.d.ts +19 -4
  63. package/dist/platform/index.d.ts +2 -1
  64. package/dist/platform/index.js +2 -1
  65. package/dist/platform/loader-hook.d.ts +32 -0
  66. package/dist/platform/loader-hook.js +90 -0
  67. package/dist/{node → platform}/module-loader.d.ts +13 -0
  68. package/dist/{node → platform}/module-loader.js +51 -4
  69. package/dist/platform/node.d.ts +19 -8
  70. package/dist/platform/node.js +50 -20
  71. package/dist/platform/types.d.ts +7 -47
  72. package/dist/process/context-process.d.ts +3 -18
  73. package/dist/process/context-process.js +3 -44
  74. package/dist/process/control.d.ts +21 -0
  75. package/dist/process/control.js +34 -0
  76. package/dist/process/converters.d.ts +23 -0
  77. package/dist/process/converters.js +92 -0
  78. package/dist/process/cursor.js +2 -22
  79. package/dist/process/{diagnostics-sink.d.ts → diagnostics.d.ts} +0 -7
  80. package/dist/process/{diagnostics-sink.js → diagnostics.js} +6 -8
  81. package/dist/process/index.d.ts +1 -3
  82. package/dist/process/index.js +1 -3
  83. package/dist/process/input-dispatcher.d.ts +4 -13
  84. package/dist/process/input-dispatcher.js +48 -69
  85. package/dist/process/managed-record.d.ts +3 -31
  86. package/dist/process/metadata-store.d.ts +0 -41
  87. package/dist/process/metadata-store.js +2 -341
  88. package/dist/process/process-driver.js +2 -2
  89. package/dist/process/process-manager.d.ts +8 -50
  90. package/dist/process/process-manager.js +28 -417
  91. package/dist/process/quotas.d.ts +14 -0
  92. package/dist/process/quotas.js +29 -0
  93. package/dist/process/run-executor.js +0 -1
  94. package/dist/process/terminal-output-cache.d.ts +20 -34
  95. package/dist/process/terminal-output-cache.js +43 -64
  96. package/dist/profile/index.d.ts +1 -2
  97. package/dist/profile/index.js +1 -2
  98. package/dist/profile/manager.d.ts +2 -4
  99. package/dist/profile/manager.js +10 -40
  100. package/dist/profile/types.d.ts +1 -17
  101. package/dist/project/digest.d.ts +5 -1
  102. package/dist/project/digest.js +81 -219
  103. package/dist/project/index.d.ts +4 -5
  104. package/dist/project/index.js +4 -5
  105. package/dist/project/init.js +2 -2
  106. package/dist/project/loader.d.ts +3 -3
  107. package/dist/project/loader.js +72 -50
  108. package/dist/project/lockfile.js +6 -5
  109. package/dist/project/manifest.js +5 -4
  110. package/dist/project/transactions.d.ts +4 -42
  111. package/dist/project/transactions.js +83 -138
  112. package/dist/project/types-generator.js +2 -1
  113. package/dist/project/types.d.ts +2 -0
  114. package/dist/registry/index.d.ts +0 -1
  115. package/dist/registry/index.js +0 -1
  116. package/dist/registry/lock.d.ts +2 -11
  117. package/dist/registry/lock.js +14 -183
  118. package/dist/registry/registry.d.ts +1 -6
  119. package/dist/registry/registry.js +5 -17
  120. package/dist/runtime/action-registry.d.ts +1 -5
  121. package/dist/runtime/action-registry.js +0 -12
  122. package/dist/runtime/context.js +2 -2
  123. package/dist/runtime/events.d.ts +11 -50
  124. package/dist/runtime/events.js +88 -368
  125. package/dist/runtime/index.d.ts +0 -4
  126. package/dist/runtime/index.js +0 -4
  127. package/dist/runtime/run-persistence.d.ts +2 -0
  128. package/dist/runtime/run-persistence.js +2 -1
  129. package/dist/runtime/standalone-commands.d.ts +18 -0
  130. package/dist/runtime/standalone-commands.js +466 -0
  131. package/dist/runtime/standalone-help.d.ts +20 -0
  132. package/dist/runtime/standalone-help.js +72 -0
  133. package/dist/runtime/standalone.d.ts +1 -44
  134. package/dist/runtime/standalone.js +32 -573
  135. package/dist/schema/validator.d.ts +2 -2
  136. package/dist/schema/validator.js +2 -9
  137. package/dist/server/index.d.ts +0 -2
  138. package/dist/server/index.js +0 -2
  139. package/dist/server/routes/actions.js +1 -1
  140. package/dist/server/routes/info.js +1 -1
  141. package/dist/server/routes/playbooks.js +1 -1
  142. package/dist/server/routes/runs.js +123 -16
  143. package/dist/server/routes/state.js +43 -18
  144. package/dist/server/security.d.ts +1 -1
  145. package/dist/server/security.js +2 -2
  146. package/dist/server/server.js +3 -7
  147. package/dist/service/factory.js +4 -3
  148. package/dist/service/index.d.ts +1 -1
  149. package/dist/service/index.js +1 -1
  150. package/dist/service/remote-errors.d.ts +1 -1
  151. package/dist/service/remote-errors.js +6 -6
  152. package/dist/service/remote-polling.d.ts +3 -0
  153. package/dist/service/remote-polling.js +10 -5
  154. package/dist/service/remote.d.ts +5 -1
  155. package/dist/service/remote.js +108 -17
  156. package/dist/service/sse-stream.js +2 -2
  157. package/dist/service/types.d.ts +22 -19
  158. package/dist/service/types.js +1 -24
  159. package/dist/storage/clock.d.ts +1 -1
  160. package/dist/storage/clock.js +1 -1
  161. package/dist/storage/data-dir-lock.d.ts +10 -22
  162. package/dist/storage/data-dir-lock.js +28 -56
  163. package/dist/storage/file-lock.d.ts +64 -0
  164. package/dist/storage/file-lock.js +447 -0
  165. package/dist/storage/index.d.ts +2 -2
  166. package/dist/storage/index.js +5 -4
  167. package/dist/storage/run-liveness.d.ts +48 -0
  168. package/dist/storage/run-liveness.js +44 -0
  169. package/dist/storage/sqlite-config.d.ts +16 -0
  170. package/dist/storage/sqlite-config.js +59 -0
  171. package/dist/storage/sqlite-driver.d.ts +3 -1
  172. package/dist/storage/sqlite-driver.js +14 -4
  173. package/dist/storage/sqlite-events.d.ts +13 -0
  174. package/dist/storage/sqlite-events.js +48 -0
  175. package/dist/storage/sqlite-runs.d.ts +107 -0
  176. package/dist/storage/sqlite-runs.js +622 -0
  177. package/dist/storage/sqlite-schema.d.ts +5 -0
  178. package/dist/storage/sqlite-schema.js +143 -0
  179. package/dist/storage/sqlite-state.d.ts +33 -0
  180. package/dist/storage/sqlite-state.js +270 -0
  181. package/dist/storage/sqlite.d.ts +30 -57
  182. package/dist/storage/sqlite.js +84 -741
  183. package/dist/storage/types.d.ts +35 -2
  184. package/dist/utils/index.d.ts +18 -14
  185. package/dist/utils/index.js +37 -29
  186. package/dist/utils/semver.d.ts +18 -0
  187. package/dist/utils/semver.js +19 -0
  188. package/dist/utils/warning.d.ts +1 -0
  189. package/dist/utils/warning.js +52 -0
  190. package/dist/{json/value-validator.d.ts → value-validator.d.ts} +9 -0
  191. package/dist/value-validator.js +330 -0
  192. package/dist/version.d.ts +1 -1
  193. package/dist/version.js +1 -1
  194. package/package.json +10 -12
  195. package/dist/execution/index.d.ts +0 -2
  196. package/dist/execution/index.js +0 -2
  197. package/dist/filter/index.d.ts +0 -1
  198. package/dist/filter/index.js +0 -1
  199. package/dist/graph/index.d.ts +0 -4
  200. package/dist/graph/index.js +0 -4
  201. package/dist/input/metadata.d.ts +0 -99
  202. package/dist/input/metadata.js +0 -99
  203. package/dist/invocation/index.d.ts +0 -2
  204. package/dist/invocation/index.js +0 -2
  205. package/dist/ipc/index.d.ts +0 -4
  206. package/dist/ipc/index.js +0 -4
  207. package/dist/json/index.d.ts +0 -1
  208. package/dist/json/index.js +0 -1
  209. package/dist/json/value-validator.js +0 -330
  210. package/dist/node/index.d.ts +0 -1
  211. package/dist/node/index.js +0 -1
  212. package/dist/platform/node-fs.d.ts +0 -37
  213. package/dist/platform/node-fs.js +0 -81
  214. package/dist/process/control-arbiter.d.ts +0 -108
  215. package/dist/process/control-arbiter.js +0 -250
  216. package/dist/process/process-executor.d.ts +0 -47
  217. package/dist/process/process-executor.js +0 -296
  218. package/dist/profile/client-health.d.ts +0 -14
  219. package/dist/profile/client-query.d.ts +0 -30
  220. package/dist/profile/client-query.js +0 -69
  221. package/dist/profile/client.d.ts +0 -26
  222. package/dist/profile/client.js +0 -31
  223. package/dist/project/closure.d.ts +0 -25
  224. package/dist/project/closure.js +0 -74
  225. package/dist/registry/store.d.ts +0 -42
  226. package/dist/registry/store.js +0 -43
  227. package/dist/runtime/clock.d.ts +0 -7
  228. package/dist/runtime/clock.js +0 -7
  229. package/dist/runtime/module-loader.d.ts +0 -2
  230. package/dist/runtime/module-loader.js +0 -1
  231. package/dist/runtime/process.d.ts +0 -8
  232. package/dist/runtime/process.js +0 -1
  233. package/dist/runtime/runner.d.ts +0 -234
  234. package/dist/runtime/runner.js +0 -609
  235. package/dist/schema/index.d.ts +0 -1
  236. package/dist/schema/index.js +0 -1
  237. package/dist/server/dispatcher.d.ts +0 -25
  238. package/dist/server/dispatcher.js +0 -54
  239. package/dist/service/local.d.ts +0 -27
  240. package/dist/service/local.js +0 -141
  241. package/dist/storage/driver.d.ts +0 -10
  242. package/dist/storage/driver.js +0 -10
  243. package/dist/storage/lazy.d.ts +0 -8
  244. package/dist/storage/lazy.js +0 -45
  245. package/dist/storage/lock-core.d.ts +0 -158
  246. package/dist/storage/lock-core.js +0 -872
  247. package/dist/utils/net.d.ts +0 -10
  248. package/dist/utils/net.js +0 -16
  249. package/dist/utils/process.d.ts +0 -10
  250. package/dist/utils/process.js +0 -21
  251. /package/dist/{filter → utils}/intent.d.ts +0 -0
  252. /package/dist/{filter → utils}/intent.js +0 -0
@@ -1,7 +1,7 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { DefaultActionCatalog, DefaultPackageGraph, parseActionRef, resolveAction, resolvePlaybook, } from "../catalog/index.js";
3
3
  import { InvocationPolicy } from "../invocation/policy.js";
4
- import { ActionDockError, PACKAGE_NOT_FOUND } from "../errors.js";
4
+ import { ActionDockError, PACKAGE_NOT_FOUND, UNDECLARED_ACTION_DEPENDENCY } from "../errors.js";
5
5
  /**
6
6
  * 宽松解析引用:优先结构化解析,失败时按对象或裸短标识符回退。
7
7
  * 委派纯领域解析 parseActionRef 单一事实源。
@@ -92,12 +92,12 @@ export async function describeVisiblePlaybook(runtimes, id, visibility) {
92
92
  if (!isPublic && visibility.graph) {
93
93
  const rootNode = visibility.graph.root ? visibility.graph.getNode(visibility.graph.root.id) : undefined;
94
94
  if (!rootNode?.directDependencies.has(resolved.packageId)) {
95
- throw new Error(`UNDECLARED_ACTION_DEPENDENCY: Playbook '${id}' belongs to undeclared transitive package '${resolved.packageId}'`);
95
+ throw new ActionDockError(UNDECLARED_ACTION_DEPENDENCY, `UNDECLARED_ACTION_DEPENDENCY: Playbook '${id}' belongs to undeclared transitive package '${resolved.packageId}'`);
96
96
  }
97
97
  }
98
98
  const runtime = runtimes.find((a) => a.packageId === resolved.packageId);
99
99
  if (!runtime) {
100
- throw new Error(`Package '${resolved.packageId}' not found in host`);
100
+ throw new ActionDockError(PACKAGE_NOT_FOUND, `Package '${resolved.packageId}' not found in host`);
101
101
  }
102
102
  return runtime.describePlaybook(resolved.playbookId);
103
103
  }
@@ -123,7 +123,7 @@ export function buildRuntimeError(code, message, details) {
123
123
  export async function describeActionAcrossRuntimes(ref, runtimes, visibility, failedLinkedPackages, catalog, graph) {
124
124
  const parsed = parseRefLoose(ref);
125
125
  if (parsed.packageId && failedLinkedPackages.has(parsed.packageId)) {
126
- throw new Error(packageNotFoundMessage(parsed.packageId, failedLinkedPackages));
126
+ throw new ActionDockError(PACKAGE_NOT_FOUND, packageNotFoundMessage(parsed.packageId, failedLinkedPackages));
127
127
  }
128
128
  const effectiveGraph = graph || visibility.graph || buildFallbackGraph(runtimes);
129
129
  const effectiveCatalog = catalog ||
@@ -145,11 +145,11 @@ export async function describeActionAcrossRuntimes(ref, runtimes, visibility, fa
145
145
  throw err;
146
146
  }
147
147
  if (!isRootCallVisible(resolved.package.id, resolved.ref.actionId, visibility.hostPublicPackageIds, effectiveGraph)) {
148
- throw new Error(`UNDECLARED_ACTION_DEPENDENCY: Action '${resolved.package.id}/${resolved.ref.actionId}' is not declared as a direct dependency in actiondock.json and is not delegated by a visible playbook`);
148
+ throw new ActionDockError(UNDECLARED_ACTION_DEPENDENCY, `UNDECLARED_ACTION_DEPENDENCY: Action '${resolved.package.id}/${resolved.ref.actionId}' is not declared as a direct dependency in actiondock.json and is not delegated by a visible playbook`);
149
149
  }
150
150
  const runtime = runtimes.find((a) => a.packageId === resolved.package.id);
151
151
  if (!runtime) {
152
- throw new Error(packageNotFoundMessage(resolved.package.id, failedLinkedPackages));
152
+ throw new ActionDockError(PACKAGE_NOT_FOUND, packageNotFoundMessage(resolved.package.id, failedLinkedPackages));
153
153
  }
154
154
  const spec = await runtime.describeAction(resolved.ref.actionId);
155
155
  return {
@@ -2,11 +2,21 @@ import type { ActionRef, ExecutionEvent, ExecutionResult, JsonValue, Logger, Pro
2
2
  import type { PackageInfo, PackageRuntime, PackageRuntimeOptions, ActionSpec, ActionSummary, ListActionsOptions, PlaybookSpec, PlaybookSummary } from "../package/types.js";
3
3
  import type { CancelResult, ExecutionTicket } from "../execution/types.js";
4
4
  import type { RunOptions } from "../invocation/types.js";
5
- import type { Clock } from "../runtime/clock.js";
5
+ import type { Clock } from "../storage/clock.js";
6
6
  import type { EventSink } from "../runtime/events.js";
7
7
  import type { RuntimePlatform } from "../platform/types.js";
8
- import type { ConfigValueView, ListRunsOptions, StateScopeOptions } from "../service/types.js";
8
+ import type { ActionDockService, ConfigValueView, EventsPort, ListRunsOptions, StateScopeOptions } from "../service/types.js";
9
9
  import type { StateEntry } from "../storage/types.js";
10
+ /**
11
+ * 宿主事件服务端口(既作为独立方法调用,又满足 EventsPort 规范)。
12
+ */
13
+ export interface HostEventsPort extends EventsPort {
14
+ (runId: string, options?: {
15
+ after?: number | string;
16
+ signal?: AbortSignal;
17
+ maxQueueSize?: number;
18
+ }): AsyncIterable<ExecutionEvent>;
19
+ }
10
20
  /**
11
21
  * ActionDock 宿主容器初始化配置选项。
12
22
  */
@@ -45,14 +55,19 @@ export interface ActionDockHostOptions {
45
55
  inMemory?: boolean;
46
56
  /** 事件接收器 */
47
57
  eventSink?: EventSink;
58
+ /** 是否开启配置与状态管理端口(默认 true) */
59
+ enableManagement?: boolean;
48
60
  }
49
61
  /**
50
62
  * ActionDock 多包宿主容器领域契约。
51
63
  * 作为多包环境下的全局协调中枢,负责多包生命周期、完全限定引用路由、依赖校验与配额管理。
64
+ * 同时作为本地默认 ActionDockService 实现,直接挂载 discovery/execution/runs/management 服务端口。
52
65
  */
53
- export interface ActionDockHost {
66
+ export interface ActionDockHost extends ActionDockService {
54
67
  /** 宿主容器初始化配置项(只读) */
55
68
  readonly options?: ActionDockHostOptions;
69
+ /** 统一事件订阅端口(兼作原生订阅函数与事件服务端口) */
70
+ readonly events: HostEventsPort;
56
71
  /** 获取所有已注册包的元数据信息列表 */
57
72
  info(): Promise<PackageInfo[]>;
58
73
  /** 静态列出所有已注册包中可用的 Action 摘要 */
@@ -71,9 +86,11 @@ export interface ActionDockHost {
71
86
  /** 异步启动指定 Action 并立即返回任务执行票据 */
72
87
  startAction(ref: ActionRef | string, input: JsonValue, options?: RunOptions): Promise<ExecutionTicket>;
73
88
  /** 查询指定运行标识的记录详情 */
74
- getRun(runId: string): Promise<RunRecord | undefined>;
89
+ getRun(runId: string, signal?: AbortSignal): Promise<RunRecord | undefined>;
75
90
  /** 列出运行记录 */
76
- listRuns(query?: ListRunsOptions): Promise<RunRecord[]>;
91
+ listRuns(query?: ListRunsOptions, signal?: AbortSignal): Promise<RunRecord[]>;
92
+ /** 统计符合条件的运行记录总数 */
93
+ countRuns(query?: ListRunsOptions, signal?: AbortSignal): Promise<number>;
77
94
  /** 清理运行记录 */
78
95
  clearRuns(options?: {
79
96
  packageId?: string;
@@ -86,12 +103,6 @@ export interface ActionDockHost {
86
103
  cleanExpiredRuns(policy?: import("../storage/types.js").RunsRetentionPolicy): Promise<number>;
87
104
  /** 取消指定在运行的任务 */
88
105
  cancelRun(runId: string, reason?: string): Promise<CancelResult>;
89
- /** 订阅指定运行的事件流 */
90
- events(runId: string, options?: {
91
- after?: number | string;
92
- signal?: AbortSignal;
93
- maxQueueSize?: number;
94
- }): AsyncIterable<ExecutionEvent>;
95
106
  /** 获取配置项视图 */
96
107
  getConfig(packageId: string, key: string): Promise<ConfigValueView>;
97
108
  /** 设置配置项 */
@@ -107,9 +118,9 @@ export interface ActionDockHost {
107
118
  /** 删除状态项 */
108
119
  deleteState(packageId: string, actionId: string, key: string, options?: StateScopeOptions): Promise<boolean>;
109
120
  /** 列出状态项键名 */
110
- listStateKeys(packageId: string, actionId: string, options?: StateScopeOptions): Promise<string[]>;
121
+ listStateKeys(packageId: string, actionId?: string, options?: StateScopeOptions): Promise<string[]>;
111
122
  /** 清理状态项 */
112
- clearState(packageId: string, actionId: string, options?: StateScopeOptions): Promise<number>;
123
+ clearState(packageId: string, actionId?: string, options?: StateScopeOptions): Promise<number>;
113
124
  /** 列出状态项明细 */
114
125
  listStateEntries(packageId: string, options?: any): Promise<StateEntry[]>;
115
126
  /** 根据包唯一标识获取指定 Runtime 实例 */
@@ -120,6 +131,7 @@ export interface ActionDockHost {
120
131
  registerRuntime(runtime: PackageRuntime): void;
121
132
  /** 优雅关闭宿主容器。统一完整关闭所管理的所有 Runtime 实例并安全释放底层资源。 */
122
133
  close(options?: {
134
+ timeoutMs?: number;
123
135
  graceMs?: number;
124
136
  }): Promise<void>;
125
137
  }
package/dist/index.d.ts CHANGED
@@ -5,19 +5,24 @@
5
5
  * 平台大对象驱动与解析器工具移至特定子路径导出(./server, ./project, ./registry,
6
6
  * ./profile, ./graph, ./package),严格杜绝在根导出泄露内部执行与平台上下文机制。
7
7
  */
8
+ export { suppressExperimentalWarnings } from "./utils/warning.js";
8
9
  export { ACTIONDOCK_VERSION } from "./version.js";
9
10
  export { createActionDock, connectActionDock, } from "./service/factory.js";
10
- export type { ActionDockService, ActionDockService as ActionDock, DiscoveryPort, ExecutionPort, RunsPort, EventsPort, RunEventSubscriptionOptions, ConfigPort, StatePort, CreateActionDockOptions, ConnectActionDockOptions, RemoteServiceOptions, ConfigValueView, ListRunsOptions, StateScopeOptions, } from "./service/types.js";
11
- export { DEFAULT_RUNS_RETENTION_MS, DEFAULT_MAX_RUNS_PER_PACKAGE, DEFAULT_MIN_RETAIN_RUNS, type RunsRetentionPolicy, } from "./storage/types.js";
11
+ export type { ActionDockService, ActionDockService as ActionDock, DiscoveryPort, ExecutionPort, RunsPort, EventsPort, RunEventSubscriptionOptions, ConfigPort, StatePort, CreateActionDockOptions, ConnectActionDockOptions, RemoteServiceOptions, ConfigValueView, ListRunsOptions, RunReadOptions, StateScopeOptions, } from "./service/types.js";
12
+ export { isTerminalRunStatus, DEFAULT_RUNS_RETENTION_MS, DEFAULT_MAX_RUNS_PER_PACKAGE, DEFAULT_MIN_RETAIN_RUNS, } from "./storage/types.js";
13
+ export { isRunHostDead } from "./storage/run-liveness.js";
14
+ export type { TerminalRunStatus } from "./storage/types.js";
12
15
  export { parseDuration } from "./utils/index.js";
16
+ export { toSnakeUpperCase, resolveEnvValue } from "./runtime/env.js";
17
+ export type { ResolvedEnv } from "./runtime/env.js";
13
18
  export type { ActionRef, ResolvedActionRef, ExecutionResult, RunRecord, ExecutionEvent, } from "@actiondock/sdk";
14
19
  export type { RunOptions, ExecutionTicket, CancelResult, } from "./execution/types.js";
15
20
  export type { ActionSpec, ActionSummary, PlaybookSpec, PlaybookSummary, PackageInfo, ListActionsOptions, } from "./package/types.js";
16
- export { createNodePlatform, type NodePlatformOptions, } from "./platform/node.js";
21
+ export { createNodePlatform, } from "./platform/node.js";
17
22
  export { startActionDockServer, } from "./server/server.js";
18
23
  export type { ServerOptions, ServerOptions as ActionDockServerOptions, ActionDockServerInstance, } from "./server/types.js";
19
24
  export { initProject } from "./project/init.js";
20
25
  export { loadProjectConfig, findProjectRoot, } from "./project/loader.js";
21
26
  export type { ProjectConfig, } from "./project/types.js";
22
27
  export type { PackageGraph, } from "./catalog/graph.js";
23
- export { ActionDockError, ProcessError, type ErrorCode, type ActionDockErrorCode, PACKAGE_NOT_FOUND, ACTION_PACKAGE_VERSION_CONFLICT, ACTION_NOT_FOUND, ACTION_LOAD_FAILED, ACTION_FAILED, ACTION_TIMEOUT, ACTION_CANCELLED, INPUT_VALIDATION_FAILED, OUTPUT_VALIDATION_FAILED, INPUT_NOT_JSON, OUTPUT_NOT_JSON, ACTION_SUBRUN_LIMIT, ACTION_CALL_CYCLE, UNDECLARED_ACTION_DEPENDENCY, INVALID_ACTION_REF, IDEMPOTENCY_CONFLICT, EXECUTION_FAILED, UNHANDLED_EXECUTION_ERROR, RUN_REPOSITORY_UNAVAILABLE, RUN_PERSISTENCE_FAILED, STANDALONE_ASYNC_UNSUPPORTED, INVOCATION_UNSUPPORTED, HOST_PROCESS_EXITED, EXECUTION_ABORTED, TIMEOUT, NETWORK_ERROR, REMOTE_STREAM_UNAVAILABLE, CAPABILITY_UNAVAILABLE, STATE_KEY_NOT_FOUND, STORAGE_BUSY, PROJECT_BUSY, PROJECT_RECOVERY_REQUIRED, STORAGE_WORKER_EXITED, EVENT_BACKPRESSURE_LIMIT, EVENT_CURSOR_EXPIRED, PROCESS_OUTPUT_LIMIT, PROCESS_SPAWN_ERROR, PROCESS_CANCELLED, PROCESS_TIMEOUT, UNAUTHORIZED, NOT_FOUND, SERVER_ERROR, BAD_REQUEST, PACKAGE_FORBIDDEN, ACTION_FORBIDDEN, PLAYBOOK_NOT_FOUND, REQUEST_TOO_LARGE, ACTION_START_FAILED, ACTION_EXECUTION_ERROR, ACTIONS_LIST_ERROR, PLAYBOOKS_LIST_ERROR, RUNS_LIST_ERROR, RUNS_CLEAR_ERROR, INFO_ERROR, PACKAGES_INFO_ERROR, DOCTOR_ERROR, RUN_INTERRUPTED, CONFIG_ENV_ERROR, CONFIG_LIST_ERROR, CONFIG_SET_ERROR, CONFIG_DELETE_ERROR, STATE_LIST_ERROR, STATE_CLEAR_ERROR, STATE_KEY_ERROR, DATA_DIR_IN_USE, DATA_DIR_RECOVERY_REQUIRED, UNSUPPORTED_STORAGE_SCHEMA, STORED_ERROR_DECODE_FAILED, PROCESS_FAILED, GENERATED_TYPES_OUTDATED, PROTOCOL_UNSUPPORTED, SERVICE_RESULT_UNKNOWN, MCP_TOOL_NAME_COLLISION, ACCESS_DENIED, UNSUPPORTED_CAPABILITY, CONTROL_BUSY, CONTROL_EXPIRED, CONTROL_REVOKED, PROCESS_QUARANTINED, PROCESS_LOST, REQUEST_CONFLICT, INPUT_OUTCOME_UNKNOWN, OUTPUT_GAP, OUTPUT_UNAVAILABLE, INVALID_CURSOR, QUEUE_FULL, QUOTA_EXCEEDED, INPUT_CLOSED, INVALID_FLAT_ARGUMENT, INVALID_JSON, INVALID_JSON_LITERAL, INPUT_PATH_CONFLICT, FLAT_INPUT_LIMIT_EXCEEDED, INPUT_LIMIT_EXCEEDED, INPUT_POLICY_VIOLATION, INPUT_CONFLICT, INPUT_FILE_NOT_FOUND, INPUT_FILE_READ_FAILED, INVALID_ARGUMENT, PACKAGE_NOT_ALLOWED, INVALID_PACKAGE_ID, PATH_TRAVERSAL, AMBIGUOUS_STATE_KEY, RUN_NOT_FOUND, RUN_ALREADY_FINISHED, IPC_ERROR, describeActionLoadFailure, type ActionLoadFailureContext, createErrorEnvelope, type ErrorEnvelope, resolveExecutionHint, } from "./errors.js";
28
+ export { ActionDockError, ProcessError, PACKAGE_NOT_FOUND, ACTION_PACKAGE_VERSION_CONFLICT, ACTION_NOT_FOUND, ACTION_LOAD_FAILED, ACTION_FAILED, ACTION_TIMEOUT, ACTION_CANCELLED, INPUT_VALIDATION_FAILED, OUTPUT_VALIDATION_FAILED, INPUT_NOT_JSON, OUTPUT_NOT_JSON, ACTION_SUBRUN_LIMIT, ACTION_CALL_CYCLE, UNDECLARED_ACTION_DEPENDENCY, INVALID_ACTION_REF, IDEMPOTENCY_CONFLICT, EXECUTION_FAILED, UNHANDLED_EXECUTION_ERROR, RUN_REPOSITORY_UNAVAILABLE, RUN_PERSISTENCE_FAILED, STANDALONE_ASYNC_UNSUPPORTED, HOST_PROCESS_EXITED, EXECUTION_ABORTED, TIMEOUT, NETWORK_ERROR, CAPABILITY_UNAVAILABLE, STATE_KEY_NOT_FOUND, STORAGE_BUSY, PROJECT_BUSY, PROJECT_RECOVERY_REQUIRED, EVENT_BACKPRESSURE_LIMIT, EVENT_CURSOR_EXPIRED, PROCESS_OUTPUT_LIMIT, PROCESS_SPAWN_ERROR, PROCESS_CANCELLED, PROCESS_TIMEOUT, UNAUTHORIZED, NOT_FOUND, SERVER_ERROR, PACKAGE_FORBIDDEN, ACTION_FORBIDDEN, PLAYBOOK_NOT_FOUND, REQUEST_TOO_LARGE, ACTION_START_FAILED, ACTION_EXECUTION_ERROR, DATA_DIR_IN_USE, DATA_DIR_RECOVERY_REQUIRED, PROCESS_FAILED, MCP_TOOL_NAME_COLLISION, ACCESS_DENIED, INVALID_FLAT_ARGUMENT, INVALID_JSON, INVALID_JSON_LITERAL, INPUT_PATH_CONFLICT, FLAT_INPUT_LIMIT_EXCEEDED, INPUT_LIMIT_EXCEEDED, INPUT_POLICY_VIOLATION, INPUT_CONFLICT, INPUT_FILE_NOT_FOUND, INPUT_FILE_READ_FAILED, INVALID_ARGUMENT, PACKAGE_NOT_ALLOWED, INVALID_PACKAGE_ID, PATH_TRAVERSAL, AMBIGUOUS_STATE_KEY, RUN_NOT_FOUND, RUN_ALREADY_FINISHED, PROJECT_ROOT_NOT_FOUND, describeActionLoadFailure, createErrorEnvelope, resolveExecutionHint, } from "./errors.js";
package/dist/index.js CHANGED
@@ -5,12 +5,15 @@
5
5
  * 平台大对象驱动与解析器工具移至特定子路径导出(./server, ./project, ./registry,
6
6
  * ./profile, ./graph, ./package),严格杜绝在根导出泄露内部执行与平台上下文机制。
7
7
  */
8
+ export { suppressExperimentalWarnings } from "./utils/warning.js";
8
9
  // 1. 核心版本号单一事实源
9
10
  export { ACTIONDOCK_VERSION } from "./version.js";
10
11
  // 2. 统一服务门面与聚合契约接口
11
12
  export { createActionDock, connectActionDock, } from "./service/factory.js";
12
- export { DEFAULT_RUNS_RETENTION_MS, DEFAULT_MAX_RUNS_PER_PACKAGE, DEFAULT_MIN_RETAIN_RUNS, } from "./storage/types.js";
13
+ export { isTerminalRunStatus, DEFAULT_RUNS_RETENTION_MS, DEFAULT_MAX_RUNS_PER_PACKAGE, DEFAULT_MIN_RETAIN_RUNS, } from "./storage/types.js";
14
+ export { isRunHostDead } from "./storage/run-liveness.js";
13
15
  export { parseDuration } from "./utils/index.js";
16
+ export { toSnakeUpperCase, resolveEnvValue } from "./runtime/env.js";
14
17
  // 5. 原生平台装配与服务启动
15
18
  export { createNodePlatform, } from "./platform/node.js";
16
19
  export { startActionDockServer, } from "./server/server.js";
@@ -18,4 +21,4 @@ export { startActionDockServer, } from "./server/server.js";
18
21
  export { initProject } from "./project/init.js";
19
22
  export { loadProjectConfig, findProjectRoot, } from "./project/loader.js";
20
23
  // 8. 统一错误模型与核心标准错误码常量
21
- export { ActionDockError, ProcessError, PACKAGE_NOT_FOUND, ACTION_PACKAGE_VERSION_CONFLICT, ACTION_NOT_FOUND, ACTION_LOAD_FAILED, ACTION_FAILED, ACTION_TIMEOUT, ACTION_CANCELLED, INPUT_VALIDATION_FAILED, OUTPUT_VALIDATION_FAILED, INPUT_NOT_JSON, OUTPUT_NOT_JSON, ACTION_SUBRUN_LIMIT, ACTION_CALL_CYCLE, UNDECLARED_ACTION_DEPENDENCY, INVALID_ACTION_REF, IDEMPOTENCY_CONFLICT, EXECUTION_FAILED, UNHANDLED_EXECUTION_ERROR, RUN_REPOSITORY_UNAVAILABLE, RUN_PERSISTENCE_FAILED, STANDALONE_ASYNC_UNSUPPORTED, INVOCATION_UNSUPPORTED, HOST_PROCESS_EXITED, EXECUTION_ABORTED, TIMEOUT, NETWORK_ERROR, REMOTE_STREAM_UNAVAILABLE, CAPABILITY_UNAVAILABLE, STATE_KEY_NOT_FOUND, STORAGE_BUSY, PROJECT_BUSY, PROJECT_RECOVERY_REQUIRED, STORAGE_WORKER_EXITED, EVENT_BACKPRESSURE_LIMIT, EVENT_CURSOR_EXPIRED, PROCESS_OUTPUT_LIMIT, PROCESS_SPAWN_ERROR, PROCESS_CANCELLED, PROCESS_TIMEOUT, UNAUTHORIZED, NOT_FOUND, SERVER_ERROR, BAD_REQUEST, PACKAGE_FORBIDDEN, ACTION_FORBIDDEN, PLAYBOOK_NOT_FOUND, REQUEST_TOO_LARGE, ACTION_START_FAILED, ACTION_EXECUTION_ERROR, ACTIONS_LIST_ERROR, PLAYBOOKS_LIST_ERROR, RUNS_LIST_ERROR, RUNS_CLEAR_ERROR, INFO_ERROR, PACKAGES_INFO_ERROR, DOCTOR_ERROR, RUN_INTERRUPTED, CONFIG_ENV_ERROR, CONFIG_LIST_ERROR, CONFIG_SET_ERROR, CONFIG_DELETE_ERROR, STATE_LIST_ERROR, STATE_CLEAR_ERROR, STATE_KEY_ERROR, DATA_DIR_IN_USE, DATA_DIR_RECOVERY_REQUIRED, UNSUPPORTED_STORAGE_SCHEMA, STORED_ERROR_DECODE_FAILED, PROCESS_FAILED, GENERATED_TYPES_OUTDATED, PROTOCOL_UNSUPPORTED, SERVICE_RESULT_UNKNOWN, MCP_TOOL_NAME_COLLISION, ACCESS_DENIED, UNSUPPORTED_CAPABILITY, CONTROL_BUSY, CONTROL_EXPIRED, CONTROL_REVOKED, PROCESS_QUARANTINED, PROCESS_LOST, REQUEST_CONFLICT, INPUT_OUTCOME_UNKNOWN, OUTPUT_GAP, OUTPUT_UNAVAILABLE, INVALID_CURSOR, QUEUE_FULL, QUOTA_EXCEEDED, INPUT_CLOSED, INVALID_FLAT_ARGUMENT, INVALID_JSON, INVALID_JSON_LITERAL, INPUT_PATH_CONFLICT, FLAT_INPUT_LIMIT_EXCEEDED, INPUT_LIMIT_EXCEEDED, INPUT_POLICY_VIOLATION, INPUT_CONFLICT, INPUT_FILE_NOT_FOUND, INPUT_FILE_READ_FAILED, INVALID_ARGUMENT, PACKAGE_NOT_ALLOWED, INVALID_PACKAGE_ID, PATH_TRAVERSAL, AMBIGUOUS_STATE_KEY, RUN_NOT_FOUND, RUN_ALREADY_FINISHED, IPC_ERROR, describeActionLoadFailure, createErrorEnvelope, resolveExecutionHint, } from "./errors.js";
24
+ export { ActionDockError, ProcessError, PACKAGE_NOT_FOUND, ACTION_PACKAGE_VERSION_CONFLICT, ACTION_NOT_FOUND, ACTION_LOAD_FAILED, ACTION_FAILED, ACTION_TIMEOUT, ACTION_CANCELLED, INPUT_VALIDATION_FAILED, OUTPUT_VALIDATION_FAILED, INPUT_NOT_JSON, OUTPUT_NOT_JSON, ACTION_SUBRUN_LIMIT, ACTION_CALL_CYCLE, UNDECLARED_ACTION_DEPENDENCY, INVALID_ACTION_REF, IDEMPOTENCY_CONFLICT, EXECUTION_FAILED, UNHANDLED_EXECUTION_ERROR, RUN_REPOSITORY_UNAVAILABLE, RUN_PERSISTENCE_FAILED, STANDALONE_ASYNC_UNSUPPORTED, HOST_PROCESS_EXITED, EXECUTION_ABORTED, TIMEOUT, NETWORK_ERROR, CAPABILITY_UNAVAILABLE, STATE_KEY_NOT_FOUND, STORAGE_BUSY, PROJECT_BUSY, PROJECT_RECOVERY_REQUIRED, EVENT_BACKPRESSURE_LIMIT, EVENT_CURSOR_EXPIRED, PROCESS_OUTPUT_LIMIT, PROCESS_SPAWN_ERROR, PROCESS_CANCELLED, PROCESS_TIMEOUT, UNAUTHORIZED, NOT_FOUND, SERVER_ERROR, PACKAGE_FORBIDDEN, ACTION_FORBIDDEN, PLAYBOOK_NOT_FOUND, REQUEST_TOO_LARGE, ACTION_START_FAILED, ACTION_EXECUTION_ERROR, DATA_DIR_IN_USE, DATA_DIR_RECOVERY_REQUIRED, PROCESS_FAILED, MCP_TOOL_NAME_COLLISION, ACCESS_DENIED, INVALID_FLAT_ARGUMENT, INVALID_JSON, INVALID_JSON_LITERAL, INPUT_PATH_CONFLICT, FLAT_INPUT_LIMIT_EXCEEDED, INPUT_LIMIT_EXCEEDED, INPUT_POLICY_VIOLATION, INPUT_CONFLICT, INPUT_FILE_NOT_FOUND, INPUT_FILE_READ_FAILED, INVALID_ARGUMENT, PACKAGE_NOT_ALLOWED, INVALID_PACKAGE_ID, PATH_TRAVERSAL, AMBIGUOUS_STATE_KEY, RUN_NOT_FOUND, RUN_ALREADY_FINISHED, PROJECT_ROOT_NOT_FOUND, describeActionLoadFailure, createErrorEnvelope, resolveExecutionHint, } from "./errors.js";
@@ -58,47 +58,3 @@ export declare function buildCliInputAdviceV1(schema: unknown): CliInputAdviceV1
58
58
  * 禁止在本文件另建独立正则分叉。
59
59
  */
60
60
  export declare const FLAT_ENCODING_GUIDELINES: readonly string[];
61
- /**
62
- * 单个字段的输入建议明细。
63
- */
64
- export interface ActionInputFieldAdvice {
65
- /** 字段路径(属性名) */
66
- path: string;
67
- /** 字段类型字符串 */
68
- type: string;
69
- /** 是否为必填字段 */
70
- required: boolean;
71
- /** 字段名是否满足扁平编码安全规范 */
72
- flatSafe: boolean;
73
- /** 编码模板(如 "name=TEXT"、"age:=NUMBER"、"meta:=JSON"),非直接可执行 token */
74
- assignmentTemplate?: string;
75
- /** 人类说明文字,如 "大型结构建议使用 --input-file" */
76
- hint?: string;
77
- /** 字段描述信息 */
78
- description?: string;
79
- }
80
- /**
81
- * Action 输入模式整体编码顾问分析报告。
82
- */
83
- export interface ActionInputAdvice {
84
- /** 根模式是否支持扁平入参赋值(仅当根模式为对象且所有 required 字段均具备 flatSafe 赋值方案时为 true) */
85
- flatSupported: boolean;
86
- /** 是否存在至少一个可扁平化的字段 */
87
- hasFlatFields: boolean;
88
- /** 字段明细清单 */
89
- fields: ActionInputFieldAdvice[];
90
- /** 所有必填字段的编码模板数组 */
91
- requiredTemplates: string[];
92
- /** 可选字段的编码模板数组 */
93
- optionalTemplates: string[];
94
- /** 结构化提示与降级说明清单 */
95
- notes: string[];
96
- }
97
- /**
98
- * 依据 inputSchema 构造统一的 Action 输入编码建议。
99
- *
100
- * @param schema Action 的 inputSchema 定义
101
- * @returns 结构化编码建议报告
102
- */
103
- export declare function buildActionInputAdvice(schema: unknown): ActionInputAdvice;
104
- export { formatActionDetail } from "./describe.js";
@@ -1,4 +1,4 @@
1
- import { isFlatSafePropertyName, isFlatPathPropertyName, isForbiddenActionInputPropertyName, } from "./flat-predicates.js";
1
+ import { isFlatPathPropertyName, isForbiddenActionInputPropertyName, } from "./flat-predicates.js";
2
2
  const RECOGNIZED_SCHEMA_TYPES = new Set([
3
3
  "object",
4
4
  "array",
@@ -440,12 +440,12 @@ export function buildCliInputAdviceV1(schema) {
440
440
  array: {
441
441
  encoding: "json-array",
442
442
  assignmentTemplate: `${key}:=JSON`,
443
- hint: "建议使用 --input-file 或标准输入传递数组结构",
443
+ hint: "Using --input-file or stdin is recommended for arrays",
444
444
  },
445
445
  object: {
446
446
  encoding: "json-object",
447
447
  assignmentTemplate: `${key}:=JSON`,
448
- hint: "大型结构建议使用 --input-file",
448
+ hint: "Using --input-file is recommended for large structures",
449
449
  },
450
450
  };
451
451
  const flatSafeEntry = flatSafeTypeTable[propType];
@@ -575,142 +575,8 @@ export function buildCliInputAdviceV1(schema) {
575
575
  * 禁止在本文件另建独立正则分叉。
576
576
  */
577
577
  export const FLAT_ENCODING_GUIDELINES = [
578
- "字符串: path=TEXT",
579
- "JSON 标量与结构: path:=JSON (例如 count:=1, enabled:=true)",
580
- "数组元素: path.INDEX=... (例如 items.0=first)",
581
- "提示: 复杂嵌套或大段文本建议使用 --input 或 --input-file",
578
+ "Strings: path=TEXT",
579
+ "JSON scalars and structures: path:=JSON (e.g. count:=1, enabled:=true)",
580
+ "Array elements: path.INDEX=... (e.g. items.0=first)",
581
+ "Tip: For complex nested data or long text, using --input or --input-file is recommended",
582
582
  ];
583
- /**
584
- * 构造无扁平能力、无字段明细的空结果建议报告(各降级早退分支共用单一事实源)。
585
- * 键序与既有契约保持一致,禁止调整。
586
- */
587
- function createEmptyFlatAdvice(notes) {
588
- return {
589
- flatSupported: false,
590
- hasFlatFields: false,
591
- fields: [],
592
- requiredTemplates: [],
593
- optionalTemplates: [],
594
- notes,
595
- };
596
- }
597
- /**
598
- * 依据 inputSchema 构造统一的 Action 输入编码建议。
599
- *
600
- * @param schema Action 的 inputSchema 定义
601
- * @returns 结构化编码建议报告
602
- */
603
- export function buildActionInputAdvice(schema) {
604
- if (typeof schema === "boolean") {
605
- if (schema === false) {
606
- return createEmptyFlatAdvice(["布尔模式 false:拒绝所有输入,任何调用参数均判定为非法"]);
607
- }
608
- return createEmptyFlatAdvice([
609
- "布尔模式 true:接受任意合法 JSON 输入;调用时无需指定必填参数,非对象根输入请使用 --input-file 或 --input",
610
- ]);
611
- }
612
- if (!schema || typeof schema !== "object") {
613
- return createEmptyFlatAdvice(["根模式未声明输入字段,直接调用或使用 --input-file / --input '{}'"]);
614
- }
615
- const s = schema;
616
- // 校验根模式是否为 object 类型
617
- if (s.type !== undefined && s.type !== "object") {
618
- return createEmptyFlatAdvice([
619
- `根模式类型为 '${s.type}',不支持扁平赋值,建议使用 --input-file 或 --input`,
620
- ]);
621
- }
622
- const properties = (s.properties || {});
623
- const required = Array.isArray(s.required) ? s.required : [];
624
- const propKeys = Object.keys(properties);
625
- if (propKeys.length === 0) {
626
- return createEmptyFlatAdvice(["根模式无声明属性,不支持扁平赋值,建议使用 --input-file 或 --input '{}'"]);
627
- }
628
- const fields = [];
629
- const requiredTemplates = [];
630
- const optionalTemplates = [];
631
- const notes = [];
632
- for (const key of propKeys) {
633
- const prop = properties[key] || {};
634
- const typeStr = prop.type ? String(prop.type) : "any";
635
- const isReq = required.includes(key);
636
- const isFlatSafe = isFlatSafePropertyName(key);
637
- let assignmentTemplate;
638
- let hint;
639
- if (isFlatSafe) {
640
- // 数组元素标量类型到扁平元素赋值模板的参数表(共用同一守卫与拼接规则)。
641
- // 命中时模板形态为 `${key}.0<operator><占位符>`,未命中回退数组整体 JSON 模板。
642
- const itemsTypeTemplates = {
643
- string: `${key}.0=TEXT`,
644
- number: `${key}.0:=NUMBER`,
645
- integer: `${key}.0:=NUMBER`,
646
- boolean: `${key}.0:=BOOLEAN`,
647
- };
648
- const itemsTemplate = prop.type === "array" && prop.items && typeof prop.items === "object"
649
- ? itemsTypeTemplates[prop.items.type]
650
- : undefined;
651
- if (prop.type === "string") {
652
- assignmentTemplate = `${key}=TEXT`;
653
- }
654
- else if (prop.type === "number" || prop.type === "integer") {
655
- assignmentTemplate = `${key}:=NUMBER`;
656
- }
657
- else if (prop.type === "boolean") {
658
- assignmentTemplate = `${key}:=BOOLEAN`;
659
- }
660
- else if (itemsTemplate) {
661
- assignmentTemplate = itemsTemplate;
662
- }
663
- else if (prop.type === "array") {
664
- assignmentTemplate = `${key}:=JSON`;
665
- hint = "数组结构建议使用 --input-file";
666
- }
667
- else if (prop.type === "object") {
668
- assignmentTemplate = `${key}:=JSON`;
669
- hint = "大型结构建议使用 --input-file";
670
- }
671
- else {
672
- assignmentTemplate = `${key}:=JSON`;
673
- hint = "复杂或未知类型建议使用 --input-file";
674
- }
675
- if (isReq) {
676
- if (assignmentTemplate) {
677
- requiredTemplates.push(assignmentTemplate);
678
- }
679
- }
680
- else {
681
- if (assignmentTemplate) {
682
- optionalTemplates.push(assignmentTemplate);
683
- }
684
- }
685
- }
686
- else {
687
- hint = "包含非安全字符,建议使用 --input-file";
688
- notes.push(`属性 '${key}' 包含非安全字符,不支持扁平赋值,建议使用 --input-file`);
689
- }
690
- fields.push({
691
- path: key,
692
- type: typeStr,
693
- required: isReq,
694
- flatSafe: isFlatSafe,
695
- assignmentTemplate,
696
- hint,
697
- description: prop.description,
698
- });
699
- }
700
- const hasFlatFields = fields.some((f) => f.flatSafe && f.assignmentTemplate !== undefined);
701
- // 仅当根模式为对象且所有 required 字段均具备 flatSafe 赋值方案时为 true
702
- const allRequiredFlatSafe = required.every((reqKey) => {
703
- const f = fields.find((field) => field.path === reqKey);
704
- return f !== undefined && f.flatSafe && f.assignmentTemplate !== undefined;
705
- });
706
- const flatSupported = hasFlatFields && allRequiredFlatSafe;
707
- return {
708
- flatSupported,
709
- hasFlatFields,
710
- fields,
711
- requiredTemplates,
712
- optionalTemplates,
713
- notes,
714
- };
715
- }
716
- export { formatActionDetail } from "./describe.js";
@@ -1,7 +1,7 @@
1
1
  import { inputPathConflict, flatInputLimitExceeded, invalidFlatArgument, } from "./flat-errors.js";
2
2
  import { isForbiddenActionInputPropertyName } from "./flat-predicates.js";
3
3
  import { DEFAULT_MAX_MATERIALIZED_SIZE_BYTES } from "./flat-parser.js";
4
- import { validateJsonValue } from "../json/value-validator.js";
4
+ import { validateJsonValue } from "../value-validator.js";
5
5
  /**
6
6
  * 节点状态枚举(四态节点模型)。
7
7
  */
@@ -1,6 +1,6 @@
1
1
  import { invalidFlatArgument, invalidJsonLiteral, flatInputLimitExceeded, } from "./flat-errors.js";
2
2
  import { isFlatPathPropertyName, isForbiddenActionInputPropertyName, } from "./flat-predicates.js";
3
- import { validateJsonValue } from "../json/value-validator.js";
3
+ import { validateJsonValue } from "../value-validator.js";
4
4
  /** 最大赋值表达式总数 */
5
5
  export const DEFAULT_MAX_ASSIGNMENTS = 1000;
6
6
  /** 最大路径段深度 */
@@ -10,5 +10,4 @@ export * from "./file-input.js";
10
10
  export * from "./stdin-input.js";
11
11
  export * from "./input-resolver.js";
12
12
  export * from "./advice.js";
13
- export * from "./metadata.js";
14
13
  export * from "./describe.js";
@@ -10,5 +10,4 @@ export * from "./file-input.js";
10
10
  export * from "./stdin-input.js";
11
11
  export * from "./input-resolver.js";
12
12
  export * from "./advice.js";
13
- export * from "./metadata.js";
14
13
  export * from "./describe.js";
@@ -1,6 +1,6 @@
1
1
  import { inputConflict, inputLimitExceeded, invalidJson, InputError, FlatInputError, } from "./flat-errors.js";
2
2
  import { decodeFlatInput } from "./flat-decode.js";
3
- import { validateJsonValue, DEFAULT_MAX_JSON_DEPTH, } from "../json/value-validator.js";
3
+ import { validateJsonValue, DEFAULT_MAX_JSON_DEPTH, } from "../value-validator.js";
4
4
  import { scanJsonDepth } from "./json-depth-scanner.js";
5
5
  import { decodeUtf8Strict, stripBom } from "./utf8.js";
6
6
  import { readRegularFileBounded, DEFAULT_MAX_INPUT_BYTES, } from "./file-input.js";
@@ -1,5 +1,5 @@
1
1
  import { InputError, type InputValidationSource } from "./flat-errors.js";
2
- import type { ActionInputValidationResult, JsonValueValidationResult } from "../json/value-validator.js";
2
+ import type { ActionInputValidationResult, JsonValueValidationResult } from "../value-validator.js";
3
3
  /**
4
4
  * 校验失败结构化输入描述。
5
5
  */
@@ -1,39 +1,26 @@
1
1
  import type { Readable, Writable } from "node:stream";
2
2
  /**
3
- * 诊断日志限流排空转发器配置选项。
3
+ * 诊断日志转发器配置选项。
4
4
  */
5
5
  export interface DiagnosticForwarderOptions {
6
- /** 允许转发的累计最大字节数(默认 512 KB) */
7
- maxBytes?: number;
8
- /** 每秒允许转发的最大字节速率(默认 64 KB/秒) */
9
- maxRateBytesPerSec?: number;
10
6
  /** 目标输出流(默认 process.stderr) */
11
7
  target?: Writable;
12
8
  /** 诊断流标识前缀 */
13
9
  prefix?: string;
14
- /** 触发超限截断时的回调通知 */
15
- onTruncated?: (reason: "size_limit" | "rate_limit") => void;
10
+ /** 写入错误处理回调 */
11
+ onError?: (err: Error) => void;
16
12
  }
17
13
  /**
18
- * 诊断流受控转发与限流排空器(DiagnosticForwarder)。
14
+ * 诊断流极简转发器(DiagnosticForwarder)。
19
15
  *
20
- * 职责:
21
- * 1. 独占捕获子进程的标准输出与标准错误流,杜绝第三方代码污染父进程标准协议通道。
22
- * 2. 实时监测字节总量与秒级传输速率上限。
23
- * 3. 达到阈值后立即停止对外转发、向诊断通道记录截断事件。
24
- * 4. 持续以非阻塞方式静默排空后续数据流,避免子进程因管道背压堆积死锁。
16
+ * 将子进程输出流(stdout/stderr)的数据转发至目标流。
17
+ * 严禁静默丢数据,遇到写入异常即时透传。
25
18
  */
26
19
  export declare class DiagnosticForwarder {
27
- private readonly maxBytes;
28
- private readonly maxRateBytesPerSec;
29
20
  private readonly target;
30
21
  private readonly prefix;
31
- private readonly onTruncated?;
32
- private totalBytesEmitted;
33
- private windowStartMs;
34
- private bytesInCurrentWindow;
35
- private truncated;
36
- private attachedStreams;
22
+ private readonly onError?;
23
+ private readonly attachedStreams;
37
24
  constructor(options?: DiagnosticForwarderOptions);
38
25
  /**
39
26
  * 绑定并监听可读流(如 childProcess.stdout 或 childProcess.stderr)。
@@ -1,29 +1,18 @@
1
1
  /**
2
- * 诊断流受控转发与限流排空器(DiagnosticForwarder)。
2
+ * 诊断流极简转发器(DiagnosticForwarder)。
3
3
  *
4
- * 职责:
5
- * 1. 独占捕获子进程的标准输出与标准错误流,杜绝第三方代码污染父进程标准协议通道。
6
- * 2. 实时监测字节总量与秒级传输速率上限。
7
- * 3. 达到阈值后立即停止对外转发、向诊断通道记录截断事件。
8
- * 4. 持续以非阻塞方式静默排空后续数据流,避免子进程因管道背压堆积死锁。
4
+ * 将子进程输出流(stdout/stderr)的数据转发至目标流。
5
+ * 严禁静默丢数据,遇到写入异常即时透传。
9
6
  */
10
7
  export class DiagnosticForwarder {
11
- maxBytes;
12
- maxRateBytesPerSec;
13
8
  target;
14
9
  prefix;
15
- onTruncated;
16
- totalBytesEmitted = 0;
17
- windowStartMs = Date.now();
18
- bytesInCurrentWindow = 0;
19
- truncated = false;
10
+ onError;
20
11
  attachedStreams = new Map();
21
12
  constructor(options = {}) {
22
- this.maxBytes = options.maxBytes ?? 512 * 1024;
23
- this.maxRateBytesPerSec = options.maxRateBytesPerSec ?? 64 * 1024;
24
13
  this.target = options.target ?? process.stderr;
25
14
  this.prefix = options.prefix ?? "";
26
- this.onTruncated = options.onTruncated;
15
+ this.onError = options.onError;
27
16
  }
28
17
  /**
29
18
  * 绑定并监听可读流(如 childProcess.stdout 或 childProcess.stderr)。
@@ -36,52 +25,30 @@ export class DiagnosticForwarder {
36
25
  return;
37
26
  const handler = (chunk) => {
38
27
  const buf = typeof chunk === "string" ? Buffer.from(chunk, "utf-8") : chunk;
39
- const len = buf.length;
40
- // 刷新秒级速率统计窗口
41
- const now = Date.now();
42
- if (now - this.windowStartMs >= 1000) {
43
- this.windowStartMs = now;
44
- this.bytesInCurrentWindow = 0;
45
- }
46
- if (this.truncated) {
47
- // 已截断:仅排空丢弃数据,不转发,保持流处于读取排空状态
48
- return;
49
- }
50
- // 检查容量与速率上限
51
- let exceedReason = null;
52
- if (this.totalBytesEmitted + len > this.maxBytes) {
53
- exceedReason = "size_limit";
54
- }
55
- else if (this.bytesInCurrentWindow + len > this.maxRateBytesPerSec) {
56
- exceedReason = "rate_limit";
57
- }
58
- if (exceedReason) {
59
- this.truncated = true;
60
- const tag = label ? `[${label}] ` : "";
61
- const notice = `\n[Supervisor] ${tag}Diagnostic output exceeded ${exceedReason === "size_limit" ? `size limit (${this.maxBytes} bytes)` : `rate limit (${this.maxRateBytesPerSec} B/s)`}. Forwarding suspended; draining stream.\n`;
62
- try {
63
- this.target.write(notice);
64
- }
65
- catch {
66
- // 忽略写入失败
67
- }
68
- this.onTruncated?.(exceedReason);
69
- return;
70
- }
71
- // 正常转发
72
- this.totalBytesEmitted += len;
73
- this.bytesInCurrentWindow += len;
28
+ const effectivePrefix = this.prefix || (label ? `[${label}] ` : "");
29
+ const data = effectivePrefix
30
+ ? Buffer.concat([Buffer.from(effectivePrefix, "utf-8"), buf])
31
+ : buf;
74
32
  try {
75
- if (this.prefix) {
76
- this.target.write(`${this.prefix}${buf.toString("utf-8")}`);
33
+ this.target.write(data, (err) => {
34
+ if (err) {
35
+ if (this.onError) {
36
+ this.onError(err);
37
+ }
38
+ else {
39
+ this.target.emit("error", err);
40
+ }
41
+ }
42
+ });
43
+ }
44
+ catch (err) {
45
+ if (this.onError) {
46
+ this.onError(err);
77
47
  }
78
48
  else {
79
- this.target.write(buf);
49
+ this.target.emit("error", err);
80
50
  }
81
51
  }
82
- catch {
83
- // 忽略目标写入异常
84
- }
85
52
  };
86
53
  stream.on("data", handler);
87
54
  this.attachedStreams.set(stream, handler);