@lark-apaas/miaoda-cli 0.1.4 → 0.1.5-beta.27ede41

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 (52) hide show
  1. package/README.md +6 -5
  2. package/dist/api/deploy/index.js +13 -1
  3. package/dist/api/deploy/modern-types.js +23 -0
  4. package/dist/api/deploy/modern.js +78 -0
  5. package/dist/api/deploy/plugin-instances-types.js +6 -0
  6. package/dist/api/deploy/plugin-instances.js +22 -0
  7. package/dist/api/observability/api.js +10 -0
  8. package/dist/api/observability/index.js +2 -1
  9. package/dist/cli/commands/app/index.js +84 -2
  10. package/dist/cli/commands/deploy/modern.js +50 -0
  11. package/dist/cli/commands/index.js +33 -5
  12. package/dist/cli/commands/observability/index.js +62 -6
  13. package/dist/cli/commands/shared.js +5 -0
  14. package/dist/cli/commands/skills/index.js +63 -0
  15. package/dist/cli/handlers/app/index.js +6 -1
  16. package/dist/cli/handlers/app/init.js +88 -0
  17. package/dist/cli/handlers/deploy/modern.js +33 -0
  18. package/dist/cli/handlers/observability/helpers.js +4 -0
  19. package/dist/cli/handlers/observability/index.js +3 -1
  20. package/dist/cli/handlers/observability/log.js +8 -2
  21. package/dist/cli/handlers/observability/source-stack.js +389 -0
  22. package/dist/cli/handlers/observability/trace.js +7 -1
  23. package/dist/cli/handlers/skills/index.js +7 -0
  24. package/dist/cli/handlers/skills/status.js +31 -0
  25. package/dist/cli/handlers/skills/sync.js +38 -0
  26. package/dist/services/app/init/index.js +12 -0
  27. package/dist/services/app/init/install.js +101 -0
  28. package/dist/services/app/init/template.js +87 -0
  29. package/dist/services/deploy/modern/atoms/build.js +59 -0
  30. package/dist/services/deploy/modern/atoms/context.js +27 -0
  31. package/dist/services/deploy/modern/atoms/index.js +17 -0
  32. package/dist/services/deploy/modern/atoms/local-release.js +27 -0
  33. package/dist/services/deploy/modern/atoms/pre-release.js +13 -0
  34. package/dist/services/deploy/modern/atoms/save-plugin-instances.js +72 -0
  35. package/dist/services/deploy/modern/atoms/upload.js +246 -0
  36. package/dist/services/deploy/modern/check.js +53 -0
  37. package/dist/services/deploy/modern/constants.js +13 -0
  38. package/dist/services/deploy/modern/index.js +16 -0
  39. package/dist/services/deploy/modern/pipelines/index.js +5 -0
  40. package/dist/services/deploy/modern/pipelines/local.js +75 -0
  41. package/dist/services/deploy/modern/protocol.js +122 -0
  42. package/dist/services/deploy/modern/run-types.js +4 -0
  43. package/dist/services/deploy/modern/run.js +13 -0
  44. package/dist/services/deploy/modern/template-key-map.js +22 -0
  45. package/dist/services/skills/index.js +5 -0
  46. package/dist/services/skills/status.js +37 -0
  47. package/dist/utils/coding-steering.js +85 -0
  48. package/dist/utils/git.js +22 -0
  49. package/dist/utils/http.js +21 -11
  50. package/dist/utils/npm-pack.js +55 -0
  51. package/dist/utils/spark-meta.js +42 -0
  52. package/package.json +1 -1
package/README.md CHANGED
@@ -36,10 +36,11 @@ miaoda file ls --output json
36
36
 
37
37
  命令以"域"作为第一级命名空间:
38
38
 
39
- | 域 | 用途 |
40
- |---|---|
41
- | `miaoda file ...` | 文件操作:上传、下载、元数据、签名下载、批量删除 |
42
- | `miaoda db ...` | 数据操作:SQL 执行、表结构查询、数据导入导出 |
39
+ | 域 | 用途 |
40
+ | -------------------------- | ---------------------------------------------------- |
41
+ | `miaoda file ...` | 文件操作:上传、下载、元数据、签名下载、批量删除 |
42
+ | `miaoda db ...` | 数据操作:SQL 执行、表结构查询、数据导入导出 |
43
+ | `miaoda observability ...` | 线上日志、链路、前端源码堆栈反查、监控指标、运营指标 |
43
44
 
44
45
  完整命令通过 `miaoda --help` 或 `miaoda <domain> --help` 查看。
45
46
 
@@ -54,7 +55,7 @@ miaoda file ls --output json
54
55
  ## 环境变量
55
56
 
56
57
  - `MIAODA_APP_ID`:默认应用 ID,等价于 `--app-id`。
57
- - `MIAODA_CANARY_HEADER`:设置后所有 HTTP 请求自动带上 `x-tt-env: <值>` 小流量头(例:`export MIAODA_CANARY_HEADER=boe_xxx`)。
58
+ - `MIAODA_CANARY_HEADER`:HTTP 请求的 `x-tt-env` 小流量头取值。未设置时默认 `boe_miaoda_doubao`;设为空字符串则不带该头(例:`export MIAODA_CANARY_HEADER=boe_xxx`)。值形如 `ppe_xxx` 时额外带上 `x-use-ppe: 1`。
58
59
 
59
60
  ## 输出契约
60
61
 
@@ -1,11 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NodeStatus = exports.nodeStatusFromText = exports.nodeStatusText = exports.errorJobSchema = exports.deployGetSchema = exports.deployHistorySchema = exports.queryPipelineInstance = exports.getErrorLog = exports.listPipelineInstances = exports.createRelease = void 0;
3
+ exports.NodeStatus = exports.nodeStatusFromText = exports.nodeStatusText = exports.errorJobSchema = exports.deployGetSchema = exports.deployHistorySchema = exports.batchSavePluginInstances = exports.LocalReleaseStatus = exports.getModernLastPublishedVersion = exports.getModernReleaseStatus = exports.createModernRelease = exports.callbackStatic = exports.updateLocalRelease = exports.createLocalRelease = exports.preRelease = exports.queryPipelineInstance = exports.getErrorLog = exports.listPipelineInstances = exports.createRelease = void 0;
4
4
  var api_1 = require("./api");
5
5
  Object.defineProperty(exports, "createRelease", { enumerable: true, get: function () { return api_1.createRelease; } });
6
6
  Object.defineProperty(exports, "listPipelineInstances", { enumerable: true, get: function () { return api_1.listPipelineInstances; } });
7
7
  Object.defineProperty(exports, "getErrorLog", { enumerable: true, get: function () { return api_1.getErrorLog; } });
8
8
  Object.defineProperty(exports, "queryPipelineInstance", { enumerable: true, get: function () { return api_1.queryPipelineInstance; } });
9
+ var modern_1 = require("./modern");
10
+ Object.defineProperty(exports, "preRelease", { enumerable: true, get: function () { return modern_1.preRelease; } });
11
+ Object.defineProperty(exports, "createLocalRelease", { enumerable: true, get: function () { return modern_1.createLocalRelease; } });
12
+ Object.defineProperty(exports, "updateLocalRelease", { enumerable: true, get: function () { return modern_1.updateLocalRelease; } });
13
+ Object.defineProperty(exports, "callbackStatic", { enumerable: true, get: function () { return modern_1.callbackStatic; } });
14
+ Object.defineProperty(exports, "createModernRelease", { enumerable: true, get: function () { return modern_1.createRelease; } });
15
+ Object.defineProperty(exports, "getModernReleaseStatus", { enumerable: true, get: function () { return modern_1.getReleaseStatus; } });
16
+ Object.defineProperty(exports, "getModernLastPublishedVersion", { enumerable: true, get: function () { return modern_1.getLastPublishedVersion; } });
17
+ var modern_types_1 = require("./modern-types");
18
+ Object.defineProperty(exports, "LocalReleaseStatus", { enumerable: true, get: function () { return modern_types_1.LocalReleaseStatus; } });
19
+ var plugin_instances_1 = require("./plugin-instances");
20
+ Object.defineProperty(exports, "batchSavePluginInstances", { enumerable: true, get: function () { return plugin_instances_1.batchSavePluginInstances; } });
9
21
  var schemas_1 = require("./schemas");
10
22
  Object.defineProperty(exports, "deployHistorySchema", { enumerable: true, get: function () { return schemas_1.deployHistorySchema; } });
11
23
  Object.defineProperty(exports, "deployGetSchema", { enumerable: true, get: function () { return schemas_1.deployGetSchema; } });
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ // modern deploy 接口的请求 / 响应类型(与服务端发布编排接口对齐)。
3
+ // 第一期落地的链路:本地构建 + 本地部署。
4
+ //
5
+ // 接口分两类:
6
+ // - preRelease:所有"本地构建"链路共用,签发动态配置(含 pre-signed TOS upload URL)
7
+ // - localPublish:本地构建 + 本地部署专用(createReleaseLocalPublish + updateReleaseLocalPublish)
8
+ //
9
+ // 远端部署链路(B/C)所需的 release 接口先预留类型骨架,待 B/C 落地时启用。
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.LocalReleaseStatus = void 0;
12
+ /**
13
+ * localPublish 状态枚举(数值,与服务端 IDL 对齐)。
14
+ * CLI updateLocalRelease 只翻 Finished / Failed 两个终态;其它由后端流转。
15
+ */
16
+ exports.LocalReleaseStatus = {
17
+ Unspecified: 0,
18
+ Publishing: 1,
19
+ Finished: 2,
20
+ Failed: 3,
21
+ Canceled: 4,
22
+ Rollback: 5,
23
+ };
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ // modern deploy 接口客户端。统一走管理端 innerapi(postInnerApi 信封解析)。
3
+ //
4
+ // 第一期落地(本地构建 + 本地部署):
5
+ // - preRelease:拿 pre_release_id + version + 动态配置 data
6
+ // - createLocalRelease / updateLocalRelease:完整本地部署生命周期
7
+ //
8
+ // 远端部署(本地构建+远端部署、远端构建+远端部署)需要 createRelease + getReleaseStatus,
9
+ // 后续 commit 接入;本文件已预留 endpoint 骨架但暂不导出。
10
+ //
11
+ // 约定:所有接口的 appID 走 URL :appID 路径参数,body 不再冗余携带 appID。
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.preRelease = preRelease;
14
+ exports.createLocalRelease = createLocalRelease;
15
+ exports.updateLocalRelease = updateLocalRelease;
16
+ exports.callbackStatic = callbackStatic;
17
+ exports.createRelease = createRelease;
18
+ exports.getReleaseStatus = getReleaseStatus;
19
+ exports.getLastPublishedVersion = getLastPublishedVersion;
20
+ const http_1 = require("../../utils/http");
21
+ const devops_error_1 = require("../../utils/devops-error");
22
+ const DEFAULT_ERR_CODE = 'INTERNAL_DEVOPS_ERROR';
23
+ function envelopeOpts(errPrefix) {
24
+ // modern deploy 接口与 default deploy / app 走同一个 lark.apaas.devops PSM,
25
+ // 业务错误码命名空间共享,直接复用 mapDevopsError 把 BAM 码翻为 AppError。
26
+ return {
27
+ errPrefix,
28
+ defaultErrCode: DEFAULT_ERR_CODE,
29
+ mapErr: devops_error_1.mapDevopsError,
30
+ };
31
+ }
32
+ // ── preRelease ──
33
+ /** POST /v1/devops/app/:appID/pre_release */
34
+ async function preRelease(req) {
35
+ const { appID, ...body } = req;
36
+ const url = `/v1/devops/app/${encodeURIComponent(appID)}/pre_release`;
37
+ return (0, http_1.postInnerApi)(url, body, envelopeOpts('Failed to pre-release'));
38
+ }
39
+ // ── localPublish ──
40
+ /** POST /v1/devops/app/:appID/local_publish/release */
41
+ async function createLocalRelease(req) {
42
+ const { appID, ...body } = req;
43
+ const url = `/v1/devops/app/${encodeURIComponent(appID)}/local_publish/release`;
44
+ return (0, http_1.postInnerApi)(url, body, envelopeOpts('Failed to create local release'));
45
+ }
46
+ /** POST /v1/devops/app/:appID/local_publish/update_release */
47
+ async function updateLocalRelease(req) {
48
+ const { appID, ...body } = req;
49
+ const url = `/v1/devops/app/${encodeURIComponent(appID)}/local_publish/update_release`;
50
+ await (0, http_1.postInnerApi)(url, body, envelopeOpts('Failed to update local release'));
51
+ }
52
+ // ── callbackStatic(PaaS Storage 静态资源上传完成回调) ──
53
+ /** POST /v1/storage/app/:appID/bucket/:bucketID/object/callbackStatic */
54
+ async function callbackStatic(req) {
55
+ const { appID, bucketID, uploadID } = req;
56
+ const url = `/v1/storage/app/${encodeURIComponent(appID)}/bucket/${encodeURIComponent(bucketID)}/object/callbackStatic`;
57
+ return (0, http_1.postInnerApi)(url, { uploadID }, envelopeOpts('Failed to callback static upload'));
58
+ }
59
+ // ── release(远端部署,B / C 链路;本期不导出,类型骨架已就绪) ──
60
+ /** POST /v1/devops/app/:appID/remote_publish/release */
61
+ async function createRelease(req) {
62
+ const { appID, ...body } = req;
63
+ const url = `/v1/devops/app/${encodeURIComponent(appID)}/remote_publish/release`;
64
+ return (0, http_1.postInnerApi)(url, body, envelopeOpts('Failed to create release'));
65
+ }
66
+ /** POST /v1/devops/app/:appID/release/status */
67
+ async function getReleaseStatus(req) {
68
+ const { appID, ...body } = req;
69
+ const url = `/v1/devops/app/${encodeURIComponent(appID)}/release/status`;
70
+ return (0, http_1.postInnerApi)(url, body, envelopeOpts('Failed to query release status'));
71
+ }
72
+ // ── getLastPublishedVersion(URL path 待文档补充) ──
73
+ /** POST /v1/devops/app/:appID/last_published_version(path 待后端确认) */
74
+ async function getLastPublishedVersion(req) {
75
+ const { appID } = req;
76
+ const url = `/v1/devops/app/${encodeURIComponent(appID)}/last_published_version`;
77
+ return (0, http_1.postInnerApi)(url, {}, envelopeOpts('Failed to get last published version'));
78
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ // plugin_instances batch_save 接口的请求 / 响应类型。
3
+ //
4
+ // 后端已统一到 InnerEnvelope(`{data, status_code, message}`),与 modern deploy
5
+ // 其它接口一致;旧的 BaseResp 形态已下线,类型也不再保留。
6
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ // studio_server 的 plugin_instances 批量保存接口。
3
+ //
4
+ // 后端已统一到 InnerEnvelope(`{data, status_code, message}`)信封;不再手撸
5
+ // 旧 BaseResp 解析,直接复用 utils/http.ts 的 postInnerApi,verbose 下也能拿到
6
+ // `→ POST` / `body:` / `resp:` 的完整日志。
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.batchSavePluginInstances = batchSavePluginInstances;
9
+ const http_1 = require("../../utils/http");
10
+ const URL_PATH = '/api/v1/studio/innerapi/plugin_instances/batch_save';
11
+ /**
12
+ * POST /api/v1/studio/innerapi/plugin_instances/batch_save
13
+ *
14
+ * 把发布版本的 capability 集合注册到 studio_server。
15
+ * 失败时抛 AppError("DEPLOY_PLUGIN_BATCH_SAVE_FAILED"),错误信息来自 envelope.message。
16
+ */
17
+ async function batchSavePluginInstances(req) {
18
+ await (0, http_1.postInnerApi)(URL_PATH, req, {
19
+ errPrefix: 'Failed to save plugin instances',
20
+ defaultErrCode: 'DEPLOY_PLUGIN_BATCH_SAVE_FAILED',
21
+ });
22
+ }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.searchLogs = searchLogs;
4
4
  exports.searchTraces = searchTraces;
5
5
  exports.getTraces = getTraces;
6
+ exports.resolveStackTrace = resolveStackTrace;
6
7
  exports.queryMetricsData = queryMetricsData;
7
8
  exports.queryAnalyticsData = queryAnalyticsData;
8
9
  const http_1 = require("../../utils/http");
@@ -30,6 +31,15 @@ async function getTraces(req) {
30
31
  defaultErrCode: DEFAULT_ERR_CODE,
31
32
  });
32
33
  }
34
+ // ── 前端源码堆栈反解 ──
35
+ async function resolveStackTrace(req) {
36
+ const url = `/v1/observability/app/${encodeURIComponent(req.appID)}/resolve_stack_trace`;
37
+ const { appID: _appID, ...body } = req;
38
+ return (0, http_1.postInnerApi)(url, body, {
39
+ errPrefix: 'Failed to resolve frontend source stack',
40
+ defaultErrCode: DEFAULT_ERR_CODE,
41
+ });
42
+ }
33
43
  // ── 监控指标 ──
34
44
  async function queryMetricsData(req) {
35
45
  const url = `/v1/observability/app/${encodeURIComponent(req.appID)}/metrics/data/query`;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StatusCode = exports.SpanKind = exports.WordOperator = exports.spanSchema = exports.logItemSchema = exports.queryAnalyticsData = exports.queryMetricsData = exports.getTraces = exports.searchTraces = exports.searchLogs = void 0;
3
+ exports.StatusCode = exports.SpanKind = exports.WordOperator = exports.spanSchema = exports.logItemSchema = exports.queryAnalyticsData = exports.queryMetricsData = exports.resolveStackTrace = exports.getTraces = exports.searchTraces = exports.searchLogs = void 0;
4
4
  var api_1 = require("./api");
5
5
  Object.defineProperty(exports, "searchLogs", { enumerable: true, get: function () { return api_1.searchLogs; } });
6
6
  Object.defineProperty(exports, "searchTraces", { enumerable: true, get: function () { return api_1.searchTraces; } });
7
7
  Object.defineProperty(exports, "getTraces", { enumerable: true, get: function () { return api_1.getTraces; } });
8
+ Object.defineProperty(exports, "resolveStackTrace", { enumerable: true, get: function () { return api_1.resolveStackTrace; } });
8
9
  Object.defineProperty(exports, "queryMetricsData", { enumerable: true, get: function () { return api_1.queryMetricsData; } });
9
10
  Object.defineProperty(exports, "queryAnalyticsData", { enumerable: true, get: function () { return api_1.queryAnalyticsData; } });
10
11
  var schemas_1 = require("./schemas");
@@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.registerAppCommands = registerAppCommands;
4
4
  const shared_1 = require("../../../cli/commands/shared");
5
5
  const index_1 = require("../../../cli/handlers/app/index");
6
- function registerAppCommands(program) {
7
- const appCmd = program.command('app').description('应用元数据管理:查看 / 修改');
6
+ const error_1 = require("../../../utils/error");
7
+ function registerAppCommands(program, opts = {}) {
8
+ const description = opts.includeInit
9
+ ? '应用元数据管理:查看 / 修改 / 初始化'
10
+ : '应用元数据管理:查看 / 修改';
11
+ const appCmd = program.command('app').description(description);
8
12
  appCmd.action(() => {
9
13
  appCmd.outputHelp();
10
14
  });
@@ -15,6 +19,9 @@ function registerAppCommands(program) {
15
19
  `);
16
20
  registerAppGet(appCmd);
17
21
  registerAppUpdate(appCmd);
22
+ if (opts.includeInit) {
23
+ registerAppInit(appCmd);
24
+ }
18
25
  }
19
26
  function registerAppGet(parent) {
20
27
  const cmd = parent
@@ -60,3 +67,78 @@ JSON 输出
60
67
  });
61
68
  }));
62
69
  }
70
+ function registerAppInit(parent) {
71
+ const cmd = parent
72
+ .command('init')
73
+ .description('初始化应用代码:抓 template 渲染、装 .agent/steering/ skills、写 .spark/meta.json。.spark/meta.json 已存在则直接退出')
74
+ .option('--template <stack>', `技术栈短名(${index_1.SUPPORTED_STACKS.join(' / ')})`)
75
+ .option('--conf <json>', 'init 配置 JSON。支持 {"version": "<template 版本>"} / {"steeringVersion": "<steering 版本>"},均默认 latest')
76
+ .option('--skip-install', '跳过依赖安装', false)
77
+ .addHelpText('after', `
78
+ 幂等
79
+ .spark/meta.json 已存在时直接退出(initialized=false, reason=already_initialized),
80
+ 不再触发 template 渲染、不重新拉 skills、不安装依赖。
81
+ meta.json 在 init 流程最后才写,写了 = 已完整成功一次;
82
+ 上一次失败留下半渲染状态时(package.json 在但 meta.json 没在)允许重跑。
83
+
84
+ 应用身份(appId)
85
+ init 不再持久化 appId。运行端命令(deploy / file / plugin 等)始终从 MIAODA_APP_ID env 读,
86
+ init 阶段也无需感知 appId。
87
+
88
+ 依赖安装
89
+ 默认:npm install --no-audit --no-fund
90
+ --skip-install: 跳过
91
+ MIAODA_DEP_CACHE_DIR 环境变量:
92
+ 若设了且 CWD 含 package.json,先算 md5(package.json),
93
+ 命中 \${MIAODA_DEP_CACHE_DIR}/\${hash}.zip 则 unzip 复用缓存;未命中或解压后 node_modules
94
+ 为空都会 fallback npm install。
95
+ JSON 模式下子进程 stdout 重定向到 stderr,避免污染最终 emit 的 JSON。
96
+
97
+ JSON 输出
98
+ 已初始化:{"data": {"initialized": false, "reason": "already_initialized", "targetDir": "..."}}
99
+ 新初始化:{"data": {"initialized": true, "template": "...", "templateVersion": "...", "steeringVersion": "...",
100
+ "installed": true, "installSource": "cache|npm|skipped", "installHash": "...", ...}}
101
+
102
+ 示例
103
+ $ miaoda app init --template vite-react
104
+ $ miaoda app init --template vite-react --conf '{"version": "0.1.0-alpha.1"}'
105
+ $ miaoda app init --template vite-react --conf '{"steeringVersion": "0.1.0"}'
106
+ $ miaoda app init --template vite-react --skip-install
107
+ $ MIAODA_DEP_CACHE_DIR=/tmp/dep-cache miaoda app init --template vite-react
108
+ `);
109
+ cmd.action((0, shared_1.withHelp)(cmd, async (rawOpts) => {
110
+ const conf = parseInitConf(rawOpts.conf);
111
+ await (0, index_1.handleAppInit)({
112
+ template: rawOpts.template,
113
+ conf,
114
+ skipInstall: rawOpts.skipInstall,
115
+ });
116
+ }));
117
+ }
118
+ function parseInitConf(raw) {
119
+ if (raw === undefined)
120
+ return undefined;
121
+ let parsed;
122
+ try {
123
+ parsed = JSON.parse(raw);
124
+ }
125
+ catch (err) {
126
+ const msg = err instanceof Error ? err.message : String(err);
127
+ throw new error_1.AppError('ARGS_INVALID', `--conf 必须是合法 JSON:${msg}`);
128
+ }
129
+ if (!isPlainObject(parsed)) {
130
+ throw new error_1.AppError('ARGS_INVALID', '--conf 必须是 JSON 对象');
131
+ }
132
+ const version = parsed.version;
133
+ if (version !== undefined && typeof version !== 'string') {
134
+ throw new error_1.AppError('ARGS_INVALID', '--conf.version 必须是字符串');
135
+ }
136
+ const steeringVersion = parsed.steeringVersion;
137
+ if (steeringVersion !== undefined && typeof steeringVersion !== 'string') {
138
+ throw new error_1.AppError('ARGS_INVALID', '--conf.steeringVersion 必须是字符串');
139
+ }
140
+ return { version, steeringVersion };
141
+ }
142
+ function isPlainObject(v) {
143
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
144
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerDeployCommandsModern = registerDeployCommandsModern;
4
+ const shared_1 = require("../../../cli/commands/shared");
5
+ const modern_1 = require("../../../cli/handlers/deploy/modern");
6
+ /**
7
+ * modern scene (MIAODA_APP_TYPE=7) 专用 deploy 注册。
8
+ * 仅披露顶层 `miaoda deploy`,CLI 表面对齐 openclaw-cli:`--dir / --skip-build`。
9
+ *
10
+ * 与 default 的 registerDeployCommands 完全平行:两套实现 100% 隔离,
11
+ * 不共享分支、不互相依赖。后端调用与编排在 src/services/deploy/modern/。
12
+ */
13
+ function registerDeployCommandsModern(program) {
14
+ const deployCmd = program
15
+ .command('deploy')
16
+ .description('触发 modern 应用发布:本地构建 + 本地部署(preRelease + localPublish)')
17
+ .option('--dir <path>', '项目目录', '.')
18
+ .option('--skip-build', '跳过 build 步骤(已构建好时使用)', false)
19
+ .addHelpText('after', `
20
+ 不要用异步模式或后台模式调用 deploy,否则调用可能提前结束,Agent 会误判发布已完成。
21
+
22
+ 前置要求
23
+ - 项目已 init(.spark/meta.json 含 stack)
24
+ - MIAODA_APP_ID 已设置(应用身份从 env 读,不再从 meta.json 读)
25
+ - node_modules 已安装
26
+ - package.json 含 build script
27
+ - 沙箱内预装 tosutil(用于把构建产物上传到 TOS)
28
+
29
+ 流程概览(stderr 进度提示)
30
+ 1. prepareContext 2. preRelease 3. build
31
+ 4. createLocalRelease 5. uploadArtifacts
32
+ 6. savePluginInstances(扫描 dist/output_capabilities/*.json 批量注册)
33
+ 7. finalizeLocalRelease(Finished|Failed)
34
+
35
+ JSON 输出(stdout)
36
+ {"data": {"appId": "...", "version": <n>, "url": "...", "releaseID": "...", "preReleaseID": "..."}}
37
+
38
+ 示例
39
+ $ miaoda deploy
40
+ $ miaoda deploy --dir ./my-app
41
+ $ miaoda deploy --skip-build
42
+ `);
43
+ deployCmd.action((0, shared_1.withHelp)(deployCmd, async (rawOpts) => {
44
+ await (0, modern_1.handleDeployModern)({
45
+ dir: rawOpts.dir ?? '.',
46
+ appId: (0, shared_1.resolveAppId)({}),
47
+ skipBuild: rawOpts.skipBuild,
48
+ });
49
+ }));
50
+ }
@@ -1,15 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveScene = resolveScene;
3
4
  exports.registerCommands = registerCommands;
4
5
  const index_1 = require("../../cli/commands/file/index");
5
6
  const index_2 = require("../../cli/commands/db/index");
6
7
  const index_3 = require("../../cli/commands/observability/index");
7
8
  const index_4 = require("../../cli/commands/app/index");
8
9
  const index_5 = require("../../cli/commands/deploy/index");
10
+ const modern_1 = require("../../cli/commands/deploy/modern");
11
+ const index_6 = require("../../cli/commands/skills/index");
12
+ function resolveScene(appType, _archType) {
13
+ if (appType === '7')
14
+ return 'modern';
15
+ return 'default';
16
+ }
17
+ const SCENE_REGISTRARS = {
18
+ default: (p) => {
19
+ (0, index_4.registerAppCommands)(p);
20
+ (0, index_5.registerDeployCommands)(p);
21
+ (0, index_2.registerDbCommands)(p);
22
+ (0, index_1.registerFileCommands)(p);
23
+ (0, index_3.registerObservabilityCommands)(p);
24
+ },
25
+ modern: (p) => {
26
+ (0, index_4.registerAppCommands)(p, { includeInit: true });
27
+ (0, modern_1.registerDeployCommandsModern)(p);
28
+ (0, index_6.registerSkillsCommands)(p);
29
+ },
30
+ };
31
+ function readEnv(name) {
32
+ const v = process.env[name]?.trim();
33
+ return v !== undefined && v !== '' ? v : undefined;
34
+ }
9
35
  function registerCommands(program) {
10
- (0, index_1.registerFileCommands)(program);
11
- (0, index_2.registerDbCommands)(program);
12
- (0, index_3.registerObservabilityCommands)(program);
13
- (0, index_4.registerAppCommands)(program);
14
- (0, index_5.registerDeployCommands)(program);
36
+ const appType = readEnv('MIAODA_APP_TYPE');
37
+ const archType = readEnv('MIAODA_APP_ARCH_TYPE');
38
+ const scene = resolveScene(appType, archType);
39
+ SCENE_REGISTRARS[scene](program);
40
+ if (process.env.MIAODA_VERBOSE === '1' || process.argv.includes('--verbose')) {
41
+ process.stderr.write(`[miaoda] scene=${scene} app_type=${appType ?? '-'} arch_type=${archType ?? '-'}\n`);
42
+ }
15
43
  }
@@ -14,6 +14,24 @@ const COMMON_TIME_HELP = `
14
14
  1) 不带时区的形式与 pretty 输出闭环(同机器复制粘贴稳定);跨机器请带显式时区。
15
15
  2) 必须用 T 分隔日期与时间,禁止空格——shell 会把不带引号的 'YYYY-MM-DD HH:mm:ss' 拆成两个参数。
16
16
  `;
17
+ function normalizeRepeatedOption(value) {
18
+ if (Array.isArray(value)) {
19
+ const items = value.filter((item) => typeof item === 'string' && item.length > 0);
20
+ return items.length === 1 ? items[0] : items;
21
+ }
22
+ return value;
23
+ }
24
+ function normalizeRepeatedArray(value) {
25
+ if (Array.isArray(value)) {
26
+ return value.filter((item) => typeof item === 'string' && item.length > 0);
27
+ }
28
+ return typeof value === 'string' && value ? [value] : [];
29
+ }
30
+ function compactRepeatedOption(values) {
31
+ if (values.length === 0)
32
+ return undefined;
33
+ return values.length === 1 ? values[0] : values;
34
+ }
17
35
  function registerObservabilityCommands(program) {
18
36
  const obCmd = program
19
37
  .command('observability')
@@ -31,6 +49,7 @@ function registerObservabilityCommands(program) {
31
49
  `);
32
50
  registerLog(obCmd);
33
51
  registerTrace(obCmd);
52
+ registerSourceStack(obCmd);
34
53
  registerMetric(obCmd);
35
54
  registerAnalytics(obCmd);
36
55
  }
@@ -45,8 +64,8 @@ function registerLog(parent) {
45
64
  .argParser((0, shared_1.caseInsensitiveChoice)(['DEBUG', 'INFO', 'WARN', 'ERROR'])))
46
65
  .option('--since <time>', '开始时间')
47
66
  .option('--until <time>', '截止时间')
48
- .option('--log-id <id>', '按请求 logid 过滤(attributes.ob_data_id)')
49
- .option('--trace-id <id>', '按 trace ID 过滤')
67
+ .addOption(new commander_1.Option('--log-id <id>', '按请求 logid 过滤(可重复传入)').argParser(shared_1.collectRepeatedOption))
68
+ .addOption(new commander_1.Option('--trace-id <id>', '按 trace ID 过滤(可重复传入)').argParser(shared_1.collectRepeatedOption))
50
69
  .option('--grep <pattern>', '按关键字模糊搜索 body')
51
70
  .option('--module <name>', '按模块名过滤')
52
71
  .option('--user-id <user-id>', '按触发用户 ID 过滤')
@@ -63,7 +82,9 @@ JSON 输出
63
82
  示例
64
83
  $ miaoda observability log --since 1h --level error --json
65
84
  $ miaoda observability log --log-id log_abc123 --json
85
+ $ miaoda observability log --log-id log_1 --log-id log_2 --json
66
86
  $ miaoda observability log --trace-id 140ebb5ac9b... --json
87
+ $ miaoda observability log --trace-id trace_1 --trace-id trace_2 --json
67
88
  $ miaoda observability log --api /api/orders --min-duration 200 --json
68
89
  `);
69
90
  cmd.action((0, shared_1.withHelp)(cmd, async (rawOpts) => {
@@ -74,8 +95,8 @@ JSON 输出
74
95
  level: rawOpts.level,
75
96
  since: rawOpts.since,
76
97
  until: rawOpts.until,
77
- logId: rawOpts.logId,
78
- traceId: rawOpts.traceId,
98
+ logId: normalizeRepeatedOption(rawOpts.logId),
99
+ traceId: normalizeRepeatedOption(rawOpts.traceId),
79
100
  grep: rawOpts.grep,
80
101
  module: rawOpts.module,
81
102
  userId: rawOpts.userId,
@@ -100,7 +121,7 @@ function registerTrace(parent) {
100
121
  .addOption((0, shared_1.appIdOption)().hideHelp())
101
122
  .option('--since <time>', '开始时间')
102
123
  .option('--until <time>', '截止时间')
103
- .option('--trace-id <id>', '按 trace ID 过滤')
124
+ .addOption(new commander_1.Option('--trace-id <id>', '按 trace ID 过滤(可重复传入)').argParser(shared_1.collectRepeatedOption))
104
125
  .option('--root-span <span-name>', '按入口节点关键词过滤')
105
126
  .option('--user-id <user-id>', '按触发用户 ID 过滤')
106
127
  .option('--limit <n>', '返回条数上限(1~100)', parseLimit, 50)
@@ -111,6 +132,7 @@ JSON 输出
111
132
 
112
133
  示例
113
134
  $ miaoda observability trace list --since 1h --json
135
+ $ miaoda observability trace list --trace-id trace_1 --trace-id trace_2 --json
114
136
  $ miaoda observability trace list --root-span api-gateway --limit 20 --json
115
137
  `);
116
138
  listCmd.action((0, shared_1.withHelp)(listCmd, async (rawOpts) => {
@@ -120,7 +142,7 @@ JSON 输出
120
142
  appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
121
143
  since: rawOpts.since,
122
144
  until: rawOpts.until,
123
- traceId: rawOpts.traceId,
145
+ traceId: normalizeRepeatedOption(rawOpts.traceId),
124
146
  rootSpan: rawOpts.rootSpan,
125
147
  userId: rawOpts.userId,
126
148
  limit: rawOpts.limit,
@@ -154,6 +176,40 @@ JSON 输出
154
176
  });
155
177
  }));
156
178
  }
179
+ // ── source-stack ──
180
+ function registerSourceStack(parent) {
181
+ const cmd = parent
182
+ .command('source-stack')
183
+ .description('反解前端错误堆栈到源码位置')
184
+ .argument('[log-ids...]', '前端错误请求 logid,可传多个')
185
+ .addOption((0, shared_1.appIdOption)().hideHelp())
186
+ .addOption(new commander_1.Option('--log-id <id>', '前端错误请求 logid(可重复传入)').argParser(shared_1.collectRepeatedOption))
187
+ .addOption(new commander_1.Option('--trace-id <id>', '包含前端错误的 trace ID(可重复传入)').argParser(shared_1.collectRepeatedOption))
188
+ .option('--since <time>', '开始时间')
189
+ .option('--until <time>', '截止时间')
190
+ .option('--limit <n>', '每类查询返回条数上限(1~100)', parseLimit, 50)
191
+ .addHelpText('after', `${COMMON_TIME_HELP}
192
+ JSON 输出
193
+ {"data": [{"log_id": "...", "trace_id": "...", "status": "resolved", "error_message_stack": "Error: boom\\n at src/App.tsx:42:7"}], "next_cursor": null, "has_more": false}
194
+
195
+ 示例
196
+ $ miaoda observability source-stack --log-id log_1 --log-id log_2 --json
197
+ $ miaoda observability source-stack --trace-id trace_1 --trace-id trace_2 --json
198
+ $ miaoda observability source-stack log_abc123 --json
199
+ `);
200
+ cmd.action((0, shared_1.withHelp)(cmd, async (logIds, rawOpts) => {
201
+ (0, shared_1.validateTimeOptions)(rawOpts, 'since', 'until');
202
+ (0, shared_1.rejectCliOverride)(cmd, 'appId');
203
+ await (0, index_1.handleObservabilitySourceStack)({
204
+ appId: (0, shared_1.resolveAppId)({ appId: rawOpts.appId }),
205
+ logId: compactRepeatedOption([...logIds, ...normalizeRepeatedArray(rawOpts.logId)]),
206
+ traceId: normalizeRepeatedOption(rawOpts.traceId),
207
+ since: rawOpts.since,
208
+ until: rawOpts.until,
209
+ limit: rawOpts.limit,
210
+ });
211
+ }));
212
+ }
157
213
  // ── metric ──
158
214
  function registerMetric(parent) {
159
215
  const cmd = parent
@@ -7,6 +7,7 @@ exports.softRequiredOption = softRequiredOption;
7
7
  exports.resolveAppId = resolveAppId;
8
8
  exports.withHelp = withHelp;
9
9
  exports.caseInsensitiveChoice = caseInsensitiveChoice;
10
+ exports.collectRepeatedOption = collectRepeatedOption;
10
11
  exports.validateTimeOptions = validateTimeOptions;
11
12
  exports.rejectCliOverride = rejectCliOverride;
12
13
  const commander_1 = require("commander");
@@ -86,6 +87,10 @@ function caseInsensitiveChoice(canonical) {
86
87
  return hit;
87
88
  };
88
89
  }
90
+ /** Commander repeatable option parser:重复传入时收集为数组。 */
91
+ function collectRepeatedOption(value, previous = []) {
92
+ return [...previous, value];
93
+ }
89
94
  /**
90
95
  * --since / --until 等时间参数的 action 阶段校验。
91
96
  *
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerSkillsCommands = registerSkillsCommands;
4
+ const shared_1 = require("../../../cli/commands/shared");
5
+ const index_1 = require("../../../cli/handlers/skills/index");
6
+ /**
7
+ * miaoda skills:本地 agent skills 维护。
8
+ *
9
+ * 当前仅 steering 一类子集(coding-steering 包内的 _common/skills + <stack>/skills + tech.md);
10
+ * 后续如有更多 skill 类型再加 --type。`app init` 会一次性同步装上,独立 `skills sync` 用于
11
+ * 后续单独升级 / pin 版本,不必走完整 init。
12
+ */
13
+ function registerSkillsCommands(program) {
14
+ const skillsCmd = program.command('skills').description('本地 agent skills(含 steering)维护');
15
+ skillsCmd.action(() => {
16
+ skillsCmd.outputHelp();
17
+ });
18
+ registerSkillsSync(skillsCmd);
19
+ registerSkillsStatus(skillsCmd);
20
+ }
21
+ function registerSkillsSync(parent) {
22
+ const cmd = parent
23
+ .command('sync')
24
+ .description('同步 coding-steering(latest 或指定版本)到 .agent/steering/')
25
+ .argument('[version]', 'coding-steering 包版本或 dist-tag,缺省 latest')
26
+ .option('--dir <path>', '项目目录,默认当前目录', '.')
27
+ .addHelpText('after', `
28
+ 前置要求
29
+ 当前目录(或 --dir)已走过 'miaoda app init'(.spark/meta.json 含 stack)
30
+
31
+ JSON 输出
32
+ {"data": {"stack": "...", "version": "...", "syncedSkills": [...], "techSynced": true|false}}
33
+
34
+ 示例
35
+ $ miaoda skills sync
36
+ $ miaoda skills sync 0.2.0
37
+ $ miaoda skills sync --dir ./my-app
38
+ `);
39
+ cmd.action((0, shared_1.withHelp)(cmd, async (version, rawOpts) => {
40
+ await (0, index_1.handleSkillsSync)({
41
+ dir: rawOpts.dir,
42
+ version,
43
+ });
44
+ }));
45
+ }
46
+ function registerSkillsStatus(parent) {
47
+ const cmd = parent
48
+ .command('status')
49
+ .description('查看本地 .agent/steering/ 的当前状态(不联网)')
50
+ .option('--dir <path>', '项目目录,默认当前目录', '.')
51
+ .addHelpText('after', `
52
+ JSON 输出
53
+ {"data": {"present": true|false, "skills": [...], "techSynced": true|false}}
54
+
55
+ 示例
56
+ $ miaoda skills status
57
+ `);
58
+ cmd.action((0, shared_1.withHelp)(cmd, async (rawOpts) => {
59
+ await (0, index_1.handleSkillsStatus)({
60
+ dir: rawOpts.dir,
61
+ });
62
+ }));
63
+ }