@lark-apaas/miaoda-cli 0.1.24-alpha.4554556 → 0.1.24-alpha.495fda7
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/cli/commands/deploy/modern.js +0 -13
- package/dist/cli/commands/skills/index.js +7 -1
- package/dist/cli/handlers/deploy/modern.js +0 -1
- package/dist/cli/handlers/skills/sync.js +20 -0
- package/dist/services/deploy/modern/atoms/index.js +1 -5
- package/dist/services/deploy/modern/pipelines/design-local.js +8 -9
- package/dist/services/deploy/modern/pipelines/local.js +12 -13
- package/dist/utils/npm-pack.js +33 -0
- package/dist/utils/sandbox-skills.js +221 -0
- package/package.json +1 -1
- package/dist/services/deploy/modern/atoms/release-tracker.js +0 -43
|
@@ -17,7 +17,6 @@ function registerDeployCommandsModern(program) {
|
|
|
17
17
|
.description('触发 modern 应用发布:本地构建 + 本地部署(preRelease + localPublish)')
|
|
18
18
|
.option('--dir <path>', '项目目录', '.')
|
|
19
19
|
.option('--skip-build', '跳过 build 步骤(已构建好时使用)', false)
|
|
20
|
-
.option('--skip-release', '不创建/更新本地发布单,发布单状态由外部托管', false)
|
|
21
20
|
.option('--conf <json>', '关联元信息 JSON,仅识别 checkPointVersion / commitID 两字段')
|
|
22
21
|
.addHelpText('after', `
|
|
23
22
|
不要用异步模式或后台模式调用 deploy,否则调用可能提前结束,Agent 会误判发布已完成。
|
|
@@ -35,15 +34,6 @@ function registerDeployCommandsModern(program) {
|
|
|
35
34
|
6. savePluginInstances(扫描 dist/output_capabilities/*.json 批量注册)
|
|
36
35
|
7. finalizeLocalRelease(Finished|Failed)
|
|
37
36
|
|
|
38
|
-
--skip-release(发布单外部托管)
|
|
39
|
-
跳过第 4、7 步(createLocalRelease / updateLocalRelease),其余步骤不变:
|
|
40
|
-
preRelease 仍照常签发 version,构建、上传、capability 注册照常执行。
|
|
41
|
-
外部据 stdout 返回的 version / preReleaseID 自行建单,并据本命令的
|
|
42
|
-
退出码决定把发布单翻成 Finished 还是 Failed —— 失败态由外部负责,CLI 不再兜底。
|
|
43
|
-
该模式下 releaseID / url 输出为 null(CLI 未建单,无从得知)。
|
|
44
|
-
注意:--conf 的 checkPointVersion / commitID 唯一消费者是 createLocalRelease,
|
|
45
|
-
本模式下不生效(静默忽略,不报错),需要关联请在外部建单时自行传递。
|
|
46
|
-
|
|
47
37
|
--conf(关联元信息透传)
|
|
48
38
|
值为 JSON string,只识别两个字段,其余 key 忽略:
|
|
49
39
|
checkPointVersion 关联的 checkpoint 版本
|
|
@@ -52,13 +42,11 @@ function registerDeployCommandsModern(program) {
|
|
|
52
42
|
|
|
53
43
|
JSON 输出(stdout)
|
|
54
44
|
{"data": {"appId": "...", "version": <n>, "url": "...", "releaseID": "...", "preReleaseID": "..."}}
|
|
55
|
-
--skip-release 时 url 与 releaseID 为 null,字段本身仍在。
|
|
56
45
|
|
|
57
46
|
示例
|
|
58
47
|
$ miaoda deploy
|
|
59
48
|
$ miaoda deploy --dir ./my-app
|
|
60
49
|
$ miaoda deploy --skip-build
|
|
61
|
-
$ miaoda deploy --skip-release
|
|
62
50
|
$ miaoda deploy --conf '{"checkPointVersion":"v3","commitID":"a1b2c3d"}'
|
|
63
51
|
`);
|
|
64
52
|
deployCmd.action((0, shared_1.withHelp)(deployCmd, async (rawOpts) => {
|
|
@@ -66,7 +54,6 @@ JSON 输出(stdout)
|
|
|
66
54
|
dir: rawOpts.dir ?? '.',
|
|
67
55
|
appId: (0, shared_1.resolveAppId)({}),
|
|
68
56
|
skipBuild: rawOpts.skipBuild,
|
|
69
|
-
skipRelease: rawOpts.skipRelease,
|
|
70
57
|
conf: rawOpts.conf,
|
|
71
58
|
});
|
|
72
59
|
}));
|
|
@@ -21,11 +21,15 @@ function registerSkillsCommands(program) {
|
|
|
21
21
|
function registerSkillsSync(parent) {
|
|
22
22
|
const cmd = parent
|
|
23
23
|
.command('sync')
|
|
24
|
-
.description('同步 coding-steering
|
|
24
|
+
.description('同步 skills 到 user app(默认 coding-steering;带 --type 时走 sandbox-skills)')
|
|
25
25
|
.option('--dir <path>', '项目目录,默认当前目录', '.')
|
|
26
26
|
.option('--version <ver>', 'coding-steering 包版本或 dist-tag,缺省 latest')
|
|
27
27
|
.option('--local', '走本地 dev / agent 输出形态:拷到 .agents/skills 平铺 + 创建 .claude/skills 软链。' +
|
|
28
28
|
'不传时退回老形态:拷到 .agent/skills/steering/<stack>/skills/(跟沙箱端 update-skills.sh 对齐)', false)
|
|
29
|
+
.option('--type <type>', '走 sandbox-skills 分支:miaoda | miaoda-modern | miaoda-design | openclaw。' +
|
|
30
|
+
'有值时忽略 --version/--local,改从 @lark-apaas/coding-<pkg>-sandbox 拉对应包写入 .agent/skills/')
|
|
31
|
+
.option('--tgz-key <key>', '配合 --type 使用;老 TCC skillsUpdateTgzKey 值透传,' +
|
|
32
|
+
'从 skills_versions/all_<X>.tgz 反推出 dist-tag lane-<X>;缺省走 @latest')
|
|
29
33
|
.addHelpText('after', `
|
|
30
34
|
前置要求
|
|
31
35
|
当前目录(或 --dir)已走过 'miaoda app init'(.spark/meta.json 含 stack)
|
|
@@ -56,6 +60,8 @@ JSON 输出
|
|
|
56
60
|
dir: rawOpts.dir,
|
|
57
61
|
version: rawOpts.version,
|
|
58
62
|
local: rawOpts.local,
|
|
63
|
+
type: rawOpts.type,
|
|
64
|
+
tgzKey: rawOpts.tgzKey,
|
|
59
65
|
});
|
|
60
66
|
}));
|
|
61
67
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.handleSkillsSync = handleSkillsSync;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const coding_steering_1 = require("../../../utils/coding-steering");
|
|
9
|
+
const sandbox_skills_1 = require("../../../utils/sandbox-skills");
|
|
9
10
|
const spark_meta_1 = require("../../../utils/spark-meta");
|
|
10
11
|
const error_1 = require("../../../utils/error");
|
|
11
12
|
const output_1 = require("../../../utils/output");
|
|
@@ -26,6 +27,25 @@ const output_1 = require("../../../utils/output");
|
|
|
26
27
|
async function handleSkillsSync(opts) {
|
|
27
28
|
await Promise.resolve();
|
|
28
29
|
const targetDir = node_path_1.default.resolve(opts.dir ?? process.cwd());
|
|
30
|
+
// --type 走 sandbox-skills 分支(迁仓后沙箱内 update-skills.sh 调用),跟本地 dev 的
|
|
31
|
+
// steering 同步逻辑并列——两条路径的目标 / 拉包 / 目录结构完全不同,用 --type 显式路由。
|
|
32
|
+
if (opts.type !== undefined && opts.type !== '') {
|
|
33
|
+
const { type, tgzKey } = (0, sandbox_skills_1.validateSandboxSyncOpts)({ type: opts.type, tgzKey: opts.tgzKey });
|
|
34
|
+
const result = (0, sandbox_skills_1.syncSandboxSkills)({ type, tgzKey, targetDir });
|
|
35
|
+
(0, output_1.emit)({
|
|
36
|
+
data: {
|
|
37
|
+
mode: 'sandbox',
|
|
38
|
+
type,
|
|
39
|
+
packageName: result.packageName,
|
|
40
|
+
version: result.version,
|
|
41
|
+
lane: result.lane,
|
|
42
|
+
syncedTop: result.syncedTop,
|
|
43
|
+
targetDir: result.targetDir,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// 原有 coding-steering 同步逻辑(本地 dev / miaoda app init 用)
|
|
29
49
|
const meta = (0, spark_meta_1.readSparkMeta)(targetDir);
|
|
30
50
|
if (meta.stack === undefined || meta.stack === '') {
|
|
31
51
|
throw new error_1.AppError('SKILLS_META_INCOMPLETE', '.spark/meta.json missing stack — run `miaoda app init` first');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.savePluginInstances = exports.
|
|
3
|
+
exports.savePluginInstances = exports.LocalReleaseStatus = exports.finalizeLocalRelease = exports.createLocalRelease = exports.uploadArtifacts = exports.uploadDesignArtifacts = exports.cleanDesignDist = exports.buildDesignOutput = exports.runBuild = exports.preRelease = exports.prepareDeployContext = void 0;
|
|
4
4
|
var context_1 = require("./context");
|
|
5
5
|
Object.defineProperty(exports, "prepareDeployContext", { enumerable: true, get: function () { return context_1.prepareDeployContext; } });
|
|
6
6
|
var pre_release_1 = require("./pre-release");
|
|
@@ -18,9 +18,5 @@ var local_release_1 = require("./local-release");
|
|
|
18
18
|
Object.defineProperty(exports, "createLocalRelease", { enumerable: true, get: function () { return local_release_1.createLocalRelease; } });
|
|
19
19
|
Object.defineProperty(exports, "finalizeLocalRelease", { enumerable: true, get: function () { return local_release_1.finalizeLocalRelease; } });
|
|
20
20
|
Object.defineProperty(exports, "LocalReleaseStatus", { enumerable: true, get: function () { return local_release_1.LocalReleaseStatus; } });
|
|
21
|
-
var release_tracker_1 = require("./release-tracker");
|
|
22
|
-
Object.defineProperty(exports, "NOOP_RELEASE_TRACKER", { enumerable: true, get: function () { return release_tracker_1.NOOP_RELEASE_TRACKER; } });
|
|
23
|
-
Object.defineProperty(exports, "createManagedReleaseTracker", { enumerable: true, get: function () { return release_tracker_1.createManagedReleaseTracker; } });
|
|
24
|
-
Object.defineProperty(exports, "resolveReleaseTracker", { enumerable: true, get: function () { return release_tracker_1.resolveReleaseTracker; } });
|
|
25
21
|
var save_plugin_instances_1 = require("./save-plugin-instances");
|
|
26
22
|
Object.defineProperty(exports, "savePluginInstances", { enumerable: true, get: function () { return save_plugin_instances_1.savePluginInstances; } });
|
|
@@ -24,26 +24,25 @@ async function designLocalPublishPipeline(opts) {
|
|
|
24
24
|
if (!opts.skipBuild) {
|
|
25
25
|
(0, index_1.buildDesignOutput)({ projectDir: ctx.projectDir });
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
extra: { checkPointVersion: opts.checkPointVersion, commitID: opts.commitID },
|
|
27
|
+
(0, logger_1.log)('deploy', 'Creating local release...');
|
|
28
|
+
const release = await (0, index_1.createLocalRelease)(ctx.appId, pre.version, {
|
|
29
|
+
checkPointVersion: opts.checkPointVersion,
|
|
30
|
+
commitID: opts.commitID,
|
|
32
31
|
});
|
|
33
32
|
try {
|
|
34
33
|
await (0, index_1.uploadDesignArtifacts)({ projectDir: ctx.projectDir, data });
|
|
35
|
-
await
|
|
34
|
+
await (0, index_1.finalizeLocalRelease)(ctx.appId, release.releaseID, index_1.LocalReleaseStatus.Finished);
|
|
36
35
|
}
|
|
37
36
|
catch (err) {
|
|
38
|
-
await
|
|
37
|
+
await (0, index_1.finalizeLocalRelease)(ctx.appId, release.releaseID, index_1.LocalReleaseStatus.Failed);
|
|
39
38
|
throw err;
|
|
40
39
|
}
|
|
41
40
|
(0, logger_1.log)('deploy', 'Deployed successfully');
|
|
42
41
|
return {
|
|
43
42
|
appId: ctx.appId,
|
|
44
43
|
version: pre.version,
|
|
45
|
-
url:
|
|
46
|
-
releaseID:
|
|
44
|
+
url: release.onlineUrl ?? '',
|
|
45
|
+
releaseID: release.releaseID,
|
|
47
46
|
preReleaseID: pre.preReleaseID,
|
|
48
47
|
};
|
|
49
48
|
}
|
|
@@ -11,14 +11,14 @@ const index_1 = require("../atoms/index");
|
|
|
11
11
|
* 1. prepareDeployContext — 校验项目 + 读 meta
|
|
12
12
|
* 2. preRelease — 签发 pre_release_id / version / 动态配置 data
|
|
13
13
|
* 3. runBuild — 本地 npm run build(注入 data 中的 CDN 前缀)
|
|
14
|
-
* 4.
|
|
14
|
+
* 4. createLocalRelease — 创建发布单(加锁、拿 releaseID)
|
|
15
15
|
* 5. uploadArtifacts — 把产物推到 preRelease 下发的 pre-signed URL
|
|
16
16
|
* 6. savePluginInstances — 扫描 dist/output_capabilities/*.json,批量注册插件能力
|
|
17
|
-
* 7.
|
|
17
|
+
* 7. finalizeLocalRelease — Finished / Failed 翻终态
|
|
18
18
|
*
|
|
19
|
-
*
|
|
19
|
+
* createLocalRelease 提前到 upload 之前:发布单先建出来,
|
|
20
|
+
* upload / savePluginInstances 在已知 releaseID 的前提下进行;
|
|
20
21
|
* 任一步失败都会精准把该发布单标记为 Failed,避免遗留挂态。
|
|
21
|
-
* `--skip-release` 下发布单由外部托管,tracker 为 NOOP,失败信息通过非零退出码传递。
|
|
22
22
|
*/
|
|
23
23
|
async function localBuildLocalPublishPipeline(opts) {
|
|
24
24
|
const ctx = (0, index_1.prepareDeployContext)(opts.projectDir, opts.appId);
|
|
@@ -41,11 +41,10 @@ async function localBuildLocalPublishPipeline(opts) {
|
|
|
41
41
|
data,
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
extra: { checkPointVersion: opts.checkPointVersion, commitID: opts.commitID },
|
|
44
|
+
(0, logger_1.log)('deploy', 'Creating local release...');
|
|
45
|
+
const release = await (0, index_1.createLocalRelease)(ctx.appId, pre.version, {
|
|
46
|
+
checkPointVersion: opts.checkPointVersion,
|
|
47
|
+
commitID: opts.commitID,
|
|
49
48
|
});
|
|
50
49
|
try {
|
|
51
50
|
(0, logger_1.log)('deploy', 'Uploading artifacts...');
|
|
@@ -58,18 +57,18 @@ async function localBuildLocalPublishPipeline(opts) {
|
|
|
58
57
|
if (saveResult.saved > 0) {
|
|
59
58
|
(0, logger_1.log)('deploy', `${String(saveResult.saved)} capability instance(s) registered`);
|
|
60
59
|
}
|
|
61
|
-
await
|
|
60
|
+
await (0, index_1.finalizeLocalRelease)(ctx.appId, release.releaseID, index_1.LocalReleaseStatus.Finished);
|
|
62
61
|
}
|
|
63
62
|
catch (err) {
|
|
64
|
-
await
|
|
63
|
+
await (0, index_1.finalizeLocalRelease)(ctx.appId, release.releaseID, index_1.LocalReleaseStatus.Failed);
|
|
65
64
|
throw err;
|
|
66
65
|
}
|
|
67
66
|
(0, logger_1.log)('deploy', 'Deployed successfully');
|
|
68
67
|
return {
|
|
69
68
|
appId: ctx.appId,
|
|
70
69
|
version: pre.version,
|
|
71
|
-
url:
|
|
72
|
-
releaseID:
|
|
70
|
+
url: release.onlineUrl ?? '',
|
|
71
|
+
releaseID: release.releaseID,
|
|
73
72
|
preReleaseID: pre.preReleaseID,
|
|
74
73
|
};
|
|
75
74
|
}
|
package/dist/utils/npm-pack.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pickLaneVersion = pickLaneVersion;
|
|
6
7
|
exports.fetchNpmPackage = fetchNpmPackage;
|
|
7
8
|
const node_child_process_1 = require("node:child_process");
|
|
8
9
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
@@ -11,6 +12,38 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
11
12
|
const error_1 = require("./error");
|
|
12
13
|
const logger_1 = require("./logger");
|
|
13
14
|
const DEFAULT_REGISTRY = 'https://registry.npmmirror.com/';
|
|
15
|
+
/**
|
|
16
|
+
* 从 `npm view <pkg> versions --json` 里过滤出后缀 `-alpha.<X>` 的版本。
|
|
17
|
+
*
|
|
18
|
+
* 用于 sandbox-skills 新姿势(2026-08 迁离 lane-<X> dist-tag 之后):
|
|
19
|
+
* publish-sandbox-skills.sh 每次发的版本号 = `<base>-alpha.<LANE>-<YYYYMMDDHHMMSS>`,
|
|
20
|
+
* TCC 里的 X = `<LANE>-<TIMESTAMP>` 全局唯一。反推侧过滤 versions 数组即可精确命中。
|
|
21
|
+
*
|
|
22
|
+
* **不 throw 是硬要求**(消费方 fallback @latest 依赖返回 null 判定):
|
|
23
|
+
* - `npm view` 网络挂、包不存在、metadata 解析失败 → 返回 null
|
|
24
|
+
* - 无版本匹配 → 返回 null
|
|
25
|
+
* - 多版本匹配(理论上不该发生,因 timestamp 精度到秒)→ 字符串排序取最大(timestamp 最大)
|
|
26
|
+
*/
|
|
27
|
+
function pickLaneVersion(packageName, X, registry) {
|
|
28
|
+
const reg = registry ?? process.env.MIAODA_NPM_REGISTRY ?? DEFAULT_REGISTRY;
|
|
29
|
+
const suffix = `-alpha.${X}`;
|
|
30
|
+
try {
|
|
31
|
+
const stdout = (0, node_child_process_1.execFileSync)('npm', ['view', packageName, 'versions', '--json', '--registry', reg], { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
|
|
32
|
+
const versions = JSON.parse(stdout);
|
|
33
|
+
if (!Array.isArray(versions))
|
|
34
|
+
return null;
|
|
35
|
+
const matched = versions.filter((v) => typeof v === 'string' && v.endsWith(suffix));
|
|
36
|
+
if (matched.length === 0)
|
|
37
|
+
return null;
|
|
38
|
+
// 通常唯一命中(X 含 timestamp 到秒);多命中时字符串排序取最大(timestamp 更晚)
|
|
39
|
+
matched.sort();
|
|
40
|
+
return matched[matched.length - 1] ?? null;
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
(0, logger_1.debug)(`pickLaneVersion(${packageName}, X=${X}) failed: ${err.message}`);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
14
47
|
/**
|
|
15
48
|
* `npm pack <pkg>@<ver> --registry <r>` + `tar -xzf`,解到临时目录。
|
|
16
49
|
* extractDir 是包内容根(含 package.json)。使用完必须 cleanup()。
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractLaneFromTgzKey = extractLaneFromTgzKey;
|
|
7
|
+
exports.syncSandboxSkills = syncSandboxSkills;
|
|
8
|
+
exports.validateSandboxSyncOpts = validateSandboxSyncOpts;
|
|
9
|
+
const node_child_process_1 = require("node:child_process");
|
|
10
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
+
const npm_pack_1 = require("../utils/npm-pack");
|
|
13
|
+
const error_1 = require("../utils/error");
|
|
14
|
+
const logger_1 = require("../utils/logger");
|
|
15
|
+
/**
|
|
16
|
+
* 覆盖式清空目录,权限兜底:`chmod -R u+w` → `rm -rf` → `fs.rmSync`。
|
|
17
|
+
*
|
|
18
|
+
* 为什么要 chmod:沙箱里 skill 目录 owner 是当前用户 (gem),但老
|
|
19
|
+
* `update-skills.sh` 会显式 `chmod -R a-w` 把 skill 目录锁只读(防用户改 skill 内容)。
|
|
20
|
+
* gem 是 owner 但没 write 权限,unlink 里面文件挂 EACCES;shell `rm -rf` 也过不去。
|
|
21
|
+
* 因为 gem 是 owner,`chmod -R u+w` 能自己给自己加写权限(不需要 sudo,绕过沙箱
|
|
22
|
+
* "no new privileges" 容器 flag)。
|
|
23
|
+
*/
|
|
24
|
+
function forceRemoveDir(dir) {
|
|
25
|
+
if (!node_fs_1.default.existsSync(dir))
|
|
26
|
+
return;
|
|
27
|
+
// 先 chmod -R u+w 恢复写权限(应对老 update.sh 的 `chmod -R a-w` 只读锁)
|
|
28
|
+
try {
|
|
29
|
+
(0, node_child_process_1.execFileSync)('chmod', ['-R', 'u+w', dir], { stdio: ['ignore', 'ignore', 'pipe'] });
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
(0, logger_1.debug)(`sandbox-skills: chmod -R u+w ${dir} failed: ${err.message}`);
|
|
33
|
+
}
|
|
34
|
+
// 主档:shell rm -rf
|
|
35
|
+
try {
|
|
36
|
+
(0, node_child_process_1.execFileSync)('rm', ['-rf', dir], { stdio: ['ignore', 'ignore', 'pipe'] });
|
|
37
|
+
if (!node_fs_1.default.existsSync(dir))
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
(0, logger_1.debug)(`sandbox-skills: rm -rf ${dir} failed: ${err.message}`);
|
|
42
|
+
}
|
|
43
|
+
// Fallback:Node fs.rmSync 尽力而为
|
|
44
|
+
node_fs_1.default.rmSync(dir, { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
const PACKAGE_BY_TYPE = {
|
|
47
|
+
miaoda: '@lark-apaas/coding-miaoda-sandbox-skills',
|
|
48
|
+
'miaoda-modern': '@lark-apaas/coding-miaoda-sandbox-skills',
|
|
49
|
+
'miaoda-design': '@lark-apaas/coding-miaoda-sandbox-skills',
|
|
50
|
+
openclaw: '@lark-apaas/coding-openclaw-sandbox-skills',
|
|
51
|
+
};
|
|
52
|
+
// 合并包内的业务线子目录(miaoda / miaoda-modern / miaoda-design);shared 单独处理。
|
|
53
|
+
const BUSINESS_LINE_BY_TYPE = {
|
|
54
|
+
miaoda: 'miaoda',
|
|
55
|
+
'miaoda-modern': 'miaoda-modern',
|
|
56
|
+
'miaoda-design': 'miaoda-design',
|
|
57
|
+
openclaw: null, // openclaw 独立包,直接展平
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* 从 TCC skillsUpdateTgzKey 反推 lane 名。
|
|
61
|
+
* skills_versions/all_feat-xxx.tgz → feat-xxx
|
|
62
|
+
* skills_versions/all_feat_xxx.tgz → feat-xxx (_ sanitize → -)
|
|
63
|
+
* skills_versions/all_latest.tgz → null(走 @latest)
|
|
64
|
+
* 任何 all_<X>.tgz → <X> 里 _ 全部转 -
|
|
65
|
+
*
|
|
66
|
+
* **宽进严出**:正则允许 `_` 匹配(兼容老 miaoda-skills 时代 TOS key 含 `_` 的存量 TCC
|
|
67
|
+
* 命名),但返回时 sanitize 成 `-` —— 对齐 publish-sandbox-skills.sh 侧只发 `-` 版
|
|
68
|
+
* lane 的现实(npm SemVer pre-release 只允许 `[A-Za-z0-9-]`,不允许 `_`)。
|
|
69
|
+
* 存量 TCC 里如果有 `all_feat_xxx.tgz` 这种命名,反推出 `feat-xxx` 后能正确命中
|
|
70
|
+
* npm 上实际发出的 `@lane-feat-xxx` 包,而不是静默 fallback 到 @latest。
|
|
71
|
+
*
|
|
72
|
+
* 用 nullable 而不是空字符串 —— 让调用方能判断"没 lane 就走 latest"。
|
|
73
|
+
*/
|
|
74
|
+
function extractLaneFromTgzKey(tgzKey) {
|
|
75
|
+
if (tgzKey === undefined || tgzKey === '') {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const match = /(?:^|\/)all_([A-Za-z0-9][A-Za-z0-9_-]*)\.tgz$/.exec(tgzKey);
|
|
79
|
+
if (match === null) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
const lane = match[1].replace(/_/g, '-');
|
|
83
|
+
if (lane === 'latest') {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return lane;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 主流程:按 type 拉包 + sync 到目标目录。
|
|
90
|
+
*
|
|
91
|
+
* sync 策略:**覆盖式写入 + 老文件清理**,对齐老 cp-skills.sh 行为
|
|
92
|
+
* (`rm -rf $TARGET; mkdir -p $TARGET; cp -r ...`)。
|
|
93
|
+
*/
|
|
94
|
+
function syncSandboxSkills(opts) {
|
|
95
|
+
const targetDir = node_path_1.default.resolve(opts.targetDir ?? process.cwd());
|
|
96
|
+
const packageName = PACKAGE_BY_TYPE[opts.type];
|
|
97
|
+
const businessLine = BUSINESS_LINE_BY_TYPE[opts.type];
|
|
98
|
+
const lane = extractLaneFromTgzKey(opts.tgzKey);
|
|
99
|
+
// ---- lane 拉包 ----
|
|
100
|
+
// 新姿势(2026-08 迁离 lane-<X> dist-tag 之后):
|
|
101
|
+
// TCC 里的 X(比如 `feat-migrate-skills-from-miaoda-skills-20260805143512`)
|
|
102
|
+
// 包含 branch + timestamp,`pickLaneVersion` 走 `npm view <pkg> versions --json`
|
|
103
|
+
// 过滤 `endsWith('-alpha.' + X)`(因 X 含 timestamp 全局唯一,唯一命中或 0 命中)。
|
|
104
|
+
// 0 命中 → fallback @latest(对齐旧 TCC 值找不到、灰度切换期间的兜底语义)。
|
|
105
|
+
// `pickLaneVersion` 内部对 `npm view` 报错 / 无匹配都返回 null,绝不 throw ——
|
|
106
|
+
// 目标就是"不挂掉"。
|
|
107
|
+
let fetched;
|
|
108
|
+
const laneVersion = lane === null ? null : (0, npm_pack_1.pickLaneVersion)(packageName, lane, opts.registry);
|
|
109
|
+
if (lane !== null && laneVersion === null) {
|
|
110
|
+
(0, logger_1.debug)(`sandbox-skills: no npm version matched -alpha.${lane}, fallback to @latest ` +
|
|
111
|
+
`(TCC 里的 X 可能是老 lane dist-tag 命名 / 已 unpublish / npm view 挂 / 网络断)`);
|
|
112
|
+
}
|
|
113
|
+
const primaryVersion = laneVersion ?? 'latest';
|
|
114
|
+
try {
|
|
115
|
+
(0, logger_1.debug)(`sandbox-skills: fetching ${packageName}@${primaryVersion}`);
|
|
116
|
+
fetched = (0, npm_pack_1.fetchNpmPackage)({
|
|
117
|
+
packageName,
|
|
118
|
+
version: primaryVersion,
|
|
119
|
+
registry: opts.registry,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
if (primaryVersion === 'latest') {
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
126
|
+
(0, logger_1.debug)(`sandbox-skills: pack ${primaryVersion} failed, fallback to @latest (err: ${err.message})`);
|
|
127
|
+
fetched = (0, npm_pack_1.fetchNpmPackage)({
|
|
128
|
+
packageName,
|
|
129
|
+
version: 'latest',
|
|
130
|
+
registry: opts.registry,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
// 计算 skill 目标根目录:
|
|
135
|
+
// - openclaw → <targetDir>/skills/(跟老 cp-skills.sh 的 openclaw 分支对齐,落 $WORKSPACE_DIR/agent/skills)
|
|
136
|
+
// - 其它 → <targetDir>/.agent/skills/
|
|
137
|
+
const skillsRoot = opts.type === 'openclaw'
|
|
138
|
+
? node_path_1.default.join(targetDir, 'skills')
|
|
139
|
+
: node_path_1.default.join(targetDir, '.agent', 'skills');
|
|
140
|
+
// 覆盖式:清空目标 skill 根目录(对齐 cp-skills.sh 行为,避免遗留老 skill)
|
|
141
|
+
// 用 forceRemoveDir 兜底:老沙箱可能残留其他用户写的 stale 文件(例如老 update.sh
|
|
142
|
+
// 以 root 跑,写下 root owned 的 `.last-update`),fs.rmSync {force:true} 遇到 EACCES
|
|
143
|
+
// 会 throw。见 forceRemoveDir 注释。
|
|
144
|
+
forceRemoveDir(skillsRoot);
|
|
145
|
+
node_fs_1.default.mkdirSync(skillsRoot, { recursive: true });
|
|
146
|
+
const syncedTop = [];
|
|
147
|
+
if (businessLine !== null) {
|
|
148
|
+
// 合并包 miaoda/miaoda-modern/miaoda-design:cp <extractDir>/<business-line>/* 到 target
|
|
149
|
+
const sourceDir = node_path_1.default.join(fetched.extractDir, businessLine);
|
|
150
|
+
if (node_fs_1.default.existsSync(sourceDir)) {
|
|
151
|
+
for (const entry of node_fs_1.default.readdirSync(sourceDir)) {
|
|
152
|
+
const from = node_path_1.default.join(sourceDir, entry);
|
|
153
|
+
const to = node_path_1.default.join(skillsRoot, entry);
|
|
154
|
+
node_fs_1.default.cpSync(from, to, { recursive: true });
|
|
155
|
+
syncedTop.push(entry);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
(0, logger_1.debug)(`sandbox-skills: source dir ${sourceDir} not found in package (skipped)`);
|
|
160
|
+
}
|
|
161
|
+
// shared:sync 合并包内 shared/* 到 target(对齐老 build.sh 的 shared 分发行为)
|
|
162
|
+
const sharedDir = node_path_1.default.join(fetched.extractDir, 'shared');
|
|
163
|
+
if (node_fs_1.default.existsSync(sharedDir)) {
|
|
164
|
+
for (const entry of node_fs_1.default.readdirSync(sharedDir)) {
|
|
165
|
+
const from = node_path_1.default.join(sharedDir, entry);
|
|
166
|
+
const to = node_path_1.default.join(skillsRoot, entry);
|
|
167
|
+
if (node_fs_1.default.existsSync(to)) {
|
|
168
|
+
// shared 命中已存在的 skill(如同名)— 保留业务线版本,跳过 shared(对齐老 build.sh:shared 是补丁,同名不覆盖)
|
|
169
|
+
(0, logger_1.debug)(`sandbox-skills: shared/${entry} conflicts with business-line skill, skipped`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
node_fs_1.default.cpSync(from, to, { recursive: true });
|
|
173
|
+
syncedTop.push(entry);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
// openclaw 独立包:直接把包内所有 skill 目录(除 package.json 等元文件外)平铺到 skillsRoot
|
|
179
|
+
for (const entry of node_fs_1.default.readdirSync(fetched.extractDir)) {
|
|
180
|
+
if (entry === 'package.json' || entry === 'README.md' || entry === 'LICENSE')
|
|
181
|
+
continue;
|
|
182
|
+
const from = node_path_1.default.join(fetched.extractDir, entry);
|
|
183
|
+
const stat = node_fs_1.default.statSync(from);
|
|
184
|
+
if (!stat.isDirectory())
|
|
185
|
+
continue;
|
|
186
|
+
const to = node_path_1.default.join(skillsRoot, entry);
|
|
187
|
+
node_fs_1.default.cpSync(from, to, { recursive: true });
|
|
188
|
+
syncedTop.push(entry);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// 写 .last-update 时间戳(对齐老 update-skills.sh;供 feida-ai freshness 检查用)
|
|
192
|
+
const lastUpdatePath = node_path_1.default.join(skillsRoot, '.last-update');
|
|
193
|
+
node_fs_1.default.writeFileSync(lastUpdatePath, String(Date.now()));
|
|
194
|
+
return {
|
|
195
|
+
packageName,
|
|
196
|
+
version: fetched.version,
|
|
197
|
+
lane,
|
|
198
|
+
syncedTop,
|
|
199
|
+
targetDir: skillsRoot,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
fetched.cleanup();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* 参数校验:type 白名单 + tgzKey 格式(避免非法值透传到 npm 包名)。
|
|
208
|
+
*/
|
|
209
|
+
function validateSandboxSyncOpts(opts) {
|
|
210
|
+
const validTypes = ['miaoda', 'miaoda-modern', 'miaoda-design', 'openclaw'];
|
|
211
|
+
if (opts.type === undefined || !validTypes.includes(opts.type)) {
|
|
212
|
+
throw new error_1.AppError('SKILLS_INVALID_TYPE', `--type must be one of: ${validTypes.join(', ')} (got: ${opts.type ?? 'undefined'})`);
|
|
213
|
+
}
|
|
214
|
+
if (opts.tgzKey !== undefined && opts.tgzKey !== '') {
|
|
215
|
+
// 校验 tgz key 大致格式(前缀 skills_versions/ + all_ + 允许字符 + .tgz);避免非法值影响 lane 反推
|
|
216
|
+
if (!/^[A-Za-z0-9/_\-.]+\.tgz$/.test(opts.tgzKey)) {
|
|
217
|
+
throw new error_1.AppError('SKILLS_INVALID_TGZ_KEY', `--tgz-key value looks invalid: ${opts.tgzKey}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return { type: opts.type, tgzKey: opts.tgzKey };
|
|
221
|
+
}
|
package/package.json
CHANGED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NOOP_RELEASE_TRACKER = void 0;
|
|
4
|
-
exports.createManagedReleaseTracker = createManagedReleaseTracker;
|
|
5
|
-
exports.resolveReleaseTracker = resolveReleaseTracker;
|
|
6
|
-
const logger_1 = require("../../../../utils/logger");
|
|
7
|
-
const local_release_1 = require("./local-release");
|
|
8
|
-
/**
|
|
9
|
-
* 建本地发布单并返回受管 tracker。
|
|
10
|
-
*
|
|
11
|
-
* url 沿用原有口径:后端 onlineUrl 缺失时为空串(`''` 表示"后端没给",
|
|
12
|
-
* 与外部托管模式的 `null`「本模式不产生」是两个不同语义,别合并)。
|
|
13
|
-
*/
|
|
14
|
-
async function createManagedReleaseTracker(appId, version, extra) {
|
|
15
|
-
(0, logger_1.log)('deploy', 'Creating local release...');
|
|
16
|
-
const release = await (0, local_release_1.createLocalRelease)(appId, version, extra);
|
|
17
|
-
return {
|
|
18
|
-
releaseID: release.releaseID,
|
|
19
|
-
url: release.onlineUrl ?? '',
|
|
20
|
-
finish: () => (0, local_release_1.finalizeLocalRelease)(appId, release.releaseID, local_release_1.LocalReleaseStatus.Finished),
|
|
21
|
-
fail: () => (0, local_release_1.finalizeLocalRelease)(appId, release.releaseID, local_release_1.LocalReleaseStatus.Failed),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* 空实现:发布单由外部托管,CLI 不建单也不翻终态。
|
|
26
|
-
*
|
|
27
|
-
* 外部据 CLI 的退出码决定把自己的发布单翻成 Finished 还是 Failed,
|
|
28
|
-
* 因此这里的 finish/fail 必须是真正的 no-op,不能顺手打日志误导排查。
|
|
29
|
-
*/
|
|
30
|
-
exports.NOOP_RELEASE_TRACKER = {
|
|
31
|
-
releaseID: null,
|
|
32
|
-
url: null,
|
|
33
|
-
finish: () => Promise.resolve(),
|
|
34
|
-
fail: () => Promise.resolve(),
|
|
35
|
-
};
|
|
36
|
-
/** 按 skipRelease 选 tracker:跳过则 NOOP,否则建真实发布单。 */
|
|
37
|
-
async function resolveReleaseTracker(opts) {
|
|
38
|
-
if (opts.skipRelease) {
|
|
39
|
-
(0, logger_1.log)('deploy', 'Skipping local release (managed externally)');
|
|
40
|
-
return exports.NOOP_RELEASE_TRACKER;
|
|
41
|
-
}
|
|
42
|
-
return createManagedReleaseTracker(opts.appId, opts.version, opts.extra);
|
|
43
|
-
}
|