@lark-apaas/miaoda-cli 0.1.24-alpha.54e1135 → 0.1.24-alpha.5e3d4ef
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/api/app/api.js +50 -5
- package/dist/cli/commands/app/index.js +14 -9
- package/dist/cli/commands/skills/index.js +1 -7
- package/dist/cli/handlers/app/export.js +62 -14
- package/dist/cli/handlers/skills/sync.js +0 -20
- package/dist/utils/devops-error.js +19 -5
- package/package.json +1 -1
- package/dist/utils/sandbox-skills.js +0 -202
package/dist/api/app/api.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.updateAppMeta = updateAppMeta;
|
|
|
5
5
|
exports.getCodeArchive = getCodeArchive;
|
|
6
6
|
const http_1 = require("../../utils/http");
|
|
7
7
|
const devops_error_1 = require("../../utils/devops-error");
|
|
8
|
+
const error_1 = require("../../utils/error");
|
|
8
9
|
const DEFAULT_ERR_CODE = 'INTERNAL_DEVOPS_ERROR';
|
|
9
10
|
function envelopeOpts(errPrefix) {
|
|
10
11
|
return {
|
|
@@ -24,22 +25,66 @@ async function updateAppMeta(req) {
|
|
|
24
25
|
// 路径已带 appID,body 里也保留以匹配 BAM IDL 的 sensitive:"no" 透传约定
|
|
25
26
|
return (0, http_1.postInnerApi)(url, req, envelopeOpts('Failed to update app'));
|
|
26
27
|
}
|
|
28
|
+
function mapExportError(bizCode, message, source) {
|
|
29
|
+
// token 是敏感令牌,错误信息只截前 8 位辅助定位
|
|
30
|
+
const sourceDesc = source.sourceAppID
|
|
31
|
+
? `应用 ${source.sourceAppID}`
|
|
32
|
+
: `分享 token ${(source.sourceMetaToken ?? '').slice(0, 8)}...`;
|
|
33
|
+
switch (bizCode) {
|
|
34
|
+
// 身份换取失败,或非源应用协作者(服务端 DOWNLOAD 鉴权不过)
|
|
35
|
+
case devops_error_1.BizErrCode.STUDIO_UNAUTHENTICATED:
|
|
36
|
+
return new error_1.AppError('EXPORT_PERMISSION_DENIED', `无权导出 ${sourceDesc}:${message}`, {
|
|
37
|
+
next_actions: [
|
|
38
|
+
`确认你是源应用的协作者;不是的话请让应用所有者添加协作者后重试`,
|
|
39
|
+
'这是权限问题,不是凭证配置或服务端抖动:不要重复执行本命令,也不要尝试自行签发 token',
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
// meta_token 无效或未绑定妙搭应用(服务端 ResolveAppIDByMetaToken 反查失败)
|
|
43
|
+
case devops_error_1.BizErrCode.STUDIO_APP_NOT_FOUND:
|
|
44
|
+
return new error_1.AppError('EXPORT_APP_NOT_FOUND', `${sourceDesc} 未找到对应应用:${message}`, {
|
|
45
|
+
next_actions: [
|
|
46
|
+
'核对分享 token / 链接是否完整(创意应用 URL 形如 https://<tenant>.feishu.cn/page/<token>)',
|
|
47
|
+
'确认目标是创意应用(只有创意应用有分享 token);这是目标不存在问题:不要重复执行本命令,请向用户确认',
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
// 应用不存在(错误 ID)
|
|
51
|
+
case devops_error_1.BizErrCode.DEVOPS_APP_NOT_FOUND:
|
|
52
|
+
case devops_error_1.BizErrCode.DEVOPS_APP_NOT_FOUND_ALT:
|
|
53
|
+
return new error_1.AppError('EXPORT_APP_NOT_FOUND', `${sourceDesc} 不存在或不可访问:${message}`, {
|
|
54
|
+
next_actions: [
|
|
55
|
+
'核对源应用 ID(应用页 URL 形如 /app/app_xxx,该段才是应用 ID)',
|
|
56
|
+
'这是目标不存在问题:不要重复执行本命令,请向用户确认正确的应用 ID',
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
default:
|
|
60
|
+
return (0, devops_error_1.mapDevopsError)(bizCode, message);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
27
63
|
/**
|
|
28
|
-
* GET /api/v1/studio/innerapi/apps/:appID/code-archive
|
|
64
|
+
* GET /api/v1/studio/innerapi/apps/:appID/code-archive — 导出源应用源码归档。
|
|
29
65
|
* 走 studio_server inner 通道(force 身份,服务侧 force→lark 换取后按 DOWNLOAD 鉴权,
|
|
30
|
-
*
|
|
66
|
+
* 鉴权对象是源应用),与 comment 域同一 inner 信封;创意应用升级链路(app export)消费。
|
|
31
67
|
*
|
|
32
68
|
* path :appID 必须是当前沙箱应用:网关 apaas_force_admin_plugin 强校验 URL appID 与沙箱
|
|
33
69
|
* AK 绑定应用一致(不一致 400 "appID in url is illegal"),跨应用导出目标因此走 query。
|
|
70
|
+
* 源应用定位二选一:sourceAppID(app_xxx),或 sourceMetaToken(创意应用分享 URL
|
|
71
|
+
* /page/<token> 的 CCM token,服务端反查 appID 后按同一口径鉴权)。
|
|
34
72
|
*/
|
|
35
73
|
async function getCodeArchive(params) {
|
|
36
|
-
const { appID, sourceAppID, checkpointID } = params;
|
|
37
|
-
|
|
38
|
-
|
|
74
|
+
const { appID, sourceAppID, sourceMetaToken, checkpointID } = params;
|
|
75
|
+
if (!sourceAppID === !sourceMetaToken) {
|
|
76
|
+
throw new error_1.AppError('ARGS_INVALID', 'sourceAppID 与 sourceMetaToken 必须恰传其一');
|
|
77
|
+
}
|
|
78
|
+
const sourceQuery = sourceAppID
|
|
79
|
+
? `sourceAppID=${encodeURIComponent(sourceAppID)}`
|
|
80
|
+
: `sourceMetaToken=${encodeURIComponent(sourceMetaToken ?? '')}`;
|
|
81
|
+
let url = `/api/v1/studio/innerapi/apps/${encodeURIComponent(appID)}/code-archive?` + sourceQuery;
|
|
39
82
|
if (checkpointID !== undefined && checkpointID > 0) {
|
|
40
83
|
url += `&checkPointID=${String(checkpointID)}`;
|
|
41
84
|
}
|
|
42
85
|
return (0, http_1.getInnerApi)(url, {
|
|
43
86
|
errPrefix: 'Failed to export code archive',
|
|
87
|
+
defaultErrCode: DEFAULT_ERR_CODE,
|
|
88
|
+
mapErr: (bizCode, message) => mapExportError(bizCode, message, { sourceAppID, sourceMetaToken }),
|
|
44
89
|
});
|
|
45
90
|
}
|
|
@@ -122,32 +122,37 @@ JSON 输出
|
|
|
122
122
|
}
|
|
123
123
|
function registerAppExport(parent) {
|
|
124
124
|
const cmd = parent
|
|
125
|
-
.command('export <app-id>')
|
|
126
|
-
.description('
|
|
125
|
+
.command('export <app-id-or-token>')
|
|
126
|
+
.description('导出指定应用的源码到本工程(创意应用升级:拉取创意稿作只读参考物);接受应用 ID(app_xxx)或创意应用分享 token')
|
|
127
127
|
.option('--out <dir>', '输出目录(相对当前目录)', 'source_package/creative')
|
|
128
128
|
.option('--checkpoint <n>', '按检查点版本导出;缺省为最新提交(HEAD)')
|
|
129
129
|
.addHelpText('after', `
|
|
130
130
|
说明
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
从服务端导出源应用(可以不是当前应用)的源码归档并解压到 --out 目录,导出完成后写
|
|
132
|
+
--out/.upgrade-manifest.json(含 sourceAppId / 导出时间 / 文件数),供升级链路幂等
|
|
133
|
+
判定与 skill 发现使用。调用者须为源应用协作者(服务端 DOWNLOAD 鉴权)。
|
|
134
|
+
<app-id-or-token> 两种形态等价:应用 ID(app_xxx)或创意应用分享 token。拿到的是
|
|
135
|
+
分享链接(https://<tenant>.feishu.cn/page/<token>)时,提取其中 /page/ 后的 <token> 段传入。
|
|
136
|
+
请求以当前应用(MIAODA_APP_ID)为路径主体、源应用走 sourceAppID / sourceMetaToken 参数。
|
|
135
137
|
|
|
136
138
|
幂等
|
|
137
|
-
--out 已存在 manifest
|
|
139
|
+
--out 已存在 manifest 且源定位(sourceAppId / sourceMetaToken)一致时跳过导出
|
|
140
|
+
(skipped=true),重复调用安全。
|
|
138
141
|
|
|
139
142
|
JSON 输出
|
|
140
143
|
{"data": {"appId": "...", "out": "source_package/creative", "fileCount": <n>,
|
|
141
144
|
"archiveName": "...", "skipped": false}}
|
|
142
145
|
跳过时:{"data": {"appId": "...", "out": "...", "skipped": true, "reason": "already_exported"}}
|
|
146
|
+
appId 始终是实际导出的源应用 ID(传 token 时为服务端反查结果)。
|
|
143
147
|
|
|
144
148
|
失败
|
|
145
149
|
源应用无可导出内容(从未提交过代码)→ EXPORT_EMPTY_ARCHIVE,请先在源应用完成一轮创作。
|
|
146
|
-
|
|
150
|
+
非源应用协作者 → EXPORT_PERMISSION_DENIED,权限问题,重试无效,需应用所有者加协作者。
|
|
151
|
+
应用 ID 不存在,或 token 未找到对应应用 → EXPORT_APP_NOT_FOUND,核对入参,重试无效。
|
|
147
152
|
|
|
148
153
|
示例
|
|
149
154
|
$ miaoda app export app_demo_source
|
|
150
|
-
$ miaoda app export
|
|
155
|
+
$ miaoda app export DemoPageTokenAbCdEf123456789
|
|
151
156
|
$ miaoda app export app_demo_source --checkpoint 3
|
|
152
157
|
`);
|
|
153
158
|
cmd.action((0, shared_1.withHelp)(cmd, async (appId, rawOpts) => {
|
|
@@ -21,15 +21,11 @@ function registerSkillsCommands(program) {
|
|
|
21
21
|
function registerSkillsSync(parent) {
|
|
22
22
|
const cmd = parent
|
|
23
23
|
.command('sync')
|
|
24
|
-
.description('同步
|
|
24
|
+
.description('同步 coding-steering(latest 或指定版本)到 user app')
|
|
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')
|
|
33
29
|
.addHelpText('after', `
|
|
34
30
|
前置要求
|
|
35
31
|
当前目录(或 --dir)已走过 'miaoda app init'(.spark/meta.json 含 stack)
|
|
@@ -60,8 +56,6 @@ JSON 输出
|
|
|
60
56
|
dir: rawOpts.dir,
|
|
61
57
|
version: rawOpts.version,
|
|
62
58
|
local: rawOpts.local,
|
|
63
|
-
type: rawOpts.type,
|
|
64
|
-
tgzKey: rawOpts.tgzKey,
|
|
65
59
|
});
|
|
66
60
|
}));
|
|
67
61
|
}
|
|
@@ -46,6 +46,29 @@ const api = __importStar(require("../../../api/index"));
|
|
|
46
46
|
const error_1 = require("../../../utils/error");
|
|
47
47
|
const output_1 = require("../../../utils/output");
|
|
48
48
|
const logger_1 = require("../../../utils/logger");
|
|
49
|
+
/** 妙搭应用 ID 形态:`app_` + 字母数字下划线。非此形态按创意应用分享 token 处理。 */
|
|
50
|
+
const MIAODA_APP_ID_PATTERN = /^app_\w{1,64}$/;
|
|
51
|
+
/** 分享 token 宽松形态:16-128 位字母数字(CCM token 实际 20+ 位)。只拦明显不是 token 的输入(误传 flag / 短串),不追平服务端精确口径。 */
|
|
52
|
+
const META_TOKEN_PATTERN = /^[A-Za-z0-9_-]{16,128}$/;
|
|
53
|
+
/**
|
|
54
|
+
* 解析位置参数为源应用定位:app_xxx → appId;满足 token 宽松形态的串 → metaToken 透传
|
|
55
|
+
* (精确校验交给服务端反查,避免和服务端口径漂移)。不支持直接传分享链接——调用方
|
|
56
|
+
* (上游 agent)自行从链接提取 /page/<token> 段后传 token。
|
|
57
|
+
*/
|
|
58
|
+
function parseSourceRef(raw) {
|
|
59
|
+
if (MIAODA_APP_ID_PATTERN.test(raw)) {
|
|
60
|
+
return { appId: raw };
|
|
61
|
+
}
|
|
62
|
+
if (!META_TOKEN_PATTERN.test(raw)) {
|
|
63
|
+
throw new error_1.AppError('ARGS_INVALID', `无法识别的源应用定位:${raw}`, {
|
|
64
|
+
next_actions: [
|
|
65
|
+
'接受两种形态:应用 ID(app_xxx)或创意应用分享 token(16 位以上字母数字)',
|
|
66
|
+
'拿到的是分享链接(https://<tenant>.feishu.cn/page/<token>)时,请提取其中 /page/ 后的 <token> 段传入',
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return { metaToken: raw };
|
|
71
|
+
}
|
|
49
72
|
/** 导出目录默认值:创意升级链路的参考物约定位置。 */
|
|
50
73
|
exports.DEFAULT_EXPORT_OUT = 'source_package/creative';
|
|
51
74
|
/** 升级 manifest 文件名:前置钩子幂等标记 / skill workspace-contains 锚点 / skill 第 0 步信息源。 */
|
|
@@ -97,7 +120,7 @@ function countFiles(dir) {
|
|
|
97
120
|
return count;
|
|
98
121
|
}
|
|
99
122
|
/**
|
|
100
|
-
* miaoda app export <app-id> [--out <dir>] [--checkpoint <n>]
|
|
123
|
+
* miaoda app export <app-id-or-token> [--out <dir>] [--checkpoint <n>]
|
|
101
124
|
*
|
|
102
125
|
* 创意应用升级链路:把源应用(创意稿)的源码从服务端导出到本工程,作为只读参考物。
|
|
103
126
|
* 链路:studio_server InnerGetCodeArchive(inner 通道,force 身份鉴权:调用者须为源应用
|
|
@@ -105,15 +128,18 @@ function countFiles(dir) {
|
|
|
105
128
|
* skill workspace-contains 锚点 + skill 第 0 步信息源)。
|
|
106
129
|
*
|
|
107
130
|
* URL 形状:path :appID 是当前沙箱应用(网关强校验其与沙箱 AK 一致),源应用走 query
|
|
108
|
-
* sourceAppID
|
|
131
|
+
* (sourceAppID 或 sourceMetaToken 二选一)—— 跨应用(升级常态:新应用沙箱里导出源
|
|
132
|
+
* 创意应用)必须如此。位置参数接受应用 ID / 分享 token 两种形态。
|
|
109
133
|
*
|
|
110
|
-
* 幂等:--out 已存在 manifest
|
|
134
|
+
* 幂等:--out 已存在 manifest 且源定位(sourceAppId / sourceMetaToken)一致时跳过导出
|
|
135
|
+
* 直接返回(重试/多轮不重复拉取)。
|
|
111
136
|
*/
|
|
112
137
|
async function handleAppExport(opts) {
|
|
113
|
-
const
|
|
114
|
-
if (!
|
|
115
|
-
throw new error_1.AppError('ARGS_INVALID', 'app-id 不能为空');
|
|
138
|
+
const rawSource = (opts.appId || '').trim();
|
|
139
|
+
if (!rawSource) {
|
|
140
|
+
throw new error_1.AppError('ARGS_INVALID', 'app-id-or-token 不能为空');
|
|
116
141
|
}
|
|
142
|
+
const source = parseSourceRef(rawSource);
|
|
117
143
|
// 当前沙箱应用:网关 AK 校验要求 path :appID 与沙箱绑定应用一致
|
|
118
144
|
const currentAppId = (opts.currentAppId || '').trim();
|
|
119
145
|
if (!currentAppId) {
|
|
@@ -124,13 +150,24 @@ async function handleAppExport(opts) {
|
|
|
124
150
|
const outRel = normalizeOutDir(opts.out ?? exports.DEFAULT_EXPORT_OUT);
|
|
125
151
|
const outDir = node_path_1.default.resolve(process.cwd(), outRel);
|
|
126
152
|
const manifestPath = node_path_1.default.join(outDir, exports.UPGRADE_MANIFEST_FILENAME);
|
|
127
|
-
// 幂等:同源应用已导出过则直接复用(前置钩子重试 /
|
|
153
|
+
// 幂等:同源应用已导出过则直接复用(前置钩子重试 / 多轮对话不重复拉取)。
|
|
154
|
+
// token 入参时按 manifest 记录的 sourceMetaToken 比对(导出前拿不到反查后的 appId)。
|
|
128
155
|
if (node_fs_1.default.existsSync(manifestPath)) {
|
|
129
156
|
try {
|
|
130
157
|
const prev = JSON.parse(node_fs_1.default.readFileSync(manifestPath, 'utf-8'));
|
|
131
|
-
|
|
158
|
+
const matched = source.appId
|
|
159
|
+
? prev.sourceAppId === source.appId
|
|
160
|
+
: prev.sourceMetaToken === source.metaToken;
|
|
161
|
+
if (matched) {
|
|
132
162
|
(0, logger_1.log)('export', `Already exported (manifest matched), skip: ${outRel}`);
|
|
133
|
-
(0, output_1.emit)({
|
|
163
|
+
(0, output_1.emit)({
|
|
164
|
+
data: {
|
|
165
|
+
appId: prev.sourceAppId ?? '',
|
|
166
|
+
out: outRel,
|
|
167
|
+
skipped: true,
|
|
168
|
+
reason: 'already_exported',
|
|
169
|
+
},
|
|
170
|
+
});
|
|
134
171
|
return;
|
|
135
172
|
}
|
|
136
173
|
}
|
|
@@ -138,10 +175,11 @@ async function handleAppExport(opts) {
|
|
|
138
175
|
// manifest 损坏视为未导出,走覆盖导出
|
|
139
176
|
}
|
|
140
177
|
}
|
|
141
|
-
(0, logger_1.log)('export', `Fetching code archive of ${appId}...`);
|
|
178
|
+
(0, logger_1.log)('export', `Fetching code archive of ${source.appId ?? 'meta token source'}...`);
|
|
142
179
|
const resp = await api.app.getCodeArchive({
|
|
143
180
|
appID: currentAppId,
|
|
144
|
-
sourceAppID: appId,
|
|
181
|
+
sourceAppID: source.appId,
|
|
182
|
+
sourceMetaToken: source.metaToken,
|
|
145
183
|
checkpointID: opts.checkpoint,
|
|
146
184
|
});
|
|
147
185
|
const fileBase64 = resp.file ?? '';
|
|
@@ -157,9 +195,11 @@ async function handleAppExport(opts) {
|
|
|
157
195
|
if (archive.length > MAX_ARCHIVE_BYTES) {
|
|
158
196
|
throw new error_1.AppError('EXPORT_ARCHIVE_TOO_LARGE', `归档超过大小上限(${String(archive.length)} > ${String(MAX_ARCHIVE_BYTES)} bytes)`);
|
|
159
197
|
}
|
|
198
|
+
// 实际导出的源应用 ID:服务端回传优先(token 入参时为反查结果),appId 入参时兜底自身
|
|
199
|
+
const resolvedSourceAppId = resp.sourceAppID ?? source.appId ?? '';
|
|
160
200
|
// 归档先落临时文件再解压;解压成功前不动已存在的 outDir 内容之外的文件
|
|
161
201
|
const tmpDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'miaoda-export-'));
|
|
162
|
-
const archivePath = node_path_1.default.join(tmpDir, resp.name ?? `${
|
|
202
|
+
const archivePath = node_path_1.default.join(tmpDir, resp.name ?? `${resolvedSourceAppId || 'source'}.zip`);
|
|
163
203
|
try {
|
|
164
204
|
node_fs_1.default.writeFileSync(archivePath, archive);
|
|
165
205
|
node_fs_1.default.mkdirSync(outDir, { recursive: true });
|
|
@@ -177,7 +217,9 @@ async function handleAppExport(opts) {
|
|
|
177
217
|
node_fs_1.default.rmSync(node_path_1.default.join(outDir, '.gitignore'), { force: true });
|
|
178
218
|
const fileCount = countFiles(outDir);
|
|
179
219
|
const manifest = {
|
|
180
|
-
sourceAppId:
|
|
220
|
+
sourceAppId: resolvedSourceAppId,
|
|
221
|
+
// token 入参时记录 token 供幂等比对;appId 入参时不写该字段
|
|
222
|
+
...(source.metaToken ? { sourceMetaToken: source.metaToken } : {}),
|
|
181
223
|
archiveName: resp.name ?? '',
|
|
182
224
|
checkpointId: opts.checkpoint ?? 0,
|
|
183
225
|
exportedAt: new Date().toISOString(),
|
|
@@ -186,6 +228,12 @@ async function handleAppExport(opts) {
|
|
|
186
228
|
node_fs_1.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n', 'utf-8');
|
|
187
229
|
(0, logger_1.log)('export', 'Exported successfully');
|
|
188
230
|
(0, output_1.emit)({
|
|
189
|
-
data: {
|
|
231
|
+
data: {
|
|
232
|
+
appId: resolvedSourceAppId,
|
|
233
|
+
out: outRel,
|
|
234
|
+
fileCount,
|
|
235
|
+
archiveName: manifest.archiveName,
|
|
236
|
+
skipped: false,
|
|
237
|
+
},
|
|
190
238
|
});
|
|
191
239
|
}
|
|
@@ -6,7 +6,6 @@ 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");
|
|
10
9
|
const spark_meta_1 = require("../../../utils/spark-meta");
|
|
11
10
|
const error_1 = require("../../../utils/error");
|
|
12
11
|
const output_1 = require("../../../utils/output");
|
|
@@ -27,25 +26,6 @@ const output_1 = require("../../../utils/output");
|
|
|
27
26
|
async function handleSkillsSync(opts) {
|
|
28
27
|
await Promise.resolve();
|
|
29
28
|
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 用)
|
|
49
29
|
const meta = (0, spark_meta_1.readSparkMeta)(targetDir);
|
|
50
30
|
if (meta.stack === undefined || meta.stack === '') {
|
|
51
31
|
throw new error_1.AppError('SKILLS_META_INCOMPLETE', '.spark/meta.json missing stack — run `miaoda app init` first');
|
|
@@ -1,24 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BizErrCode = void 0;
|
|
3
4
|
exports.mapDevopsError = mapDevopsError;
|
|
4
5
|
const error_1 = require("./error");
|
|
6
|
+
exports.BizErrCode = {
|
|
7
|
+
/** devops:应用不存在(含把非应用 ID 当 app-id 传入的情况) */
|
|
8
|
+
DEVOPS_APP_NOT_FOUND: '400002577',
|
|
9
|
+
/** devops:应用不存在(另一路径,与上同义) */
|
|
10
|
+
DEVOPS_APP_NOT_FOUND_ALT: '400002569',
|
|
11
|
+
/** devops:无应用权限 */
|
|
12
|
+
DEVOPS_APP_PERMISSION_DENIED: '400002579',
|
|
13
|
+
/** devops:参数非法(如 name / description 超长) */
|
|
14
|
+
DEVOPS_INVALID_ARG: '400002575',
|
|
15
|
+
/** studio_server:ErrUnauthenticated —— 身份换取失败或未通过资源鉴权 */
|
|
16
|
+
STUDIO_UNAUTHENTICATED: '400002671',
|
|
17
|
+
/** studio_server:ErrStudioAppNotFound —— meta_token 无效或未绑定妙搭应用 */
|
|
18
|
+
STUDIO_APP_NOT_FOUND: '400002667',
|
|
19
|
+
};
|
|
5
20
|
/**
|
|
6
21
|
* 把 BAM lark.apaas.devops 的业务码(数字字符串)映射成 CLI 错误码。
|
|
7
|
-
* 来源:服务端技术方案 wiki L7P8wlNQ5iyShLkxzlOcCo8LnTg「业务错误码映射表」。
|
|
8
22
|
*
|
|
9
23
|
* 放在 utils 下而不是某个具体 api 域里:app / deploy 都跑在 lark.apaas.devops
|
|
10
24
|
* 这同一 PSM,业务码命名空间也共享;boundaries 规则又禁止 api 域间互引。
|
|
11
25
|
*/
|
|
12
26
|
function mapDevopsError(bizCode, message) {
|
|
13
27
|
switch (bizCode) {
|
|
14
|
-
case
|
|
15
|
-
case
|
|
28
|
+
case exports.BizErrCode.DEVOPS_APP_NOT_FOUND:
|
|
29
|
+
case exports.BizErrCode.DEVOPS_APP_NOT_FOUND_ALT:
|
|
16
30
|
return new error_1.AppError('APP_NOT_FOUND', message, {
|
|
17
31
|
next_actions: ['Run `miaoda app list` to see available apps'],
|
|
18
32
|
});
|
|
19
|
-
case
|
|
33
|
+
case exports.BizErrCode.DEVOPS_APP_PERMISSION_DENIED:
|
|
20
34
|
return new error_1.AppError('APP_PERMISSION_DENIED', message);
|
|
21
|
-
case
|
|
35
|
+
case exports.BizErrCode.DEVOPS_INVALID_ARG:
|
|
22
36
|
return new error_1.AppError('INVALID_ARG_VALUE', message, {
|
|
23
37
|
next_actions: ['缩短 --name / --description 后重试(后端有长度限制)'],
|
|
24
38
|
});
|
package/package.json
CHANGED
|
@@ -1,202 +0,0 @@
|
|
|
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',
|
|
48
|
-
'miaoda-modern': '@lark-apaas/coding-miaoda-sandbox',
|
|
49
|
-
'miaoda-design': '@lark-apaas/coding-miaoda-sandbox',
|
|
50
|
-
openclaw: '@lark-apaas/coding-openclaw-sandbox',
|
|
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_latest.tgz → null(走 @latest)
|
|
63
|
-
* 任何 all_<X>.tgz → <X>
|
|
64
|
-
*
|
|
65
|
-
* 用 nullable 而不是空字符串 —— 让调用方能判断"没 lane 就走 latest"。
|
|
66
|
-
*/
|
|
67
|
-
function extractLaneFromTgzKey(tgzKey) {
|
|
68
|
-
if (tgzKey === undefined || tgzKey === '') {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
const match = /(?:^|\/)all_([A-Za-z0-9][A-Za-z0-9_-]*)\.tgz$/.exec(tgzKey);
|
|
72
|
-
if (match === null) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
const lane = match[1];
|
|
76
|
-
if (lane === 'latest') {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
return lane;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* 主流程:按 type 拉包 + sync 到目标目录。
|
|
83
|
-
*
|
|
84
|
-
* sync 策略:**覆盖式写入 + 老文件清理**,对齐老 cp-skills.sh 行为
|
|
85
|
-
* (`rm -rf $TARGET; mkdir -p $TARGET; cp -r ...`)。
|
|
86
|
-
*/
|
|
87
|
-
function syncSandboxSkills(opts) {
|
|
88
|
-
const targetDir = node_path_1.default.resolve(opts.targetDir ?? process.cwd());
|
|
89
|
-
const packageName = PACKAGE_BY_TYPE[opts.type];
|
|
90
|
-
const businessLine = BUSINESS_LINE_BY_TYPE[opts.type];
|
|
91
|
-
const lane = extractLaneFromTgzKey(opts.tgzKey);
|
|
92
|
-
// 优先拉 lane dist-tag;失败 fallback 到 latest(防灰度切换期间 dist-tag 缺失 404)
|
|
93
|
-
const primaryVersion = lane !== null ? `lane-${lane}` : 'latest';
|
|
94
|
-
let fetched;
|
|
95
|
-
try {
|
|
96
|
-
(0, logger_1.debug)(`sandbox-skills: fetching ${packageName}@${primaryVersion}`);
|
|
97
|
-
fetched = (0, npm_pack_1.fetchNpmPackage)({
|
|
98
|
-
packageName,
|
|
99
|
-
version: primaryVersion,
|
|
100
|
-
registry: opts.registry,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
catch (err) {
|
|
104
|
-
if (lane === null) {
|
|
105
|
-
throw err;
|
|
106
|
-
}
|
|
107
|
-
(0, logger_1.debug)(`sandbox-skills: lane ${primaryVersion} not available, fallback to @latest (err: ${err.message})`);
|
|
108
|
-
fetched = (0, npm_pack_1.fetchNpmPackage)({
|
|
109
|
-
packageName,
|
|
110
|
-
version: 'latest',
|
|
111
|
-
registry: opts.registry,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
try {
|
|
115
|
-
// 计算 skill 目标根目录:
|
|
116
|
-
// - openclaw → <targetDir>/skills/(跟老 cp-skills.sh 的 openclaw 分支对齐,落 $WORKSPACE_DIR/agent/skills)
|
|
117
|
-
// - 其它 → <targetDir>/.agent/skills/
|
|
118
|
-
const skillsRoot = opts.type === 'openclaw'
|
|
119
|
-
? node_path_1.default.join(targetDir, 'skills')
|
|
120
|
-
: node_path_1.default.join(targetDir, '.agent', 'skills');
|
|
121
|
-
// 覆盖式:清空目标 skill 根目录(对齐 cp-skills.sh 行为,避免遗留老 skill)
|
|
122
|
-
// 用 forceRemoveDir 兜底:老沙箱可能残留其他用户写的 stale 文件(例如老 update.sh
|
|
123
|
-
// 以 root 跑,写下 root owned 的 `.last-update`),fs.rmSync {force:true} 遇到 EACCES
|
|
124
|
-
// 会 throw。见 forceRemoveDir 注释。
|
|
125
|
-
forceRemoveDir(skillsRoot);
|
|
126
|
-
node_fs_1.default.mkdirSync(skillsRoot, { recursive: true });
|
|
127
|
-
const syncedTop = [];
|
|
128
|
-
if (businessLine !== null) {
|
|
129
|
-
// 合并包 miaoda/miaoda-modern/miaoda-design:cp <extractDir>/<business-line>/* 到 target
|
|
130
|
-
const sourceDir = node_path_1.default.join(fetched.extractDir, businessLine);
|
|
131
|
-
if (node_fs_1.default.existsSync(sourceDir)) {
|
|
132
|
-
for (const entry of node_fs_1.default.readdirSync(sourceDir)) {
|
|
133
|
-
const from = node_path_1.default.join(sourceDir, entry);
|
|
134
|
-
const to = node_path_1.default.join(skillsRoot, entry);
|
|
135
|
-
node_fs_1.default.cpSync(from, to, { recursive: true });
|
|
136
|
-
syncedTop.push(entry);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
(0, logger_1.debug)(`sandbox-skills: source dir ${sourceDir} not found in package (skipped)`);
|
|
141
|
-
}
|
|
142
|
-
// shared:sync 合并包内 shared/* 到 target(对齐老 build.sh 的 shared 分发行为)
|
|
143
|
-
const sharedDir = node_path_1.default.join(fetched.extractDir, 'shared');
|
|
144
|
-
if (node_fs_1.default.existsSync(sharedDir)) {
|
|
145
|
-
for (const entry of node_fs_1.default.readdirSync(sharedDir)) {
|
|
146
|
-
const from = node_path_1.default.join(sharedDir, entry);
|
|
147
|
-
const to = node_path_1.default.join(skillsRoot, entry);
|
|
148
|
-
if (node_fs_1.default.existsSync(to)) {
|
|
149
|
-
// shared 命中已存在的 skill(如同名)— 保留业务线版本,跳过 shared(对齐老 build.sh:shared 是补丁,同名不覆盖)
|
|
150
|
-
(0, logger_1.debug)(`sandbox-skills: shared/${entry} conflicts with business-line skill, skipped`);
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
node_fs_1.default.cpSync(from, to, { recursive: true });
|
|
154
|
-
syncedTop.push(entry);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
// openclaw 独立包:直接把包内所有 skill 目录(除 package.json 等元文件外)平铺到 skillsRoot
|
|
160
|
-
for (const entry of node_fs_1.default.readdirSync(fetched.extractDir)) {
|
|
161
|
-
if (entry === 'package.json' || entry === 'README.md' || entry === 'LICENSE')
|
|
162
|
-
continue;
|
|
163
|
-
const from = node_path_1.default.join(fetched.extractDir, entry);
|
|
164
|
-
const stat = node_fs_1.default.statSync(from);
|
|
165
|
-
if (!stat.isDirectory())
|
|
166
|
-
continue;
|
|
167
|
-
const to = node_path_1.default.join(skillsRoot, entry);
|
|
168
|
-
node_fs_1.default.cpSync(from, to, { recursive: true });
|
|
169
|
-
syncedTop.push(entry);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
// 写 .last-update 时间戳(对齐老 update-skills.sh;供 feida-ai freshness 检查用)
|
|
173
|
-
const lastUpdatePath = node_path_1.default.join(skillsRoot, '.last-update');
|
|
174
|
-
node_fs_1.default.writeFileSync(lastUpdatePath, String(Date.now()));
|
|
175
|
-
return {
|
|
176
|
-
packageName,
|
|
177
|
-
version: fetched.version,
|
|
178
|
-
lane,
|
|
179
|
-
syncedTop,
|
|
180
|
-
targetDir: skillsRoot,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
finally {
|
|
184
|
-
fetched.cleanup();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* 参数校验:type 白名单 + tgzKey 格式(避免非法值透传到 npm 包名)。
|
|
189
|
-
*/
|
|
190
|
-
function validateSandboxSyncOpts(opts) {
|
|
191
|
-
const validTypes = ['miaoda', 'miaoda-modern', 'miaoda-design', 'openclaw'];
|
|
192
|
-
if (opts.type === undefined || !validTypes.includes(opts.type)) {
|
|
193
|
-
throw new error_1.AppError('SKILLS_INVALID_TYPE', `--type must be one of: ${validTypes.join(', ')} (got: ${opts.type ?? 'undefined'})`);
|
|
194
|
-
}
|
|
195
|
-
if (opts.tgzKey !== undefined && opts.tgzKey !== '') {
|
|
196
|
-
// 校验 tgz key 大致格式(前缀 skills_versions/ + all_ + 允许字符 + .tgz);避免非法值影响 lane 反推
|
|
197
|
-
if (!/^[A-Za-z0-9/_\-.]+\.tgz$/.test(opts.tgzKey)) {
|
|
198
|
-
throw new error_1.AppError('SKILLS_INVALID_TGZ_KEY', `--tgz-key value looks invalid: ${opts.tgzKey}`);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return { type: opts.type, tgzKey: opts.tgzKey };
|
|
202
|
-
}
|