@actiondock/core 2.5.1 → 2.6.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 (134) 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 +2 -0
  25. package/dist/errors.js +2 -0
  26. package/dist/execution/service.js +14 -9
  27. package/dist/host/host.d.ts +33 -0
  28. package/dist/host/host.js +222 -362
  29. package/dist/host/routing.d.ts +92 -0
  30. package/dist/host/routing.js +238 -0
  31. package/dist/host/types.d.ts +8 -0
  32. package/dist/ipc/host.js +38 -0
  33. package/dist/platform/types.d.ts +7 -0
  34. package/dist/process/control-arbiter.d.ts +107 -0
  35. package/dist/process/control-arbiter.js +251 -0
  36. package/dist/process/diagnostics-sink.d.ts +26 -0
  37. package/dist/process/diagnostics-sink.js +35 -0
  38. package/dist/process/index.d.ts +7 -0
  39. package/dist/process/index.js +7 -0
  40. package/dist/process/input-dispatcher.d.ts +88 -0
  41. package/dist/process/input-dispatcher.js +240 -0
  42. package/dist/process/managed-record.d.ts +78 -0
  43. package/dist/process/managed-record.js +1 -0
  44. package/dist/process/process-manager.d.ts +15 -56
  45. package/dist/process/process-manager.js +119 -707
  46. package/dist/process/reservation-table.d.ts +39 -0
  47. package/dist/process/reservation-table.js +80 -0
  48. package/dist/process/run-executor.d.ts +16 -0
  49. package/dist/process/run-executor.js +155 -0
  50. package/dist/process/terminal-output-cache.d.ts +66 -0
  51. package/dist/process/terminal-output-cache.js +132 -0
  52. package/dist/profile/client-actions.d.ts +56 -0
  53. package/dist/profile/client-actions.js +215 -0
  54. package/dist/profile/client-config.d.ts +20 -0
  55. package/dist/profile/client-config.js +51 -0
  56. package/dist/profile/client-health.d.ts +14 -0
  57. package/dist/profile/client-health.js +68 -0
  58. package/dist/profile/client-playbooks.d.ts +19 -0
  59. package/dist/profile/client-playbooks.js +36 -0
  60. package/dist/profile/client-query.d.ts +30 -0
  61. package/dist/profile/client-query.js +70 -0
  62. package/dist/profile/client-runs.d.ts +42 -0
  63. package/dist/profile/client-runs.js +58 -0
  64. package/dist/profile/client-state.d.ts +56 -0
  65. package/dist/profile/client-state.js +83 -0
  66. package/dist/profile/client-transport.d.ts +61 -0
  67. package/dist/profile/client-transport.js +155 -0
  68. package/dist/profile/client.d.ts +23 -142
  69. package/dist/profile/client.js +28 -588
  70. package/dist/profile/manager.js +1 -1
  71. package/dist/project/closure.d.ts +4 -4
  72. package/dist/project/closure.js +11 -5
  73. package/dist/project/init.js +2 -2
  74. package/dist/project/loader.d.ts +0 -25
  75. package/dist/project/loader.js +1 -154
  76. package/dist/project/transactions.d.ts +12 -14
  77. package/dist/project/transactions.js +60 -836
  78. package/dist/registry/registry.js +6 -4
  79. package/dist/registry/resolve.js +1 -1
  80. package/dist/runtime/action-registry.d.ts +45 -0
  81. package/dist/runtime/action-registry.js +108 -0
  82. package/dist/runtime/clock.d.ts +5 -17
  83. package/dist/runtime/clock.js +5 -15
  84. package/dist/runtime/context.d.ts +3 -0
  85. package/dist/runtime/context.js +17 -56
  86. package/dist/runtime/index.d.ts +3 -0
  87. package/dist/runtime/index.js +3 -0
  88. package/dist/runtime/package-runner-factory.d.ts +82 -0
  89. package/dist/runtime/package-runner-factory.js +186 -0
  90. package/dist/runtime/run-persistence.d.ts +85 -0
  91. package/dist/runtime/run-persistence.js +111 -0
  92. package/dist/runtime/runner.d.ts +23 -33
  93. package/dist/runtime/runner.js +92 -286
  94. package/dist/runtime/standalone.d.ts +11 -1
  95. package/dist/runtime/standalone.js +137 -25
  96. package/dist/server/dispatcher.d.ts +8 -3
  97. package/dist/server/dispatcher.js +16 -40
  98. package/dist/server/routes/runs.js +6 -4
  99. package/dist/server/security.d.ts +1 -7
  100. package/dist/server/security.js +2 -13
  101. package/dist/storage/clock.d.ts +25 -0
  102. package/dist/storage/clock.js +23 -0
  103. package/dist/storage/data-dir-lock.d.ts +3 -36
  104. package/dist/storage/data-dir-lock.js +48 -881
  105. package/dist/storage/index.d.ts +8 -1
  106. package/dist/storage/index.js +8 -2
  107. package/dist/storage/lazy.js +1 -0
  108. package/dist/storage/lock-core.d.ts +162 -0
  109. package/dist/storage/lock-core.js +885 -0
  110. package/dist/storage/sqlite.d.ts +19 -6
  111. package/dist/storage/sqlite.js +81 -89
  112. package/dist/storage/types.d.ts +27 -5
  113. package/dist/storage/types.js +21 -0
  114. package/dist/storage/utils.d.ts +22 -0
  115. package/dist/storage/utils.js +34 -0
  116. package/dist/target/local.d.ts +1 -0
  117. package/dist/target/local.js +23 -17
  118. package/dist/target/remote-errors.d.ts +21 -0
  119. package/dist/target/remote-errors.js +51 -0
  120. package/dist/target/remote-polling.d.ts +35 -0
  121. package/dist/target/remote-polling.js +104 -0
  122. package/dist/target/remote.d.ts +4 -0
  123. package/dist/target/remote.js +108 -301
  124. package/dist/target/sse-parser.d.ts +35 -0
  125. package/dist/target/sse-parser.js +163 -0
  126. package/dist/target/target.js +2 -0
  127. package/dist/target/types.d.ts +6 -0
  128. package/dist/utils/index.d.ts +1 -0
  129. package/dist/utils/index.js +1 -0
  130. package/dist/utils/net.d.ts +10 -0
  131. package/dist/utils/net.js +16 -0
  132. package/dist/version.d.ts +1 -1
  133. package/dist/version.js +1 -1
  134. package/package.json +2 -2
@@ -86,10 +86,10 @@ export function initProject(targetDir, options = {}) {
86
86
  node: ">=24.12.0",
87
87
  },
88
88
  dependencies: {
89
- "@actiondock/sdk": "^2.5.1",
89
+ "@actiondock/sdk": "^2.6.0",
90
90
  },
91
91
  devDependencies: {
92
- "@actiondock/testing": "^2.5.1",
92
+ "@actiondock/testing": "^2.6.0",
93
93
  "@types/node": "^22.13.0",
94
94
  "tsx": "^4.19.0",
95
95
  "typescript": "^5.7.0",
@@ -25,30 +25,6 @@ export declare const ALLOWED_INSTALLERS: Set<string>;
25
25
  * - 候选回退优先级探测(npm > bun)。
26
26
  */
27
27
  export declare function getInstallCommand(projectRoot?: string): string[];
28
- /**
29
- * 读取项目当前缓存的依赖指纹哈希。
30
- */
31
- export declare function readStoredDependencyFingerprint(projectRoot: string): string | null;
32
- /**
33
- * 将最新的依赖指纹哈希写入缓存文件。
34
- */
35
- export declare function saveDependencyFingerprint(projectRoot: string, fingerprint: string): void;
36
- /**
37
- * 计算项目依赖的指纹哈希(基于 package.json 依赖声明及可能存在的锁文件内容)。
38
- *
39
- * @param projectRoot 项目根目录
40
- * @returns 64位十六进制哈希字符串,若 package.json 不存在或解析失败则返回 null
41
- */
42
- export declare function computeDependencyFingerprint(projectRoot: string): string | null;
43
- /**
44
- * 确保项目依赖(node_modules)已正确安装。
45
- * 若尚未安装、依赖版本变更(指纹不匹配)或加载失败时,自动触发包管理器执行依赖安装。
46
- *
47
- * @param projectRoot 项目根目录
48
- * @param force 是否强制重新安装
49
- * @returns 是否成功执行了安装或更新
50
- */
51
- export declare function ensureProjectDependencies(projectRoot: string, force?: boolean): boolean;
52
28
  /**
53
29
  * 发现并检索项目 actions 目录下的所有 Action 源码文件(.ts)。
54
30
  *
@@ -67,7 +43,6 @@ export declare function discoverActionFiles(projectRoot: string, actionsDir?: st
67
43
  * @returns Map<ActionId, ActionDefinition> 映射
68
44
  */
69
45
  export declare function loadActions(projectRoot: string, _actionsDir?: string, options?: {
70
- autoInstall?: boolean;
71
46
  loader?: ModuleLoader;
72
47
  }): Promise<Map<string, ActionDefinition>>;
73
48
  /**
@@ -1,6 +1,5 @@
1
1
  import { spawnSync } from "node:child_process";
2
- import { createHash } from "node:crypto";
3
- import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
2
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
4
3
  import { basename, dirname, join, resolve } from "node:path";
5
4
  import { DefaultModuleLoader } from "../runtime/module-loader.js";
6
5
  import { ACTION_LOAD_FAILED, isMissingModuleError } from "../errors.js";
@@ -126,158 +125,6 @@ export function getInstallCommand(projectRoot) {
126
125
  }
127
126
  return ["npm", "install"];
128
127
  }
129
- /**
130
- * 缓存依赖指纹的文件相对路径(位于 node_modules/.cache/actiondock 下)。
131
- * 基于项目绝对路径生成唯一哈希标识,避免软链接共享 node_modules 时指纹冲突。
132
- */
133
- function getDependencyFingerprintPath(projectRoot) {
134
- const projectKey = createHash("sha256").update(resolve(projectRoot)).digest("hex").slice(0, 16);
135
- return join(projectRoot, "node_modules", ".cache", "actiondock", `${projectKey}-deps.hash`);
136
- }
137
- /**
138
- * 读取项目当前缓存的依赖指纹哈希。
139
- */
140
- export function readStoredDependencyFingerprint(projectRoot) {
141
- const fpPath = getDependencyFingerprintPath(projectRoot);
142
- try {
143
- if (existsSync(fpPath)) {
144
- return readFileSync(fpPath, "utf-8").trim();
145
- }
146
- }
147
- catch {
148
- // 忽略读取异常
149
- }
150
- return null;
151
- }
152
- /**
153
- * 将最新的依赖指纹哈希写入缓存文件。
154
- */
155
- export function saveDependencyFingerprint(projectRoot, fingerprint) {
156
- try {
157
- const fpPath = getDependencyFingerprintPath(projectRoot);
158
- const dir = dirname(fpPath);
159
- if (!existsSync(dir)) {
160
- mkdirSync(dir, { recursive: true });
161
- }
162
- writeFileSync(fpPath, fingerprint, "utf-8");
163
- }
164
- catch {
165
- // 忽略写入异常(如只读文件系统或权限限制)
166
- }
167
- }
168
- /**
169
- * 递归对对象所有键名进行升序排序,保证 JSON.stringify 序列化结果的唯一性与确定性。
170
- */
171
- function sortObjectKeys(obj) {
172
- if (obj === null || typeof obj !== "object" || Array.isArray(obj)) {
173
- return obj;
174
- }
175
- const sorted = {};
176
- for (const key of Object.keys(obj).sort()) {
177
- sorted[key] = sortObjectKeys(obj[key]);
178
- }
179
- return sorted;
180
- }
181
- /**
182
- * 计算项目依赖的指纹哈希(基于 package.json 依赖声明及可能存在的锁文件内容)。
183
- *
184
- * @param projectRoot 项目根目录
185
- * @returns 64位十六进制哈希字符串,若 package.json 不存在或解析失败则返回 null
186
- */
187
- export function computeDependencyFingerprint(projectRoot) {
188
- const pkgJsonPath = join(projectRoot, "package.json");
189
- if (!existsSync(pkgJsonPath)) {
190
- return null;
191
- }
192
- try {
193
- const raw = readFileSync(pkgJsonPath, "utf-8");
194
- const pkg = JSON.parse(raw);
195
- const depSpec = {
196
- dependencies: pkg.dependencies || {},
197
- devDependencies: pkg.devDependencies || {},
198
- peerDependencies: pkg.peerDependencies || {},
199
- optionalDependencies: pkg.optionalDependencies || {},
200
- overrides: pkg.overrides || {},
201
- resolutions: pkg.resolutions || {},
202
- };
203
- const hash = createHash("sha256");
204
- hash.update(JSON.stringify(sortObjectKeys(depSpec)));
205
- // 锁文件变化(如团队协同合并或手动更新锁文件)同样代表依赖版本变更
206
- const lockFiles = [
207
- "package-lock.json",
208
- "npm-shrinkwrap.json",
209
- "bun.lockb",
210
- "bun.lock",
211
- ];
212
- for (const lockFile of lockFiles) {
213
- const lockPath = join(projectRoot, lockFile);
214
- if (existsSync(lockPath)) {
215
- try {
216
- hash.update(lockFile);
217
- hash.update(readFileSync(lockPath));
218
- }
219
- catch {
220
- // 忽略不可读的锁文件
221
- }
222
- }
223
- }
224
- return hash.digest("hex");
225
- }
226
- catch {
227
- return null;
228
- }
229
- }
230
- /**
231
- * 确保项目依赖(node_modules)已正确安装。
232
- * 若尚未安装、依赖版本变更(指纹不匹配)或加载失败时,自动触发包管理器执行依赖安装。
233
- *
234
- * @param projectRoot 项目根目录
235
- * @param force 是否强制重新安装
236
- * @returns 是否成功执行了安装或更新
237
- */
238
- export function ensureProjectDependencies(projectRoot, force = false) {
239
- if (process.env.ACTIONDOCK_AUTO_INSTALL === "false") {
240
- return false;
241
- }
242
- const pkgJsonPath = join(projectRoot, "package.json");
243
- if (!existsSync(pkgJsonPath)) {
244
- return false;
245
- }
246
- let pkg;
247
- try {
248
- const raw = readFileSync(pkgJsonPath, "utf-8");
249
- pkg = JSON.parse(raw);
250
- }
251
- catch {
252
- return false;
253
- }
254
- const hasDeps = (pkg.dependencies && Object.keys(pkg.dependencies).length > 0) ||
255
- (pkg.devDependencies && Object.keys(pkg.devDependencies).length > 0) ||
256
- (pkg.peerDependencies && Object.keys(pkg.peerDependencies).length > 0) ||
257
- (pkg.optionalDependencies && Object.keys(pkg.optionalDependencies).length > 0);
258
- if (!hasDeps && !force) {
259
- return false;
260
- }
261
- const nodeModulesPath = join(projectRoot, "node_modules");
262
- const nodeModulesExists = existsSync(nodeModulesPath);
263
- const currentFingerprint = computeDependencyFingerprint(projectRoot);
264
- if (!force && nodeModulesExists) {
265
- const storedFingerprint = readStoredDependencyFingerprint(projectRoot);
266
- if (storedFingerprint === null) {
267
- // 首次接入已包含 node_modules 的外部环境或既有项目,信任现有依赖并记录初始指纹
268
- if (currentFingerprint) {
269
- saveDependencyFingerprint(projectRoot, currentFingerprint);
270
- }
271
- return false;
272
- }
273
- if (currentFingerprint && storedFingerprint === currentFingerprint) {
274
- // 依赖声明与锁文件指纹一致,无需重新安装
275
- return false;
276
- }
277
- }
278
- // ActionDock 2.0 彻底移除运行时静默在线安装依赖逻辑,严禁静默联网安装
279
- return false;
280
- }
281
128
  /**
282
129
  * 递归扫描指定目录下的特定后缀文件(自动排除测试文件 *.test.ts, *.spec.ts 和 *.d.ts)。
283
130
  */
@@ -24,14 +24,6 @@ export interface ProjectTransaction {
24
24
  * 检查当前进程 PID 是否处于活跃运行状态。
25
25
  */
26
26
  export declare function isPidAlive(pid: number): boolean;
27
- /**
28
- * 安全清理陈旧接管守卫(reclaim guard)。
29
- * 采用原子重命名检疫并严格核对 guardToken 与持有者存活状态,确保仅删除目标陈旧 guard,严禁误删活跃守卫或并发新守卫。
30
- *
31
- * @param reclaimPath 目标守卫路径
32
- * @param expectedGuardToken 预期持有的守卫令牌(必填,拒绝未指定令牌的盲目清理)
33
- */
34
- export declare function safeRemoveStaleProjectReclaimGuard(reclaimPath: string, expectedGuardToken: string): void;
35
27
  /**
36
28
  * 从工程锁隔离或回滚临时目录名称中解析操作者 PID 与隔离生成时间戳。
37
29
  * 命名规范:*.(quarantine|rollback|release).<pid>.<timestamp>.<uuid> 或 *.orphan.<timestamp>.<uuid>
@@ -42,21 +34,27 @@ export declare function parseProjectQuarantineTimestamp(entryName: string): {
42
34
  };
43
35
  export declare const parseQuarantineTimestamp: typeof parseProjectQuarantineTimestamp;
44
36
  /**
45
- * 清理过期的工程锁隔离目录(GC 回收机制)。
46
- * 实施分流存活校验,防止误删活跃持锁者与回滚中目录,同时防止孤儿目录无限泄漏:
47
- * - 共同前置条件:存活年龄必须超过 maxAgeMs(默认 10000ms),未超期前严禁清理(保持宽限期)。
48
- * - 活跃隔离目录(quarantine / rollback / release):若 operatorPid 存活或内部 metadata.json 记录的 pid 与 childPids 存活,跳过不予清理。
49
- * - 孤儿脱离目录(orphan):内部旧 metadata.pid 不再作为续命依据;提取其内部 orphanToken,仅当当前规范主路径(主锁目录与 reclaim 目录)依然持有该凭证时保守跳过;规范路径不存在或已变更凭据时直接安全清理。
37
+ * 安全清理陈旧接管守卫(reclaim guard)。
38
+ * 采用原子重命名检疫并严格核对 guardToken 与持有者存活状态,确保仅删除目标陈旧 guard,严禁误删活跃守卫或并发新守卫。
39
+ *
40
+ * @param reclaimPath 目标守卫路径
41
+ * @param expectedGuardToken 预期持有的守卫令牌(必填,拒绝未指定令牌的盲目清理)
50
42
  */
51
- export declare function cleanStaleProjectQuarantines(parentDir: string, basePrefix: string, maxAgeMs?: number, deadline?: number): void;
43
+ export declare function safeRemoveStaleProjectReclaimGuard(reclaimPath: string, expectedGuardToken: string): void;
52
44
  /**
53
45
  * 安全回滚当前进程创建的工程修改锁。
54
46
  * 优先核对 lockToken,回退核对 sessionToken,防止误删接管者或并发新锁。
55
47
  */
56
48
  export declare function safeRollbackProjectLock(lockPath: string, expectedSessionToken: string, expectedLockToken?: string): void;
49
+ /**
50
+ * 清理过期的工程锁隔离目录(GC 回收机制)。
51
+ * 实施分流存活校验,防止误删活跃持锁者与回滚中目录,同时防止孤儿目录无限泄漏,语义由目录锁内核统一承载。
52
+ */
53
+ export declare function cleanStaleProjectQuarantines(parentDir: string, basePrefix: string, maxAgeMs?: number, deadline?: number): void;
57
54
  /**
58
55
  * 安全释放工程主锁。
59
56
  * 仅当锁目录中持有当前 lockToken / sessionToken 时才删除,杜绝删除他人新锁。
57
+ * 释放后同步触发一轮工程锁隔离目录 GC。
60
58
  */
61
59
  export declare function safeReleaseProjectLock(lockPath: string, expectedSessionToken: string, expectedLockToken?: string): void;
62
60
  /**