@lark-apaas/miaoda-cli 0.1.6 → 0.1.7-alpha.785a451

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/api/deploy/schemas.js +3 -0
  2. package/dist/cli/commands/app/index.js +67 -7
  3. package/dist/cli/commands/deploy/modern.js +9 -0
  4. package/dist/cli/commands/index.js +36 -1
  5. package/dist/cli/commands/skills/index.js +18 -2
  6. package/dist/cli/handlers/app/index.js +4 -1
  7. package/dist/cli/handlers/app/init.js +60 -9
  8. package/dist/cli/handlers/app/sync.js +266 -0
  9. package/dist/cli/handlers/deploy/modern.js +39 -0
  10. package/dist/cli/handlers/plugin/plugin-local.js +1 -1
  11. package/dist/cli/handlers/skills/sync.js +15 -4
  12. package/dist/config/fullstack-cli-pin.js +13 -0
  13. package/dist/config/sync-configs/design-stack.js +98 -0
  14. package/dist/config/sync-configs/index.js +62 -0
  15. package/dist/config/sync-configs/nestjs-react-fullstack.js +177 -0
  16. package/dist/config/sync.js +14 -0
  17. package/dist/services/app/init/install.js +44 -13
  18. package/dist/services/app/init/template.js +23 -6
  19. package/dist/services/deploy/modern/atoms/local-release.js +7 -2
  20. package/dist/services/deploy/modern/pipelines/local.js +4 -1
  21. package/dist/utils/coding-steering.js +107 -28
  22. package/dist/utils/file-ops.js +45 -0
  23. package/dist/utils/githooks.js +55 -0
  24. package/dist/utils/merge-json.js +63 -0
  25. package/dist/utils/platform-sync.js +160 -0
  26. package/dist/utils/sync-rule.js +295 -0
  27. package/package.json +7 -4
  28. package/upgrade/templates/README.md +34 -0
  29. package/upgrade/templates/design-stack/templates/.githooks/pre-commit +4 -0
  30. package/upgrade/templates/design-stack/templates/scripts/dev-local.js +84 -0
  31. package/upgrade/templates/design-stack/templates/scripts/dev.sh +26 -0
  32. package/upgrade/templates/design-stack/templates/scripts/hooks/run-precommit.js +37 -0
  33. package/upgrade/templates/nestjs-react-fullstack/templates/.githooks/pre-commit +4 -0
  34. package/upgrade/templates/nestjs-react-fullstack/templates/.gitignore.append +8 -0
  35. package/upgrade/templates/nestjs-react-fullstack/templates/.spark_project +16 -0
  36. package/upgrade/templates/nestjs-react-fullstack/templates/drizzle.config.ts +55 -0
  37. package/upgrade/templates/nestjs-react-fullstack/templates/helper/gen-openapi.ts +34 -0
  38. package/upgrade/templates/nestjs-react-fullstack/templates/nest-cli.json +25 -0
  39. package/upgrade/templates/nestjs-react-fullstack/templates/scripts/build.sh +207 -0
  40. package/upgrade/templates/nestjs-react-fullstack/templates/scripts/dev-local.js +113 -0
  41. package/upgrade/templates/nestjs-react-fullstack/templates/scripts/dev.js +295 -0
  42. package/upgrade/templates/nestjs-react-fullstack/templates/scripts/dev.sh +26 -0
  43. package/upgrade/templates/nestjs-react-fullstack/templates/scripts/hooks/run-precommit.js +37 -0
  44. package/upgrade/templates/nestjs-react-fullstack/templates/scripts/lint.js +150 -0
  45. package/upgrade/templates/nestjs-react-fullstack/templates/scripts/prune-smart.js +330 -0
  46. package/upgrade/templates/nestjs-react-fullstack/templates/scripts/run.sh +8 -0
  47. package/upgrade/templates/nestjs-react-fullstack/templates/server/global.d.ts +19 -0
  48. package/upgrade/templates/nestjs-react-fullstack/templates/tsconfig.node.json +5 -0
@@ -19,6 +19,9 @@ function nodeStatusText(v) {
19
19
  return v;
20
20
  if (typeof v !== 'number')
21
21
  return undefined;
22
+ // `number` 不在 `NodeStatus` 枚举键集时,TS Partial<Record<NodeStatus,_>> 推断
23
+ // 出来类型不友好(eslint 报 unsafe-return);cast 到 Record<number,string|undefined>
24
+ // 等价安全访问。
22
25
  return NODE_STATUS_TEXT[v];
23
26
  }
24
27
  /** NodeStatus 文本(CLI flag 字符串)→ 枚举数值 */
@@ -6,7 +6,7 @@ const index_1 = require("../../../cli/handlers/app/index");
6
6
  const error_1 = require("../../../utils/error");
7
7
  function registerAppCommands(program, opts = {}) {
8
8
  const description = opts.includeInit
9
- ? '应用元数据管理:查看 / 修改 / 初始化'
9
+ ? '应用元数据管理:查看 / 修改 / 初始化 / 升级平台资产'
10
10
  : '应用元数据管理:查看 / 修改';
11
11
  const appCmd = program.command('app').description(description);
12
12
  appCmd.action(() => {
@@ -21,8 +21,57 @@ function registerAppCommands(program, opts = {}) {
21
21
  registerAppUpdate(appCmd);
22
22
  if (opts.includeInit) {
23
23
  registerAppInit(appCmd);
24
+ registerAppSync(appCmd);
24
25
  }
25
26
  }
27
+ function registerAppSync(parent) {
28
+ const cmd = parent
29
+ .command('sync')
30
+ .alias('upgrade')
31
+ .description('一站式同步:按 stack 的 SyncRule 全套 apply + 按钉死版本表升 @lark-apaas/* deps + npm install')
32
+ .option('--dir <path>', '项目目录,默认 cwd(需含 .spark/meta.json)')
33
+ .addHelpText('after', `
34
+ 别名
35
+ miaoda app sync 与 miaoda app upgrade 等价(upgrade 是历史别名,新调用方请用 sync)。
36
+
37
+ 流程
38
+ 1. 按 stack 的 SyncRule[] 全套 apply(src/config/sync-configs/<stack>.ts 定义):
39
+ directory → 整个目录拷贝(.sh 自动 +x)
40
+ file → 单文件覆盖(可选 onlyIfExists / overwrite)
41
+ merge-json → JSON deep merge(可选 arrayMerge by key 去重)
42
+ add-script → npm script 不存在时添加(overwrite=false 默认不覆盖)
43
+ patch-script → npm script 以指定前缀开头时改写(守护用户自定义)
44
+ add-line → 行不存在时追加到文件
45
+ remove-line → 行存在时移除
46
+ delete-file/delete-directory → 删除
47
+ 沙箱里跑的 fullstack-cli sync 走同一套 rule 类型,行为对齐;miaoda app sync 在此之上
48
+ 补 dev:local 等本地开发独有规则。
49
+ 2. 平台 deps 指 latest:按 handlers/app/sync.ts 里 MANAGED_PLATFORM_PACKAGES 白名单把
50
+ user app 已装的 @lark-apaas/* 包改写为 "latest";表外 / 未装的不动。
51
+ 3. activateGitHooks:core.hooksPath 一次性指向 .githooks/。
52
+ 4. npm install --no-audit --no-fund --ignore-scripts。--ignore-scripts 是为绕开
53
+ action-plugin postinstall 在 npm install 时缺平台 env 的卡点(需要时再
54
+ FORCE_AUTHN_INNERAPI_DOMAIN=... npm install 手动跑一次)。
55
+
56
+ JSON 输出
57
+ {"data": {"stack": "...",
58
+ "appliedRules": [{"type": "...", "action": "...", "path": "...", "detail": "..."}],
59
+ "syncedFiles": [...],
60
+ "mergedJsonFiles": [{"path": "...", "keys": [...]}],
61
+ "patchedScripts": [...],
62
+ "upgradedPackages": [{"name": "...", "from": "...", "to": "...", "section": "..."}]}}
63
+
64
+ 示例
65
+ $ miaoda app sync
66
+ $ miaoda app sync --dir /path/to/app
67
+ $ miaoda app upgrade # 等价于 miaoda app sync
68
+ `);
69
+ cmd.action((0, shared_1.withHelp)(cmd, async (rawOpts) => {
70
+ await (0, index_1.handleAppSync)({
71
+ dir: rawOpts.dir,
72
+ });
73
+ }));
74
+ }
26
75
  function registerAppGet(parent) {
27
76
  const cmd = parent
28
77
  .command('get')
@@ -70,20 +119,28 @@ JSON 输出
70
119
  function registerAppInit(parent) {
71
120
  const cmd = parent
72
121
  .command('init')
73
- .description('初始化应用代码:抓 template 渲染、装 .agent/steering/ skills、写 .spark/meta.json。.spark/meta.json 已存在则直接退出')
122
+ .description('初始化应用代码:抓 template 渲染、同步 upgrade/templates、装 .agent/steering/ skills、写 .spark/meta.json。.spark/meta.json 已存在则直接退出')
74
123
  .option('--template <stack>', `技术栈短名(${index_1.SUPPORTED_STACKS.join(' / ')})`)
75
124
  .option('--conf <json>', 'init 配置 JSON。支持 {"version": "<template 版本>"} / {"steeringVersion": "<steering 版本>"},均默认 latest')
76
125
  .option('--skip-install', '跳过依赖安装', false)
126
+ .addOption((0, shared_1.appIdOption)())
77
127
  .addHelpText('after', `
78
128
  幂等
79
129
  .spark/meta.json 已存在时直接退出(initialized=false, reason=already_initialized),
80
- 不再触发 template 渲染、不重新拉 skills、不安装依赖。
130
+ 不再触发 template 渲染、不重新跑 upgrade/templates 同步、不重新拉 skills、不安装依赖。
81
131
  meta.json 在 init 流程最后才写,写了 = 已完整成功一次;
82
132
  上一次失败留下半渲染状态时(package.json 在但 meta.json 没在)允许重跑。
83
133
 
84
- 应用身份(appId
85
- init 不再持久化 appId。运行端命令(deploy / file / plugin 等)始终从 MIAODA_APP_ID env 读,
86
- init 阶段也无需感知 appId。
134
+ 应用身份(app_id
135
+ --app-id <id>(或 MIAODA_APP_ID env)提供时写入 .spark/meta.json app_id 字段;
136
+ 未提供则不写。运行端命令(deploy / file / plugin 等)仍优先读 MIAODA_APP_ID env,
137
+ env 未设置时回退到 meta.json.app_id。
138
+
139
+ 平台同步(upgrade/templates)
140
+ init 内嵌一次 upgrade/templates 同步(跟 app upgrade 共用同一份 util):
141
+ 从 miaoda-cli 自带的 upgrade/templates/<stack>/ 同步 files/(覆盖)+ patches/
142
+ (JSON deep merge,含 scripts.dev:local 等)。目标 stack 未纳入 upgrade/templates/
143
+ 时跳过(不报错)。后续要把 @lark-apaas/* 平台包统一指 latest,跑 'miaoda app upgrade'。
87
144
 
88
145
  依赖安装
89
146
  默认:npm install --no-audit --no-fund
@@ -97,11 +154,13 @@ function registerAppInit(parent) {
97
154
  JSON 输出
98
155
  已初始化:{"data": {"initialized": false, "reason": "already_initialized", "targetDir": "..."}}
99
156
  新初始化:{"data": {"initialized": true, "template": "...", "templateVersion": "...", "steeringVersion": "...",
157
+ "appId": "...", "platformStackFound": true, "platformSyncedFiles": [...],
100
158
  "installed": true, "installSource": "cache|npm|skipped", "installHash": "...", ...}}
101
159
 
102
160
  示例
103
161
  $ miaoda app init --template vite-react
104
- $ miaoda app init --template vite-react --conf '{"version": "0.1.0-alpha.1"}'
162
+ $ miaoda app init --template nestjs-react-fullstack --app-id app_xxx
163
+ $ miaoda app init --template vite-react --conf '{"version": "0.1.0"}'
105
164
  $ miaoda app init --template vite-react --conf '{"steeringVersion": "0.1.0"}'
106
165
  $ miaoda app init --template vite-react --skip-install
107
166
  $ MIAODA_DEP_CACHE_DIR=/tmp/dep-cache miaoda app init --template vite-react
@@ -112,6 +171,7 @@ JSON 输出
112
171
  template: rawOpts.template,
113
172
  conf,
114
173
  skipInstall: rawOpts.skipInstall,
174
+ appId: rawOpts.appId,
115
175
  });
116
176
  }));
117
177
  }
@@ -16,6 +16,7 @@ function registerDeployCommandsModern(program) {
16
16
  .description('触发 modern 应用发布:本地构建 + 本地部署(preRelease + localPublish)')
17
17
  .option('--dir <path>', '项目目录', '.')
18
18
  .option('--skip-build', '跳过 build 步骤(已构建好时使用)', false)
19
+ .option('--conf <json>', '关联元信息 JSON,仅识别 checkPointVersion / commitID 两字段')
19
20
  .addHelpText('after', `
20
21
  不要用异步模式或后台模式调用 deploy,否则调用可能提前结束,Agent 会误判发布已完成。
21
22
 
@@ -32,6 +33,12 @@ function registerDeployCommandsModern(program) {
32
33
  6. savePluginInstances(扫描 dist/output_capabilities/*.json 批量注册)
33
34
  7. finalizeLocalRelease(Finished|Failed)
34
35
 
36
+ --conf(关联元信息透传)
37
+ 值为 JSON string,只识别两个字段,其余 key 忽略:
38
+ checkPointVersion 关联的 checkpoint 版本
39
+ commitID 关联的代码 commit ID
40
+ 两字段均可选;非法 JSON / 非对象 / 字段值非字符串会报错。
41
+
35
42
  JSON 输出(stdout)
36
43
  {"data": {"appId": "...", "version": <n>, "url": "...", "releaseID": "...", "preReleaseID": "..."}}
37
44
 
@@ -39,12 +46,14 @@ JSON 输出(stdout)
39
46
  $ miaoda deploy
40
47
  $ miaoda deploy --dir ./my-app
41
48
  $ miaoda deploy --skip-build
49
+ $ miaoda deploy --conf '{"checkPointVersion":"v3","commitID":"a1b2c3d"}'
42
50
  `);
43
51
  deployCmd.action((0, shared_1.withHelp)(deployCmd, async (rawOpts) => {
44
52
  await (0, modern_1.handleDeployModern)({
45
53
  dir: rawOpts.dir ?? '.',
46
54
  appId: (0, shared_1.resolveAppId)({}),
47
55
  skipBuild: rawOpts.skipBuild,
56
+ conf: rawOpts.conf,
48
57
  });
49
58
  }));
50
59
  }
@@ -9,24 +9,59 @@ const index_4 = require("../../cli/commands/app/index");
9
9
  const index_5 = require("../../cli/commands/deploy/index");
10
10
  const modern_1 = require("../../cli/commands/deploy/modern");
11
11
  const index_6 = require("../../cli/commands/skills/index");
12
+ // scene 跟 dispatcher(MIAODA_APP_TYPE)同语义层级 —— app 业务类型维度,
13
+ // 对齐后端 devops app_common.AppType 枚举:
14
+ // 3 = AppType_APPLICATION(全栈应用,当前仅 nestjs-react-fullstack 一个 stack)
15
+ // 4 = AppType_DESIGN(design-stack,SSR 渲染、无业务逻辑、无数据库)
16
+ // 7 = miaoda-cli 自定义 modern 占位(后端枚举无 7,沙箱目前不传)
17
+ // 其它(0/1/2/5/6 / 未设)→ default(命令全开,本地 dev / CI / 兼容回退)
18
+ // stack 维度(nestjs-react-fullstack / vite-react / ...)是正交的,
19
+ // skills sync 内部按 .spark/meta.json.stack 拉对应 coding-steering/steering/<stack>/ 子目录。
12
20
  function resolveScene(appType, _archType) {
13
21
  if (appType === '7')
14
22
  return 'modern';
23
+ if (appType === '3')
24
+ return 'application';
25
+ if (appType === '4')
26
+ return 'design';
15
27
  return 'default';
16
28
  }
17
29
  const SCENE_REGISTRARS = {
18
30
  default: (p) => {
19
- (0, index_4.registerAppCommands)(p);
31
+ // init / upgrade / skills 都挂出来:本地用户不需要 export MIAODA_APP_TYPE=3
32
+ // 就能跑 `miaoda app init` / `miaoda app upgrade` / `miaoda skills sync`。
33
+ // 其它 scene 的差异(design 裁 db/file,modern 拆 deploy)仍按 MIAODA_APP_TYPE 路由
34
+ (0, index_4.registerAppCommands)(p, { includeInit: true });
20
35
  (0, index_5.registerDeployCommands)(p);
21
36
  (0, index_2.registerDbCommands)(p);
22
37
  (0, index_1.registerFileCommands)(p);
23
38
  (0, index_3.registerObservabilityCommands)(p);
39
+ (0, index_6.registerSkillsCommands)(p);
24
40
  },
25
41
  modern: (p) => {
26
42
  (0, index_4.registerAppCommands)(p, { includeInit: true });
27
43
  (0, modern_1.registerDeployCommandsModern)(p);
28
44
  (0, index_6.registerSkillsCommands)(p);
29
45
  },
46
+ // application scene(AppType_APPLICATION=3):
47
+ // 在 default 命令集基础上加 skills(按 meta.json.stack 拉对应 stack 技能)
48
+ // + app init(新一代应用走 init 写 .spark/meta.json)
49
+ application: (p) => {
50
+ (0, index_4.registerAppCommands)(p, { includeInit: true });
51
+ (0, index_5.registerDeployCommands)(p);
52
+ (0, index_2.registerDbCommands)(p);
53
+ (0, index_1.registerFileCommands)(p);
54
+ (0, index_3.registerObservabilityCommands)(p);
55
+ (0, index_6.registerSkillsCommands)(p);
56
+ },
57
+ // design scene(AppType_DESIGN=4):design-stack 仅 SSR 渲染、无后端业务逻辑、
58
+ // 无数据库、无 UGC 文件。命令集裁掉 db / file,保留 deploy / observability / app(init) / skills。
59
+ design: (p) => {
60
+ (0, index_4.registerAppCommands)(p, { includeInit: true });
61
+ (0, index_5.registerDeployCommands)(p);
62
+ (0, index_3.registerObservabilityCommands)(p);
63
+ (0, index_6.registerSkillsCommands)(p);
64
+ },
30
65
  };
31
66
  function readEnv(name) {
32
67
  const v = process.env[name]?.trim();
@@ -21,18 +21,33 @@ function registerSkillsCommands(program) {
21
21
  function registerSkillsSync(parent) {
22
22
  const cmd = parent
23
23
  .command('sync')
24
- .description('同步 coding-steering(latest 或指定版本)到 .agent/steering/')
24
+ .description('同步 coding-steering(latest 或指定版本)到 user app')
25
25
  .argument('[version]', 'coding-steering 包版本或 dist-tag,缺省 latest')
26
26
  .option('--dir <path>', '项目目录,默认当前目录', '.')
27
+ .option('--local', '走本地 dev / agent 输出形态:拷到 .agents/skills 平铺 + 创建 .claude/skills 软链。' +
28
+ '不传时退回老形态:拷到 .agent/skills/steering/<stack>/skills/(跟沙箱端 update-skills.sh 对齐)', false)
27
29
  .addHelpText('after', `
28
30
  前置要求
29
31
  当前目录(或 --dir)已走过 'miaoda app init'(.spark/meta.json 含 stack)
30
32
 
33
+ 输出形态(--local 切换)
34
+ 默认(不传 --local):
35
+ .agent/skills/steering/<stack>/skills/<skill>/...
36
+ .agent/skills/steering/<stack>/tech.md
37
+ (老链路,沙箱端 update-skills.sh 也输出这套结构)
38
+
39
+ 传 --local:
40
+ .agents/skills/<skill>/... ← 平铺,无 stack 命名空间
41
+ .agents/tech.md
42
+ .claude/skills → ../.agents/skills(软链,让 Claude Code 识别同一份)
43
+
31
44
  JSON 输出
32
- {"data": {"stack": "...", "version": "...", "syncedSkills": [...], "techSynced": true|false}}
45
+ {"data": {"stack": "...", "version": "...", "syncedSkills": [...], "techSynced": true|false,
46
+ "claudeSkillsLink": "created|updated|noop|conflict" // 仅 --local 时}}
33
47
 
34
48
  示例
35
49
  $ miaoda skills sync
50
+ $ miaoda skills sync --local # 本地 dev / agent 用
36
51
  $ miaoda skills sync 0.2.0
37
52
  $ miaoda skills sync --dir ./my-app
38
53
  `);
@@ -40,6 +55,7 @@ JSON 输出
40
55
  await (0, index_1.handleSkillsSync)({
41
56
  dir: rawOpts.dir,
42
57
  version,
58
+ local: rawOpts.local,
43
59
  });
44
60
  }));
45
61
  }
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SUPPORTED_STACKS = exports.handleAppInit = exports.handleAppUpdate = exports.handleAppGet = void 0;
3
+ exports.SUPPORTED_STACKS = exports.handleAppUpgrade = exports.handleAppSync = exports.handleAppInit = exports.handleAppUpdate = exports.handleAppGet = void 0;
4
4
  var get_1 = require("./get");
5
5
  Object.defineProperty(exports, "handleAppGet", { enumerable: true, get: function () { return get_1.handleAppGet; } });
6
6
  var update_1 = require("./update");
7
7
  Object.defineProperty(exports, "handleAppUpdate", { enumerable: true, get: function () { return update_1.handleAppUpdate; } });
8
8
  var init_1 = require("./init");
9
9
  Object.defineProperty(exports, "handleAppInit", { enumerable: true, get: function () { return init_1.handleAppInit; } });
10
+ var sync_1 = require("./sync");
11
+ Object.defineProperty(exports, "handleAppSync", { enumerable: true, get: function () { return sync_1.handleAppSync; } });
12
+ Object.defineProperty(exports, "handleAppUpgrade", { enumerable: true, get: function () { return sync_1.handleAppUpgrade; } });
10
13
  // commands 层渲染 help 时需要这份枚举;从 handler barrel 转发,避免 commands → services 越界
11
14
  var index_1 = require("../../../services/app/init/index");
12
15
  Object.defineProperty(exports, "SUPPORTED_STACKS", { enumerable: true, get: function () { return index_1.SUPPORTED_STACKS; } });
@@ -8,13 +8,17 @@ const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const index_1 = require("../../../services/app/init/index");
10
10
  const coding_steering_1 = require("../../../utils/coding-steering");
11
+ const logger_1 = require("../../../utils/logger");
12
+ const githooks_1 = require("../../../utils/githooks");
13
+ const sync_1 = require("../../../cli/handlers/app/sync");
11
14
  const error_1 = require("../../../utils/error");
12
15
  const output_1 = require("../../../utils/output");
13
16
  /**
14
17
  * miaoda app init
15
18
  *
16
- * 只负责本地脚手架:render templatesync skillsinstall deps,把 {stack, version, archType}
17
- * 写入 .spark/meta.json。appId 不在此处持久化——deploy 等运行端通过 MIAODA_APP_ID env 拿。
19
+ * 一站式本地脚手架:render template → upgrade/templates sync skills sync → install deps,把
20
+ * {stack, version, archType, app_id?} 写入 .spark/meta.json。--app-id(或 MIAODA_APP_ID)提供时
21
+ * 持久化 app_id;运行端命令仍优先读 env,未设置时回退到 meta.json。
18
22
  *
19
23
  * 幂等:.spark/meta.json 存在即表示已完整成功一次,直接退出,不重跑任何子步骤。
20
24
  * 半渲染状态(package.json 在但 meta.json 不在)会重新跑完整流程。
@@ -50,24 +54,59 @@ async function handleAppInit(opts) {
50
54
  const version = opts.conf?.version;
51
55
  const projectName = node_path_1.default.basename(targetDir);
52
56
  const tplResult = (0, index_1.renderTemplate)({ stack, version, targetDir, projectName });
53
- const steeringResult = (0, coding_steering_1.syncCodingSteering)({
54
- stack,
55
- targetDir,
56
- version: opts.conf?.steeringVersion,
57
- logPrefix: 'init',
58
- });
57
+ // sync 紧跟 template 渲染之后,赶在 install 之前:
58
+ // 这样 directory / merge-json / add-script 等 rule 都已落地,install 出来的 lockfile
59
+ // 与最终态对齐;patches 还能覆盖 template 提供的同名文件。
60
+ const syncRunResult = (0, sync_1.runStackSync)(stack, targetDir, 'init');
61
+ const syncSummary = (0, sync_1.summarizeSyncResults)(syncRunResult);
62
+ // template 渲染下来的 @lark-apaas/* 版本可能落后 MANAGED_PLATFORM_PACKAGES 白名单,赶在
63
+ // install 之前统一指 latest,这样一次 npm install 就直接装最新版本,不需要 install 完再补。
64
+ const upgradedPackages = (0, sync_1.upgradePlatformDeps)(targetDir, 'init');
65
+ // skills 同步软失败:拉不到 coding-steering 包不该阻断 writeSparkMeta /
66
+ // activateGitHooks(之前会让 .spark/meta.json 没写,下次 init 半渲染状态又得重跑全套)。
67
+ // 按 stack 分流 outputLayout:
68
+ // - nestjs-react-fullstack:本地主战场,用 flat 布局
69
+ // (.agents/skills + .claude/skills 软链),不再创建 .agent/ 老目录
70
+ // - 其他 stack:仍走默认 nested (.agent/skills/steering/<stack>/skills/),
71
+ // 跟沙箱端 update-skills.sh 老链路对齐,避免破坏
72
+ const outputLayout = stack === 'nestjs-react-fullstack' ? 'flat' : 'nested';
73
+ let steeringResult;
74
+ let steeringError;
75
+ try {
76
+ steeringResult = (0, coding_steering_1.syncCodingSteering)({
77
+ stack,
78
+ targetDir,
79
+ version: opts.conf?.steeringVersion,
80
+ logPrefix: 'init',
81
+ outputLayout,
82
+ });
83
+ }
84
+ catch (err) {
85
+ steeringError = err instanceof Error ? err.message : String(err);
86
+ (0, logger_1.log)('init', `⚠ skills sync failed (continuing init): ${steeringError}`);
87
+ steeringResult = { version: 'unknown', syncedSkills: [], techSynced: false };
88
+ }
59
89
  const installResult = (0, index_1.installDependencies)({
60
90
  targetDir,
61
91
  skip: opts.skipInstall,
62
92
  quietStdout: (0, output_1.isJsonMode)(),
63
93
  });
94
+ // template 自带 .githooks/pre-commit;如果用户项目已 git init,顺便设上 core.hooksPath。
95
+ const hookActivation = (0, githooks_1.activateGitHooks)(targetDir);
64
96
  (0, index_1.writeSparkMeta)(targetDir, {
65
97
  stack,
66
98
  version: tplResult.version,
67
99
  archType: tplResult.archType,
100
+ app_id: opts.appId,
101
+ steeringVersion: steeringResult.version,
68
102
  });
103
+ const syncedSummary = syncRunResult.stackFound
104
+ ? syncRunResult.rulesApplied.length > 0
105
+ ? `${syncRunResult.rulesApplied.length.toString()} rule(s)`
106
+ : 'legacy'
107
+ : 'skipped';
69
108
  if (!(0, output_1.isJsonMode)()) {
70
- process.stdout.write(`✓ Initialized ${stack} (template ${tplResult.version}, steering ${steeringResult.version}, install ${installResult.source}) in ${targetDir}\n`);
109
+ process.stdout.write(`✓ Initialized ${stack} (template ${tplResult.version}, steering ${steeringResult.version}, sync ${syncedSummary}, install ${installResult.source}) in ${targetDir}\n`);
71
110
  }
72
111
  (0, output_1.emit)({
73
112
  data: {
@@ -77,12 +116,24 @@ async function handleAppInit(opts) {
77
116
  templateVersion: tplResult.version,
78
117
  steeringVersion: steeringResult.version,
79
118
  archType: tplResult.archType,
119
+ appId: opts.appId,
80
120
  syncedSkills: steeringResult.syncedSkills,
81
121
  techSynced: steeringResult.techSynced,
122
+ steeringError,
123
+ // sync 流程的产出:rule-driven 时 appliedRules + 一系列汇总字段;fallback 到旧 platform-sync
124
+ // 时只填 platformSyncedFiles / platformMergedJsonFiles;stack 不识别时全空且 platformStackFound=false。
125
+ platformStackFound: syncRunResult.stackFound,
126
+ appliedRules: syncSummary.appliedRules,
127
+ platformSyncedFiles: syncSummary.syncedFiles,
128
+ platformMergedJsonFiles: syncSummary.mergedJsonFiles,
129
+ patchedScripts: syncSummary.patchedScripts,
130
+ upgradedPackages,
131
+ gitHooks: hookActivation.action,
82
132
  installed: installResult.installed,
83
133
  installSource: installResult.source,
84
134
  installHash: installResult.hash,
85
135
  cacheZip: installResult.cacheZip,
136
+ installError: installResult.error,
86
137
  },
87
138
  });
88
139
  }