@actiondock/core 2.0.11 → 2.2.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 (258) 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 +9 -0
  9. package/dist/catalog/action-index.js +93 -0
  10. package/dist/catalog/action-resolver.d.ts +20 -0
  11. package/dist/catalog/action-resolver.js +95 -0
  12. package/dist/catalog/index.d.ts +5 -0
  13. package/dist/catalog/index.js +5 -0
  14. package/dist/catalog/location-registry.d.ts +15 -0
  15. package/dist/catalog/location-registry.js +138 -0
  16. package/dist/catalog/package-catalog.d.ts +7 -0
  17. package/dist/catalog/package-catalog.js +76 -0
  18. package/dist/catalog/types.d.ts +68 -0
  19. package/dist/catalog/types.js +1 -0
  20. package/dist/doctor/doctor.d.ts +7 -0
  21. package/dist/doctor/doctor.js +613 -0
  22. package/dist/doctor/index.d.ts +2 -0
  23. package/dist/doctor/index.js +2 -0
  24. package/dist/doctor/types.d.ts +23 -0
  25. package/dist/doctor/types.js +1 -0
  26. package/dist/errors.d.ts +122 -0
  27. package/dist/errors.js +123 -0
  28. package/dist/execution/index.d.ts +2 -0
  29. package/dist/execution/index.js +2 -0
  30. package/dist/execution/service.d.ts +79 -0
  31. package/dist/execution/service.js +633 -0
  32. package/dist/execution/types.d.ts +131 -0
  33. package/dist/execution/types.js +1 -0
  34. package/dist/export/index.d.ts +1 -0
  35. package/dist/export/index.js +1 -0
  36. package/dist/export/templates.d.ts +71 -0
  37. package/dist/export/templates.js +621 -0
  38. package/dist/filter/index.d.ts +1 -0
  39. package/dist/filter/index.js +1 -0
  40. package/dist/filter/intent.d.ts +33 -0
  41. package/dist/filter/intent.js +123 -0
  42. package/dist/host/host.d.ts +55 -0
  43. package/dist/host/host.js +740 -0
  44. package/dist/host/index.d.ts +2 -0
  45. package/dist/host/index.js +2 -0
  46. package/dist/host/types.d.ts +81 -0
  47. package/dist/host/types.js +1 -0
  48. package/dist/index.d.ts +21 -0
  49. package/dist/index.js +20 -0
  50. package/dist/ipc/diagnostic.d.ts +65 -0
  51. package/dist/ipc/diagnostic.js +129 -0
  52. package/dist/ipc/host.d.ts +7 -0
  53. package/dist/ipc/host.js +93 -0
  54. package/dist/ipc/index.d.ts +4 -0
  55. package/dist/ipc/index.js +4 -0
  56. package/dist/ipc/target.d.ts +56 -0
  57. package/dist/ipc/target.js +297 -0
  58. package/dist/ipc/types.d.ts +42 -0
  59. package/dist/ipc/types.js +1 -0
  60. package/dist/platform/default.d.ts +32 -0
  61. package/dist/platform/default.js +40 -0
  62. package/dist/platform/index.d.ts +3 -0
  63. package/dist/platform/index.js +3 -0
  64. package/dist/platform/node-fs.d.ts +37 -0
  65. package/dist/platform/node-fs.js +81 -0
  66. package/dist/platform/types.d.ts +104 -0
  67. package/dist/platform/types.js +1 -0
  68. package/dist/profile/client.d.ts +162 -0
  69. package/dist/profile/client.js +467 -0
  70. package/dist/profile/index.d.ts +3 -0
  71. package/dist/profile/index.js +3 -0
  72. package/dist/profile/manager.d.ts +47 -0
  73. package/dist/profile/manager.js +294 -0
  74. package/dist/profile/types.d.ts +61 -0
  75. package/dist/profile/types.js +1 -0
  76. package/dist/project/closure.d.ts +25 -0
  77. package/dist/project/closure.js +68 -0
  78. package/dist/project/digest.d.ts +29 -0
  79. package/dist/project/digest.js +324 -0
  80. package/dist/project/index.d.ts +10 -0
  81. package/dist/project/index.js +10 -0
  82. package/dist/project/init.d.ts +26 -0
  83. package/dist/project/init.js +175 -0
  84. package/dist/project/loader.d.ts +99 -0
  85. package/dist/project/loader.js +484 -0
  86. package/dist/project/lockfile.d.ts +55 -0
  87. package/dist/project/lockfile.js +175 -0
  88. package/dist/project/manifest.d.ts +22 -0
  89. package/dist/project/manifest.js +220 -0
  90. package/dist/project/resolver.d.ts +116 -0
  91. package/dist/project/resolver.js +376 -0
  92. package/dist/project/transactions.d.ts +103 -0
  93. package/dist/project/transactions.js +1203 -0
  94. package/dist/project/types-generator.d.ts +33 -0
  95. package/dist/project/types-generator.js +168 -0
  96. package/dist/project/types.d.ts +107 -0
  97. package/dist/project/types.js +1 -0
  98. package/dist/registry/index.d.ts +5 -0
  99. package/dist/registry/index.js +5 -0
  100. package/dist/registry/lock.d.ts +27 -0
  101. package/dist/registry/lock.js +93 -0
  102. package/dist/registry/registry.d.ts +45 -0
  103. package/dist/registry/registry.js +611 -0
  104. package/dist/registry/resolve.d.ts +62 -0
  105. package/dist/registry/resolve.js +195 -0
  106. package/dist/registry/scan.d.ts +38 -0
  107. package/dist/registry/scan.js +135 -0
  108. package/dist/registry/types.d.ts +117 -0
  109. package/dist/registry/types.js +1 -0
  110. package/dist/runtime/action-collection.d.ts +27 -0
  111. package/dist/runtime/action-collection.js +57 -0
  112. package/dist/runtime/clock.d.ts +19 -0
  113. package/dist/runtime/clock.js +17 -0
  114. package/dist/runtime/context.d.ts +86 -0
  115. package/dist/runtime/context.js +242 -0
  116. package/dist/runtime/env.d.ts +56 -0
  117. package/dist/runtime/env.js +159 -0
  118. package/dist/runtime/events.d.ts +93 -0
  119. package/dist/runtime/events.js +604 -0
  120. package/dist/runtime/execution-manager.d.ts +48 -0
  121. package/dist/runtime/execution-manager.js +66 -0
  122. package/dist/runtime/index.d.ts +10 -0
  123. package/dist/runtime/index.js +10 -0
  124. package/dist/runtime/module-loader.d.ts +34 -0
  125. package/dist/runtime/module-loader.js +16 -0
  126. package/dist/runtime/process.d.ts +9 -0
  127. package/dist/runtime/process.js +146 -0
  128. package/dist/runtime/runner.d.ts +293 -0
  129. package/dist/runtime/runner.js +984 -0
  130. package/dist/runtime/standalone.d.ts +89 -0
  131. package/dist/runtime/standalone.js +536 -0
  132. package/dist/schema/validator.d.ts +28 -0
  133. package/dist/schema/validator.js +116 -0
  134. package/dist/server/body.d.ts +40 -0
  135. package/dist/server/body.js +93 -0
  136. package/dist/server/index.d.ts +5 -0
  137. package/dist/server/index.js +5 -0
  138. package/dist/server/routes/actions.d.ts +5 -0
  139. package/dist/server/routes/actions.js +298 -0
  140. package/dist/server/routes/common.d.ts +47 -0
  141. package/dist/server/routes/common.js +104 -0
  142. package/dist/server/routes/config.d.ts +6 -0
  143. package/dist/server/routes/config.js +173 -0
  144. package/dist/server/routes/doctor.d.ts +5 -0
  145. package/dist/server/routes/doctor.js +63 -0
  146. package/dist/server/routes/health.d.ts +5 -0
  147. package/dist/server/routes/health.js +35 -0
  148. package/dist/server/routes/index.d.ts +9 -0
  149. package/dist/server/routes/index.js +9 -0
  150. package/dist/server/routes/info.d.ts +7 -0
  151. package/dist/server/routes/info.js +158 -0
  152. package/dist/server/routes/playbooks.d.ts +5 -0
  153. package/dist/server/routes/playbooks.js +134 -0
  154. package/dist/server/routes/runs.d.ts +5 -0
  155. package/dist/server/routes/runs.js +343 -0
  156. package/dist/server/routes/state.d.ts +6 -0
  157. package/dist/server/routes/state.js +169 -0
  158. package/dist/server/security.d.ts +44 -0
  159. package/dist/server/security.js +101 -0
  160. package/dist/server/server.d.ts +15 -0
  161. package/dist/server/server.js +355 -0
  162. package/dist/server/types.d.ts +78 -0
  163. package/dist/server/types.js +1 -0
  164. package/dist/storage/data-dir-lock.d.ts +119 -0
  165. package/dist/storage/data-dir-lock.js +1016 -0
  166. package/dist/storage/driver.d.ts +9 -0
  167. package/dist/storage/driver.js +59 -0
  168. package/dist/storage/index.d.ts +64 -0
  169. package/dist/storage/index.js +98 -0
  170. package/dist/storage/lazy.d.ts +8 -0
  171. package/dist/storage/lazy.js +44 -0
  172. package/dist/storage/mask.d.ts +26 -0
  173. package/dist/storage/mask.js +48 -0
  174. package/dist/storage/params.d.ts +13 -0
  175. package/dist/storage/params.js +32 -0
  176. package/dist/storage/sqlite.d.ts +79 -0
  177. package/dist/storage/sqlite.js +689 -0
  178. package/dist/storage/types.d.ts +172 -0
  179. package/dist/storage/types.js +14 -0
  180. package/dist/target/index.d.ts +4 -0
  181. package/dist/target/index.js +4 -0
  182. package/dist/target/local.d.ts +52 -0
  183. package/dist/target/local.js +343 -0
  184. package/dist/target/remote.d.ts +76 -0
  185. package/dist/target/remote.js +839 -0
  186. package/dist/target/target.d.ts +6 -0
  187. package/dist/target/target.js +35 -0
  188. package/dist/target/types.d.ts +246 -0
  189. package/dist/target/types.js +34 -0
  190. package/dist/utils/index.d.ts +49 -0
  191. package/dist/utils/index.js +180 -0
  192. package/dist/version.d.ts +4 -0
  193. package/dist/version.js +4 -0
  194. package/package.json +13 -13
  195. package/src/build/index.ts +0 -1
  196. package/src/build/templates.ts +0 -59
  197. package/src/catalog/action-index.ts +0 -92
  198. package/src/catalog/action-resolver.ts +0 -120
  199. package/src/catalog/index.ts +0 -5
  200. package/src/catalog/location-registry.ts +0 -134
  201. package/src/catalog/package-catalog.ts +0 -87
  202. package/src/catalog/types.ts +0 -75
  203. package/src/doctor/doctor.ts +0 -419
  204. package/src/doctor/index.ts +0 -2
  205. package/src/doctor/types.ts +0 -25
  206. package/src/execution/index.ts +0 -2
  207. package/src/execution/service.ts +0 -322
  208. package/src/execution/types.ts +0 -73
  209. package/src/export/index.ts +0 -1
  210. package/src/export/templates.ts +0 -590
  211. package/src/filter/index.ts +0 -1
  212. package/src/filter/intent.ts +0 -154
  213. package/src/index.ts +0 -16
  214. package/src/profile/client.ts +0 -552
  215. package/src/profile/index.ts +0 -3
  216. package/src/profile/manager.ts +0 -341
  217. package/src/profile/types.ts +0 -71
  218. package/src/project/index.ts +0 -4
  219. package/src/project/init.ts +0 -242
  220. package/src/project/loader.ts +0 -479
  221. package/src/project/manifest.ts +0 -299
  222. package/src/project/types.ts +0 -141
  223. package/src/registry/index.ts +0 -2
  224. package/src/registry/registry.ts +0 -940
  225. package/src/registry/types.ts +0 -127
  226. package/src/runtime/clock.ts +0 -41
  227. package/src/runtime/context.ts +0 -259
  228. package/src/runtime/env.ts +0 -172
  229. package/src/runtime/events.ts +0 -142
  230. package/src/runtime/execution-manager.ts +0 -74
  231. package/src/runtime/index.ts +0 -10
  232. package/src/runtime/module-loader.ts +0 -67
  233. package/src/runtime/process.ts +0 -245
  234. package/src/runtime/runner.ts +0 -527
  235. package/src/runtime/standalone.ts +0 -429
  236. package/src/schema/validator.ts +0 -61
  237. package/src/server/body.ts +0 -112
  238. package/src/server/index.ts +0 -7
  239. package/src/server/routes/actions.ts +0 -262
  240. package/src/server/routes/common.ts +0 -126
  241. package/src/server/routes/config.ts +0 -147
  242. package/src/server/routes/doctor.ts +0 -29
  243. package/src/server/routes/health.ts +0 -40
  244. package/src/server/routes/index.ts +0 -9
  245. package/src/server/routes/info.ts +0 -221
  246. package/src/server/routes/playbooks.ts +0 -109
  247. package/src/server/routes/runs.ts +0 -301
  248. package/src/server/routes/state.ts +0 -133
  249. package/src/server/runtime-registry.ts +0 -115
  250. package/src/server/security.ts +0 -115
  251. package/src/server/server.ts +0 -251
  252. package/src/server/types.ts +0 -57
  253. package/src/storage/driver.ts +0 -126
  254. package/src/storage/index.ts +0 -81
  255. package/src/storage/mask.ts +0 -34
  256. package/src/storage/sqlite.ts +0 -714
  257. package/src/storage/types.ts +0 -139
  258. package/src/utils/index.ts +0 -62
@@ -1,3 +0,0 @@
1
- export * from "./types";
2
- export * from "./manager";
3
- export * from "./client";
@@ -1,341 +0,0 @@
1
- import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { toSnakeUpperCase } from "../runtime/env";
4
- import { getActionDockHome } from "../utils";
5
- import type {
6
- ProfileEntry,
7
- ProfilesConfig,
8
- ResolvedTarget,
9
- TokenResolutionSource,
10
- } from "./types";
11
-
12
- const PROFILE_NAME_REGEX = /^[a-zA-Z0-9_\-\.]+$/;
13
-
14
- /**
15
- * 默认初始 Profiles 配置(预设 local 本地环境)。
16
- */
17
- export const DEFAULT_PROFILES_CONFIG: ProfilesConfig = {
18
- currentProfile: "local",
19
- profiles: {
20
- local: {
21
- serverUrl: "local",
22
- description: "Local execution environment",
23
- },
24
- },
25
- };
26
-
27
- /**
28
- * 格式化并规范化 Server URL 地址(自动补齐 http:// 协议头并移除末尾斜杠)。
29
- */
30
- export function normalizeServerUrl(url: string): string {
31
- let cleaned = url.trim().replace(/\/+$/, "");
32
- if (!/^https?:\/\//i.test(cleaned) && cleaned !== "local") {
33
- cleaned = `http://${cleaned}`;
34
- }
35
- return cleaned;
36
- }
37
-
38
- /**
39
- * 获取 profiles.json 配置文件的物理绝对路径(~/.actiondock/profiles.json)。
40
- */
41
- export function getProfilesFilePath(customHome?: string): string {
42
- const baseDir = getActionDockHome(customHome);
43
- return join(baseDir, ".actiondock", "profiles.json");
44
- }
45
-
46
- /**
47
- * 加载并读取 profiles.json 配置文件。
48
- */
49
- export function loadProfiles(customHome?: string): ProfilesConfig {
50
- const filePath = getProfilesFilePath(customHome);
51
- if (!existsSync(filePath)) {
52
- return structuredClone(DEFAULT_PROFILES_CONFIG);
53
- }
54
-
55
- try {
56
- const raw = readFileSync(filePath, "utf-8");
57
- const parsed = JSON.parse(raw);
58
- if (!parsed || typeof parsed !== "object" || !parsed.profiles) {
59
- return structuredClone(DEFAULT_PROFILES_CONFIG);
60
- }
61
- return parsed as ProfilesConfig;
62
- } catch {
63
- return structuredClone(DEFAULT_PROFILES_CONFIG);
64
- }
65
- }
66
-
67
- /**
68
- * 保存并写入 profiles.json 配置文件,并严格限制文件权限为 0600。
69
- */
70
- export function saveProfiles(data: ProfilesConfig, customHome?: string): void {
71
- const filePath = getProfilesFilePath(customHome);
72
- const dir = dirname(filePath);
73
- try {
74
- mkdirSync(dir, { recursive: true, mode: 0o700 });
75
- try {
76
- chmodSync(dir, 0o700);
77
- } catch {
78
- // Ignore on systems where chmod is not supported
79
- }
80
- } catch {
81
- // Ignore
82
- }
83
-
84
- writeFileSync(filePath, JSON.stringify(data, null, 2) + "\n", {
85
- encoding: "utf-8",
86
- mode: 0o600,
87
- });
88
-
89
- try {
90
- chmodSync(filePath, 0o600);
91
- } catch {
92
- // Ignore on systems where chmod is not supported
93
- }
94
- }
95
-
96
- export function addProfile(
97
- name: string,
98
- entry: ProfileEntry,
99
- customHome?: string
100
- ): void {
101
- const trimmedName = name.trim();
102
- if (!trimmedName) {
103
- throw new Error("Profile name cannot be empty");
104
- }
105
- if (!PROFILE_NAME_REGEX.test(trimmedName)) {
106
- throw new Error(
107
- `Invalid profile name '${trimmedName}'. Profile names may only contain letters, numbers, hyphens, underscores, and dots.`
108
- );
109
- }
110
-
111
- const profilesConfig = loadProfiles(customHome);
112
- const normalizedServer = normalizeServerUrl(entry.serverUrl);
113
-
114
- profilesConfig.profiles[trimmedName] = {
115
- serverUrl: normalizedServer,
116
- token: entry.token?.trim() || undefined,
117
- tokenEnv: entry.tokenEnv?.trim() || undefined,
118
- description: entry.description?.trim() || undefined,
119
- };
120
-
121
- saveProfiles(profilesConfig, customHome);
122
- }
123
-
124
- export function removeProfile(name: string, customHome?: string): boolean {
125
- const trimmedName = name.trim();
126
- const profilesConfig = loadProfiles(customHome);
127
-
128
- if (!profilesConfig.profiles[trimmedName]) {
129
- return false;
130
- }
131
-
132
- delete profilesConfig.profiles[trimmedName];
133
- if (profilesConfig.currentProfile === trimmedName) {
134
- profilesConfig.currentProfile = "local";
135
- }
136
-
137
- saveProfiles(profilesConfig, customHome);
138
- return true;
139
- }
140
-
141
- export function useProfile(name: string, customHome?: string): void {
142
- const trimmedName = name.trim();
143
- const profilesConfig = loadProfiles(customHome);
144
-
145
- if (trimmedName !== "local" && !profilesConfig.profiles[trimmedName]) {
146
- throw new Error(
147
- `Profile '${trimmedName}' not found. Use 'ad profile list' to see available profiles or 'ad profile add' to register one.`
148
- );
149
- }
150
-
151
- profilesConfig.currentProfile = trimmedName;
152
- saveProfiles(profilesConfig, customHome);
153
- }
154
-
155
- export function getProfile(
156
- name: string,
157
- customHome?: string
158
- ): ProfileEntry | undefined {
159
- const profilesConfig = loadProfiles(customHome);
160
- return profilesConfig.profiles[name.trim()];
161
- }
162
-
163
- export function listProfiles(
164
- customHome?: string
165
- ): Array<{ name: string; isCurrent: boolean; entry: ProfileEntry }> {
166
- const profilesConfig = loadProfiles(customHome);
167
- const current = profilesConfig.currentProfile || "local";
168
-
169
- const entries: Array<{
170
- name: string;
171
- isCurrent: boolean;
172
- entry: ProfileEntry;
173
- }> = [];
174
-
175
- // Ensure 'local' is listed
176
- if (!profilesConfig.profiles["local"]) {
177
- entries.push({
178
- name: "local",
179
- isCurrent: current === "local",
180
- entry: {
181
- serverUrl: "local",
182
- description: "Local execution environment",
183
- },
184
- });
185
- }
186
-
187
- for (const [name, entry] of Object.entries(profilesConfig.profiles)) {
188
- entries.push({
189
- name,
190
- isCurrent: name === current,
191
- entry,
192
- });
193
- }
194
-
195
- return entries;
196
- }
197
-
198
- /**
199
- * Resolves token following multi-tier precedence:
200
- * 1. CLI explicit --token
201
- * 2. profile.tokenEnv specified environment variable
202
- * 3. Derived profile environment variable: ACTIONDOCK_<PROFILE>_TOKEN or <PROFILE>_TOKEN
203
- * 4. Stored token in profiles.json (deprecated)
204
- * 5. Global ACTIONDOCK_TOKEN
205
- */
206
- export function resolveProfileToken(
207
- profileName?: string,
208
- entry?: ProfileEntry,
209
- explicitToken?: string
210
- ): { token?: string; source: TokenResolutionSource } {
211
- // 1. Explicit CLI --token
212
- if (explicitToken && explicitToken.trim()) {
213
- return { token: explicitToken.trim(), source: "cli" };
214
- }
215
-
216
- // 2. Explicit tokenEnv in profile
217
- if (entry?.tokenEnv && entry.tokenEnv.trim()) {
218
- const envKey = entry.tokenEnv.trim();
219
- const envVal = process.env[envKey];
220
- if (envVal !== undefined && envVal.trim()) {
221
- return { token: envVal.trim(), source: "tokenEnv" };
222
- }
223
- }
224
-
225
- // 3. Derived profile environment variable: ACTIONDOCK_<PROFILE>_TOKEN / <PROFILE>_TOKEN
226
- if (profileName && profileName !== "local") {
227
- const snakeName = toSnakeUpperCase(profileName);
228
- const candidate1 = `ACTIONDOCK_${snakeName}_TOKEN`;
229
- const candidate2 = `${snakeName}_TOKEN`;
230
- if (process.env[candidate1] && process.env[candidate1]!.trim()) {
231
- return { token: process.env[candidate1]!.trim(), source: "profileEnv" };
232
- }
233
- if (process.env[candidate2] && process.env[candidate2]!.trim()) {
234
- return { token: process.env[candidate2]!.trim(), source: "profileEnv" };
235
- }
236
- }
237
-
238
- // 4. Stored token in profiles.json (deprecated fallback)
239
- if (entry?.token && entry.token.trim()) {
240
- return { token: entry.token.trim(), source: "profile" };
241
- }
242
-
243
- // 5. Global ACTIONDOCK_TOKEN
244
- if (process.env.ACTIONDOCK_TOKEN && process.env.ACTIONDOCK_TOKEN.trim()) {
245
- return { token: process.env.ACTIONDOCK_TOKEN.trim(), source: "globalEnv" };
246
- }
247
-
248
- return { token: undefined, source: "none" };
249
- }
250
-
251
- export function resolveTarget(
252
- options?: { profile?: string; server?: string; token?: string },
253
- customHome?: string
254
- ): ResolvedTarget {
255
- // 1. Explicit CLI --server flag
256
- if (options?.server && options.server.trim()) {
257
- const resolvedToken = resolveProfileToken(undefined, undefined, options.token);
258
- return {
259
- type: "remote",
260
- serverUrl: normalizeServerUrl(options.server),
261
- token: resolvedToken.token,
262
- tokenSource: resolvedToken.source,
263
- };
264
- }
265
-
266
- const profilesConfig = loadProfiles(customHome);
267
-
268
- // 2. Explicit CLI --profile flag
269
- if (options?.profile && options.profile.trim()) {
270
- const pName = options.profile.trim();
271
- if (pName === "local") {
272
- return { type: "local", profileName: "local" };
273
- }
274
- const found = profilesConfig.profiles[pName];
275
- if (!found) {
276
- throw new Error(
277
- `Profile '${pName}' not found. Configure it with 'ad profile add ${pName} --server <url>'`
278
- );
279
- }
280
- const resolvedToken = resolveProfileToken(pName, found, options.token);
281
- return {
282
- type: "remote",
283
- profileName: pName,
284
- serverUrl: found.serverUrl,
285
- token: resolvedToken.token,
286
- tokenSource: resolvedToken.source,
287
- };
288
- }
289
-
290
- // 3. Environment variable ACTIONDOCK_SERVER_URL
291
- if (process.env.ACTIONDOCK_SERVER_URL && process.env.ACTIONDOCK_SERVER_URL.trim()) {
292
- const resolvedToken = resolveProfileToken(undefined, undefined, options?.token);
293
- return {
294
- type: "remote",
295
- serverUrl: normalizeServerUrl(process.env.ACTIONDOCK_SERVER_URL),
296
- token: resolvedToken.token,
297
- tokenSource: resolvedToken.source,
298
- };
299
- }
300
-
301
- // 4. Environment variable ACTIONDOCK_PROFILE
302
- if (process.env.ACTIONDOCK_PROFILE && process.env.ACTIONDOCK_PROFILE.trim()) {
303
- const pName = process.env.ACTIONDOCK_PROFILE.trim();
304
- if (pName === "local") {
305
- return { type: "local", profileName: "local" };
306
- }
307
- const found = profilesConfig.profiles[pName];
308
- if (!found) {
309
- throw new Error(
310
- `Profile '${pName}' (from ACTIONDOCK_PROFILE) not found. Configure it with 'ad profile add ${pName} --server <url>'`
311
- );
312
- }
313
- const resolvedToken = resolveProfileToken(pName, found, options?.token);
314
- return {
315
- type: "remote",
316
- profileName: pName,
317
- serverUrl: found.serverUrl,
318
- token: resolvedToken.token,
319
- tokenSource: resolvedToken.source,
320
- };
321
- }
322
-
323
- // 5. Current Profile in config
324
- const current = profilesConfig.currentProfile;
325
- if (current && current !== "local") {
326
- const found = profilesConfig.profiles[current];
327
- if (found && found.serverUrl && found.serverUrl !== "local") {
328
- const resolvedToken = resolveProfileToken(current, found, options?.token);
329
- return {
330
- type: "remote",
331
- profileName: current,
332
- serverUrl: found.serverUrl,
333
- token: resolvedToken.token,
334
- tokenSource: resolvedToken.source,
335
- };
336
- }
337
- }
338
-
339
- // 6. Default to local
340
- return { type: "local", profileName: "local" };
341
- }
@@ -1,71 +0,0 @@
1
- /**
2
- * 单个远端配置环境(Profile)实体定义。
3
- */
4
- export interface ProfileEntry {
5
- /** 远端 ActionDock 服务端地址(如 "http://192.168.1.100:5177" 或 "local") */
6
- serverUrl: string;
7
- /**
8
- * 存储在配置文件中的明文鉴权 Token。
9
- * @deprecated 强烈建议使用 tokenEnv 或标准环境变量(如 ACTIONDOCK_<PROFILE>_TOKEN),避免明文持久化
10
- */
11
- token?: string;
12
- /** 指定从哪一个操作系统环境变量名动态读取 Token */
13
- tokenEnv?: string;
14
- /** 该机器/环境的描述信息 */
15
- description?: string;
16
- }
17
-
18
- /**
19
- * 全局 profiles.json 配置文件结构契约。
20
- */
21
- export interface ProfilesConfig {
22
- /** 当前激活的默认 Profile 名称(默认为 "local") */
23
- currentProfile?: string;
24
- /** 已配置的 Profile 字典映射表 */
25
- profiles: Record<string, ProfileEntry>;
26
- }
27
-
28
- /**
29
- * Token 解析命中来源枚举。
30
- */
31
- export type TokenResolutionSource =
32
- | "cli" // 来源于显式 CLI 参数 (--token)
33
- | "tokenEnv" // 来源于 Profile 显式绑定的 tokenEnv 环境变量
34
- | "profileEnv" // 来源于自动推导的 ACTIONDOCK_<PROFILE>_TOKEN
35
- | "profile" // 来源于 profiles.json 中存储的遗留明文 Token
36
- | "globalEnv" // 来源于全局 ACTIONDOCK_TOKEN
37
- | "none"; // 未配置任何 Token
38
-
39
- /**
40
- * 经过解析后确定的最终执行目标环境。
41
- */
42
- export interface ResolvedTarget {
43
- /** 执行环境类型:local (本地 Bun 进程) 或 remote (远端 HTTP Server) */
44
- type: "local" | "remote";
45
- /** 命中的 Profile 名称 */
46
- profileName?: string;
47
- /** 远端 Server URL */
48
- serverUrl?: string;
49
- /** 解析出的有效鉴权 Token */
50
- token?: string;
51
- /** Token 数据来源 */
52
- tokenSource?: TokenResolutionSource;
53
- }
54
-
55
- /**
56
- * 远端服务器健康探测与时延检测结果。
57
- */
58
- export interface RemoteHealthResult {
59
- /** 服务端是否连通且鉴权成功 */
60
- ok: boolean;
61
- /** 服务端状态标识(如 "ok") */
62
- status?: string;
63
- /** 远端 ActionDock 版本号 */
64
- version?: string;
65
- /** 远端服务运行时间(秒) */
66
- uptime?: number;
67
- /** 网络往返延迟(毫秒) */
68
- latencyMs: number;
69
- /** 探测失败时的错误信息 */
70
- error?: string;
71
- }
@@ -1,4 +0,0 @@
1
- export * from "./init";
2
- export * from "./loader";
3
- export * from "./manifest";
4
- export * from "./types";
@@ -1,242 +0,0 @@
1
- import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
- import { basename, join, resolve } from "node:path";
3
-
4
- /**
5
- * 项目初始化脚手架选项。
6
- */
7
- export interface InitOptions {
8
- /** 自定义项目 ID(默认使用目录名) */
9
- id?: string;
10
- /** 自定义项目展示名称(默认由目录名美化生成) */
11
- name?: string;
12
- /** 自定义项目描述 */
13
- description?: string;
14
- }
15
-
16
- /**
17
- * 在目标目录初始化一个完整的 ActionDock 2.0 Action Package 脚手架。
18
- * 生成内容包括:
19
- * - actiondock.json(项目元数据与配置声明)
20
- * - actiondock.manifest.json(声明式元数据清单事实源)
21
- * - package.json(Node.js 标准脚本与依赖声明)
22
- * - tsconfig.json(现代 NodeNext 模块规范)
23
- * - .gitignore(排除持久化 db、node_modules、dist)
24
- * - actions/greet.ts(标准示例 Action,演示 config、state、log 使用)
25
- * - playbooks/greet-user.md(标准 SOP Playbook 演示)
26
- * - tests/greet.test.ts(基于 node:test 与 @actiondock/testing 的测试用例)
27
- *
28
- * @param targetDir 目标项目目录
29
- * @param options 初始化选项
30
- */
31
- export function initProject(targetDir: string, options: InitOptions = {}): void {
32
- const root = resolve(targetDir);
33
- if (!existsSync(root)) {
34
- mkdirSync(root, { recursive: true });
35
- }
36
-
37
- const dirName = basename(root);
38
- const id = options.id || dirName;
39
- const name = options.name || dirName.replace(/[-_]/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
40
- const description = options.description || "ActionDock AI Agent Actions";
41
-
42
- // 1. actiondock.json
43
- const actiondockJson = {
44
- id,
45
- name,
46
- version: "0.1.0",
47
- description,
48
- actionsDir: "actions",
49
- playbooksDir: "playbooks",
50
- config: {
51
- SAMPLE_GREETING: {
52
- description: "Default greeting message",
53
- default: "Hello",
54
- },
55
- },
56
- };
57
- writeFileSync(
58
- join(root, "actiondock.json"),
59
- JSON.stringify(actiondockJson, null, 2) + "\n"
60
- );
61
-
62
- // 2. actiondock.manifest.json
63
- const manifestJson = {
64
- schemaVersion: 1,
65
- actions: {
66
- "sample.greet": {
67
- entry: "actions/greet.ts",
68
- description: "Greeting action demonstrating basic input, config, and state usage",
69
- inputSchema: {
70
- type: "object",
71
- properties: {
72
- name: {
73
- type: "string",
74
- description: "Name of the person to greet",
75
- },
76
- },
77
- required: ["name"],
78
- },
79
- outputSchema: {
80
- type: "object",
81
- properties: {
82
- message: { type: "string" },
83
- timesGreeted: { type: "number" },
84
- },
85
- required: ["message", "timesGreeted"],
86
- },
87
- uses: [],
88
- tags: ["sample"],
89
- },
90
- },
91
- assets: [],
92
- };
93
- writeFileSync(
94
- join(root, "actiondock.manifest.json"),
95
- JSON.stringify(manifestJson, null, 2) + "\n"
96
- );
97
-
98
- // 3. package.json
99
- const packageJson = {
100
- name: id,
101
- version: "0.1.0",
102
- description,
103
- type: "module",
104
- scripts: {
105
- test: "node --import tsx --test tests/*.test.ts",
106
- },
107
- engines: {
108
- node: ">=22.12.0",
109
- },
110
- dependencies: {
111
- "@actiondock/sdk": "^2.0.11",
112
- },
113
- devDependencies: {
114
- "@actiondock/testing": "^2.0.11",
115
- "@types/node": "^22.12.0",
116
- "tsx": "^4.19.0",
117
- "typescript": "^5.7.0",
118
- },
119
- };
120
- writeFileSync(
121
- join(root, "package.json"),
122
- JSON.stringify(packageJson, null, 2) + "\n"
123
- );
124
-
125
- // 4. tsconfig.json
126
- const tsconfigJson = {
127
- compilerOptions: {
128
- target: "ES2022",
129
- module: "NodeNext",
130
- moduleResolution: "NodeNext",
131
- strict: true,
132
- skipLibCheck: true,
133
- types: ["node"],
134
- },
135
- };
136
- writeFileSync(
137
- join(root, "tsconfig.json"),
138
- JSON.stringify(tsconfigJson, null, 2) + "\n"
139
- );
140
-
141
- // 5. .gitignore
142
- const gitignore = `.actiondock/
143
- node_modules/
144
- dist/
145
- build/
146
- *.log
147
- .env
148
- `;
149
- writeFileSync(join(root, ".gitignore"), gitignore);
150
-
151
- // 6. actions/
152
- const actionsDir = join(root, "actions");
153
- mkdirSync(actionsDir, { recursive: true });
154
-
155
- const sampleAction = `import { defineAction } from "@actiondock/sdk";
156
-
157
- export default defineAction({
158
- id: "sample.greet",
159
- description: "Greeting action demonstrating basic input, config, and state usage",
160
- tags: ["sample"],
161
-
162
- inputSchema: {
163
- type: "object",
164
- properties: {
165
- name: {
166
- type: "string",
167
- description: "Name of the person to greet",
168
- },
169
- },
170
- required: ["name"],
171
- },
172
-
173
- outputSchema: {
174
- type: "object",
175
- properties: {
176
- message: { type: "string" },
177
- timesGreeted: { type: "number" },
178
- },
179
- required: ["message", "timesGreeted"],
180
- },
181
-
182
- async run(input: { name: string }, ctx) {
183
- const greeting = ctx.config.get("SAMPLE_GREETING", "Hello");
184
- const count = ((await ctx.state.get<number>("greet_count")) || 0) + 1;
185
- await ctx.state.set("greet_count", count);
186
-
187
- ctx.log.info(\`Greeting \${input.name} (times greeted: \${count})\`);
188
-
189
- return {
190
- message: \`\${greeting}, \${input.name}!\`,
191
- timesGreeted: count,
192
- };
193
- },
194
- });
195
- `;
196
- writeFileSync(join(actionsDir, "greet.ts"), sampleAction);
197
-
198
- // 7. playbooks/
199
- const playbooksDir = join(root, "playbooks");
200
- mkdirSync(playbooksDir, { recursive: true });
201
-
202
- const samplePlaybook = `---
203
- id: greet-user
204
- description: SOP for greeting a new user and verifying system health
205
- actions:
206
- - sample.greet
207
- ---
208
-
209
- # Greeting SOP
210
-
211
- - Call \`sample.greet\` with the user's name.
212
- - Confirm the returned greeting message.
213
- `;
214
- writeFileSync(join(playbooksDir, "greet-user.md"), samplePlaybook);
215
-
216
- // 8. tests/
217
- const testsDir = join(root, "tests");
218
- mkdirSync(testsDir, { recursive: true });
219
-
220
- const sampleTest = `import { describe, it } from "node:test";
221
- import assert from "node:assert/strict";
222
- import { createTestRuntime } from "@actiondock/testing";
223
- import greetAction from "../actions/greet";
224
-
225
- describe("greet action", () => {
226
- it("should greet user with greeting and increment count", async () => {
227
- const runtime = createTestRuntime({
228
- config: { SAMPLE_GREETING: "Hi" },
229
- });
230
-
231
- const res1 = await runtime.run(greetAction, { name: "Alice" });
232
- assert.equal(res1.message, "Hi, Alice!");
233
- assert.equal(await runtime.state.get("greet_count"), 1);
234
-
235
- const res2 = await runtime.run(greetAction, { name: "Bob" });
236
- assert.equal(res2.message, "Hi, Bob!");
237
- assert.equal(await runtime.state.get("greet_count"), 2);
238
- });
239
- });
240
- `;
241
- writeFileSync(join(testsDir, "greet.test.ts"), sampleTest);
242
- }