@actiondock/core 2.0.11 → 2.0.12

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 (119) hide show
  1. package/dist/build/templates.d.ts +19 -0
  2. package/dist/catalog/action-index.d.ts +9 -0
  3. package/dist/catalog/action-resolver.d.ts +20 -0
  4. package/dist/catalog/location-registry.d.ts +15 -0
  5. package/dist/catalog/package-catalog.d.ts +7 -0
  6. package/dist/catalog/types.d.ts +68 -0
  7. package/dist/doctor/doctor.d.ts +6 -0
  8. package/dist/doctor/types.d.ts +23 -0
  9. package/dist/execution/index.d.ts +2 -0
  10. package/dist/execution/service.d.ts +74 -0
  11. package/dist/execution/types.d.ts +74 -0
  12. package/dist/export/templates.d.ts +33 -0
  13. package/dist/filter/intent.d.ts +33 -0
  14. package/{src/index.ts → dist/index.d.ts} +1 -1
  15. package/dist/index.js +8458 -0
  16. package/dist/profile/client.d.ts +116 -0
  17. package/dist/profile/manager.d.ts +47 -0
  18. package/dist/profile/types.d.ts +61 -0
  19. package/dist/project/closure.d.ts +25 -0
  20. package/{src/project/index.ts → dist/project/index.d.ts} +1 -0
  21. package/dist/project/init.d.ts +27 -0
  22. package/dist/project/loader.d.ts +105 -0
  23. package/dist/project/manifest.d.ts +44 -0
  24. package/dist/project/types.d.ts +131 -0
  25. package/dist/registry/registry.d.ts +24 -0
  26. package/dist/registry/types.d.ts +117 -0
  27. package/dist/runtime/clock.d.ts +21 -0
  28. package/dist/runtime/context.d.ts +75 -0
  29. package/dist/runtime/env.d.ts +54 -0
  30. package/dist/runtime/events.d.ts +61 -0
  31. package/dist/runtime/execution-manager.d.ts +48 -0
  32. package/{src/runtime/index.ts → dist/runtime/index.d.ts} +0 -1
  33. package/dist/runtime/module-loader.d.ts +42 -0
  34. package/dist/runtime/process.d.ts +11 -0
  35. package/dist/runtime/runner.d.ts +186 -0
  36. package/dist/runtime/standalone.d.ts +40 -0
  37. package/dist/schema/validator.d.ts +28 -0
  38. package/dist/server/body.d.ts +40 -0
  39. package/{src/server/index.ts → dist/server/index.d.ts} +0 -1
  40. package/dist/server/routes/actions.d.ts +5 -0
  41. package/dist/server/routes/common.d.ts +36 -0
  42. package/dist/server/routes/config.d.ts +5 -0
  43. package/dist/server/routes/doctor.d.ts +5 -0
  44. package/dist/server/routes/health.d.ts +5 -0
  45. package/dist/server/routes/info.d.ts +5 -0
  46. package/dist/server/routes/playbooks.d.ts +5 -0
  47. package/dist/server/routes/runs.d.ts +5 -0
  48. package/dist/server/routes/state.d.ts +5 -0
  49. package/dist/server/runtime-registry.d.ts +78 -0
  50. package/dist/server/security.d.ts +37 -0
  51. package/dist/server/server.d.ts +15 -0
  52. package/dist/server/types.d.ts +59 -0
  53. package/dist/storage/driver.d.ts +15 -0
  54. package/dist/storage/index.d.ts +44 -0
  55. package/{src/storage/mask.ts → dist/storage/mask.d.ts} +5 -20
  56. package/dist/storage/sqlite.d.ts +66 -0
  57. package/dist/storage/types.d.ts +121 -0
  58. package/dist/utils/index.d.ts +29 -0
  59. package/dist/version.d.ts +4 -0
  60. package/package.json +11 -10
  61. package/src/build/templates.ts +0 -59
  62. package/src/catalog/action-index.ts +0 -92
  63. package/src/catalog/action-resolver.ts +0 -120
  64. package/src/catalog/location-registry.ts +0 -134
  65. package/src/catalog/package-catalog.ts +0 -87
  66. package/src/catalog/types.ts +0 -75
  67. package/src/doctor/doctor.ts +0 -419
  68. package/src/doctor/types.ts +0 -25
  69. package/src/execution/index.ts +0 -2
  70. package/src/execution/service.ts +0 -322
  71. package/src/execution/types.ts +0 -73
  72. package/src/export/templates.ts +0 -590
  73. package/src/filter/intent.ts +0 -154
  74. package/src/profile/client.ts +0 -552
  75. package/src/profile/manager.ts +0 -341
  76. package/src/profile/types.ts +0 -71
  77. package/src/project/init.ts +0 -242
  78. package/src/project/loader.ts +0 -479
  79. package/src/project/manifest.ts +0 -299
  80. package/src/project/types.ts +0 -141
  81. package/src/registry/registry.ts +0 -940
  82. package/src/registry/types.ts +0 -127
  83. package/src/runtime/clock.ts +0 -41
  84. package/src/runtime/context.ts +0 -259
  85. package/src/runtime/env.ts +0 -172
  86. package/src/runtime/events.ts +0 -142
  87. package/src/runtime/execution-manager.ts +0 -74
  88. package/src/runtime/module-loader.ts +0 -67
  89. package/src/runtime/process.ts +0 -245
  90. package/src/runtime/runner.ts +0 -527
  91. package/src/runtime/standalone.ts +0 -429
  92. package/src/schema/validator.ts +0 -61
  93. package/src/server/body.ts +0 -112
  94. package/src/server/routes/actions.ts +0 -262
  95. package/src/server/routes/common.ts +0 -126
  96. package/src/server/routes/config.ts +0 -147
  97. package/src/server/routes/doctor.ts +0 -29
  98. package/src/server/routes/health.ts +0 -40
  99. package/src/server/routes/info.ts +0 -221
  100. package/src/server/routes/playbooks.ts +0 -109
  101. package/src/server/routes/runs.ts +0 -301
  102. package/src/server/routes/state.ts +0 -133
  103. package/src/server/runtime-registry.ts +0 -115
  104. package/src/server/security.ts +0 -115
  105. package/src/server/server.ts +0 -251
  106. package/src/server/types.ts +0 -57
  107. package/src/storage/driver.ts +0 -126
  108. package/src/storage/index.ts +0 -81
  109. package/src/storage/sqlite.ts +0 -714
  110. package/src/storage/types.ts +0 -139
  111. package/src/utils/index.ts +0 -62
  112. /package/{src/build/index.ts → dist/build/index.d.ts} +0 -0
  113. /package/{src/catalog/index.ts → dist/catalog/index.d.ts} +0 -0
  114. /package/{src/doctor/index.ts → dist/doctor/index.d.ts} +0 -0
  115. /package/{src/export/index.ts → dist/export/index.d.ts} +0 -0
  116. /package/{src/filter/index.ts → dist/filter/index.d.ts} +0 -0
  117. /package/{src/profile/index.ts → dist/profile/index.d.ts} +0 -0
  118. /package/{src/registry/index.ts → dist/registry/index.d.ts} +0 -0
  119. /package/{src/server/routes/index.ts → dist/server/routes/index.d.ts} +0 -0
@@ -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,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
- }