@actiondock/core 2.19.0 → 2.20.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 (66) hide show
  1. package/dist/client/config.d.ts +17 -14
  2. package/dist/client/config.js +112 -14
  3. package/dist/client/index.d.ts +1 -1
  4. package/dist/client/index.js +1 -1
  5. package/dist/errors.d.ts +3 -1
  6. package/dist/errors.js +2 -0
  7. package/dist/execution/service.js +8 -5
  8. package/dist/execution/types.d.ts +3 -3
  9. package/dist/host/host.d.ts +9 -1
  10. package/dist/host/host.js +183 -38
  11. package/dist/host/types.d.ts +3 -0
  12. package/dist/index.d.ts +4 -3
  13. package/dist/index.js +1 -1
  14. package/dist/input/config-override.d.ts +5 -0
  15. package/dist/input/config-override.js +23 -0
  16. package/dist/input/input-resolver.d.ts +24 -7
  17. package/dist/input/input-resolver.js +73 -5
  18. package/dist/invocation/bindings.d.ts +53 -0
  19. package/dist/invocation/bindings.js +248 -0
  20. package/dist/invocation/policy.d.ts +5 -1
  21. package/dist/invocation/policy.js +16 -9
  22. package/dist/invocation/remote.d.ts +40 -0
  23. package/dist/invocation/remote.js +489 -0
  24. package/dist/invocation/types.d.ts +2 -0
  25. package/dist/invocation/types.js +1 -0
  26. package/dist/package/index.d.ts +1 -1
  27. package/dist/package/runtime.js +31 -12
  28. package/dist/platform/types.d.ts +48 -1
  29. package/dist/project/config-declarations.d.ts +61 -0
  30. package/dist/project/config-declarations.js +297 -0
  31. package/dist/project/index.d.ts +5 -2
  32. package/dist/project/index.js +5 -2
  33. package/dist/project/init.js +2 -2
  34. package/dist/project/loader.js +4 -0
  35. package/dist/project/manifest.js +10 -0
  36. package/dist/project/types.d.ts +30 -0
  37. package/dist/runtime/context.d.ts +6 -3
  38. package/dist/runtime/context.js +60 -13
  39. package/dist/runtime/env.js +15 -1
  40. package/dist/runtime/standalone-commands.d.ts +2 -2
  41. package/dist/runtime/standalone-commands.js +113 -47
  42. package/dist/runtime/standalone-help.d.ts +1 -0
  43. package/dist/runtime/standalone-help.js +15 -9
  44. package/dist/runtime/standalone.js +2 -2
  45. package/dist/server/policy.d.ts +24 -107
  46. package/dist/server/policy.js +134 -291
  47. package/dist/server/routes/actions.js +10 -8
  48. package/dist/server/routes/common.d.ts +5 -20
  49. package/dist/server/routes/common.js +22 -58
  50. package/dist/server/routes/config.js +65 -7
  51. package/dist/server/routes/doctor.d.ts +1 -0
  52. package/dist/server/routes/doctor.js +4 -3
  53. package/dist/server/routes/info.js +100 -13
  54. package/dist/server/routes/playbooks.js +1 -3
  55. package/dist/server/routes/runs.js +96 -18
  56. package/dist/server/server.js +25 -53
  57. package/dist/server/types.d.ts +6 -6
  58. package/dist/service/factory.js +1 -0
  59. package/dist/service/remote.js +14 -29
  60. package/dist/service/types.d.ts +20 -5
  61. package/dist/service/types.js +8 -0
  62. package/dist/storage/mask.d.ts +33 -6
  63. package/dist/storage/mask.js +298 -16
  64. package/dist/version.d.ts +1 -1
  65. package/dist/version.js +1 -1
  66. package/package.json +2 -2
@@ -1,15 +1,45 @@
1
1
  /**
2
- * 检查指定配置项是否为敏感数据(密码、私钥、Token、密钥等)。
3
- *
4
- * 判定逻辑:
5
- * 严格依据配置项元数据属性判定:若声明了 `secret: true`,直接判定为敏感数据;否则不视为敏感数据。
6
- * 不进行基于正则或键名的自动探测,由开发者显式配置驱动。
2
+ * 递归检查 Schema 是否包含任何标记为 secret: true 的节点。
3
+ */
4
+ function schemaHasSecret(schema) {
5
+ if (!schema || typeof schema !== "object") {
6
+ return false;
7
+ }
8
+ if (schema.secret === true) {
9
+ return true;
10
+ }
11
+ if (schema.properties) {
12
+ for (const propSchema of Object.values(schema.properties)) {
13
+ if (schemaHasSecret(propSchema)) {
14
+ return true;
15
+ }
16
+ }
17
+ }
18
+ if (schema.items && schemaHasSecret(schema.items)) {
19
+ return true;
20
+ }
21
+ if (schema.additionalProperties &&
22
+ typeof schema.additionalProperties === "object" &&
23
+ schemaHasSecret(schema.additionalProperties)) {
24
+ return true;
25
+ }
26
+ return false;
27
+ }
28
+ /**
29
+ * 检查指定配置项是否为敏感数据(顶层 secret: true 或模式中嵌套 secret: true)。
30
+ * 不进行基于正则或键名的自动探测,调用方若涉及模板应先解析具体声明项。
7
31
  *
8
32
  * @param _key 配置键名(保留入参以兼容契约)
9
33
  * @param declaredItem 项目中声明的配置元数据(可选)
10
34
  */
11
35
  export function isSecretConfigKey(_key, declaredItem) {
12
- return declaredItem?.secret === true;
36
+ if (declaredItem?.secret === true) {
37
+ return true;
38
+ }
39
+ if (declaredItem?.schema && schemaHasSecret(declaredItem.schema)) {
40
+ return true;
41
+ }
42
+ return false;
13
43
  }
14
44
  /**
15
45
  * 对敏感数据的值进行掩码脱敏处理(返回 "********")。
@@ -24,25 +54,277 @@ export function maskSecretValue(value) {
24
54
  return "null";
25
55
  return "********";
26
56
  }
57
+ function escapePointerToken(token) {
58
+ return token.replace(/~/g, "~0").replace(/\//g, "~1");
59
+ }
60
+ function unescapePointerToken(token) {
61
+ return token.replace(/~1/g, "/").replace(/~0/g, "~");
62
+ }
63
+ function isTypeMatch(val, expectedType) {
64
+ if (!expectedType)
65
+ return true;
66
+ switch (expectedType) {
67
+ case "string":
68
+ return typeof val === "string";
69
+ case "number":
70
+ return typeof val === "number" && Number.isFinite(val);
71
+ case "integer":
72
+ return typeof val === "number" && Number.isInteger(val);
73
+ case "boolean":
74
+ return typeof val === "boolean";
75
+ case "array":
76
+ return Array.isArray(val);
77
+ case "object":
78
+ return val !== null && typeof val === "object" && !Array.isArray(val);
79
+ default:
80
+ return true;
81
+ }
82
+ }
83
+ function redactNode(val, schema, path) {
84
+ // 模式显式标记敏感节点:直接掩码并终止下钻
85
+ if (schema?.secret === true) {
86
+ return {
87
+ value: "********",
88
+ redacted: true,
89
+ paths: [path],
90
+ };
91
+ }
92
+ // 即使省略 type,结构关键字也不能让标量绕过子字段的秘密保护。
93
+ const objectShape = schema?.properties !== undefined || schema?.additionalProperties !== undefined || schema?.required !== undefined;
94
+ const arrayShape = schema?.items !== undefined;
95
+ const incompatibleShape = !schema?.type && (objectShape || arrayShape) &&
96
+ !(objectShape && val !== null && typeof val === "object" && !Array.isArray(val)) &&
97
+ !(arrayShape && Array.isArray(val));
98
+ // 结构与声明类型不符:保守隐藏该节点
99
+ if (incompatibleShape || (schema?.type && !isTypeMatch(val, schema.type))) {
100
+ return {
101
+ value: "********",
102
+ redacted: true,
103
+ paths: [path],
104
+ };
105
+ }
106
+ // 数组节点处理
107
+ if (Array.isArray(val)) {
108
+ const newArr = [];
109
+ const childPaths = [];
110
+ let childRedacted = false;
111
+ if (schema?.items && typeof schema.items === "object") {
112
+ for (let i = 0; i < val.length; i++) {
113
+ const elemPath = path === "" ? `/${i}` : `${path}/${i}`;
114
+ const res = redactNode(val[i], schema.items, elemPath);
115
+ newArr.push(res.value);
116
+ if (res.redacted)
117
+ childRedacted = true;
118
+ childPaths.push(...res.paths);
119
+ }
120
+ }
121
+ else {
122
+ // 数组按 items 遍历,无对应声明则元素隐藏
123
+ for (let i = 0; i < val.length; i++) {
124
+ const elemPath = path === "" ? `/${i}` : `${path}/${i}`;
125
+ newArr.push("********");
126
+ childPaths.push(elemPath);
127
+ }
128
+ if (val.length > 0) {
129
+ childRedacted = true;
130
+ }
131
+ }
132
+ return {
133
+ value: newArr,
134
+ redacted: childRedacted,
135
+ paths: childPaths,
136
+ };
137
+ }
138
+ // 普通对象节点处理
139
+ if (val !== null && typeof val === "object") {
140
+ const entries = [];
141
+ const childPaths = [];
142
+ let childRedacted = false;
143
+ for (const k of Object.keys(val)) {
144
+ const childVal = val[k];
145
+ const token = escapePointerToken(k);
146
+ const propPath = path === "" ? `/${token}` : `${path}/${token}`;
147
+ if (schema?.properties && Object.prototype.hasOwnProperty.call(schema.properties, k)) {
148
+ const res = redactNode(childVal, schema.properties[k], propPath);
149
+ entries.push([k, res.value]);
150
+ if (res.redacted)
151
+ childRedacted = true;
152
+ childPaths.push(...res.paths);
153
+ }
154
+ else if (schema?.additionalProperties && typeof schema.additionalProperties === "object") {
155
+ // additionalProperties 声明为模式时继续递归
156
+ const res = redactNode(childVal, schema.additionalProperties, propPath);
157
+ entries.push([k, res.value]);
158
+ if (res.redacted)
159
+ childRedacted = true;
160
+ childPaths.push(...res.paths);
161
+ }
162
+ else {
163
+ // 对象未知属性值隐藏
164
+ entries.push([k, "********"]);
165
+ childRedacted = true;
166
+ childPaths.push(propPath);
167
+ }
168
+ }
169
+ return {
170
+ value: Object.fromEntries(entries),
171
+ redacted: childRedacted,
172
+ paths: childPaths,
173
+ };
174
+ }
175
+ // 标量基元节点
176
+ return {
177
+ value: val,
178
+ redacted: false,
179
+ paths: [],
180
+ };
181
+ }
182
+ /**
183
+ * 依据单项配置声明对配置值执行纯函数脱敏处理。
184
+ *
185
+ * @param value 待脱敏的配置原始数据值
186
+ * @param item 对应的单项配置定义元数据
187
+ */
188
+ export function redactConfigValue(value, item) {
189
+ // 外层 secret: true 判定
190
+ if (item?.secret === true) {
191
+ if (value === undefined) {
192
+ return { value: undefined, secret: true, redactedPaths: [] };
193
+ }
194
+ return { value: undefined, secret: true, redactedPaths: [""] };
195
+ }
196
+ // 未声明 schema 且非顶层 secret 维持旧行为
197
+ if (!item?.schema) {
198
+ return { value: value, secret: false, redactedPaths: [] };
199
+ }
200
+ // 数据值未配置时,不生成虚假脱敏路径,但反映声明敏感性
201
+ if (value === undefined) {
202
+ return {
203
+ value: undefined,
204
+ secret: schemaHasSecret(item.schema),
205
+ redactedPaths: [],
206
+ };
207
+ }
208
+ const res = redactNode(value, item.schema, "");
209
+ const declarationHasSecret = schemaHasSecret(item.schema);
210
+ const secret = declarationHasSecret || res.redacted;
211
+ return {
212
+ value: res.value,
213
+ secret,
214
+ redactedPaths: res.paths,
215
+ };
216
+ }
217
+ function isAncestorPath(parent, child) {
218
+ return parent === "" ? child !== "" : child.startsWith(parent + "/");
219
+ }
220
+ /** 根据可信隐藏路径应用幂等掩码,绝不把远端提供的路径本身当成已脱敏的证据。 */
221
+ export function redactConfigValueAtPaths(value, paths) {
222
+ const hideRoot = () => ({ value: undefined, secret: true, redactedPaths: [""] });
223
+ if (paths.some((path) => typeof path !== "string" || (path !== "" && (!path.startsWith("/") || /~(?![01])/.test(path))))) {
224
+ return hideRoot();
225
+ }
226
+ if (paths.includes(""))
227
+ return hideRoot();
228
+ const unique = [...new Set(paths)];
229
+ const minimal = unique.filter((path) => !unique.some((parent) => parent !== path && isAncestorPath(parent, path))).sort();
230
+ const copy = structuredClone(value);
231
+ for (const path of minimal) {
232
+ const tokens = path.slice(1).split("/").map(unescapePointerToken);
233
+ let node = copy;
234
+ for (const token of tokens.slice(0, -1)) {
235
+ if (node === null || typeof node !== "object")
236
+ return hideRoot();
237
+ if (!Object.hasOwn(node, token)) {
238
+ node = undefined;
239
+ break;
240
+ }
241
+ node = node[token];
242
+ }
243
+ if (node === undefined)
244
+ continue;
245
+ if (node === null || typeof node !== "object")
246
+ return hideRoot();
247
+ const leaf = tokens[tokens.length - 1];
248
+ if (Object.hasOwn(node, leaf)) {
249
+ Object.defineProperty(node, leaf, { value: "********", enumerable: true, writable: true, configurable: true });
250
+ }
251
+ }
252
+ return { value: copy, secret: minimal.length > 0, redactedPaths: minimal };
253
+ }
254
+ /**
255
+ * 依据跨包多重声明对配置值执行合并脱敏处理(取脱敏路径并集,祖先路径覆盖子路径)。
256
+ *
257
+ * @param value 待脱敏的配置原始数据值
258
+ * @param items 各相关包分别解析得到的配置声明集合
259
+ */
260
+ export function redactConfigValueForDeclarations(value, items) {
261
+ if (!items || items.length === 0) {
262
+ return { value: value, secret: false, redactedPaths: [] };
263
+ }
264
+ // 任何声明要求整项敏感,直接隐藏整个根节点
265
+ if (items.some((item) => item.secret === true)) {
266
+ if (value === undefined) {
267
+ return { value: undefined, secret: true, redactedPaths: [] };
268
+ }
269
+ return { value: undefined, secret: true, redactedPaths: [""] };
270
+ }
271
+ if (value === undefined) {
272
+ const hasSecret = items.some((item) => isSecretConfigKey("", item));
273
+ return { value: undefined, secret: hasSecret, redactedPaths: [] };
274
+ }
275
+ let anySecret = false;
276
+ const allPaths = new Set();
277
+ for (const item of items) {
278
+ const res = redactConfigValue(value, item);
279
+ if (res.secret) {
280
+ anySecret = true;
281
+ }
282
+ for (const p of res.redactedPaths) {
283
+ allPaths.add(p);
284
+ }
285
+ }
286
+ const merged = redactConfigValueAtPaths(value, [...allPaths]);
287
+ return { ...merged, secret: anySecret || merged.secret };
288
+ }
289
+ function sanitizeSchemaNode(schema, inheritedSecret = false) {
290
+ const copy = { ...schema };
291
+ const hidden = inheritedSecret || schema.secret === true;
292
+ // 祖先枚举也可能携带子字段秘密,未知结构同样不可借约束回显。
293
+ if (hidden || schemaHasSecret(schema) || schema.enum?.some((value) => redactNode(value, schema, "").redacted)) {
294
+ delete copy.enum;
295
+ }
296
+ if (copy.properties) {
297
+ copy.properties = Object.fromEntries(Object.entries(copy.properties).map(([key, child]) => [key, sanitizeSchemaNode(child, hidden)]));
298
+ }
299
+ if (copy.additionalProperties && typeof copy.additionalProperties === "object") {
300
+ copy.additionalProperties = sanitizeSchemaNode(copy.additionalProperties, hidden);
301
+ }
302
+ if (copy.items && typeof copy.items === "object") {
303
+ copy.items = sanitizeSchemaNode(copy.items, hidden);
304
+ }
305
+ return copy;
306
+ }
27
307
  /**
28
308
  * 对配置定义字典进行脱敏处理:
29
- * 针对声明为 secret: true 的项,剥离其 default 默认值,不返回敏感默认值。
309
+ * - 针对外层 secret: true 或嵌套包含敏感字段的项,剥离其 default 默认值,避免敏感默认值泄露或误用于执行;
310
+ * - 针对模式中敏感节点的 enum 约束列表进行清洗,杜绝约束文本泄露秘密;
311
+ * - 仅返回安全副本,严禁修改清单原始数据。
30
312
  *
31
313
  * @param config 声明的配置定义字典
32
314
  */
33
315
  export function sanitizeConfigDefinitions(config) {
34
316
  if (!config)
35
317
  return config;
36
- const result = {};
37
- for (const [key, item] of Object.entries(config)) {
38
- if (item?.secret === true) {
39
- const copy = { ...item };
318
+ return Object.fromEntries(Object.entries(config).map(([key, item]) => {
319
+ if (!item)
320
+ return [key, item];
321
+ const copy = { ...item };
322
+ if (isSecretConfigKey(key, item) || redactConfigValue(item.default, item).redactedPaths.length > 0) {
40
323
  delete copy.default;
41
- result[key] = copy;
42
324
  }
43
- else {
44
- result[key] = item;
325
+ if (copy.schema) {
326
+ copy.schema = sanitizeSchemaNode(copy.schema, copy.secret === true);
45
327
  }
46
- }
47
- return result;
328
+ return [key, copy];
329
+ }));
48
330
  }
package/dist/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * ActionDock 核心版本号单一事实源。
3
3
  */
4
- export declare const ACTIONDOCK_VERSION = "2.19.0";
4
+ export declare const ACTIONDOCK_VERSION = "2.20.0";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * ActionDock 核心版本号单一事实源。
3
3
  */
4
- export const ACTIONDOCK_VERSION = "2.19.0";
4
+ export const ACTIONDOCK_VERSION = "2.20.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actiondock/core",
3
- "version": "2.19.0",
3
+ "version": "2.20.0",
4
4
  "description": "ActionDock Core Engine - Project loader, runtime execution, SQLite storage, standalone builder, and skill exporter",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -59,7 +59,7 @@
59
59
  "test": "node ../../scripts/run-tests.ts"
60
60
  },
61
61
  "dependencies": {
62
- "@actiondock/sdk": "^2.19.0",
62
+ "@actiondock/sdk": "^2.20.0",
63
63
  "ajv": "^8.17.1",
64
64
  "ajv-formats": "^3.0.1",
65
65
  "undici": "^7.29.1"