@lark-apaas/fullstack-cli 1.1.71-alpha.20261105115926 → 1.1.71-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -1
- package/dist/index.js +1749 -327
- package/package.json +1 -1
- package/templates/scripts/build.sh +39 -22
- package/templates/scripts/dev.js +0 -12
- package/templates/scripts/prune-smart.js +20 -1
- package/templates/scripts/compile-cache-flush.js +0 -23
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import fs34 from "fs";
|
|
3
|
+
import path27 from "path";
|
|
4
4
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
5
5
|
import { config as dotenvConfig } from "dotenv";
|
|
6
6
|
|
|
@@ -1497,6 +1497,16 @@ async function postprocessDrizzleSchema(targetPath, options = {}) {
|
|
|
1497
1497
|
// src/utils/http-client.ts
|
|
1498
1498
|
import { HttpClient } from "@lark-apaas/http-client";
|
|
1499
1499
|
var clientInstance = null;
|
|
1500
|
+
var adminClientInstance = null;
|
|
1501
|
+
function applyCanaryHeader(client) {
|
|
1502
|
+
const canaryEnv = process.env.FORCE_FRAMEWORK_CLI_CANARY_ENV;
|
|
1503
|
+
if (canaryEnv) {
|
|
1504
|
+
client.interceptors.request.use((req) => {
|
|
1505
|
+
req.headers = { ...req.headers, "x-tt-env": canaryEnv };
|
|
1506
|
+
return req;
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1500
1510
|
function getHttpClient() {
|
|
1501
1511
|
if (!clientInstance) {
|
|
1502
1512
|
clientInstance = new HttpClient({
|
|
@@ -1505,16 +1515,23 @@ function getHttpClient() {
|
|
|
1505
1515
|
enabled: true
|
|
1506
1516
|
}
|
|
1507
1517
|
});
|
|
1508
|
-
|
|
1509
|
-
if (canaryEnv) {
|
|
1510
|
-
clientInstance.interceptors.request.use((req) => {
|
|
1511
|
-
req.headers["x-tt-env"] = canaryEnv;
|
|
1512
|
-
return req;
|
|
1513
|
-
});
|
|
1514
|
-
}
|
|
1518
|
+
applyCanaryHeader(clientInstance);
|
|
1515
1519
|
}
|
|
1516
1520
|
return clientInstance;
|
|
1517
1521
|
}
|
|
1522
|
+
function getAdminHttpClient() {
|
|
1523
|
+
if (!adminClientInstance) {
|
|
1524
|
+
adminClientInstance = new HttpClient({
|
|
1525
|
+
timeout: 3e4,
|
|
1526
|
+
platform: {
|
|
1527
|
+
enabled: true,
|
|
1528
|
+
adminInnerApi: true
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1531
|
+
applyCanaryHeader(adminClientInstance);
|
|
1532
|
+
}
|
|
1533
|
+
return adminClientInstance;
|
|
1534
|
+
}
|
|
1518
1535
|
|
|
1519
1536
|
// src/commands/db/gen-dbschema/utils/fetch-synced-tables.ts
|
|
1520
1537
|
var DEFAULT_TIMEOUT_MS2 = 1e4;
|
|
@@ -4610,172 +4627,21 @@ async function remove(nameWithVersion) {
|
|
|
4610
4627
|
}
|
|
4611
4628
|
}
|
|
4612
4629
|
|
|
4613
|
-
// src/commands/action-plugin/list.handler.ts
|
|
4614
|
-
async function list() {
|
|
4615
|
-
try {
|
|
4616
|
-
const plugins = Object.entries(readActionPlugins());
|
|
4617
|
-
if (plugins.length === 0) {
|
|
4618
|
-
console.log("[action-plugin] No plugins installed");
|
|
4619
|
-
console.log('[action-plugin] Use "action-plugin install <name>" to install a plugin');
|
|
4620
|
-
return;
|
|
4621
|
-
}
|
|
4622
|
-
console.log("[action-plugin] Installed plugins:\n");
|
|
4623
|
-
const nameWidth = Math.max(40, ...plugins.map(([name]) => name.length + 2));
|
|
4624
|
-
const versionWidth = 15;
|
|
4625
|
-
console.log(
|
|
4626
|
-
" " + "Plugin".padEnd(nameWidth) + "Version"
|
|
4627
|
-
);
|
|
4628
|
-
console.log(" " + "-".repeat(nameWidth + versionWidth));
|
|
4629
|
-
for (const [name, version] of plugins) {
|
|
4630
|
-
console.log(
|
|
4631
|
-
" " + name.padEnd(nameWidth) + version
|
|
4632
|
-
);
|
|
4633
|
-
}
|
|
4634
|
-
console.log(`
|
|
4635
|
-
Total: ${plugins.length} plugin(s)`);
|
|
4636
|
-
} catch (error) {
|
|
4637
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
4638
|
-
console.error(`[action-plugin] Failed to list plugins: ${message}`);
|
|
4639
|
-
process.exit(1);
|
|
4640
|
-
}
|
|
4641
|
-
}
|
|
4642
|
-
|
|
4643
|
-
// src/commands/action-plugin/cache.handler.ts
|
|
4644
|
-
async function cacheList() {
|
|
4645
|
-
const cached = listCachedPlugins();
|
|
4646
|
-
if (cached.length === 0) {
|
|
4647
|
-
console.log("[action-plugin] No cached plugins found");
|
|
4648
|
-
return;
|
|
4649
|
-
}
|
|
4650
|
-
console.log("[action-plugin] Cached plugins:\n");
|
|
4651
|
-
console.log(" Name Version Size Modified");
|
|
4652
|
-
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
4653
|
-
let totalSize = 0;
|
|
4654
|
-
for (const plugin of cached) {
|
|
4655
|
-
const name = plugin.name.padEnd(38);
|
|
4656
|
-
const version = plugin.version.padEnd(10);
|
|
4657
|
-
const size = formatSize(plugin.size).padEnd(9);
|
|
4658
|
-
const mtime = plugin.mtime.toISOString().replace("T", " ").slice(0, 19);
|
|
4659
|
-
console.log(` ${name} ${version} ${size} ${mtime}`);
|
|
4660
|
-
totalSize += plugin.size;
|
|
4661
|
-
}
|
|
4662
|
-
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
4663
|
-
console.log(` Total: ${cached.length} cached file(s), ${formatSize(totalSize)}`);
|
|
4664
|
-
}
|
|
4665
|
-
async function cacheClean(pluginName, version) {
|
|
4666
|
-
let count;
|
|
4667
|
-
if (pluginName) {
|
|
4668
|
-
console.log(`[action-plugin] Cleaning cache for ${pluginName}${version ? `@${version}` : ""}...`);
|
|
4669
|
-
count = cleanPluginCache(pluginName, version);
|
|
4670
|
-
if (count === 0) {
|
|
4671
|
-
console.log(`[action-plugin] No cached files found for ${pluginName}${version ? `@${version}` : ""}`);
|
|
4672
|
-
} else {
|
|
4673
|
-
console.log(`[action-plugin] Cleaned ${count} cached file(s)`);
|
|
4674
|
-
}
|
|
4675
|
-
} else {
|
|
4676
|
-
console.log("[action-plugin] Cleaning all cached plugins...");
|
|
4677
|
-
count = cleanAllCache();
|
|
4678
|
-
if (count === 0) {
|
|
4679
|
-
console.log("[action-plugin] No cached files found");
|
|
4680
|
-
} else {
|
|
4681
|
-
console.log(`[action-plugin] Cleaned ${count} cached file(s)`);
|
|
4682
|
-
}
|
|
4683
|
-
}
|
|
4684
|
-
}
|
|
4685
|
-
function formatSize(bytes) {
|
|
4686
|
-
if (bytes < 1024) {
|
|
4687
|
-
return `${bytes} B`;
|
|
4688
|
-
} else if (bytes < 1024 * 1024) {
|
|
4689
|
-
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
4690
|
-
} else {
|
|
4691
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
4692
|
-
}
|
|
4693
|
-
}
|
|
4694
|
-
|
|
4695
|
-
// src/commands/action-plugin/index.ts
|
|
4696
|
-
var initCommand = {
|
|
4697
|
-
name: "init",
|
|
4698
|
-
description: "Install all plugins from package.json",
|
|
4699
|
-
register(program) {
|
|
4700
|
-
program.command(this.name).description(this.description).action(async () => {
|
|
4701
|
-
await init();
|
|
4702
|
-
});
|
|
4703
|
-
}
|
|
4704
|
-
};
|
|
4705
|
-
var installCommand = {
|
|
4706
|
-
name: "install",
|
|
4707
|
-
description: "Install action plugin(s) (default: latest version)",
|
|
4708
|
-
aliases: ["i"],
|
|
4709
|
-
register(program) {
|
|
4710
|
-
program.command(this.name).alias("i").description(this.description).argument("<names...>", "Plugin name(s) (e.g., @office/feishu-create-group or @office/feishu-create-group@1.0.0)").action(async (names) => {
|
|
4711
|
-
await install(names);
|
|
4712
|
-
});
|
|
4713
|
-
}
|
|
4714
|
-
};
|
|
4715
|
-
var updateCommand = {
|
|
4716
|
-
name: "update",
|
|
4717
|
-
description: "Update action plugin(s) to the latest version",
|
|
4718
|
-
aliases: ["up"],
|
|
4719
|
-
register(program) {
|
|
4720
|
-
program.command(this.name).alias("up").description(this.description).argument("<names...>", "Plugin name(s) (e.g., @office/feishu-create-group)").action(async (names) => {
|
|
4721
|
-
await update(names);
|
|
4722
|
-
});
|
|
4723
|
-
}
|
|
4724
|
-
};
|
|
4725
|
-
var removeCommand = {
|
|
4726
|
-
name: "remove",
|
|
4727
|
-
description: "Remove an installed action plugin",
|
|
4728
|
-
aliases: ["rm"],
|
|
4729
|
-
register(program) {
|
|
4730
|
-
program.command(this.name).alias("rm").description(this.description).argument("<name>", "Plugin name (e.g., @office/feishu-create-group)").action(async (name) => {
|
|
4731
|
-
await remove(name);
|
|
4732
|
-
});
|
|
4733
|
-
}
|
|
4734
|
-
};
|
|
4735
|
-
var listCommand = {
|
|
4736
|
-
name: "list",
|
|
4737
|
-
description: "List all installed action plugins",
|
|
4738
|
-
aliases: ["ls"],
|
|
4739
|
-
register(program) {
|
|
4740
|
-
program.command(this.name).alias("ls").description(this.description).action(async () => {
|
|
4741
|
-
await list();
|
|
4742
|
-
});
|
|
4743
|
-
}
|
|
4744
|
-
};
|
|
4745
|
-
var cacheListCommand = {
|
|
4746
|
-
name: "cache-list",
|
|
4747
|
-
description: "List all cached plugin packages",
|
|
4748
|
-
register(program) {
|
|
4749
|
-
program.command(this.name).description(this.description).action(async () => {
|
|
4750
|
-
await cacheList();
|
|
4751
|
-
});
|
|
4752
|
-
}
|
|
4753
|
-
};
|
|
4754
|
-
var cacheCleanCommand = {
|
|
4755
|
-
name: "cache-clean",
|
|
4756
|
-
description: "Clean cached plugin packages",
|
|
4757
|
-
register(program) {
|
|
4758
|
-
program.command(this.name).description(this.description).argument("[name]", "Plugin name to clean (e.g., @office/feishu-create-group). If not provided, clean all cache.").option("-v, --version <version>", "Specific version to clean").action(async (name, options) => {
|
|
4759
|
-
await cacheClean(name, options.version);
|
|
4760
|
-
});
|
|
4761
|
-
}
|
|
4762
|
-
};
|
|
4763
|
-
var actionPluginCommandGroup = {
|
|
4764
|
-
name: "action-plugin",
|
|
4765
|
-
description: "Manage action plugins",
|
|
4766
|
-
commands: [initCommand, installCommand, updateCommand, removeCommand, listCommand, cacheListCommand, cacheCleanCommand]
|
|
4767
|
-
};
|
|
4768
|
-
|
|
4769
4630
|
// src/commands/capability/utils.ts
|
|
4770
4631
|
import fs17 from "fs";
|
|
4771
4632
|
import { createRequire as createRequire2 } from "module";
|
|
4772
4633
|
import path14 from "path";
|
|
4773
4634
|
var CAPABILITIES_DIR = "server/capabilities";
|
|
4774
4635
|
var SHARED_CAPABILITIES_DIR = "shared/capabilities";
|
|
4636
|
+
var CAPABILITIES_DIR_ENV = "CAPABILITIES_DIR";
|
|
4775
4637
|
function getProjectRoot2() {
|
|
4776
4638
|
return process.cwd();
|
|
4777
4639
|
}
|
|
4778
4640
|
function getCapabilitiesDir() {
|
|
4641
|
+
const fromEnv = process.env[CAPABILITIES_DIR_ENV]?.trim();
|
|
4642
|
+
if (fromEnv) {
|
|
4643
|
+
return path14.resolve(getProjectRoot2(), fromEnv.replace(/\/+$/, ""));
|
|
4644
|
+
}
|
|
4779
4645
|
const sharedDir = path14.join(getProjectRoot2(), SHARED_CAPABILITIES_DIR);
|
|
4780
4646
|
if (fs17.existsSync(sharedDir)) {
|
|
4781
4647
|
return sharedDir;
|
|
@@ -4950,74 +4816,1630 @@ function logError(message) {
|
|
|
4950
4816
|
console.error(`[capability] Error: ${message}`);
|
|
4951
4817
|
}
|
|
4952
4818
|
|
|
4953
|
-
// src/commands/
|
|
4954
|
-
|
|
4819
|
+
// src/commands/action-plugin/form-context.ts
|
|
4820
|
+
import fs19 from "fs";
|
|
4821
|
+
|
|
4822
|
+
// src/commands/action-plugin/form-errors.ts
|
|
4823
|
+
import fs18 from "fs";
|
|
4824
|
+
var FormCliErrorCode = {
|
|
4825
|
+
PLUGIN_NOT_INSTALLED: "PLUGIN_NOT_INSTALLED",
|
|
4826
|
+
PLUGIN_SDK_TOO_OLD: "PLUGIN_SDK_TOO_OLD",
|
|
4827
|
+
PLUGIN_VERSION_MISMATCH: "PLUGIN_VERSION_MISMATCH",
|
|
4828
|
+
/** 插件包在 node_modules 里但 import 失败(spec 未列,执行层补充) */
|
|
4829
|
+
PLUGIN_LOAD_FAILED: "PLUGIN_LOAD_FAILED",
|
|
4830
|
+
FORM_ACTION_NOT_FOUND: "FORM_ACTION_NOT_FOUND",
|
|
4831
|
+
INSTANCE_MISMATCH: "INSTANCE_MISMATCH",
|
|
4832
|
+
/** capability create:目标 id 已存在,不覆盖 */
|
|
4833
|
+
INSTANCE_EXISTS: "INSTANCE_EXISTS",
|
|
4834
|
+
/** capability update / --id:目标实例不存在 */
|
|
4835
|
+
INSTANCE_NOT_FOUND: "INSTANCE_NOT_FOUND",
|
|
4836
|
+
CONTEXT_UNAVAILABLE: "CONTEXT_UNAVAILABLE",
|
|
4837
|
+
VALIDATION_EXECUTION_FAILED: "VALIDATION_EXECUTION_FAILED",
|
|
4838
|
+
/** 插件保存前检查返回 success:false;插件自己的问题标识只在 issues[].code 里 */
|
|
4839
|
+
VALIDATION_FAILED: "VALIDATION_FAILED",
|
|
4840
|
+
EXECUTION_TIMEOUT: "EXECUTION_TIMEOUT",
|
|
4841
|
+
/** 命令行入参(文件 / 选项)不合法;与 SDK 入参校验失败共用同一码 */
|
|
4842
|
+
INVALID_INPUT: "INVALID_INPUT"
|
|
4843
|
+
};
|
|
4844
|
+
var FormCliError = class _FormCliError extends Error {
|
|
4845
|
+
constructor(code, message, options = {}) {
|
|
4846
|
+
super(message);
|
|
4847
|
+
this.name = "FormCliError";
|
|
4848
|
+
this.code = code;
|
|
4849
|
+
this.hint = options.hint;
|
|
4850
|
+
this.details = options.details;
|
|
4851
|
+
this.issues = options.issues;
|
|
4852
|
+
Object.setPrototypeOf(this, _FormCliError.prototype);
|
|
4853
|
+
}
|
|
4854
|
+
};
|
|
4855
|
+
function isPluginError(error) {
|
|
4856
|
+
if (!error || typeof error !== "object") {
|
|
4857
|
+
return false;
|
|
4858
|
+
}
|
|
4859
|
+
const candidate = error;
|
|
4860
|
+
return candidate.name === "PluginError" && typeof candidate.code === "string";
|
|
4861
|
+
}
|
|
4862
|
+
function toFailureOutput(error, fallbackCode, pluginErrorHint) {
|
|
4863
|
+
if (error instanceof FormCliError) {
|
|
4864
|
+
const output = {
|
|
4865
|
+
ok: false,
|
|
4866
|
+
code: error.code,
|
|
4867
|
+
message: error.message
|
|
4868
|
+
};
|
|
4869
|
+
if (error.hint !== void 0) output.hint = error.hint;
|
|
4870
|
+
if (error.details !== void 0) output.details = error.details;
|
|
4871
|
+
if (error.issues !== void 0) output.issues = error.issues;
|
|
4872
|
+
return output;
|
|
4873
|
+
}
|
|
4874
|
+
if (isPluginError(error)) {
|
|
4875
|
+
const output = {
|
|
4876
|
+
ok: false,
|
|
4877
|
+
code: error.code,
|
|
4878
|
+
message: error.message
|
|
4879
|
+
};
|
|
4880
|
+
const hint = pluginErrorHint?.(error.code);
|
|
4881
|
+
if (hint !== void 0) output.hint = hint;
|
|
4882
|
+
if (error.details !== void 0) output.details = error.details;
|
|
4883
|
+
return output;
|
|
4884
|
+
}
|
|
4885
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4886
|
+
return { ok: false, code: fallbackCode, message };
|
|
4887
|
+
}
|
|
4888
|
+
function finishWithJson(data, exitCode) {
|
|
4889
|
+
process.stdout.write(`${JSON.stringify(data, null, 2)}
|
|
4890
|
+
`, () => {
|
|
4891
|
+
process.exit(exitCode);
|
|
4892
|
+
});
|
|
4893
|
+
}
|
|
4894
|
+
function withTimeout(promise, timeoutMs, what) {
|
|
4895
|
+
return new Promise((resolve2, reject) => {
|
|
4896
|
+
const timer = setTimeout(() => {
|
|
4897
|
+
reject(
|
|
4898
|
+
new FormCliError(
|
|
4899
|
+
FormCliErrorCode.EXECUTION_TIMEOUT,
|
|
4900
|
+
`${what} timed out after ${timeoutMs}ms`,
|
|
4901
|
+
{
|
|
4902
|
+
hint: `Retry later, or pass a larger --timeout (current: ${timeoutMs} ms).`,
|
|
4903
|
+
details: { timeoutMs }
|
|
4904
|
+
}
|
|
4905
|
+
)
|
|
4906
|
+
);
|
|
4907
|
+
}, timeoutMs);
|
|
4908
|
+
promise.then(
|
|
4909
|
+
(value) => {
|
|
4910
|
+
clearTimeout(timer);
|
|
4911
|
+
resolve2(value);
|
|
4912
|
+
},
|
|
4913
|
+
(error) => {
|
|
4914
|
+
clearTimeout(timer);
|
|
4915
|
+
reject(error);
|
|
4916
|
+
}
|
|
4917
|
+
);
|
|
4918
|
+
});
|
|
4919
|
+
}
|
|
4920
|
+
var DEFAULT_TIMEOUT_MS3 = 6e4;
|
|
4921
|
+
function parseTimeout(raw) {
|
|
4922
|
+
if (raw === void 0 || raw === "") {
|
|
4923
|
+
return DEFAULT_TIMEOUT_MS3;
|
|
4924
|
+
}
|
|
4925
|
+
const value = typeof raw === "number" ? raw : Number(raw);
|
|
4926
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
4927
|
+
throw new FormCliError(
|
|
4928
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
4929
|
+
`--timeout must be a positive integer (ms), got: ${raw}`
|
|
4930
|
+
);
|
|
4931
|
+
}
|
|
4932
|
+
return value;
|
|
4933
|
+
}
|
|
4934
|
+
function readJsonFile(filePath, label) {
|
|
4935
|
+
if (!fs18.existsSync(filePath)) {
|
|
4936
|
+
throw new FormCliError(
|
|
4937
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
4938
|
+
`${label} not found: ${filePath}`
|
|
4939
|
+
);
|
|
4940
|
+
}
|
|
4941
|
+
let content;
|
|
4955
4942
|
try {
|
|
4956
|
-
|
|
4957
|
-
logError("capabilities directory not found (looked for shared/capabilities and server/capabilities)");
|
|
4958
|
-
process.exit(1);
|
|
4959
|
-
}
|
|
4960
|
-
if (options.id) {
|
|
4961
|
-
await listSingle(options.id, options.summary);
|
|
4962
|
-
} else {
|
|
4963
|
-
await listAll(options.summary);
|
|
4964
|
-
}
|
|
4943
|
+
content = fs18.readFileSync(filePath, "utf-8");
|
|
4965
4944
|
} catch (error) {
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4945
|
+
throw new FormCliError(
|
|
4946
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
4947
|
+
`Failed to read ${label} ${filePath}: ${error instanceof Error ? error.message : String(error)}`
|
|
4948
|
+
);
|
|
4949
|
+
}
|
|
4950
|
+
try {
|
|
4951
|
+
return JSON.parse(content);
|
|
4952
|
+
} catch {
|
|
4953
|
+
throw new FormCliError(
|
|
4954
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
4955
|
+
`${label} is not valid JSON: ${filePath}`
|
|
4956
|
+
);
|
|
4969
4957
|
}
|
|
4970
4958
|
}
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4959
|
+
function parseJsonText(text, label) {
|
|
4960
|
+
try {
|
|
4961
|
+
return JSON.parse(text);
|
|
4962
|
+
} catch (error) {
|
|
4963
|
+
throw new FormCliError(
|
|
4964
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
4965
|
+
`${label} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
4966
|
+
);
|
|
4978
4967
|
}
|
|
4979
4968
|
}
|
|
4980
|
-
|
|
4981
|
-
const
|
|
4982
|
-
if (
|
|
4983
|
-
|
|
4984
|
-
|
|
4969
|
+
function assertSingleStdinArg(args) {
|
|
4970
|
+
const stdinFlags = Object.keys(args).filter((flag) => args[flag] === "-");
|
|
4971
|
+
if (stdinFlags.length > 1) {
|
|
4972
|
+
throw new FormCliError(
|
|
4973
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
4974
|
+
`Only one argument can read from stdin ("-"), got: ${stdinFlags.join(", ")}`
|
|
4975
|
+
);
|
|
4985
4976
|
}
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4977
|
+
}
|
|
4978
|
+
function readJsonArg(raw, flag) {
|
|
4979
|
+
if (raw === "-") {
|
|
4980
|
+
let content;
|
|
4981
|
+
try {
|
|
4982
|
+
content = fs18.readFileSync(0, "utf-8");
|
|
4983
|
+
} catch (error) {
|
|
4984
|
+
throw new FormCliError(
|
|
4985
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
4986
|
+
`Failed to read ${flag} from stdin: ${error instanceof Error ? error.message : String(error)}`
|
|
4987
|
+
);
|
|
4993
4988
|
}
|
|
4994
|
-
|
|
4989
|
+
return parseJsonText(content, `${flag} (stdin)`);
|
|
4995
4990
|
}
|
|
4991
|
+
if (raw.startsWith("@")) {
|
|
4992
|
+
return readJsonFile(raw.slice(1), `${flag} file`);
|
|
4993
|
+
}
|
|
4994
|
+
return parseJsonText(raw, flag);
|
|
4996
4995
|
}
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
4996
|
+
function readJsonObjectArg(raw, flag) {
|
|
4997
|
+
const value = readJsonArg(raw, flag);
|
|
4998
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
4999
|
+
throw new FormCliError(
|
|
5000
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
5001
|
+
`${flag} must be a JSON object`
|
|
5002
|
+
);
|
|
5003
|
+
}
|
|
5004
|
+
return value;
|
|
5005
|
+
}
|
|
5006
|
+
function outputParseErrorsAsJson(command) {
|
|
5007
|
+
const target = command;
|
|
5008
|
+
target._outputConfiguration = { ...target._outputConfiguration };
|
|
5009
|
+
return command.configureOutput({
|
|
5010
|
+
outputError: (str) => {
|
|
5011
|
+
const usage = [command.parent?.name(), command.name()].filter(Boolean).join(" ");
|
|
5012
|
+
const output = {
|
|
5013
|
+
ok: false,
|
|
5014
|
+
code: FormCliErrorCode.INVALID_INPUT,
|
|
5015
|
+
message: str.replace(/^error:\s*/, "").trim(),
|
|
5016
|
+
hint: `Run "fullstack-cli ${usage} --help" for usage.`
|
|
5017
|
+
};
|
|
5018
|
+
fs18.writeSync(1, `${JSON.stringify(output, null, 2)}
|
|
5019
|
+
`);
|
|
5020
|
+
}
|
|
5021
|
+
});
|
|
5022
|
+
}
|
|
5023
|
+
function camelToKebab(name) {
|
|
5024
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
5025
|
+
}
|
|
5026
|
+
function kebabToCamel(name) {
|
|
5027
|
+
return name.replace(/-([a-zA-Z0-9])/g, (_, ch) => ch.toUpperCase());
|
|
5028
|
+
}
|
|
5029
|
+
function resolveFormActionKey(input, keys) {
|
|
5030
|
+
if (keys.includes(input)) {
|
|
5031
|
+
return input;
|
|
5032
|
+
}
|
|
5033
|
+
const camel = kebabToCamel(input);
|
|
5034
|
+
if (keys.includes(camel)) {
|
|
5035
|
+
return camel;
|
|
5036
|
+
}
|
|
5037
|
+
return keys.find((key) => camelToKebab(key) === input);
|
|
5038
|
+
}
|
|
5039
|
+
|
|
5040
|
+
// src/commands/action-plugin/form-context.ts
|
|
5041
|
+
var AUTHN_CODE_ENV = "MIAODA_AUTHN_CODE";
|
|
5042
|
+
var ACCESS_KEY_ENV = "FORCE_AUTHN_ACCESS_KEY";
|
|
5043
|
+
function parseTenantIdFromAccessKey(accessKey) {
|
|
5044
|
+
if (!accessKey) {
|
|
5045
|
+
return void 0;
|
|
5046
|
+
}
|
|
5047
|
+
const firstUnderscore = accessKey.indexOf("_");
|
|
5048
|
+
const lastUnderscore = accessKey.lastIndexOf("_");
|
|
5049
|
+
if (firstUnderscore <= 0 || lastUnderscore === firstUnderscore) {
|
|
5050
|
+
return void 0;
|
|
5051
|
+
}
|
|
5052
|
+
return accessKey.slice(0, firstUnderscore);
|
|
5053
|
+
}
|
|
5054
|
+
function assertOperatorCredential(env = process.env) {
|
|
5055
|
+
if (!env[AUTHN_CODE_ENV]) {
|
|
5056
|
+
throw new FormCliError(
|
|
5057
|
+
FormCliErrorCode.CONTEXT_UNAVAILABLE,
|
|
5058
|
+
`Operator credential is unavailable: environment variable ${AUTHN_CODE_ENV} is not set`,
|
|
5059
|
+
{
|
|
5060
|
+
hint: `This command calls the platform as the current operator. Run it through the platform's command execution (agent_tool), which injects ${AUTHN_CODE_ENV}; it cannot run in a plain terminal.`
|
|
5061
|
+
}
|
|
5062
|
+
);
|
|
5063
|
+
}
|
|
5064
|
+
}
|
|
5065
|
+
function readUserContext(env = process.env) {
|
|
5066
|
+
const project = readProjectIdentity();
|
|
5067
|
+
return {
|
|
5068
|
+
userId: "",
|
|
5069
|
+
tenantId: project.tenantId || parseTenantIdFromAccessKey(env[ACCESS_KEY_ENV]) || "",
|
|
5070
|
+
appId: project.appId || ""
|
|
5071
|
+
};
|
|
5072
|
+
}
|
|
5073
|
+
function createStderrLogger(prefix) {
|
|
5074
|
+
const write = (level, args) => {
|
|
5075
|
+
console.error(`[${prefix}] [${level}]`, ...args);
|
|
5076
|
+
};
|
|
5077
|
+
return {
|
|
5078
|
+
log: (...args) => write("log", args),
|
|
5079
|
+
error: (...args) => write("error", args),
|
|
5080
|
+
warn: (...args) => write("warn", args),
|
|
5081
|
+
debug: (...args) => write("debug", args)
|
|
5082
|
+
};
|
|
5083
|
+
}
|
|
5084
|
+
function readMatchingCapability(instanceId, pluginKey) {
|
|
5085
|
+
if (!fs19.existsSync(getCapabilityPath(instanceId))) {
|
|
5086
|
+
throw new FormCliError(
|
|
5087
|
+
FormCliErrorCode.INSTANCE_NOT_FOUND,
|
|
5088
|
+
`Capability instance ${instanceId} not found`,
|
|
5089
|
+
{
|
|
5090
|
+
hint: 'Check the id with "fullstack-cli capability list --summary", or omit --id when creating a new instance.'
|
|
5091
|
+
}
|
|
5092
|
+
);
|
|
5093
|
+
}
|
|
5094
|
+
let capability;
|
|
5095
|
+
try {
|
|
5096
|
+
capability = readCapability(instanceId);
|
|
5097
|
+
} catch (error) {
|
|
5098
|
+
throw new FormCliError(
|
|
5099
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
5100
|
+
`Capability instance ${instanceId} cannot be read: ${error instanceof Error ? error.message : String(error)}`
|
|
5101
|
+
);
|
|
5102
|
+
}
|
|
5103
|
+
if (capability.pluginKey !== pluginKey) {
|
|
5104
|
+
throw new FormCliError(
|
|
5105
|
+
FormCliErrorCode.INSTANCE_MISMATCH,
|
|
5106
|
+
`Capability instance ${instanceId} belongs to plugin ${capability.pluginKey}, not ${pluginKey}`,
|
|
5107
|
+
{
|
|
5108
|
+
hint: `Use --plugin ${capability.pluginKey}, or pick an instance of ${pluginKey}.`,
|
|
5109
|
+
details: {
|
|
5110
|
+
instancePluginKey: capability.pluginKey,
|
|
5111
|
+
requestedPluginKey: pluginKey
|
|
5112
|
+
}
|
|
5113
|
+
}
|
|
5114
|
+
);
|
|
5115
|
+
}
|
|
5116
|
+
return capability;
|
|
5117
|
+
}
|
|
5118
|
+
function buildFormActionContext(options) {
|
|
5119
|
+
assertOperatorCredential();
|
|
5120
|
+
const ctx = {
|
|
5121
|
+
userContext: readUserContext(),
|
|
5122
|
+
logger: createStderrLogger(options.pluginKey),
|
|
5123
|
+
platformHttpClient: getAdminHttpClient(),
|
|
5124
|
+
isDebug: false
|
|
5125
|
+
};
|
|
5126
|
+
if (options.formValue !== void 0) {
|
|
5127
|
+
ctx.formValue = options.formValue;
|
|
5128
|
+
}
|
|
5129
|
+
if (options.instanceId !== void 0) {
|
|
5130
|
+
ctx.instanceId = options.instanceId;
|
|
5131
|
+
}
|
|
5132
|
+
return ctx;
|
|
5133
|
+
}
|
|
5134
|
+
|
|
5135
|
+
// src/commands/action-plugin/plugin-resolve.ts
|
|
5136
|
+
function checkInstalledVersion(pluginKey) {
|
|
5137
|
+
const installedVersion = getPackageVersion(pluginKey);
|
|
5138
|
+
if (!installedVersion) {
|
|
5139
|
+
throw new FormCliError(
|
|
5140
|
+
FormCliErrorCode.PLUGIN_NOT_INSTALLED,
|
|
5141
|
+
`Plugin ${pluginKey} is not installed in node_modules`,
|
|
5142
|
+
{ hint: `Run "fullstack-cli action-plugin install ${pluginKey}" first.` }
|
|
5143
|
+
);
|
|
5144
|
+
}
|
|
5145
|
+
let declaredVersion;
|
|
5146
|
+
try {
|
|
5147
|
+
declaredVersion = readActionPlugins()[pluginKey];
|
|
5148
|
+
} catch (error) {
|
|
5149
|
+
throw new FormCliError(
|
|
5150
|
+
FormCliErrorCode.PLUGIN_NOT_INSTALLED,
|
|
5151
|
+
`Cannot read package.json actionPlugins: ${error instanceof Error ? error.message : String(error)}`,
|
|
5152
|
+
{
|
|
5153
|
+
hint: "Run the command in the project root (the directory containing package.json)."
|
|
5154
|
+
}
|
|
5155
|
+
);
|
|
5156
|
+
}
|
|
5157
|
+
if (!declaredVersion) {
|
|
5158
|
+
throw new FormCliError(
|
|
5159
|
+
FormCliErrorCode.PLUGIN_NOT_INSTALLED,
|
|
5160
|
+
`Plugin ${pluginKey} is not recorded in package.json actionPlugins`,
|
|
5161
|
+
{
|
|
5162
|
+
hint: `Run "fullstack-cli action-plugin install ${pluginKey}" first.`,
|
|
5163
|
+
details: { installedVersion }
|
|
5164
|
+
}
|
|
5165
|
+
);
|
|
5166
|
+
}
|
|
5167
|
+
if (declaredVersion !== installedVersion) {
|
|
5168
|
+
throw new FormCliError(
|
|
5169
|
+
FormCliErrorCode.PLUGIN_VERSION_MISMATCH,
|
|
5170
|
+
`Plugin ${pluginKey} version mismatch: package.json actionPlugins declares ${declaredVersion}, node_modules has ${installedVersion}`,
|
|
5171
|
+
{
|
|
5172
|
+
hint: `To use the declared version, run "fullstack-cli action-plugin install ${pluginKey}@${declaredVersion}"; to keep ${installedVersion}, run "fullstack-cli action-plugin install ${pluginKey}@${installedVersion}" so package.json records it.`,
|
|
5173
|
+
details: { declaredVersion, installedVersion }
|
|
5174
|
+
}
|
|
5175
|
+
);
|
|
5176
|
+
}
|
|
5177
|
+
return installedVersion;
|
|
5178
|
+
}
|
|
5179
|
+
function readInstalledManifest(pluginKey) {
|
|
5180
|
+
try {
|
|
5181
|
+
return readPluginManifest(pluginKey);
|
|
5182
|
+
} catch (error) {
|
|
5183
|
+
throw new FormCliError(
|
|
5184
|
+
FormCliErrorCode.PLUGIN_NOT_INSTALLED,
|
|
5185
|
+
error instanceof Error ? error.message : String(error)
|
|
5186
|
+
);
|
|
5187
|
+
}
|
|
5188
|
+
}
|
|
5189
|
+
async function resolveInstalledPlugin(pluginKey) {
|
|
5190
|
+
const version = checkInstalledVersion(pluginKey);
|
|
5191
|
+
const manifest = readInstalledManifest(pluginKey);
|
|
5192
|
+
let module;
|
|
5193
|
+
try {
|
|
5194
|
+
module = await loadPlugin(pluginKey);
|
|
5195
|
+
} catch (error) {
|
|
5196
|
+
throw new FormCliError(
|
|
5197
|
+
FormCliErrorCode.PLUGIN_LOAD_FAILED,
|
|
5198
|
+
`Failed to load plugin ${pluginKey} from node_modules: ${error instanceof Error ? error.message : String(error)}`,
|
|
5199
|
+
{
|
|
5200
|
+
hint: `Reinstall it with "fullstack-cli action-plugin install ${pluginKey}"; if it still fails, the plugin package is broken.`
|
|
5201
|
+
}
|
|
5202
|
+
);
|
|
5203
|
+
}
|
|
5204
|
+
return { key: pluginKey, version, manifest, module };
|
|
5205
|
+
}
|
|
5206
|
+
var SDK_TOO_OLD_HINT = (pluginKey) => `Run "fullstack-cli action-plugin update ${pluginKey}" to get the latest version; if it still fails, this plugin does not support form actions or validateForm.`;
|
|
5207
|
+
function hasFormActionSdk(module) {
|
|
5208
|
+
return typeof module.runFormAction === "function" && typeof module.validateForm === "function" && typeof module.hasValidateForm === "function";
|
|
5209
|
+
}
|
|
5210
|
+
function assertFormActionSdk(module, pluginKey) {
|
|
5211
|
+
if (!hasFormActionSdk(module)) {
|
|
5212
|
+
throw new FormCliError(
|
|
5213
|
+
FormCliErrorCode.PLUGIN_SDK_TOO_OLD,
|
|
5214
|
+
`Plugin ${pluginKey} was built with an SDK that has no form action support (runFormAction / validateForm / hasValidateForm missing)`,
|
|
5215
|
+
{ hint: SDK_TOO_OLD_HINT(pluginKey) }
|
|
5216
|
+
);
|
|
5217
|
+
}
|
|
5218
|
+
}
|
|
5219
|
+
|
|
5220
|
+
// src/commands/action-plugin/form-action.handler.ts
|
|
5221
|
+
function pickLocalizedText(text) {
|
|
5222
|
+
if (text === void 0 || text === null) {
|
|
5223
|
+
return void 0;
|
|
5224
|
+
}
|
|
5225
|
+
if (typeof text === "string") {
|
|
5226
|
+
return text;
|
|
5227
|
+
}
|
|
5228
|
+
return text["zh-CN"] ?? text["en-US"] ?? Object.values(text).find((v) => typeof v === "string");
|
|
5229
|
+
}
|
|
5230
|
+
function summarize(action) {
|
|
5231
|
+
const summary = {
|
|
5232
|
+
key: action.key,
|
|
5233
|
+
alias: camelToKebab(action.key)
|
|
5234
|
+
};
|
|
5235
|
+
const title = pickLocalizedText(action.title);
|
|
5236
|
+
const description = pickLocalizedText(action.description);
|
|
5237
|
+
if (title !== void 0) summary.title = title;
|
|
5238
|
+
if (description !== void 0) summary.description = description;
|
|
5239
|
+
return summary;
|
|
5240
|
+
}
|
|
5241
|
+
function describeFormActions(pluginKey) {
|
|
5242
|
+
const manifest = readInstalledManifest(pluginKey);
|
|
5243
|
+
const description = {
|
|
5244
|
+
key: pluginKey,
|
|
5245
|
+
version: getPackageVersion(pluginKey),
|
|
5246
|
+
formActions: (manifest.formActions ?? []).map(summarize),
|
|
5247
|
+
hasValidateForm: manifest.hasValidateForm === true
|
|
5248
|
+
};
|
|
5249
|
+
if (!Array.isArray(manifest.formActions)) {
|
|
5250
|
+
description.hint = `Plugin ${pluginKey} manifest has no formActions field. Upgrade the plugin to a version built with the formActions-capable SDK.`;
|
|
5251
|
+
}
|
|
5252
|
+
return description;
|
|
5253
|
+
}
|
|
5254
|
+
function findFormAction(pluginKey, action, formActions) {
|
|
5255
|
+
const keys = formActions.map((fa) => fa.key);
|
|
5256
|
+
const resolvedKey = resolveFormActionKey(action, keys);
|
|
5257
|
+
const found = resolvedKey ? formActions.find((fa) => fa.key === resolvedKey) : void 0;
|
|
5258
|
+
if (!found) {
|
|
5259
|
+
throw new FormCliError(
|
|
5260
|
+
FormCliErrorCode.FORM_ACTION_NOT_FOUND,
|
|
5261
|
+
`Form action "${action}" not found in plugin ${pluginKey}. Available: ${keys.length ? keys.join(", ") : "(none)"}`,
|
|
5262
|
+
{
|
|
5263
|
+
hint: keys.length ? "Use one of details.available as --action." : `Plugin ${pluginKey} has no form actions; upgrade it with "fullstack-cli action-plugin update ${pluginKey}" if a newer version adds them.`,
|
|
5264
|
+
details: { available: keys }
|
|
5265
|
+
}
|
|
5266
|
+
);
|
|
5267
|
+
}
|
|
5268
|
+
return found;
|
|
5269
|
+
}
|
|
5270
|
+
function describeFormAction(pluginKey, action) {
|
|
5271
|
+
const manifest = readInstalledManifest(pluginKey);
|
|
5272
|
+
const found = findFormAction(pluginKey, action, manifest.formActions ?? []);
|
|
5273
|
+
const summary = summarize(found);
|
|
5274
|
+
return {
|
|
5275
|
+
key: pluginKey,
|
|
5276
|
+
version: getPackageVersion(pluginKey),
|
|
5277
|
+
action: {
|
|
5278
|
+
...summary,
|
|
5279
|
+
inputSchema: found.inputSchema ?? {},
|
|
5280
|
+
...found.outputSchema ? { outputSchema: found.outputSchema } : {}
|
|
5281
|
+
}
|
|
5282
|
+
};
|
|
5283
|
+
}
|
|
5284
|
+
async function executeFormAction(options) {
|
|
5285
|
+
const timeoutMs = parseTimeout(options.timeout);
|
|
5286
|
+
assertSingleStdinArg({
|
|
5287
|
+
"--input": options.input,
|
|
5288
|
+
"--form-value": options.formValue
|
|
5289
|
+
});
|
|
5290
|
+
const input = readJsonArg(options.input, "--input");
|
|
5291
|
+
const resolved = await resolveInstalledPlugin(options.pluginKey);
|
|
5292
|
+
const formAction = findFormAction(
|
|
5293
|
+
options.pluginKey,
|
|
5294
|
+
options.action,
|
|
5295
|
+
resolved.manifest.formActions ?? []
|
|
5296
|
+
);
|
|
5297
|
+
assertFormActionSdk(resolved.module, options.pluginKey);
|
|
5298
|
+
let formValue;
|
|
5299
|
+
if (options.instanceId) {
|
|
5300
|
+
formValue = readMatchingCapability(
|
|
5301
|
+
options.instanceId,
|
|
5302
|
+
options.pluginKey
|
|
5303
|
+
).formValue;
|
|
5304
|
+
}
|
|
5305
|
+
if (options.formValue !== void 0) {
|
|
5306
|
+
formValue = readJsonObjectArg(options.formValue, "--form-value");
|
|
5307
|
+
}
|
|
5308
|
+
const ctx = buildFormActionContext({
|
|
5309
|
+
pluginKey: options.pluginKey,
|
|
5310
|
+
instanceId: options.instanceId,
|
|
5311
|
+
formValue
|
|
5312
|
+
});
|
|
5313
|
+
return withTimeout(
|
|
5314
|
+
resolved.module.runFormAction(formAction.key, ctx, input),
|
|
5315
|
+
timeoutMs,
|
|
5316
|
+
`form action ${formAction.key}`
|
|
5317
|
+
);
|
|
5318
|
+
}
|
|
5319
|
+
function printFormActionsText(description) {
|
|
5320
|
+
const lines = [];
|
|
5321
|
+
lines.push(
|
|
5322
|
+
`Plugin: ${description.key}${description.version ? ` (v${description.version})` : ""}`
|
|
5323
|
+
);
|
|
5324
|
+
lines.push(`validateForm: ${description.hasValidateForm ? "yes" : "no"}`);
|
|
5325
|
+
lines.push("");
|
|
5326
|
+
if (description.formActions.length === 0) {
|
|
5327
|
+
lines.push("No form actions.");
|
|
5328
|
+
} else {
|
|
5329
|
+
lines.push("Form actions:");
|
|
5330
|
+
for (const fa of description.formActions) {
|
|
5331
|
+
const label = fa.alias === fa.key ? fa.key : `${fa.alias} (${fa.key})`;
|
|
5332
|
+
const text = fa.title ?? fa.description ?? "";
|
|
5333
|
+
lines.push(` ${label.padEnd(40)}${text}`);
|
|
5334
|
+
}
|
|
5335
|
+
lines.push("");
|
|
5336
|
+
lines.push(
|
|
5337
|
+
`Run "fullstack-cli action-plugin form-action-get --plugin ${description.key} --action <action>" for input/output schema.`
|
|
5338
|
+
);
|
|
5339
|
+
}
|
|
5340
|
+
if (description.hint) {
|
|
5341
|
+
lines.push("");
|
|
5342
|
+
lines.push(`Note: ${description.hint}`);
|
|
5343
|
+
}
|
|
5344
|
+
console.log(lines.join("\n"));
|
|
5345
|
+
}
|
|
5346
|
+
function printFormActionText(description) {
|
|
5347
|
+
const { action } = description;
|
|
5348
|
+
const lines = [];
|
|
5349
|
+
lines.push(
|
|
5350
|
+
`Plugin: ${description.key}${description.version ? ` (v${description.version})` : ""}`
|
|
5351
|
+
);
|
|
5352
|
+
lines.push(
|
|
5353
|
+
`Action: ${action.key}${action.alias !== action.key ? ` (alias: ${action.alias})` : ""}`
|
|
5354
|
+
);
|
|
5355
|
+
if (action.title) lines.push(`Title: ${action.title}`);
|
|
5356
|
+
if (action.description) lines.push(`Description: ${action.description}`);
|
|
5357
|
+
lines.push("");
|
|
5358
|
+
lines.push("Input schema:");
|
|
5359
|
+
lines.push(JSON.stringify(action.inputSchema, null, 2));
|
|
5360
|
+
if (action.outputSchema) {
|
|
5361
|
+
lines.push("");
|
|
5362
|
+
lines.push("Output schema:");
|
|
5363
|
+
lines.push(JSON.stringify(action.outputSchema, null, 2));
|
|
5364
|
+
}
|
|
5365
|
+
lines.push("");
|
|
5366
|
+
lines.push(
|
|
5367
|
+
`Run: fullstack-cli action-plugin form-action-execute --plugin ${description.key} --action ${action.alias} --input '<json>|@<file>|-' [--id <id>] [--form-value '<json>|@<file>|-'] [--timeout <ms>]`
|
|
5368
|
+
);
|
|
5369
|
+
console.log(lines.join("\n"));
|
|
5370
|
+
}
|
|
5371
|
+
function parseOutputFormat(raw) {
|
|
5372
|
+
if (raw === void 0 || raw === "json") {
|
|
5373
|
+
return "json";
|
|
5374
|
+
}
|
|
5375
|
+
if (raw === "pretty") {
|
|
5376
|
+
return "pretty";
|
|
5377
|
+
}
|
|
5378
|
+
throw new FormCliError(
|
|
5379
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
5380
|
+
`--format must be json or pretty, got: ${raw}`
|
|
5381
|
+
);
|
|
5382
|
+
}
|
|
5383
|
+
function finishWithFailure(error, pluginErrorHint) {
|
|
5384
|
+
if (process.env.DEBUG && error instanceof Error) {
|
|
5385
|
+
console.error(error.stack);
|
|
5386
|
+
}
|
|
5387
|
+
finishWithJson(toFailureOutput(error, "EXECUTION_ERROR", pluginErrorHint), 1);
|
|
5388
|
+
}
|
|
5389
|
+
async function formActionList(options) {
|
|
5390
|
+
try {
|
|
5391
|
+
const format = parseOutputFormat(options.format);
|
|
5392
|
+
const description = describeFormActions(options.plugin);
|
|
5393
|
+
if (format === "pretty") {
|
|
5394
|
+
printFormActionsText(description);
|
|
5395
|
+
} else {
|
|
5396
|
+
finishWithJson(description, 0);
|
|
5397
|
+
}
|
|
5398
|
+
} catch (error) {
|
|
5399
|
+
finishWithFailure(error);
|
|
5400
|
+
}
|
|
5401
|
+
}
|
|
5402
|
+
async function formActionGet(options) {
|
|
5403
|
+
try {
|
|
5404
|
+
const format = parseOutputFormat(options.format);
|
|
5405
|
+
const description = describeFormAction(options.plugin, options.action);
|
|
5406
|
+
if (format === "pretty") {
|
|
5407
|
+
printFormActionText(description);
|
|
5408
|
+
} else {
|
|
5409
|
+
finishWithJson(description, 0);
|
|
5410
|
+
}
|
|
5411
|
+
} catch (error) {
|
|
5412
|
+
finishWithFailure(error);
|
|
5413
|
+
}
|
|
5414
|
+
}
|
|
5415
|
+
async function formActionExecute(options) {
|
|
5416
|
+
try {
|
|
5417
|
+
const result = await executeFormAction({
|
|
5418
|
+
pluginKey: options.plugin,
|
|
5419
|
+
action: options.action,
|
|
5420
|
+
input: options.input,
|
|
5421
|
+
instanceId: options.id,
|
|
5422
|
+
formValue: options.formValue,
|
|
5423
|
+
timeout: options.timeout
|
|
5424
|
+
});
|
|
5425
|
+
finishWithJson(result, 0);
|
|
5426
|
+
} catch (error) {
|
|
5427
|
+
finishWithFailure(
|
|
5428
|
+
error,
|
|
5429
|
+
(code) => code === FormCliErrorCode.INVALID_INPUT ? `Check --input against the action's inputSchema: run "fullstack-cli action-plugin form-action-get --plugin ${options.plugin} --action ${options.action}".` : void 0
|
|
5430
|
+
);
|
|
5431
|
+
}
|
|
5432
|
+
}
|
|
5433
|
+
|
|
5434
|
+
// src/commands/action-plugin/list.handler.ts
|
|
5435
|
+
function describeInstalledPlugin(key, version) {
|
|
5436
|
+
try {
|
|
5437
|
+
const manifest = readPluginManifest(key);
|
|
5438
|
+
return {
|
|
5439
|
+
key,
|
|
5440
|
+
version,
|
|
5441
|
+
formActions: (manifest.formActions ?? []).map((fa) => {
|
|
5442
|
+
const description = pickLocalizedText(fa.description);
|
|
5443
|
+
return description === void 0 ? { name: fa.key } : { name: fa.key, description };
|
|
5444
|
+
}),
|
|
5445
|
+
hasValidateForm: manifest.hasValidateForm === true
|
|
5446
|
+
};
|
|
5447
|
+
} catch (error) {
|
|
5448
|
+
return {
|
|
5449
|
+
key,
|
|
5450
|
+
version,
|
|
5451
|
+
formActions: [],
|
|
5452
|
+
hasValidateForm: false,
|
|
5453
|
+
_manifestError: error instanceof Error ? error.message : String(error)
|
|
5454
|
+
};
|
|
5455
|
+
}
|
|
5456
|
+
}
|
|
5457
|
+
async function list(options = {}) {
|
|
5458
|
+
try {
|
|
5459
|
+
const plugins = Object.entries(readActionPlugins());
|
|
5460
|
+
if (options.json) {
|
|
5461
|
+
printJson(plugins.map(([key, version]) => describeInstalledPlugin(key, version)));
|
|
5462
|
+
return;
|
|
5463
|
+
}
|
|
5464
|
+
if (plugins.length === 0) {
|
|
5465
|
+
console.log("[action-plugin] No plugins installed");
|
|
5466
|
+
console.log('[action-plugin] Use "action-plugin install <name>" to install a plugin');
|
|
5467
|
+
return;
|
|
5468
|
+
}
|
|
5469
|
+
console.log("[action-plugin] Installed plugins:\n");
|
|
5470
|
+
const nameWidth = Math.max(40, ...plugins.map(([name]) => name.length + 2));
|
|
5471
|
+
const versionWidth = 15;
|
|
5472
|
+
console.log(
|
|
5473
|
+
" " + "Plugin".padEnd(nameWidth) + "Version"
|
|
5474
|
+
);
|
|
5475
|
+
console.log(" " + "-".repeat(nameWidth + versionWidth));
|
|
5476
|
+
for (const [name, version] of plugins) {
|
|
5477
|
+
console.log(
|
|
5478
|
+
" " + name.padEnd(nameWidth) + version
|
|
5479
|
+
);
|
|
5480
|
+
}
|
|
5481
|
+
console.log(`
|
|
5482
|
+
Total: ${plugins.length} plugin(s)`);
|
|
5483
|
+
} catch (error) {
|
|
5484
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5485
|
+
if (options.json) {
|
|
5486
|
+
printJson({ ok: false, code: "LIST_FAILED", message });
|
|
5487
|
+
}
|
|
5488
|
+
console.error(`[action-plugin] Failed to list plugins: ${message}`);
|
|
5489
|
+
process.exit(1);
|
|
5490
|
+
}
|
|
5491
|
+
}
|
|
5492
|
+
|
|
5493
|
+
// src/commands/action-plugin/cache.handler.ts
|
|
5494
|
+
async function cacheList() {
|
|
5495
|
+
const cached = listCachedPlugins();
|
|
5496
|
+
if (cached.length === 0) {
|
|
5497
|
+
console.log("[action-plugin] No cached plugins found");
|
|
5498
|
+
return;
|
|
5499
|
+
}
|
|
5500
|
+
console.log("[action-plugin] Cached plugins:\n");
|
|
5501
|
+
console.log(" Name Version Size Modified");
|
|
5502
|
+
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
5503
|
+
let totalSize = 0;
|
|
5504
|
+
for (const plugin of cached) {
|
|
5505
|
+
const name = plugin.name.padEnd(38);
|
|
5506
|
+
const version = plugin.version.padEnd(10);
|
|
5507
|
+
const size = formatSize(plugin.size).padEnd(9);
|
|
5508
|
+
const mtime = plugin.mtime.toISOString().replace("T", " ").slice(0, 19);
|
|
5509
|
+
console.log(` ${name} ${version} ${size} ${mtime}`);
|
|
5510
|
+
totalSize += plugin.size;
|
|
5511
|
+
}
|
|
5512
|
+
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
5513
|
+
console.log(` Total: ${cached.length} cached file(s), ${formatSize(totalSize)}`);
|
|
5514
|
+
}
|
|
5515
|
+
async function cacheClean(pluginName, version) {
|
|
5516
|
+
let count;
|
|
5517
|
+
if (pluginName) {
|
|
5518
|
+
console.log(`[action-plugin] Cleaning cache for ${pluginName}${version ? `@${version}` : ""}...`);
|
|
5519
|
+
count = cleanPluginCache(pluginName, version);
|
|
5520
|
+
if (count === 0) {
|
|
5521
|
+
console.log(`[action-plugin] No cached files found for ${pluginName}${version ? `@${version}` : ""}`);
|
|
5522
|
+
} else {
|
|
5523
|
+
console.log(`[action-plugin] Cleaned ${count} cached file(s)`);
|
|
5524
|
+
}
|
|
5525
|
+
} else {
|
|
5526
|
+
console.log("[action-plugin] Cleaning all cached plugins...");
|
|
5527
|
+
count = cleanAllCache();
|
|
5528
|
+
if (count === 0) {
|
|
5529
|
+
console.log("[action-plugin] No cached files found");
|
|
5530
|
+
} else {
|
|
5531
|
+
console.log(`[action-plugin] Cleaned ${count} cached file(s)`);
|
|
5532
|
+
}
|
|
5533
|
+
}
|
|
5534
|
+
}
|
|
5535
|
+
function formatSize(bytes) {
|
|
5536
|
+
if (bytes < 1024) {
|
|
5537
|
+
return `${bytes} B`;
|
|
5538
|
+
} else if (bytes < 1024 * 1024) {
|
|
5539
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
5540
|
+
} else {
|
|
5541
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
5542
|
+
}
|
|
5543
|
+
}
|
|
5544
|
+
|
|
5545
|
+
// src/commands/action-plugin/index.ts
|
|
5546
|
+
var initCommand = {
|
|
5547
|
+
name: "init",
|
|
5548
|
+
description: "Install all plugins from package.json",
|
|
5549
|
+
register(program) {
|
|
5550
|
+
program.command(this.name).description(this.description).action(async () => {
|
|
5551
|
+
await init();
|
|
5552
|
+
});
|
|
5553
|
+
}
|
|
5554
|
+
};
|
|
5555
|
+
var installCommand = {
|
|
5556
|
+
name: "install",
|
|
5557
|
+
description: "Install action plugin(s) (default: latest version)",
|
|
5558
|
+
aliases: ["i"],
|
|
5559
|
+
register(program) {
|
|
5560
|
+
program.command(this.name).alias("i").description(this.description).argument("<names...>", "Plugin name(s) (e.g., @office/feishu-create-group or @office/feishu-create-group@1.0.0)").action(async (names) => {
|
|
5561
|
+
await install(names);
|
|
5562
|
+
});
|
|
5563
|
+
}
|
|
5564
|
+
};
|
|
5565
|
+
var updateCommand = {
|
|
5566
|
+
name: "update",
|
|
5567
|
+
description: "Update action plugin(s) to the latest version",
|
|
5568
|
+
aliases: ["up"],
|
|
5569
|
+
register(program) {
|
|
5570
|
+
program.command(this.name).alias("up").description(this.description).argument("<names...>", "Plugin name(s) (e.g., @office/feishu-create-group)").action(async (names) => {
|
|
5571
|
+
await update(names);
|
|
5572
|
+
});
|
|
5573
|
+
}
|
|
5574
|
+
};
|
|
5575
|
+
var removeCommand = {
|
|
5576
|
+
name: "remove",
|
|
5577
|
+
description: "Remove an installed action plugin",
|
|
5578
|
+
aliases: ["rm"],
|
|
5579
|
+
register(program) {
|
|
5580
|
+
program.command(this.name).alias("rm").description(this.description).argument("<name>", "Plugin name (e.g., @office/feishu-create-group)").action(async (name) => {
|
|
5581
|
+
await remove(name);
|
|
5582
|
+
});
|
|
5583
|
+
}
|
|
5584
|
+
};
|
|
5585
|
+
var listCommand = {
|
|
5586
|
+
name: "list",
|
|
5587
|
+
description: "List all installed action plugins",
|
|
5588
|
+
aliases: ["ls"],
|
|
5589
|
+
register(program) {
|
|
5590
|
+
program.command(this.name).alias("ls").description(this.description).option("--json", "Output JSON with form action summary per plugin").action(async (options) => {
|
|
5591
|
+
await list(options);
|
|
5592
|
+
});
|
|
5593
|
+
}
|
|
5594
|
+
};
|
|
5595
|
+
var FORMAT_OPTION_DESC = "Output format: json (default) or pretty";
|
|
5596
|
+
var JSON_ARG_HINT = "inline JSON, @<file>, or - for stdin";
|
|
5597
|
+
var PLUGIN_OPTION_DESC = "(required) Plugin key, e.g. @office/feishu-bitable";
|
|
5598
|
+
var ACTION_OPTION_DESC = "(required) Form action key or alias from form-action-list, e.g. getTableFields or get-table-fields";
|
|
5599
|
+
var formActionListCommand = {
|
|
5600
|
+
name: "form-action-list",
|
|
5601
|
+
description: "List the form actions of an installed plugin (queries used while configuring it, e.g. search bases, list tables)",
|
|
5602
|
+
register(program) {
|
|
5603
|
+
outputParseErrorsAsJson(program.command(this.name)).description(this.description).requiredOption("--plugin <key>", PLUGIN_OPTION_DESC).option("--format <format>", FORMAT_OPTION_DESC).addHelpText(
|
|
5604
|
+
"after",
|
|
5605
|
+
`
|
|
5606
|
+
Reads the local plugin manifest only; no credential needed.
|
|
5607
|
+
Output: {key, version, formActions: [{key, alias, title, description}], hasValidateForm}
|
|
5608
|
+
Next: run form-action-get to see an action's input schema.
|
|
5609
|
+
|
|
5610
|
+
Example:
|
|
5611
|
+
fullstack-cli action-plugin form-action-list --plugin @office/feishu-bitable`
|
|
5612
|
+
).action(async (options) => {
|
|
5613
|
+
await formActionList(options);
|
|
5614
|
+
});
|
|
5615
|
+
}
|
|
5616
|
+
};
|
|
5617
|
+
var formActionGetCommand = {
|
|
5618
|
+
name: "form-action-get",
|
|
5619
|
+
description: "Show the input and output schema of a plugin form action",
|
|
5620
|
+
register(program) {
|
|
5621
|
+
outputParseErrorsAsJson(program.command(this.name)).description(this.description).requiredOption("--plugin <key>", PLUGIN_OPTION_DESC).requiredOption("--action <name>", ACTION_OPTION_DESC).option("--format <format>", FORMAT_OPTION_DESC).addHelpText(
|
|
5622
|
+
"after",
|
|
5623
|
+
`
|
|
5624
|
+
Reads the local plugin manifest only; no credential needed.
|
|
5625
|
+
Output: {key, version, action: {key, alias, title, description, inputSchema, outputSchema}}
|
|
5626
|
+
Next: build --input from inputSchema and run form-action-execute.
|
|
5627
|
+
|
|
5628
|
+
Example:
|
|
5629
|
+
fullstack-cli action-plugin form-action-get --plugin @office/feishu-bitable --action list-tables`
|
|
5630
|
+
).action(async (options) => {
|
|
5631
|
+
await formActionGet(options);
|
|
5632
|
+
});
|
|
5633
|
+
}
|
|
5634
|
+
};
|
|
5635
|
+
var formActionExecuteCommand = {
|
|
5636
|
+
name: "form-action-execute",
|
|
5637
|
+
description: "Run a plugin form action (e.g. list tables) and print the result as JSON",
|
|
5638
|
+
register(program) {
|
|
5639
|
+
outputParseErrorsAsJson(program.command(this.name)).description(this.description).requiredOption("--plugin <key>", PLUGIN_OPTION_DESC).requiredOption("--action <name>", ACTION_OPTION_DESC).requiredOption(
|
|
5640
|
+
"--input <json>",
|
|
5641
|
+
`(required) Action input matching the action's inputSchema: ${JSON_ARG_HINT}`
|
|
5642
|
+
).option(
|
|
5643
|
+
"--id <id>",
|
|
5644
|
+
"Existing capability ID; the plugin sees that instance's saved form value (e.g. to keep the user's previous choices)"
|
|
5645
|
+
).option(
|
|
5646
|
+
"--form-value <json>",
|
|
5647
|
+
`Unsaved form value for the plugin to see instead of the saved one (JSON object; wins over --id): ${JSON_ARG_HINT}`
|
|
5648
|
+
).option("--timeout <ms>", "Timeout in milliseconds (default: 60000)").addHelpText(
|
|
5649
|
+
"after",
|
|
5650
|
+
`
|
|
5651
|
+
Requires the operator credential MIAODA_AUTHN_CODE, which the platform injects when the
|
|
5652
|
+
command runs through agent_tool; it cannot run in a plain terminal.
|
|
5653
|
+
Output: on success, the plugin's result JSON (exit 0); on failure,
|
|
5654
|
+
{ok: false, code, message, hint?, details?} (exit 1). Logs go to stderr.
|
|
5655
|
+
At most one of --input / --form-value can read from stdin (-).
|
|
5656
|
+
|
|
5657
|
+
Examples:
|
|
5658
|
+
fullstack-cli action-plugin form-action-execute --plugin @office/feishu-bitable --action search-apps --input '{"keyword":"tasks"}'
|
|
5659
|
+
fullstack-cli action-plugin form-action-execute --plugin @office/feishu-bitable --action get-table-fields --input @./input.json --id bitable_tasks`
|
|
5660
|
+
).action(async (options) => {
|
|
5661
|
+
await formActionExecute(options);
|
|
5662
|
+
});
|
|
5663
|
+
}
|
|
5664
|
+
};
|
|
5665
|
+
var cacheListCommand = {
|
|
5666
|
+
name: "cache-list",
|
|
5667
|
+
description: "List all cached plugin packages",
|
|
5668
|
+
register(program) {
|
|
5669
|
+
program.command(this.name).description(this.description).action(async () => {
|
|
5670
|
+
await cacheList();
|
|
5671
|
+
});
|
|
5672
|
+
}
|
|
5673
|
+
};
|
|
5674
|
+
var cacheCleanCommand = {
|
|
5675
|
+
name: "cache-clean",
|
|
5676
|
+
description: "Clean cached plugin packages",
|
|
5677
|
+
register(program) {
|
|
5678
|
+
program.command(this.name).description(this.description).argument("[name]", "Plugin name to clean (e.g., @office/feishu-create-group). If not provided, clean all cache.").option("-v, --version <version>", "Specific version to clean").action(async (name, options) => {
|
|
5679
|
+
await cacheClean(name, options.version);
|
|
5680
|
+
});
|
|
5681
|
+
}
|
|
5682
|
+
};
|
|
5683
|
+
var actionPluginCommandGroup = {
|
|
5684
|
+
name: "action-plugin",
|
|
5685
|
+
description: "Manage action plugins",
|
|
5686
|
+
commands: [
|
|
5687
|
+
initCommand,
|
|
5688
|
+
installCommand,
|
|
5689
|
+
updateCommand,
|
|
5690
|
+
removeCommand,
|
|
5691
|
+
listCommand,
|
|
5692
|
+
formActionListCommand,
|
|
5693
|
+
formActionGetCommand,
|
|
5694
|
+
formActionExecuteCommand,
|
|
5695
|
+
cacheListCommand,
|
|
5696
|
+
cacheCleanCommand
|
|
5697
|
+
]
|
|
5698
|
+
};
|
|
5699
|
+
|
|
5700
|
+
// src/commands/capability/list.handler.ts
|
|
5701
|
+
async function list2(options) {
|
|
5702
|
+
try {
|
|
5703
|
+
if (!capabilitiesDirExists()) {
|
|
5704
|
+
logError("capabilities directory not found (looked for shared/capabilities and server/capabilities)");
|
|
5705
|
+
process.exit(1);
|
|
5706
|
+
}
|
|
5707
|
+
if (options.id) {
|
|
5708
|
+
await listSingle(options.id, options.summary);
|
|
5709
|
+
} else {
|
|
5710
|
+
await listAll(options.summary);
|
|
5711
|
+
}
|
|
5712
|
+
} catch (error) {
|
|
5713
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5714
|
+
logError(message);
|
|
5715
|
+
process.exit(1);
|
|
5716
|
+
}
|
|
5717
|
+
}
|
|
5718
|
+
async function listSingle(id, summary) {
|
|
5719
|
+
const capability = readCapability(id);
|
|
5720
|
+
if (summary) {
|
|
5721
|
+
printJson(capability);
|
|
5722
|
+
} else {
|
|
5723
|
+
const hydrated = await hydrateCapability(capability);
|
|
5724
|
+
printJson(hydrated);
|
|
5725
|
+
}
|
|
5726
|
+
}
|
|
5727
|
+
async function listAll(summary) {
|
|
5728
|
+
const capabilities = readAllCapabilities();
|
|
5729
|
+
if (capabilities.length === 0) {
|
|
5730
|
+
printJson([]);
|
|
5731
|
+
return;
|
|
5732
|
+
}
|
|
5733
|
+
if (summary) {
|
|
5734
|
+
printJson(capabilities);
|
|
5735
|
+
} else {
|
|
5736
|
+
const hydrated = [];
|
|
5737
|
+
for (const capability of capabilities) {
|
|
5738
|
+
const result = await hydrateCapability(capability);
|
|
5739
|
+
hydrated.push(result);
|
|
5740
|
+
}
|
|
5741
|
+
printJson(hydrated);
|
|
5742
|
+
}
|
|
5743
|
+
}
|
|
5744
|
+
|
|
5745
|
+
// src/commands/capability/template-refs.ts
|
|
5746
|
+
var INPUT_REF_REGEX = /\{\{\s*input\.([a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*\s*\}\}/g;
|
|
5747
|
+
var TemplateIssueCode = {
|
|
5748
|
+
/** 表单值引用了 paramsSchema 没声明的变量 */
|
|
5749
|
+
UNDEFINED_INPUT_REF: "UNDEFINED_INPUT_REF",
|
|
5750
|
+
/** paramsSchema 声明的变量表单值里没有引用(提醒,不阻塞) */
|
|
5751
|
+
UNUSED_INPUT_PARAM: "UNUSED_INPUT_PARAM"
|
|
5752
|
+
};
|
|
5753
|
+
function toJsonPointer(path28) {
|
|
5754
|
+
if (path28.length === 0) {
|
|
5755
|
+
return "";
|
|
5756
|
+
}
|
|
5757
|
+
return "/" + path28.map((segment) => String(segment).replace(/~/g, "~0").replace(/\//g, "~1")).join("/");
|
|
5758
|
+
}
|
|
5759
|
+
function forEachString(value, path28, visit) {
|
|
5760
|
+
if (typeof value === "string") {
|
|
5761
|
+
visit(value, path28);
|
|
5762
|
+
return;
|
|
5763
|
+
}
|
|
5764
|
+
if (Array.isArray(value)) {
|
|
5765
|
+
value.forEach(
|
|
5766
|
+
(item, index) => forEachString(item, [...path28, index], visit)
|
|
5767
|
+
);
|
|
5768
|
+
return;
|
|
5769
|
+
}
|
|
5770
|
+
if (value && typeof value === "object") {
|
|
5771
|
+
for (const [key, item] of Object.entries(value)) {
|
|
5772
|
+
forEachString(item, [...path28, key], visit);
|
|
5773
|
+
}
|
|
5774
|
+
}
|
|
5775
|
+
}
|
|
5776
|
+
function declaredParams(paramsSchema) {
|
|
5777
|
+
const properties = paramsSchema.properties;
|
|
5778
|
+
if (!properties || typeof properties !== "object" || Array.isArray(properties)) {
|
|
5779
|
+
return [];
|
|
5780
|
+
}
|
|
5781
|
+
return Object.keys(properties);
|
|
5782
|
+
}
|
|
5783
|
+
function checkTemplateRefs(formValue, paramsSchema) {
|
|
5784
|
+
const errors = [];
|
|
5785
|
+
const reminders = [];
|
|
5786
|
+
const declared = new Set(declaredParams(paramsSchema));
|
|
5787
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
5788
|
+
forEachString(formValue, [], (str, path28) => {
|
|
5789
|
+
const pointer = toJsonPointer(path28);
|
|
5790
|
+
for (const match of str.matchAll(INPUT_REF_REGEX)) {
|
|
5791
|
+
const name = match[1];
|
|
5792
|
+
referenced.add(name);
|
|
5793
|
+
if (!declared.has(name)) {
|
|
5794
|
+
errors.push({
|
|
5795
|
+
code: TemplateIssueCode.UNDEFINED_INPUT_REF,
|
|
5796
|
+
path: pointer,
|
|
5797
|
+
message: `{{input.${name}}} is not declared in paramsSchema.properties`
|
|
5798
|
+
});
|
|
5799
|
+
}
|
|
5800
|
+
}
|
|
5801
|
+
});
|
|
5802
|
+
for (const name of declared) {
|
|
5803
|
+
if (!referenced.has(name)) {
|
|
5804
|
+
reminders.push({
|
|
5805
|
+
code: TemplateIssueCode.UNUSED_INPUT_PARAM,
|
|
5806
|
+
message: `paramsSchema declares "${name}" but the form value never references {{input.${name}}}, so the value passed for it would be dropped`
|
|
5807
|
+
});
|
|
5808
|
+
}
|
|
5809
|
+
}
|
|
5810
|
+
return { errors, reminders };
|
|
5811
|
+
}
|
|
5812
|
+
|
|
5813
|
+
// src/commands/capability/validate.handler.ts
|
|
5814
|
+
function zodIssuesToFormIssues(issues) {
|
|
5815
|
+
return issues.map((issue) => ({
|
|
5816
|
+
message: issue.message,
|
|
5817
|
+
path: toJsonPointer(issue.path)
|
|
5818
|
+
}));
|
|
5819
|
+
}
|
|
5820
|
+
function isZodLikeSchema(value) {
|
|
5821
|
+
return !!value && typeof value.safeParse === "function";
|
|
5822
|
+
}
|
|
5823
|
+
function isLegacyManifest(manifest) {
|
|
5824
|
+
return manifest.formActions === void 0 && manifest.hasValidateForm === void 0;
|
|
5825
|
+
}
|
|
5826
|
+
function isRecord(value) {
|
|
5827
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
5828
|
+
}
|
|
5829
|
+
var PLUGIN_BUG_HINT = "This is a bug in the plugin, not in the form value. Do not retry or change the form value for it; report it to the plugin author.";
|
|
5830
|
+
function normalizeIssue(issue) {
|
|
5831
|
+
if (!isRecord(issue)) {
|
|
5832
|
+
return void 0;
|
|
5833
|
+
}
|
|
5834
|
+
const { code, message, path: path28 } = issue;
|
|
5835
|
+
if (typeof message !== "string" || message === "") {
|
|
5836
|
+
return void 0;
|
|
5837
|
+
}
|
|
5838
|
+
if (code !== void 0 && (typeof code !== "string" || code === "")) {
|
|
5839
|
+
return void 0;
|
|
5840
|
+
}
|
|
5841
|
+
if (path28 !== void 0 && typeof path28 !== "string") {
|
|
5842
|
+
return void 0;
|
|
5843
|
+
}
|
|
5844
|
+
return {
|
|
5845
|
+
message,
|
|
5846
|
+
...code === void 0 ? {} : { code },
|
|
5847
|
+
...path28 === void 0 ? {} : { path: path28 }
|
|
5848
|
+
};
|
|
5849
|
+
}
|
|
5850
|
+
function normalizeResult(raw) {
|
|
5851
|
+
if (!isRecord(raw) || typeof raw.success !== "boolean" || raw.issues !== void 0 && !Array.isArray(raw.issues)) {
|
|
5852
|
+
throw new FormCliError(
|
|
5853
|
+
FormCliErrorCode.VALIDATION_EXECUTION_FAILED,
|
|
5854
|
+
"validateForm returned an unexpected shape: expected { success: boolean, issues?: FormIssue[] }",
|
|
5855
|
+
{ hint: PLUGIN_BUG_HINT }
|
|
5856
|
+
);
|
|
5857
|
+
}
|
|
5858
|
+
const rawIssues = raw.issues ?? [];
|
|
5859
|
+
const issues = rawIssues.map((rawIssue, index) => {
|
|
5860
|
+
const issue = normalizeIssue(rawIssue);
|
|
5861
|
+
if (!issue) {
|
|
5862
|
+
throw new FormCliError(
|
|
5863
|
+
FormCliErrorCode.VALIDATION_EXECUTION_FAILED,
|
|
5864
|
+
`validateForm returned a malformed issue at index ${index}: message must be a non-empty string; code, if given, must be a non-empty string; path, if given, must be a string`,
|
|
5865
|
+
{ hint: PLUGIN_BUG_HINT, details: { issue: rawIssue } }
|
|
5866
|
+
);
|
|
5867
|
+
}
|
|
5868
|
+
return issue;
|
|
5869
|
+
});
|
|
5870
|
+
return { success: raw.success, issues };
|
|
5871
|
+
}
|
|
5872
|
+
async function runValidate(options, resolvedParamsSchema) {
|
|
5873
|
+
const timeoutMs = parseTimeout(options.timeout);
|
|
5874
|
+
assertSingleStdinArg({
|
|
5875
|
+
"--form-value": options.formValue,
|
|
5876
|
+
"--params-schema": options.paramsSchema
|
|
5877
|
+
});
|
|
5878
|
+
const next = readJsonObjectArg(options.formValue, "--form-value");
|
|
5879
|
+
const explicitParamsSchema = resolvedParamsSchema ?? (options.paramsSchema === void 0 ? void 0 : readJsonObjectArg(options.paramsSchema, "--params-schema"));
|
|
5880
|
+
const resolved = await resolveInstalledPlugin(options.plugin);
|
|
5881
|
+
const { manifest, module, version: pluginVersion } = resolved;
|
|
5882
|
+
const instance = options.id ? readMatchingCapability(options.id, options.plugin) : void 0;
|
|
5883
|
+
const previous = instance?.formValue;
|
|
5884
|
+
let normalizedFormValue = next;
|
|
5885
|
+
const configSchema = module.__definition?.config;
|
|
5886
|
+
if (manifest.form?.refType === "config" && isZodLikeSchema(configSchema)) {
|
|
5887
|
+
const parsed = configSchema.safeParse(next);
|
|
5888
|
+
if (!parsed.success) {
|
|
5889
|
+
const issues = zodIssuesToFormIssues(parsed.error.issues);
|
|
5890
|
+
return {
|
|
5891
|
+
ok: false,
|
|
5892
|
+
code: FormCliErrorCode.INVALID_INPUT,
|
|
5893
|
+
message: `form value does not match plugin ${options.plugin} config schema (${issues.length} issue(s))`,
|
|
5894
|
+
hint: "Fix the fields listed in issues (path is a JSON Pointer into the form value) and run again.",
|
|
5895
|
+
issues,
|
|
5896
|
+
validated: false,
|
|
5897
|
+
pluginVersion
|
|
5898
|
+
};
|
|
5899
|
+
}
|
|
5900
|
+
if (parsed.data && typeof parsed.data === "object" && !Array.isArray(parsed.data)) {
|
|
5901
|
+
normalizedFormValue = parsed.data;
|
|
5902
|
+
}
|
|
5903
|
+
}
|
|
5904
|
+
let templateReminders = [];
|
|
5905
|
+
if (manifest.form?.refType !== "config") {
|
|
5906
|
+
const paramsSchema = explicitParamsSchema ?? instance?.paramsSchema ?? {};
|
|
5907
|
+
const { errors, reminders } = checkTemplateRefs(next, paramsSchema);
|
|
5908
|
+
if (errors.length > 0) {
|
|
5909
|
+
return {
|
|
5910
|
+
ok: false,
|
|
5911
|
+
code: FormCliErrorCode.INVALID_INPUT,
|
|
5912
|
+
message: `form value references params not declared in paramsSchema (${errors.length} issue(s))`,
|
|
5913
|
+
hint: "Declare every {{input.x}} used in the form value under paramsSchema.properties (pass it with --params-schema), or remove the reference; then run again.",
|
|
5914
|
+
issues: [...errors, ...reminders],
|
|
5915
|
+
validated: false,
|
|
5916
|
+
pluginVersion
|
|
5917
|
+
};
|
|
5918
|
+
}
|
|
5919
|
+
templateReminders = reminders;
|
|
5920
|
+
}
|
|
5921
|
+
const manifestClaims = manifest.hasValidateForm === true;
|
|
5922
|
+
const sdkReady = hasFormActionSdk(module);
|
|
5923
|
+
if (manifestClaims && (!sdkReady || typeof module.validateForm !== "function")) {
|
|
5924
|
+
throw new FormCliError(
|
|
5925
|
+
FormCliErrorCode.VALIDATION_EXECUTION_FAILED,
|
|
5926
|
+
`Plugin ${options.plugin} manifest declares hasValidateForm but the loaded module has no validateForm`,
|
|
5927
|
+
{ hint: PLUGIN_BUG_HINT }
|
|
5928
|
+
);
|
|
5929
|
+
}
|
|
5930
|
+
let pluginHas = false;
|
|
5931
|
+
if (sdkReady) {
|
|
5932
|
+
pluginHas = module.hasValidateForm() === true;
|
|
5933
|
+
} else if (!isLegacyManifest(manifest)) {
|
|
5934
|
+
throw new FormCliError(
|
|
5935
|
+
FormCliErrorCode.PLUGIN_SDK_TOO_OLD,
|
|
5936
|
+
`Plugin ${options.plugin} manifest has form action fields but the module lacks runFormAction / validateForm / hasValidateForm`,
|
|
5937
|
+
{ hint: SDK_TOO_OLD_HINT(options.plugin) }
|
|
5938
|
+
);
|
|
5939
|
+
}
|
|
5940
|
+
if (manifestClaims && !pluginHas) {
|
|
5941
|
+
throw new FormCliError(
|
|
5942
|
+
FormCliErrorCode.VALIDATION_EXECUTION_FAILED,
|
|
5943
|
+
`Plugin ${options.plugin} manifest declares hasValidateForm but plugin.hasValidateForm() returned false`,
|
|
5944
|
+
{ hint: PLUGIN_BUG_HINT }
|
|
5945
|
+
);
|
|
5946
|
+
}
|
|
5947
|
+
if (!pluginHas) {
|
|
5948
|
+
return {
|
|
5949
|
+
ok: true,
|
|
5950
|
+
issues: templateReminders,
|
|
5951
|
+
validated: false,
|
|
5952
|
+
pluginVersion,
|
|
5953
|
+
normalizedFormValue
|
|
5954
|
+
};
|
|
5955
|
+
}
|
|
5956
|
+
const ctx = buildFormActionContext({
|
|
5957
|
+
pluginKey: options.plugin,
|
|
5958
|
+
instanceId: options.id,
|
|
5959
|
+
formValue: normalizedFormValue
|
|
5960
|
+
});
|
|
5961
|
+
let checked;
|
|
5962
|
+
try {
|
|
5963
|
+
const result = await withTimeout(
|
|
5964
|
+
module.validateForm(
|
|
5965
|
+
ctx,
|
|
5966
|
+
{ previous, next: normalizedFormValue }
|
|
5967
|
+
),
|
|
5968
|
+
timeoutMs,
|
|
5969
|
+
`validateForm of ${options.plugin}`
|
|
5970
|
+
);
|
|
5971
|
+
checked = normalizeResult(result);
|
|
5972
|
+
} catch (error) {
|
|
5973
|
+
if (error instanceof FormCliError) {
|
|
5974
|
+
throw error;
|
|
5975
|
+
}
|
|
5976
|
+
const cause = isPluginError(error) ? { code: error.code, message: error.message, details: error.details } : { message: error instanceof Error ? error.message : String(error) };
|
|
5977
|
+
throw new FormCliError(
|
|
5978
|
+
FormCliErrorCode.VALIDATION_EXECUTION_FAILED,
|
|
5979
|
+
`validateForm of ${options.plugin} threw: ${cause.message}`,
|
|
5980
|
+
{
|
|
5981
|
+
hint: "See details.cause: a permission or platform error needs to be resolved first (or retried later if it is transient); anything else is a bug in the plugin, so do not change the form value for it.",
|
|
5982
|
+
details: { cause }
|
|
5983
|
+
}
|
|
5984
|
+
);
|
|
5985
|
+
}
|
|
5986
|
+
const output = {
|
|
5987
|
+
ok: checked.success,
|
|
5988
|
+
issues: [...checked.issues, ...templateReminders],
|
|
5989
|
+
validated: true,
|
|
5990
|
+
pluginVersion,
|
|
5991
|
+
normalizedFormValue
|
|
5992
|
+
};
|
|
5993
|
+
if (!checked.success) {
|
|
5994
|
+
output.code = FormCliErrorCode.VALIDATION_FAILED;
|
|
5995
|
+
output.message = checked.issues[0]?.message ?? `plugin ${options.plugin} validateForm did not pass`;
|
|
5996
|
+
output.hint = checked.issues.length > 0 ? "Fix the form value according to issues and run again." : "The plugin rejected the form value without giving a reason; review the values against the plugin schema and run again.";
|
|
5997
|
+
}
|
|
5998
|
+
return output;
|
|
5999
|
+
}
|
|
6000
|
+
async function validate(options) {
|
|
6001
|
+
try {
|
|
6002
|
+
const output = await runValidate(options);
|
|
6003
|
+
finishWithJson(output, output.ok ? 0 : 1);
|
|
6004
|
+
} catch (error) {
|
|
6005
|
+
if (process.env.DEBUG && error instanceof Error) {
|
|
6006
|
+
console.error(error.stack);
|
|
6007
|
+
}
|
|
6008
|
+
finishWithJson(
|
|
6009
|
+
toFailureOutput(error, FormCliErrorCode.VALIDATION_EXECUTION_FAILED),
|
|
6010
|
+
1
|
|
6011
|
+
);
|
|
6012
|
+
}
|
|
6013
|
+
}
|
|
6014
|
+
|
|
6015
|
+
// src/commands/capability/write.handler.ts
|
|
6016
|
+
import fs20 from "fs";
|
|
6017
|
+
import path15 from "path";
|
|
6018
|
+
var CAPABILITY_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
|
|
6019
|
+
var CREATED_BY_PLACEHOLDER = "__fullstack_cli_created_by__";
|
|
6020
|
+
function assertValidId(id) {
|
|
6021
|
+
if (!CAPABILITY_ID_PATTERN.test(id)) {
|
|
6022
|
+
throw new FormCliError(
|
|
6023
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
6024
|
+
`Invalid capability id "${id}": only letters, digits, "_" and "-" are allowed (max 128, must not start with "_" or "-")`
|
|
6025
|
+
);
|
|
6026
|
+
}
|
|
6027
|
+
}
|
|
6028
|
+
function capabilityFilePath(id) {
|
|
6029
|
+
const dir = getCapabilitiesDir();
|
|
6030
|
+
const relative = path15.relative(getProjectRoot2(), dir);
|
|
6031
|
+
if (relative === ".." || relative.startsWith(`..${path15.sep}`) || path15.isAbsolute(relative)) {
|
|
6032
|
+
throw new FormCliError(
|
|
6033
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
6034
|
+
`Capabilities directory ${dir} is outside the project root ${getProjectRoot2()}; check ${CAPABILITIES_DIR_ENV}`
|
|
6035
|
+
);
|
|
6036
|
+
}
|
|
6037
|
+
return path15.join(dir, `${id}.json`);
|
|
6038
|
+
}
|
|
6039
|
+
function toProjectRelative(absolutePath) {
|
|
6040
|
+
return path15.relative(getProjectRoot2(), absolutePath).split(path15.sep).join("/");
|
|
6041
|
+
}
|
|
6042
|
+
function readPluginIcon(pluginKey) {
|
|
6043
|
+
try {
|
|
6044
|
+
const pkg2 = JSON.parse(
|
|
6045
|
+
fs20.readFileSync(
|
|
6046
|
+
path15.join(getPluginPath(pluginKey), "package.json"),
|
|
6047
|
+
"utf-8"
|
|
6048
|
+
)
|
|
6049
|
+
);
|
|
6050
|
+
return typeof pkg2.icon === "string" ? pkg2.icon : "";
|
|
6051
|
+
} catch {
|
|
6052
|
+
return "";
|
|
6053
|
+
}
|
|
6054
|
+
}
|
|
6055
|
+
function extractRawCreatedBy(rawText) {
|
|
6056
|
+
return /"createdBy"\s*:\s*(-?\d+)/.exec(rawText)?.[1];
|
|
6057
|
+
}
|
|
6058
|
+
function serializeCapability(record, createdByToken) {
|
|
6059
|
+
const json = JSON.stringify(record, null, 2);
|
|
6060
|
+
return createdByToken === void 0 ? json : json.replace(`"${CREATED_BY_PLACEHOLDER}"`, createdByToken);
|
|
6061
|
+
}
|
|
6062
|
+
function writeAtomically(filePath, content, options) {
|
|
6063
|
+
const dir = path15.dirname(filePath);
|
|
6064
|
+
fs20.mkdirSync(dir, { recursive: true });
|
|
6065
|
+
const tmp = path15.join(
|
|
6066
|
+
dir,
|
|
6067
|
+
`.${path15.basename(filePath)}.${process.pid}.${Date.now()}.tmp`
|
|
6068
|
+
);
|
|
6069
|
+
fs20.writeFileSync(tmp, content);
|
|
6070
|
+
try {
|
|
6071
|
+
if (options.exclusive) {
|
|
6072
|
+
try {
|
|
6073
|
+
fs20.linkSync(tmp, filePath);
|
|
6074
|
+
} catch (error) {
|
|
6075
|
+
if (error.code === "EEXIST") {
|
|
6076
|
+
throw new FormCliError(
|
|
6077
|
+
FormCliErrorCode.INSTANCE_EXISTS,
|
|
6078
|
+
`Capability file ${toProjectRelative(filePath)} was created concurrently`,
|
|
6079
|
+
{
|
|
6080
|
+
hint: 'Use "fullstack-cli capability update" to modify it, or pick another --id.'
|
|
6081
|
+
}
|
|
6082
|
+
);
|
|
6083
|
+
}
|
|
6084
|
+
throw error;
|
|
6085
|
+
}
|
|
6086
|
+
} else {
|
|
6087
|
+
fs20.renameSync(tmp, filePath);
|
|
6088
|
+
}
|
|
6089
|
+
} finally {
|
|
6090
|
+
fs20.rmSync(tmp, { force: true });
|
|
6091
|
+
}
|
|
6092
|
+
}
|
|
6093
|
+
function readParamsSchema(raw) {
|
|
6094
|
+
return raw === void 0 ? void 0 : readJsonObjectArg(raw, "--params-schema");
|
|
6095
|
+
}
|
|
6096
|
+
function successOutput(id, filePath, check2) {
|
|
6097
|
+
const relative = toProjectRelative(filePath);
|
|
6098
|
+
return {
|
|
6099
|
+
ok: true,
|
|
6100
|
+
id,
|
|
6101
|
+
path: relative,
|
|
6102
|
+
pluginVersion: check2.pluginVersion,
|
|
6103
|
+
validated: check2.validated,
|
|
6104
|
+
issues: check2.issues,
|
|
6105
|
+
affectedFilePaths: [relative]
|
|
6106
|
+
};
|
|
6107
|
+
}
|
|
6108
|
+
async function runCreate(options) {
|
|
6109
|
+
assertValidId(options.id);
|
|
6110
|
+
if (!options.name || !options.name.trim()) {
|
|
6111
|
+
throw new FormCliError(
|
|
6112
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
6113
|
+
"--name must not be empty"
|
|
6114
|
+
);
|
|
6115
|
+
}
|
|
6116
|
+
const filePath = capabilityFilePath(options.id);
|
|
6117
|
+
if (fs20.existsSync(filePath)) {
|
|
6118
|
+
throw new FormCliError(
|
|
6119
|
+
FormCliErrorCode.INSTANCE_EXISTS,
|
|
6120
|
+
`Capability ${options.id} already exists at ${toProjectRelative(filePath)}`,
|
|
6121
|
+
{
|
|
6122
|
+
hint: 'Use "fullstack-cli capability update" to modify it, or pick another --id.'
|
|
6123
|
+
}
|
|
6124
|
+
);
|
|
6125
|
+
}
|
|
6126
|
+
assertSingleStdinArg({
|
|
6127
|
+
"--form-value": options.formValue,
|
|
6128
|
+
"--params-schema": options.paramsSchema
|
|
6129
|
+
});
|
|
6130
|
+
const paramsSchema = readParamsSchema(options.paramsSchema) ?? {};
|
|
6131
|
+
const check2 = await runValidate(
|
|
6132
|
+
{
|
|
6133
|
+
plugin: options.plugin,
|
|
6134
|
+
formValue: options.formValue,
|
|
6135
|
+
timeout: options.timeout
|
|
6136
|
+
},
|
|
6137
|
+
paramsSchema
|
|
6138
|
+
);
|
|
6139
|
+
if (!check2.ok) {
|
|
6140
|
+
return check2;
|
|
6141
|
+
}
|
|
6142
|
+
const now = Date.now();
|
|
6143
|
+
const record = {
|
|
6144
|
+
id: options.id,
|
|
6145
|
+
pluginKey: options.plugin,
|
|
6146
|
+
pluginVersion: check2.pluginVersion,
|
|
6147
|
+
name: options.name,
|
|
6148
|
+
description: options.description ?? "",
|
|
6149
|
+
icon: readPluginIcon(options.plugin),
|
|
6150
|
+
paramsSchema,
|
|
6151
|
+
formValue: check2.normalizedFormValue ?? {},
|
|
6152
|
+
createdAt: now,
|
|
6153
|
+
updatedAt: now,
|
|
6154
|
+
createdBy: 0
|
|
6155
|
+
};
|
|
6156
|
+
writeAtomically(filePath, serializeCapability(record, void 0), {
|
|
6157
|
+
exclusive: true
|
|
6158
|
+
});
|
|
6159
|
+
return successOutput(options.id, filePath, check2);
|
|
6160
|
+
}
|
|
6161
|
+
async function runUpdate(options) {
|
|
6162
|
+
assertValidId(options.id);
|
|
6163
|
+
const filePath = capabilityFilePath(options.id);
|
|
6164
|
+
if (!fs20.existsSync(filePath)) {
|
|
6165
|
+
throw new FormCliError(
|
|
6166
|
+
FormCliErrorCode.INSTANCE_NOT_FOUND,
|
|
6167
|
+
`Capability ${options.id} not found at ${toProjectRelative(filePath)}`,
|
|
6168
|
+
{
|
|
6169
|
+
hint: 'Check the id with "fullstack-cli capability list --summary", or use "fullstack-cli capability create" to create it.'
|
|
6170
|
+
}
|
|
6171
|
+
);
|
|
6172
|
+
}
|
|
6173
|
+
const rawText = fs20.readFileSync(filePath, "utf-8");
|
|
6174
|
+
let existing;
|
|
6175
|
+
try {
|
|
6176
|
+
const parsed = JSON.parse(rawText);
|
|
6177
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
6178
|
+
throw new Error("not a JSON object");
|
|
6179
|
+
}
|
|
6180
|
+
existing = parsed;
|
|
6181
|
+
} catch (error) {
|
|
6182
|
+
throw new FormCliError(
|
|
6183
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
6184
|
+
`Existing capability file ${toProjectRelative(filePath)} is not a valid JSON object: ${error instanceof Error ? error.message : String(error)}`
|
|
6185
|
+
);
|
|
6186
|
+
}
|
|
6187
|
+
if (typeof existing.pluginKey !== "string" || !existing.pluginKey) {
|
|
6188
|
+
throw new FormCliError(
|
|
6189
|
+
FormCliErrorCode.INVALID_INPUT,
|
|
6190
|
+
`Existing capability file ${toProjectRelative(filePath)} has no pluginKey`
|
|
6191
|
+
);
|
|
6192
|
+
}
|
|
6193
|
+
assertSingleStdinArg({
|
|
6194
|
+
"--form-value": options.formValue,
|
|
6195
|
+
"--params-schema": options.paramsSchema
|
|
6196
|
+
});
|
|
6197
|
+
const paramsSchema = readParamsSchema(options.paramsSchema);
|
|
6198
|
+
const check2 = await runValidate(
|
|
6199
|
+
{
|
|
6200
|
+
plugin: existing.pluginKey,
|
|
6201
|
+
formValue: options.formValue,
|
|
6202
|
+
id: options.id,
|
|
6203
|
+
timeout: options.timeout
|
|
6204
|
+
},
|
|
6205
|
+
paramsSchema
|
|
6206
|
+
);
|
|
6207
|
+
if (!check2.ok) {
|
|
6208
|
+
return check2;
|
|
6209
|
+
}
|
|
6210
|
+
const record = {
|
|
6211
|
+
...existing,
|
|
6212
|
+
pluginVersion: check2.pluginVersion,
|
|
6213
|
+
formValue: check2.normalizedFormValue ?? {},
|
|
6214
|
+
updatedAt: Date.now()
|
|
6215
|
+
};
|
|
6216
|
+
if (options.name !== void 0) record.name = options.name;
|
|
6217
|
+
if (options.description !== void 0)
|
|
6218
|
+
record.description = options.description;
|
|
6219
|
+
if (paramsSchema !== void 0) record.paramsSchema = paramsSchema;
|
|
6220
|
+
const createdByToken = extractRawCreatedBy(rawText);
|
|
6221
|
+
if (createdByToken !== void 0) {
|
|
6222
|
+
record.createdBy = CREATED_BY_PLACEHOLDER;
|
|
6223
|
+
}
|
|
6224
|
+
writeAtomically(filePath, serializeCapability(record, createdByToken), {
|
|
6225
|
+
exclusive: false
|
|
6226
|
+
});
|
|
6227
|
+
return successOutput(options.id, filePath, check2);
|
|
6228
|
+
}
|
|
6229
|
+
function readPluginKeyOf(filePath) {
|
|
6230
|
+
try {
|
|
6231
|
+
const parsed = JSON.parse(fs20.readFileSync(filePath, "utf-8"));
|
|
6232
|
+
return typeof parsed?.pluginKey === "string" && parsed.pluginKey ? parsed.pluginKey : void 0;
|
|
6233
|
+
} catch {
|
|
6234
|
+
return void 0;
|
|
6235
|
+
}
|
|
6236
|
+
}
|
|
6237
|
+
function runDelete(options) {
|
|
6238
|
+
assertValidId(options.id);
|
|
6239
|
+
const filePath = capabilityFilePath(options.id);
|
|
6240
|
+
const relative = toProjectRelative(filePath);
|
|
6241
|
+
const notFound = () => new FormCliError(
|
|
6242
|
+
FormCliErrorCode.INSTANCE_NOT_FOUND,
|
|
6243
|
+
`Capability ${options.id} not found at ${relative}`,
|
|
6244
|
+
{
|
|
6245
|
+
hint: 'Check the id with "fullstack-cli capability list --summary".'
|
|
6246
|
+
}
|
|
6247
|
+
);
|
|
6248
|
+
if (!fs20.existsSync(filePath)) {
|
|
6249
|
+
throw notFound();
|
|
6250
|
+
}
|
|
6251
|
+
const pluginKey = readPluginKeyOf(filePath);
|
|
6252
|
+
try {
|
|
6253
|
+
fs20.unlinkSync(filePath);
|
|
6254
|
+
} catch (error) {
|
|
6255
|
+
if (error.code === "ENOENT") {
|
|
6256
|
+
throw notFound();
|
|
6257
|
+
}
|
|
6258
|
+
throw error;
|
|
6259
|
+
}
|
|
6260
|
+
const output = {
|
|
6261
|
+
ok: true,
|
|
6262
|
+
id: options.id,
|
|
6263
|
+
path: relative,
|
|
6264
|
+
...pluginKey ? { pluginKey } : {},
|
|
6265
|
+
affectedFilePaths: [relative]
|
|
6266
|
+
};
|
|
6267
|
+
if (pluginKey && !readAllCapabilities().some((c) => c.pluginKey === pluginKey)) {
|
|
6268
|
+
output.hint = `No other capability uses ${pluginKey}; if the plugin is no longer needed, run "fullstack-cli action-plugin remove ${pluginKey}".`;
|
|
6269
|
+
}
|
|
6270
|
+
return output;
|
|
6271
|
+
}
|
|
6272
|
+
async function finish(run8) {
|
|
6273
|
+
try {
|
|
6274
|
+
const output = await run8();
|
|
6275
|
+
finishWithJson(output, output.ok ? 0 : 1);
|
|
6276
|
+
} catch (error) {
|
|
6277
|
+
if (process.env.DEBUG && error instanceof Error) {
|
|
6278
|
+
console.error(error.stack);
|
|
6279
|
+
}
|
|
6280
|
+
finishWithJson(toFailureOutput(error, "EXECUTION_ERROR"), 1);
|
|
6281
|
+
}
|
|
6282
|
+
}
|
|
6283
|
+
async function create(options) {
|
|
6284
|
+
await finish(() => runCreate(options));
|
|
6285
|
+
}
|
|
6286
|
+
async function update2(options) {
|
|
6287
|
+
await finish(() => runUpdate(options));
|
|
6288
|
+
}
|
|
6289
|
+
async function remove2(options) {
|
|
6290
|
+
await finish(async () => runDelete(options));
|
|
6291
|
+
}
|
|
6292
|
+
|
|
6293
|
+
// src/commands/capability/index.ts
|
|
6294
|
+
var JSON_ARG_HINT2 = "inline JSON, @<file>, or - for stdin";
|
|
6295
|
+
var listCommand2 = {
|
|
6296
|
+
name: "list",
|
|
6297
|
+
description: "List capability configurations",
|
|
6298
|
+
aliases: ["ls"],
|
|
6299
|
+
register(program) {
|
|
6300
|
+
program.command(this.name).alias("ls").description(this.description).option("--summary", "Return raw capability config (without hydration)").option("--id <id>", "Specify capability ID").action(async (options) => {
|
|
6301
|
+
await list2(options);
|
|
6302
|
+
});
|
|
6303
|
+
}
|
|
6304
|
+
};
|
|
6305
|
+
var getCommand = {
|
|
6306
|
+
name: "get",
|
|
6307
|
+
description: 'Get raw capability config by ID (alias of "list --id <id> --summary")',
|
|
6308
|
+
register(program) {
|
|
6309
|
+
program.command(this.name).description(this.description).requiredOption("--id <id>", "Capability ID").action(async (options) => {
|
|
6310
|
+
await list2({ id: options.id, summary: true });
|
|
6311
|
+
});
|
|
6312
|
+
}
|
|
6313
|
+
};
|
|
6314
|
+
var PLUGIN_OPTION_DESC2 = "(required) Plugin key, e.g. @office/feishu-bitable";
|
|
6315
|
+
var TIMEOUT_OPTION_DESC = "Timeout for the plugin's validateForm in milliseconds (default: 60000)";
|
|
6316
|
+
var WRITE_OUTPUT_HELP = `Output: {ok, id, path, pluginVersion, validated, issues, affectedFilePaths} (exit 0);
|
|
6317
|
+
when the check fails, the same output as "capability validate" and nothing is written (exit 1).
|
|
6318
|
+
Requires MIAODA_AUTHN_CODE only when the plugin defines validateForm.`;
|
|
6319
|
+
var validateCommand = {
|
|
6320
|
+
name: "validate",
|
|
6321
|
+
description: "Check a form value before saving: the plugin's config schema, then the plugin's own validateForm. Writes nothing",
|
|
6322
|
+
register(program) {
|
|
6323
|
+
outputParseErrorsAsJson(program.command(this.name)).description(this.description).requiredOption("--plugin <key>", PLUGIN_OPTION_DESC2).requiredOption(
|
|
6324
|
+
"--form-value <json>",
|
|
6325
|
+
`(required) Complete form value to check (JSON object): ${JSON_ARG_HINT2}`
|
|
6326
|
+
).option(
|
|
6327
|
+
"--id <id>",
|
|
6328
|
+
"Existing capability ID when modifying; its saved form value is passed to the plugin as the previous value. Omit when creating"
|
|
6329
|
+
).option(
|
|
6330
|
+
"--params-schema <json>",
|
|
6331
|
+
`paramsSchema of an action plugin instance, used to check {{input.x}} references (default: the --id instance's, else {}): ${JSON_ARG_HINT2}`
|
|
6332
|
+
).option("--timeout <ms>", TIMEOUT_OPTION_DESC).addHelpText(
|
|
6333
|
+
"after",
|
|
6334
|
+
`
|
|
6335
|
+
Output: {ok, validated, pluginVersion, issues, normalizedFormValue} (exit 0); when the check fails,
|
|
6336
|
+
ok: false with code VALIDATION_FAILED or INVALID_INPUT, plus issues and hint (exit 1).
|
|
6337
|
+
validated: false means the plugin has no validateForm, so only the schema check ran.
|
|
6338
|
+
For action plugins (form.refType is not config) the schema check is replaced by a template check:
|
|
6339
|
+
every {{input.x}} in the form value must be declared in paramsSchema.properties (otherwise
|
|
6340
|
+
INVALID_INPUT); a declared param that is never referenced only adds a reminder to issues.
|
|
6341
|
+
Requires MIAODA_AUTHN_CODE only when the plugin defines validateForm.
|
|
6342
|
+
|
|
6343
|
+
Examples:
|
|
6344
|
+
fullstack-cli capability validate --plugin @office/feishu-bitable --form-value @./form.json
|
|
6345
|
+
fullstack-cli capability validate --plugin @office/ai-text-generate --form-value '{"prompt":"Summarize: {{input.text}}"}' --params-schema '{"type":"object","properties":{"text":{"type":"string","description":"text to summarize"}}}'`
|
|
6346
|
+
).action(
|
|
6347
|
+
async (options) => {
|
|
6348
|
+
await validate(options);
|
|
6349
|
+
}
|
|
6350
|
+
);
|
|
6351
|
+
}
|
|
6352
|
+
};
|
|
6353
|
+
var createCommand = {
|
|
6354
|
+
name: "create",
|
|
6355
|
+
description: 'Create a capability instance; runs the same checks as "capability validate" first and writes nothing if they fail',
|
|
6356
|
+
register(program) {
|
|
6357
|
+
outputParseErrorsAsJson(program.command(this.name)).description(this.description).requiredOption("--plugin <key>", PLUGIN_OPTION_DESC2).requiredOption(
|
|
6358
|
+
"--id <id>",
|
|
6359
|
+
'(required) New capability ID: letters, digits, "_" and "-", starting with a letter or digit, max 128'
|
|
6360
|
+
).requiredOption("--name <name>", "(required) Display name").requiredOption(
|
|
6361
|
+
"--form-value <json>",
|
|
6362
|
+
`(required) Complete form value (JSON object): ${JSON_ARG_HINT2}`
|
|
6363
|
+
).option("--description <text>", "Description (default: empty)").option(
|
|
6364
|
+
"--params-schema <json>",
|
|
6365
|
+
`paramsSchema (JSON object, default: {}): ${JSON_ARG_HINT2}`
|
|
6366
|
+
).option("--timeout <ms>", TIMEOUT_OPTION_DESC).addHelpText(
|
|
6367
|
+
"after",
|
|
6368
|
+
`
|
|
6369
|
+
Writes <CAPABILITIES_DIR>/<id>.json (default: shared/capabilities if it exists, else server/capabilities).
|
|
6370
|
+
Fails with INSTANCE_EXISTS when the id is taken.
|
|
6371
|
+
${WRITE_OUTPUT_HELP}
|
|
6372
|
+
|
|
6373
|
+
Example:
|
|
6374
|
+
fullstack-cli capability create --plugin @office/feishu-bitable --id bitable_tasks --name Tasks --form-value @./form.json`
|
|
6375
|
+
).action(async (options) => {
|
|
6376
|
+
await create(options);
|
|
6377
|
+
});
|
|
6378
|
+
}
|
|
6379
|
+
};
|
|
6380
|
+
var updateCommand2 = {
|
|
6381
|
+
name: "update",
|
|
6382
|
+
description: 'Update an existing capability instance; runs the same checks as "capability validate" first and writes nothing if they fail',
|
|
6383
|
+
register(program) {
|
|
6384
|
+
outputParseErrorsAsJson(program.command(this.name)).description(this.description).requiredOption("--id <id>", "(required) Existing capability ID").requiredOption(
|
|
6385
|
+
"--form-value <json>",
|
|
6386
|
+
`(required) Complete new form value (JSON object), replacing the saved one: ${JSON_ARG_HINT2}`
|
|
6387
|
+
).option("--name <name>", "New display name (kept when omitted)").option("--description <text>", "New description (kept when omitted)").option(
|
|
6388
|
+
"--params-schema <json>",
|
|
6389
|
+
`New paramsSchema (JSON object, kept when omitted): ${JSON_ARG_HINT2}`
|
|
6390
|
+
).option("--timeout <ms>", TIMEOUT_OPTION_DESC).addHelpText(
|
|
6391
|
+
"after",
|
|
6392
|
+
`
|
|
6393
|
+
The plugin key comes from the existing instance file; other fields such as createdAt are kept.
|
|
6394
|
+
Fails with INSTANCE_NOT_FOUND when the id does not exist.
|
|
6395
|
+
${WRITE_OUTPUT_HELP}
|
|
6396
|
+
|
|
6397
|
+
Example:
|
|
6398
|
+
fullstack-cli capability update --id bitable_tasks --form-value @./form.json`
|
|
6399
|
+
).action(async (options) => {
|
|
6400
|
+
await update2(options);
|
|
6401
|
+
});
|
|
6402
|
+
}
|
|
6403
|
+
};
|
|
6404
|
+
var deleteCommand = {
|
|
6405
|
+
name: "delete",
|
|
6406
|
+
description: "Delete a capability instance file. Does not uninstall the plugin or touch code that calls it",
|
|
6407
|
+
register(program) {
|
|
6408
|
+
outputParseErrorsAsJson(program.command(this.name)).description(this.description).requiredOption("--id <id>", "(required) Existing capability ID").addHelpText(
|
|
6409
|
+
"after",
|
|
6410
|
+
`
|
|
6411
|
+
Removes <CAPABILITIES_DIR>/<id>.json. Fails with INSTANCE_NOT_FOUND when the id does not exist.
|
|
6412
|
+
Output: {ok, id, path, pluginKey, affectedFilePaths, hint?} (exit 0); hint is set when no other
|
|
6413
|
+
capability uses the same plugin, suggesting "action-plugin remove".
|
|
6414
|
+
Code that still calls this capability fails at runtime with "Capability not found"; remove those
|
|
6415
|
+
calls as well.
|
|
6416
|
+
|
|
6417
|
+
Example:
|
|
6418
|
+
fullstack-cli capability delete --id bitable_tasks`
|
|
6419
|
+
).action(async (options) => {
|
|
6420
|
+
await remove2(options);
|
|
5006
6421
|
});
|
|
5007
6422
|
}
|
|
5008
6423
|
};
|
|
5009
6424
|
var capabilityCommandGroup = {
|
|
5010
6425
|
name: "capability",
|
|
5011
6426
|
description: "Manage capability configurations",
|
|
5012
|
-
commands: [
|
|
6427
|
+
commands: [
|
|
6428
|
+
listCommand2,
|
|
6429
|
+
getCommand,
|
|
6430
|
+
validateCommand,
|
|
6431
|
+
createCommand,
|
|
6432
|
+
updateCommand2,
|
|
6433
|
+
deleteCommand
|
|
6434
|
+
]
|
|
5013
6435
|
};
|
|
5014
6436
|
|
|
5015
6437
|
// src/commands/component/add.handler.ts
|
|
5016
6438
|
import { execFile } from "child_process";
|
|
5017
6439
|
|
|
5018
6440
|
// src/commands/component/registry-preparer.ts
|
|
5019
|
-
import
|
|
5020
|
-
import
|
|
6441
|
+
import fs21 from "fs";
|
|
6442
|
+
import path16 from "path";
|
|
5021
6443
|
import os from "os";
|
|
5022
6444
|
|
|
5023
6445
|
// src/commands/component/service.ts
|
|
@@ -5077,7 +6499,7 @@ async function sendInstallEvent(key) {
|
|
|
5077
6499
|
}
|
|
5078
6500
|
|
|
5079
6501
|
// src/commands/component/registry-preparer.ts
|
|
5080
|
-
var REGISTRY_TEMP_DIR =
|
|
6502
|
+
var REGISTRY_TEMP_DIR = path16.join(os.tmpdir(), "miaoda-registry");
|
|
5081
6503
|
function parseComponentKey(key) {
|
|
5082
6504
|
const match = key.match(/^@([^/]+)\/(.+)$/);
|
|
5083
6505
|
if (!match) {
|
|
@@ -5089,11 +6511,11 @@ function parseComponentKey(key) {
|
|
|
5089
6511
|
}
|
|
5090
6512
|
function getLocalRegistryPath(key) {
|
|
5091
6513
|
const { scope, name } = parseComponentKey(key);
|
|
5092
|
-
return
|
|
6514
|
+
return path16.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
|
|
5093
6515
|
}
|
|
5094
6516
|
function ensureDir(dirPath) {
|
|
5095
|
-
if (!
|
|
5096
|
-
|
|
6517
|
+
if (!fs21.existsSync(dirPath)) {
|
|
6518
|
+
fs21.mkdirSync(dirPath, { recursive: true });
|
|
5097
6519
|
}
|
|
5098
6520
|
}
|
|
5099
6521
|
async function prepareRecursive(key, visited) {
|
|
@@ -5126,8 +6548,8 @@ async function prepareRecursive(key, visited) {
|
|
|
5126
6548
|
registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
|
|
5127
6549
|
};
|
|
5128
6550
|
const localPath = getLocalRegistryPath(key);
|
|
5129
|
-
ensureDir(
|
|
5130
|
-
|
|
6551
|
+
ensureDir(path16.dirname(localPath));
|
|
6552
|
+
fs21.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
|
|
5131
6553
|
debug("\u4FDD\u5B58\u5230: %s", localPath);
|
|
5132
6554
|
}
|
|
5133
6555
|
async function prepareComponentRegistryItems(id) {
|
|
@@ -5137,18 +6559,18 @@ async function prepareComponentRegistryItems(id) {
|
|
|
5137
6559
|
}
|
|
5138
6560
|
function cleanupTempDir() {
|
|
5139
6561
|
try {
|
|
5140
|
-
if (
|
|
5141
|
-
|
|
6562
|
+
if (fs21.existsSync(REGISTRY_TEMP_DIR)) {
|
|
6563
|
+
fs21.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
|
|
5142
6564
|
}
|
|
5143
6565
|
} catch {
|
|
5144
6566
|
}
|
|
5145
6567
|
}
|
|
5146
6568
|
function getDownloadedRegistryItem(itemId) {
|
|
5147
6569
|
const localPath = getLocalRegistryPath(itemId);
|
|
5148
|
-
if (!
|
|
6570
|
+
if (!fs21.existsSync(localPath)) {
|
|
5149
6571
|
return null;
|
|
5150
6572
|
}
|
|
5151
|
-
const content =
|
|
6573
|
+
const content = fs21.readFileSync(localPath, "utf-8");
|
|
5152
6574
|
return JSON.parse(content);
|
|
5153
6575
|
}
|
|
5154
6576
|
|
|
@@ -5316,58 +6738,58 @@ var componentCommandGroup = {
|
|
|
5316
6738
|
};
|
|
5317
6739
|
|
|
5318
6740
|
// src/commands/migration/version-manager.ts
|
|
5319
|
-
import
|
|
5320
|
-
import
|
|
6741
|
+
import fs22 from "fs";
|
|
6742
|
+
import path17 from "path";
|
|
5321
6743
|
var PACKAGE_JSON = "package.json";
|
|
5322
6744
|
var VERSION_FIELD = "migrationVersion";
|
|
5323
6745
|
function getPackageJsonPath2() {
|
|
5324
|
-
return
|
|
6746
|
+
return path17.join(process.cwd(), PACKAGE_JSON);
|
|
5325
6747
|
}
|
|
5326
6748
|
function getCurrentVersion() {
|
|
5327
6749
|
const pkgPath = getPackageJsonPath2();
|
|
5328
|
-
if (!
|
|
6750
|
+
if (!fs22.existsSync(pkgPath)) {
|
|
5329
6751
|
throw new Error("package.json not found");
|
|
5330
6752
|
}
|
|
5331
|
-
const pkg2 = JSON.parse(
|
|
6753
|
+
const pkg2 = JSON.parse(fs22.readFileSync(pkgPath, "utf-8"));
|
|
5332
6754
|
return pkg2[VERSION_FIELD] ?? 0;
|
|
5333
6755
|
}
|
|
5334
6756
|
function setCurrentVersion(version) {
|
|
5335
6757
|
const pkgPath = getPackageJsonPath2();
|
|
5336
|
-
const pkg2 = JSON.parse(
|
|
6758
|
+
const pkg2 = JSON.parse(fs22.readFileSync(pkgPath, "utf-8"));
|
|
5337
6759
|
pkg2[VERSION_FIELD] = version;
|
|
5338
|
-
|
|
6760
|
+
fs22.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
|
|
5339
6761
|
}
|
|
5340
6762
|
|
|
5341
6763
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
5342
|
-
import
|
|
5343
|
-
import
|
|
6764
|
+
import fs24 from "fs";
|
|
6765
|
+
import path19 from "path";
|
|
5344
6766
|
|
|
5345
6767
|
// src/commands/migration/versions/v001_capability/utils.ts
|
|
5346
|
-
import
|
|
5347
|
-
import
|
|
6768
|
+
import fs23 from "fs";
|
|
6769
|
+
import path18 from "path";
|
|
5348
6770
|
var CAPABILITIES_DIR2 = "server/capabilities";
|
|
5349
6771
|
function getProjectRoot3() {
|
|
5350
6772
|
return process.cwd();
|
|
5351
6773
|
}
|
|
5352
6774
|
function getCapabilitiesDir2() {
|
|
5353
|
-
return
|
|
6775
|
+
return path18.join(getProjectRoot3(), CAPABILITIES_DIR2);
|
|
5354
6776
|
}
|
|
5355
6777
|
function getPluginManifestPath2(pluginKey) {
|
|
5356
|
-
return
|
|
6778
|
+
return path18.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
|
|
5357
6779
|
}
|
|
5358
6780
|
|
|
5359
6781
|
// src/commands/migration/versions/v001_capability/json-migrator/detector.ts
|
|
5360
6782
|
function detectJsonMigration() {
|
|
5361
6783
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5362
|
-
const oldFilePath =
|
|
5363
|
-
if (!
|
|
6784
|
+
const oldFilePath = path19.join(capabilitiesDir, "capabilities.json");
|
|
6785
|
+
if (!fs24.existsSync(oldFilePath)) {
|
|
5364
6786
|
return {
|
|
5365
6787
|
needsMigration: false,
|
|
5366
6788
|
reason: "capabilities.json not found"
|
|
5367
6789
|
};
|
|
5368
6790
|
}
|
|
5369
6791
|
try {
|
|
5370
|
-
const content =
|
|
6792
|
+
const content = fs24.readFileSync(oldFilePath, "utf-8");
|
|
5371
6793
|
const parsed = JSON.parse(content);
|
|
5372
6794
|
if (!Array.isArray(parsed)) {
|
|
5373
6795
|
return {
|
|
@@ -5418,8 +6840,8 @@ async function check(options) {
|
|
|
5418
6840
|
}
|
|
5419
6841
|
|
|
5420
6842
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5421
|
-
import
|
|
5422
|
-
import
|
|
6843
|
+
import fs25 from "fs";
|
|
6844
|
+
import path20 from "path";
|
|
5423
6845
|
|
|
5424
6846
|
// src/commands/migration/versions/v001_capability/mapping.ts
|
|
5425
6847
|
var DEFAULT_PLUGIN_VERSION = "1.0.0";
|
|
@@ -5649,18 +7071,18 @@ function transformCapabilities(oldCapabilities) {
|
|
|
5649
7071
|
// src/commands/migration/versions/v001_capability/json-migrator/index.ts
|
|
5650
7072
|
function loadExistingCapabilities() {
|
|
5651
7073
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5652
|
-
if (!
|
|
7074
|
+
if (!fs25.existsSync(capabilitiesDir)) {
|
|
5653
7075
|
return [];
|
|
5654
7076
|
}
|
|
5655
|
-
const files =
|
|
7077
|
+
const files = fs25.readdirSync(capabilitiesDir);
|
|
5656
7078
|
const capabilities = [];
|
|
5657
7079
|
for (const file of files) {
|
|
5658
7080
|
if (file === "capabilities.json" || !file.endsWith(".json")) {
|
|
5659
7081
|
continue;
|
|
5660
7082
|
}
|
|
5661
7083
|
try {
|
|
5662
|
-
const filePath =
|
|
5663
|
-
const content =
|
|
7084
|
+
const filePath = path20.join(capabilitiesDir, file);
|
|
7085
|
+
const content = fs25.readFileSync(filePath, "utf-8");
|
|
5664
7086
|
const capability = JSON.parse(content);
|
|
5665
7087
|
if (capability.id && capability.pluginKey) {
|
|
5666
7088
|
capabilities.push(capability);
|
|
@@ -5718,9 +7140,9 @@ async function migrateJsonFiles(options) {
|
|
|
5718
7140
|
}
|
|
5719
7141
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
5720
7142
|
for (const cap of newCapabilities) {
|
|
5721
|
-
const filePath =
|
|
7143
|
+
const filePath = path20.join(capabilitiesDir, `${cap.id}.json`);
|
|
5722
7144
|
const content = JSON.stringify(cap, null, 2);
|
|
5723
|
-
|
|
7145
|
+
fs25.writeFileSync(filePath, content, "utf-8");
|
|
5724
7146
|
console.log(` \u2713 Created: ${cap.id}.json`);
|
|
5725
7147
|
}
|
|
5726
7148
|
return {
|
|
@@ -5732,11 +7154,11 @@ async function migrateJsonFiles(options) {
|
|
|
5732
7154
|
}
|
|
5733
7155
|
|
|
5734
7156
|
// src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
|
|
5735
|
-
import
|
|
7157
|
+
import fs26 from "fs";
|
|
5736
7158
|
function isPluginInstalled2(pluginKey) {
|
|
5737
7159
|
const actionPlugins = readActionPlugins();
|
|
5738
7160
|
const manifestPath = getPluginManifestPath2(pluginKey);
|
|
5739
|
-
return
|
|
7161
|
+
return fs26.existsSync(manifestPath) && !!actionPlugins[pluginKey];
|
|
5740
7162
|
}
|
|
5741
7163
|
function detectPluginsToInstall(capabilities) {
|
|
5742
7164
|
const pluginKeys = /* @__PURE__ */ new Set();
|
|
@@ -5812,12 +7234,12 @@ async function installPlugins(capabilities, options) {
|
|
|
5812
7234
|
}
|
|
5813
7235
|
|
|
5814
7236
|
// src/commands/migration/versions/v001_capability/code-migrator/index.ts
|
|
5815
|
-
import
|
|
7237
|
+
import path22 from "path";
|
|
5816
7238
|
import { Project as Project3 } from "ts-morph";
|
|
5817
7239
|
|
|
5818
7240
|
// src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
|
|
5819
|
-
import
|
|
5820
|
-
import
|
|
7241
|
+
import fs27 from "fs";
|
|
7242
|
+
import path21 from "path";
|
|
5821
7243
|
var EXCLUDED_DIRS = [
|
|
5822
7244
|
"node_modules",
|
|
5823
7245
|
"dist",
|
|
@@ -5832,9 +7254,9 @@ var EXCLUDED_PATTERNS = [
|
|
|
5832
7254
|
/\.d\.ts$/
|
|
5833
7255
|
];
|
|
5834
7256
|
function scanDirectory(dir, files = []) {
|
|
5835
|
-
const entries =
|
|
7257
|
+
const entries = fs27.readdirSync(dir, { withFileTypes: true });
|
|
5836
7258
|
for (const entry of entries) {
|
|
5837
|
-
const fullPath =
|
|
7259
|
+
const fullPath = path21.join(dir, entry.name);
|
|
5838
7260
|
if (entry.isDirectory()) {
|
|
5839
7261
|
if (EXCLUDED_DIRS.includes(entry.name)) {
|
|
5840
7262
|
continue;
|
|
@@ -5850,14 +7272,14 @@ function scanDirectory(dir, files = []) {
|
|
|
5850
7272
|
return files;
|
|
5851
7273
|
}
|
|
5852
7274
|
function scanServerFiles() {
|
|
5853
|
-
const serverDir =
|
|
5854
|
-
if (!
|
|
7275
|
+
const serverDir = path21.join(getProjectRoot3(), "server");
|
|
7276
|
+
if (!fs27.existsSync(serverDir)) {
|
|
5855
7277
|
return [];
|
|
5856
7278
|
}
|
|
5857
7279
|
return scanDirectory(serverDir);
|
|
5858
7280
|
}
|
|
5859
7281
|
function hasCapabilityImport(filePath) {
|
|
5860
|
-
const content =
|
|
7282
|
+
const content = fs27.readFileSync(filePath, "utf-8");
|
|
5861
7283
|
return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
|
|
5862
7284
|
}
|
|
5863
7285
|
function scanFilesToMigrate() {
|
|
@@ -6234,7 +7656,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
6234
7656
|
const callSites = analyzeCallSites(sourceFile, imports);
|
|
6235
7657
|
const classInfo = analyzeClass(sourceFile);
|
|
6236
7658
|
const { canMigrate, reason } = canAutoMigrate(classInfo);
|
|
6237
|
-
const relativePath =
|
|
7659
|
+
const relativePath = path22.relative(getProjectRoot3(), filePath);
|
|
6238
7660
|
return {
|
|
6239
7661
|
filePath: relativePath,
|
|
6240
7662
|
imports,
|
|
@@ -6245,7 +7667,7 @@ function analyzeFile(project, filePath, actionNameMap) {
|
|
|
6245
7667
|
};
|
|
6246
7668
|
}
|
|
6247
7669
|
function migrateFile(project, analysis, dryRun) {
|
|
6248
|
-
const absolutePath =
|
|
7670
|
+
const absolutePath = path22.join(getProjectRoot3(), analysis.filePath);
|
|
6249
7671
|
if (!analysis.canAutoMigrate) {
|
|
6250
7672
|
return {
|
|
6251
7673
|
filePath: analysis.filePath,
|
|
@@ -6348,17 +7770,17 @@ function getSuggestion(analysis) {
|
|
|
6348
7770
|
}
|
|
6349
7771
|
|
|
6350
7772
|
// src/commands/migration/versions/v001_capability/cleanup.ts
|
|
6351
|
-
import
|
|
6352
|
-
import
|
|
7773
|
+
import fs28 from "fs";
|
|
7774
|
+
import path23 from "path";
|
|
6353
7775
|
function cleanupOldFiles(capabilities, dryRun) {
|
|
6354
7776
|
const deletedFiles = [];
|
|
6355
7777
|
const errors = [];
|
|
6356
7778
|
const capabilitiesDir = getCapabilitiesDir2();
|
|
6357
|
-
const oldJsonPath =
|
|
6358
|
-
if (
|
|
7779
|
+
const oldJsonPath = path23.join(capabilitiesDir, "capabilities.json");
|
|
7780
|
+
if (fs28.existsSync(oldJsonPath)) {
|
|
6359
7781
|
try {
|
|
6360
7782
|
if (!dryRun) {
|
|
6361
|
-
|
|
7783
|
+
fs28.unlinkSync(oldJsonPath);
|
|
6362
7784
|
}
|
|
6363
7785
|
deletedFiles.push("capabilities.json");
|
|
6364
7786
|
} catch (error) {
|
|
@@ -6366,11 +7788,11 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
6366
7788
|
}
|
|
6367
7789
|
}
|
|
6368
7790
|
for (const cap of capabilities) {
|
|
6369
|
-
const tsFilePath =
|
|
6370
|
-
if (
|
|
7791
|
+
const tsFilePath = path23.join(capabilitiesDir, `${cap.id}.ts`);
|
|
7792
|
+
if (fs28.existsSync(tsFilePath)) {
|
|
6371
7793
|
try {
|
|
6372
7794
|
if (!dryRun) {
|
|
6373
|
-
|
|
7795
|
+
fs28.unlinkSync(tsFilePath);
|
|
6374
7796
|
}
|
|
6375
7797
|
deletedFiles.push(`${cap.id}.ts`);
|
|
6376
7798
|
} catch (error) {
|
|
@@ -6386,8 +7808,8 @@ function cleanupOldFiles(capabilities, dryRun) {
|
|
|
6386
7808
|
}
|
|
6387
7809
|
|
|
6388
7810
|
// src/commands/migration/versions/v001_capability/report-generator.ts
|
|
6389
|
-
import
|
|
6390
|
-
import
|
|
7811
|
+
import fs29 from "fs";
|
|
7812
|
+
import path24 from "path";
|
|
6391
7813
|
var REPORT_FILE = "capability-migration-report.md";
|
|
6392
7814
|
function printSummary(result) {
|
|
6393
7815
|
const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
|
|
@@ -6550,15 +7972,15 @@ async function generateReport(result) {
|
|
|
6550
7972
|
}
|
|
6551
7973
|
lines.push("");
|
|
6552
7974
|
const logDir = process.env.LOG_DIR || "logs";
|
|
6553
|
-
if (!
|
|
7975
|
+
if (!fs29.existsSync(logDir)) {
|
|
6554
7976
|
return;
|
|
6555
7977
|
}
|
|
6556
|
-
const reportDir =
|
|
6557
|
-
if (!
|
|
6558
|
-
|
|
7978
|
+
const reportDir = path24.join(logDir, "migration");
|
|
7979
|
+
if (!fs29.existsSync(reportDir)) {
|
|
7980
|
+
fs29.mkdirSync(reportDir, { recursive: true });
|
|
6559
7981
|
}
|
|
6560
|
-
const reportPath =
|
|
6561
|
-
|
|
7982
|
+
const reportPath = path24.join(reportDir, REPORT_FILE);
|
|
7983
|
+
fs29.writeFileSync(reportPath, lines.join("\n"), "utf-8");
|
|
6562
7984
|
console.log(`\u{1F4C4} Report generated: ${reportPath}`);
|
|
6563
7985
|
}
|
|
6564
7986
|
|
|
@@ -7090,10 +8512,10 @@ var migrationCommand = {
|
|
|
7090
8512
|
};
|
|
7091
8513
|
|
|
7092
8514
|
// src/commands/read-logs/index.ts
|
|
7093
|
-
import
|
|
8515
|
+
import path25 from "path";
|
|
7094
8516
|
|
|
7095
8517
|
// src/commands/read-logs/std-utils.ts
|
|
7096
|
-
import
|
|
8518
|
+
import fs30 from "fs";
|
|
7097
8519
|
function formatStdPrefixTime(localTime) {
|
|
7098
8520
|
const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
|
|
7099
8521
|
if (!match) return localTime;
|
|
@@ -7123,11 +8545,11 @@ function stripPrefixFromStdLine(line) {
|
|
|
7123
8545
|
return `[${time}] ${content}`;
|
|
7124
8546
|
}
|
|
7125
8547
|
function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
|
|
7126
|
-
const stat =
|
|
8548
|
+
const stat = fs30.statSync(filePath);
|
|
7127
8549
|
if (stat.size === 0) {
|
|
7128
8550
|
return { lines: [], markerFound: false, totalLinesCount: 0 };
|
|
7129
8551
|
}
|
|
7130
|
-
const fd =
|
|
8552
|
+
const fd = fs30.openSync(filePath, "r");
|
|
7131
8553
|
const chunkSize = 64 * 1024;
|
|
7132
8554
|
let position = stat.size;
|
|
7133
8555
|
let remainder = "";
|
|
@@ -7141,7 +8563,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
7141
8563
|
const length = Math.min(chunkSize, position);
|
|
7142
8564
|
position -= length;
|
|
7143
8565
|
const buffer = Buffer.alloc(length);
|
|
7144
|
-
|
|
8566
|
+
fs30.readSync(fd, buffer, 0, length, position);
|
|
7145
8567
|
let chunk = buffer.toString("utf8");
|
|
7146
8568
|
if (remainder) {
|
|
7147
8569
|
chunk += remainder;
|
|
@@ -7183,7 +8605,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
|
|
|
7183
8605
|
}
|
|
7184
8606
|
}
|
|
7185
8607
|
} finally {
|
|
7186
|
-
|
|
8608
|
+
fs30.closeSync(fd);
|
|
7187
8609
|
}
|
|
7188
8610
|
return { lines: collected.reverse(), markerFound, totalLinesCount };
|
|
7189
8611
|
}
|
|
@@ -7204,21 +8626,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
|
|
|
7204
8626
|
}
|
|
7205
8627
|
|
|
7206
8628
|
// src/commands/read-logs/tail.ts
|
|
7207
|
-
import
|
|
8629
|
+
import fs31 from "fs";
|
|
7208
8630
|
function fileExists(filePath) {
|
|
7209
8631
|
try {
|
|
7210
|
-
|
|
8632
|
+
fs31.accessSync(filePath, fs31.constants.F_OK | fs31.constants.R_OK);
|
|
7211
8633
|
return true;
|
|
7212
8634
|
} catch {
|
|
7213
8635
|
return false;
|
|
7214
8636
|
}
|
|
7215
8637
|
}
|
|
7216
8638
|
function readFileTailLines(filePath, maxLines) {
|
|
7217
|
-
const stat =
|
|
8639
|
+
const stat = fs31.statSync(filePath);
|
|
7218
8640
|
if (stat.size === 0) {
|
|
7219
8641
|
return [];
|
|
7220
8642
|
}
|
|
7221
|
-
const fd =
|
|
8643
|
+
const fd = fs31.openSync(filePath, "r");
|
|
7222
8644
|
const chunkSize = 64 * 1024;
|
|
7223
8645
|
const chunks = [];
|
|
7224
8646
|
let position = stat.size;
|
|
@@ -7228,13 +8650,13 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
7228
8650
|
const length = Math.min(chunkSize, position);
|
|
7229
8651
|
position -= length;
|
|
7230
8652
|
const buffer = Buffer.alloc(length);
|
|
7231
|
-
|
|
8653
|
+
fs31.readSync(fd, buffer, 0, length, position);
|
|
7232
8654
|
chunks.unshift(buffer.toString("utf8"));
|
|
7233
8655
|
const chunkLines = buffer.toString("utf8").split("\n").length - 1;
|
|
7234
8656
|
collectedLines += chunkLines;
|
|
7235
8657
|
}
|
|
7236
8658
|
} finally {
|
|
7237
|
-
|
|
8659
|
+
fs31.closeSync(fd);
|
|
7238
8660
|
}
|
|
7239
8661
|
const content = chunks.join("");
|
|
7240
8662
|
const allLines = content.split("\n");
|
|
@@ -7250,11 +8672,11 @@ function readFileTailLines(filePath, maxLines) {
|
|
|
7250
8672
|
return allLines.slice(allLines.length - maxLines);
|
|
7251
8673
|
}
|
|
7252
8674
|
function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
7253
|
-
const stat =
|
|
8675
|
+
const stat = fs31.statSync(filePath);
|
|
7254
8676
|
if (stat.size === 0) {
|
|
7255
8677
|
return { lines: [], totalLinesCount: 0 };
|
|
7256
8678
|
}
|
|
7257
|
-
const fd =
|
|
8679
|
+
const fd = fs31.openSync(filePath, "r");
|
|
7258
8680
|
const chunkSize = 64 * 1024;
|
|
7259
8681
|
let position = stat.size;
|
|
7260
8682
|
let remainder = "";
|
|
@@ -7266,7 +8688,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
7266
8688
|
const length = Math.min(chunkSize, position);
|
|
7267
8689
|
position -= length;
|
|
7268
8690
|
const buffer = Buffer.alloc(length);
|
|
7269
|
-
|
|
8691
|
+
fs31.readSync(fd, buffer, 0, length, position);
|
|
7270
8692
|
let chunk = buffer.toString("utf8");
|
|
7271
8693
|
if (remainder) {
|
|
7272
8694
|
chunk += remainder;
|
|
@@ -7297,7 +8719,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
|
|
|
7297
8719
|
}
|
|
7298
8720
|
}
|
|
7299
8721
|
} finally {
|
|
7300
|
-
|
|
8722
|
+
fs31.closeSync(fd);
|
|
7301
8723
|
}
|
|
7302
8724
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7303
8725
|
}
|
|
@@ -7439,7 +8861,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
|
|
|
7439
8861
|
}
|
|
7440
8862
|
|
|
7441
8863
|
// src/commands/read-logs/json-lines.ts
|
|
7442
|
-
import
|
|
8864
|
+
import fs32 from "fs";
|
|
7443
8865
|
|
|
7444
8866
|
// src/commands/read-logs/structured-log.ts
|
|
7445
8867
|
function normalizeLevelName(value) {
|
|
@@ -7515,11 +8937,11 @@ function buildWantedLevelSet(levels) {
|
|
|
7515
8937
|
return set.size > 0 ? set : null;
|
|
7516
8938
|
}
|
|
7517
8939
|
function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
7518
|
-
const stat =
|
|
8940
|
+
const stat = fs32.statSync(filePath);
|
|
7519
8941
|
if (stat.size === 0) {
|
|
7520
8942
|
return { lines: [], totalLinesCount: 0 };
|
|
7521
8943
|
}
|
|
7522
|
-
const fd =
|
|
8944
|
+
const fd = fs32.openSync(filePath, "r");
|
|
7523
8945
|
const chunkSize = 64 * 1024;
|
|
7524
8946
|
let position = stat.size;
|
|
7525
8947
|
let remainder = "";
|
|
@@ -7534,7 +8956,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7534
8956
|
const length = Math.min(chunkSize, position);
|
|
7535
8957
|
position -= length;
|
|
7536
8958
|
const buffer = Buffer.alloc(length);
|
|
7537
|
-
|
|
8959
|
+
fs32.readSync(fd, buffer, 0, length, position);
|
|
7538
8960
|
let chunk = buffer.toString("utf8");
|
|
7539
8961
|
if (remainder) {
|
|
7540
8962
|
chunk += remainder;
|
|
@@ -7596,7 +9018,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
|
|
|
7596
9018
|
}
|
|
7597
9019
|
}
|
|
7598
9020
|
} finally {
|
|
7599
|
-
|
|
9021
|
+
fs32.closeSync(fd);
|
|
7600
9022
|
}
|
|
7601
9023
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7602
9024
|
}
|
|
@@ -7639,11 +9061,11 @@ function extractTraceId(obj) {
|
|
|
7639
9061
|
function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
7640
9062
|
const wanted = traceId.trim();
|
|
7641
9063
|
if (!wanted) return { lines: [], totalLinesCount: 0 };
|
|
7642
|
-
const stat =
|
|
9064
|
+
const stat = fs32.statSync(filePath);
|
|
7643
9065
|
if (stat.size === 0) {
|
|
7644
9066
|
return { lines: [], totalLinesCount: 0 };
|
|
7645
9067
|
}
|
|
7646
|
-
const fd =
|
|
9068
|
+
const fd = fs32.openSync(filePath, "r");
|
|
7647
9069
|
const chunkSize = 64 * 1024;
|
|
7648
9070
|
let position = stat.size;
|
|
7649
9071
|
let remainder = "";
|
|
@@ -7656,7 +9078,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7656
9078
|
const length = Math.min(chunkSize, position);
|
|
7657
9079
|
position -= length;
|
|
7658
9080
|
const buffer = Buffer.alloc(length);
|
|
7659
|
-
|
|
9081
|
+
fs32.readSync(fd, buffer, 0, length, position);
|
|
7660
9082
|
let chunk = buffer.toString("utf8");
|
|
7661
9083
|
if (remainder) {
|
|
7662
9084
|
chunk += remainder;
|
|
@@ -7709,7 +9131,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
|
|
|
7709
9131
|
}
|
|
7710
9132
|
}
|
|
7711
9133
|
} finally {
|
|
7712
|
-
|
|
9134
|
+
fs32.closeSync(fd);
|
|
7713
9135
|
}
|
|
7714
9136
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7715
9137
|
}
|
|
@@ -7718,11 +9140,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7718
9140
|
if (!wantedLevelSet) {
|
|
7719
9141
|
return { lines: [], totalLinesCount: 0 };
|
|
7720
9142
|
}
|
|
7721
|
-
const stat =
|
|
9143
|
+
const stat = fs32.statSync(filePath);
|
|
7722
9144
|
if (stat.size === 0) {
|
|
7723
9145
|
return { lines: [], totalLinesCount: 0 };
|
|
7724
9146
|
}
|
|
7725
|
-
const fd =
|
|
9147
|
+
const fd = fs32.openSync(filePath, "r");
|
|
7726
9148
|
const chunkSize = 64 * 1024;
|
|
7727
9149
|
let position = stat.size;
|
|
7728
9150
|
let remainder = "";
|
|
@@ -7734,7 +9156,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7734
9156
|
const length = Math.min(chunkSize, position);
|
|
7735
9157
|
position -= length;
|
|
7736
9158
|
const buffer = Buffer.alloc(length);
|
|
7737
|
-
|
|
9159
|
+
fs32.readSync(fd, buffer, 0, length, position);
|
|
7738
9160
|
let chunk = buffer.toString("utf8");
|
|
7739
9161
|
if (remainder) {
|
|
7740
9162
|
chunk += remainder;
|
|
@@ -7781,7 +9203,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
|
|
|
7781
9203
|
}
|
|
7782
9204
|
}
|
|
7783
9205
|
} finally {
|
|
7784
|
-
|
|
9206
|
+
fs32.closeSync(fd);
|
|
7785
9207
|
}
|
|
7786
9208
|
return { lines: collected.reverse(), totalLinesCount };
|
|
7787
9209
|
}
|
|
@@ -8274,30 +9696,30 @@ async function readLogsJsonResult(options) {
|
|
|
8274
9696
|
};
|
|
8275
9697
|
}
|
|
8276
9698
|
function resolveLogFilePath(logDir, type) {
|
|
8277
|
-
const base =
|
|
9699
|
+
const base = path25.isAbsolute(logDir) ? logDir : path25.join(process.cwd(), logDir);
|
|
8278
9700
|
if (type === "server") {
|
|
8279
|
-
return
|
|
9701
|
+
return path25.join(base, "server.log");
|
|
8280
9702
|
}
|
|
8281
9703
|
if (type === "trace") {
|
|
8282
|
-
return
|
|
9704
|
+
return path25.join(base, "trace.log");
|
|
8283
9705
|
}
|
|
8284
9706
|
if (type === "server-std") {
|
|
8285
|
-
return
|
|
9707
|
+
return path25.join(base, "server.std.log");
|
|
8286
9708
|
}
|
|
8287
9709
|
if (type === "client-std") {
|
|
8288
|
-
return
|
|
9710
|
+
return path25.join(base, "client.std.log");
|
|
8289
9711
|
}
|
|
8290
9712
|
if (type === "dev") {
|
|
8291
|
-
return
|
|
9713
|
+
return path25.join(base, "dev.log");
|
|
8292
9714
|
}
|
|
8293
9715
|
if (type === "dev-std") {
|
|
8294
|
-
return
|
|
9716
|
+
return path25.join(base, "dev.std.log");
|
|
8295
9717
|
}
|
|
8296
9718
|
if (type === "install-dep-std") {
|
|
8297
|
-
return
|
|
9719
|
+
return path25.join(base, "install-dep.std.log");
|
|
8298
9720
|
}
|
|
8299
9721
|
if (type === "browser") {
|
|
8300
|
-
return
|
|
9722
|
+
return path25.join(base, "browser.log");
|
|
8301
9723
|
}
|
|
8302
9724
|
throw new Error(`Unsupported log type: ${type}`);
|
|
8303
9725
|
}
|
|
@@ -8448,7 +9870,7 @@ async function getToken(options) {
|
|
|
8448
9870
|
for (const key of sceneConfig.requiredOptions) {
|
|
8449
9871
|
if (!options[key]) {
|
|
8450
9872
|
console.error(
|
|
8451
|
-
`[build] Error: --${
|
|
9873
|
+
`[build] Error: --${camelToKebab2(key)} is required for scene "${options.scene}"`
|
|
8452
9874
|
);
|
|
8453
9875
|
process.exit(1);
|
|
8454
9876
|
}
|
|
@@ -8462,14 +9884,14 @@ async function getToken(options) {
|
|
|
8462
9884
|
process.exit(1);
|
|
8463
9885
|
}
|
|
8464
9886
|
}
|
|
8465
|
-
function
|
|
9887
|
+
function camelToKebab2(str) {
|
|
8466
9888
|
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
8467
9889
|
}
|
|
8468
9890
|
|
|
8469
9891
|
// src/commands/build/upload-static.handler.ts
|
|
8470
|
-
import * as
|
|
9892
|
+
import * as fs33 from "fs";
|
|
8471
9893
|
import * as os2 from "os";
|
|
8472
|
-
import * as
|
|
9894
|
+
import * as path26 from "path";
|
|
8473
9895
|
import { execFileSync } from "child_process";
|
|
8474
9896
|
function readCredentialsFromEnv() {
|
|
8475
9897
|
const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
|
|
@@ -8493,8 +9915,8 @@ async function uploadStatic(options) {
|
|
|
8493
9915
|
endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
|
|
8494
9916
|
region = UPLOAD_STATIC_DEFAULTS.region
|
|
8495
9917
|
} = options;
|
|
8496
|
-
const resolvedStaticDir =
|
|
8497
|
-
if (!
|
|
9918
|
+
const resolvedStaticDir = path26.resolve(staticDir);
|
|
9919
|
+
if (!fs33.existsSync(resolvedStaticDir)) {
|
|
8498
9920
|
console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
|
|
8499
9921
|
return;
|
|
8500
9922
|
}
|
|
@@ -8527,8 +9949,8 @@ async function uploadStatic(options) {
|
|
|
8527
9949
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
8528
9950
|
}
|
|
8529
9951
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
8530
|
-
const confPath =
|
|
8531
|
-
|
|
9952
|
+
const confPath = path26.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
9953
|
+
fs33.writeFileSync(confPath, "");
|
|
8532
9954
|
try {
|
|
8533
9955
|
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
8534
9956
|
configureTosutil(resolvedTosutil, confPath, {
|
|
@@ -8542,7 +9964,7 @@ async function uploadStatic(options) {
|
|
|
8542
9964
|
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
8543
9965
|
} finally {
|
|
8544
9966
|
try {
|
|
8545
|
-
|
|
9967
|
+
fs33.unlinkSync(confPath);
|
|
8546
9968
|
} catch {
|
|
8547
9969
|
}
|
|
8548
9970
|
}
|
|
@@ -8562,8 +9984,8 @@ async function uploadStatic(options) {
|
|
|
8562
9984
|
}
|
|
8563
9985
|
}
|
|
8564
9986
|
function resolveTosutilPath(tosutilPath) {
|
|
8565
|
-
if (
|
|
8566
|
-
return
|
|
9987
|
+
if (path26.isAbsolute(tosutilPath)) {
|
|
9988
|
+
return fs33.existsSync(tosutilPath) ? tosutilPath : null;
|
|
8567
9989
|
}
|
|
8568
9990
|
try {
|
|
8569
9991
|
const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
|
|
@@ -8608,7 +10030,7 @@ async function resolveBucketId(appId) {
|
|
|
8608
10030
|
return bucketId;
|
|
8609
10031
|
}
|
|
8610
10032
|
function isDirEmpty(dirPath) {
|
|
8611
|
-
const entries =
|
|
10033
|
+
const entries = fs33.readdirSync(dirPath);
|
|
8612
10034
|
return entries.length === 0;
|
|
8613
10035
|
}
|
|
8614
10036
|
|
|
@@ -8704,13 +10126,13 @@ var commands = [
|
|
|
8704
10126
|
|
|
8705
10127
|
// src/index.ts
|
|
8706
10128
|
for (const filename of [".env.local", ".env"]) {
|
|
8707
|
-
const envPath =
|
|
8708
|
-
if (
|
|
10129
|
+
const envPath = path27.join(process.cwd(), filename);
|
|
10130
|
+
if (fs34.existsSync(envPath)) {
|
|
8709
10131
|
dotenvConfig({ path: envPath });
|
|
8710
10132
|
}
|
|
8711
10133
|
}
|
|
8712
|
-
var __dirname =
|
|
8713
|
-
var pkg = JSON.parse(
|
|
10134
|
+
var __dirname = path27.dirname(fileURLToPath5(import.meta.url));
|
|
10135
|
+
var pkg = JSON.parse(fs34.readFileSync(path27.join(__dirname, "../package.json"), "utf-8"));
|
|
8714
10136
|
var cli = new FullstackCLI(pkg.version);
|
|
8715
10137
|
cli.useAll(commands);
|
|
8716
10138
|
cli.run();
|