@lark-apaas/fullstack-cli 1.1.16-beta.3 → 1.1.16-beta.4

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 (3) hide show
  1. package/README.md +41 -3
  2. package/dist/index.js +713 -217
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/index.ts
2
- import fs22 from "fs";
3
- import path18 from "path";
4
- import { fileURLToPath as fileURLToPath4 } from "url";
2
+ import fs25 from "fs";
3
+ import path21 from "path";
4
+ import { fileURLToPath as fileURLToPath5 } from "url";
5
5
  import { config as dotenvConfig } from "dotenv";
6
6
 
7
7
  // src/cli.ts
@@ -481,6 +481,7 @@ var replaceUnknownTransform = {
481
481
  transform(ctx) {
482
482
  const { sourceFile, stats } = ctx;
483
483
  const fullText = sourceFile.getFullText();
484
+ const replacements = [];
484
485
  sourceFile.forEachDescendant((node) => {
485
486
  if (!Node5.isCallExpression(node)) {
486
487
  return;
@@ -511,13 +512,23 @@ var replaceUnknownTransform = {
511
512
  break;
512
513
  }
513
514
  }
515
+ replacements.push({
516
+ expression,
517
+ factoryName,
518
+ foundKnownType,
519
+ isArrayType,
520
+ node
521
+ });
522
+ });
523
+ for (const { expression, factoryName, foundKnownType, isArrayType, node } of replacements) {
514
524
  expression.replaceWithText(factoryName);
515
525
  if (isArrayType && foundKnownType) {
516
526
  const parent = node.getParent();
517
527
  if (Node5.isPropertyAccessExpression(parent) && parent.getName() === "array") {
518
528
  const grandParent = parent.getParent();
519
529
  if (Node5.isCallExpression(grandParent)) {
520
- grandParent.replaceWithText(node.getText());
530
+ const nodeText = node.getText();
531
+ grandParent.replaceWithText(nodeText);
521
532
  }
522
533
  }
523
534
  }
@@ -526,7 +537,7 @@ var replaceUnknownTransform = {
526
537
  } else {
527
538
  stats.fallbackToText++;
528
539
  }
529
- });
540
+ }
530
541
  const todoCommentRegex = /\/\/ TODO: failed to parse database type '[^']+'\s*\n/g;
531
542
  const currentText = sourceFile.getFullText();
532
543
  const cleanedText = currentText.replace(todoCommentRegex, "");
@@ -2408,10 +2419,420 @@ var syncCommand = {
2408
2419
  }
2409
2420
  };
2410
2421
 
2411
- // src/commands/action-plugin/utils.ts
2422
+ // src/utils/http-client.ts
2423
+ import { HttpClient } from "@lark-apaas/http-client";
2424
+ var clientInstance = null;
2425
+ function getHttpClient() {
2426
+ if (!clientInstance) {
2427
+ clientInstance = new HttpClient({
2428
+ timeout: 3e4,
2429
+ platform: {
2430
+ enabled: true
2431
+ }
2432
+ });
2433
+ const canaryEnv = process.env.FORCE_FRAMEWORK_CLI_CANARY_ENV;
2434
+ if (canaryEnv) {
2435
+ clientInstance.interceptors.request.use((req) => {
2436
+ req.headers["x-tt-env"] = canaryEnv;
2437
+ return req;
2438
+ });
2439
+ }
2440
+ }
2441
+ return clientInstance;
2442
+ }
2443
+
2444
+ // src/utils/telemetry.ts
2445
+ async function reportEvents(events) {
2446
+ if (events.length === 0) {
2447
+ return true;
2448
+ }
2449
+ try {
2450
+ const client = getHttpClient();
2451
+ const response = await client.post("/api/v1/studio/innerapi/resource_events", { events });
2452
+ if (!response.ok) {
2453
+ console.warn(`[telemetry] Failed to report events: ${response.status} ${response.statusText}`);
2454
+ return false;
2455
+ }
2456
+ const result = await response.json();
2457
+ if (result.status_code !== "0") {
2458
+ console.warn(`[telemetry] API error: ${result.message}`);
2459
+ return false;
2460
+ }
2461
+ return true;
2462
+ } catch (error) {
2463
+ console.warn(`[telemetry] Failed to report events: ${error instanceof Error ? error.message : error}`);
2464
+ return false;
2465
+ }
2466
+ }
2467
+ async function reportInstallEvent(pluginKey, version) {
2468
+ await reportEvents([
2469
+ {
2470
+ resourceType: "plugin",
2471
+ resourceKey: pluginKey,
2472
+ eventType: "install",
2473
+ details: { version }
2474
+ }
2475
+ ]);
2476
+ }
2477
+ async function reportCreateInstanceEvent(pluginKey, version) {
2478
+ await reportEvents([
2479
+ {
2480
+ resourceType: "plugin",
2481
+ resourceKey: pluginKey,
2482
+ eventType: "create_instance",
2483
+ details: { version }
2484
+ }
2485
+ ]);
2486
+ }
2487
+
2488
+ // src/utils/git.ts
2489
+ import { execSync, spawnSync as spawnSync2 } from "child_process";
2412
2490
  import fs7 from "fs";
2413
2491
  import path5 from "path";
2414
- import { spawnSync as spawnSync2, execSync } from "child_process";
2492
+ function isGitRepository(cwd = process.cwd()) {
2493
+ try {
2494
+ const gitDir = path5.join(cwd, ".git");
2495
+ if (fs7.existsSync(gitDir)) {
2496
+ return true;
2497
+ }
2498
+ const result = spawnSync2("git", ["rev-parse", "--git-dir"], {
2499
+ cwd,
2500
+ stdio: "pipe",
2501
+ encoding: "utf-8"
2502
+ });
2503
+ return result.status === 0;
2504
+ } catch {
2505
+ return false;
2506
+ }
2507
+ }
2508
+ function getChangedFiles(cwd = process.cwd()) {
2509
+ try {
2510
+ const output = execSync("git status --porcelain", {
2511
+ cwd,
2512
+ stdio: "pipe",
2513
+ encoding: "utf-8"
2514
+ });
2515
+ return output.split("\n").filter((line) => line.trim()).map((line) => line.substring(3));
2516
+ } catch (error) {
2517
+ const message = error instanceof Error ? error.message : String(error);
2518
+ throw new Error(`Failed to get changed files: ${message}`);
2519
+ }
2520
+ }
2521
+ function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
2522
+ const filteredFiles = [];
2523
+ for (const filePath of filesToStage) {
2524
+ if (fs7.existsSync(path5.join(cwd, filePath))) {
2525
+ filteredFiles.push(filePath);
2526
+ continue;
2527
+ }
2528
+ const tracked = spawnSync2("git", ["ls-files", "--error-unmatch", "--", filePath], {
2529
+ cwd,
2530
+ stdio: "pipe",
2531
+ encoding: "utf-8"
2532
+ });
2533
+ if (tracked.status === 0) {
2534
+ filteredFiles.push(filePath);
2535
+ }
2536
+ }
2537
+ if (filteredFiles.length === 0) {
2538
+ return;
2539
+ }
2540
+ const result = spawnSync2("git", ["add", "--", ...filteredFiles], {
2541
+ cwd,
2542
+ stdio: "pipe",
2543
+ encoding: "utf-8"
2544
+ });
2545
+ if (result.error || result.status !== 0) {
2546
+ const errorMsg = result.stderr || result.error?.message || "Unknown error";
2547
+ throw new Error(`git add failed: ${errorMsg}`);
2548
+ }
2549
+ }
2550
+ function hasStagedChanges(cwd = process.cwd()) {
2551
+ const result = spawnSync2("git", ["diff", "--cached", "--quiet"], {
2552
+ cwd,
2553
+ stdio: "pipe",
2554
+ encoding: "utf-8"
2555
+ });
2556
+ if (result.status === 0) {
2557
+ return false;
2558
+ }
2559
+ if (result.status === 1) {
2560
+ return true;
2561
+ }
2562
+ const errorMsg = result.stderr || result.error?.message || "Unknown error";
2563
+ throw new Error(`Failed to check staged changes: ${errorMsg}`);
2564
+ }
2565
+ function gitCommit(message, cwd = process.cwd()) {
2566
+ const result = spawnSync2("git", ["commit", "-m", message], {
2567
+ cwd,
2568
+ stdio: "pipe",
2569
+ encoding: "utf-8"
2570
+ });
2571
+ if (result.error || result.status !== 0) {
2572
+ const errorMsg = result.stderr || result.error?.message || "Unknown error";
2573
+ throw new Error(`git commit failed: ${errorMsg}`);
2574
+ }
2575
+ }
2576
+ function autoCommitUpgradeChanges(version, cwd, filesToStage, commitMessage) {
2577
+ if (!isGitRepository(cwd)) {
2578
+ console.log("[fullstack-cli] \u26A0 Not a git repository, skipping auto-commit");
2579
+ return false;
2580
+ }
2581
+ const changedFiles = getChangedFiles(cwd);
2582
+ if (changedFiles.length === 0) {
2583
+ console.log("[fullstack-cli] No changes to commit");
2584
+ return false;
2585
+ }
2586
+ try {
2587
+ gitAddUpgradeFiles(cwd, filesToStage);
2588
+ if (!hasStagedChanges(cwd)) {
2589
+ console.log("[fullstack-cli] No upgrade changes to commit");
2590
+ return false;
2591
+ }
2592
+ const message = commitMessage || `chore(upgrade): auto-upgrade by fullstack-cli
2593
+
2594
+ - Sync template files
2595
+ - Cleanup package.json config
2596
+ - Upgrade @lark-apaas dependencies (if any)
2597
+
2598
+ Auto-committed by fullstack-cli v${version}`;
2599
+ gitCommit(message, cwd);
2600
+ console.log(`[fullstack-cli] \u2713 Auto-committed ${changedFiles.length} changed file(s)`);
2601
+ return true;
2602
+ } catch (error) {
2603
+ const message = error instanceof Error ? error.message : String(error);
2604
+ throw new Error(`Failed to auto-commit changes: ${message}`);
2605
+ }
2606
+ }
2607
+
2608
+ // src/utils/package-json.ts
2609
+ import fs8 from "fs";
2610
+ import path6 from "path";
2611
+ function readPackageJson(cwd = process.cwd()) {
2612
+ const pkgPath = path6.join(cwd, "package.json");
2613
+ if (!fs8.existsSync(pkgPath)) {
2614
+ throw new Error(`package.json not found at ${pkgPath}`);
2615
+ }
2616
+ const content = fs8.readFileSync(pkgPath, "utf-8");
2617
+ return JSON.parse(content);
2618
+ }
2619
+ function writePackageJson(pkg2, cwd = process.cwd()) {
2620
+ const pkgPath = path6.join(cwd, "package.json");
2621
+ const content = JSON.stringify(pkg2, null, 2) + "\n";
2622
+ fs8.writeFileSync(pkgPath, content, "utf-8");
2623
+ }
2624
+ function removeUpgradeScript(pkg2) {
2625
+ if (!pkg2.scripts?.upgrade) {
2626
+ return false;
2627
+ }
2628
+ delete pkg2.scripts.upgrade;
2629
+ return true;
2630
+ }
2631
+ function cleanDevScript(pkg2) {
2632
+ if (!pkg2.scripts?.dev) {
2633
+ return false;
2634
+ }
2635
+ const originalDev = pkg2.scripts.dev;
2636
+ const cleanedDev = originalDev.replace(/npm\s+run\s+upgrade\s*&&\s*/g, "").replace(/npm\s+run\s+upgrade\s*$/g, "").trim();
2637
+ if (cleanedDev !== originalDev) {
2638
+ pkg2.scripts.dev = cleanedDev;
2639
+ return true;
2640
+ }
2641
+ return false;
2642
+ }
2643
+ function cleanupPackageJson(cwd = process.cwd()) {
2644
+ try {
2645
+ const pkg2 = readPackageJson(cwd);
2646
+ let changed = false;
2647
+ if (removeUpgradeScript(pkg2)) {
2648
+ console.log("[fullstack-cli] \u2713 Removed scripts.upgrade");
2649
+ changed = true;
2650
+ }
2651
+ if (cleanDevScript(pkg2)) {
2652
+ console.log("[fullstack-cli] \u2713 Cleaned scripts.dev (removed npm run upgrade)");
2653
+ changed = true;
2654
+ }
2655
+ if (changed) {
2656
+ writePackageJson(pkg2, cwd);
2657
+ }
2658
+ return changed;
2659
+ } catch (error) {
2660
+ const message = error instanceof Error ? error.message : String(error);
2661
+ console.log(`[fullstack-cli] \u26A0 Could not cleanup package.json: ${message}`);
2662
+ return false;
2663
+ }
2664
+ }
2665
+
2666
+ // src/commands/upgrade/shared/utils.ts
2667
+ import path7 from "path";
2668
+ import fs9 from "fs";
2669
+ import { fileURLToPath as fileURLToPath4 } from "url";
2670
+ function getCliVersion() {
2671
+ try {
2672
+ const __filename = fileURLToPath4(import.meta.url);
2673
+ const __dirname2 = path7.dirname(__filename);
2674
+ const pkgPath = path7.resolve(__dirname2, "../../../package.json");
2675
+ const pkgContent = fs9.readFileSync(pkgPath, "utf-8");
2676
+ const pkg2 = JSON.parse(pkgContent);
2677
+ return pkg2.version || "unknown";
2678
+ } catch {
2679
+ return "unknown";
2680
+ }
2681
+ }
2682
+
2683
+ // src/commands/upgrade/get-upgrade-files.ts
2684
+ function getUpgradeFilesToStage(disableGenOpenapi = true) {
2685
+ const syncConfig2 = genSyncConfig({ disableGenOpenapi });
2686
+ const filesToStage = /* @__PURE__ */ new Set();
2687
+ syncConfig2.sync.forEach((rule) => {
2688
+ if (rule.type === "file" || rule.type === "directory") {
2689
+ filesToStage.add(rule.to);
2690
+ } else if (rule.type === "remove-line" || rule.type === "add-line") {
2691
+ filesToStage.add(rule.to);
2692
+ } else if (rule.type === "add-script") {
2693
+ filesToStage.add("package.json");
2694
+ } else if (rule.type === "delete-file" || rule.type === "delete-directory") {
2695
+ filesToStage.add(rule.to);
2696
+ }
2697
+ });
2698
+ filesToStage.add("package.json");
2699
+ filesToStage.add("package-lock.json");
2700
+ return Array.from(filesToStage);
2701
+ }
2702
+
2703
+ // src/commands/upgrade/run.handler.ts
2704
+ async function run3(options = {}) {
2705
+ const userProjectRoot = process.env.INIT_CWD || process.cwd();
2706
+ console.log("[fullstack-cli] Starting upgrade...");
2707
+ try {
2708
+ console.log("[fullstack-cli] Step 1/3: Syncing template files...");
2709
+ await run2({ disableGenOpenapi: options.disableGenOpenapi ?? true });
2710
+ console.log("[fullstack-cli] Step 2/3: Cleaning up package.json...");
2711
+ const cleaned = cleanupPackageJson(userProjectRoot);
2712
+ if (!cleaned) {
2713
+ console.log("[fullstack-cli] \u25CB No cleanup needed");
2714
+ }
2715
+ const shouldCommit = options.commit ?? true;
2716
+ if (shouldCommit) {
2717
+ console.log("[fullstack-cli] Step 3/3: Committing changes...");
2718
+ const version = getCliVersion();
2719
+ const filesToStage = getUpgradeFilesToStage(options.disableGenOpenapi ?? true);
2720
+ autoCommitUpgradeChanges(version, userProjectRoot, filesToStage);
2721
+ } else {
2722
+ console.log("[fullstack-cli] Step 3/3: Skipping commit (--no-commit flag)");
2723
+ }
2724
+ console.log("[fullstack-cli] Upgrade completed successfully \u2705");
2725
+ } catch (error) {
2726
+ const message = error instanceof Error ? error.message : String(error);
2727
+ console.error("[fullstack-cli] Failed to upgrade:", message);
2728
+ process.exit(1);
2729
+ }
2730
+ }
2731
+
2732
+ // src/commands/upgrade/deps/run.handler.ts
2733
+ import { spawnSync as spawnSync3 } from "child_process";
2734
+ function findLarkAapaasPackages(cwd, filterPackages) {
2735
+ const pkg2 = readPackageJson(cwd);
2736
+ const allPackages = /* @__PURE__ */ new Set();
2737
+ if (pkg2.dependencies) {
2738
+ Object.keys(pkg2.dependencies).forEach((name) => {
2739
+ if (name.startsWith("@lark-apaas/")) {
2740
+ allPackages.add(name);
2741
+ }
2742
+ });
2743
+ }
2744
+ if (pkg2.devDependencies) {
2745
+ Object.keys(pkg2.devDependencies).forEach((name) => {
2746
+ if (name.startsWith("@lark-apaas/")) {
2747
+ allPackages.add(name);
2748
+ }
2749
+ });
2750
+ }
2751
+ const packages = Array.from(allPackages);
2752
+ if (filterPackages) {
2753
+ const filter = new Set(filterPackages.split(",").map((p) => p.trim()));
2754
+ return packages.filter((p) => filter.has(p));
2755
+ }
2756
+ return packages;
2757
+ }
2758
+ function upgradePackages(packages, version, cwd) {
2759
+ if (version) {
2760
+ console.log(`[fullstack-cli] Upgrading to version ${version}...`);
2761
+ packages.forEach((pkg2) => {
2762
+ const target = `${pkg2}@${version}`;
2763
+ console.log(`[fullstack-cli] Installing ${target}...`);
2764
+ const result = spawnSync3("npm", ["install", target], {
2765
+ cwd,
2766
+ stdio: "inherit"
2767
+ });
2768
+ if (result.error || result.status !== 0) {
2769
+ throw new Error(`Failed to install ${target}`);
2770
+ }
2771
+ });
2772
+ } else {
2773
+ console.log("[fullstack-cli] Upgrading to latest compatible versions...");
2774
+ packages.forEach((pkg2) => {
2775
+ console.log(`[fullstack-cli] Updating ${pkg2}...`);
2776
+ const result = spawnSync3("npm", ["update", pkg2], {
2777
+ cwd,
2778
+ stdio: "inherit"
2779
+ });
2780
+ if (result.error || result.status !== 0) {
2781
+ throw new Error(`Failed to update ${pkg2}`);
2782
+ }
2783
+ });
2784
+ }
2785
+ }
2786
+ async function run4(options = {}) {
2787
+ const cwd = process.env.INIT_CWD || process.cwd();
2788
+ console.log("[fullstack-cli] Starting dependencies upgrade...");
2789
+ try {
2790
+ console.log("[fullstack-cli] Step 1/2: Scanning @lark-apaas dependencies...");
2791
+ const packages = findLarkAapaasPackages(cwd, options.packages);
2792
+ if (packages.length === 0) {
2793
+ console.log("[fullstack-cli] No @lark-apaas packages found");
2794
+ return;
2795
+ }
2796
+ console.log(`[fullstack-cli] Found ${packages.length} @lark-apaas package(s):`);
2797
+ packages.forEach((p) => console.log(` - ${p}`));
2798
+ console.log("[fullstack-cli] Step 2/2: Upgrading packages...");
2799
+ upgradePackages(packages, options.version, cwd);
2800
+ console.log(`[fullstack-cli] \u2713 Successfully upgraded ${packages.length} package(s)`);
2801
+ console.log("[fullstack-cli] Dependencies upgrade completed successfully \u2705");
2802
+ } catch (error) {
2803
+ const message = error instanceof Error ? error.message : String(error);
2804
+ console.error("[fullstack-cli] Failed to upgrade dependencies:", message);
2805
+ process.exit(1);
2806
+ }
2807
+ }
2808
+
2809
+ // src/commands/upgrade/deps/index.ts
2810
+ var depsCommand = {
2811
+ name: "deps",
2812
+ description: "Upgrade @lark-apaas dependencies",
2813
+ register(parentCommand) {
2814
+ parentCommand.command(this.name).description(this.description).option("--version <version>", "Upgrade to specific version").option("--packages <packages>", "Only upgrade specific packages (comma-separated)").action(async (options) => {
2815
+ await run4(options);
2816
+ });
2817
+ }
2818
+ };
2819
+
2820
+ // src/commands/upgrade/index.ts
2821
+ var upgradeCommand = {
2822
+ name: "upgrade",
2823
+ description: "Upgrade template files and auto-commit changes",
2824
+ register(program) {
2825
+ const upgradeCmd = program.command(this.name).description(this.description).option("--disable-gen-openapi", "Disable generating openapi.ts").option("--no-commit", "Skip auto-commit changes").action(async (options) => {
2826
+ await run3(options);
2827
+ });
2828
+ depsCommand.register(upgradeCmd);
2829
+ }
2830
+ };
2831
+
2832
+ // src/commands/action-plugin/utils.ts
2833
+ import fs10 from "fs";
2834
+ import path8 from "path";
2835
+ import { spawnSync as spawnSync4, execSync as execSync2 } from "child_process";
2415
2836
  function parsePluginName(input) {
2416
2837
  const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
2417
2838
  if (!match) {
@@ -2428,35 +2849,35 @@ function getProjectRoot() {
2428
2849
  return process.cwd();
2429
2850
  }
2430
2851
  function getPackageJsonPath() {
2431
- return path5.join(getProjectRoot(), "package.json");
2852
+ return path8.join(getProjectRoot(), "package.json");
2432
2853
  }
2433
2854
  function getPluginPath(pluginName) {
2434
- return path5.join(getProjectRoot(), "node_modules", pluginName);
2855
+ return path8.join(getProjectRoot(), "node_modules", pluginName);
2435
2856
  }
2436
- function readPackageJson() {
2857
+ function readPackageJson2() {
2437
2858
  const pkgPath = getPackageJsonPath();
2438
- if (!fs7.existsSync(pkgPath)) {
2859
+ if (!fs10.existsSync(pkgPath)) {
2439
2860
  throw new Error("package.json not found in current directory");
2440
2861
  }
2441
2862
  try {
2442
- const content = fs7.readFileSync(pkgPath, "utf-8");
2863
+ const content = fs10.readFileSync(pkgPath, "utf-8");
2443
2864
  return JSON.parse(content);
2444
2865
  } catch {
2445
2866
  throw new Error("Failed to parse package.json");
2446
2867
  }
2447
2868
  }
2448
- function writePackageJson(pkg2) {
2869
+ function writePackageJson2(pkg2) {
2449
2870
  const pkgPath = getPackageJsonPath();
2450
- fs7.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
2871
+ fs10.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
2451
2872
  }
2452
2873
  function readActionPlugins() {
2453
- const pkg2 = readPackageJson();
2874
+ const pkg2 = readPackageJson2();
2454
2875
  return pkg2.actionPlugins || {};
2455
2876
  }
2456
2877
  function writeActionPlugins(plugins) {
2457
- const pkg2 = readPackageJson();
2878
+ const pkg2 = readPackageJson2();
2458
2879
  pkg2.actionPlugins = plugins;
2459
- writePackageJson(pkg2);
2880
+ writePackageJson2(pkg2);
2460
2881
  }
2461
2882
  function isPluginInstalled(pluginName) {
2462
2883
  const plugins = readActionPlugins();
@@ -2468,7 +2889,7 @@ function getInstalledPluginVersion(pluginName) {
2468
2889
  }
2469
2890
  function npmInstall(tgzPath) {
2470
2891
  console.log(`[action-plugin] Running npm install ${tgzPath}...`);
2471
- const result = spawnSync2("npm", ["install", tgzPath, "--no-save", "--no-package-lock", "--ignore-scripts"], {
2892
+ const result = spawnSync4("npm", ["install", tgzPath, "--no-save", "--no-package-lock", "--ignore-scripts"], {
2472
2893
  cwd: getProjectRoot(),
2473
2894
  stdio: "inherit"
2474
2895
  });
@@ -2480,12 +2901,12 @@ function npmInstall(tgzPath) {
2480
2901
  }
2481
2902
  }
2482
2903
  function getPackageVersion(pluginName) {
2483
- const pkgJsonPath = path5.join(getPluginPath(pluginName), "package.json");
2484
- if (!fs7.existsSync(pkgJsonPath)) {
2904
+ const pkgJsonPath = path8.join(getPluginPath(pluginName), "package.json");
2905
+ if (!fs10.existsSync(pkgJsonPath)) {
2485
2906
  return null;
2486
2907
  }
2487
2908
  try {
2488
- const content = fs7.readFileSync(pkgJsonPath, "utf-8");
2909
+ const content = fs10.readFileSync(pkgJsonPath, "utf-8");
2489
2910
  const pkg2 = JSON.parse(content);
2490
2911
  return pkg2.version || null;
2491
2912
  } catch {
@@ -2493,49 +2914,49 @@ function getPackageVersion(pluginName) {
2493
2914
  }
2494
2915
  }
2495
2916
  function readPluginPackageJson(pluginPath) {
2496
- const pkgJsonPath = path5.join(pluginPath, "package.json");
2497
- if (!fs7.existsSync(pkgJsonPath)) {
2917
+ const pkgJsonPath = path8.join(pluginPath, "package.json");
2918
+ if (!fs10.existsSync(pkgJsonPath)) {
2498
2919
  return null;
2499
2920
  }
2500
2921
  try {
2501
- const content = fs7.readFileSync(pkgJsonPath, "utf-8");
2922
+ const content = fs10.readFileSync(pkgJsonPath, "utf-8");
2502
2923
  return JSON.parse(content);
2503
2924
  } catch {
2504
2925
  return null;
2505
2926
  }
2506
2927
  }
2507
2928
  function extractTgzToNodeModules(tgzPath, pluginName) {
2508
- const nodeModulesPath = path5.join(getProjectRoot(), "node_modules");
2509
- const targetDir = path5.join(nodeModulesPath, pluginName);
2510
- const scopeDir = path5.dirname(targetDir);
2511
- if (!fs7.existsSync(scopeDir)) {
2512
- fs7.mkdirSync(scopeDir, { recursive: true });
2929
+ const nodeModulesPath = path8.join(getProjectRoot(), "node_modules");
2930
+ const targetDir = path8.join(nodeModulesPath, pluginName);
2931
+ const scopeDir = path8.dirname(targetDir);
2932
+ if (!fs10.existsSync(scopeDir)) {
2933
+ fs10.mkdirSync(scopeDir, { recursive: true });
2513
2934
  }
2514
- if (fs7.existsSync(targetDir)) {
2515
- fs7.rmSync(targetDir, { recursive: true });
2935
+ if (fs10.existsSync(targetDir)) {
2936
+ fs10.rmSync(targetDir, { recursive: true });
2516
2937
  }
2517
- const tempDir = path5.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
2518
- if (fs7.existsSync(tempDir)) {
2519
- fs7.rmSync(tempDir, { recursive: true });
2938
+ const tempDir = path8.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
2939
+ if (fs10.existsSync(tempDir)) {
2940
+ fs10.rmSync(tempDir, { recursive: true });
2520
2941
  }
2521
- fs7.mkdirSync(tempDir, { recursive: true });
2942
+ fs10.mkdirSync(tempDir, { recursive: true });
2522
2943
  try {
2523
- execSync(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
2524
- const extractedDir = path5.join(tempDir, "package");
2525
- if (fs7.existsSync(extractedDir)) {
2526
- fs7.renameSync(extractedDir, targetDir);
2944
+ execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
2945
+ const extractedDir = path8.join(tempDir, "package");
2946
+ if (fs10.existsSync(extractedDir)) {
2947
+ fs10.renameSync(extractedDir, targetDir);
2527
2948
  } else {
2528
- const files = fs7.readdirSync(tempDir);
2949
+ const files = fs10.readdirSync(tempDir);
2529
2950
  if (files.length === 1) {
2530
- fs7.renameSync(path5.join(tempDir, files[0]), targetDir);
2951
+ fs10.renameSync(path8.join(tempDir, files[0]), targetDir);
2531
2952
  } else {
2532
2953
  throw new Error("Unexpected tgz structure");
2533
2954
  }
2534
2955
  }
2535
2956
  return targetDir;
2536
2957
  } finally {
2537
- if (fs7.existsSync(tempDir)) {
2538
- fs7.rmSync(tempDir, { recursive: true });
2958
+ if (fs10.existsSync(tempDir)) {
2959
+ fs10.rmSync(tempDir, { recursive: true });
2539
2960
  }
2540
2961
  }
2541
2962
  }
@@ -2544,10 +2965,10 @@ function checkMissingPeerDeps(peerDeps) {
2544
2965
  return [];
2545
2966
  }
2546
2967
  const missing = [];
2547
- const nodeModulesPath = path5.join(getProjectRoot(), "node_modules");
2968
+ const nodeModulesPath = path8.join(getProjectRoot(), "node_modules");
2548
2969
  for (const [depName, _version] of Object.entries(peerDeps)) {
2549
- const depPath = path5.join(nodeModulesPath, depName);
2550
- if (!fs7.existsSync(depPath)) {
2970
+ const depPath = path8.join(nodeModulesPath, depName);
2971
+ if (!fs10.existsSync(depPath)) {
2551
2972
  missing.push(depName);
2552
2973
  }
2553
2974
  }
@@ -2558,7 +2979,7 @@ function installMissingDeps(deps) {
2558
2979
  return;
2559
2980
  }
2560
2981
  console.log(`[action-plugin] Installing missing dependencies: ${deps.join(", ")}`);
2561
- const result = spawnSync2("npm", ["install", ...deps, "--no-save", "--no-package-lock"], {
2982
+ const result = spawnSync4("npm", ["install", ...deps, "--no-save", "--no-package-lock"], {
2562
2983
  cwd: getProjectRoot(),
2563
2984
  stdio: "inherit"
2564
2985
  });
@@ -2571,40 +2992,16 @@ function installMissingDeps(deps) {
2571
2992
  }
2572
2993
  function removePluginDirectory(pluginName) {
2573
2994
  const pluginPath = getPluginPath(pluginName);
2574
- if (fs7.existsSync(pluginPath)) {
2575
- fs7.rmSync(pluginPath, { recursive: true });
2995
+ if (fs10.existsSync(pluginPath)) {
2996
+ fs10.rmSync(pluginPath, { recursive: true });
2576
2997
  console.log(`[action-plugin] Removed ${pluginName}`);
2577
2998
  }
2578
2999
  }
2579
3000
 
2580
3001
  // src/commands/action-plugin/api-client.ts
2581
3002
  import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
2582
- import fs8 from "fs";
2583
- import path6 from "path";
2584
-
2585
- // src/utils/http-client.ts
2586
- import { HttpClient } from "@lark-apaas/http-client";
2587
- var clientInstance = null;
2588
- function getHttpClient() {
2589
- if (!clientInstance) {
2590
- clientInstance = new HttpClient({
2591
- timeout: 3e4,
2592
- platform: {
2593
- enabled: true
2594
- }
2595
- });
2596
- const canaryEnv = process.env.FORCE_FRAMEWORK_CLI_CANARY_ENV;
2597
- if (canaryEnv) {
2598
- clientInstance.interceptors.request.use((req) => {
2599
- req.headers["x-tt-env"] = canaryEnv;
2600
- return req;
2601
- });
2602
- }
2603
- }
2604
- return clientInstance;
2605
- }
2606
-
2607
- // src/commands/action-plugin/api-client.ts
3003
+ import fs11 from "fs";
3004
+ import path9 from "path";
2608
3005
  var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
2609
3006
  async function getPluginVersions(keys, latestOnly = true) {
2610
3007
  const client = getHttpClient();
@@ -2668,19 +3065,19 @@ async function downloadFromPublic(downloadURL) {
2668
3065
  return Buffer.from(arrayBuffer);
2669
3066
  }
2670
3067
  function getPluginCacheDir() {
2671
- return path6.join(process.cwd(), PLUGIN_CACHE_DIR);
3068
+ return path9.join(process.cwd(), PLUGIN_CACHE_DIR);
2672
3069
  }
2673
3070
  function ensureCacheDir() {
2674
3071
  const cacheDir = getPluginCacheDir();
2675
- if (!fs8.existsSync(cacheDir)) {
2676
- fs8.mkdirSync(cacheDir, { recursive: true });
3072
+ if (!fs11.existsSync(cacheDir)) {
3073
+ fs11.mkdirSync(cacheDir, { recursive: true });
2677
3074
  }
2678
3075
  }
2679
3076
  function getTempFilePath(pluginKey, version) {
2680
3077
  ensureCacheDir();
2681
3078
  const safeKey = pluginKey.replace(/[/@]/g, "_");
2682
3079
  const filename = `${safeKey}@${version}.tgz`;
2683
- return path6.join(getPluginCacheDir(), filename);
3080
+ return path9.join(getPluginCacheDir(), filename);
2684
3081
  }
2685
3082
  var MAX_RETRIES = 2;
2686
3083
  async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
@@ -2717,7 +3114,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
2717
3114
  );
2718
3115
  }
2719
3116
  const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
2720
- fs8.writeFileSync(tgzPath, tgzBuffer);
3117
+ fs11.writeFileSync(tgzPath, tgzBuffer);
2721
3118
  console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
2722
3119
  return {
2723
3120
  tgzPath,
@@ -2731,18 +3128,18 @@ function getCachePath(pluginKey, version) {
2731
3128
  ensureCacheDir();
2732
3129
  const safeKey = pluginKey.replace(/[/@]/g, "_");
2733
3130
  const filename = `${safeKey}@${version}.tgz`;
2734
- return path6.join(getPluginCacheDir(), filename);
3131
+ return path9.join(getPluginCacheDir(), filename);
2735
3132
  }
2736
3133
  function hasCachedPlugin(pluginKey, version) {
2737
3134
  const cachePath = getCachePath(pluginKey, version);
2738
- return fs8.existsSync(cachePath);
3135
+ return fs11.existsSync(cachePath);
2739
3136
  }
2740
3137
  function listCachedPlugins() {
2741
3138
  const cacheDir = getPluginCacheDir();
2742
- if (!fs8.existsSync(cacheDir)) {
3139
+ if (!fs11.existsSync(cacheDir)) {
2743
3140
  return [];
2744
3141
  }
2745
- const files = fs8.readdirSync(cacheDir);
3142
+ const files = fs11.readdirSync(cacheDir);
2746
3143
  const result = [];
2747
3144
  for (const file of files) {
2748
3145
  if (!file.endsWith(".tgz")) continue;
@@ -2750,8 +3147,8 @@ function listCachedPlugins() {
2750
3147
  if (!match) continue;
2751
3148
  const [, rawName, version] = match;
2752
3149
  const name = rawName.replace(/^_/, "@").replace(/_/, "/");
2753
- const filePath = path6.join(cacheDir, file);
2754
- const stat = fs8.statSync(filePath);
3150
+ const filePath = path9.join(cacheDir, file);
3151
+ const stat = fs11.statSync(filePath);
2755
3152
  result.push({
2756
3153
  name,
2757
3154
  version,
@@ -2764,14 +3161,14 @@ function listCachedPlugins() {
2764
3161
  }
2765
3162
  function cleanAllCache() {
2766
3163
  const cacheDir = getPluginCacheDir();
2767
- if (!fs8.existsSync(cacheDir)) {
3164
+ if (!fs11.existsSync(cacheDir)) {
2768
3165
  return 0;
2769
3166
  }
2770
- const files = fs8.readdirSync(cacheDir);
3167
+ const files = fs11.readdirSync(cacheDir);
2771
3168
  let count = 0;
2772
3169
  for (const file of files) {
2773
3170
  if (file.endsWith(".tgz")) {
2774
- fs8.unlinkSync(path6.join(cacheDir, file));
3171
+ fs11.unlinkSync(path9.join(cacheDir, file));
2775
3172
  count++;
2776
3173
  }
2777
3174
  }
@@ -2779,21 +3176,21 @@ function cleanAllCache() {
2779
3176
  }
2780
3177
  function cleanPluginCache(pluginKey, version) {
2781
3178
  const cacheDir = getPluginCacheDir();
2782
- if (!fs8.existsSync(cacheDir)) {
3179
+ if (!fs11.existsSync(cacheDir)) {
2783
3180
  return 0;
2784
3181
  }
2785
3182
  const safeKey = pluginKey.replace(/[/@]/g, "_");
2786
- const files = fs8.readdirSync(cacheDir);
3183
+ const files = fs11.readdirSync(cacheDir);
2787
3184
  let count = 0;
2788
3185
  for (const file of files) {
2789
3186
  if (version) {
2790
3187
  if (file === `${safeKey}@${version}.tgz`) {
2791
- fs8.unlinkSync(path6.join(cacheDir, file));
3188
+ fs11.unlinkSync(path9.join(cacheDir, file));
2792
3189
  count++;
2793
3190
  }
2794
3191
  } else {
2795
3192
  if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
2796
- fs8.unlinkSync(path6.join(cacheDir, file));
3193
+ fs11.unlinkSync(path9.join(cacheDir, file));
2797
3194
  count++;
2798
3195
  }
2799
3196
  }
@@ -2887,6 +3284,8 @@ async function installOne(nameWithVersion) {
2887
3284
  if (actualVersion === requestedVersion) {
2888
3285
  console.log(`[action-plugin] Plugin ${name}@${requestedVersion} is already installed`);
2889
3286
  syncActionPluginsRecord(name, actualVersion);
3287
+ reportCreateInstanceEvent(name, actualVersion).catch(() => {
3288
+ });
2890
3289
  return { name, version: actualVersion, success: true, skipped: true };
2891
3290
  }
2892
3291
  }
@@ -2897,6 +3296,8 @@ async function installOne(nameWithVersion) {
2897
3296
  if (actualVersion === targetVersion) {
2898
3297
  console.log(`[action-plugin] Plugin ${name} is already up to date (version: ${actualVersion})`);
2899
3298
  syncActionPluginsRecord(name, actualVersion);
3299
+ reportCreateInstanceEvent(name, actualVersion).catch(() => {
3300
+ });
2900
3301
  return { name, version: actualVersion, success: true, skipped: true };
2901
3302
  }
2902
3303
  console.log(`[action-plugin] Found newer version: ${targetVersion} (installed: ${actualVersion || "none"})`);
@@ -2927,6 +3328,10 @@ async function installOne(nameWithVersion) {
2927
3328
  writeActionPlugins(plugins);
2928
3329
  const source = fromCache ? "from cache" : "downloaded";
2929
3330
  console.log(`[action-plugin] Successfully installed ${name}@${installedVersion} (${source})`);
3331
+ reportInstallEvent(name, installedVersion).catch(() => {
3332
+ });
3333
+ reportCreateInstanceEvent(name, installedVersion).catch(() => {
3334
+ });
2930
3335
  return { name, version: installedVersion, success: true };
2931
3336
  } catch (error) {
2932
3337
  const message = error instanceof Error ? error.message : String(error);
@@ -3212,40 +3617,40 @@ var actionPluginCommandGroup = {
3212
3617
  };
3213
3618
 
3214
3619
  // src/commands/capability/utils.ts
3215
- import fs9 from "fs";
3620
+ import fs12 from "fs";
3216
3621
  import { createRequire as createRequire2 } from "module";
3217
- import path7 from "path";
3622
+ import path10 from "path";
3218
3623
  var CAPABILITIES_DIR = "server/capabilities";
3219
3624
  function getProjectRoot2() {
3220
3625
  return process.cwd();
3221
3626
  }
3222
3627
  function getCapabilitiesDir() {
3223
- return path7.join(getProjectRoot2(), CAPABILITIES_DIR);
3628
+ return path10.join(getProjectRoot2(), CAPABILITIES_DIR);
3224
3629
  }
3225
3630
  function getCapabilityPath(id) {
3226
- return path7.join(getCapabilitiesDir(), `${id}.json`);
3631
+ return path10.join(getCapabilitiesDir(), `${id}.json`);
3227
3632
  }
3228
3633
  function getPluginManifestPath(pluginKey) {
3229
- return path7.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
3634
+ return path10.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
3230
3635
  }
3231
3636
  function capabilitiesDirExists() {
3232
- return fs9.existsSync(getCapabilitiesDir());
3637
+ return fs12.existsSync(getCapabilitiesDir());
3233
3638
  }
3234
3639
  function listCapabilityIds() {
3235
3640
  const dir = getCapabilitiesDir();
3236
- if (!fs9.existsSync(dir)) {
3641
+ if (!fs12.existsSync(dir)) {
3237
3642
  return [];
3238
3643
  }
3239
- const files = fs9.readdirSync(dir);
3644
+ const files = fs12.readdirSync(dir);
3240
3645
  return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
3241
3646
  }
3242
3647
  function readCapability(id) {
3243
3648
  const filePath = getCapabilityPath(id);
3244
- if (!fs9.existsSync(filePath)) {
3649
+ if (!fs12.existsSync(filePath)) {
3245
3650
  throw new Error(`Capability not found: ${id}`);
3246
3651
  }
3247
3652
  try {
3248
- const content = fs9.readFileSync(filePath, "utf-8");
3653
+ const content = fs12.readFileSync(filePath, "utf-8");
3249
3654
  return JSON.parse(content);
3250
3655
  } catch (error) {
3251
3656
  if (error instanceof SyntaxError) {
@@ -3272,11 +3677,11 @@ function readAllCapabilities() {
3272
3677
  }
3273
3678
  function readPluginManifest(pluginKey) {
3274
3679
  const manifestPath = getPluginManifestPath(pluginKey);
3275
- if (!fs9.existsSync(manifestPath)) {
3680
+ if (!fs12.existsSync(manifestPath)) {
3276
3681
  throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
3277
3682
  }
3278
3683
  try {
3279
- const content = fs9.readFileSync(manifestPath, "utf-8");
3684
+ const content = fs12.readFileSync(manifestPath, "utf-8");
3280
3685
  return JSON.parse(content);
3281
3686
  } catch (error) {
3282
3687
  if (error instanceof SyntaxError) {
@@ -3293,7 +3698,7 @@ function hasValidParamsSchema(paramsSchema) {
3293
3698
  }
3294
3699
  async function loadPlugin(pluginKey) {
3295
3700
  try {
3296
- const userRequire = createRequire2(path7.join(getProjectRoot2(), "package.json"));
3701
+ const userRequire = createRequire2(path10.join(getProjectRoot2(), "package.json"));
3297
3702
  const resolvedPath = userRequire.resolve(pluginKey);
3298
3703
  const pluginModule = await import(resolvedPath);
3299
3704
  const pluginPackage = pluginModule.default ?? pluginModule;
@@ -3452,9 +3857,12 @@ var capabilityCommandGroup = {
3452
3857
  commands: [listCommand2]
3453
3858
  };
3454
3859
 
3860
+ // src/commands/component/add.handler.ts
3861
+ import { execFile } from "child_process";
3862
+
3455
3863
  // src/commands/component/registry-preparer.ts
3456
- import fs10 from "fs";
3457
- import path8 from "path";
3864
+ import fs13 from "fs";
3865
+ import path11 from "path";
3458
3866
  import os from "os";
3459
3867
 
3460
3868
  // src/commands/component/service.ts
@@ -3510,7 +3918,7 @@ async function sendInstallEvent(key) {
3510
3918
  }
3511
3919
 
3512
3920
  // src/commands/component/registry-preparer.ts
3513
- var REGISTRY_TEMP_DIR = path8.join(os.tmpdir(), "miaoda-registry");
3921
+ var REGISTRY_TEMP_DIR = path11.join(os.tmpdir(), "miaoda-registry");
3514
3922
  function parseComponentKey(key) {
3515
3923
  const match = key.match(/^@([^/]+)\/(.+)$/);
3516
3924
  if (!match) {
@@ -3522,11 +3930,11 @@ function parseComponentKey(key) {
3522
3930
  }
3523
3931
  function getLocalRegistryPath(key) {
3524
3932
  const { scope, name } = parseComponentKey(key);
3525
- return path8.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
3933
+ return path11.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
3526
3934
  }
3527
3935
  function ensureDir(dirPath) {
3528
- if (!fs10.existsSync(dirPath)) {
3529
- fs10.mkdirSync(dirPath, { recursive: true });
3936
+ if (!fs13.existsSync(dirPath)) {
3937
+ fs13.mkdirSync(dirPath, { recursive: true });
3530
3938
  }
3531
3939
  }
3532
3940
  async function prepareRecursive(key, visited) {
@@ -3559,8 +3967,8 @@ async function prepareRecursive(key, visited) {
3559
3967
  registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
3560
3968
  };
3561
3969
  const localPath = getLocalRegistryPath(key);
3562
- ensureDir(path8.dirname(localPath));
3563
- fs10.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
3970
+ ensureDir(path11.dirname(localPath));
3971
+ fs13.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
3564
3972
  debug("\u4FDD\u5B58\u5230: %s", localPath);
3565
3973
  }
3566
3974
  async function prepareComponentRegistryItems(id) {
@@ -3570,18 +3978,18 @@ async function prepareComponentRegistryItems(id) {
3570
3978
  }
3571
3979
  function cleanupTempDir() {
3572
3980
  try {
3573
- if (fs10.existsSync(REGISTRY_TEMP_DIR)) {
3574
- fs10.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
3981
+ if (fs13.existsSync(REGISTRY_TEMP_DIR)) {
3982
+ fs13.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
3575
3983
  }
3576
3984
  } catch {
3577
3985
  }
3578
3986
  }
3579
3987
  function getDownloadedRegistryItem(itemId) {
3580
3988
  const localPath = getLocalRegistryPath(itemId);
3581
- if (!fs10.existsSync(localPath)) {
3989
+ if (!fs13.existsSync(localPath)) {
3582
3990
  return null;
3583
3991
  }
3584
- const content = fs10.readFileSync(localPath, "utf-8");
3992
+ const content = fs13.readFileSync(localPath, "utf-8");
3585
3993
  return JSON.parse(content);
3586
3994
  }
3587
3995
 
@@ -3681,6 +4089,16 @@ async function executeShadcnAdd(registryItemPath) {
3681
4089
  }
3682
4090
 
3683
4091
  // src/commands/component/add.handler.ts
4092
+ function runActionPluginInit() {
4093
+ return new Promise((resolve) => {
4094
+ execFile("fullstack-cli", ["action-plugin", "init"], { cwd: process.cwd(), stdio: "ignore" }, (error) => {
4095
+ if (error) {
4096
+ debug("action-plugin init \u5931\u8D25: %s", error.message);
4097
+ }
4098
+ resolve();
4099
+ });
4100
+ });
4101
+ }
3684
4102
  function printResult(result) {
3685
4103
  console.log(JSON.stringify(result, null, 2));
3686
4104
  }
@@ -3717,6 +4135,7 @@ async function add(key) {
3717
4135
  errors: [{ message: errorMessage }]
3718
4136
  });
3719
4137
  } finally {
4138
+ await runActionPluginInit();
3720
4139
  cleanupTempDir();
3721
4140
  }
3722
4141
  }
@@ -3738,58 +4157,58 @@ var componentCommandGroup = {
3738
4157
  };
3739
4158
 
3740
4159
  // src/commands/migration/version-manager.ts
3741
- import fs11 from "fs";
3742
- import path9 from "path";
4160
+ import fs14 from "fs";
4161
+ import path12 from "path";
3743
4162
  var PACKAGE_JSON = "package.json";
3744
4163
  var VERSION_FIELD = "migrationVersion";
3745
4164
  function getPackageJsonPath2() {
3746
- return path9.join(process.cwd(), PACKAGE_JSON);
4165
+ return path12.join(process.cwd(), PACKAGE_JSON);
3747
4166
  }
3748
4167
  function getCurrentVersion() {
3749
4168
  const pkgPath = getPackageJsonPath2();
3750
- if (!fs11.existsSync(pkgPath)) {
4169
+ if (!fs14.existsSync(pkgPath)) {
3751
4170
  throw new Error("package.json not found");
3752
4171
  }
3753
- const pkg2 = JSON.parse(fs11.readFileSync(pkgPath, "utf-8"));
4172
+ const pkg2 = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
3754
4173
  return pkg2[VERSION_FIELD] ?? 0;
3755
4174
  }
3756
4175
  function setCurrentVersion(version) {
3757
4176
  const pkgPath = getPackageJsonPath2();
3758
- const pkg2 = JSON.parse(fs11.readFileSync(pkgPath, "utf-8"));
4177
+ const pkg2 = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
3759
4178
  pkg2[VERSION_FIELD] = version;
3760
- fs11.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
4179
+ fs14.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
3761
4180
  }
3762
4181
 
3763
4182
  // src/commands/migration/versions/v001_capability/json-migrator/detector.ts
3764
- import fs13 from "fs";
3765
- import path11 from "path";
4183
+ import fs16 from "fs";
4184
+ import path14 from "path";
3766
4185
 
3767
4186
  // src/commands/migration/versions/v001_capability/utils.ts
3768
- import fs12 from "fs";
3769
- import path10 from "path";
4187
+ import fs15 from "fs";
4188
+ import path13 from "path";
3770
4189
  var CAPABILITIES_DIR2 = "server/capabilities";
3771
4190
  function getProjectRoot3() {
3772
4191
  return process.cwd();
3773
4192
  }
3774
4193
  function getCapabilitiesDir2() {
3775
- return path10.join(getProjectRoot3(), CAPABILITIES_DIR2);
4194
+ return path13.join(getProjectRoot3(), CAPABILITIES_DIR2);
3776
4195
  }
3777
4196
  function getPluginManifestPath2(pluginKey) {
3778
- return path10.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
4197
+ return path13.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
3779
4198
  }
3780
4199
 
3781
4200
  // src/commands/migration/versions/v001_capability/json-migrator/detector.ts
3782
4201
  function detectJsonMigration() {
3783
4202
  const capabilitiesDir = getCapabilitiesDir2();
3784
- const oldFilePath = path11.join(capabilitiesDir, "capabilities.json");
3785
- if (!fs13.existsSync(oldFilePath)) {
4203
+ const oldFilePath = path14.join(capabilitiesDir, "capabilities.json");
4204
+ if (!fs16.existsSync(oldFilePath)) {
3786
4205
  return {
3787
4206
  needsMigration: false,
3788
4207
  reason: "capabilities.json not found"
3789
4208
  };
3790
4209
  }
3791
4210
  try {
3792
- const content = fs13.readFileSync(oldFilePath, "utf-8");
4211
+ const content = fs16.readFileSync(oldFilePath, "utf-8");
3793
4212
  const parsed = JSON.parse(content);
3794
4213
  if (!Array.isArray(parsed)) {
3795
4214
  return {
@@ -3840,8 +4259,8 @@ async function check(options) {
3840
4259
  }
3841
4260
 
3842
4261
  // src/commands/migration/versions/v001_capability/json-migrator/index.ts
3843
- import fs14 from "fs";
3844
- import path12 from "path";
4262
+ import fs17 from "fs";
4263
+ import path15 from "path";
3845
4264
 
3846
4265
  // src/commands/migration/versions/v001_capability/mapping.ts
3847
4266
  var DEFAULT_PLUGIN_VERSION = "1.0.0";
@@ -4071,18 +4490,18 @@ function transformCapabilities(oldCapabilities) {
4071
4490
  // src/commands/migration/versions/v001_capability/json-migrator/index.ts
4072
4491
  function loadExistingCapabilities() {
4073
4492
  const capabilitiesDir = getCapabilitiesDir2();
4074
- if (!fs14.existsSync(capabilitiesDir)) {
4493
+ if (!fs17.existsSync(capabilitiesDir)) {
4075
4494
  return [];
4076
4495
  }
4077
- const files = fs14.readdirSync(capabilitiesDir);
4496
+ const files = fs17.readdirSync(capabilitiesDir);
4078
4497
  const capabilities = [];
4079
4498
  for (const file of files) {
4080
4499
  if (file === "capabilities.json" || !file.endsWith(".json")) {
4081
4500
  continue;
4082
4501
  }
4083
4502
  try {
4084
- const filePath = path12.join(capabilitiesDir, file);
4085
- const content = fs14.readFileSync(filePath, "utf-8");
4503
+ const filePath = path15.join(capabilitiesDir, file);
4504
+ const content = fs17.readFileSync(filePath, "utf-8");
4086
4505
  const capability = JSON.parse(content);
4087
4506
  if (capability.id && capability.pluginKey) {
4088
4507
  capabilities.push(capability);
@@ -4140,9 +4559,9 @@ async function migrateJsonFiles(options) {
4140
4559
  }
4141
4560
  const capabilitiesDir = getCapabilitiesDir2();
4142
4561
  for (const cap of newCapabilities) {
4143
- const filePath = path12.join(capabilitiesDir, `${cap.id}.json`);
4562
+ const filePath = path15.join(capabilitiesDir, `${cap.id}.json`);
4144
4563
  const content = JSON.stringify(cap, null, 2);
4145
- fs14.writeFileSync(filePath, content, "utf-8");
4564
+ fs17.writeFileSync(filePath, content, "utf-8");
4146
4565
  console.log(` \u2713 Created: ${cap.id}.json`);
4147
4566
  }
4148
4567
  return {
@@ -4154,11 +4573,11 @@ async function migrateJsonFiles(options) {
4154
4573
  }
4155
4574
 
4156
4575
  // src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
4157
- import fs15 from "fs";
4576
+ import fs18 from "fs";
4158
4577
  function isPluginInstalled2(pluginKey) {
4159
4578
  const actionPlugins = readActionPlugins();
4160
4579
  const manifestPath = getPluginManifestPath2(pluginKey);
4161
- return fs15.existsSync(manifestPath) && !!actionPlugins[pluginKey];
4580
+ return fs18.existsSync(manifestPath) && !!actionPlugins[pluginKey];
4162
4581
  }
4163
4582
  function detectPluginsToInstall(capabilities) {
4164
4583
  const pluginKeys = /* @__PURE__ */ new Set();
@@ -4234,12 +4653,12 @@ async function installPlugins(capabilities, options) {
4234
4653
  }
4235
4654
 
4236
4655
  // src/commands/migration/versions/v001_capability/code-migrator/index.ts
4237
- import path14 from "path";
4656
+ import path17 from "path";
4238
4657
  import { Project as Project3 } from "ts-morph";
4239
4658
 
4240
4659
  // src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
4241
- import fs16 from "fs";
4242
- import path13 from "path";
4660
+ import fs19 from "fs";
4661
+ import path16 from "path";
4243
4662
  var EXCLUDED_DIRS = [
4244
4663
  "node_modules",
4245
4664
  "dist",
@@ -4254,9 +4673,9 @@ var EXCLUDED_PATTERNS = [
4254
4673
  /\.d\.ts$/
4255
4674
  ];
4256
4675
  function scanDirectory(dir, files = []) {
4257
- const entries = fs16.readdirSync(dir, { withFileTypes: true });
4676
+ const entries = fs19.readdirSync(dir, { withFileTypes: true });
4258
4677
  for (const entry of entries) {
4259
- const fullPath = path13.join(dir, entry.name);
4678
+ const fullPath = path16.join(dir, entry.name);
4260
4679
  if (entry.isDirectory()) {
4261
4680
  if (EXCLUDED_DIRS.includes(entry.name)) {
4262
4681
  continue;
@@ -4272,14 +4691,14 @@ function scanDirectory(dir, files = []) {
4272
4691
  return files;
4273
4692
  }
4274
4693
  function scanServerFiles() {
4275
- const serverDir = path13.join(getProjectRoot3(), "server");
4276
- if (!fs16.existsSync(serverDir)) {
4694
+ const serverDir = path16.join(getProjectRoot3(), "server");
4695
+ if (!fs19.existsSync(serverDir)) {
4277
4696
  return [];
4278
4697
  }
4279
4698
  return scanDirectory(serverDir);
4280
4699
  }
4281
4700
  function hasCapabilityImport(filePath) {
4282
- const content = fs16.readFileSync(filePath, "utf-8");
4701
+ const content = fs19.readFileSync(filePath, "utf-8");
4283
4702
  return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
4284
4703
  }
4285
4704
  function scanFilesToMigrate() {
@@ -4656,7 +5075,7 @@ function analyzeFile(project, filePath, actionNameMap) {
4656
5075
  const callSites = analyzeCallSites(sourceFile, imports);
4657
5076
  const classInfo = analyzeClass(sourceFile);
4658
5077
  const { canMigrate, reason } = canAutoMigrate(classInfo);
4659
- const relativePath = path14.relative(getProjectRoot3(), filePath);
5078
+ const relativePath = path17.relative(getProjectRoot3(), filePath);
4660
5079
  return {
4661
5080
  filePath: relativePath,
4662
5081
  imports,
@@ -4667,7 +5086,7 @@ function analyzeFile(project, filePath, actionNameMap) {
4667
5086
  };
4668
5087
  }
4669
5088
  function migrateFile(project, analysis, dryRun) {
4670
- const absolutePath = path14.join(getProjectRoot3(), analysis.filePath);
5089
+ const absolutePath = path17.join(getProjectRoot3(), analysis.filePath);
4671
5090
  if (!analysis.canAutoMigrate) {
4672
5091
  return {
4673
5092
  filePath: analysis.filePath,
@@ -4770,17 +5189,17 @@ function getSuggestion(analysis) {
4770
5189
  }
4771
5190
 
4772
5191
  // src/commands/migration/versions/v001_capability/cleanup.ts
4773
- import fs17 from "fs";
4774
- import path15 from "path";
5192
+ import fs20 from "fs";
5193
+ import path18 from "path";
4775
5194
  function cleanupOldFiles(capabilities, dryRun) {
4776
5195
  const deletedFiles = [];
4777
5196
  const errors = [];
4778
5197
  const capabilitiesDir = getCapabilitiesDir2();
4779
- const oldJsonPath = path15.join(capabilitiesDir, "capabilities.json");
4780
- if (fs17.existsSync(oldJsonPath)) {
5198
+ const oldJsonPath = path18.join(capabilitiesDir, "capabilities.json");
5199
+ if (fs20.existsSync(oldJsonPath)) {
4781
5200
  try {
4782
5201
  if (!dryRun) {
4783
- fs17.unlinkSync(oldJsonPath);
5202
+ fs20.unlinkSync(oldJsonPath);
4784
5203
  }
4785
5204
  deletedFiles.push("capabilities.json");
4786
5205
  } catch (error) {
@@ -4788,11 +5207,11 @@ function cleanupOldFiles(capabilities, dryRun) {
4788
5207
  }
4789
5208
  }
4790
5209
  for (const cap of capabilities) {
4791
- const tsFilePath = path15.join(capabilitiesDir, `${cap.id}.ts`);
4792
- if (fs17.existsSync(tsFilePath)) {
5210
+ const tsFilePath = path18.join(capabilitiesDir, `${cap.id}.ts`);
5211
+ if (fs20.existsSync(tsFilePath)) {
4793
5212
  try {
4794
5213
  if (!dryRun) {
4795
- fs17.unlinkSync(tsFilePath);
5214
+ fs20.unlinkSync(tsFilePath);
4796
5215
  }
4797
5216
  deletedFiles.push(`${cap.id}.ts`);
4798
5217
  } catch (error) {
@@ -4808,8 +5227,8 @@ function cleanupOldFiles(capabilities, dryRun) {
4808
5227
  }
4809
5228
 
4810
5229
  // src/commands/migration/versions/v001_capability/report-generator.ts
4811
- import fs18 from "fs";
4812
- import path16 from "path";
5230
+ import fs21 from "fs";
5231
+ import path19 from "path";
4813
5232
  var REPORT_FILE = "capability-migration-report.md";
4814
5233
  function printSummary(result) {
4815
5234
  const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
@@ -4972,15 +5391,15 @@ async function generateReport(result) {
4972
5391
  }
4973
5392
  lines.push("");
4974
5393
  const logDir = process.env.LOG_DIR || "logs";
4975
- if (!fs18.existsSync(logDir)) {
5394
+ if (!fs21.existsSync(logDir)) {
4976
5395
  return;
4977
5396
  }
4978
- const reportDir = path16.join(logDir, "migration");
4979
- if (!fs18.existsSync(reportDir)) {
4980
- fs18.mkdirSync(reportDir, { recursive: true });
5397
+ const reportDir = path19.join(logDir, "migration");
5398
+ if (!fs21.existsSync(reportDir)) {
5399
+ fs21.mkdirSync(reportDir, { recursive: true });
4981
5400
  }
4982
- const reportPath = path16.join(reportDir, REPORT_FILE);
4983
- fs18.writeFileSync(reportPath, lines.join("\n"), "utf-8");
5401
+ const reportPath = path19.join(reportDir, REPORT_FILE);
5402
+ fs21.writeFileSync(reportPath, lines.join("\n"), "utf-8");
4984
5403
  console.log(`\u{1F4C4} Report generated: ${reportPath}`);
4985
5404
  }
4986
5405
 
@@ -5157,7 +5576,7 @@ function buildResult(jsonMigration, pluginInstallation, codeMigration, cleanup)
5157
5576
  }
5158
5577
 
5159
5578
  // src/commands/migration/versions/v001_capability/run.ts
5160
- async function run3(options) {
5579
+ async function run5(options) {
5161
5580
  try {
5162
5581
  const migrationOptions = {
5163
5582
  dryRun: options.dryRun ?? false
@@ -5222,7 +5641,7 @@ var v001CapabilityMigration = {
5222
5641
  name: "capability",
5223
5642
  description: "Migrate capability configurations from old format (capabilities.json array) to new format (individual JSON files)",
5224
5643
  check,
5225
- run: run3
5644
+ run: run5
5226
5645
  };
5227
5646
 
5228
5647
  // src/commands/migration/versions/index.ts
@@ -5512,10 +5931,10 @@ var migrationCommand = {
5512
5931
  };
5513
5932
 
5514
5933
  // src/commands/read-logs/index.ts
5515
- import path17 from "path";
5934
+ import path20 from "path";
5516
5935
 
5517
5936
  // src/commands/read-logs/std-utils.ts
5518
- import fs19 from "fs";
5937
+ import fs22 from "fs";
5519
5938
  function formatStdPrefixTime(localTime) {
5520
5939
  const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
5521
5940
  if (!match) return localTime;
@@ -5545,11 +5964,11 @@ function stripPrefixFromStdLine(line) {
5545
5964
  return `[${time}] ${content}`;
5546
5965
  }
5547
5966
  function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
5548
- const stat = fs19.statSync(filePath);
5967
+ const stat = fs22.statSync(filePath);
5549
5968
  if (stat.size === 0) {
5550
5969
  return { lines: [], markerFound: false, totalLinesCount: 0 };
5551
5970
  }
5552
- const fd = fs19.openSync(filePath, "r");
5971
+ const fd = fs22.openSync(filePath, "r");
5553
5972
  const chunkSize = 64 * 1024;
5554
5973
  let position = stat.size;
5555
5974
  let remainder = "";
@@ -5563,7 +5982,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
5563
5982
  const length = Math.min(chunkSize, position);
5564
5983
  position -= length;
5565
5984
  const buffer = Buffer.alloc(length);
5566
- fs19.readSync(fd, buffer, 0, length, position);
5985
+ fs22.readSync(fd, buffer, 0, length, position);
5567
5986
  let chunk = buffer.toString("utf8");
5568
5987
  if (remainder) {
5569
5988
  chunk += remainder;
@@ -5605,7 +6024,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
5605
6024
  }
5606
6025
  }
5607
6026
  } finally {
5608
- fs19.closeSync(fd);
6027
+ fs22.closeSync(fd);
5609
6028
  }
5610
6029
  return { lines: collected.reverse(), markerFound, totalLinesCount };
5611
6030
  }
@@ -5626,21 +6045,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
5626
6045
  }
5627
6046
 
5628
6047
  // src/commands/read-logs/tail.ts
5629
- import fs20 from "fs";
6048
+ import fs23 from "fs";
5630
6049
  function fileExists(filePath) {
5631
6050
  try {
5632
- fs20.accessSync(filePath, fs20.constants.F_OK | fs20.constants.R_OK);
6051
+ fs23.accessSync(filePath, fs23.constants.F_OK | fs23.constants.R_OK);
5633
6052
  return true;
5634
6053
  } catch {
5635
6054
  return false;
5636
6055
  }
5637
6056
  }
5638
6057
  function readFileTailLines(filePath, maxLines) {
5639
- const stat = fs20.statSync(filePath);
6058
+ const stat = fs23.statSync(filePath);
5640
6059
  if (stat.size === 0) {
5641
6060
  return [];
5642
6061
  }
5643
- const fd = fs20.openSync(filePath, "r");
6062
+ const fd = fs23.openSync(filePath, "r");
5644
6063
  const chunkSize = 64 * 1024;
5645
6064
  const chunks = [];
5646
6065
  let position = stat.size;
@@ -5650,13 +6069,13 @@ function readFileTailLines(filePath, maxLines) {
5650
6069
  const length = Math.min(chunkSize, position);
5651
6070
  position -= length;
5652
6071
  const buffer = Buffer.alloc(length);
5653
- fs20.readSync(fd, buffer, 0, length, position);
6072
+ fs23.readSync(fd, buffer, 0, length, position);
5654
6073
  chunks.unshift(buffer.toString("utf8"));
5655
6074
  const chunkLines = buffer.toString("utf8").split("\n").length - 1;
5656
6075
  collectedLines += chunkLines;
5657
6076
  }
5658
6077
  } finally {
5659
- fs20.closeSync(fd);
6078
+ fs23.closeSync(fd);
5660
6079
  }
5661
6080
  const content = chunks.join("");
5662
6081
  const allLines = content.split("\n");
@@ -5672,11 +6091,11 @@ function readFileTailLines(filePath, maxLines) {
5672
6091
  return allLines.slice(allLines.length - maxLines);
5673
6092
  }
5674
6093
  function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
5675
- const stat = fs20.statSync(filePath);
6094
+ const stat = fs23.statSync(filePath);
5676
6095
  if (stat.size === 0) {
5677
6096
  return { lines: [], totalLinesCount: 0 };
5678
6097
  }
5679
- const fd = fs20.openSync(filePath, "r");
6098
+ const fd = fs23.openSync(filePath, "r");
5680
6099
  const chunkSize = 64 * 1024;
5681
6100
  let position = stat.size;
5682
6101
  let remainder = "";
@@ -5688,7 +6107,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
5688
6107
  const length = Math.min(chunkSize, position);
5689
6108
  position -= length;
5690
6109
  const buffer = Buffer.alloc(length);
5691
- fs20.readSync(fd, buffer, 0, length, position);
6110
+ fs23.readSync(fd, buffer, 0, length, position);
5692
6111
  let chunk = buffer.toString("utf8");
5693
6112
  if (remainder) {
5694
6113
  chunk += remainder;
@@ -5719,7 +6138,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
5719
6138
  }
5720
6139
  }
5721
6140
  } finally {
5722
- fs20.closeSync(fd);
6141
+ fs23.closeSync(fd);
5723
6142
  }
5724
6143
  return { lines: collected.reverse(), totalLinesCount };
5725
6144
  }
@@ -5861,7 +6280,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
5861
6280
  }
5862
6281
 
5863
6282
  // src/commands/read-logs/json-lines.ts
5864
- import fs21 from "fs";
6283
+ import fs24 from "fs";
5865
6284
  function normalizePid(value) {
5866
6285
  if (typeof value === "number") {
5867
6286
  return String(value);
@@ -5912,11 +6331,11 @@ function buildWantedLevelSet(levels) {
5912
6331
  return set.size > 0 ? set : null;
5913
6332
  }
5914
6333
  function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
5915
- const stat = fs21.statSync(filePath);
6334
+ const stat = fs24.statSync(filePath);
5916
6335
  if (stat.size === 0) {
5917
6336
  return { lines: [], totalLinesCount: 0 };
5918
6337
  }
5919
- const fd = fs21.openSync(filePath, "r");
6338
+ const fd = fs24.openSync(filePath, "r");
5920
6339
  const chunkSize = 64 * 1024;
5921
6340
  let position = stat.size;
5922
6341
  let remainder = "";
@@ -5931,7 +6350,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
5931
6350
  const length = Math.min(chunkSize, position);
5932
6351
  position -= length;
5933
6352
  const buffer = Buffer.alloc(length);
5934
- fs21.readSync(fd, buffer, 0, length, position);
6353
+ fs24.readSync(fd, buffer, 0, length, position);
5935
6354
  let chunk = buffer.toString("utf8");
5936
6355
  if (remainder) {
5937
6356
  chunk += remainder;
@@ -5993,7 +6412,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
5993
6412
  }
5994
6413
  }
5995
6414
  } finally {
5996
- fs21.closeSync(fd);
6415
+ fs24.closeSync(fd);
5997
6416
  }
5998
6417
  return { lines: collected.reverse(), totalLinesCount };
5999
6418
  }
@@ -6036,11 +6455,11 @@ function extractTraceId(obj) {
6036
6455
  function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
6037
6456
  const wanted = traceId.trim();
6038
6457
  if (!wanted) return { lines: [], totalLinesCount: 0 };
6039
- const stat = fs21.statSync(filePath);
6458
+ const stat = fs24.statSync(filePath);
6040
6459
  if (stat.size === 0) {
6041
6460
  return { lines: [], totalLinesCount: 0 };
6042
6461
  }
6043
- const fd = fs21.openSync(filePath, "r");
6462
+ const fd = fs24.openSync(filePath, "r");
6044
6463
  const chunkSize = 64 * 1024;
6045
6464
  let position = stat.size;
6046
6465
  let remainder = "";
@@ -6053,7 +6472,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
6053
6472
  const length = Math.min(chunkSize, position);
6054
6473
  position -= length;
6055
6474
  const buffer = Buffer.alloc(length);
6056
- fs21.readSync(fd, buffer, 0, length, position);
6475
+ fs24.readSync(fd, buffer, 0, length, position);
6057
6476
  let chunk = buffer.toString("utf8");
6058
6477
  if (remainder) {
6059
6478
  chunk += remainder;
@@ -6106,7 +6525,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
6106
6525
  }
6107
6526
  }
6108
6527
  } finally {
6109
- fs21.closeSync(fd);
6528
+ fs24.closeSync(fd);
6110
6529
  }
6111
6530
  return { lines: collected.reverse(), totalLinesCount };
6112
6531
  }
@@ -6115,11 +6534,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
6115
6534
  if (!wantedLevelSet) {
6116
6535
  return { lines: [], totalLinesCount: 0 };
6117
6536
  }
6118
- const stat = fs21.statSync(filePath);
6537
+ const stat = fs24.statSync(filePath);
6119
6538
  if (stat.size === 0) {
6120
6539
  return { lines: [], totalLinesCount: 0 };
6121
6540
  }
6122
- const fd = fs21.openSync(filePath, "r");
6541
+ const fd = fs24.openSync(filePath, "r");
6123
6542
  const chunkSize = 64 * 1024;
6124
6543
  let position = stat.size;
6125
6544
  let remainder = "";
@@ -6131,7 +6550,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
6131
6550
  const length = Math.min(chunkSize, position);
6132
6551
  position -= length;
6133
6552
  const buffer = Buffer.alloc(length);
6134
- fs21.readSync(fd, buffer, 0, length, position);
6553
+ fs24.readSync(fd, buffer, 0, length, position);
6135
6554
  let chunk = buffer.toString("utf8");
6136
6555
  if (remainder) {
6137
6556
  chunk += remainder;
@@ -6178,7 +6597,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
6178
6597
  }
6179
6598
  }
6180
6599
  } finally {
6181
- fs21.closeSync(fd);
6600
+ fs24.closeSync(fd);
6182
6601
  }
6183
6602
  return { lines: collected.reverse(), totalLinesCount };
6184
6603
  }
@@ -6412,34 +6831,34 @@ async function readLogsJsonResult(options) {
6412
6831
  };
6413
6832
  }
6414
6833
  function resolveLogFilePath(logDir, type) {
6415
- const base = path17.isAbsolute(logDir) ? logDir : path17.join(process.cwd(), logDir);
6834
+ const base = path20.isAbsolute(logDir) ? logDir : path20.join(process.cwd(), logDir);
6416
6835
  if (type === "server") {
6417
- return path17.join(base, "server.log");
6836
+ return path20.join(base, "server.log");
6418
6837
  }
6419
6838
  if (type === "trace") {
6420
- return path17.join(base, "trace.log");
6839
+ return path20.join(base, "trace.log");
6421
6840
  }
6422
6841
  if (type === "server-std") {
6423
- return path17.join(base, "server.std.log");
6842
+ return path20.join(base, "server.std.log");
6424
6843
  }
6425
6844
  if (type === "client-std") {
6426
- return path17.join(base, "client.std.log");
6845
+ return path20.join(base, "client.std.log");
6427
6846
  }
6428
6847
  if (type === "dev") {
6429
- return path17.join(base, "dev.log");
6848
+ return path20.join(base, "dev.log");
6430
6849
  }
6431
6850
  if (type === "dev-std") {
6432
- return path17.join(base, "dev.std.log");
6851
+ return path20.join(base, "dev.std.log");
6433
6852
  }
6434
6853
  if (type === "install-dep-std") {
6435
- return path17.join(base, "install-dep.std.log");
6854
+ return path20.join(base, "install-dep.std.log");
6436
6855
  }
6437
6856
  if (type === "browser") {
6438
- return path17.join(base, "browser.log");
6857
+ return path20.join(base, "browser.log");
6439
6858
  }
6440
6859
  throw new Error(`Unsupported log type: ${type}`);
6441
6860
  }
6442
- async function run4(options) {
6861
+ async function run6(options) {
6443
6862
  const result = await readLogsJsonResult(options);
6444
6863
  process.stdout.write(JSON.stringify(result) + "\n");
6445
6864
  }
@@ -6481,7 +6900,7 @@ var readLogsCommand = {
6481
6900
  const offset = parseNonNegativeInt(rawOptions.offset, "--offset");
6482
6901
  const traceId = typeof rawOptions.traceId === "string" ? rawOptions.traceId : void 0;
6483
6902
  const levels = parseCommaSeparatedList(rawOptions.level);
6484
- await run4({ logDir, type, maxLines, offset, traceId, levels });
6903
+ await run6({ logDir, type, maxLines, offset, traceId, levels });
6485
6904
  } catch (error) {
6486
6905
  const message = error instanceof Error ? error.message : String(error);
6487
6906
  process.stderr.write(message + "\n");
@@ -6491,24 +6910,101 @@ var readLogsCommand = {
6491
6910
  }
6492
6911
  };
6493
6912
 
6913
+ // src/commands/build/types.ts
6914
+ var SCENE_CONFIGS = {
6915
+ pipeline: {
6916
+ name: "pipeline",
6917
+ requiredOptions: ["commitId"],
6918
+ buildRequestBody: (opts) => ({ commitID: opts.commitId })
6919
+ },
6920
+ static: {
6921
+ name: "static",
6922
+ requiredOptions: [],
6923
+ buildRequestBody: () => ({ commitID: "" })
6924
+ }
6925
+ };
6926
+
6927
+ // src/commands/build/api-client.ts
6928
+ async function genArtifactUploadCredential(appId, body) {
6929
+ const client = getHttpClient();
6930
+ const url = `/v1/app/${appId}/pipeline/gen_artifact_upload_credential`;
6931
+ const response = await client.post(url, body);
6932
+ if (!response.ok || response.status !== 200) {
6933
+ throw new Error(
6934
+ `API request failed: ${response.status} ${response.statusText}`
6935
+ );
6936
+ }
6937
+ return response.json();
6938
+ }
6939
+
6940
+ // src/commands/build/get-token.handler.ts
6941
+ async function getToken(options) {
6942
+ try {
6943
+ const sceneConfig = SCENE_CONFIGS[options.scene];
6944
+ if (!sceneConfig) {
6945
+ const available = Object.keys(SCENE_CONFIGS).join(", ");
6946
+ console.error(
6947
+ `[build] Error: invalid scene "${options.scene}". Available scenes: ${available}`
6948
+ );
6949
+ process.exit(1);
6950
+ }
6951
+ for (const key of sceneConfig.requiredOptions) {
6952
+ if (!options[key]) {
6953
+ console.error(
6954
+ `[build] Error: --${camelToKebab(key)} is required for scene "${options.scene}"`
6955
+ );
6956
+ process.exit(1);
6957
+ }
6958
+ }
6959
+ const body = sceneConfig.buildRequestBody(options);
6960
+ const response = await genArtifactUploadCredential(options.appId, body);
6961
+ console.log(JSON.stringify(response));
6962
+ } catch (error) {
6963
+ const message = error instanceof Error ? error.message : String(error);
6964
+ console.error(`[build] Error: ${message}`);
6965
+ process.exit(1);
6966
+ }
6967
+ }
6968
+ function camelToKebab(str) {
6969
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
6970
+ }
6971
+
6972
+ // src/commands/build/index.ts
6973
+ var getTokenCommand = {
6974
+ name: "get-token",
6975
+ description: "Get artifact upload credential (STI token)",
6976
+ register(program) {
6977
+ program.command(this.name).description(this.description).requiredOption("--app-id <id>", "Application ID").requiredOption("--scene <scene>", "Build scene (pipeline, static)").option("--commit-id <id>", "Git commit ID (required for pipeline scene)").action(async (options) => {
6978
+ await getToken(options);
6979
+ });
6980
+ }
6981
+ };
6982
+ var buildCommandGroup = {
6983
+ name: "build",
6984
+ description: "Build related commands",
6985
+ commands: [getTokenCommand]
6986
+ };
6987
+
6494
6988
  // src/commands/index.ts
6495
6989
  var commands = [
6496
6990
  genDbSchemaCommand,
6497
6991
  syncCommand,
6992
+ upgradeCommand,
6498
6993
  actionPluginCommandGroup,
6499
6994
  capabilityCommandGroup,
6500
6995
  componentCommandGroup,
6501
6996
  migrationCommand,
6502
- readLogsCommand
6997
+ readLogsCommand,
6998
+ buildCommandGroup
6503
6999
  ];
6504
7000
 
6505
7001
  // src/index.ts
6506
- var envPath = path18.join(process.cwd(), ".env");
6507
- if (fs22.existsSync(envPath)) {
7002
+ var envPath = path21.join(process.cwd(), ".env");
7003
+ if (fs25.existsSync(envPath)) {
6508
7004
  dotenvConfig({ path: envPath });
6509
7005
  }
6510
- var __dirname = path18.dirname(fileURLToPath4(import.meta.url));
6511
- var pkg = JSON.parse(fs22.readFileSync(path18.join(__dirname, "../package.json"), "utf-8"));
7006
+ var __dirname = path21.dirname(fileURLToPath5(import.meta.url));
7007
+ var pkg = JSON.parse(fs25.readFileSync(path21.join(__dirname, "../package.json"), "utf-8"));
6512
7008
  var cli = new FullstackCLI(pkg.version);
6513
7009
  cli.useAll(commands);
6514
7010
  cli.run();