@actiondock/builder 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.
package/dist/index.d.ts CHANGED
@@ -8,9 +8,10 @@ export { assertNoFileProtocolDeps, assertValidManifestActionIds, serializeManife
8
8
  export type { SerializePlanManifestOptions } from "./manifest.js";
9
9
  export { createTarGzArchive, createTarGzArchiveAsync, createZipArchive, createZipArchiveAsync, dosDateTime, writeToStream, } from "./archive.js";
10
10
  export type { TarGzArchiveOptions } from "./archive.js";
11
- export { BuildPlanner, buildPlan, SelectionPlanner, selectionPlan } from "./planner.js";
11
+ export { SelectionPlanner } from "./planner.js";
12
12
  export { assertRelativeDependenciesIntegrity, extractRelativeSpecifiers, resolveRelativeModule, } from "./dependency-check.js";
13
13
  export { buildProject } from "./build.js";
14
14
  export { packProject } from "./pack.js";
15
- export { exportCompositeSkill, exportSkill, exportSkillBatch, findExistingCompositeSkillMd, findExistingSingleSkillMd, SkillExporter, } from "./exporter.js";
16
- export type { ActionDependency, ArchiveFormat, AssetDependency, BatchSkillExportOptions, BatchSkillExportResult, BuildOptions, BuildPlan, BuildPlanDependencies, BuildPlannerOptions, BuildResult, CompositeSkillExportOptions, CompositeSkillExportResult, ExternalDependency, LockfileInfo, PackOptions, PackResult, PlaybookPlanEntry, ProjectConfigWithDeclarations, SelectionPlan, SelectionPlannerOptions, SkillExporterOptions, SkillExportResult, } from "./types.js";
15
+ export { exportCompositeSkill, exportSkill, exportSkillBatch, SkillExporter, } from "./exporter.js";
16
+ export { findExistingCompositeSkillMd, findExistingSingleSkillMd, } from "./skill-md.js";
17
+ export type { ActionDependency, ArchiveFormat, AssetDependency, BatchSkillExportOptions, BatchSkillExportResult, BuildOptions, BuildPlan, BuildPlanDependencies, BuildResult, CompositeSkillExportOptions, CompositeSkillExportResult, ExternalDependency, LockfileInfo, PackOptions, PackResult, PlaybookPlanEntry, ProjectConfigWithDeclarations, SelectionPlan, SelectionPlannerOptions, SkillExporterOptions, SkillExportResult, } from "./types.js";
package/dist/index.js CHANGED
@@ -11,11 +11,13 @@ export { assertNoFileProtocolDeps, assertValidManifestActionIds, serializeManife
11
11
  // 归档压缩
12
12
  export { createTarGzArchive, createTarGzArchiveAsync, createZipArchive, createZipArchiveAsync, dosDateTime, writeToStream, } from "./archive.js";
13
13
  // 构建规划
14
- export { BuildPlanner, buildPlan, SelectionPlanner, selectionPlan } from "./planner.js";
14
+ export { SelectionPlanner } from "./planner.js";
15
15
  // 相对依赖完整性校验
16
16
  export { assertRelativeDependenciesIntegrity, extractRelativeSpecifiers, resolveRelativeModule, } from "./dependency-check.js";
17
17
  // 目录型构建与 npm 打包
18
18
  export { buildProject } from "./build.js";
19
19
  export { packProject } from "./pack.js";
20
20
  // Skill 导出
21
- export { exportCompositeSkill, exportSkill, exportSkillBatch, findExistingCompositeSkillMd, findExistingSingleSkillMd, SkillExporter, } from "./exporter.js";
21
+ // 入口函数与导出器门面位于 ./exporter;SKILL.md 发现能力单一事实源位于 ./skill-md
22
+ export { exportCompositeSkill, exportSkill, exportSkillBatch, SkillExporter, } from "./exporter.js";
23
+ export { findExistingCompositeSkillMd, findExistingSingleSkillMd, } from "./skill-md.js";
package/dist/pack.js CHANGED
@@ -345,9 +345,23 @@ async function runNpmPack(stagingPkgDir, packDestination, fallbackName) {
345
345
  if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
346
346
  try {
347
347
  const parsed = JSON.parse(trimmed);
348
- const items = Array.isArray(parsed) ? parsed : [parsed];
349
- const filename = items[0]?.filename;
350
- if (typeof filename === "string" && filename.length > 0) {
348
+ let items;
349
+ if (Array.isArray(parsed)) {
350
+ items = parsed;
351
+ }
352
+ else if (typeof parsed === "object" && parsed !== null) {
353
+ // npm >= 11 的 pack --json 输出为按包名索引的对象,取全部包含 filename 的条目
354
+ items = Object.values(parsed).filter((entry) => typeof entry === "object" && entry !== null && "filename" in entry);
355
+ }
356
+ else {
357
+ items = [];
358
+ }
359
+ // 多包输出时取最后一个 filename(npm 按依赖顺序逐包输出,末尾为当前项目产物)
360
+ const filenames = items
361
+ .map((item) => item.filename)
362
+ .filter((name) => typeof name === "string" && name.length > 0);
363
+ const filename = filenames[filenames.length - 1];
364
+ if (filename !== undefined) {
351
365
  generatedName = filename;
352
366
  }
353
367
  }
package/dist/planner.d.ts CHANGED
@@ -49,20 +49,3 @@ export declare class SelectionPlanner {
49
49
  */
50
50
  static plan(options: SelectionPlannerOptions): SelectionPlan;
51
51
  }
52
- /**
53
- * 构建规划器标准导出。
54
- * @deprecated SelectionPlanner 的历史别名,请直接使用 SelectionPlanner,将在两个版本后移除。
55
- */
56
- export declare const BuildPlanner: typeof SelectionPlanner;
57
- /** @deprecated SelectionPlanner 类型的历史别名,请直接使用 SelectionPlanner 类型。 */
58
- export type BuildPlanner = SelectionPlanner;
59
- /**
60
- * 快捷选择规划函数。
61
- * @deprecated 便捷快捷函数,请直接使用 SelectionPlanner.plan,将在两个版本后移除。
62
- */
63
- export declare function selectionPlan(options: SelectionPlannerOptions): SelectionPlan;
64
- /**
65
- * 快捷构建规划函数标准导出。
66
- * @deprecated selectionPlan 的历史别名,请改用 SelectionPlanner.plan,将在两个版本后移除。
67
- */
68
- export declare const buildPlan: typeof selectionPlan;
package/dist/planner.js CHANGED
@@ -670,20 +670,3 @@ export class SelectionPlanner {
670
670
  return planner.plan(options);
671
671
  }
672
672
  }
673
- /**
674
- * 构建规划器标准导出。
675
- * @deprecated SelectionPlanner 的历史别名,请直接使用 SelectionPlanner,将在两个版本后移除。
676
- */
677
- export const BuildPlanner = SelectionPlanner;
678
- /**
679
- * 快捷选择规划函数。
680
- * @deprecated 便捷快捷函数,请直接使用 SelectionPlanner.plan,将在两个版本后移除。
681
- */
682
- export function selectionPlan(options) {
683
- return SelectionPlanner.plan(options);
684
- }
685
- /**
686
- * 快捷构建规划函数标准导出。
687
- * @deprecated selectionPlan 的历史别名,请改用 SelectionPlanner.plan,将在两个版本后移除。
688
- */
689
- export const buildPlan = selectionPlan;
@@ -0,0 +1,47 @@
1
+ import { type CompositeCustomDeclaration, type PlaybookDefinition, type ProjectConfig, type SkillActionItem } from "@actiondock/core";
2
+ import type { CompositeSkillExportOptions, SelectionPlan } from "./types.js";
3
+ /**
4
+ * SKILL.md 发现、复用与模板视图适配层。
5
+ *
6
+ * 职责单一聚焦:定位项目中已有的 SKILL.md(单包与复合套件两种检索策略)、
7
+ * 解析自定义说明书声明,并将规划产物适配为模板生成所需视图。
8
+ */
9
+ /** 供模板生成使用的 SkillActionItem 兼容视图 */
10
+ type PlanActionView = SkillActionItem;
11
+ /**
12
+ * 将规划产物中的 Action 列表适配为模板所需的 SkillActionItem 视图。
13
+ */
14
+ export declare function toSkillActionItems(actions: SelectionPlan["actions"]): PlanActionView[];
15
+ /**
16
+ * 将规划产物中的 Playbook 列表适配为模板所需的 PlaybookDefinition 视图。
17
+ */
18
+ export declare function toPlaybookDefinitions(playbooks: SelectionPlan["playbooks"]): PlaybookDefinition[];
19
+ /**
20
+ * 检索单个 Action 项目目录中已存在的 SKILL.md 文件。
21
+ */
22
+ export declare function findExistingSingleSkillMd(projectRoot: string, explicitPath?: string, pkgSlug?: string): string | undefined;
23
+ /**
24
+ * 检索复合套件工作区中已存在的 SKILL.md 文件。
25
+ */
26
+ export declare function findExistingCompositeSkillMd(options: CompositeSkillExportOptions): string | undefined;
27
+ /**
28
+ * 解析复合技能自定义说明书:显式 customMdPath 优先(缺失即报错),
29
+ * 否则按 `SKILL.custom.md` 约定名在工作区根目录与当前目录自动发现。
30
+ */
31
+ export declare function resolveCustomSkillDeclaration(options: CompositeSkillExportOptions): (CompositeCustomDeclaration & {
32
+ file: string;
33
+ }) | undefined;
34
+ /**
35
+ * 复制或生成 SKILL.md 到目标目录。
36
+ * 返回实际复用的已有 SKILL.md 路径(若发生复用)。
37
+ */
38
+ export declare function writeSkillMd(root: string, destDir: string, plan: SelectionPlan, options: {
39
+ skipSkillMd?: boolean;
40
+ skillMdPath?: string;
41
+ pkgSlug: string;
42
+ }, generate: () => string): string | undefined;
43
+ /**
44
+ * 构造模板生成所需的 ProjectConfig 视图。
45
+ */
46
+ export declare function buildConfigForTemplates(plan: SelectionPlan, actionsDir: string, playbooksDir: string): ProjectConfig;
47
+ export {};
@@ -0,0 +1,166 @@
1
+ import { copyFileSync, existsSync, readFileSync, statSync, writeFileSync } from "node:fs";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { COMPOSITE_CUSTOM_DECLARATION_FILE, parseCustomSkillDeclaration, getPackageSlug, } from "@actiondock/core";
4
+ import { BuilderError } from "./errors.js";
5
+ /**
6
+ * 将规划产物中的 Action 列表适配为模板所需的 SkillActionItem 视图。
7
+ */
8
+ export function toSkillActionItems(actions) {
9
+ return actions;
10
+ }
11
+ /**
12
+ * 将规划产物中的 Playbook 列表适配为模板所需的 PlaybookDefinition 视图。
13
+ */
14
+ export function toPlaybookDefinitions(playbooks) {
15
+ return playbooks;
16
+ }
17
+ /**
18
+ * 检索单个 Action 项目目录中已存在的 SKILL.md 文件。
19
+ */
20
+ export function findExistingSingleSkillMd(projectRoot, explicitPath, pkgSlug) {
21
+ if (explicitPath && existsSync(explicitPath)) {
22
+ try {
23
+ if (statSync(explicitPath).isFile())
24
+ return resolve(explicitPath);
25
+ }
26
+ catch {
27
+ // 忽略文件属性读取异常
28
+ }
29
+ }
30
+ const candidates = [
31
+ join(projectRoot, "SKILL.md"),
32
+ join(projectRoot, "skill.md"),
33
+ join(projectRoot, "skills", "SKILL.md"),
34
+ join(projectRoot, "skills", "skill.md"),
35
+ ];
36
+ if (pkgSlug) {
37
+ candidates.push(join(projectRoot, "skills", pkgSlug, "SKILL.md"), join(projectRoot, "skills", pkgSlug, "skill.md"));
38
+ }
39
+ for (const candidate of candidates) {
40
+ if (existsSync(candidate)) {
41
+ try {
42
+ if (statSync(candidate).isFile())
43
+ return resolve(candidate);
44
+ }
45
+ catch {
46
+ // 忽略文件属性读取异常
47
+ }
48
+ }
49
+ }
50
+ return undefined;
51
+ }
52
+ /**
53
+ * 检索复合套件工作区中已存在的 SKILL.md 文件。
54
+ */
55
+ export function findExistingCompositeSkillMd(options) {
56
+ if (options.skillMdPath && existsSync(options.skillMdPath)) {
57
+ try {
58
+ if (statSync(options.skillMdPath).isFile())
59
+ return resolve(options.skillMdPath);
60
+ }
61
+ catch {
62
+ // 忽略文件属性读取异常
63
+ }
64
+ }
65
+ const bundleSlug = getPackageSlug(options.bundleName);
66
+ const searchDirs = new Set();
67
+ if (options.workspaceRoot && existsSync(options.workspaceRoot)) {
68
+ searchDirs.add(resolve(options.workspaceRoot));
69
+ }
70
+ searchDirs.add(process.cwd());
71
+ for (const root of options.projectRoots) {
72
+ const absRoot = resolve(root);
73
+ // 仅搜索父目录(工作区根)一级;祖父目录搜索可能命中毫不相关的全局 SKILL.md 并复制进产物
74
+ searchDirs.add(dirname(absRoot));
75
+ }
76
+ const candidateRelativePaths = [
77
+ join("skills", options.bundleName, "SKILL.md"),
78
+ join("skills", bundleSlug, "SKILL.md"),
79
+ join("skills", "SKILL.md"),
80
+ "SKILL.md",
81
+ join("skills", options.bundleName, "skill.md"),
82
+ join("skills", bundleSlug, "skill.md"),
83
+ join("skills", "skill.md"),
84
+ "skill.md",
85
+ ];
86
+ for (const dir of searchDirs) {
87
+ for (const rel of candidateRelativePaths) {
88
+ const fullPath = join(dir, rel);
89
+ if (existsSync(fullPath)) {
90
+ try {
91
+ if (statSync(fullPath).isFile())
92
+ return fullPath;
93
+ }
94
+ catch {
95
+ // 忽略文件属性读取异常
96
+ }
97
+ }
98
+ }
99
+ }
100
+ return undefined;
101
+ }
102
+ /**
103
+ * 解析复合技能自定义说明书:显式 customMdPath 优先(缺失即报错),
104
+ * 否则按 `SKILL.custom.md` 约定名在工作区根目录与当前目录自动发现。
105
+ */
106
+ export function resolveCustomSkillDeclaration(options) {
107
+ let filePath;
108
+ if (options.customMdPath) {
109
+ if (!existsSync(options.customMdPath)) {
110
+ throw new BuilderError(`Custom skill declaration file not found: '${options.customMdPath}'`);
111
+ }
112
+ filePath = resolve(options.customMdPath);
113
+ }
114
+ else {
115
+ const searchDirs = [options.workspaceRoot, process.cwd()].filter(Boolean);
116
+ for (const dir of searchDirs) {
117
+ const candidate = join(resolve(dir), COMPOSITE_CUSTOM_DECLARATION_FILE);
118
+ if (existsSync(candidate)) {
119
+ filePath = candidate;
120
+ break;
121
+ }
122
+ }
123
+ }
124
+ if (!filePath) {
125
+ return undefined;
126
+ }
127
+ return {
128
+ file: filePath,
129
+ ...parseCustomSkillDeclaration(readFileSync(filePath, "utf-8")),
130
+ };
131
+ }
132
+ /**
133
+ * 复制或生成 SKILL.md 到目标目录。
134
+ * 返回实际复用的已有 SKILL.md 路径(若发生复用)。
135
+ */
136
+ export function writeSkillMd(root, destDir, plan, options, generate) {
137
+ const existingSkill = options.skipSkillMd
138
+ ? undefined
139
+ : findExistingSingleSkillMd(root, options.skillMdPath, options.pkgSlug);
140
+ if (existingSkill) {
141
+ const destSkillMd = join(destDir, "SKILL.md");
142
+ if (resolve(existingSkill) !== resolve(destSkillMd)) {
143
+ copyFileSync(existingSkill, destSkillMd);
144
+ }
145
+ return existingSkill;
146
+ }
147
+ if (!options.skipSkillMd) {
148
+ writeFileSync(join(destDir, "SKILL.md"), generate(), "utf-8");
149
+ }
150
+ return undefined;
151
+ }
152
+ /**
153
+ * 构造模板生成所需的 ProjectConfig 视图。
154
+ */
155
+ export function buildConfigForTemplates(plan, actionsDir, playbooksDir) {
156
+ return {
157
+ id: plan.packageId,
158
+ name: plan.packageName,
159
+ version: plan.version,
160
+ description: plan.description,
161
+ actionsDir,
162
+ playbooksDir,
163
+ // 声明性配置字典在规划侧为宽松结构,模板仅透传展示
164
+ config: plan.configDefs,
165
+ };
166
+ }
package/dist/types.d.ts CHANGED
@@ -138,9 +138,9 @@ export interface BuildPlan {
138
138
  */
139
139
  export type SelectionPlan = BuildPlan;
140
140
  /**
141
- * 构建规划器配置选项。
141
+ * 声明式选择规划器配置选项。
142
142
  */
143
- export interface BuildPlannerOptions {
143
+ export interface SelectionPlannerOptions {
144
144
  /** 项目根目录绝对路径 */
145
145
  projectRoot: string;
146
146
  /** 显式传入的项目配置(若未提供则从 actiondock.json 读取) */
@@ -164,10 +164,6 @@ export interface BuildPlannerOptions {
164
164
  /** 是否跳过本地相对依赖完整性校验(默认 false) */
165
165
  skipDependencyValidation?: boolean;
166
166
  }
167
- /**
168
- * 声明式选择规划器配置选项别名。
169
- */
170
- export type SelectionPlannerOptions = BuildPlannerOptions;
171
167
  /**
172
168
  * 归档压缩格式。
173
169
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actiondock/builder",
3
- "version": "2.5.1",
3
+ "version": "2.6.0",
4
4
  "description": "ActionDock Build Planner, distribution packaging, and Skill exporter",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -29,9 +29,9 @@
29
29
  "test": "node ../../scripts/run-tests.ts"
30
30
  },
31
31
  "dependencies": {
32
- "@actiondock/core": "^2.5.1",
33
- "@actiondock/runtime-node": "^2.5.1",
34
- "@actiondock/sdk": "^2.5.1"
32
+ "@actiondock/core": "^2.6.0",
33
+ "@actiondock/runtime-node": "^2.6.0",
34
+ "@actiondock/sdk": "^2.6.0"
35
35
  },
36
36
  "keywords": [
37
37
  "actiondock",