@lark-apaas/miaoda-cli 0.1.39-alpha.e972368 → 0.1.39-alpha.f2b5342

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/README.md CHANGED
@@ -49,6 +49,7 @@ miaoda file ls --output json
49
49
  | `miaoda comment ...` | 应用评论:查看评论列表、解决评论(仅 design-html 场景开放) |
50
50
  | `miaoda registry ...` | 组件 registry:列出 / copy-in SDK 文件(本地执行) |
51
51
  | `miaoda app ...` | 应用生命周期:元数据、初始化、外部项目导入、平台同步、源码导出、静态产物导出 |
52
+ | `miaoda skills ...` | 按项目技术栈同步 skill、查看同步状态 |
52
53
 
53
54
  完整命令通过 `miaoda --help` 或 `miaoda <domain> --help` 查看。
54
55
 
@@ -57,7 +58,7 @@ miaoda file ls --output json
57
58
  `miaoda app init / import / sync / migrate` 管理本地应用工程(平台调用方与本地开发共用):
58
59
 
59
60
  - `init`:按 `--template` 或 `--app-type` 渲染模板(`full_stack → nestjs-react-fullstack`,`frontend / jspage → vite-react`)。工程已存在时不重新渲染、不覆盖业务代码,只输出就绪核验结果 `ready / problems`;`--strict` 下未就绪(meta 损坏、stack 不符、必要文件缺失、依赖未安装、上次操作失败)退出码 1。同步安装失败输出 `status=failed`、`failedStage=install`;退出码只在 `--strict` 时为 1,不带 `--strict` 时为 0(依赖由后续 `sync` 补装)。
60
- - `import`:外部项目导入(平台在 `init` 渲染模板之后、首次 git 提交之前于工程根目录调用)。`--zip <path>` 或 `--zip-url <预签名 URL>` 二选一,`--platform lovable|replit|gemini|zip`(默认 `zip`)。按平台规则把用户代码叠加到 `client/src`、`client/public`、`shared`,其余原样落到 `source_package/`;从不新建 / 覆盖模板托管文件(根 `package.json`、`package-lock.json`、`.npmrc`、`tsconfig*.json`、`vite.config.*`、`eslint.config.*`、`AGENTS.md`、`.githooks/`、`scripts/`、`.spark/`、`node_modules/`、`server/main.ts`、`client/src/index.tsx`),命中时改放 `source_package/` 并记入 `protectedConflicts`。**不合并 package.json、不装依赖**:用户 `package.json` 保留为 `source_package/package.json`,依赖静态分类(`platform_managed` / `excluded` / `present` / `build_chain` / `missing`)写进 `.spark/import/manifest.json`,由 Coding Agent 后续按需安装。先算完整计划、整体暂存再移入,失败时工程原样(`WRITE_FAILED`);manifest 最后写,存在即视为已导入(`alreadyImported=true`,不再改动)。`--dry-run` 只输出计划;`--rules-json` 覆盖默认排除路径 / 排除依赖。错误码:`ARGS_INVALID`(退出码 2)、`NOT_INITIALIZED`、`DOWNLOAD_FAILED`、`INVALID_ZIP`(非 zip / 超 50MB / 解压失败)、`WRITE_FAILED`。
61
+ - `import`(不在 help 列表中展示,仅供平台调用):外部项目导入(平台在 `init` 渲染模板之后、首次 git 提交之前于工程根目录调用)。`--zip <path>` 或 `--zip-url <预签名 URL>` 二选一,`--platform lovable|replit|gemini|zip`(默认 `zip`)。按平台规则把用户代码叠加到 `client/src`、`client/public`、`shared`,其余原样落到 `source_package/`;从不新建 / 覆盖模板托管文件(根 `package.json`、`package-lock.json`、`.npmrc`、`tsconfig*.json`、`vite.config.*`、`eslint.config.*`、`AGENTS.md`、`.githooks/`、`scripts/`、`.spark/`、`node_modules/`、`server/main.ts`、`client/src/index.tsx`),命中时改放 `source_package/` 并记入 `protectedConflicts`。**不合并 package.json、不装依赖**:用户 `package.json` 保留为 `source_package/package.json`,依赖静态分类(`platform_managed` / `present` / `build_chain` / `missing`)写进 `.spark/import/manifest.json`,由 Coding Agent 后续按需安装。先算完整计划、整体暂存、预检移入目标再逐个移入,任一阶段失败都会回滚,工程恢复原样(`WRITE_FAILED`,只可能留下新建的空目录);同时写待迁移标记 `.spark/import/MIGRATION_PENDING`(沙箱 skill `import-migration` 以它为加载条件,Coding Agent 迁移完成后删除);manifest 最后写,存在即视为已导入(`alreadyImported=true`,不再改动)。`--dry-run` 只输出计划;`--rules-json` 覆盖默认排除路径。错误码:`ARGS_INVALID`(退出码 2)、`NOT_INITIALIZED`、`DOWNLOAD_FAILED`、`INVALID_ZIP`(非 zip / 超 50MB / 解压失败)、`WRITE_FAILED`。
61
62
  - `sync`:按 stack 的同步规则更新平台托管内容。全栈工程的托管文件是明确清单(`scripts/dev.sh`、`dev.js`、`dev-local.js`、`build.sh`、`run.sh`、`lint.js`、`prune-smart.js`、`hooks/run-precommit.js` 与 `.githooks/pre-commit`),`scripts/` 下其他用户文件保留;连续执行无漂移。依赖安装失败输出 `status=failed`、`failedStage=install`;退出码只在 `--strict`(平台严格调用)时为 1,不带 `--strict` 时为 0,`dev.sh` 与 lark-cli `+init` 不带它。
62
63
  - `migrate`(不在 help 列表中展示):工程转换原语,在原工程目录内执行。目标模板先渲染到临时模板目录(不复制用户工程),再只读预检冲突(同路径不同内容、重复插件 ID、自定义同名 script、无法确定的 package.json / tsconfig / vite.config / index.html 形态等),随后在原目录定向转换(`src/ public/ → client/`、插件迁 `server/capabilities`、配置定向适配)并安装依赖;迁移配置声明了验证步骤时再执行验证(vite-react → 全栈不做完整构建)。冲突按 `--purpose` 决定的策略处理,结果字段 `conflictPolicy` 给出本次策略:
63
64
  - `stop`(`--purpose upgrade` / `history_restore`,平台调用):预检发现冲突返回 `status=conflict` 与具体路径,工程不写入;执行中才出现的冲突即停、不覆盖用户不同内容。
@@ -72,6 +73,20 @@ miaoda file ls --output json
72
73
 
73
74
  全栈 / design-stack 的 `postinstall` 只升级完整历史平台值(`fullstack-cli action-plugin init` 或 `npx -y @lark-apaas/fullstack-cli action-plugin init`),目标为 `npx -y @lark-apaas/fullstack-cli@latest action-plugin init`;`latest` 是渠道,不是固定版本。带追加命令、参数或用户指定版本的值保留。`migrate` 在原目录执行正常 npm 安装生命周期,包括用户脚本及依赖补丁;生命周期失败即 `install` 阶段失败,保留现场。
74
75
 
76
+ ## 同步项目的技术栈 skill
77
+
78
+ `miaoda app init` 在初始化支持的技术栈时同步 steering。已有项目运行 `miaoda skills sync --local` 可更新项目内的 `.agents/skills/`。沙箱的 `miaoda skills sync --type <type>` 使用相同的 steering 来源规则。
79
+
80
+ 宿主设置 `MIAODA_SANDBOX_PROVIDER=tae` 时,CLI 在公共包上叠加 bnpm 扩展包 `@byted-miaoda/coding-steering-extension-internal`。扩展包在 `package.json.miaodaSkillsExtension` 声明 `add`、`remove` 动作,CLI 按当前栈和开发模式计算最终集合;没有协议的旧包沿用目录叠加。miaoda-coding 的内容校验和发布门禁禁止新增条目与公共 skill 重名,CLI 保留原有底层覆盖能力。内网包独立选版,BOE 使用 `dev`,其他环境使用 `latest`。命令的 `--version` 和沙箱 lane 只选择公共版本。同步结果中的 `internalVersion`(`app init` 为 `internalSteeringVersion`)给出实际取得的内网版本。
81
+
82
+ 协议版本为 `schemaVersion: 1`,目标为 `coding-steering`。动作包含 `op`、`stack`、`id`,`add` 另指定包内相对目录 `source`;可选 `modes` 为 `local`、`sandbox`,默认同时生效。只安装声明的新增目录,完整复制其引用文件。协议格式、版本、来源目录或动作冲突不合法时,拒绝本次 steering 同步,保留已有文件。
83
+
84
+ `remove` 只排除指定的基础 skill,目标不存在时为空操作。当前内网包移除 `anycross-forward`,公共包内容保持原样;`removedSkills` 返回本轮声明的排除 ID。沙箱按最终集合重建。本地只移除受管且未修改的条目,遇到同名自建或手改内容返回 `SKILLS_REMOVE_CONFLICT`,在写入其他条目前终止。
85
+
86
+ 本地切回公共版,或扩展撤销 `remove` 后,再执行 `miaoda skills sync --local` 会从当前公共包恢复对应 skill,并清理仅内网提供的受管条目。移除后新建的本地同名内容仍会保留,`preservedLocalSkills` 列出恢复或覆盖时的冲突。来源、摘要和移除记录写入 `.agents/.miaoda-internal-steering.json`。
87
+
88
+ 升级时先部署支持协议的 CLI,再发布协议扩展包;旧 CLI 无法执行 `remove`。协议定义与示例见 [skill 扩展协议](https://code.byted.org/apaas/miaoda-coding/blob/feat/internal-steering/docs/skills-extension-protocol.md)。
89
+
75
90
  ## 全栈应用的 MCP UI 检查
76
91
 
77
92
  创建 MCP UI 时,Agent 在 `server/mcp/ui` 中同时生成 `tsconfig.json` 和 `eslint.config.cjs`,修改 UI 或其 shared 依赖后主动运行独立检查。模板和 CLI 不生成 UI 配置,也不将 UI 检查接入主工程 lint/type:check。
@@ -142,6 +157,7 @@ miaoda registry add deck-slide --overwrite # 目标已存在时覆盖(
142
157
  ## 环境变量
143
158
 
144
159
  - `MIAODA_APP_ID`:默认应用 ID,等价于 `--app-id`。
160
+ - `MIAODA_SANDBOX_PROVIDER` 标识宿主的沙箱提供方。值为 `tae` 时追加内网 steering 包,其他值或未设置时仅同步公共包。
145
161
  - `MIAODA_MIGRATE_STEP_TIMEOUT_MS`:`app migrate` 单个依赖安装 / 构建步骤的超时(毫秒),默认 20 分钟。
146
162
  - `MIAODA_CANARY_HEADER`:HTTP 请求的 `x-tt-env` 小流量头取值。未设置时默认 `boe_miaoda_ccm`;设为空字符串则不带该头(例:`export MIAODA_CANARY_HEADER=boe_xxx`)。值形如 `ppe_xxx` 时额外带上 `x-use-ppe: 1`。
147
163
 
@@ -435,6 +435,7 @@ JSON 输出
435
435
  "appId": "...", "appType": "modern_html", "sourceImported": true, "importedFileCount": 7,
436
436
  "platformStackFound": true, "platformSyncedFiles": [...],
437
437
  "installed": true, "installSource": "cache|npm|skipped", "installHash": "...", ...}}
438
+ 宿主设置 MIAODA_SANDBOX_PROVIDER=tae 且内网包同步成功时,另返回 internalSteeringVersion。
438
439
  async 模式:{"data": {"initialized": true, "asyncInstall": true, "installed": false,
439
440
  "installSource": "async", "installPid": 123, "installLogPath": "...",
440
441
  "eventReadyPath": "...", "eventFailedPath": "..."}}
@@ -464,13 +465,15 @@ JSON 输出
464
465
  }));
465
466
  }
466
467
  function registerAppImport(parent) {
467
- const cmd = parent
468
- .command('import')
468
+ // 与 migrate 同理:import 只由平台(sandbox_console 建应用时)调用,**不暴露给 Agent**。
469
+ // hidden 后 `miaoda app -h` 不列出,避免 Agent 在已有应用里自行导入 zip 覆盖业务代码;
470
+ // 显式调用 `miaoda app import ...` 行为不变。
471
+ const cmd = new commander_1.Command('import')
469
472
  .description('外部项目导入:把 zip 包(lovable / replit / gemini / 普通 zip)按平台规则叠加进已初始化的工程;不碰模板托管文件、不合并 package.json、不装依赖')
470
473
  .option('--zip <path>', '本地 zip 路径(与 --zip-url 二选一)')
471
474
  .option('--zip-url <url>', 'zip 下载地址(预签名 GET URL,与 --zip 二选一)')
472
475
  .option('--platform <platform>', `来源平台(${index_1.IMPORT_PLATFORMS.join(' / ')})`, index_1.DEFAULT_IMPORT_PLATFORM)
473
- .option('--rules-json <json>', '覆盖默认规则:{"excludedPaths": [...], "excludedDependencies": [...]},提供的字段整体替换该平台默认值')
476
+ .option('--rules-json <json>', '覆盖默认排除路径:{"excludedPaths": [...]},提供后整体替换该平台默认值')
474
477
  .option('--dry-run', '只计算并输出放置计划,不写任何文件', false)
475
478
  .option('--dir <path>', '项目目录,默认 cwd(需含 .spark/meta.json)')
476
479
  .addHelpText('after', `
@@ -498,18 +501,22 @@ function registerAppImport(parent) {
498
501
  types.ts / constants.ts → client/src/
499
502
  zip src/** → client/src/**(命中排除路径 → source_package/src/**);public/** → client/public/**;
500
503
  src/components/ui/<name>.<ext> 与工程已有 client/src/components/ui/<name>.* 同名时,
501
- 删除模板文件、写入用户文件
504
+ 删除模板文件、写入用户文件(记入 replacedTemplateFiles);
505
+ 例外:用户文件是 .js / .jsx 而模板有 .ts / .tsx 时保留模板版本,
506
+ 用户文件改放 source_package/ 并记入 protectedConflicts
502
507
  受保护目标(根 package.json / package-lock.json / .npmrc / tsconfig*.json / vite.config.* /
503
508
  eslint.config.* / AGENTS.md / .githooks/ / scripts/ / .spark/ / node_modules/ / server/main.ts /
504
509
  client/src/index.tsx)从不新建或覆盖,命中时改放 source_package/ 并记入 protectedConflicts。
505
510
  用户的 package.json 保留在 source_package/package.json。
506
511
 
507
512
  原子性
508
- 先算完整计划、整体暂存,再移入工程;移入前任何失败工程保持原样(WRITE_FAILED)。
513
+ 先算完整计划、整体暂存,再预检移入目标(目标已是目录 / 父路径是文件),最后逐个移入工程。
514
+ 任一阶段失败都抛 WRITE_FAILED:移入中途失败会按逆序回滚已移入、已覆盖、已删除的文件,
515
+ 工程恢复原样(只可能留下新建的空目录)。
509
516
 
510
517
  依赖清单(.spark/import/manifest.json 的 dependencies,只做静态分析,不安装、不联网)
511
- status 优先级:platform_managed(@lark-apaas/*)> excluded(排除依赖)>
512
- present(工程已有,附 templateRange)> build_chain(构建链 / 工具链)> missing
518
+ status 优先级:platform_managed(@lark-apaas/*)> present(工程已有,附 templateRange)>
519
+ build_chain(构建链 / 工具链)> missing
513
520
 
514
521
  JSON 输出
515
522
  {"data": {"imported": true, "alreadyImported": false, "platform": "zip",
@@ -537,6 +544,7 @@ JSON 输出
537
544
  dir: rawOpts.dir,
538
545
  });
539
546
  }));
547
+ parent.addCommand(cmd, { hidden: true });
540
548
  }
541
549
  function parseInitConf(raw) {
542
550
  // --conf 为可选值:未传(undefined)、裸 --conf(Commander 给 true)、空/纯空白字符串
@@ -23,7 +23,7 @@ function registerSkillsSync(parent) {
23
23
  .command('sync')
24
24
  .description('同步 skills 到 user app(默认 coding-steering;带 --type 时走 sandbox-skills)')
25
25
  .option('--dir <path>', '项目目录,默认当前目录', '.')
26
- .option('--version <ver>', 'coding-steering 包版本或 dist-tag,缺省 latest')
26
+ .option('--version <ver>', '指定公共 coding-steering 包的版本或 dist-tag')
27
27
  .option('--local', '走本地 dev / agent 输出形态:拷到 .agents/skills 平铺 + 创建 .claude/skills 软链。' +
28
28
  '不传时退回老形态:拷到 .agent/skills/steering/<stack>/skills/(跟沙箱端 update-skills.sh 对齐)', false)
29
29
  .option('--type <type>', '走 sandbox 分支:miaoda | miaoda-modern | miaoda-design | openclaw。有值时忽略 --local,' +
@@ -35,6 +35,13 @@ function registerSkillsSync(parent) {
35
35
  前置要求
36
36
  当前目录(或 --dir)已走过 'miaoda app init'(.spark/meta.json 含 stack)
37
37
 
38
+ 技术栈 skill 来源
39
+ MIAODA_SANDBOX_PROVIDER=tae 时,从 bnpm 额外同步 @byted-miaoda/coding-steering-extension-internal。
40
+ 有 miaodaSkillsExtension 协议时按 add/remove 动作同步;旧包沿用目录叠加。
41
+ remove 排除基础 skill,撤销动作或切回公共版后恢复当前公共版本。
42
+ 内网包在 BOE 取 dev,其余环境取 latest。--version 和 --tgz-key 仅影响公共来源。
43
+ 未设置或其他 provider 值时仅同步公共包。
44
+
38
45
  输出形态(--local 切换)
39
46
  默认(不传 --local):
40
47
  .agent/skills/steering/<stack>/skills/<skill>/...
@@ -54,6 +61,8 @@ function registerSkillsSync(parent) {
54
61
  JSON 输出
55
62
  {"data": {"stack": "...", "version": "...", "syncedSkills": [...], "techSynced": true|false,
56
63
  "claudeSkillsLink": "created|updated|noop|conflict|unsupported" // 仅 --local 时}}
64
+ 内网包同步成功时包含 internalVersion;协议排除项列在 removedSkills。
65
+ 本地移除遇到自建或手改条目时返回 SKILLS_REMOVE_CONFLICT;恢复或覆盖冲突列在 preservedLocalSkills。
57
66
 
58
67
  传 --type 时:
59
68
  {"data": {"mode": "sandbox", "type": "...", "packageName": "...", "version": "...",
@@ -102,7 +102,6 @@ async function handleAppImport(opts) {
102
102
  entries,
103
103
  extractDir,
104
104
  projectDir,
105
- excludedDependencies: rules.excludedDependencies,
106
105
  warnings,
107
106
  });
108
107
  if (opts.dryRun) {
@@ -134,6 +133,7 @@ async function handleAppImport(opts) {
134
133
  applyWithStaging({ plan, extractDir, projectDir });
135
134
  const manifest = (0, index_1.buildImportManifest)({ platform, plan, dependencies });
136
135
  try {
136
+ (0, index_1.writeImportPendingMarker)(projectDir);
137
137
  (0, index_1.writeImportManifest)(projectDir, manifest);
138
138
  }
139
139
  catch (err) {
@@ -164,11 +164,7 @@ function analyzeDependencies(opts) {
164
164
  return [];
165
165
  const sourcePkg = readPackageJson(node_path_1.default.join(opts.extractDir, ...pkgEntry.raw.split('/')), '导入包 package.json', opts.warnings);
166
166
  const projectPkg = readPackageJson(node_path_1.default.join(opts.projectDir, 'package.json'), '工程 package.json', opts.warnings);
167
- return (0, index_1.classifyDependencies)({
168
- sourcePkg,
169
- projectPkg,
170
- excludedDependencies: opts.excludedDependencies,
171
- });
167
+ return (0, index_1.classifyDependencies)({ sourcePkg, projectPkg });
172
168
  }
173
169
  /**
174
170
  * 暂存目录放在工程 .spark/import/ 下:与工程同一文件系统,rename 不会 EXDEV。
@@ -190,6 +190,7 @@ async function handleAppInit(opts) {
190
190
  templatePackage: tplResult.packageName,
191
191
  templateVersion: tplResult.version,
192
192
  steeringVersion: steeringResult.version,
193
+ internalSteeringVersion: steeringResult.internalVersion,
193
194
  archType: tplResult.archType,
194
195
  appId: opts.appId,
195
196
  appType: opts.appType,
@@ -198,6 +199,7 @@ async function handleAppInit(opts) {
198
199
  importedFileCount: sourceImport.importedFileCount,
199
200
  sourceIgnoredReason: sourceImport.sourceIgnoredReason,
200
201
  syncedSkills: steeringResult.syncedSkills,
202
+ preservedLocalSkills: steeringResult.preservedLocalSkills,
201
203
  techSynced: steeringResult.techSynced,
202
204
  steeringError,
203
205
  gitHooks: hookActivation.action,
@@ -45,7 +45,7 @@ function syncSteeringForSandbox(params) {
45
45
  // 配了 tgzKey 也永远命中不了。把 version 原样透传(未指定就是 undefined),让
46
46
  // syncCodingSteering 一处算全链:version > lane > dev > latest。
47
47
  try {
48
- const r = (0, coding_steering_1.syncCodingSteering)({
48
+ const result = (0, coding_steering_1.syncCodingSteering)({
49
49
  stack,
50
50
  targetDir: params.targetDir,
51
51
  version: params.version,
@@ -62,14 +62,7 @@ function syncSteeringForSandbox(params) {
62
62
  // 同理固定 nested:落 .agent/skills/steering/<stack>/,与老链路一致
63
63
  outputLayout: 'nested',
64
64
  });
65
- return {
66
- status: 'synced',
67
- stack,
68
- version: r.version,
69
- syncedSkills: r.syncedSkills,
70
- techSynced: r.techSynced,
71
- prunedStacks: r.prunedStacks,
72
- };
65
+ return { status: 'synced', stack, ...result };
73
66
  }
74
67
  catch (err) {
75
68
  return { status: 'failed', reason: err.message };
@@ -183,14 +176,8 @@ function syncSteeringOnly(params) {
183
176
  (0, output_1.emit)({
184
177
  data: {
185
178
  stack: meta.stack,
186
- version: result.version,
187
179
  versionSource,
188
- syncedSkills: result.syncedSkills,
189
- techSynced: result.techSynced,
190
- prunedStacks: result.prunedStacks,
191
- ...(result.claudeSkillsLink !== undefined
192
- ? { claudeSkillsLink: result.claudeSkillsLink }
193
- : {}),
180
+ ...result,
194
181
  },
195
182
  });
196
183
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readJsonFile = exports.importManifestPath = exports.writeImportManifest = exports.buildImportManifest = exports.classifyDependencies = exports.IMPORT_MANIFEST_VERSION = exports.IMPORT_MANIFEST_REL = exports.FILE_COUNT_KEYS = exports.mapSourcePath = exports.applyImportPlan = exports.buildImportPlan = exports.normalizeEntries = exports.collectFiles = exports.MAX_IMPORT_ZIP_BYTES = exports.extractImportZip = exports.assertLocalZip = exports.downloadZip = exports.isGitRepoDir = exports.getImportedPrefix = exports.sanitizePathSegments = exports.isProtectedTarget = exports.isBuildChainDependency = exports.resolveImportRules = exports.parsePlatform = exports.BUILD_CHAIN_PATTERNS = exports.DEFAULT_IMPORT_RULES = exports.PLATFORM_IMPORT_RULES = exports.SOURCE_PACKAGE_DIR = exports.DEFAULT_IMPORT_PLATFORM = exports.IMPORT_PLATFORMS = void 0;
3
+ exports.readJsonFile = exports.importManifestPath = exports.writeImportManifest = exports.buildImportManifest = exports.classifyDependencies = exports.IMPORT_MANIFEST_VERSION = exports.writeImportPendingMarker = exports.IMPORT_PENDING_MARKER_REL = exports.IMPORT_MANIFEST_REL = exports.FILE_COUNT_KEYS = exports.mapSourcePath = exports.applyImportPlan = exports.buildImportPlan = exports.normalizeEntries = exports.collectFiles = exports.MAX_IMPORT_ZIP_BYTES = exports.extractImportZip = exports.assertLocalZip = exports.downloadZip = exports.isGitRepoDir = exports.getImportedPrefix = exports.sanitizePathSegments = exports.isProtectedTarget = exports.isBuildChainDependency = exports.resolveImportRules = exports.parsePlatform = exports.BUILD_CHAIN_PATTERNS = exports.DEFAULT_IMPORT_RULES = exports.PLATFORM_IMPORT_RULES = exports.SOURCE_PACKAGE_DIR = exports.DEFAULT_IMPORT_PLATFORM = exports.IMPORT_PLATFORMS = void 0;
4
4
  var rules_1 = require("./rules");
5
5
  Object.defineProperty(exports, "IMPORT_PLATFORMS", { enumerable: true, get: function () { return rules_1.IMPORT_PLATFORMS; } });
6
6
  Object.defineProperty(exports, "DEFAULT_IMPORT_PLATFORM", { enumerable: true, get: function () { return rules_1.DEFAULT_IMPORT_PLATFORM; } });
@@ -29,6 +29,8 @@ Object.defineProperty(exports, "mapSourcePath", { enumerable: true, get: functio
29
29
  Object.defineProperty(exports, "FILE_COUNT_KEYS", { enumerable: true, get: function () { return place_1.FILE_COUNT_KEYS; } });
30
30
  var manifest_1 = require("./manifest");
31
31
  Object.defineProperty(exports, "IMPORT_MANIFEST_REL", { enumerable: true, get: function () { return manifest_1.IMPORT_MANIFEST_REL; } });
32
+ Object.defineProperty(exports, "IMPORT_PENDING_MARKER_REL", { enumerable: true, get: function () { return manifest_1.IMPORT_PENDING_MARKER_REL; } });
33
+ Object.defineProperty(exports, "writeImportPendingMarker", { enumerable: true, get: function () { return manifest_1.writeImportPendingMarker; } });
32
34
  Object.defineProperty(exports, "IMPORT_MANIFEST_VERSION", { enumerable: true, get: function () { return manifest_1.IMPORT_MANIFEST_VERSION; } });
33
35
  Object.defineProperty(exports, "classifyDependencies", { enumerable: true, get: function () { return manifest_1.classifyDependencies; } });
34
36
  Object.defineProperty(exports, "buildImportManifest", { enumerable: true, get: function () { return manifest_1.buildImportManifest; } });
@@ -3,11 +3,12 @@ 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.IMPORT_MANIFEST_VERSION = exports.IMPORT_MANIFEST_REL = void 0;
6
+ exports.IMPORT_PENDING_MARKER_REL = exports.IMPORT_MANIFEST_VERSION = exports.IMPORT_MANIFEST_REL = void 0;
7
7
  exports.classifyDependencies = classifyDependencies;
8
8
  exports.readJsonFile = readJsonFile;
9
9
  exports.buildImportManifest = buildImportManifest;
10
10
  exports.importManifestPath = importManifestPath;
11
+ exports.writeImportPendingMarker = writeImportPendingMarker;
11
12
  exports.writeImportManifest = writeImportManifest;
12
13
  const node_fs_1 = __importDefault(require("node:fs"));
13
14
  const node_path_1 = __importDefault(require("node:path"));
@@ -15,6 +16,12 @@ const rules_1 = require("./rules");
15
16
  /** manifest 相对工程根的位置。它是导入的幂等标记,必须最后写。 */
16
17
  exports.IMPORT_MANIFEST_REL = '.spark/import/manifest.json';
17
18
  exports.IMPORT_MANIFEST_VERSION = 1;
19
+ /**
20
+ * 「待迁移」标记:导入时与 manifest 一起写入,Coding Agent 完成迁移后删除。
21
+ * 沙箱 skill `import-migration` 以它的存在为加载条件,删除后该 skill 不再注入。
22
+ * manifest 则长期保留(导入幂等标记 + 依赖分析记录),两者职责分开。
23
+ */
24
+ exports.IMPORT_PENDING_MARKER_REL = '.spark/import/MIGRATION_PENDING';
18
25
  function readDepField(pkg, field) {
19
26
  if (typeof pkg !== 'object' || pkg === null)
20
27
  return {};
@@ -29,22 +36,19 @@ function readDepField(pkg, field) {
29
36
  }
30
37
  /**
31
38
  * 依赖清单分类(只做静态分析,不装、不联网)。优先级:
32
- * platform_managed(@lark-apaas/*)> excluded > present(工程已有,带 templateRange)> build_chain > missing
39
+ * platform_managed(@lark-apaas/*)> present(工程已有,带 templateRange)> build_chain > missing
33
40
  */
34
41
  function classifyDependencies(opts) {
35
42
  const projectDeps = {
36
43
  ...readDepField(opts.projectPkg, 'devDependencies'),
37
44
  ...readDepField(opts.projectPkg, 'dependencies'),
38
45
  };
39
- const excluded = new Set(opts.excludedDependencies);
40
46
  const result = [];
41
47
  for (const field of ['dependencies', 'devDependencies']) {
42
48
  for (const [name, requested] of Object.entries(readDepField(opts.sourcePkg, field))) {
43
49
  const dep = { name, requested, field, status: 'missing' };
44
50
  if ((0, rules_1.isPlatformManagedDependency)(name))
45
51
  dep.status = 'platform_managed';
46
- else if (excluded.has(name))
47
- dep.status = 'excluded';
48
52
  else if (Object.prototype.hasOwnProperty.call(projectDeps, name)) {
49
53
  dep.status = 'present';
50
54
  dep.templateRange = projectDeps[name];
@@ -78,6 +82,12 @@ function buildImportManifest(opts) {
78
82
  function importManifestPath(projectDir) {
79
83
  return node_path_1.default.join(projectDir, ...exports.IMPORT_MANIFEST_REL.split('/'));
80
84
  }
85
+ /** 写「待迁移」标记。必须在 manifest 之前写:manifest 是幂等标记,先写标记再写 manifest,中途失败重跑仍会补齐两者。 */
86
+ function writeImportPendingMarker(projectDir) {
87
+ const file = node_path_1.default.join(projectDir, ...exports.IMPORT_PENDING_MARKER_REL.split('/'));
88
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(file), { recursive: true });
89
+ node_fs_1.default.writeFileSync(file, '本工程由外部项目导入,用户代码尚未迁移完成。迁移全部完成后删除本文件。\n', 'utf-8');
90
+ }
81
91
  function writeImportManifest(projectDir, manifest) {
82
92
  const file = importManifestPath(projectDir);
83
93
  node_fs_1.default.mkdirSync(node_path_1.default.dirname(file), { recursive: true });
@@ -64,6 +64,8 @@ function normalizeEntries(rawPaths, platform) {
64
64
  }
65
65
  const UI_PREFIX_SRC = 'src/components/ui/';
66
66
  const UI_PREFIX_PROJECT = 'client/src/components/ui/';
67
+ const JS_EXTS = new Set(['.js', '.jsx']);
68
+ const TS_EXTS = new Set(['.ts', '.tsx']);
67
69
  function stripExt(name) {
68
70
  const ext = node_path_1.default.posix.extname(name);
69
71
  return ext ? name.slice(0, -ext.length) : name;
@@ -130,6 +132,11 @@ function mapSourcePath(src, platform, rules, uiComponents) {
130
132
  if (!rest.includes('/')) {
131
133
  const existing = uiComponents.get(stripExt(rest));
132
134
  if (existing && existing.length > 0) {
135
+ // 模板业务组件依赖 TS 版 UI 组件的类型,JS 版替换后会类型报错,保留模板版本
136
+ const tsVersion = existing.find((p) => TS_EXTS.has(node_path_1.default.posix.extname(p)));
137
+ if (tsVersion && JS_EXTS.has(node_path_1.default.posix.extname(rest))) {
138
+ return { target: fallback, excluded: false, uiKept: tsVersion };
139
+ }
133
140
  return { target: `client/${src}`, excluded: false, uiReplaced: existing };
134
141
  }
135
142
  }
@@ -171,6 +178,9 @@ function buildImportPlan(opts) {
171
178
  protectedConflicts.push({ source: src, target, placedAt });
172
179
  target = placedAt;
173
180
  }
181
+ else if (mapped.uiKept) {
182
+ protectedConflicts.push({ source: src, target: mapped.uiKept, placedAt: target });
183
+ }
174
184
  else if (mapped.uiReplaced) {
175
185
  for (const p of mapped.uiReplaced)
176
186
  replaced.add(p);
@@ -215,13 +225,64 @@ function writeFailed(stage, err) {
215
225
  return new error_1.AppError('WRITE_FAILED', `导入写入失败(${stage}):${err instanceof Error ? err.message : String(err)}`, { next_actions: ['检查磁盘空间 / 目录权限后重试 miaoda app import'] });
216
226
  }
217
227
  /**
218
- * 两阶段落盘:
228
+ * 预检移入目标:rename 遇到「目标已是目录」或「父路径上有普通文件」必然失败,
229
+ * 在动工程之前拦下,避免移入到一半才报错。
230
+ */
231
+ function preflightTargets(plan, projectDir) {
232
+ for (const p of plan.placements) {
233
+ const segs = p.target.split('/');
234
+ for (let i = 1; i < segs.length; i += 1) {
235
+ const parent = node_path_1.default.join(projectDir, ...segs.slice(0, i));
236
+ if (node_fs_1.default.existsSync(parent) && !node_fs_1.default.statSync(parent).isDirectory()) {
237
+ throw writeFailed('preflight', new Error(`目标父路径是文件:${segs.slice(0, i).join('/')}(${p.target})`));
238
+ }
239
+ }
240
+ const dest = node_path_1.default.join(projectDir, ...segs);
241
+ if (node_fs_1.default.existsSync(dest) && node_fs_1.default.statSync(dest).isDirectory()) {
242
+ throw writeFailed('preflight', new Error(`目标路径已是目录:${p.target}`));
243
+ }
244
+ }
245
+ }
246
+ /** 把工程里已有的 rel 挪进 backupDir,返回暂存位置;不存在则返回 undefined。 */
247
+ function backupExisting(projectDir, backupDir, rel) {
248
+ const dest = node_path_1.default.join(projectDir, ...rel.split('/'));
249
+ if (!node_fs_1.default.existsSync(dest))
250
+ return undefined;
251
+ const backup = node_path_1.default.join(backupDir, ...rel.split('/'));
252
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(backup), { recursive: true });
253
+ node_fs_1.default.renameSync(dest, backup);
254
+ return backup;
255
+ }
256
+ /** 逆序撤回已执行的移入 / 删除;返回撤回失败的路径(尽力而为,不中断)。 */
257
+ function rollbackMoves(records) {
258
+ const failed = [];
259
+ for (const r of [...records].reverse()) {
260
+ try {
261
+ node_fs_1.default.rmSync(r.dest, { force: true });
262
+ if (r.backup) {
263
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(r.dest), { recursive: true });
264
+ node_fs_1.default.renameSync(r.backup, r.dest);
265
+ }
266
+ }
267
+ catch {
268
+ failed.push(r.dest);
269
+ }
270
+ }
271
+ return failed;
272
+ }
273
+ /**
274
+ * 三阶段落盘:
219
275
  * 1. 全部文件先拷进 stagingDir(工程不动);任一失败 → 清理暂存,工程保持原样
220
- * 2. 逐个 rename 进工程,再删被替换的模板 UI 组件
221
- * 第 2 步失败只能抛 WRITE_FAILED(不写 manifest,重跑会重新导入覆盖)。
276
+ * 2. 预检所有移入目标(目标已是目录 / 父路径是文件);不通过 → 工程保持原样
277
+ * 3. 逐个移入工程、删被替换的模板 UI 组件;被覆盖或删除的原文件先挪进暂存目录下的备份,
278
+ * 中途失败按逆序回滚,工程恢复原样(只可能留下新建的空目录)
279
+ * 失败一律抛 WRITE_FAILED,调用方不写 manifest,重跑会重新导入。
222
280
  */
223
281
  function applyImportPlan(opts) {
224
282
  const { plan, extractDir, projectDir, stagingDir } = opts;
283
+ // 备份放暂存目录下(同一文件系统,rename 不跨设备),finally 一并清理;
284
+ // 放置目标都以 client/ shared/ source_package/ 开头,不会与它重名。
285
+ const backupDir = node_path_1.default.join(stagingDir, '.backup');
225
286
  try {
226
287
  try {
227
288
  for (const p of plan.placements) {
@@ -233,18 +294,30 @@ function applyImportPlan(opts) {
233
294
  catch (err) {
234
295
  throw writeFailed('stage', err);
235
296
  }
297
+ preflightTargets(plan, projectDir);
298
+ const records = [];
236
299
  try {
237
300
  for (const p of plan.placements) {
238
301
  const staged = node_path_1.default.join(stagingDir, ...p.target.split('/'));
239
302
  const dest = node_path_1.default.join(projectDir, ...p.target.split('/'));
303
+ const backup = backupExisting(projectDir, backupDir, p.target);
304
+ records.push({ dest, backup });
240
305
  node_fs_1.default.mkdirSync(node_path_1.default.dirname(dest), { recursive: true });
241
306
  node_fs_1.default.renameSync(staged, dest);
242
307
  }
243
308
  for (const rel of plan.deletions) {
244
- node_fs_1.default.rmSync(node_path_1.default.join(projectDir, ...rel.split('/')), { force: true });
309
+ const backup = backupExisting(projectDir, backupDir, rel);
310
+ if (backup)
311
+ records.push({ dest: node_path_1.default.join(projectDir, ...rel.split('/')), backup });
245
312
  }
246
313
  }
247
314
  catch (err) {
315
+ const notRestored = rollbackMoves(records);
316
+ if (notRestored.length > 0) {
317
+ throw writeFailed('move', new Error(`${err instanceof Error ? err.message : String(err)};回滚未完成:${notRestored
318
+ .map((d) => node_path_1.default.relative(projectDir, d))
319
+ .join(', ')}`));
320
+ }
248
321
  throw writeFailed('move', err);
249
322
  }
250
323
  }
@@ -33,8 +33,11 @@ exports.SOURCE_PACKAGE_DIR = 'source_package';
33
33
  /** 单个路径段字节上限;超过则 hash 截断重命名,避免沙箱解压 ENAMETOOLONG(对齐 merger.go)。 */
34
34
  exports.MAX_PATH_SEGMENT_BYTES = 60;
35
35
  /**
36
- * 平台排除清单(取线上 TCC ImportMergerConfig 的值,而非代码兜底值)。
37
- * 实际生效 = 平台清单 + DEFAULT 清单(对齐 tcc.GetImportExcludedPaths / GetImportExcludedDependencies)。
36
+ * 平台排除路径(取线上 TCC ImportMergerConfig 的 excluded_paths,而非代码兜底值)。
37
+ * 实际生效 = 平台清单 + DEFAULT 清单(对齐 tcc.GetImportExcludedPaths)。
38
+ *
39
+ * 不再有排除依赖清单:导入不合并 package.json,依赖由 Coding Agent 参考 manifest 自行安装、
40
+ * 遇到冲突自行处理。
38
41
  */
39
42
  exports.PLATFORM_IMPORT_RULES = {
40
43
  lovable: {
@@ -46,7 +49,6 @@ exports.PLATFORM_IMPORT_RULES = {
46
49
  'src/integrations/supabase',
47
50
  'src/lib/supabase.ts',
48
51
  ],
49
- excludedDependencies: ['lovable-tagger'],
50
52
  },
51
53
  replit: {
52
54
  excludedPaths: [
@@ -55,11 +57,9 @@ exports.PLATFORM_IMPORT_RULES = {
55
57
  'client/src/index.css',
56
58
  'client/src/hooks/use-mobile.tsx',
57
59
  ],
58
- excludedDependencies: [],
59
60
  },
60
61
  gemini: {
61
62
  excludedPaths: [],
62
- excludedDependencies: [],
63
63
  },
64
64
  zip: {
65
65
  excludedPaths: [
@@ -73,21 +73,10 @@ exports.PLATFORM_IMPORT_RULES = {
73
73
  'src/App.jsx',
74
74
  'src/main.jsx',
75
75
  ],
76
- excludedDependencies: [
77
- '@supabase/supabase-js',
78
- 'video-react',
79
- '@builder.io/vite-plugin-jsx-loc',
80
- ],
81
76
  },
82
77
  };
83
78
  exports.DEFAULT_IMPORT_RULES = {
84
79
  excludedPaths: [],
85
- excludedDependencies: [
86
- 'react-helmet-async',
87
- 'eslint-plugin-react-hooks',
88
- 'vite-plugin-enter-dev',
89
- 'eslint-plugin-tailwindcss',
90
- ],
91
80
  };
92
81
  /**
93
82
  * 构建链 / 工具链依赖:模板已有自己的构建体系,用户包里的这类依赖通常不需要装。
@@ -162,10 +151,6 @@ function resolveImportRules(platform, rulesJson) {
162
151
  ...exports.PLATFORM_IMPORT_RULES[platform].excludedPaths,
163
152
  ...exports.DEFAULT_IMPORT_RULES.excludedPaths,
164
153
  ],
165
- excludedDependencies: [
166
- ...exports.PLATFORM_IMPORT_RULES[platform].excludedDependencies,
167
- ...exports.DEFAULT_IMPORT_RULES.excludedDependencies,
168
- ],
169
154
  };
170
155
  if (rulesJson === undefined || rulesJson.trim() === '')
171
156
  return rules;
@@ -181,7 +166,7 @@ function resolveImportRules(platform, rulesJson) {
181
166
  throw new error_1.AppError('ARGS_INVALID', '--rules-json 必须是 JSON 对象');
182
167
  }
183
168
  const obj = parsed;
184
- for (const key of ['excludedPaths', 'excludedDependencies']) {
169
+ for (const key of ['excludedPaths']) {
185
170
  const v = obj[key];
186
171
  if (v === undefined)
187
172
  continue;
@@ -0,0 +1,55 @@
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.isSafeSteeringId = isSafeSteeringId;
7
+ exports.copySkillTree = copySkillTree;
8
+ exports.treeDigest = treeDigest;
9
+ const node_crypto_1 = require("node:crypto");
10
+ const node_fs_1 = __importDefault(require("node:fs"));
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ const error_1 = require("../utils/error");
13
+ /** 包内与所有权记录里的 ID 只允许可移植的单个路径段。 */
14
+ function isSafeSteeringId(id) {
15
+ return (typeof id === 'string' &&
16
+ /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(id) &&
17
+ !id.endsWith('.') &&
18
+ !/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(id));
19
+ }
20
+ function copySkillTree(src, dest) {
21
+ node_fs_1.default.mkdirSync(dest);
22
+ for (const entry of node_fs_1.default.readdirSync(src, { withFileTypes: true })) {
23
+ const from = node_path_1.default.join(src, entry.name);
24
+ const to = node_path_1.default.join(dest, entry.name);
25
+ if (entry.isDirectory())
26
+ copySkillTree(from, to);
27
+ else if (entry.isFile())
28
+ node_fs_1.default.copyFileSync(from, to);
29
+ else
30
+ throw new error_1.AppError('SKILLS_INVALID_PACKAGE', `skill 含软链或特殊文件:${from}`);
31
+ }
32
+ }
33
+ /** 类型、文件名与内容都参与摘要,含新增空目录。用户改成软链/特殊文件时按修改处理。 */
34
+ function treeDigest(root) {
35
+ if (!node_fs_1.default.lstatSync(root).isDirectory())
36
+ return undefined;
37
+ const hash = (0, node_crypto_1.createHash)('sha256');
38
+ for (const name of node_fs_1.default.readdirSync(root).sort()) {
39
+ const child = node_path_1.default.join(root, name);
40
+ const stat = node_fs_1.default.lstatSync(child);
41
+ let digest;
42
+ if (stat.isDirectory())
43
+ digest = treeDigest(child);
44
+ else if (stat.isFile())
45
+ digest = (0, node_crypto_1.createHash)('sha256').update(node_fs_1.default.readFileSync(child)).digest('hex');
46
+ if (digest === undefined)
47
+ return undefined;
48
+ hash
49
+ .update(stat.isDirectory() ? 'd' : 'f')
50
+ .update(name)
51
+ .update('\0')
52
+ .update(digest);
53
+ }
54
+ return hash.digest('hex');
55
+ }