@actiondock/core 2.0.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 (43) hide show
  1. package/README.md +50 -0
  2. package/package.json +51 -0
  3. package/src/build/builder.ts +205 -0
  4. package/src/build/index.ts +2 -0
  5. package/src/build/templates.ts +59 -0
  6. package/src/doctor/doctor.ts +332 -0
  7. package/src/doctor/index.ts +2 -0
  8. package/src/doctor/types.ts +25 -0
  9. package/src/export/index.ts +2 -0
  10. package/src/export/skill.ts +349 -0
  11. package/src/export/templates.ts +258 -0
  12. package/src/filter/index.ts +1 -0
  13. package/src/filter/intent.ts +154 -0
  14. package/src/index.ts +13 -0
  15. package/src/profile/client.ts +302 -0
  16. package/src/profile/index.ts +3 -0
  17. package/src/profile/manager.ts +341 -0
  18. package/src/profile/types.ts +71 -0
  19. package/src/project/index.ts +3 -0
  20. package/src/project/init.ts +194 -0
  21. package/src/project/loader.ts +382 -0
  22. package/src/project/types.ts +62 -0
  23. package/src/registry/index.ts +2 -0
  24. package/src/registry/registry.ts +703 -0
  25. package/src/registry/types.ts +127 -0
  26. package/src/runtime/context.ts +232 -0
  27. package/src/runtime/env.ts +172 -0
  28. package/src/runtime/execution-manager.ts +74 -0
  29. package/src/runtime/index.ts +5 -0
  30. package/src/runtime/runner.ts +368 -0
  31. package/src/runtime/standalone.ts +429 -0
  32. package/src/schema/validator.ts +61 -0
  33. package/src/server/body.ts +112 -0
  34. package/src/server/index.ts +6 -0
  35. package/src/server/runtime-registry.ts +80 -0
  36. package/src/server/security.ts +115 -0
  37. package/src/server/server.ts +572 -0
  38. package/src/server/types.ts +42 -0
  39. package/src/storage/index.ts +64 -0
  40. package/src/storage/mask.ts +34 -0
  41. package/src/storage/sqlite.ts +578 -0
  42. package/src/storage/types.ts +111 -0
  43. package/src/utils/index.ts +60 -0
@@ -0,0 +1,42 @@
1
+ import type { ServerRuntimeRegistry } from "./runtime-registry";
2
+
3
+ /**
4
+ * 启动 ActionDock HTTP Runner 服务端的配置选项。
5
+ */
6
+ export interface ServerOptions {
7
+ /** 监听端口号(默认 5177) */
8
+ port?: number;
9
+ /** 绑定监听的主机地址(默认 "127.0.0.1") */
10
+ host?: string;
11
+ /** 用于 HTTP Bearer Token 鉴权的密钥令牌 */
12
+ token?: string;
13
+ /** 服务的项目根目录(可选,若未指定则自动向上查找或进入全局 Registry 模式) */
14
+ projectRoot?: string;
15
+ /** 自定义 ActionDock 用户家目录 */
16
+ customHome?: string;
17
+ /** 是否允许非回环地址(如 0.0.0.0)在未配置 Token 的情况下启动(不安全) */
18
+ allowInsecureNoAuth?: boolean;
19
+ /** 允许跨域请求的 CORS Origin 白名单列表 */
20
+ corsOrigins?: string[];
21
+ /** 最大允许的请求体字节限制(默认 1MB,防 DoS) */
22
+ maxBodyBytes?: number;
23
+ /** 是否在 health 和 info 接口中透传本地 projectRoot 等调试路径 */
24
+ exposeDebugInfo?: boolean;
25
+ }
26
+
27
+ /**
28
+ * 已启动的 ActionDock HTTP Runner 实例句柄。
29
+ */
30
+ export interface ActionDockServerInstance {
31
+ /** 实际监听的端口号 */
32
+ port: number;
33
+ /** 实际绑定的主机地址 */
34
+ host: string;
35
+ /** 服务端可访问的基础 URL(如 "http://127.0.0.1:5177") */
36
+ url: string;
37
+ /** 关联的 ServerRuntimeRegistry 运行时注册表 */
38
+ runtimeRegistry?: ServerRuntimeRegistry;
39
+ /** 优雅关闭服务端并释放所有存储连接 */
40
+ stop: () => Promise<void> | void;
41
+ }
42
+
@@ -0,0 +1,64 @@
1
+ import { homedir } from "node:os";
2
+ import { join } from "node:path";
3
+ import { SqliteRuntimeStorage } from "./sqlite";
4
+ import type { RuntimeStorage, StorageOptions } from "./types";
5
+
6
+ export * from "./mask";
7
+ export * from "./sqlite";
8
+ export * from "./types";
9
+
10
+ /**
11
+ * 解析并计算目标 SQLite 数据库文件的绝对路径。
12
+ *
13
+ * 优先级规则:
14
+ * 1. inMemory: true -> 返回 ":memory:"
15
+ * 2. 显式指定 dataDir -> 返回 `<dataDir>/<packageId>/runtime.db`
16
+ * 3. 显式指定 projectRoot(开发态项目) -> 返回 `<projectRoot>/.actiondock/runtime.db`
17
+ * 4. 默认独立二进制存储路径 -> 返回 `~/.actiondock/data/<packageId>/runtime.db`
18
+ *
19
+ * @param packageId 所属 Package ID
20
+ * @param options 路径解析选项
21
+ */
22
+ export function resolveDatabasePath(
23
+ packageId: string,
24
+ options: { projectRoot?: string; dataDir?: string; inMemory?: boolean } = {}
25
+ ): string {
26
+ if (options.inMemory) {
27
+ return ":memory:";
28
+ }
29
+ if (options.dataDir) {
30
+ return join(options.dataDir, packageId, "runtime.db");
31
+ }
32
+ if (options.projectRoot) {
33
+ return join(options.projectRoot, ".actiondock", "runtime.db");
34
+ }
35
+ // 独立执行二进制默认存储路径: ~/.actiondock/data/<package-id>/runtime.db
36
+ return join(homedir(), ".actiondock", "data", packageId, "runtime.db");
37
+ }
38
+
39
+ /**
40
+ * 工厂函数:为指定 Package 创建或连接 RuntimeStorage 实例。
41
+ *
42
+ * @param packageId 目标 Package ID
43
+ * @param options 存储配置参数(支持 projectRoot, dataDir, inMemory)
44
+ */
45
+ export function createStorage(
46
+ packageId: string,
47
+ options: { projectRoot?: string; dataDir?: string; inMemory?: boolean } = {}
48
+ ): RuntimeStorage {
49
+ const dbPath = resolveDatabasePath(packageId, options);
50
+ return new SqliteRuntimeStorage({ dbPath, packageId });
51
+ }
52
+
53
+ /**
54
+ * 工厂函数:创建或连接 ActionDock 全局共享数据库(~/.actiondock/global.db)。
55
+ * 用于跨 Package 共享的全局配置项存储。
56
+ *
57
+ * @param customHome 自定义家目录路径(可选)
58
+ */
59
+ export function createGlobalStorage(customHome?: string): RuntimeStorage {
60
+ const baseDir = customHome || process.env.ACTIONDOCK_HOME || homedir();
61
+ const dbPath = join(baseDir, ".actiondock", "global.db");
62
+ return new SqliteRuntimeStorage({ dbPath, packageId: "__global__" });
63
+ }
64
+
@@ -0,0 +1,34 @@
1
+ import type { ConfigItemDefinition } from "../project/types";
2
+
3
+ /**
4
+ * 检查指定配置项是否为敏感数据(密码、私钥、Token、密钥等)。
5
+ *
6
+ * 判定逻辑:
7
+ * 1. 若 actiondock.json 中显式声明了 `secret: true`,直接判定为敏感。
8
+ * 2. 若未显式声明,使用正则探测包含 PASSWORD/SECRET/TOKEN/KEY/PASS/AUTH/CREDENTIAL/PRIVATE_KEY 的通用敏感命名特征。
9
+ *
10
+ * @param key 配置键名
11
+ * @param declaredItem 项目中声明的配置元数据(可选)
12
+ */
13
+ export function isSecretConfigKey(
14
+ key: string,
15
+ declaredItem?: ConfigItemDefinition
16
+ ): boolean {
17
+ if (declaredItem?.secret === true) {
18
+ return true;
19
+ }
20
+ // 匹配常见敏感词命名特征
21
+ return /^(.*_)?(PASSWORD|SECRET|TOKEN|KEY|PASS|AUTH|CREDENTIAL|PRIVATE_KEY)(_.*)?$/i.test(key);
22
+ }
23
+
24
+ /**
25
+ * 对敏感数据的值进行掩码脱敏处理(返回 "********")。
26
+ *
27
+ * @param value 原始数据值
28
+ * @returns 掩码脱敏后的安全展示字符串
29
+ */
30
+ export function maskSecretValue(value: unknown): string {
31
+ if (value === undefined) return "undefined";
32
+ if (value === null) return "null";
33
+ return "********";
34
+ }