@lark-apaas/fullstack-cli 1.1.46-alpha.0 → 1.1.46-alpha.2

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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
- import fs27 from "fs";
3
- import path23 from "path";
2
+ import fs29 from "fs";
3
+ import path25 from "path";
4
4
  import { fileURLToPath as fileURLToPath5 } from "url";
5
5
  import { config as dotenvConfig } from "dotenv";
6
6
 
@@ -2373,13 +2373,35 @@ import { fileURLToPath as fileURLToPath3 } from "url";
2373
2373
  var syncConfig = {
2374
2374
  // 派生规则
2375
2375
  sync: [
2376
- // 1. 派生 scripts 目录(总是覆盖)
2376
+ // 1. 派生 scripts 目录(总是覆盖;递归同步,包含 scripts/hooks/run-precommit.js)
2377
2377
  {
2378
2378
  from: "templates/scripts",
2379
2379
  to: "scripts",
2380
2380
  type: "directory",
2381
2381
  overwrite: true
2382
2382
  },
2383
+ // 1a. 同步 .githooks 目录(hook 入口,可执行 sh 脚本)
2384
+ {
2385
+ from: "templates/.githooks",
2386
+ to: ".githooks",
2387
+ type: "directory",
2388
+ overwrite: true
2389
+ },
2390
+ // 1b. scripts.prepare:npm install 后自动激活 git hooks(原生 git,无第三方依赖)
2391
+ // 直接写 core.hooksPath,并保底给 pre-commit 加执行位;非 git 仓库下静默退出
2392
+ {
2393
+ type: "add-script",
2394
+ name: "prepare",
2395
+ command: "chmod +x .githooks/pre-commit 2>/dev/null; git config core.hooksPath .githooks 2>/dev/null || true",
2396
+ overwrite: false
2397
+ },
2398
+ // 1c. scripts.precommit = pre-commit 真正的执行体(跑 npm run lint)
2399
+ {
2400
+ type: "add-script",
2401
+ name: "precommit",
2402
+ command: "node scripts/hooks/run-precommit.js",
2403
+ overwrite: false
2404
+ },
2383
2405
  // 2. 智能合并 nest-cli.json 配置(保留用户自定义的 assets、plugins 等)
2384
2406
  {
2385
2407
  from: "templates/nest-cli.json",
@@ -2440,6 +2462,14 @@ var syncConfig = {
2440
2462
  to: ".spark_project",
2441
2463
  type: "file",
2442
2464
  overwrite: true
2465
+ },
2466
+ // 9. 把模板版本的 lint 脚本替换为支持 --files 的 runner
2467
+ // 只识别平台模板生成的 `concurrently ...` 形态,用户真正改写过的脚本保持原样
2468
+ {
2469
+ type: "patch-script",
2470
+ name: "lint",
2471
+ to: "node ./scripts/lint.js",
2472
+ ifStartsWith: "concurrently "
2443
2473
  }
2444
2474
  ],
2445
2475
  // 文件权限设置
@@ -2527,79 +2557,44 @@ function deepMergeJson(user, template, arrayMerge = {}, currentPath = "") {
2527
2557
  return result;
2528
2558
  }
2529
2559
 
2530
- // src/utils/package-json.ts
2560
+ // src/commands/sync/activate-hooks.ts
2531
2561
  import fs6 from "fs";
2532
2562
  import path4 from "path";
2533
- var LEGACY_LINT_SCRIPT = 'concurrently "npm run eslint" "npm run type:check" "npm run stylelint"';
2534
- var PATCHED_LINT_SCRIPT = "node ./scripts/lint.js";
2535
- function readPackageJson(cwd = process.cwd()) {
2536
- const pkgPath = path4.join(cwd, "package.json");
2537
- if (!fs6.existsSync(pkgPath)) {
2538
- throw new Error(`package.json not found at ${pkgPath}`);
2539
- }
2540
- const content = fs6.readFileSync(pkgPath, "utf-8");
2541
- return JSON.parse(content);
2542
- }
2543
- function writePackageJson(pkg2, cwd = process.cwd()) {
2544
- const pkgPath = path4.join(cwd, "package.json");
2545
- const content = JSON.stringify(pkg2, null, 2) + "\n";
2546
- fs6.writeFileSync(pkgPath, content, "utf-8");
2547
- }
2548
- function patchLintScriptForFilesSupport(pkg2) {
2549
- const currentLint = pkg2.scripts?.lint;
2550
- if (!currentLint) {
2551
- return "skipped-missing";
2552
- }
2553
- if (currentLint === PATCHED_LINT_SCRIPT || currentLint === "node scripts/lint.js") {
2554
- return "already-patched";
2555
- }
2556
- if (currentLint !== LEGACY_LINT_SCRIPT) {
2557
- return "skipped-custom";
2558
- }
2559
- pkg2.scripts = pkg2.scripts || {};
2560
- pkg2.scripts.lint = PATCHED_LINT_SCRIPT;
2561
- return "patched";
2562
- }
2563
- function removeUpgradeScript(pkg2) {
2564
- if (!pkg2.scripts?.upgrade) {
2565
- return false;
2566
- }
2567
- delete pkg2.scripts.upgrade;
2568
- return true;
2569
- }
2570
- function cleanDevScript(pkg2) {
2571
- if (!pkg2.scripts?.dev) {
2572
- return false;
2573
- }
2574
- const originalDev = pkg2.scripts.dev;
2575
- const cleanedDev = originalDev.replace(/npm\s+run\s+upgrade\s*&&\s*/g, "").replace(/npm\s+run\s+upgrade\s*$/g, "").trim();
2576
- if (cleanedDev !== originalDev) {
2577
- pkg2.scripts.dev = cleanedDev;
2578
- return true;
2579
- }
2580
- return false;
2581
- }
2582
- function cleanupPackageJson(cwd = process.cwd()) {
2583
- try {
2584
- const pkg2 = readPackageJson(cwd);
2585
- let changed = false;
2586
- if (removeUpgradeScript(pkg2)) {
2587
- console.log("[fullstack-cli] \u2713 Removed scripts.upgrade");
2588
- changed = true;
2589
- }
2590
- if (cleanDevScript(pkg2)) {
2591
- console.log("[fullstack-cli] \u2713 Cleaned scripts.dev (removed npm run upgrade)");
2592
- changed = true;
2593
- }
2594
- if (changed) {
2595
- writePackageJson(pkg2, cwd);
2563
+ import { spawnSync as spawnSync2 } from "child_process";
2564
+ function activateGitHooks(userProjectRoot) {
2565
+ if (!fs6.existsSync(path4.join(userProjectRoot, ".git"))) {
2566
+ return { action: "skipped-no-git" };
2567
+ }
2568
+ const hookFile = path4.join(userProjectRoot, ".githooks", "pre-commit");
2569
+ if (!fs6.existsSync(hookFile)) {
2570
+ return { action: "skipped-no-hook-file" };
2571
+ }
2572
+ let changed = false;
2573
+ const currentMode = fs6.statSync(hookFile).mode & 511;
2574
+ if ((currentMode & 73) !== 73) {
2575
+ fs6.chmodSync(hookFile, 493);
2576
+ changed = true;
2577
+ }
2578
+ const probe = spawnSync2("git", ["config", "--get", "core.hooksPath"], {
2579
+ cwd: userProjectRoot,
2580
+ stdio: ["ignore", "pipe", "ignore"]
2581
+ });
2582
+ const currentHooksPath = probe.stdout ? probe.stdout.toString().trim() : "";
2583
+ if (currentHooksPath !== ".githooks") {
2584
+ const res = spawnSync2("git", ["config", "core.hooksPath", ".githooks"], {
2585
+ cwd: userProjectRoot,
2586
+ stdio: ["ignore", "inherit", "inherit"]
2587
+ });
2588
+ if (res.status !== 0) {
2589
+ throw new Error(`git config core.hooksPath exited with ${String(res.status)}`);
2596
2590
  }
2597
- return changed;
2598
- } catch (error) {
2599
- const message = error instanceof Error ? error.message : String(error);
2600
- console.log(`[fullstack-cli] \u26A0 Could not cleanup package.json: ${message}`);
2601
- return false;
2591
+ changed = true;
2602
2592
  }
2593
+ if (changed) {
2594
+ console.log("[fullstack-cli] \u2713 git hooks activated (core.hooksPath -> .githooks)");
2595
+ return { action: "activated" };
2596
+ }
2597
+ return { action: "already-active" };
2603
2598
  }
2604
2599
 
2605
2600
  // src/commands/sync/run.handler.ts
@@ -2617,6 +2612,19 @@ async function run2(options) {
2617
2612
  console.log("[fullstack-cli] Skip syncing (not a valid npm project)");
2618
2613
  process.exit(0);
2619
2614
  }
2615
+ const sparkMetaPath = path5.join(userProjectRoot, ".spark", "meta.json");
2616
+ if (fs7.existsSync(sparkMetaPath)) {
2617
+ try {
2618
+ const meta = JSON.parse(fs7.readFileSync(sparkMetaPath, "utf-8"));
2619
+ if (Number(meta.archType) === 2) {
2620
+ console.log("[fullstack-cli] Skip syncing (.spark/meta.json archType=2)");
2621
+ process.exit(0);
2622
+ }
2623
+ } catch (error) {
2624
+ const message = error instanceof Error ? error.message : String(error);
2625
+ console.warn(`[fullstack-cli] \u26A0 Failed to read .spark/meta.json, fallback to default sync: ${message}`);
2626
+ }
2627
+ }
2620
2628
  try {
2621
2629
  console.log("[fullstack-cli] Starting sync...");
2622
2630
  const config = genSyncConfig({
@@ -2629,10 +2637,15 @@ async function run2(options) {
2629
2637
  for (const rule of config.sync) {
2630
2638
  await syncRule(rule, pluginRoot, userProjectRoot);
2631
2639
  }
2632
- patchUserPackageJson(userProjectRoot);
2633
2640
  if (config.permissions) {
2634
2641
  setPermissions(config.permissions, userProjectRoot);
2635
2642
  }
2643
+ try {
2644
+ activateGitHooks(userProjectRoot);
2645
+ } catch (error) {
2646
+ const message = error instanceof Error ? error.message : String(error);
2647
+ console.warn(`[fullstack-cli] \u26A0 Failed to activate git hooks: ${message}`);
2648
+ }
2636
2649
  console.log("[fullstack-cli] Sync completed successfully \u2705");
2637
2650
  } catch (error) {
2638
2651
  const message = error instanceof Error ? error.message : String(error);
@@ -2640,29 +2653,6 @@ async function run2(options) {
2640
2653
  process.exit(1);
2641
2654
  }
2642
2655
  }
2643
- function patchUserPackageJson(userProjectRoot) {
2644
- try {
2645
- const pkg2 = readPackageJson(userProjectRoot);
2646
- const lintPatchResult = patchLintScriptForFilesSupport(pkg2);
2647
- if (lintPatchResult === "patched") {
2648
- writePackageJson(pkg2, userProjectRoot);
2649
- console.log("[fullstack-cli] \u2713 Patched scripts.lint to support --files");
2650
- return;
2651
- }
2652
- if (lintPatchResult === "already-patched") {
2653
- console.log("[fullstack-cli] \u25CB scripts.lint already supports --files");
2654
- return;
2655
- }
2656
- if (lintPatchResult === "skipped-custom") {
2657
- console.warn(
2658
- "[fullstack-cli] \u26A0 Skipped patching scripts.lint because it has been customized"
2659
- );
2660
- }
2661
- } catch (error) {
2662
- const message = error instanceof Error ? error.message : String(error);
2663
- console.warn(`[fullstack-cli] \u26A0 Could not patch package.json: ${message}`);
2664
- }
2665
- }
2666
2656
  async function syncRule(rule, pluginRoot, userProjectRoot) {
2667
2657
  if (rule.type === "delete-file" || rule.type === "delete-directory") {
2668
2658
  const destPath2 = path5.join(userProjectRoot, rule.to);
@@ -2683,6 +2673,11 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
2683
2673
  addScript(packageJsonPath, rule.name, rule.command, rule.overwrite ?? false);
2684
2674
  return;
2685
2675
  }
2676
+ if (rule.type === "patch-script") {
2677
+ const packageJsonPath = path5.join(userProjectRoot, "package.json");
2678
+ patchScript(packageJsonPath, rule.name, rule.to, rule.ifStartsWith);
2679
+ return;
2680
+ }
2686
2681
  if (rule.type === "add-line") {
2687
2682
  const destPath2 = path5.join(userProjectRoot, rule.to);
2688
2683
  addLineToFile(destPath2, rule.line);
@@ -2820,6 +2815,37 @@ function addScript(packageJsonPath, name, command, overwrite) {
2820
2815
  fs7.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
2821
2816
  console.log(`[fullstack-cli] \u2713 scripts.${name}`);
2822
2817
  }
2818
+ function patchScript(packageJsonPath, name, to, ifStartsWith) {
2819
+ if (!fs7.existsSync(packageJsonPath)) {
2820
+ console.log(`[fullstack-cli] \u25CB package.json (not found)`);
2821
+ return;
2822
+ }
2823
+ try {
2824
+ const content = fs7.readFileSync(packageJsonPath, "utf-8");
2825
+ const pkg2 = JSON.parse(content);
2826
+ const current = pkg2.scripts?.[name];
2827
+ if (!current) {
2828
+ console.log(`[fullstack-cli] \u25CB scripts.${name} (not present, skipped)`);
2829
+ return;
2830
+ }
2831
+ if (current === to) {
2832
+ console.log(`[fullstack-cli] \u25CB scripts.${name} (already patched)`);
2833
+ return;
2834
+ }
2835
+ if (!current.startsWith(ifStartsWith)) {
2836
+ console.warn(
2837
+ `[fullstack-cli] \u26A0 Skipped patching scripts.${name} because it has been customized`
2838
+ );
2839
+ return;
2840
+ }
2841
+ pkg2.scripts[name] = to;
2842
+ fs7.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
2843
+ console.log(`[fullstack-cli] \u2713 Patched scripts.${name}`);
2844
+ } catch (error) {
2845
+ const message = error instanceof Error ? error.message : String(error);
2846
+ console.warn(`[fullstack-cli] \u26A0 Could not patch scripts.${name}: ${message}`);
2847
+ }
2848
+ }
2823
2849
  function addLineToFile(filePath, line) {
2824
2850
  const fileName = path5.basename(filePath);
2825
2851
  if (!fs7.existsSync(filePath)) {
@@ -2920,7 +2946,7 @@ async function reportCreateInstanceEvent(pluginKey, version) {
2920
2946
  }
2921
2947
 
2922
2948
  // src/utils/git.ts
2923
- import { execSync, spawnSync as spawnSync2 } from "child_process";
2949
+ import { execSync, spawnSync as spawnSync3 } from "child_process";
2924
2950
  import fs8 from "fs";
2925
2951
  import path6 from "path";
2926
2952
  function isGitRepository(cwd = process.cwd()) {
@@ -2929,7 +2955,7 @@ function isGitRepository(cwd = process.cwd()) {
2929
2955
  if (fs8.existsSync(gitDir)) {
2930
2956
  return true;
2931
2957
  }
2932
- const result = spawnSync2("git", ["rev-parse", "--git-dir"], {
2958
+ const result = spawnSync3("git", ["rev-parse", "--git-dir"], {
2933
2959
  cwd,
2934
2960
  stdio: "pipe",
2935
2961
  encoding: "utf-8"
@@ -2959,7 +2985,7 @@ function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
2959
2985
  filteredFiles.push(filePath);
2960
2986
  continue;
2961
2987
  }
2962
- const tracked = spawnSync2("git", ["ls-files", "--error-unmatch", "--", filePath], {
2988
+ const tracked = spawnSync3("git", ["ls-files", "--error-unmatch", "--", filePath], {
2963
2989
  cwd,
2964
2990
  stdio: "pipe",
2965
2991
  encoding: "utf-8"
@@ -2971,7 +2997,7 @@ function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
2971
2997
  if (filteredFiles.length === 0) {
2972
2998
  return;
2973
2999
  }
2974
- const result = spawnSync2("git", ["add", "--", ...filteredFiles], {
3000
+ const result = spawnSync3("git", ["add", "--", ...filteredFiles], {
2975
3001
  cwd,
2976
3002
  stdio: "pipe",
2977
3003
  encoding: "utf-8"
@@ -2982,7 +3008,7 @@ function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
2982
3008
  }
2983
3009
  }
2984
3010
  function hasStagedChanges(cwd = process.cwd()) {
2985
- const result = spawnSync2("git", ["diff", "--cached", "--quiet"], {
3011
+ const result = spawnSync3("git", ["diff", "--cached", "--quiet"], {
2986
3012
  cwd,
2987
3013
  stdio: "pipe",
2988
3014
  encoding: "utf-8"
@@ -2997,7 +3023,7 @@ function hasStagedChanges(cwd = process.cwd()) {
2997
3023
  throw new Error(`Failed to check staged changes: ${errorMsg}`);
2998
3024
  }
2999
3025
  function gitCommit(message, cwd = process.cwd()) {
3000
- const result = spawnSync2("git", ["commit", "-m", message], {
3026
+ const result = spawnSync3("git", ["commit", "-m", message], {
3001
3027
  cwd,
3002
3028
  stdio: "pipe",
3003
3029
  encoding: "utf-8"
@@ -3039,16 +3065,74 @@ Auto-committed by fullstack-cli`;
3039
3065
  }
3040
3066
  }
3041
3067
 
3042
- // src/commands/upgrade/shared/utils.ts
3043
- import path7 from "path";
3068
+ // src/utils/package-json.ts
3044
3069
  import fs9 from "fs";
3070
+ import path7 from "path";
3071
+ function readPackageJson(cwd = process.cwd()) {
3072
+ const pkgPath = path7.join(cwd, "package.json");
3073
+ if (!fs9.existsSync(pkgPath)) {
3074
+ throw new Error(`package.json not found at ${pkgPath}`);
3075
+ }
3076
+ const content = fs9.readFileSync(pkgPath, "utf-8");
3077
+ return JSON.parse(content);
3078
+ }
3079
+ function writePackageJson(pkg2, cwd = process.cwd()) {
3080
+ const pkgPath = path7.join(cwd, "package.json");
3081
+ const content = JSON.stringify(pkg2, null, 2) + "\n";
3082
+ fs9.writeFileSync(pkgPath, content, "utf-8");
3083
+ }
3084
+ function removeUpgradeScript(pkg2) {
3085
+ if (!pkg2.scripts?.upgrade) {
3086
+ return false;
3087
+ }
3088
+ delete pkg2.scripts.upgrade;
3089
+ return true;
3090
+ }
3091
+ function cleanDevScript(pkg2) {
3092
+ if (!pkg2.scripts?.dev) {
3093
+ return false;
3094
+ }
3095
+ const originalDev = pkg2.scripts.dev;
3096
+ const cleanedDev = originalDev.replace(/npm\s+run\s+upgrade\s*&&\s*/g, "").replace(/npm\s+run\s+upgrade\s*$/g, "").trim();
3097
+ if (cleanedDev !== originalDev) {
3098
+ pkg2.scripts.dev = cleanedDev;
3099
+ return true;
3100
+ }
3101
+ return false;
3102
+ }
3103
+ function cleanupPackageJson(cwd = process.cwd()) {
3104
+ try {
3105
+ const pkg2 = readPackageJson(cwd);
3106
+ let changed = false;
3107
+ if (removeUpgradeScript(pkg2)) {
3108
+ console.log("[fullstack-cli] \u2713 Removed scripts.upgrade");
3109
+ changed = true;
3110
+ }
3111
+ if (cleanDevScript(pkg2)) {
3112
+ console.log("[fullstack-cli] \u2713 Cleaned scripts.dev (removed npm run upgrade)");
3113
+ changed = true;
3114
+ }
3115
+ if (changed) {
3116
+ writePackageJson(pkg2, cwd);
3117
+ }
3118
+ return changed;
3119
+ } catch (error) {
3120
+ const message = error instanceof Error ? error.message : String(error);
3121
+ console.log(`[fullstack-cli] \u26A0 Could not cleanup package.json: ${message}`);
3122
+ return false;
3123
+ }
3124
+ }
3125
+
3126
+ // src/commands/upgrade/shared/utils.ts
3127
+ import path8 from "path";
3128
+ import fs10 from "fs";
3045
3129
  import { fileURLToPath as fileURLToPath4 } from "url";
3046
3130
  function getCliVersion() {
3047
3131
  try {
3048
3132
  const __filename = fileURLToPath4(import.meta.url);
3049
- const __dirname2 = path7.dirname(__filename);
3050
- const pkgPath = path7.resolve(__dirname2, "../../../package.json");
3051
- const pkgContent = fs9.readFileSync(pkgPath, "utf-8");
3133
+ const __dirname2 = path8.dirname(__filename);
3134
+ const pkgPath = path8.resolve(__dirname2, "../../../package.json");
3135
+ const pkgContent = fs10.readFileSync(pkgPath, "utf-8");
3052
3136
  const pkg2 = JSON.parse(pkgContent);
3053
3137
  return pkg2.version || "unknown";
3054
3138
  } catch {
@@ -3106,31 +3190,47 @@ async function run3(options = {}) {
3106
3190
  }
3107
3191
 
3108
3192
  // src/commands/upgrade/deps/run.handler.ts
3109
- import { spawnSync as spawnSync3 } from "child_process";
3110
- import fs10 from "fs";
3111
- import path8 from "path";
3193
+ import { spawnSync as spawnSync4 } from "child_process";
3194
+ import fs11 from "fs";
3195
+ import path9 from "path";
3112
3196
 
3113
3197
  // src/utils/grayscale/config.ts
3114
3198
  function getGrayscaleConfig(configJson) {
3115
3199
  if (!configJson) {
3116
3200
  return null;
3117
3201
  }
3202
+ let parsed;
3118
3203
  try {
3119
- const parsed = JSON.parse(configJson);
3120
- const config = parsed.config;
3121
- if (!config || !config.enabled) {
3204
+ parsed = JSON.parse(configJson);
3205
+ } catch {
3206
+ console.warn("[grayscale] Failed to parse grayscale config");
3207
+ return null;
3208
+ }
3209
+ if (parsed && parsed.target_versions && typeof parsed.target_versions === "object") {
3210
+ const entries = Object.entries(parsed.target_versions).filter(
3211
+ ([, v]) => typeof v === "string" && v.length > 0
3212
+ );
3213
+ if (entries.length === 0) {
3214
+ console.log("[grayscale] target_versions present but empty, skip");
3122
3215
  return null;
3123
3216
  }
3124
3217
  return {
3125
- config,
3126
- tenantId: parsed.tenant_id != null ? String(parsed.tenant_id) : void 0,
3127
- appId: parsed.app_id || void 0,
3128
- xTtEnv: parsed.x_tt_env || void 0
3218
+ kind: "resolved",
3219
+ targetVersions: new Map(entries),
3220
+ matchedChannel: typeof parsed.matched_channel === "string" ? parsed.matched_channel : void 0
3129
3221
  };
3130
- } catch {
3131
- console.warn("[grayscale] Failed to parse grayscale config");
3222
+ }
3223
+ const config = parsed?.config;
3224
+ if (!config || !config.enabled) {
3132
3225
  return null;
3133
3226
  }
3227
+ return {
3228
+ kind: "legacy",
3229
+ config,
3230
+ tenantId: parsed.tenant_id != null ? String(parsed.tenant_id) : void 0,
3231
+ appId: parsed.app_id || void 0,
3232
+ xTtEnv: parsed.x_tt_env || void 0
3233
+ };
3134
3234
  }
3135
3235
 
3136
3236
  // src/utils/grayscale/identity.ts
@@ -3218,6 +3318,19 @@ function resolveGrayscaleVersions(_cwd, configJson) {
3218
3318
  console.log("[grayscale] Config not available, skipping grayscale");
3219
3319
  return null;
3220
3320
  }
3321
+ if (result.kind === "resolved") {
3322
+ console.log(
3323
+ `[grayscale] Using server-resolved versions (matched channel: ${result.matchedChannel || "(stable)"})`
3324
+ );
3325
+ console.log(`[grayscale] Resolved ${result.targetVersions.size} package version(s):`);
3326
+ for (const [pkg2, ver] of result.targetVersions) {
3327
+ console.log(`[grayscale] ${pkg2} -> ${ver}`);
3328
+ }
3329
+ return result.targetVersions;
3330
+ }
3331
+ console.warn(
3332
+ "[grayscale] Received legacy payload (full TCC config). This path is deprecated; sandbox_console should be upgraded to server-side resolution."
3333
+ );
3221
3334
  const { config, tenantId: payloadTenantId, appId: payloadAppId, xTtEnv: payloadXTtEnv } = result;
3222
3335
  const envIdentity = readProjectIdentity();
3223
3336
  const identity = {
@@ -3298,7 +3411,7 @@ function upgradePackages(packages, version, cwd) {
3298
3411
  packages.forEach((pkg2) => {
3299
3412
  const target = `${pkg2}@${version}`;
3300
3413
  console.log(`[fullstack-cli] Installing ${target}...`);
3301
- const result = spawnSync3("npm", ["install", target], {
3414
+ const result = spawnSync4("npm", ["install", target], {
3302
3415
  cwd,
3303
3416
  stdio: "inherit"
3304
3417
  });
@@ -3310,7 +3423,7 @@ function upgradePackages(packages, version, cwd) {
3310
3423
  console.log("[fullstack-cli] Upgrading to latest compatible versions...");
3311
3424
  packages.forEach((pkg2) => {
3312
3425
  console.log(`[fullstack-cli] Updating ${pkg2}...`);
3313
- const result = spawnSync3("npm", ["update", pkg2], {
3426
+ const result = spawnSync4("npm", ["update", pkg2], {
3314
3427
  cwd,
3315
3428
  stdio: "inherit"
3316
3429
  });
@@ -3327,8 +3440,8 @@ function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun, mode
3327
3440
  if (version) {
3328
3441
  let current = "";
3329
3442
  try {
3330
- const installedPkgPath = path8.join(cwd, "node_modules", pkg2, "package.json");
3331
- const installedPkg = JSON.parse(fs10.readFileSync(installedPkgPath, "utf-8"));
3443
+ const installedPkgPath = path9.join(cwd, "node_modules", pkg2, "package.json");
3444
+ const installedPkg = JSON.parse(fs11.readFileSync(installedPkgPath, "utf-8"));
3332
3445
  current = installedPkg.version || "";
3333
3446
  } catch (err) {
3334
3447
  const code = err?.code;
@@ -3371,7 +3484,7 @@ function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun, mode
3371
3484
  }
3372
3485
  const targets = upgradePlan.map(({ pkg: pkg2, version }) => `${pkg2}@${version}`);
3373
3486
  console.log(`[fullstack-cli] Installing ${targets.join(" ")}...`);
3374
- const result = spawnSync3("npm", ["install", ...targets], {
3487
+ const result = spawnSync4("npm", ["install", ...targets], {
3375
3488
  cwd,
3376
3489
  stdio: "inherit"
3377
3490
  });
@@ -3444,6 +3557,111 @@ var depsCommand = {
3444
3557
  }
3445
3558
  };
3446
3559
 
3560
+ // src/commands/upgrade/global-deps/run.handler.ts
3561
+ import { spawnSync as spawnSync5 } from "child_process";
3562
+ import fs12 from "fs";
3563
+ import path10 from "path";
3564
+ var MANAGED_GLOBAL_CLIS = [
3565
+ "@lark-apaas/fullstack-cli",
3566
+ "@lark-apaas/miaoda-cli"
3567
+ ];
3568
+ function readGlobalInstalledVersion(pkg2) {
3569
+ const candidates = [];
3570
+ if (process.env.npm_config_prefix) candidates.push(process.env.npm_config_prefix);
3571
+ if (process.env.NPM_CONFIG_PREFIX) candidates.push(process.env.NPM_CONFIG_PREFIX);
3572
+ candidates.push("/usr");
3573
+ candidates.push("/usr/local");
3574
+ if (process.env.HOME) candidates.push(path10.join(process.env.HOME, ".npm-global"));
3575
+ const seen = /* @__PURE__ */ new Set();
3576
+ for (const prefix of candidates) {
3577
+ if (seen.has(prefix)) continue;
3578
+ seen.add(prefix);
3579
+ try {
3580
+ const pkgPath = path10.join(prefix, "lib", "node_modules", pkg2, "package.json");
3581
+ if (fs12.existsSync(pkgPath)) {
3582
+ const meta = JSON.parse(fs12.readFileSync(pkgPath, "utf-8"));
3583
+ if (meta && typeof meta.version === "string") return meta.version;
3584
+ }
3585
+ } catch (err) {
3586
+ console.warn(
3587
+ `[fullstack-cli] readGlobalInstalledVersion(${pkg2}) failed at prefix=${prefix}: ${err instanceof Error ? err.message : String(err)}`
3588
+ );
3589
+ }
3590
+ }
3591
+ return "";
3592
+ }
3593
+ function buildGlobalUpgradePlan(managed, resolvedVersions, readVersion) {
3594
+ const plan = [];
3595
+ for (const pkg2 of managed) {
3596
+ const target = resolvedVersions.get(pkg2);
3597
+ if (!target) {
3598
+ console.log(`[fullstack-cli] ${pkg2}: no target version in grayscale config, skip`);
3599
+ continue;
3600
+ }
3601
+ const current = readVersion(pkg2);
3602
+ if (current && current === target) {
3603
+ console.log(`[fullstack-cli] ${pkg2}@${target} (already installed, skip)`);
3604
+ continue;
3605
+ }
3606
+ plan.push({ pkg: pkg2, current, target });
3607
+ }
3608
+ return plan;
3609
+ }
3610
+ async function run5(options = {}) {
3611
+ console.log("[fullstack-cli] Starting global CLI upgrade...");
3612
+ if (!options.grayscaleConfig) {
3613
+ console.log("[fullstack-cli] No grayscale config, skip global upgrade");
3614
+ return;
3615
+ }
3616
+ const grayscaleVersions = resolveGrayscaleVersions("/", options.grayscaleConfig);
3617
+ if (!grayscaleVersions) {
3618
+ console.log("[fullstack-cli] Grayscale config not available, skip global upgrade");
3619
+ return;
3620
+ }
3621
+ const plan = buildGlobalUpgradePlan(MANAGED_GLOBAL_CLIS, grayscaleVersions, readGlobalInstalledVersion);
3622
+ if (plan.length === 0) {
3623
+ console.log("[fullstack-cli] No global CLI upgrade needed");
3624
+ return;
3625
+ }
3626
+ console.log(`[fullstack-cli] Global upgrade plan (${plan.length} package(s)):`);
3627
+ plan.forEach(({ pkg: pkg2, current, target }) => {
3628
+ console.log(` - ${pkg2} ${current || "(not installed)"} -> ${target}`);
3629
+ });
3630
+ if (options.dryRun) {
3631
+ console.log("[fullstack-cli] Dry run mode, skipping actual installation");
3632
+ return;
3633
+ }
3634
+ const targets = plan.map(({ pkg: pkg2, target }) => `${pkg2}@${target}`);
3635
+ const npmArgs = ["install", "-g", ...targets];
3636
+ if (options.registry) {
3637
+ npmArgs.push("--registry", options.registry);
3638
+ }
3639
+ console.log(`[fullstack-cli] Running: npm ${npmArgs.join(" ")}`);
3640
+ const result = spawnSync5("npm", npmArgs, { stdio: "inherit" });
3641
+ if (result.error || result.status !== 0) {
3642
+ console.warn(
3643
+ `[fullstack-cli] npm install -g failed: ${result.error?.message ?? `exit ${result.status}`}`
3644
+ );
3645
+ process.exit(1);
3646
+ }
3647
+ console.log("[fullstack-cli] \u2713 Global CLI upgrade completed");
3648
+ }
3649
+
3650
+ // src/commands/upgrade/global-deps/index.ts
3651
+ var globalDepsCommand = {
3652
+ name: "global-deps",
3653
+ description: "Upgrade global @lark-apaas CLIs (fullstack-cli, miaoda-cli) per grayscale config",
3654
+ register(parentCommand) {
3655
+ parentCommand.command(this.name).description(this.description).option("--grayscale-config <json>", "Grayscale config JSON (injected by sandbox_console)").option("--dry-run", "Show upgrade plan without executing").option(
3656
+ "--registry <url>",
3657
+ "npm registry URL (default: https://registry.npmmirror.com/)",
3658
+ "https://registry.npmmirror.com/"
3659
+ ).action(async (options) => {
3660
+ await run5(options);
3661
+ });
3662
+ }
3663
+ };
3664
+
3447
3665
  // src/commands/upgrade/index.ts
3448
3666
  var upgradeCommand = {
3449
3667
  name: "upgrade",
@@ -3453,13 +3671,14 @@ var upgradeCommand = {
3453
3671
  await run3(options);
3454
3672
  });
3455
3673
  depsCommand.register(upgradeCmd);
3674
+ globalDepsCommand.register(upgradeCmd);
3456
3675
  }
3457
3676
  };
3458
3677
 
3459
3678
  // src/commands/action-plugin/utils.ts
3460
- import fs11 from "fs";
3461
- import path9 from "path";
3462
- import { spawnSync as spawnSync4, execSync as execSync2 } from "child_process";
3679
+ import fs13 from "fs";
3680
+ import path11 from "path";
3681
+ import { spawnSync as spawnSync6, execSync as execSync2 } from "child_process";
3463
3682
  function parsePluginName(input) {
3464
3683
  const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
3465
3684
  if (!match) {
@@ -3476,18 +3695,18 @@ function getProjectRoot() {
3476
3695
  return process.cwd();
3477
3696
  }
3478
3697
  function getPackageJsonPath() {
3479
- return path9.join(getProjectRoot(), "package.json");
3698
+ return path11.join(getProjectRoot(), "package.json");
3480
3699
  }
3481
3700
  function getPluginPath(pluginName) {
3482
- return path9.join(getProjectRoot(), "node_modules", pluginName);
3701
+ return path11.join(getProjectRoot(), "node_modules", pluginName);
3483
3702
  }
3484
3703
  function readPackageJson2() {
3485
3704
  const pkgPath = getPackageJsonPath();
3486
- if (!fs11.existsSync(pkgPath)) {
3705
+ if (!fs13.existsSync(pkgPath)) {
3487
3706
  throw new Error("package.json not found in current directory");
3488
3707
  }
3489
3708
  try {
3490
- const content = fs11.readFileSync(pkgPath, "utf-8");
3709
+ const content = fs13.readFileSync(pkgPath, "utf-8");
3491
3710
  return JSON.parse(content);
3492
3711
  } catch {
3493
3712
  throw new Error("Failed to parse package.json");
@@ -3495,7 +3714,7 @@ function readPackageJson2() {
3495
3714
  }
3496
3715
  function writePackageJson2(pkg2) {
3497
3716
  const pkgPath = getPackageJsonPath();
3498
- fs11.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
3717
+ fs13.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
3499
3718
  }
3500
3719
  function readActionPlugins() {
3501
3720
  const pkg2 = readPackageJson2();
@@ -3516,7 +3735,7 @@ function getInstalledPluginVersion(pluginName) {
3516
3735
  }
3517
3736
  function npmInstall(tgzPath) {
3518
3737
  console.log(`[action-plugin] Running npm install ${tgzPath}...`);
3519
- const result = spawnSync4("npm", ["install", tgzPath, "--no-save", "--no-package-lock", "--ignore-scripts"], {
3738
+ const result = spawnSync6("npm", ["install", tgzPath, "--no-save", "--no-package-lock", "--ignore-scripts"], {
3520
3739
  cwd: getProjectRoot(),
3521
3740
  stdio: "inherit"
3522
3741
  });
@@ -3528,12 +3747,12 @@ function npmInstall(tgzPath) {
3528
3747
  }
3529
3748
  }
3530
3749
  function getPackageVersion(pluginName) {
3531
- const pkgJsonPath = path9.join(getPluginPath(pluginName), "package.json");
3532
- if (!fs11.existsSync(pkgJsonPath)) {
3750
+ const pkgJsonPath = path11.join(getPluginPath(pluginName), "package.json");
3751
+ if (!fs13.existsSync(pkgJsonPath)) {
3533
3752
  return null;
3534
3753
  }
3535
3754
  try {
3536
- const content = fs11.readFileSync(pkgJsonPath, "utf-8");
3755
+ const content = fs13.readFileSync(pkgJsonPath, "utf-8");
3537
3756
  const pkg2 = JSON.parse(content);
3538
3757
  return pkg2.version || null;
3539
3758
  } catch {
@@ -3541,49 +3760,49 @@ function getPackageVersion(pluginName) {
3541
3760
  }
3542
3761
  }
3543
3762
  function readPluginPackageJson(pluginPath) {
3544
- const pkgJsonPath = path9.join(pluginPath, "package.json");
3545
- if (!fs11.existsSync(pkgJsonPath)) {
3763
+ const pkgJsonPath = path11.join(pluginPath, "package.json");
3764
+ if (!fs13.existsSync(pkgJsonPath)) {
3546
3765
  return null;
3547
3766
  }
3548
3767
  try {
3549
- const content = fs11.readFileSync(pkgJsonPath, "utf-8");
3768
+ const content = fs13.readFileSync(pkgJsonPath, "utf-8");
3550
3769
  return JSON.parse(content);
3551
3770
  } catch {
3552
3771
  return null;
3553
3772
  }
3554
3773
  }
3555
3774
  function extractTgzToNodeModules(tgzPath, pluginName) {
3556
- const nodeModulesPath = path9.join(getProjectRoot(), "node_modules");
3557
- const targetDir = path9.join(nodeModulesPath, pluginName);
3558
- const scopeDir = path9.dirname(targetDir);
3559
- if (!fs11.existsSync(scopeDir)) {
3560
- fs11.mkdirSync(scopeDir, { recursive: true });
3775
+ const nodeModulesPath = path11.join(getProjectRoot(), "node_modules");
3776
+ const targetDir = path11.join(nodeModulesPath, pluginName);
3777
+ const scopeDir = path11.dirname(targetDir);
3778
+ if (!fs13.existsSync(scopeDir)) {
3779
+ fs13.mkdirSync(scopeDir, { recursive: true });
3561
3780
  }
3562
- if (fs11.existsSync(targetDir)) {
3563
- fs11.rmSync(targetDir, { recursive: true });
3781
+ if (fs13.existsSync(targetDir)) {
3782
+ fs13.rmSync(targetDir, { recursive: true });
3564
3783
  }
3565
- const tempDir = path9.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
3566
- if (fs11.existsSync(tempDir)) {
3567
- fs11.rmSync(tempDir, { recursive: true });
3784
+ const tempDir = path11.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
3785
+ if (fs13.existsSync(tempDir)) {
3786
+ fs13.rmSync(tempDir, { recursive: true });
3568
3787
  }
3569
- fs11.mkdirSync(tempDir, { recursive: true });
3788
+ fs13.mkdirSync(tempDir, { recursive: true });
3570
3789
  try {
3571
3790
  execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
3572
- const extractedDir = path9.join(tempDir, "package");
3573
- if (fs11.existsSync(extractedDir)) {
3574
- fs11.renameSync(extractedDir, targetDir);
3791
+ const extractedDir = path11.join(tempDir, "package");
3792
+ if (fs13.existsSync(extractedDir)) {
3793
+ fs13.renameSync(extractedDir, targetDir);
3575
3794
  } else {
3576
- const files = fs11.readdirSync(tempDir);
3795
+ const files = fs13.readdirSync(tempDir);
3577
3796
  if (files.length === 1) {
3578
- fs11.renameSync(path9.join(tempDir, files[0]), targetDir);
3797
+ fs13.renameSync(path11.join(tempDir, files[0]), targetDir);
3579
3798
  } else {
3580
3799
  throw new Error("Unexpected tgz structure");
3581
3800
  }
3582
3801
  }
3583
3802
  return targetDir;
3584
3803
  } finally {
3585
- if (fs11.existsSync(tempDir)) {
3586
- fs11.rmSync(tempDir, { recursive: true });
3804
+ if (fs13.existsSync(tempDir)) {
3805
+ fs13.rmSync(tempDir, { recursive: true });
3587
3806
  }
3588
3807
  }
3589
3808
  }
@@ -3592,10 +3811,10 @@ function checkMissingPeerDeps(peerDeps) {
3592
3811
  return [];
3593
3812
  }
3594
3813
  const missing = [];
3595
- const nodeModulesPath = path9.join(getProjectRoot(), "node_modules");
3814
+ const nodeModulesPath = path11.join(getProjectRoot(), "node_modules");
3596
3815
  for (const [depName, _version] of Object.entries(peerDeps)) {
3597
- const depPath = path9.join(nodeModulesPath, depName);
3598
- if (!fs11.existsSync(depPath)) {
3816
+ const depPath = path11.join(nodeModulesPath, depName);
3817
+ if (!fs13.existsSync(depPath)) {
3599
3818
  missing.push(depName);
3600
3819
  }
3601
3820
  }
@@ -3606,7 +3825,7 @@ function installMissingDeps(deps) {
3606
3825
  return;
3607
3826
  }
3608
3827
  console.log(`[action-plugin] Installing missing dependencies: ${deps.join(", ")}`);
3609
- const result = spawnSync4("npm", ["install", ...deps, "--no-save", "--no-package-lock"], {
3828
+ const result = spawnSync6("npm", ["install", ...deps, "--no-save", "--no-package-lock"], {
3610
3829
  cwd: getProjectRoot(),
3611
3830
  stdio: "inherit"
3612
3831
  });
@@ -3619,16 +3838,16 @@ function installMissingDeps(deps) {
3619
3838
  }
3620
3839
  function removePluginDirectory(pluginName) {
3621
3840
  const pluginPath = getPluginPath(pluginName);
3622
- if (fs11.existsSync(pluginPath)) {
3623
- fs11.rmSync(pluginPath, { recursive: true });
3841
+ if (fs13.existsSync(pluginPath)) {
3842
+ fs13.rmSync(pluginPath, { recursive: true });
3624
3843
  console.log(`[action-plugin] Removed ${pluginName}`);
3625
3844
  }
3626
3845
  }
3627
3846
 
3628
3847
  // src/commands/action-plugin/api-client.ts
3629
3848
  import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
3630
- import fs12 from "fs";
3631
- import path10 from "path";
3849
+ import fs14 from "fs";
3850
+ import path12 from "path";
3632
3851
  var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
3633
3852
  async function getPluginVersions(keys, latestOnly = true) {
3634
3853
  const client = getHttpClient();
@@ -3692,19 +3911,19 @@ async function downloadFromPublic(downloadURL) {
3692
3911
  return Buffer.from(arrayBuffer);
3693
3912
  }
3694
3913
  function getPluginCacheDir() {
3695
- return path10.join(process.cwd(), PLUGIN_CACHE_DIR);
3914
+ return path12.join(process.cwd(), PLUGIN_CACHE_DIR);
3696
3915
  }
3697
3916
  function ensureCacheDir() {
3698
3917
  const cacheDir = getPluginCacheDir();
3699
- if (!fs12.existsSync(cacheDir)) {
3700
- fs12.mkdirSync(cacheDir, { recursive: true });
3918
+ if (!fs14.existsSync(cacheDir)) {
3919
+ fs14.mkdirSync(cacheDir, { recursive: true });
3701
3920
  }
3702
3921
  }
3703
3922
  function getTempFilePath(pluginKey, version) {
3704
3923
  ensureCacheDir();
3705
3924
  const safeKey = pluginKey.replace(/[/@]/g, "_");
3706
3925
  const filename = `${safeKey}@${version}.tgz`;
3707
- return path10.join(getPluginCacheDir(), filename);
3926
+ return path12.join(getPluginCacheDir(), filename);
3708
3927
  }
3709
3928
  var MAX_RETRIES = 2;
3710
3929
  async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
@@ -3741,7 +3960,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
3741
3960
  );
3742
3961
  }
3743
3962
  const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
3744
- fs12.writeFileSync(tgzPath, tgzBuffer);
3963
+ fs14.writeFileSync(tgzPath, tgzBuffer);
3745
3964
  console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
3746
3965
  return {
3747
3966
  tgzPath,
@@ -3755,18 +3974,18 @@ function getCachePath(pluginKey, version) {
3755
3974
  ensureCacheDir();
3756
3975
  const safeKey = pluginKey.replace(/[/@]/g, "_");
3757
3976
  const filename = `${safeKey}@${version}.tgz`;
3758
- return path10.join(getPluginCacheDir(), filename);
3977
+ return path12.join(getPluginCacheDir(), filename);
3759
3978
  }
3760
3979
  function hasCachedPlugin(pluginKey, version) {
3761
3980
  const cachePath = getCachePath(pluginKey, version);
3762
- return fs12.existsSync(cachePath);
3981
+ return fs14.existsSync(cachePath);
3763
3982
  }
3764
3983
  function listCachedPlugins() {
3765
3984
  const cacheDir = getPluginCacheDir();
3766
- if (!fs12.existsSync(cacheDir)) {
3985
+ if (!fs14.existsSync(cacheDir)) {
3767
3986
  return [];
3768
3987
  }
3769
- const files = fs12.readdirSync(cacheDir);
3988
+ const files = fs14.readdirSync(cacheDir);
3770
3989
  const result = [];
3771
3990
  for (const file of files) {
3772
3991
  if (!file.endsWith(".tgz")) continue;
@@ -3774,8 +3993,8 @@ function listCachedPlugins() {
3774
3993
  if (!match) continue;
3775
3994
  const [, rawName, version] = match;
3776
3995
  const name = rawName.replace(/^_/, "@").replace(/_/, "/");
3777
- const filePath = path10.join(cacheDir, file);
3778
- const stat = fs12.statSync(filePath);
3996
+ const filePath = path12.join(cacheDir, file);
3997
+ const stat = fs14.statSync(filePath);
3779
3998
  result.push({
3780
3999
  name,
3781
4000
  version,
@@ -3788,14 +4007,14 @@ function listCachedPlugins() {
3788
4007
  }
3789
4008
  function cleanAllCache() {
3790
4009
  const cacheDir = getPluginCacheDir();
3791
- if (!fs12.existsSync(cacheDir)) {
4010
+ if (!fs14.existsSync(cacheDir)) {
3792
4011
  return 0;
3793
4012
  }
3794
- const files = fs12.readdirSync(cacheDir);
4013
+ const files = fs14.readdirSync(cacheDir);
3795
4014
  let count = 0;
3796
4015
  for (const file of files) {
3797
4016
  if (file.endsWith(".tgz")) {
3798
- fs12.unlinkSync(path10.join(cacheDir, file));
4017
+ fs14.unlinkSync(path12.join(cacheDir, file));
3799
4018
  count++;
3800
4019
  }
3801
4020
  }
@@ -3803,21 +4022,21 @@ function cleanAllCache() {
3803
4022
  }
3804
4023
  function cleanPluginCache(pluginKey, version) {
3805
4024
  const cacheDir = getPluginCacheDir();
3806
- if (!fs12.existsSync(cacheDir)) {
4025
+ if (!fs14.existsSync(cacheDir)) {
3807
4026
  return 0;
3808
4027
  }
3809
4028
  const safeKey = pluginKey.replace(/[/@]/g, "_");
3810
- const files = fs12.readdirSync(cacheDir);
4029
+ const files = fs14.readdirSync(cacheDir);
3811
4030
  let count = 0;
3812
4031
  for (const file of files) {
3813
4032
  if (version) {
3814
4033
  if (file === `${safeKey}@${version}.tgz`) {
3815
- fs12.unlinkSync(path10.join(cacheDir, file));
4034
+ fs14.unlinkSync(path12.join(cacheDir, file));
3816
4035
  count++;
3817
4036
  }
3818
4037
  } else {
3819
4038
  if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
3820
- fs12.unlinkSync(path10.join(cacheDir, file));
4039
+ fs14.unlinkSync(path12.join(cacheDir, file));
3821
4040
  count++;
3822
4041
  }
3823
4042
  }
@@ -4244,40 +4463,40 @@ var actionPluginCommandGroup = {
4244
4463
  };
4245
4464
 
4246
4465
  // src/commands/capability/utils.ts
4247
- import fs13 from "fs";
4466
+ import fs15 from "fs";
4248
4467
  import { createRequire as createRequire2 } from "module";
4249
- import path11 from "path";
4468
+ import path13 from "path";
4250
4469
  var CAPABILITIES_DIR = "server/capabilities";
4251
4470
  function getProjectRoot2() {
4252
4471
  return process.cwd();
4253
4472
  }
4254
4473
  function getCapabilitiesDir() {
4255
- return path11.join(getProjectRoot2(), CAPABILITIES_DIR);
4474
+ return path13.join(getProjectRoot2(), CAPABILITIES_DIR);
4256
4475
  }
4257
4476
  function getCapabilityPath(id) {
4258
- return path11.join(getCapabilitiesDir(), `${id}.json`);
4477
+ return path13.join(getCapabilitiesDir(), `${id}.json`);
4259
4478
  }
4260
4479
  function getPluginManifestPath(pluginKey) {
4261
- return path11.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
4480
+ return path13.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
4262
4481
  }
4263
4482
  function capabilitiesDirExists() {
4264
- return fs13.existsSync(getCapabilitiesDir());
4483
+ return fs15.existsSync(getCapabilitiesDir());
4265
4484
  }
4266
4485
  function listCapabilityIds() {
4267
4486
  const dir = getCapabilitiesDir();
4268
- if (!fs13.existsSync(dir)) {
4487
+ if (!fs15.existsSync(dir)) {
4269
4488
  return [];
4270
4489
  }
4271
- const files = fs13.readdirSync(dir);
4490
+ const files = fs15.readdirSync(dir);
4272
4491
  return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
4273
4492
  }
4274
4493
  function readCapability(id) {
4275
4494
  const filePath = getCapabilityPath(id);
4276
- if (!fs13.existsSync(filePath)) {
4495
+ if (!fs15.existsSync(filePath)) {
4277
4496
  throw new Error(`Capability not found: ${id}`);
4278
4497
  }
4279
4498
  try {
4280
- const content = fs13.readFileSync(filePath, "utf-8");
4499
+ const content = fs15.readFileSync(filePath, "utf-8");
4281
4500
  return JSON.parse(content);
4282
4501
  } catch (error) {
4283
4502
  if (error instanceof SyntaxError) {
@@ -4304,11 +4523,11 @@ function readAllCapabilities() {
4304
4523
  }
4305
4524
  function readPluginManifest(pluginKey) {
4306
4525
  const manifestPath = getPluginManifestPath(pluginKey);
4307
- if (!fs13.existsSync(manifestPath)) {
4526
+ if (!fs15.existsSync(manifestPath)) {
4308
4527
  throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
4309
4528
  }
4310
4529
  try {
4311
- const content = fs13.readFileSync(manifestPath, "utf-8");
4530
+ const content = fs15.readFileSync(manifestPath, "utf-8");
4312
4531
  return JSON.parse(content);
4313
4532
  } catch (error) {
4314
4533
  if (error instanceof SyntaxError) {
@@ -4325,7 +4544,7 @@ function hasValidParamsSchema(paramsSchema) {
4325
4544
  }
4326
4545
  async function loadPlugin(pluginKey) {
4327
4546
  try {
4328
- const userRequire = createRequire2(path11.join(getProjectRoot2(), "package.json"));
4547
+ const userRequire = createRequire2(path13.join(getProjectRoot2(), "package.json"));
4329
4548
  const resolvedPath = userRequire.resolve(pluginKey);
4330
4549
  const pluginModule = await import(resolvedPath);
4331
4550
  const pluginPackage = pluginModule.default ?? pluginModule;
@@ -4488,8 +4707,8 @@ var capabilityCommandGroup = {
4488
4707
  import { execFile } from "child_process";
4489
4708
 
4490
4709
  // src/commands/component/registry-preparer.ts
4491
- import fs14 from "fs";
4492
- import path12 from "path";
4710
+ import fs16 from "fs";
4711
+ import path14 from "path";
4493
4712
  import os from "os";
4494
4713
 
4495
4714
  // src/commands/component/service.ts
@@ -4545,7 +4764,7 @@ async function sendInstallEvent(key) {
4545
4764
  }
4546
4765
 
4547
4766
  // src/commands/component/registry-preparer.ts
4548
- var REGISTRY_TEMP_DIR = path12.join(os.tmpdir(), "miaoda-registry");
4767
+ var REGISTRY_TEMP_DIR = path14.join(os.tmpdir(), "miaoda-registry");
4549
4768
  function parseComponentKey(key) {
4550
4769
  const match = key.match(/^@([^/]+)\/(.+)$/);
4551
4770
  if (!match) {
@@ -4557,11 +4776,11 @@ function parseComponentKey(key) {
4557
4776
  }
4558
4777
  function getLocalRegistryPath(key) {
4559
4778
  const { scope, name } = parseComponentKey(key);
4560
- return path12.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
4779
+ return path14.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
4561
4780
  }
4562
4781
  function ensureDir(dirPath) {
4563
- if (!fs14.existsSync(dirPath)) {
4564
- fs14.mkdirSync(dirPath, { recursive: true });
4782
+ if (!fs16.existsSync(dirPath)) {
4783
+ fs16.mkdirSync(dirPath, { recursive: true });
4565
4784
  }
4566
4785
  }
4567
4786
  async function prepareRecursive(key, visited) {
@@ -4594,8 +4813,8 @@ async function prepareRecursive(key, visited) {
4594
4813
  registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
4595
4814
  };
4596
4815
  const localPath = getLocalRegistryPath(key);
4597
- ensureDir(path12.dirname(localPath));
4598
- fs14.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
4816
+ ensureDir(path14.dirname(localPath));
4817
+ fs16.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
4599
4818
  debug("\u4FDD\u5B58\u5230: %s", localPath);
4600
4819
  }
4601
4820
  async function prepareComponentRegistryItems(id) {
@@ -4605,18 +4824,18 @@ async function prepareComponentRegistryItems(id) {
4605
4824
  }
4606
4825
  function cleanupTempDir() {
4607
4826
  try {
4608
- if (fs14.existsSync(REGISTRY_TEMP_DIR)) {
4609
- fs14.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
4827
+ if (fs16.existsSync(REGISTRY_TEMP_DIR)) {
4828
+ fs16.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
4610
4829
  }
4611
4830
  } catch {
4612
4831
  }
4613
4832
  }
4614
4833
  function getDownloadedRegistryItem(itemId) {
4615
4834
  const localPath = getLocalRegistryPath(itemId);
4616
- if (!fs14.existsSync(localPath)) {
4835
+ if (!fs16.existsSync(localPath)) {
4617
4836
  return null;
4618
4837
  }
4619
- const content = fs14.readFileSync(localPath, "utf-8");
4838
+ const content = fs16.readFileSync(localPath, "utf-8");
4620
4839
  return JSON.parse(content);
4621
4840
  }
4622
4841
 
@@ -4784,58 +5003,58 @@ var componentCommandGroup = {
4784
5003
  };
4785
5004
 
4786
5005
  // src/commands/migration/version-manager.ts
4787
- import fs15 from "fs";
4788
- import path13 from "path";
5006
+ import fs17 from "fs";
5007
+ import path15 from "path";
4789
5008
  var PACKAGE_JSON = "package.json";
4790
5009
  var VERSION_FIELD = "migrationVersion";
4791
5010
  function getPackageJsonPath2() {
4792
- return path13.join(process.cwd(), PACKAGE_JSON);
5011
+ return path15.join(process.cwd(), PACKAGE_JSON);
4793
5012
  }
4794
5013
  function getCurrentVersion() {
4795
5014
  const pkgPath = getPackageJsonPath2();
4796
- if (!fs15.existsSync(pkgPath)) {
5015
+ if (!fs17.existsSync(pkgPath)) {
4797
5016
  throw new Error("package.json not found");
4798
5017
  }
4799
- const pkg2 = JSON.parse(fs15.readFileSync(pkgPath, "utf-8"));
5018
+ const pkg2 = JSON.parse(fs17.readFileSync(pkgPath, "utf-8"));
4800
5019
  return pkg2[VERSION_FIELD] ?? 0;
4801
5020
  }
4802
5021
  function setCurrentVersion(version) {
4803
5022
  const pkgPath = getPackageJsonPath2();
4804
- const pkg2 = JSON.parse(fs15.readFileSync(pkgPath, "utf-8"));
5023
+ const pkg2 = JSON.parse(fs17.readFileSync(pkgPath, "utf-8"));
4805
5024
  pkg2[VERSION_FIELD] = version;
4806
- fs15.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
5025
+ fs17.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
4807
5026
  }
4808
5027
 
4809
5028
  // src/commands/migration/versions/v001_capability/json-migrator/detector.ts
4810
- import fs17 from "fs";
4811
- import path15 from "path";
5029
+ import fs19 from "fs";
5030
+ import path17 from "path";
4812
5031
 
4813
5032
  // src/commands/migration/versions/v001_capability/utils.ts
4814
- import fs16 from "fs";
4815
- import path14 from "path";
5033
+ import fs18 from "fs";
5034
+ import path16 from "path";
4816
5035
  var CAPABILITIES_DIR2 = "server/capabilities";
4817
5036
  function getProjectRoot3() {
4818
5037
  return process.cwd();
4819
5038
  }
4820
5039
  function getCapabilitiesDir2() {
4821
- return path14.join(getProjectRoot3(), CAPABILITIES_DIR2);
5040
+ return path16.join(getProjectRoot3(), CAPABILITIES_DIR2);
4822
5041
  }
4823
5042
  function getPluginManifestPath2(pluginKey) {
4824
- return path14.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
5043
+ return path16.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
4825
5044
  }
4826
5045
 
4827
5046
  // src/commands/migration/versions/v001_capability/json-migrator/detector.ts
4828
5047
  function detectJsonMigration() {
4829
5048
  const capabilitiesDir = getCapabilitiesDir2();
4830
- const oldFilePath = path15.join(capabilitiesDir, "capabilities.json");
4831
- if (!fs17.existsSync(oldFilePath)) {
5049
+ const oldFilePath = path17.join(capabilitiesDir, "capabilities.json");
5050
+ if (!fs19.existsSync(oldFilePath)) {
4832
5051
  return {
4833
5052
  needsMigration: false,
4834
5053
  reason: "capabilities.json not found"
4835
5054
  };
4836
5055
  }
4837
5056
  try {
4838
- const content = fs17.readFileSync(oldFilePath, "utf-8");
5057
+ const content = fs19.readFileSync(oldFilePath, "utf-8");
4839
5058
  const parsed = JSON.parse(content);
4840
5059
  if (!Array.isArray(parsed)) {
4841
5060
  return {
@@ -4886,8 +5105,8 @@ async function check(options) {
4886
5105
  }
4887
5106
 
4888
5107
  // src/commands/migration/versions/v001_capability/json-migrator/index.ts
4889
- import fs18 from "fs";
4890
- import path16 from "path";
5108
+ import fs20 from "fs";
5109
+ import path18 from "path";
4891
5110
 
4892
5111
  // src/commands/migration/versions/v001_capability/mapping.ts
4893
5112
  var DEFAULT_PLUGIN_VERSION = "1.0.0";
@@ -5117,18 +5336,18 @@ function transformCapabilities(oldCapabilities) {
5117
5336
  // src/commands/migration/versions/v001_capability/json-migrator/index.ts
5118
5337
  function loadExistingCapabilities() {
5119
5338
  const capabilitiesDir = getCapabilitiesDir2();
5120
- if (!fs18.existsSync(capabilitiesDir)) {
5339
+ if (!fs20.existsSync(capabilitiesDir)) {
5121
5340
  return [];
5122
5341
  }
5123
- const files = fs18.readdirSync(capabilitiesDir);
5342
+ const files = fs20.readdirSync(capabilitiesDir);
5124
5343
  const capabilities = [];
5125
5344
  for (const file of files) {
5126
5345
  if (file === "capabilities.json" || !file.endsWith(".json")) {
5127
5346
  continue;
5128
5347
  }
5129
5348
  try {
5130
- const filePath = path16.join(capabilitiesDir, file);
5131
- const content = fs18.readFileSync(filePath, "utf-8");
5349
+ const filePath = path18.join(capabilitiesDir, file);
5350
+ const content = fs20.readFileSync(filePath, "utf-8");
5132
5351
  const capability = JSON.parse(content);
5133
5352
  if (capability.id && capability.pluginKey) {
5134
5353
  capabilities.push(capability);
@@ -5186,9 +5405,9 @@ async function migrateJsonFiles(options) {
5186
5405
  }
5187
5406
  const capabilitiesDir = getCapabilitiesDir2();
5188
5407
  for (const cap of newCapabilities) {
5189
- const filePath = path16.join(capabilitiesDir, `${cap.id}.json`);
5408
+ const filePath = path18.join(capabilitiesDir, `${cap.id}.json`);
5190
5409
  const content = JSON.stringify(cap, null, 2);
5191
- fs18.writeFileSync(filePath, content, "utf-8");
5410
+ fs20.writeFileSync(filePath, content, "utf-8");
5192
5411
  console.log(` \u2713 Created: ${cap.id}.json`);
5193
5412
  }
5194
5413
  return {
@@ -5200,11 +5419,11 @@ async function migrateJsonFiles(options) {
5200
5419
  }
5201
5420
 
5202
5421
  // src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
5203
- import fs19 from "fs";
5422
+ import fs21 from "fs";
5204
5423
  function isPluginInstalled2(pluginKey) {
5205
5424
  const actionPlugins = readActionPlugins();
5206
5425
  const manifestPath = getPluginManifestPath2(pluginKey);
5207
- return fs19.existsSync(manifestPath) && !!actionPlugins[pluginKey];
5426
+ return fs21.existsSync(manifestPath) && !!actionPlugins[pluginKey];
5208
5427
  }
5209
5428
  function detectPluginsToInstall(capabilities) {
5210
5429
  const pluginKeys = /* @__PURE__ */ new Set();
@@ -5280,12 +5499,12 @@ async function installPlugins(capabilities, options) {
5280
5499
  }
5281
5500
 
5282
5501
  // src/commands/migration/versions/v001_capability/code-migrator/index.ts
5283
- import path18 from "path";
5502
+ import path20 from "path";
5284
5503
  import { Project as Project3 } from "ts-morph";
5285
5504
 
5286
5505
  // src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
5287
- import fs20 from "fs";
5288
- import path17 from "path";
5506
+ import fs22 from "fs";
5507
+ import path19 from "path";
5289
5508
  var EXCLUDED_DIRS = [
5290
5509
  "node_modules",
5291
5510
  "dist",
@@ -5300,9 +5519,9 @@ var EXCLUDED_PATTERNS = [
5300
5519
  /\.d\.ts$/
5301
5520
  ];
5302
5521
  function scanDirectory(dir, files = []) {
5303
- const entries = fs20.readdirSync(dir, { withFileTypes: true });
5522
+ const entries = fs22.readdirSync(dir, { withFileTypes: true });
5304
5523
  for (const entry of entries) {
5305
- const fullPath = path17.join(dir, entry.name);
5524
+ const fullPath = path19.join(dir, entry.name);
5306
5525
  if (entry.isDirectory()) {
5307
5526
  if (EXCLUDED_DIRS.includes(entry.name)) {
5308
5527
  continue;
@@ -5318,14 +5537,14 @@ function scanDirectory(dir, files = []) {
5318
5537
  return files;
5319
5538
  }
5320
5539
  function scanServerFiles() {
5321
- const serverDir = path17.join(getProjectRoot3(), "server");
5322
- if (!fs20.existsSync(serverDir)) {
5540
+ const serverDir = path19.join(getProjectRoot3(), "server");
5541
+ if (!fs22.existsSync(serverDir)) {
5323
5542
  return [];
5324
5543
  }
5325
5544
  return scanDirectory(serverDir);
5326
5545
  }
5327
5546
  function hasCapabilityImport(filePath) {
5328
- const content = fs20.readFileSync(filePath, "utf-8");
5547
+ const content = fs22.readFileSync(filePath, "utf-8");
5329
5548
  return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
5330
5549
  }
5331
5550
  function scanFilesToMigrate() {
@@ -5702,7 +5921,7 @@ function analyzeFile(project, filePath, actionNameMap) {
5702
5921
  const callSites = analyzeCallSites(sourceFile, imports);
5703
5922
  const classInfo = analyzeClass(sourceFile);
5704
5923
  const { canMigrate, reason } = canAutoMigrate(classInfo);
5705
- const relativePath = path18.relative(getProjectRoot3(), filePath);
5924
+ const relativePath = path20.relative(getProjectRoot3(), filePath);
5706
5925
  return {
5707
5926
  filePath: relativePath,
5708
5927
  imports,
@@ -5713,7 +5932,7 @@ function analyzeFile(project, filePath, actionNameMap) {
5713
5932
  };
5714
5933
  }
5715
5934
  function migrateFile(project, analysis, dryRun) {
5716
- const absolutePath = path18.join(getProjectRoot3(), analysis.filePath);
5935
+ const absolutePath = path20.join(getProjectRoot3(), analysis.filePath);
5717
5936
  if (!analysis.canAutoMigrate) {
5718
5937
  return {
5719
5938
  filePath: analysis.filePath,
@@ -5816,17 +6035,17 @@ function getSuggestion(analysis) {
5816
6035
  }
5817
6036
 
5818
6037
  // src/commands/migration/versions/v001_capability/cleanup.ts
5819
- import fs21 from "fs";
5820
- import path19 from "path";
6038
+ import fs23 from "fs";
6039
+ import path21 from "path";
5821
6040
  function cleanupOldFiles(capabilities, dryRun) {
5822
6041
  const deletedFiles = [];
5823
6042
  const errors = [];
5824
6043
  const capabilitiesDir = getCapabilitiesDir2();
5825
- const oldJsonPath = path19.join(capabilitiesDir, "capabilities.json");
5826
- if (fs21.existsSync(oldJsonPath)) {
6044
+ const oldJsonPath = path21.join(capabilitiesDir, "capabilities.json");
6045
+ if (fs23.existsSync(oldJsonPath)) {
5827
6046
  try {
5828
6047
  if (!dryRun) {
5829
- fs21.unlinkSync(oldJsonPath);
6048
+ fs23.unlinkSync(oldJsonPath);
5830
6049
  }
5831
6050
  deletedFiles.push("capabilities.json");
5832
6051
  } catch (error) {
@@ -5834,11 +6053,11 @@ function cleanupOldFiles(capabilities, dryRun) {
5834
6053
  }
5835
6054
  }
5836
6055
  for (const cap of capabilities) {
5837
- const tsFilePath = path19.join(capabilitiesDir, `${cap.id}.ts`);
5838
- if (fs21.existsSync(tsFilePath)) {
6056
+ const tsFilePath = path21.join(capabilitiesDir, `${cap.id}.ts`);
6057
+ if (fs23.existsSync(tsFilePath)) {
5839
6058
  try {
5840
6059
  if (!dryRun) {
5841
- fs21.unlinkSync(tsFilePath);
6060
+ fs23.unlinkSync(tsFilePath);
5842
6061
  }
5843
6062
  deletedFiles.push(`${cap.id}.ts`);
5844
6063
  } catch (error) {
@@ -5854,8 +6073,8 @@ function cleanupOldFiles(capabilities, dryRun) {
5854
6073
  }
5855
6074
 
5856
6075
  // src/commands/migration/versions/v001_capability/report-generator.ts
5857
- import fs22 from "fs";
5858
- import path20 from "path";
6076
+ import fs24 from "fs";
6077
+ import path22 from "path";
5859
6078
  var REPORT_FILE = "capability-migration-report.md";
5860
6079
  function printSummary(result) {
5861
6080
  const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
@@ -6018,15 +6237,15 @@ async function generateReport(result) {
6018
6237
  }
6019
6238
  lines.push("");
6020
6239
  const logDir = process.env.LOG_DIR || "logs";
6021
- if (!fs22.existsSync(logDir)) {
6240
+ if (!fs24.existsSync(logDir)) {
6022
6241
  return;
6023
6242
  }
6024
- const reportDir = path20.join(logDir, "migration");
6025
- if (!fs22.existsSync(reportDir)) {
6026
- fs22.mkdirSync(reportDir, { recursive: true });
6243
+ const reportDir = path22.join(logDir, "migration");
6244
+ if (!fs24.existsSync(reportDir)) {
6245
+ fs24.mkdirSync(reportDir, { recursive: true });
6027
6246
  }
6028
- const reportPath = path20.join(reportDir, REPORT_FILE);
6029
- fs22.writeFileSync(reportPath, lines.join("\n"), "utf-8");
6247
+ const reportPath = path22.join(reportDir, REPORT_FILE);
6248
+ fs24.writeFileSync(reportPath, lines.join("\n"), "utf-8");
6030
6249
  console.log(`\u{1F4C4} Report generated: ${reportPath}`);
6031
6250
  }
6032
6251
 
@@ -6203,7 +6422,7 @@ function buildResult(jsonMigration, pluginInstallation, codeMigration, cleanup)
6203
6422
  }
6204
6423
 
6205
6424
  // src/commands/migration/versions/v001_capability/run.ts
6206
- async function run5(options) {
6425
+ async function run6(options) {
6207
6426
  try {
6208
6427
  const migrationOptions = {
6209
6428
  dryRun: options.dryRun ?? false
@@ -6268,7 +6487,7 @@ var v001CapabilityMigration = {
6268
6487
  name: "capability",
6269
6488
  description: "Migrate capability configurations from old format (capabilities.json array) to new format (individual JSON files)",
6270
6489
  check,
6271
- run: run5
6490
+ run: run6
6272
6491
  };
6273
6492
 
6274
6493
  // src/commands/migration/versions/index.ts
@@ -6558,10 +6777,10 @@ var migrationCommand = {
6558
6777
  };
6559
6778
 
6560
6779
  // src/commands/read-logs/index.ts
6561
- import path21 from "path";
6780
+ import path23 from "path";
6562
6781
 
6563
6782
  // src/commands/read-logs/std-utils.ts
6564
- import fs23 from "fs";
6783
+ import fs25 from "fs";
6565
6784
  function formatStdPrefixTime(localTime) {
6566
6785
  const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
6567
6786
  if (!match) return localTime;
@@ -6591,11 +6810,11 @@ function stripPrefixFromStdLine(line) {
6591
6810
  return `[${time}] ${content}`;
6592
6811
  }
6593
6812
  function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
6594
- const stat = fs23.statSync(filePath);
6813
+ const stat = fs25.statSync(filePath);
6595
6814
  if (stat.size === 0) {
6596
6815
  return { lines: [], markerFound: false, totalLinesCount: 0 };
6597
6816
  }
6598
- const fd = fs23.openSync(filePath, "r");
6817
+ const fd = fs25.openSync(filePath, "r");
6599
6818
  const chunkSize = 64 * 1024;
6600
6819
  let position = stat.size;
6601
6820
  let remainder = "";
@@ -6609,7 +6828,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
6609
6828
  const length = Math.min(chunkSize, position);
6610
6829
  position -= length;
6611
6830
  const buffer = Buffer.alloc(length);
6612
- fs23.readSync(fd, buffer, 0, length, position);
6831
+ fs25.readSync(fd, buffer, 0, length, position);
6613
6832
  let chunk = buffer.toString("utf8");
6614
6833
  if (remainder) {
6615
6834
  chunk += remainder;
@@ -6651,7 +6870,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
6651
6870
  }
6652
6871
  }
6653
6872
  } finally {
6654
- fs23.closeSync(fd);
6873
+ fs25.closeSync(fd);
6655
6874
  }
6656
6875
  return { lines: collected.reverse(), markerFound, totalLinesCount };
6657
6876
  }
@@ -6672,21 +6891,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
6672
6891
  }
6673
6892
 
6674
6893
  // src/commands/read-logs/tail.ts
6675
- import fs24 from "fs";
6894
+ import fs26 from "fs";
6676
6895
  function fileExists(filePath) {
6677
6896
  try {
6678
- fs24.accessSync(filePath, fs24.constants.F_OK | fs24.constants.R_OK);
6897
+ fs26.accessSync(filePath, fs26.constants.F_OK | fs26.constants.R_OK);
6679
6898
  return true;
6680
6899
  } catch {
6681
6900
  return false;
6682
6901
  }
6683
6902
  }
6684
6903
  function readFileTailLines(filePath, maxLines) {
6685
- const stat = fs24.statSync(filePath);
6904
+ const stat = fs26.statSync(filePath);
6686
6905
  if (stat.size === 0) {
6687
6906
  return [];
6688
6907
  }
6689
- const fd = fs24.openSync(filePath, "r");
6908
+ const fd = fs26.openSync(filePath, "r");
6690
6909
  const chunkSize = 64 * 1024;
6691
6910
  const chunks = [];
6692
6911
  let position = stat.size;
@@ -6696,13 +6915,13 @@ function readFileTailLines(filePath, maxLines) {
6696
6915
  const length = Math.min(chunkSize, position);
6697
6916
  position -= length;
6698
6917
  const buffer = Buffer.alloc(length);
6699
- fs24.readSync(fd, buffer, 0, length, position);
6918
+ fs26.readSync(fd, buffer, 0, length, position);
6700
6919
  chunks.unshift(buffer.toString("utf8"));
6701
6920
  const chunkLines = buffer.toString("utf8").split("\n").length - 1;
6702
6921
  collectedLines += chunkLines;
6703
6922
  }
6704
6923
  } finally {
6705
- fs24.closeSync(fd);
6924
+ fs26.closeSync(fd);
6706
6925
  }
6707
6926
  const content = chunks.join("");
6708
6927
  const allLines = content.split("\n");
@@ -6718,11 +6937,11 @@ function readFileTailLines(filePath, maxLines) {
6718
6937
  return allLines.slice(allLines.length - maxLines);
6719
6938
  }
6720
6939
  function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
6721
- const stat = fs24.statSync(filePath);
6940
+ const stat = fs26.statSync(filePath);
6722
6941
  if (stat.size === 0) {
6723
6942
  return { lines: [], totalLinesCount: 0 };
6724
6943
  }
6725
- const fd = fs24.openSync(filePath, "r");
6944
+ const fd = fs26.openSync(filePath, "r");
6726
6945
  const chunkSize = 64 * 1024;
6727
6946
  let position = stat.size;
6728
6947
  let remainder = "";
@@ -6734,7 +6953,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
6734
6953
  const length = Math.min(chunkSize, position);
6735
6954
  position -= length;
6736
6955
  const buffer = Buffer.alloc(length);
6737
- fs24.readSync(fd, buffer, 0, length, position);
6956
+ fs26.readSync(fd, buffer, 0, length, position);
6738
6957
  let chunk = buffer.toString("utf8");
6739
6958
  if (remainder) {
6740
6959
  chunk += remainder;
@@ -6765,7 +6984,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
6765
6984
  }
6766
6985
  }
6767
6986
  } finally {
6768
- fs24.closeSync(fd);
6987
+ fs26.closeSync(fd);
6769
6988
  }
6770
6989
  return { lines: collected.reverse(), totalLinesCount };
6771
6990
  }
@@ -6907,7 +7126,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
6907
7126
  }
6908
7127
 
6909
7128
  // src/commands/read-logs/json-lines.ts
6910
- import fs25 from "fs";
7129
+ import fs27 from "fs";
6911
7130
  function normalizePid(value) {
6912
7131
  if (typeof value === "number") {
6913
7132
  return String(value);
@@ -6958,11 +7177,11 @@ function buildWantedLevelSet(levels) {
6958
7177
  return set.size > 0 ? set : null;
6959
7178
  }
6960
7179
  function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
6961
- const stat = fs25.statSync(filePath);
7180
+ const stat = fs27.statSync(filePath);
6962
7181
  if (stat.size === 0) {
6963
7182
  return { lines: [], totalLinesCount: 0 };
6964
7183
  }
6965
- const fd = fs25.openSync(filePath, "r");
7184
+ const fd = fs27.openSync(filePath, "r");
6966
7185
  const chunkSize = 64 * 1024;
6967
7186
  let position = stat.size;
6968
7187
  let remainder = "";
@@ -6977,7 +7196,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
6977
7196
  const length = Math.min(chunkSize, position);
6978
7197
  position -= length;
6979
7198
  const buffer = Buffer.alloc(length);
6980
- fs25.readSync(fd, buffer, 0, length, position);
7199
+ fs27.readSync(fd, buffer, 0, length, position);
6981
7200
  let chunk = buffer.toString("utf8");
6982
7201
  if (remainder) {
6983
7202
  chunk += remainder;
@@ -7039,7 +7258,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
7039
7258
  }
7040
7259
  }
7041
7260
  } finally {
7042
- fs25.closeSync(fd);
7261
+ fs27.closeSync(fd);
7043
7262
  }
7044
7263
  return { lines: collected.reverse(), totalLinesCount };
7045
7264
  }
@@ -7082,11 +7301,11 @@ function extractTraceId(obj) {
7082
7301
  function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
7083
7302
  const wanted = traceId.trim();
7084
7303
  if (!wanted) return { lines: [], totalLinesCount: 0 };
7085
- const stat = fs25.statSync(filePath);
7304
+ const stat = fs27.statSync(filePath);
7086
7305
  if (stat.size === 0) {
7087
7306
  return { lines: [], totalLinesCount: 0 };
7088
7307
  }
7089
- const fd = fs25.openSync(filePath, "r");
7308
+ const fd = fs27.openSync(filePath, "r");
7090
7309
  const chunkSize = 64 * 1024;
7091
7310
  let position = stat.size;
7092
7311
  let remainder = "";
@@ -7099,7 +7318,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
7099
7318
  const length = Math.min(chunkSize, position);
7100
7319
  position -= length;
7101
7320
  const buffer = Buffer.alloc(length);
7102
- fs25.readSync(fd, buffer, 0, length, position);
7321
+ fs27.readSync(fd, buffer, 0, length, position);
7103
7322
  let chunk = buffer.toString("utf8");
7104
7323
  if (remainder) {
7105
7324
  chunk += remainder;
@@ -7152,7 +7371,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
7152
7371
  }
7153
7372
  }
7154
7373
  } finally {
7155
- fs25.closeSync(fd);
7374
+ fs27.closeSync(fd);
7156
7375
  }
7157
7376
  return { lines: collected.reverse(), totalLinesCount };
7158
7377
  }
@@ -7161,11 +7380,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
7161
7380
  if (!wantedLevelSet) {
7162
7381
  return { lines: [], totalLinesCount: 0 };
7163
7382
  }
7164
- const stat = fs25.statSync(filePath);
7383
+ const stat = fs27.statSync(filePath);
7165
7384
  if (stat.size === 0) {
7166
7385
  return { lines: [], totalLinesCount: 0 };
7167
7386
  }
7168
- const fd = fs25.openSync(filePath, "r");
7387
+ const fd = fs27.openSync(filePath, "r");
7169
7388
  const chunkSize = 64 * 1024;
7170
7389
  let position = stat.size;
7171
7390
  let remainder = "";
@@ -7177,7 +7396,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
7177
7396
  const length = Math.min(chunkSize, position);
7178
7397
  position -= length;
7179
7398
  const buffer = Buffer.alloc(length);
7180
- fs25.readSync(fd, buffer, 0, length, position);
7399
+ fs27.readSync(fd, buffer, 0, length, position);
7181
7400
  let chunk = buffer.toString("utf8");
7182
7401
  if (remainder) {
7183
7402
  chunk += remainder;
@@ -7224,7 +7443,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
7224
7443
  }
7225
7444
  }
7226
7445
  } finally {
7227
- fs25.closeSync(fd);
7446
+ fs27.closeSync(fd);
7228
7447
  }
7229
7448
  return { lines: collected.reverse(), totalLinesCount };
7230
7449
  }
@@ -7458,34 +7677,34 @@ async function readLogsJsonResult(options) {
7458
7677
  };
7459
7678
  }
7460
7679
  function resolveLogFilePath(logDir, type) {
7461
- const base = path21.isAbsolute(logDir) ? logDir : path21.join(process.cwd(), logDir);
7680
+ const base = path23.isAbsolute(logDir) ? logDir : path23.join(process.cwd(), logDir);
7462
7681
  if (type === "server") {
7463
- return path21.join(base, "server.log");
7682
+ return path23.join(base, "server.log");
7464
7683
  }
7465
7684
  if (type === "trace") {
7466
- return path21.join(base, "trace.log");
7685
+ return path23.join(base, "trace.log");
7467
7686
  }
7468
7687
  if (type === "server-std") {
7469
- return path21.join(base, "server.std.log");
7688
+ return path23.join(base, "server.std.log");
7470
7689
  }
7471
7690
  if (type === "client-std") {
7472
- return path21.join(base, "client.std.log");
7691
+ return path23.join(base, "client.std.log");
7473
7692
  }
7474
7693
  if (type === "dev") {
7475
- return path21.join(base, "dev.log");
7694
+ return path23.join(base, "dev.log");
7476
7695
  }
7477
7696
  if (type === "dev-std") {
7478
- return path21.join(base, "dev.std.log");
7697
+ return path23.join(base, "dev.std.log");
7479
7698
  }
7480
7699
  if (type === "install-dep-std") {
7481
- return path21.join(base, "install-dep.std.log");
7700
+ return path23.join(base, "install-dep.std.log");
7482
7701
  }
7483
7702
  if (type === "browser") {
7484
- return path21.join(base, "browser.log");
7703
+ return path23.join(base, "browser.log");
7485
7704
  }
7486
7705
  throw new Error(`Unsupported log type: ${type}`);
7487
7706
  }
7488
- async function run6(options) {
7707
+ async function run7(options) {
7489
7708
  const result = await readLogsJsonResult(options);
7490
7709
  process.stdout.write(JSON.stringify(result) + "\n");
7491
7710
  }
@@ -7527,7 +7746,7 @@ var readLogsCommand = {
7527
7746
  const offset = parseNonNegativeInt(rawOptions.offset, "--offset");
7528
7747
  const traceId = typeof rawOptions.traceId === "string" ? rawOptions.traceId : void 0;
7529
7748
  const levels = parseCommaSeparatedList(rawOptions.level);
7530
- await run6({ logDir, type, maxLines, offset, traceId, levels });
7749
+ await run7({ logDir, type, maxLines, offset, traceId, levels });
7531
7750
  } catch (error) {
7532
7751
  const message = error instanceof Error ? error.message : String(error);
7533
7752
  process.stderr.write(message + "\n");
@@ -7658,9 +7877,9 @@ function camelToKebab(str) {
7658
7877
  }
7659
7878
 
7660
7879
  // src/commands/build/upload-static.handler.ts
7661
- import * as fs26 from "fs";
7880
+ import * as fs28 from "fs";
7662
7881
  import * as os2 from "os";
7663
- import * as path22 from "path";
7882
+ import * as path24 from "path";
7664
7883
  import { execFileSync } from "child_process";
7665
7884
  function readCredentialsFromEnv() {
7666
7885
  const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
@@ -7684,8 +7903,8 @@ async function uploadStatic(options) {
7684
7903
  endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
7685
7904
  region = UPLOAD_STATIC_DEFAULTS.region
7686
7905
  } = options;
7687
- const resolvedStaticDir = path22.resolve(staticDir);
7688
- if (!fs26.existsSync(resolvedStaticDir)) {
7906
+ const resolvedStaticDir = path24.resolve(staticDir);
7907
+ if (!fs28.existsSync(resolvedStaticDir)) {
7689
7908
  console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
7690
7909
  return;
7691
7910
  }
@@ -7718,8 +7937,8 @@ async function uploadStatic(options) {
7718
7937
  ({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
7719
7938
  }
7720
7939
  console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
7721
- const confPath = path22.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
7722
- fs26.writeFileSync(confPath, "");
7940
+ const confPath = path24.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
7941
+ fs28.writeFileSync(confPath, "");
7723
7942
  try {
7724
7943
  console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
7725
7944
  configureTosutil(resolvedTosutil, confPath, {
@@ -7733,7 +7952,7 @@ async function uploadStatic(options) {
7733
7952
  uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
7734
7953
  } finally {
7735
7954
  try {
7736
- fs26.unlinkSync(confPath);
7955
+ fs28.unlinkSync(confPath);
7737
7956
  } catch {
7738
7957
  }
7739
7958
  }
@@ -7753,8 +7972,8 @@ async function uploadStatic(options) {
7753
7972
  }
7754
7973
  }
7755
7974
  function resolveTosutilPath(tosutilPath) {
7756
- if (path22.isAbsolute(tosutilPath)) {
7757
- return fs26.existsSync(tosutilPath) ? tosutilPath : null;
7975
+ if (path24.isAbsolute(tosutilPath)) {
7976
+ return fs28.existsSync(tosutilPath) ? tosutilPath : null;
7758
7977
  }
7759
7978
  try {
7760
7979
  const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
@@ -7799,7 +8018,7 @@ async function resolveBucketId(appId) {
7799
8018
  return bucketId;
7800
8019
  }
7801
8020
  function isDirEmpty(dirPath) {
7802
- const entries = fs26.readdirSync(dirPath);
8021
+ const entries = fs28.readdirSync(dirPath);
7803
8022
  return entries.length === 0;
7804
8023
  }
7805
8024
 
@@ -7894,12 +8113,12 @@ var commands = [
7894
8113
  ];
7895
8114
 
7896
8115
  // src/index.ts
7897
- var envPath = path23.join(process.cwd(), ".env");
7898
- if (fs27.existsSync(envPath)) {
8116
+ var envPath = path25.join(process.cwd(), ".env");
8117
+ if (fs29.existsSync(envPath)) {
7899
8118
  dotenvConfig({ path: envPath });
7900
8119
  }
7901
- var __dirname = path23.dirname(fileURLToPath5(import.meta.url));
7902
- var pkg = JSON.parse(fs27.readFileSync(path23.join(__dirname, "../package.json"), "utf-8"));
8120
+ var __dirname = path25.dirname(fileURLToPath5(import.meta.url));
8121
+ var pkg = JSON.parse(fs29.readFileSync(path25.join(__dirname, "../package.json"), "utf-8"));
7903
8122
  var cli = new FullstackCLI(pkg.version);
7904
8123
  cli.useAll(commands);
7905
8124
  cli.run();