@kevlns/v-cli 0.4.6 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk.mjs CHANGED
@@ -444,6 +444,7 @@ function validateResources(list, at) {
444
444
  errors.push(`${where} \u5FC5\u987B\u662F\u5BF9\u8C61`);
445
445
  return;
446
446
  }
447
+ if (entry.key !== void 0 && (typeof entry.key !== "string" || !/^[a-z][a-z0-9-]*$/.test(entry.key))) errors.push(`${where}.key \u5FC5\u987B\u662F\u7A33\u5B9A\u8D44\u6E90\u540D\u79F0`);
447
448
  if (!isNonEmptyString(entry.kind) || !RESOURCE_KINDS.includes(entry.kind)) {
448
449
  errors.push(`${where}.kind \u5FC5\u987B\u662F [${RESOURCE_KINDS.join(", ")}] \u4E4B\u4E00`);
449
450
  }
@@ -461,6 +462,9 @@ function validateCapability(descriptor, implementation, providerId) {
461
462
  const errors = [];
462
463
  if (!isPlainObject2(descriptor)) return ["descriptor \u5FC5\u987B\u662F\u5BF9\u8C61"];
463
464
  const d = descriptor;
465
+ if (d.commands !== void 0 && (!Array.isArray(d.commands) || d.commands.some((p) => !Array.isArray(p) || p.length === 0 || p.some((t) => typeof t !== "string" || !/^[a-z][a-z0-9-]*$/.test(t))))) {
466
+ errors.push("commands \u5FC5\u987B\u662F\u975E\u7A7A\u547D\u4EE4\u8DEF\u5F84\u6570\u7EC4");
467
+ }
464
468
  if (!isNonEmptyString(d.id) || !CAPABILITY_ID_RE.test(d.id)) {
465
469
  errors.push(`id \u5FC5\u987B\u662F\u5E26\u547D\u540D\u7A7A\u95F4\u7684\u7A33\u5B9A id\uFF08\u5982 unity.compile\uFF1B\u6536\u5230 ${JSON.stringify(d.id)}\uFF09`);
466
470
  } else if (!d.id.startsWith(`${providerId}.`)) {
@@ -621,6 +625,7 @@ var CapabilityRegistry = class {
621
625
  preconditions: entry.descriptor.preconditions.map((p) => p.id),
622
626
  sideEffectKinds: [...new Set(entry.descriptor.sideEffects.map((s) => s.kind))],
623
627
  resources: entry.descriptor.resources.map((r) => ({
628
+ ...r.key ? { key: r.key } : {},
624
629
  kind: r.kind,
625
630
  mode: r.mode,
626
631
  scope: r.scope
@@ -630,10 +635,11 @@ var CapabilityRegistry = class {
630
635
  }
631
636
  };
632
637
 
633
- // src/core/project/config.ts
638
+ // src/core/execution/resource-locks.ts
634
639
  import fs2 from "fs";
635
640
  import path2 from "path";
636
- import { createHash } from "crypto";
641
+ import os from "os";
642
+ import { createHash, randomUUID } from "crypto";
637
643
 
638
644
  // src/core/project/paths.ts
639
645
  import fs from "fs";
@@ -650,26 +656,26 @@ function isPlainAbsolute(input) {
650
656
  return path.isAbsolute(input) || /^[A-Za-z]:/.test(input) || input.startsWith("\\\\") || input.startsWith("//");
651
657
  }
652
658
  function resolveProjectRoot(input, cwd = process.cwd()) {
653
- const root = path.resolve(cwd, input ?? ".");
659
+ const root2 = path.resolve(cwd, input ?? ".");
654
660
  let stat;
655
661
  try {
656
- stat = fs.statSync(root);
662
+ stat = fs.statSync(root2);
657
663
  } catch {
658
- throw new PathSafetyError("project-root-missing", `\u5DE5\u7A0B\u6839\u4E0D\u5B58\u5728: ${root}`);
664
+ throw new PathSafetyError("project-root-missing", `\u5DE5\u7A0B\u6839\u4E0D\u5B58\u5728: ${root2}`);
659
665
  }
660
666
  if (!stat.isDirectory()) {
661
- throw new PathSafetyError("project-root-not-directory", `\u5DE5\u7A0B\u6839\u4E0D\u662F\u76EE\u5F55: ${root}`);
667
+ throw new PathSafetyError("project-root-not-directory", `\u5DE5\u7A0B\u6839\u4E0D\u662F\u76EE\u5F55: ${root2}`);
662
668
  }
663
669
  let realRoot;
664
670
  try {
665
- realRoot = fs.realpathSync(root);
671
+ realRoot = fs.realpathSync(root2);
666
672
  } catch (err) {
667
673
  throw new PathSafetyError(
668
674
  "project-root-unreadable",
669
675
  `\u5DE5\u7A0B\u6839\u65E0\u6CD5\u89E3\u6790 realpath: ${err instanceof Error ? err.message : String(err)}`
670
676
  );
671
677
  }
672
- return { root, realRoot };
678
+ return { root: root2, realRoot };
673
679
  }
674
680
  function splitSafeRelative(relative, label) {
675
681
  if (typeof relative !== "string" || relative.length === 0) {
@@ -746,7 +752,134 @@ function comparePathForm(p) {
746
752
  return process.platform === "win32" ? forward.toLowerCase() : forward;
747
753
  }
748
754
 
755
+ // src/core/execution/resource-locks.ts
756
+ var alive = (pid) => {
757
+ try {
758
+ process.kill(pid, 0);
759
+ return true;
760
+ } catch (e) {
761
+ return e.code !== "ESRCH";
762
+ }
763
+ };
764
+ var root = () => path2.join(
765
+ os.tmpdir(),
766
+ "vant-capability-resources",
767
+ createHash("sha256").update(os.homedir()).digest("hex")
768
+ );
769
+ var conflicts = (a, b) => a.resources.some(
770
+ (x) => b.resources.some(
771
+ (y) => x.kind === y.kind && (x.key ?? "default") === (y.key ?? "default") && (x.scope === "machine" || y.scope === "machine" || (a.paths ?? [a.project]).some(
772
+ (p) => (b.paths ?? [b.project]).some(
773
+ (q) => p === q || p.startsWith(q + "/") || q.startsWith(p + "/")
774
+ )
775
+ )) && (x.mode === "exclusive" || y.mode === "exclusive")
776
+ )
777
+ );
778
+ var pause = () => new Promise((resolve) => setTimeout(resolve, 10));
779
+ async function retryFile(action) {
780
+ const deadline = Date.now() + 3e3;
781
+ for (; ; ) {
782
+ try {
783
+ return action();
784
+ } catch (error) {
785
+ if (!["EPERM", "EBUSY", "EACCES"].includes(
786
+ error.code ?? ""
787
+ ) || Date.now() >= deadline)
788
+ throw error;
789
+ await pause();
790
+ }
791
+ }
792
+ }
793
+ async function remove(file2) {
794
+ try {
795
+ await retryFile(() => fs2.unlinkSync(file2));
796
+ } catch (e) {
797
+ if (e.code !== "ENOENT") throw e;
798
+ }
799
+ }
800
+ async function acquireResources(project, resources, bindingPaths = []) {
801
+ if (!resources.length)
802
+ return Object.assign(async () => {
803
+ }, { transfer: async () => false });
804
+ const dir = root();
805
+ fs2.mkdirSync(dir, { recursive: true });
806
+ const paths = [project, ...bindingPaths].map(
807
+ (p) => comparePathForm(fs2.existsSync(p) ? fs2.realpathSync(p) : path2.resolve(p))
808
+ );
809
+ const claim = {
810
+ token: randomUUID(),
811
+ pid: process.pid,
812
+ project: comparePathForm(project),
813
+ paths,
814
+ resources
815
+ };
816
+ const file2 = path2.join(dir, claim.token + ".json");
817
+ async function write() {
818
+ const temp = file2 + "." + randomUUID() + ".pending";
819
+ try {
820
+ fs2.writeFileSync(temp, JSON.stringify(claim), { flag: "wx" });
821
+ await retryFile(() => fs2.renameSync(temp, file2));
822
+ } finally {
823
+ if (fs2.existsSync(temp)) await remove(temp);
824
+ }
825
+ }
826
+ await write();
827
+ let transferred = false;
828
+ try {
829
+ for (const name of fs2.readdirSync(dir).filter((n) => n.endsWith(".json"))) {
830
+ const existing = path2.join(dir, name);
831
+ if (existing === file2) continue;
832
+ let other;
833
+ try {
834
+ other = JSON.parse(
835
+ await retryFile(() => fs2.readFileSync(existing, "utf8"))
836
+ );
837
+ } catch (error) {
838
+ if (error.code === "ENOENT") continue;
839
+ throw error;
840
+ }
841
+ if (!alive(other.pid)) {
842
+ await remove(existing);
843
+ continue;
844
+ }
845
+ if (conflicts(claim, other))
846
+ throw Error(`\u8D44\u6E90\u6B63\u88AB\u8FDB\u7A0B ${other.pid} \u4F7F\u7528`);
847
+ }
848
+ } catch (error) {
849
+ await remove(file2);
850
+ throw error;
851
+ }
852
+ return Object.assign(
853
+ async () => {
854
+ if (transferred) return;
855
+ try {
856
+ const current = JSON.parse(
857
+ await retryFile(() => fs2.readFileSync(file2, "utf8"))
858
+ );
859
+ if (current.pid !== process.pid) return;
860
+ } catch (error) {
861
+ if (error.code === "ENOENT") return;
862
+ throw error;
863
+ }
864
+ await remove(file2);
865
+ },
866
+ {
867
+ async transfer(pid) {
868
+ if (!Number.isInteger(pid) || pid <= 0) throw Error("\u540E\u53F0\u8FDB\u7A0B\u8EAB\u4EFD\u65E0\u6548");
869
+ if (!alive(pid)) return false;
870
+ claim.pid = pid;
871
+ await write();
872
+ transferred = true;
873
+ return true;
874
+ }
875
+ }
876
+ );
877
+ }
878
+
749
879
  // src/core/project/config.ts
880
+ import fs3 from "fs";
881
+ import path3 from "path";
882
+ import { createHash as createHash2 } from "crypto";
750
883
  var PROJECT_CLI_CONFIG_RELATIVE = ".vant/config/v-cli.json";
751
884
  var VANT_PROJECT_CONFIG_RELATIVE = ".vant/config/project.json";
752
885
  var OPERATIONS_RELATIVE = ".vant/state/operations";
@@ -800,7 +933,7 @@ function toProviderSet(providers) {
800
933
  function resolveBindings(project, config, providers) {
801
934
  const errors = [];
802
935
  const pathUnsafeErrors = [];
803
- const result = {};
936
+ const result4 = {};
804
937
  const notePathError = (err) => {
805
938
  pathUnsafeErrors.push(err instanceof PathSafetyError ? err.message : String(err));
806
939
  };
@@ -889,7 +1022,7 @@ function resolveBindings(project, config, providers) {
889
1022
  }
890
1023
  }
891
1024
  if (errors.length > 0 || pathUnsafeErrors.length > 0) continue;
892
- result[providerId] = {
1025
+ result4[providerId] = {
893
1026
  providerId,
894
1027
  section: isPlainObject3(resolution.section) ? resolution.section : rawSection,
895
1028
  dirs: resolution.dirs,
@@ -900,15 +1033,15 @@ function resolveBindings(project, config, providers) {
900
1033
  if (errors.length > 0 || pathUnsafeErrors.length > 0) {
901
1034
  return { ok: false, errors: [...pathUnsafeErrors, ...errors], pathUnsafe: pathUnsafeErrors.length > 0 };
902
1035
  }
903
- return { ok: true, bindings: result };
1036
+ return { ok: true, bindings: result4 };
904
1037
  }
905
1038
  function loadProjectConfig(project, providers) {
906
- const file2 = path2.join(project.root, ...PROJECT_CLI_CONFIG_RELATIVE.split("/"));
1039
+ const file2 = path3.join(project.root, ...PROJECT_CLI_CONFIG_RELATIVE.split("/"));
907
1040
  const initHint = `\u8BF7\u5148\u5728\u5DE5\u7A0B\u6839\u8FD0\u884C \`v-cli project init --project <\u5DE5\u7A0B\u6839>\` \u751F\u6210 ${PROJECT_CLI_CONFIG_RELATIVE}`;
908
- let text;
1041
+ let text5;
909
1042
  try {
910
1043
  resolveInsideProject(project, PROJECT_CLI_CONFIG_RELATIVE, PROJECT_CLI_CONFIG_RELATIVE);
911
- text = fs2.readFileSync(file2, "utf-8");
1044
+ text5 = fs3.readFileSync(file2, "utf-8");
912
1045
  } catch (err) {
913
1046
  if (err instanceof Error && "code" in err && String(err.code).startsWith("path-")) {
914
1047
  return { ok: false, file: file2, kind: "unsafe-binding", errors: [err.message], hint: "\u914D\u7F6E\u6587\u4EF6\u5FC5\u987B\u4F4D\u4E8E\u5DE5\u7A0B\u6839\u5185\uFF0C\u7981\u6B62\u7B26\u53F7\u94FE\u63A5" };
@@ -926,7 +1059,7 @@ function loadProjectConfig(project, providers) {
926
1059
  }
927
1060
  let parsed;
928
1061
  try {
929
- parsed = JSON.parse(text);
1062
+ parsed = JSON.parse(text5);
930
1063
  } catch (err) {
931
1064
  return {
932
1065
  ok: false,
@@ -980,32 +1113,32 @@ function renderProjectConfig(project, providers, overrides = {}) {
980
1113
  return {
981
1114
  content,
982
1115
  bytes: Buffer.byteLength(content, "utf-8"),
983
- sha256: createHash("sha256").update(content, "utf-8").digest("hex"),
1116
+ sha256: createHash2("sha256").update(content, "utf-8").digest("hex"),
984
1117
  warnings,
985
1118
  bindings
986
1119
  };
987
1120
  }
988
1121
  var CONFIG_BACKUP_RELATIVE = ".vant/state/config-backups";
989
1122
  function atomicWriteConfig(project, file2, content) {
990
- const configDir = path2.dirname(file2);
1123
+ const configDir = path3.dirname(file2);
991
1124
  resolveInsideProject(project, ".vant/config", ".vant/config");
992
- fs2.mkdirSync(configDir, { recursive: true });
1125
+ fs3.mkdirSync(configDir, { recursive: true });
993
1126
  const tmpPath = `${file2}.${process.pid}.${Date.now()}.tmp`;
994
1127
  try {
995
- fs2.writeFileSync(tmpPath, content, { encoding: "utf-8" });
996
- fs2.renameSync(tmpPath, file2);
1128
+ fs3.writeFileSync(tmpPath, content, { encoding: "utf-8" });
1129
+ fs3.renameSync(tmpPath, file2);
997
1130
  } catch (err) {
998
1131
  try {
999
- fs2.rmSync(tmpPath, { force: true });
1132
+ fs3.rmSync(tmpPath, { force: true });
1000
1133
  } catch {
1001
1134
  }
1002
1135
  throw err;
1003
1136
  }
1004
1137
  }
1005
1138
  function initProjectConfig(project, providers, overrides = {}, options = {}) {
1006
- const file2 = path2.join(project.root, ...PROJECT_CLI_CONFIG_RELATIVE.split("/"));
1007
- const vantFile = path2.join(project.root, ...VANT_PROJECT_CONFIG_RELATIVE.split("/"));
1008
- const vantConfig = { file: vantFile, exists: fs2.existsSync(vantFile) };
1139
+ const file2 = path3.join(project.root, ...PROJECT_CLI_CONFIG_RELATIVE.split("/"));
1140
+ const vantFile = path3.join(project.root, ...VANT_PROJECT_CONFIG_RELATIVE.split("/"));
1141
+ const vantConfig = { file: vantFile, exists: fs3.existsSync(vantFile) };
1009
1142
  const refused = (reason) => ({
1010
1143
  ok: false,
1011
1144
  action: "refused",
@@ -1020,14 +1153,14 @@ function initProjectConfig(project, providers, overrides = {}, options = {}) {
1020
1153
  const known = [...providers.keys()].sort().join(", ") || "\uFF08\u65E0\u5DF2\u6CE8\u518C Provider\uFF09";
1021
1154
  return refused(`\u672A\u77E5 Provider \u7ED1\u5B9A\u8986\u76D6: ${unknownOverrides.join(", ")}\uFF08\u5DF2\u6CE8\u518C: ${known}\uFF09`);
1022
1155
  }
1023
- const exists = fs2.existsSync(file2);
1156
+ const exists = fs3.existsSync(file2);
1024
1157
  const reset = options.reset === true;
1025
1158
  const dryRun = options.dryRun === true;
1026
1159
  if (exists && !reset) {
1027
1160
  resolveInsideProject(project, PROJECT_CLI_CONFIG_RELATIVE, PROJECT_CLI_CONFIG_RELATIVE);
1028
1161
  let existing;
1029
1162
  try {
1030
- existing = JSON.parse(fs2.readFileSync(file2, "utf-8"));
1163
+ existing = JSON.parse(fs3.readFileSync(file2, "utf-8"));
1031
1164
  } catch (err) {
1032
1165
  return refused(
1033
1166
  `\u5DF2\u5B58\u5728 ${PROJECT_CLI_CONFIG_RELATIVE} \u4F46\u4E0D\u662F\u5408\u6CD5 JSON\uFF08${err instanceof Error ? err.message : String(err)}\uFF09\uFF1A\u5E42\u7B49\u8865\u5168\u8981\u6C42\u53EF\u89E3\u6790\uFF0C\u8BF7\u4FEE\u6B63\u540E\u91CD\u8BD5\u6216\u663E\u5F0F --reset\uFF08\u5C06\u5148\u5907\u4EFD\u65E7\u6587\u4EF6\uFF09`
@@ -1074,7 +1207,7 @@ function initProjectConfig(project, providers, overrides = {}, options = {}) {
1074
1207
  if (!existingCheck.ok) {
1075
1208
  return refused(`\u914D\u7F6E\u9F50\u5907\u4F46\u5B58\u5728\u65E0\u6548\u7ED1\u5B9A\uFF08${existingCheck.errors.join("\uFF1B")}\uFF09\uFF1A\u8BF7\u4FEE\u6B63\u6216\u663E\u5F0F --reset`);
1076
1209
  }
1077
- const current = fs2.readFileSync(file2, "utf-8");
1210
+ const current = fs3.readFileSync(file2, "utf-8");
1078
1211
  return {
1079
1212
  ok: true,
1080
1213
  action: "unchanged",
@@ -1084,7 +1217,7 @@ function initProjectConfig(project, providers, overrides = {}, options = {}) {
1084
1217
  file: file2,
1085
1218
  relativeFile: PROJECT_CLI_CONFIG_RELATIVE,
1086
1219
  bytes: Buffer.byteLength(current, "utf-8"),
1087
- sha256: createHash("sha256").update(current, "utf-8").digest("hex"),
1220
+ sha256: createHash2("sha256").update(current, "utf-8").digest("hex"),
1088
1221
  projectRoot: project.root,
1089
1222
  bindings: existingBindings,
1090
1223
  vantConfig,
@@ -1110,7 +1243,7 @@ function initProjectConfig(project, providers, overrides = {}, options = {}) {
1110
1243
  file: file2,
1111
1244
  relativeFile: PROJECT_CLI_CONFIG_RELATIVE,
1112
1245
  bytes: Buffer.byteLength(content, "utf-8"),
1113
- sha256: createHash("sha256").update(content, "utf-8").digest("hex"),
1246
+ sha256: createHash2("sha256").update(content, "utf-8").digest("hex"),
1114
1247
  projectRoot: project.root,
1115
1248
  bindings: merged,
1116
1249
  vantConfig,
@@ -1128,21 +1261,21 @@ function initProjectConfig(project, providers, overrides = {}, options = {}) {
1128
1261
  }
1129
1262
  let backupPath;
1130
1263
  if (reset && exists && !dryRun) {
1131
- const backupDir = path2.join(project.root, ...CONFIG_BACKUP_RELATIVE.split("/"));
1264
+ const backupDir = path3.join(project.root, ...CONFIG_BACKUP_RELATIVE.split("/"));
1132
1265
  resolveInsideProject(project, CONFIG_BACKUP_RELATIVE, CONFIG_BACKUP_RELATIVE);
1133
- fs2.mkdirSync(backupDir, { recursive: true });
1266
+ fs3.mkdirSync(backupDir, { recursive: true });
1134
1267
  const stamp = `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}-${process.pid.toString(36)}`;
1135
- backupPath = path2.join(backupDir, `v-cli.${stamp}.json`);
1136
- fs2.copyFileSync(file2, backupPath);
1268
+ backupPath = path3.join(backupDir, `v-cli.${stamp}.json`);
1269
+ fs3.copyFileSync(file2, backupPath);
1137
1270
  }
1138
1271
  if (!dryRun) {
1139
1272
  if (exists) {
1140
1273
  atomicWriteConfig(project, file2, rendered.content);
1141
1274
  } else {
1142
- const configDir = path2.join(project.root, ".vant", "config");
1275
+ const configDir = path3.join(project.root, ".vant", "config");
1143
1276
  resolveInsideProject(project, ".vant/config", ".vant/config");
1144
- fs2.mkdirSync(configDir, { recursive: true });
1145
- fs2.writeFileSync(file2, rendered.content, { encoding: "utf-8", flag: "wx" });
1277
+ fs3.mkdirSync(configDir, { recursive: true });
1278
+ fs3.writeFileSync(file2, rendered.content, { encoding: "utf-8", flag: "wx" });
1146
1279
  }
1147
1280
  }
1148
1281
  return {
@@ -1189,7 +1322,7 @@ function inspectProject(project, providers) {
1189
1322
  } else if (loaded.kind === "invalid" || loaded.kind === "unsafe-binding") {
1190
1323
  let rawBindings = {};
1191
1324
  try {
1192
- const parsed = JSON.parse(fs2.readFileSync(loaded.file, "utf-8"));
1325
+ const parsed = JSON.parse(fs3.readFileSync(loaded.file, "utf-8"));
1193
1326
  if (isPlainObject3(parsed) && isPlainObject3(parsed.bindings)) rawBindings = parsed.bindings;
1194
1327
  } catch {
1195
1328
  }
@@ -1244,26 +1377,26 @@ function inspectProject(project, providers) {
1244
1377
  });
1245
1378
  }
1246
1379
  }
1247
- const vantDir = path2.join(project.root, ".vant");
1380
+ const vantDir = path3.join(project.root, ".vant");
1248
1381
  let configFiles = [];
1249
- const configDir = path2.join(vantDir, "config");
1250
- if (fs2.existsSync(configDir)) {
1382
+ const configDir = path3.join(vantDir, "config");
1383
+ if (fs3.existsSync(configDir)) {
1251
1384
  try {
1252
- configFiles = fs2.readdirSync(configDir).sort();
1385
+ configFiles = fs3.readdirSync(configDir).sort();
1253
1386
  } catch {
1254
1387
  configFiles = [];
1255
1388
  }
1256
1389
  }
1257
- const stateDir = path2.join(project.root, ...OPERATIONS_RELATIVE.split("/"));
1390
+ const stateDir = path3.join(project.root, ...OPERATIONS_RELATIVE.split("/"));
1258
1391
  let operationCount = 0;
1259
- if (fs2.existsSync(stateDir)) {
1392
+ if (fs3.existsSync(stateDir)) {
1260
1393
  try {
1261
- operationCount = fs2.readdirSync(stateDir).filter((name) => fs2.statSync(path2.join(stateDir, name)).isDirectory()).length;
1394
+ operationCount = fs3.readdirSync(stateDir).filter((name) => fs3.statSync(path3.join(stateDir, name)).isDirectory()).length;
1262
1395
  } catch {
1263
1396
  operationCount = 0;
1264
1397
  }
1265
1398
  }
1266
- const vantFile = path2.join(project.root, ...VANT_PROJECT_CONFIG_RELATIVE.split("/"));
1399
+ const vantFile = path3.join(project.root, ...VANT_PROJECT_CONFIG_RELATIVE.split("/"));
1267
1400
  let bindingsValue = {};
1268
1401
  if (loaded.ok) bindingsValue = loaded.config.bindings;
1269
1402
  return {
@@ -1283,14 +1416,14 @@ function inspectProject(project, providers) {
1283
1416
  },
1284
1417
  vant: {
1285
1418
  dir: vantDir,
1286
- exists: fs2.existsSync(vantDir),
1419
+ exists: fs3.existsSync(vantDir),
1287
1420
  configFiles,
1288
1421
  projectConfigFile: vantFile,
1289
- projectConfigExists: fs2.existsSync(vantFile)
1422
+ projectConfigExists: fs3.existsSync(vantFile)
1290
1423
  },
1291
1424
  state: {
1292
1425
  dir: stateDir,
1293
- exists: fs2.existsSync(stateDir),
1426
+ exists: fs3.existsSync(stateDir),
1294
1427
  operationCount
1295
1428
  },
1296
1429
  initHint: `v-cli project init --project ${project.root}`
@@ -1298,13 +1431,13 @@ function inspectProject(project, providers) {
1298
1431
  }
1299
1432
 
1300
1433
  // src/core/execution/handle.ts
1301
- import fs4 from "fs";
1302
- import { createHash as createHash3 } from "crypto";
1434
+ import fs5 from "fs";
1435
+ import { createHash as createHash4 } from "crypto";
1303
1436
 
1304
1437
  // src/core/project/operation-store.ts
1305
- import fs3 from "fs";
1306
- import path3 from "path";
1307
- import { createHash as createHash2, randomBytes } from "crypto";
1438
+ import fs4 from "fs";
1439
+ import path4 from "path";
1440
+ import { createHash as createHash3, randomBytes } from "crypto";
1308
1441
  var OPERATION_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
1309
1442
  var WINDOWS_RESERVED = /* @__PURE__ */ new Set([
1310
1443
  "con",
@@ -1372,7 +1505,7 @@ var OperationStore = class _OperationStore {
1372
1505
  }
1373
1506
  const operationsRoot = resolveInsideProject(project, OPERATIONS_RELATIVE, OPERATIONS_RELATIVE);
1374
1507
  try {
1375
- fs3.mkdirSync(operationsRoot.path, { recursive: true });
1508
+ fs4.mkdirSync(operationsRoot.path, { recursive: true });
1376
1509
  } catch (err) {
1377
1510
  throw new PathSafetyError(
1378
1511
  "operations-dir-failed",
@@ -1380,9 +1513,9 @@ var OperationStore = class _OperationStore {
1380
1513
  );
1381
1514
  }
1382
1515
  const verifiedRoot = resolveInsideProject(project, OPERATIONS_RELATIVE, OPERATIONS_RELATIVE);
1383
- const dir = path3.join(verifiedRoot.path, operationId);
1516
+ const dir = path4.join(verifiedRoot.path, operationId);
1384
1517
  try {
1385
- fs3.mkdirSync(dir);
1518
+ fs4.mkdirSync(dir);
1386
1519
  } catch (err) {
1387
1520
  if (err.code === "EEXIST") {
1388
1521
  throw new OperationExistsError(operationId, dir);
@@ -1408,7 +1541,7 @@ var OperationStore = class _OperationStore {
1408
1541
  write(fileName, content, flags = "w") {
1409
1542
  if (!this.enabled || !this.dir) return false;
1410
1543
  try {
1411
- fs3.writeFileSync(path3.join(this.dir, fileName), content, { encoding: "utf-8", flag: flags });
1544
+ fs4.writeFileSync(path4.join(this.dir, fileName), content, { encoding: "utf-8", flag: flags });
1412
1545
  if (!this.writtenFiles.includes(fileName)) this.writtenFiles.push(fileName);
1413
1546
  return true;
1414
1547
  } catch (err) {
@@ -1427,7 +1560,7 @@ var OperationStore = class _OperationStore {
1427
1560
  this.events.push(record);
1428
1561
  if (!this.enabled || !this.dir) return;
1429
1562
  try {
1430
- fs3.appendFileSync(path3.join(this.dir, "events.jsonl"), `${JSON.stringify(record)}
1563
+ fs4.appendFileSync(path4.join(this.dir, "events.jsonl"), `${JSON.stringify(record)}
1431
1564
  `, "utf-8");
1432
1565
  if (!this.writtenFiles.includes("events.jsonl")) this.writtenFiles.push("events.jsonl");
1433
1566
  } catch (err) {
@@ -1448,10 +1581,10 @@ var OperationStore = class _OperationStore {
1448
1581
  stderr: this.writeLog("stderr.log", input.stderr, input.stderrTruncated ?? false)
1449
1582
  };
1450
1583
  }
1451
- writeLog(fileName, text, truncated) {
1452
- const bytes = Buffer.byteLength(text, "utf-8");
1453
- const sha256 = createHash2("sha256").update(text, "utf-8").digest("hex");
1454
- const capped = bytes > MAX_LOG_BYTES ? Buffer.from(text, "utf-8").subarray(0, MAX_LOG_BYTES).toString("utf-8") : text;
1584
+ writeLog(fileName, text5, truncated) {
1585
+ const bytes = Buffer.byteLength(text5, "utf-8");
1586
+ const sha256 = createHash3("sha256").update(text5, "utf-8").digest("hex");
1587
+ const capped = bytes > MAX_LOG_BYTES ? Buffer.from(text5, "utf-8").subarray(0, MAX_LOG_BYTES).toString("utf-8") : text5;
1455
1588
  const truncatedFinal = truncated || bytes > MAX_LOG_BYTES;
1456
1589
  const saved = this.write(fileName, capped);
1457
1590
  return {
@@ -1459,12 +1592,12 @@ var OperationStore = class _OperationStore {
1459
1592
  truncated: truncatedFinal,
1460
1593
  sha256,
1461
1594
  file: saved ? fileName : null,
1462
- tail: text.length > TAIL_CHARS ? text.slice(-TAIL_CHARS) : text
1595
+ tail: text5.length > TAIL_CHARS ? text5.slice(-TAIL_CHARS) : text5
1463
1596
  };
1464
1597
  }
1465
- writeResult(result) {
1598
+ writeResult(result4) {
1466
1599
  this.event("operation-finished", "\u7ED3\u679C\u5DF2\u8BB0\u5F55");
1467
- this.write("result.json", `${JSON.stringify(result, null, 2)}
1600
+ this.write("result.json", `${JSON.stringify(result4, null, 2)}
1468
1601
  `);
1469
1602
  }
1470
1603
  summary() {
@@ -1499,7 +1632,7 @@ function canonicalize(value) {
1499
1632
  return JSON.stringify(value) ?? "null";
1500
1633
  }
1501
1634
  function handleDigest(handle) {
1502
- return createHash3("sha256").update(canonicalize(handle), "utf-8").digest("hex");
1635
+ return createHash4("sha256").update(canonicalize(handle), "utf-8").digest("hex");
1503
1636
  }
1504
1637
  function buildExecutionHandle(input) {
1505
1638
  const base = {
@@ -1601,14 +1734,14 @@ function verifyExecutionHandle(input) {
1601
1734
  }
1602
1735
  throw err;
1603
1736
  }
1604
- if (!fs4.existsSync(recordPath)) {
1737
+ if (!fs5.existsSync(recordPath)) {
1605
1738
  return fail("handle-evidence-missing", [
1606
1739
  `\u53E5\u67C4\u8BC1\u636E\u7F3A\u5931: ${expectedDir}/result.json\uFF08\u76EE\u5F55\u6216\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1B\u4E0D\u56DE\u9000\u6700\u8FD1\u4EFB\u52A1\uFF09`
1607
1740
  ]);
1608
1741
  }
1609
1742
  let raw;
1610
1743
  try {
1611
- raw = JSON.parse(fs4.readFileSync(recordPath, "utf-8"));
1744
+ raw = JSON.parse(fs5.readFileSync(recordPath, "utf-8"));
1612
1745
  } catch (err) {
1613
1746
  return fail("handle-evidence-unreadable", [
1614
1747
  `\u53E5\u67C4\u8BC1\u636E\u4E0D\u53EF\u8BFB: ${err instanceof Error ? err.message : String(err)}`
@@ -1830,16 +1963,16 @@ function validateOutcomeShape(outcome) {
1830
1963
  }
1831
1964
  return errors;
1832
1965
  }
1833
- function exitCodeForResult(result) {
1834
- const errorCategory = result.execution.error?.category;
1966
+ function exitCodeForResult(result4) {
1967
+ const errorCategory = result4.execution.error?.category;
1835
1968
  if (errorCategory === "request" || errorCategory === "config" || errorCategory === "precondition" || errorCategory === "resource") {
1836
1969
  return 2;
1837
1970
  }
1838
- if (result.execution.status === "cancelled") return 4;
1839
- if (result.execution.status === "unknown") return 5;
1840
- if (result.execution.status === "failed") return 1;
1841
- if (result.acceptance.status === "failed") return 1;
1842
- if (result.acceptance.status === "passed") return 0;
1971
+ if (result4.execution.status === "cancelled") return 4;
1972
+ if (result4.execution.status === "unknown") return 5;
1973
+ if (result4.execution.status === "failed") return 1;
1974
+ if (result4.acceptance.status === "failed") return 1;
1975
+ if (result4.acceptance.status === "passed") return 0;
1843
1976
  return 3;
1844
1977
  }
1845
1978
  function mergeEvidence(...groups) {
@@ -1997,7 +2130,7 @@ async function runCapability(registry, request, deps = {}) {
1997
2130
  };
1998
2131
  let executionHandle = null;
1999
2132
  const finish = (partial) => {
2000
- const result = buildResult({
2133
+ const result4 = buildResult({
2001
2134
  entry,
2002
2135
  operationId,
2003
2136
  project,
@@ -2016,15 +2149,15 @@ async function runCapability(registry, request, deps = {}) {
2016
2149
  finishedAt: clock(),
2017
2150
  ...partial
2018
2151
  });
2019
- if (request.persist === false) return result;
2020
- store.writeResult(result);
2152
+ if (request.persist === false) return result4;
2153
+ store.writeResult(result4);
2021
2154
  if (store.failureMessage) {
2022
- result.persisted.status = "failed";
2023
- result.persisted.error = store.failureMessage;
2155
+ result4.persisted.status = "failed";
2156
+ result4.persisted.error = store.failureMessage;
2024
2157
  warn(`\u64CD\u4F5C\u8BB0\u5F55\u5199\u5165\u4E0D\u5B8C\u6574: ${store.failureMessage}`);
2025
- store.writeResult(result);
2158
+ store.writeResult(result4);
2026
2159
  }
2027
- return result;
2160
+ return result4;
2028
2161
  };
2029
2162
  const cancelledBeforeExecution = () => finish({
2030
2163
  command: null,
@@ -2166,36 +2299,11 @@ async function runCapability(registry, request, deps = {}) {
2166
2299
  });
2167
2300
  }
2168
2301
  }
2169
- const preconditionOutcomes = [];
2170
- for (const declaration of entry.descriptor.preconditions) {
2171
- if (signal.aborted) return cancelledBeforeExecution();
2172
- const checker = entry.implementation.preconditions?.[declaration.id];
2173
- if (!checker) {
2174
- preconditionOutcomes.push({
2175
- id: declaration.id,
2176
- status: "unknown",
2177
- detail: "\u7F3A\u5C11\u524D\u7F6E\u6761\u4EF6\u68C0\u67E5\u5B9E\u73B0"
2178
- });
2179
- continue;
2180
- }
2181
- try {
2182
- const outcome2 = await checker(input, context);
2183
- if (!outcome2 || outcome2.id !== declaration.id || !["satisfied", "violated"].includes(outcome2.status) || typeof outcome2.detail !== "string") {
2184
- preconditionOutcomes.push({ id: declaration.id, status: "unknown", detail: "\u524D\u7F6E\u6761\u4EF6\u672A\u660E\u786E\u6EE1\u8DB3\u6216\u8FD4\u56DE\u4E0D\u7B26\u5408\u58F0\u660E" });
2185
- } else {
2186
- preconditionOutcomes.push(outcome2);
2187
- }
2188
- store.event("precondition", `${declaration.id}: ${outcome2.status}`, { detail: outcome2.detail });
2189
- } catch (err) {
2190
- preconditionOutcomes.push({
2191
- id: declaration.id,
2192
- status: "unknown",
2193
- detail: `\u68C0\u67E5\u629B\u51FA\u5F02\u5E38: ${err instanceof Error ? err.message : String(err)}`
2194
- });
2195
- }
2196
- }
2197
- const blocking = preconditionOutcomes.filter((o) => o.status === "violated" || o.status === "unknown");
2198
- if (blocking.length > 0) {
2302
+ let releaseResources;
2303
+ try {
2304
+ releaseResources = await acquireResources(project.realRoot, entry.descriptor.resources, Object.values(providerBindingDirs));
2305
+ store.event("resources-acquired", "\u5DF2\u53D6\u5F97\u8DE8\u8FDB\u7A0B\u8D44\u6E90\u79DF\u7EA6");
2306
+ } catch (error) {
2199
2307
  return finish({
2200
2308
  command: null,
2201
2309
  execution: {
@@ -2204,20 +2312,10 @@ async function runCapability(registry, request, deps = {}) {
2204
2312
  exitCode: null,
2205
2313
  signal: null,
2206
2314
  attempts: 0,
2207
- error: structuredError(
2208
- "precondition-failed",
2209
- "precondition",
2210
- `\u524D\u7F6E\u6761\u4EF6\u672A\u6EE1\u8DB3\uFF0C\u672A\u6267\u884C\uFF1A${blocking.map((b) => `${b.id}(${b.status})`).join(", ")}`,
2211
- { details: { outcomes: blocking } }
2212
- )
2213
- },
2214
- acceptance: {
2215
- status: "not-run",
2216
- reason: "\u524D\u7F6E\u6761\u4EF6\u672A\u6EE1\u8DB3\uFF0C\u672A\u6267\u884C",
2217
- pending: false,
2218
- evidence: mergeEvidence(...blocking.map((b) => b.evidence))
2315
+ error: structuredError("resource-busy", "resource", error instanceof Error ? error.message : String(error))
2219
2316
  },
2220
- preconditions: preconditionOutcomes,
2317
+ acceptance: { status: "not-run", reason: "\u8D44\u6E90\u6B63\u5728\u4F7F\u7528\uFF0C\u672A\u6267\u884C", pending: false, evidence: [] },
2318
+ preconditions: [],
2221
2319
  resources: authorization,
2222
2320
  sideEffects: [],
2223
2321
  artifacts: [],
@@ -2229,170 +2327,242 @@ async function runCapability(registry, request, deps = {}) {
2229
2327
  tool: null
2230
2328
  });
2231
2329
  }
2232
- if (signal.aborted) return cancelledBeforeExecution();
2233
- store.event("execute-start", `\u5F00\u59CB\u6267\u884C ${entry.descriptor.id}`);
2234
- let outcome;
2235
2330
  try {
2236
- outcome = await entry.implementation.execute(input, context);
2237
- } catch (err) {
2238
- const error = toStructuredError(err);
2239
- store.event("execute-threw", error.message);
2240
- outcome = {
2241
- execution: { status: "failed", lifecycle: "unknown", exitCode: null, signal: null, error },
2242
- acceptance: {
2243
- status: "not-run",
2244
- reason: "\u5B9E\u73B0\u629B\u51FA\u5F02\u5E38\uFF0C\u672A\u4EA7\u751F\u4E1A\u52A1\u7ED3\u8BBA",
2245
- pending: false,
2246
- evidence: []
2331
+ const preconditionOutcomes = [];
2332
+ for (const declaration of entry.descriptor.preconditions) {
2333
+ if (signal.aborted) return cancelledBeforeExecution();
2334
+ const checker = entry.implementation.preconditions?.[declaration.id];
2335
+ if (!checker) {
2336
+ preconditionOutcomes.push({
2337
+ id: declaration.id,
2338
+ status: "unknown",
2339
+ detail: "\u7F3A\u5C11\u524D\u7F6E\u6761\u4EF6\u68C0\u67E5\u5B9E\u73B0"
2340
+ });
2341
+ continue;
2247
2342
  }
2343
+ try {
2344
+ const outcome2 = await checker(input, context);
2345
+ if (!outcome2 || outcome2.id !== declaration.id || !["satisfied", "violated"].includes(outcome2.status) || typeof outcome2.detail !== "string") {
2346
+ preconditionOutcomes.push({ id: declaration.id, status: "unknown", detail: "\u524D\u7F6E\u6761\u4EF6\u672A\u660E\u786E\u6EE1\u8DB3\u6216\u8FD4\u56DE\u4E0D\u7B26\u5408\u58F0\u660E" });
2347
+ } else {
2348
+ preconditionOutcomes.push(outcome2);
2349
+ }
2350
+ store.event("precondition", `${declaration.id}: ${outcome2.status}`, { detail: outcome2.detail });
2351
+ } catch (err) {
2352
+ preconditionOutcomes.push({
2353
+ id: declaration.id,
2354
+ status: "unknown",
2355
+ detail: `\u68C0\u67E5\u629B\u51FA\u5F02\u5E38: ${err instanceof Error ? err.message : String(err)}`
2356
+ });
2357
+ }
2358
+ }
2359
+ const blocking = preconditionOutcomes.filter((o) => o.status === "violated" || o.status === "unknown");
2360
+ if (blocking.length > 0) {
2361
+ return finish({
2362
+ command: null,
2363
+ execution: {
2364
+ status: "failed",
2365
+ lifecycle: "completed",
2366
+ exitCode: null,
2367
+ signal: null,
2368
+ attempts: 0,
2369
+ error: structuredError(
2370
+ "precondition-failed",
2371
+ "precondition",
2372
+ `\u524D\u7F6E\u6761\u4EF6\u672A\u6EE1\u8DB3\uFF0C\u672A\u6267\u884C\uFF1A${blocking.map((b) => `${b.id}(${b.status})`).join(", ")}`,
2373
+ { details: { outcomes: blocking } }
2374
+ )
2375
+ },
2376
+ acceptance: {
2377
+ status: "not-run",
2378
+ reason: "\u524D\u7F6E\u6761\u4EF6\u672A\u6EE1\u8DB3\uFF0C\u672A\u6267\u884C",
2379
+ pending: false,
2380
+ evidence: mergeEvidence(...blocking.map((b) => b.evidence))
2381
+ },
2382
+ preconditions: preconditionOutcomes,
2383
+ resources: authorization,
2384
+ sideEffects: [],
2385
+ artifacts: [],
2386
+ logs: emptyLogs(),
2387
+ output: null,
2388
+ followUp: [],
2389
+ notes: [],
2390
+ warnings: [],
2391
+ tool: null
2392
+ });
2393
+ }
2394
+ if (signal.aborted) return cancelledBeforeExecution();
2395
+ store.event("execute-start", `\u5F00\u59CB\u6267\u884C ${entry.descriptor.id}`);
2396
+ let outcome;
2397
+ try {
2398
+ outcome = await entry.implementation.execute(input, context);
2399
+ if (outcome && typeof outcome === "object" && outcome.resourceOwnerPid !== void 0) {
2400
+ const transferred = await releaseResources.transfer(outcome.resourceOwnerPid);
2401
+ store.event(transferred ? "resources-transferred" : "resources-process-ended", transferred ? "\u540E\u53F0\u8FDB\u7A0B\u7EE7\u7EED\u6301\u6709\u8D44\u6E90\u79DF\u7EA6" : "\u540E\u53F0\u8FDB\u7A0B\u5DF2\u9000\u51FA\uFF0C\u4ECD\u987B\u6838\u5BF9\u539F\u5B8C\u6210\u56DE\u6267", { pid: outcome.resourceOwnerPid });
2402
+ }
2403
+ } catch (err) {
2404
+ const error = toStructuredError(err);
2405
+ store.event("execute-threw", error.message);
2406
+ outcome = {
2407
+ execution: { status: "failed", lifecycle: "unknown", exitCode: null, signal: null, error },
2408
+ acceptance: {
2409
+ status: "not-run",
2410
+ reason: "\u5B9E\u73B0\u629B\u51FA\u5F02\u5E38\uFF0C\u672A\u4EA7\u751F\u4E1A\u52A1\u7ED3\u8BBA",
2411
+ pending: false,
2412
+ evidence: []
2413
+ }
2414
+ };
2415
+ }
2416
+ const shapeErrors = validateOutcomeShape(outcome);
2417
+ const shapeError = shapeErrors.length > 0 ? structuredError("implementation-contract-violation", "internal", "\u5B9E\u73B0\u8FD4\u56DE\u7684\u7ED3\u679C\u4E0D\u7B26\u5408\u5185\u6838\u5951\u7EA6", {
2418
+ details: { errors: shapeErrors }
2419
+ }) : null;
2420
+ const safeOutcome = typeof outcome === "object" && outcome !== null ? outcome : {};
2421
+ store.event(
2422
+ "execute-finish",
2423
+ `\u6267\u884C\u72B6\u6001 ${safeOutcome.execution?.status ?? "?"}/${safeOutcome.execution?.lifecycle ?? "?"}`
2424
+ );
2425
+ if (shapeError) store.event("implementation-contract-violation", shapeError.message, { errors: shapeErrors });
2426
+ const execution = {
2427
+ status: safeOutcome.execution?.status ?? "unknown",
2428
+ lifecycle: safeOutcome.execution?.lifecycle ?? "unknown",
2429
+ exitCode: safeOutcome.execution?.exitCode ?? null,
2430
+ signal: safeOutcome.execution?.signal ?? null,
2431
+ attempts: 1,
2432
+ error: shapeError ?? safeOutcome.execution?.error ?? null
2248
2433
  };
2249
- }
2250
- const shapeErrors = validateOutcomeShape(outcome);
2251
- const shapeError = shapeErrors.length > 0 ? structuredError("implementation-contract-violation", "internal", "\u5B9E\u73B0\u8FD4\u56DE\u7684\u7ED3\u679C\u4E0D\u7B26\u5408\u5185\u6838\u5951\u7EA6", {
2252
- details: { errors: shapeErrors }
2253
- }) : null;
2254
- const safeOutcome = typeof outcome === "object" && outcome !== null ? outcome : {};
2255
- store.event(
2256
- "execute-finish",
2257
- `\u6267\u884C\u72B6\u6001 ${safeOutcome.execution?.status ?? "?"}/${safeOutcome.execution?.lifecycle ?? "?"}`
2258
- );
2259
- if (shapeError) store.event("implementation-contract-violation", shapeError.message, { errors: shapeErrors });
2260
- const execution = {
2261
- status: safeOutcome.execution?.status ?? "unknown",
2262
- lifecycle: safeOutcome.execution?.lifecycle ?? "unknown",
2263
- exitCode: safeOutcome.execution?.exitCode ?? null,
2264
- signal: safeOutcome.execution?.signal ?? null,
2265
- attempts: 1,
2266
- error: shapeError ?? safeOutcome.execution?.error ?? null
2267
- };
2268
- let output = safeOutcome.output;
2269
- const warnings = [];
2270
- const notes = Array.isArray(safeOutcome.notes) ? [...safeOutcome.notes] : [];
2271
- let contractError = shapeError;
2272
- const shouldValidateOutput = !shapeError && (output !== void 0 || execution.status === "succeeded");
2273
- if (shouldValidateOutput) {
2274
- const outputErrors = validateValue(output, entry.descriptor.outputSchema, "$output");
2275
- if (outputErrors.length > 0) {
2276
- contractError = structuredError(
2277
- output === void 0 ? "output-missing" : "output-contract-violation",
2278
- "output",
2279
- `\u8F93\u51FA\u4E0D\u7B26\u5408 ${entry.descriptor.id} \u7684\u8F93\u51FA schema`,
2280
- { details: { errors: outputErrors } }
2281
- );
2282
- store.event("output-invalid", contractError.message, { errors: outputErrors });
2283
- } else {
2284
- store.event("output-validated", "\u8F93\u51FA\u901A\u8FC7 schema \u6821\u9A8C");
2285
- }
2286
- }
2287
- const sideEffects = Array.isArray(safeOutcome.sideEffects) ? [...safeOutcome.sideEffects] : [];
2288
- const declaredKinds = new Set(entry.descriptor.sideEffects.map((s) => s.kind));
2289
- const undeclared = sideEffects.filter((s) => !declaredKinds.has(s.kind));
2290
- if (undeclared.length > 0) {
2291
- const message = `\u5B9E\u73B0\u4E0A\u62A5\u4E86\u672A\u58F0\u660E\u7684\u526F\u4F5C\u7528\u7C7B\u578B: ${[...new Set(undeclared.map((u) => u.kind))].join(", ")}`;
2292
- contractError ??= structuredError("side-effect-undeclared", "output", message, { details: { undeclared } });
2293
- store.event("side-effect-undeclared", message);
2294
- }
2295
- const handleSeed = safeOutcome.handle;
2296
- const seedErrors = handleSeed === void 0 ? [] : validateHandleSeed(handleSeed);
2297
- if (seedErrors.length > 0) {
2298
- const seedError = structuredError("handle-seed-invalid", "internal", `\u5B9E\u73B0\u63D0\u4F9B\u7684\u53E5\u67C4\u79CD\u5B50\u975E\u6CD5: ${seedErrors.join("\uFF1B")}`);
2299
- contractError ??= seedError;
2300
- store.event("handle-seed-invalid", seedError.message);
2301
- }
2302
- const executionFinal = contractError ? {
2303
- status: "unknown",
2304
- lifecycle: "unknown",
2305
- exitCode: execution.exitCode,
2306
- signal: execution.signal,
2307
- attempts: 1,
2308
- error: contractError
2309
- } : execution;
2310
- if (seedErrors.length === 0 && handleSeed !== void 0 && executionFinal.status === "succeeded") {
2311
- executionHandle = buildExecutionHandle({
2312
- seed: handleSeed,
2313
- providerId: entry.provider.id,
2314
- capabilityId: entry.descriptor.id,
2315
- operationId,
2316
- project,
2317
- configFile: loadedConfig.file,
2318
- startedAt: startedAt.toISOString(),
2319
- persisted: persist
2320
- });
2321
- store.event("handle-issued", "\u5F02\u6B65\u6267\u884C\u53E5\u67C4\u5DF2\u4EA7\u51FA", {
2322
- originOperationId: operationId,
2323
- backendTaskId: executionHandle.backendTaskId,
2324
- recoverable: executionHandle.recoverable
2325
- });
2326
- }
2327
- const outcomeAcceptance = safeOutcome.acceptance;
2328
- const acceptance = {
2329
- // 实现返回违约时一律不给验收结论(哪怕它自称 passed 并带了证据)
2330
- status: shapeError ? "not-run" : outcomeAcceptance?.status ?? "not-run",
2331
- reason: shapeError ? "\u5B9E\u73B0\u8FD4\u56DE\u4E0D\u7B26\u5408\u5185\u6838\u5951\u7EA6\uFF0C\u65E0\u9A8C\u6536\u7ED3\u8BBA" : outcomeAcceptance?.reason ?? "\u5B9E\u73B0\u672A\u7ED9\u51FA\u9A8C\u6536\u7406\u7531",
2332
- pending: false,
2333
- evidence: mergeEvidence(outcomeAcceptance?.evidence, safeOutcome.evidence)
2334
- };
2335
- if (!shapeError && outcomeAcceptance?.pending === true) acceptance.pending = true;
2336
- if (!shapeError && outcomeAcceptance?.status === "passed" && (executionFinal.status !== "succeeded" || executionFinal.lifecycle === "accepted" || executionFinal.lifecycle === "unknown" || acceptance.pending || signal.aborted)) {
2337
- acceptance.status = "not-run";
2338
- acceptance.reason = `\u6267\u884C\u72B6\u6001 ${executionFinal.status}/${executionFinal.lifecycle}\uFF0C\u5B9E\u73B0\u7ED9\u51FA\u7684 passed \u88AB\u5185\u6838\u964D\u7EA7\u4E3A not-run`;
2339
- acceptance.pending = false;
2340
- store.event("acceptance-downgraded", acceptance.reason);
2341
- }
2342
- if (acceptance.status === "passed" && acceptance.evidence.length === 0) {
2343
- acceptance.status = "not-run";
2344
- acceptance.reason = "\u9A8C\u6536\u7ED3\u8BBA\u7F3A\u5C11\u8BC1\u636E\uFF0C\u5185\u6838\u62D2\u7EDD\u7ED9\u51FA passed";
2345
- acceptance.pending = false;
2346
- store.event("acceptance-downgraded", acceptance.reason);
2347
- }
2348
- const raw = safeOutcome.rawOutput ?? { stdout: "", stderr: "" };
2349
- const logs = store.writeLogs({
2350
- stdout: typeof raw.stdout === "string" ? raw.stdout : "",
2351
- stderr: typeof raw.stderr === "string" ? raw.stderr : "",
2352
- stdoutTruncated: raw.stdoutTruncated,
2353
- stderrTruncated: raw.stderrTruncated
2354
- });
2355
- const artifacts = Array.isArray(safeOutcome.artifacts) ? [...safeOutcome.artifacts] : [];
2356
- if (logs.stdout.bytes > 0 && !artifacts.some((a) => a.kind === "log" && a.path === logs.stdout.file)) {
2357
- artifacts.push({
2358
- kind: "log",
2359
- path: logs.stdout.file,
2360
- description: "\u4E3B\u8FDB\u7A0B stdout \u539F\u6587",
2361
- sha256: logs.stdout.sha256,
2362
- bytes: logs.stdout.bytes
2434
+ let output = safeOutcome.output;
2435
+ const warnings = [];
2436
+ const notes = Array.isArray(safeOutcome.notes) ? [...safeOutcome.notes] : [];
2437
+ let contractError = shapeError;
2438
+ const shouldValidateOutput = !shapeError && (output !== void 0 || execution.status === "succeeded");
2439
+ if (shouldValidateOutput) {
2440
+ const outputErrors = validateValue(output, entry.descriptor.outputSchema, "$output");
2441
+ if (outputErrors.length > 0) {
2442
+ contractError = structuredError(
2443
+ output === void 0 ? "output-missing" : "output-contract-violation",
2444
+ "output",
2445
+ `\u8F93\u51FA\u4E0D\u7B26\u5408 ${entry.descriptor.id} \u7684\u8F93\u51FA schema`,
2446
+ { details: { errors: outputErrors } }
2447
+ );
2448
+ store.event("output-invalid", contractError.message, { errors: outputErrors });
2449
+ } else {
2450
+ store.event("output-validated", "\u8F93\u51FA\u901A\u8FC7 schema \u6821\u9A8C");
2451
+ }
2452
+ }
2453
+ const sideEffects = Array.isArray(safeOutcome.sideEffects) ? [...safeOutcome.sideEffects] : [];
2454
+ const declaredKinds = new Set(entry.descriptor.sideEffects.map((s) => s.kind));
2455
+ const undeclared = sideEffects.filter((s) => !declaredKinds.has(s.kind));
2456
+ if (undeclared.length > 0) {
2457
+ const message = `\u5B9E\u73B0\u4E0A\u62A5\u4E86\u672A\u58F0\u660E\u7684\u526F\u4F5C\u7528\u7C7B\u578B: ${[...new Set(undeclared.map((u) => u.kind))].join(", ")}`;
2458
+ contractError ??= structuredError("side-effect-undeclared", "output", message, { details: { undeclared } });
2459
+ store.event("side-effect-undeclared", message);
2460
+ }
2461
+ const handleSeed = safeOutcome.handle;
2462
+ const seedErrors = handleSeed === void 0 ? [] : validateHandleSeed(handleSeed);
2463
+ if (seedErrors.length > 0) {
2464
+ const seedError = structuredError("handle-seed-invalid", "internal", `\u5B9E\u73B0\u63D0\u4F9B\u7684\u53E5\u67C4\u79CD\u5B50\u975E\u6CD5: ${seedErrors.join("\uFF1B")}`);
2465
+ contractError ??= seedError;
2466
+ store.event("handle-seed-invalid", seedError.message);
2467
+ }
2468
+ const executionFinal = contractError ? {
2469
+ status: "unknown",
2470
+ lifecycle: "unknown",
2471
+ exitCode: execution.exitCode,
2472
+ signal: execution.signal,
2473
+ attempts: 1,
2474
+ error: contractError
2475
+ } : execution;
2476
+ if (seedErrors.length === 0 && handleSeed !== void 0 && executionFinal.status === "succeeded") {
2477
+ executionHandle = buildExecutionHandle({
2478
+ seed: handleSeed,
2479
+ providerId: entry.provider.id,
2480
+ capabilityId: entry.descriptor.id,
2481
+ operationId,
2482
+ project,
2483
+ configFile: loadedConfig.file,
2484
+ startedAt: startedAt.toISOString(),
2485
+ persisted: persist
2486
+ });
2487
+ store.event("handle-issued", "\u5F02\u6B65\u6267\u884C\u53E5\u67C4\u5DF2\u4EA7\u51FA", {
2488
+ originOperationId: operationId,
2489
+ backendTaskId: executionHandle.backendTaskId,
2490
+ recoverable: executionHandle.recoverable
2491
+ });
2492
+ }
2493
+ const outcomeAcceptance = safeOutcome.acceptance;
2494
+ const acceptance = {
2495
+ // 实现返回违约时一律不给验收结论(哪怕它自称 passed 并带了证据)
2496
+ status: shapeError ? "not-run" : outcomeAcceptance?.status ?? "not-run",
2497
+ reason: shapeError ? "\u5B9E\u73B0\u8FD4\u56DE\u4E0D\u7B26\u5408\u5185\u6838\u5951\u7EA6\uFF0C\u65E0\u9A8C\u6536\u7ED3\u8BBA" : outcomeAcceptance?.reason ?? "\u5B9E\u73B0\u672A\u7ED9\u51FA\u9A8C\u6536\u7406\u7531",
2498
+ pending: false,
2499
+ evidence: mergeEvidence(outcomeAcceptance?.evidence, safeOutcome.evidence)
2500
+ };
2501
+ if (!shapeError && outcomeAcceptance?.pending === true) acceptance.pending = true;
2502
+ if (!shapeError && outcomeAcceptance?.status === "passed" && (executionFinal.status !== "succeeded" || executionFinal.lifecycle === "accepted" || executionFinal.lifecycle === "unknown" || acceptance.pending || signal.aborted)) {
2503
+ acceptance.status = "not-run";
2504
+ acceptance.reason = `\u6267\u884C\u72B6\u6001 ${executionFinal.status}/${executionFinal.lifecycle}\uFF0C\u5B9E\u73B0\u7ED9\u51FA\u7684 passed \u88AB\u5185\u6838\u964D\u7EA7\u4E3A not-run`;
2505
+ acceptance.pending = false;
2506
+ store.event("acceptance-downgraded", acceptance.reason);
2507
+ }
2508
+ if (acceptance.status === "passed" && acceptance.evidence.length === 0) {
2509
+ acceptance.status = "not-run";
2510
+ acceptance.reason = "\u9A8C\u6536\u7ED3\u8BBA\u7F3A\u5C11\u8BC1\u636E\uFF0C\u5185\u6838\u62D2\u7EDD\u7ED9\u51FA passed";
2511
+ acceptance.pending = false;
2512
+ store.event("acceptance-downgraded", acceptance.reason);
2513
+ }
2514
+ const raw = safeOutcome.rawOutput ?? { stdout: "", stderr: "" };
2515
+ const logs = store.writeLogs({
2516
+ stdout: typeof raw.stdout === "string" ? raw.stdout : "",
2517
+ stderr: typeof raw.stderr === "string" ? raw.stderr : "",
2518
+ stdoutTruncated: raw.stdoutTruncated,
2519
+ stderrTruncated: raw.stderrTruncated
2363
2520
  });
2364
- }
2365
- if (logs.stderr.bytes > 0 && !artifacts.some((a) => a.kind === "log" && a.path === logs.stderr.file)) {
2366
- artifacts.push({
2367
- kind: "log",
2368
- path: logs.stderr.file,
2369
- description: "\u4E3B\u8FDB\u7A0B stderr \u539F\u6587",
2370
- sha256: logs.stderr.sha256,
2371
- bytes: logs.stderr.bytes
2521
+ const artifacts = Array.isArray(safeOutcome.artifacts) ? [...safeOutcome.artifacts] : [];
2522
+ if (logs.stdout.bytes > 0 && !artifacts.some((a) => a.kind === "log" && a.path === logs.stdout.file)) {
2523
+ artifacts.push({
2524
+ kind: "log",
2525
+ path: logs.stdout.file,
2526
+ description: "\u4E3B\u8FDB\u7A0B stdout \u539F\u6587",
2527
+ sha256: logs.stdout.sha256,
2528
+ bytes: logs.stdout.bytes
2529
+ });
2530
+ }
2531
+ if (logs.stderr.bytes > 0 && !artifacts.some((a) => a.kind === "log" && a.path === logs.stderr.file)) {
2532
+ artifacts.push({
2533
+ kind: "log",
2534
+ path: logs.stderr.file,
2535
+ description: "\u4E3B\u8FDB\u7A0B stderr \u539F\u6587",
2536
+ sha256: logs.stderr.sha256,
2537
+ bytes: logs.stderr.bytes
2538
+ });
2539
+ }
2540
+ return finish({
2541
+ command: safeOutcome.command ?? null,
2542
+ execution: executionFinal,
2543
+ acceptance,
2544
+ preconditions: preconditionOutcomes,
2545
+ resources: authorization,
2546
+ sideEffects,
2547
+ artifacts,
2548
+ logs,
2549
+ output,
2550
+ followUp: Array.isArray(safeOutcome.followUp) ? safeOutcome.followUp : [],
2551
+ notes,
2552
+ warnings,
2553
+ tool: safeOutcome.tool ?? null
2372
2554
  });
2555
+ } finally {
2556
+ await releaseResources();
2373
2557
  }
2374
- return finish({
2375
- command: safeOutcome.command ?? null,
2376
- execution: executionFinal,
2377
- acceptance,
2378
- preconditions: preconditionOutcomes,
2379
- resources: authorization,
2380
- sideEffects,
2381
- artifacts,
2382
- logs,
2383
- output,
2384
- followUp: Array.isArray(safeOutcome.followUp) ? safeOutcome.followUp : [],
2385
- notes,
2386
- warnings,
2387
- tool: safeOutcome.tool ?? null
2388
- });
2389
2558
  }
2390
- function formatResultJson(result) {
2391
- return JSON.stringify(result, null, 2);
2559
+ function formatResultJson(result4) {
2560
+ return JSON.stringify(result4, null, 2);
2392
2561
  }
2393
2562
 
2394
2563
  // src/core/execution/executor.ts
2395
2564
  import { spawn } from "child_process";
2565
+ import path5 from "path";
2396
2566
  var DEFAULT_MAX_OUTPUT = 8 * 1024 * 1024;
2397
2567
  var OutputCollector = class {
2398
2568
  constructor(limit) {
@@ -2460,6 +2630,7 @@ var NodeProcessExecutor = class {
2460
2630
  env: buildEnv(invocation.env),
2461
2631
  shell: false,
2462
2632
  windowsHide: true,
2633
+ detached: process.platform !== "win32",
2463
2634
  stdio: ["ignore", "pipe", "pipe"]
2464
2635
  });
2465
2636
  } catch (err) {
@@ -2491,11 +2662,37 @@ var NodeProcessExecutor = class {
2491
2662
  let aborted = false;
2492
2663
  let killRequested = false;
2493
2664
  let settled = false;
2665
+ let killTree;
2494
2666
  const requestKill = () => {
2667
+ if (killRequested) return;
2495
2668
  killRequested = true;
2496
- try {
2497
- child.kill("SIGKILL");
2498
- } catch {
2669
+ if (!child.pid) {
2670
+ killTree = Promise.resolve(false);
2671
+ return;
2672
+ }
2673
+ if (process.platform === "win32") {
2674
+ killTree = new Promise((resolve) => {
2675
+ const killer = spawn(path5.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "taskkill.exe"), ["/PID", String(child.pid), "/T", "/F"], { windowsHide: true, stdio: "ignore", shell: false });
2676
+ const timeout = setTimeout(() => {
2677
+ killer.kill();
2678
+ resolve(false);
2679
+ }, 1e4);
2680
+ killer.once("error", () => {
2681
+ clearTimeout(timeout);
2682
+ resolve(false);
2683
+ });
2684
+ killer.once("close", (code) => {
2685
+ clearTimeout(timeout);
2686
+ resolve(code === 0);
2687
+ });
2688
+ });
2689
+ } else {
2690
+ try {
2691
+ process.kill(-child.pid, "SIGKILL");
2692
+ killTree = Promise.resolve(true);
2693
+ } catch {
2694
+ killTree = Promise.resolve(false);
2695
+ }
2499
2696
  }
2500
2697
  };
2501
2698
  const timer = invocation.timeoutMs !== void 0 && invocation.timeoutMs > 0 ? setTimeout(() => {
@@ -2507,11 +2704,12 @@ var NodeProcessExecutor = class {
2507
2704
  requestKill();
2508
2705
  };
2509
2706
  invocation.signal?.addEventListener("abort", onAbort, { once: true });
2707
+ if (invocation.signal?.aborted) onAbort();
2510
2708
  const cleanup = () => {
2511
2709
  if (timer) clearTimeout(timer);
2512
2710
  invocation.signal?.removeEventListener("abort", onAbort);
2513
2711
  };
2514
- const finish = (exitCode, signal, spawnError) => {
2712
+ const finish = async (exitCode, signal, spawnError) => {
2515
2713
  if (settled) return;
2516
2714
  settled = true;
2517
2715
  cleanup();
@@ -2524,7 +2722,7 @@ var NodeProcessExecutor = class {
2524
2722
  stderrTruncated: errOut.truncated,
2525
2723
  timedOut,
2526
2724
  aborted,
2527
- killConfirmed: killRequested && spawnError === null,
2725
+ killConfirmed: killRequested && spawnError === null && await killTree === true,
2528
2726
  durationMs: Date.now() - started,
2529
2727
  startedAt: startedAt.toISOString(),
2530
2728
  finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -2540,15 +2738,14 @@ var NodeProcessExecutor = class {
2540
2738
  }
2541
2739
  };
2542
2740
 
2543
- // src/providers/unity/index.ts
2544
- import fs6 from "fs";
2545
- import path5 from "path";
2741
+ // src/providers/ship/index.ts
2742
+ import fs7 from "fs";
2546
2743
 
2547
2744
  // src/core/official.ts
2548
2745
  import { createRequire } from "module";
2549
2746
  import { fileURLToPath } from "url";
2550
- import path4 from "path";
2551
- import fs5 from "fs";
2747
+ import path6 from "path";
2748
+ import fs6 from "fs";
2552
2749
 
2553
2750
  // src/core/manifest.ts
2554
2751
  var RESERVED_MANIFEST_COMMAND_NAMES = [
@@ -2807,20 +3004,20 @@ function defaultResolvePackage(pkg, opts = {}) {
2807
3004
  const resolveFrom = opts.resolveFrom ?? process.env.V_CLI_PLUGIN_RESOLVE_FROM;
2808
3005
  const candidates = [];
2809
3006
  if (resolveFrom) {
2810
- candidates.push(path4.join(path4.resolve(cwd, resolveFrom), "node_modules", pkg, "package.json"));
3007
+ candidates.push(path6.join(path6.resolve(cwd, resolveFrom), "node_modules", pkg, "package.json"));
2811
3008
  }
2812
3009
  try {
2813
3010
  candidates.push(createRequire(baseFile).resolve(`${pkg}/package.json`));
2814
3011
  } catch {
2815
3012
  }
2816
3013
  try {
2817
- const reqCwd = createRequire(path4.join(cwd, "__v_cli_resolve__.cjs"));
3014
+ const reqCwd = createRequire(path6.join(cwd, "__v_cli_resolve__.cjs"));
2818
3015
  candidates.push(reqCwd.resolve(`${pkg}/package.json`, { paths: [cwd] }));
2819
3016
  } catch {
2820
3017
  }
2821
3018
  for (const candidate of candidates) {
2822
3019
  try {
2823
- if (fs5.existsSync(candidate)) return candidate;
3020
+ if (fs6.existsSync(candidate)) return candidate;
2824
3021
  } catch {
2825
3022
  }
2826
3023
  }
@@ -2828,13 +3025,13 @@ function defaultResolvePackage(pkg, opts = {}) {
2828
3025
  }
2829
3026
  function defaultExists(file2) {
2830
3027
  try {
2831
- return fs5.existsSync(file2);
3028
+ return fs6.existsSync(file2);
2832
3029
  } catch {
2833
3030
  return false;
2834
3031
  }
2835
3032
  }
2836
3033
  function defaultRead(file2) {
2837
- return fs5.readFileSync(file2, "utf-8");
3034
+ return fs6.readFileSync(file2, "utf-8");
2838
3035
  }
2839
3036
  function formatErrors2(errors) {
2840
3037
  return errors.join("\uFF1B");
@@ -2879,8 +3076,8 @@ function discoverOfficialPlugin(spec, io = {}) {
2879
3076
  }
2880
3077
  const vCliMeta = pkgJson.vCli && isPlainObject6(pkgJson.vCli) ? pkgJson.vCli : {};
2881
3078
  const manifestRel = typeof vCliMeta.manifest === "string" ? vCliMeta.manifest : "v-cli.plugin.json";
2882
- const pkgRoot = path4.dirname(pkgJsonPath);
2883
- const manifestPath = path4.join(pkgRoot, manifestRel);
3079
+ const pkgRoot = path6.dirname(pkgJsonPath);
3080
+ const manifestPath = path6.join(pkgRoot, manifestRel);
2884
3081
  if (!exists(manifestPath)) {
2885
3082
  return {
2886
3083
  ...base,
@@ -2935,8 +3132,8 @@ function discoverOfficialPlugin(spec, io = {}) {
2935
3132
  error: `bin "${manifest.bin}" \u7684\u542F\u52A8\u76EE\u6807\u4E0D\u662F\u5B57\u7B26\u4E32\u8DEF\u5F84`
2936
3133
  };
2937
3134
  }
2938
- const binPath = path4.resolve(pkgRoot, binRel);
2939
- const rootPrefix = pkgRoot.endsWith(path4.sep) ? pkgRoot : pkgRoot + path4.sep;
3135
+ const binPath = path6.resolve(pkgRoot, binRel);
3136
+ const rootPrefix = pkgRoot.endsWith(path6.sep) ? pkgRoot : pkgRoot + path6.sep;
2940
3137
  if (!binPath.startsWith(rootPrefix)) {
2941
3138
  return {
2942
3139
  ...base,
@@ -2944,11 +3141,28 @@ function discoverOfficialPlugin(spec, io = {}) {
2944
3141
  error: `bin "${manifest.bin}" \u7684\u76EE\u6807 ${binRel} \u9003\u9038\u4E86\u5305\u76EE\u5F55`
2945
3142
  };
2946
3143
  }
3144
+ const metadata = {
3145
+ whenToUse: manifest.agent.whenToUse,
3146
+ globalOptions: manifest.agent.globalOptions,
3147
+ commands: manifest.agent.commands.map((c) => ({
3148
+ path: c.path,
3149
+ usage: c.usage,
3150
+ description: c.description,
3151
+ arguments: c.arguments,
3152
+ options: c.options,
3153
+ output: c.output,
3154
+ exitCodes: c.exitCodes,
3155
+ safety: c.safety
3156
+ })),
3157
+ runtime: manifest.runtime,
3158
+ environment: manifest.environment
3159
+ };
2947
3160
  const requiredPlatforms = manifest.platforms;
2948
3161
  if (!requiredPlatforms.includes(platform)) {
2949
3162
  return {
2950
3163
  ...base,
2951
3164
  status: "platform-mismatch",
3165
+ ...metadata,
2952
3166
  version: typeof pkgJson.version === "string" ? pkgJson.version : void 0,
2953
3167
  requiredPlatforms,
2954
3168
  error: `\u8BE5\u63D2\u4EF6\u4EC5\u652F\u6301\u5E73\u53F0 [${requiredPlatforms.join(", ")}]\uFF0C\u5F53\u524D\u5E73\u53F0\u4E3A ${platform}`
@@ -2968,38 +3182,902 @@ function discoverOfficialPlugin(spec, io = {}) {
2968
3182
  version: typeof pkgJson.version === "string" ? pkgJson.version : void 0,
2969
3183
  requiredPlatforms,
2970
3184
  bin: binPath,
2971
- whenToUse: manifest.agent.whenToUse,
2972
- globalOptions: manifest.agent.globalOptions,
2973
- commands: manifest.agent.commands.map((c) => ({
2974
- path: c.path,
2975
- usage: c.usage,
2976
- description: c.description,
2977
- arguments: c.arguments,
2978
- options: c.options,
2979
- output: c.output,
2980
- exitCodes: c.exitCodes,
2981
- safety: c.safety
2982
- })),
2983
- runtime: manifest.runtime,
2984
- environment: manifest.environment
3185
+ ...metadata
3186
+ };
3187
+ }
3188
+
3189
+ // src/providers/command-provider.ts
3190
+ function commandRegistrations(id, definitions4, deps) {
3191
+ const discover = deps.discoverBackend ?? (() => discoverOfficialPlugin(OFFICIAL_PLUGINS.find((p) => p.command === id)));
3192
+ return definitions4.map((d) => ({
3193
+ descriptor: {
3194
+ id: `${id}.${d.id}`,
3195
+ version: "0.1.0",
3196
+ description: d.description,
3197
+ commands: d.sourceCommands ?? [d.command],
3198
+ inputSchema: {
3199
+ type: "object",
3200
+ additionalProperties: false,
3201
+ properties: d.fields,
3202
+ required: d.required ?? []
3203
+ },
3204
+ outputSchema: {
3205
+ type: "object",
3206
+ additionalProperties: false,
3207
+ required: ["result", "error"],
3208
+ properties: {
3209
+ result: { ...d.result, nullable: true },
3210
+ error: {
3211
+ type: "object",
3212
+ nullable: true,
3213
+ required: ["code", "message"],
3214
+ properties: {
3215
+ code: { type: "string" },
3216
+ message: { type: "string" }
3217
+ },
3218
+ additionalProperties: false
3219
+ }
3220
+ }
3221
+ },
3222
+ preconditions: [
3223
+ { id: `${id}.binding`, description: "\u5DE5\u5177\u5DF2\u5B89\u88C5\u4E14\u5DE5\u7A0B\u7ED1\u5B9A\u6709\u6548" }
3224
+ ],
3225
+ sideEffects: [
3226
+ "process-exec",
3227
+ "fs-read",
3228
+ ...!d.readonly ? ["fs-write"] : [],
3229
+ ...d.network ? ["network"] : []
3230
+ ].map((kind) => ({
3231
+ id: kind,
3232
+ kind,
3233
+ description: d.description,
3234
+ reversible: kind === "fs-read"
3235
+ })),
3236
+ resources: d.control ? [] : [
3237
+ {
3238
+ kind: "project-workspace",
3239
+ mode: d.readonly ? "shared" : "exclusive",
3240
+ scope: "project",
3241
+ description: "\u5DE5\u7A0B\u8BFB\u5199\u4E92\u65A5"
3242
+ },
3243
+ ...d.engine ? [
3244
+ {
3245
+ kind: "engine-editor",
3246
+ mode: "exclusive",
3247
+ scope: "project",
3248
+ description: "\u5F15\u64CE\u64CD\u4F5C\u4E92\u65A5"
3249
+ }
3250
+ ] : [],
3251
+ ...d.machine ? [
3252
+ {
3253
+ kind: "user-cache",
3254
+ key: id,
3255
+ mode: "exclusive",
3256
+ scope: "machine",
3257
+ description: "\u5DE5\u5177\u8D26\u53F7\u53CA\u7528\u6237\u7F13\u5B58\u4E92\u65A5"
3258
+ }
3259
+ ] : []
3260
+ ],
3261
+ retry: {
3262
+ safe: !!d.readonly,
3263
+ maxAttempts: 1,
3264
+ strategy: "none",
3265
+ description: "\u5355\u6B21\u6267\u884C\uFF1B\u5199\u5165\u6216\u4E0A\u4F20\u7ED3\u679C\u672A\u77E5\u65F6\u5148\u6838\u5B9E\uFF0C\u4E0D\u81EA\u52A8\u91CD\u653E"
3266
+ }
3267
+ },
3268
+ implementation: {
3269
+ preconditions: {
3270
+ [`${id}.binding`]: (input, ctx) => {
3271
+ try {
3272
+ if (!ctx.binding || discover().status !== "available")
3273
+ throw Error("\u9700\u8981\u53EF\u7528\u540E\u7AEF\u4E0E\u5DE5\u7A0B\u7ED1\u5B9A");
3274
+ if (d.pending && !ctx.persist)
3275
+ throw Error("\u540E\u53F0\u670D\u52A1\u5FC5\u987B\u4FDD\u5B58\u64CD\u4F5C\u8BB0\u5F55\uFF0C\u4EE5\u4FBF\u67E5\u8BE2\u548C\u505C\u6B62");
3276
+ d.args(input, ctx);
3277
+ return {
3278
+ id: `${id}.binding`,
3279
+ status: "satisfied",
3280
+ detail: "\u540E\u7AEF\u3001\u7ED1\u5B9A\u548C\u8DEF\u5F84\u9884\u68C0\u901A\u8FC7"
3281
+ };
3282
+ } catch (error) {
3283
+ return {
3284
+ id: `${id}.binding`,
3285
+ status: "violated",
3286
+ detail: error instanceof Error ? error.message : String(error)
3287
+ };
3288
+ }
3289
+ }
3290
+ },
3291
+ execute: async (input, ctx) => {
3292
+ const backend = discover();
3293
+ const args = [backend.bin, ...d.command, ...d.args(input, ctx)];
3294
+ const outcome = await deps.executor.run({
3295
+ file: process.execPath,
3296
+ args,
3297
+ cwd: ctx.bindingDirs.projectDir ?? ctx.projectRoot,
3298
+ env: deps.env,
3299
+ signal: ctx.signal,
3300
+ timeoutMs: 30 * 60 * 1e3
3301
+ });
3302
+ const execution = executionFromProcess(outcome);
3303
+ const effects = [
3304
+ {
3305
+ kind: "process-exec",
3306
+ description: "\u5DF2\u6267\u884C\u53D7\u63A7\u5DE5\u5177\u8FDB\u7A0B",
3307
+ reversible: false
3308
+ },
3309
+ {
3310
+ kind: "fs-read",
3311
+ description: "\u8BFB\u53D6\u5DE5\u7A0B\u914D\u7F6E\u4E0E\u4EA7\u7269",
3312
+ reversible: true
3313
+ },
3314
+ ...!d.readonly ? [
3315
+ {
3316
+ kind: "fs-write",
3317
+ description: "\u5DE5\u5177\u53EF\u80FD\u5DF2\u5199\u5165\u6587\u4EF6\u6216\u672C\u5730\u72B6\u6001\uFF0C\u8BE6\u89C1\u56DE\u6267",
3318
+ reversible: false
3319
+ }
3320
+ ] : [],
3321
+ ...d.network ? [
3322
+ {
3323
+ kind: "network",
3324
+ description: "\u5DE5\u5177\u53EF\u80FD\u5DF2\u8BBF\u95EE\u5916\u90E8\u670D\u52A1\uFF0C\u8BE6\u89C1\u56DE\u6267",
3325
+ reversible: false
3326
+ }
3327
+ ] : []
3328
+ ];
3329
+ let result4;
3330
+ try {
3331
+ result4 = d.dispatch ? { dispatched: outcome.exitCode === 0 } : JSON.parse(outcome.stdout);
3332
+ if (!result4 || typeof result4 !== "object" || Array.isArray(result4) || outcome.stdoutTruncated)
3333
+ throw Error();
3334
+ } catch {
3335
+ return {
3336
+ execution: {
3337
+ ...execution,
3338
+ status: "failed",
3339
+ lifecycle: d.readonly && execution.lifecycle !== "unknown" ? "failed" : "unknown",
3340
+ error: structuredError(
3341
+ `${id}-output-invalid`,
3342
+ "protocol",
3343
+ "\u5DE5\u5177\u672A\u8FD4\u56DE\u5B8C\u6574 JSON\uFF0C\u4E0D\u80FD\u63A8\u65AD\u64CD\u4F5C\u5B8C\u6210"
3344
+ )
3345
+ },
3346
+ acceptance: {
3347
+ status: "not-run",
3348
+ reason: "\u7ED3\u679C\u4E0D\u53EF\u9A8C\u8BC1\uFF1B\u5148\u6838\u5BF9\u539F\u64CD\u4F5C\uFF0C\u7981\u6B62\u76F2\u76EE\u91CD\u8BD5"
3349
+ },
3350
+ sideEffects: effects,
3351
+ rawOutput: outcome,
3352
+ command: { file: process.execPath, args }
3353
+ };
3354
+ }
3355
+ let valid = validateValue(result4, d.result, "$result").length === 0;
3356
+ let verified = false;
3357
+ if (valid) {
3358
+ try {
3359
+ verified = d.verify(result4);
3360
+ } catch {
3361
+ valid = false;
3362
+ }
3363
+ }
3364
+ const passed = valid && execution.status === "succeeded" && verified;
3365
+ const owner = passed ? d.pending?.(result4) : null;
3366
+ const settled = valid ? d.settlement?.(result4) : void 0;
3367
+ return {
3368
+ execution: {
3369
+ ...execution,
3370
+ ...!valid ? {
3371
+ status: "unknown",
3372
+ lifecycle: "unknown",
3373
+ error: structuredError(
3374
+ `${id}-output-invalid`,
3375
+ "protocol",
3376
+ "\u5DE5\u5177\u56DE\u6267\u672A\u901A\u8FC7 schema \u6821\u9A8C"
3377
+ )
3378
+ } : {},
3379
+ ...owner ? { lifecycle: "accepted" } : {},
3380
+ ...settled ? {
3381
+ lifecycle: settled.lifecycle,
3382
+ ...settled.lifecycle === "cancelled" ? { status: "cancelled" } : {}
3383
+ } : {}
3384
+ },
3385
+ acceptance: {
3386
+ status: settled?.acceptance ?? (owner ? "not-run" : passed ? "passed" : "failed"),
3387
+ reason: owner || settled?.pending ? "\u540E\u53F0\u670D\u52A1\u4ECD\u5728\u8FD0\u884C\uFF0C\u5C1A\u672A\u5B8C\u6210\u4E1A\u52A1\u64CD\u4F5C" : passed ? "\u5DE5\u5177\u5B8C\u6210\u56DE\u6267\u901A\u8FC7\u6821\u9A8C" : "\u5DE5\u5177\u5B8C\u6210\u56DE\u6267\u672A\u901A\u8FC7\u9A8C\u6536",
3388
+ pending: settled?.pending ?? !!owner,
3389
+ evidence: [
3390
+ {
3391
+ kind: "protocol-field",
3392
+ description: "\u5DE5\u5177\u539F\u59CB JSON \u56DE\u6267",
3393
+ data: result4
3394
+ }
3395
+ ]
3396
+ },
3397
+ ...owner ? {
3398
+ resourceOwnerPid: owner,
3399
+ handle: { backendTaskId: String(owner) }
3400
+ } : {},
3401
+ ...owner || settled?.pending ? {
3402
+ followUp: [
3403
+ {
3404
+ capabilityId: `${id}.status`,
3405
+ hint: "\u4F7F\u7528\u539F\u542F\u52A8 handle \u67E5\u8BE2\u5B8C\u6210\u56DE\u6267\uFF1B\u4E0D\u91CD\u65B0\u542F\u52A8"
3406
+ }
3407
+ ]
3408
+ } : {},
3409
+ output: valid ? { result: result4, error: null } : {
3410
+ result: null,
3411
+ error: {
3412
+ code: `${id}-output-invalid`,
3413
+ message: "\u5DE5\u5177\u56DE\u6267\u672A\u901A\u8FC7 schema \u6821\u9A8C\uFF0C\u8BE6\u60C5\u89C1\u539F\u59CB\u65E5\u5FD7"
3414
+ }
3415
+ },
3416
+ rawOutput: outcome,
3417
+ command: { file: process.execPath, args },
3418
+ sideEffects: effects,
3419
+ tool: { name: id, version: backend.version, path: backend.bin }
3420
+ };
3421
+ }
3422
+ }
3423
+ }));
3424
+ }
3425
+ function projectCommandProvider(id, definitions4, deps) {
3426
+ const discover = deps.discoverBackend ?? (() => discoverOfficialPlugin(OFFICIAL_PLUGINS.find((p) => p.command === id)));
3427
+ return {
3428
+ id,
3429
+ version: "0.1.0",
3430
+ description: `${id} \u7ED3\u6784\u5316\u6267\u884C`,
3431
+ binding: {
3432
+ schema: {
3433
+ type: "object",
3434
+ additionalProperties: false,
3435
+ required: ["projectDir"],
3436
+ properties: { projectDir: { type: "string", minLength: 1 } }
3437
+ },
3438
+ pathFields: [{ field: "projectDir", kind: "dir", required: true }],
3439
+ resolve: ({ project, raw, resolveInsideProject: resolveInsideProject2 }) => ({
3440
+ ok: true,
3441
+ dirs: {
3442
+ projectDir: resolveInsideProject2(
3443
+ project,
3444
+ raw.projectDir,
3445
+ `bindings.${id}.projectDir`
3446
+ ).path
3447
+ },
3448
+ files: {},
3449
+ section: raw,
3450
+ warnings: []
3451
+ })
3452
+ },
3453
+ defaultBinding: () => ({ section: { projectDir: "." }, warnings: [] }),
3454
+ status: () => {
3455
+ const b = discover();
3456
+ return {
3457
+ state: b.status,
3458
+ detail: b.error ?? `${b.package}@${b.version}`,
3459
+ tool: { name: id, version: b.version, path: b.bin }
3460
+ };
3461
+ },
3462
+ capabilities: () => commandRegistrations(id, definitions4, deps)
2985
3463
  };
2986
3464
  }
2987
3465
 
3466
+ // src/providers/ship/index.ts
3467
+ var text = { type: "string", minLength: 1 };
3468
+ var bool = { type: "boolean" };
3469
+ var result = (fields, required = Object.keys(fields)) => ({
3470
+ type: "object",
3471
+ properties: fields,
3472
+ required,
3473
+ additionalProperties: true
3474
+ });
3475
+ var ok = { ok: { type: "boolean" } };
3476
+ var commands = [
3477
+ ...["steam", "wx"].map((platform) => ({
3478
+ id: platform + "-open",
3479
+ command: [platform, "open"],
3480
+ description: "\u6253\u5F00\u5E73\u53F0\u7BA1\u7406\u9875\u9762",
3481
+ fields: {},
3482
+ dispatch: true,
3483
+ result: result({ dispatched: bool }),
3484
+ verify: (r) => r.dispatched === true
3485
+ })),
3486
+ {
3487
+ id: "doctor",
3488
+ command: ["doctor"],
3489
+ description: "\u8BCA\u65AD\u6E38\u620F\u5206\u53D1\u73AF\u5883",
3490
+ fields: {},
3491
+ readonly: true,
3492
+ result: result({ checks: { type: "array" } }),
3493
+ verify: (r) => Array.isArray(r.checks) && r.checks.every(
3494
+ (x) => x !== null && typeof x === "object" && ["ok", "warn", "skip"].includes(String(x.status))
3495
+ )
3496
+ },
3497
+ {
3498
+ id: "config-init",
3499
+ command: ["config", "init"],
3500
+ description: "\u521B\u5EFA\u6E38\u620F\u5206\u53D1\u914D\u7F6E",
3501
+ fields: { force: bool },
3502
+ result: result({ written: text, force: bool }),
3503
+ verify: (r) => typeof r.written === "string" && fs7.existsSync(r.written)
3504
+ },
3505
+ {
3506
+ id: "config-validate",
3507
+ command: ["config", "validate"],
3508
+ description: "\u6821\u9A8C\u6E38\u620F\u5206\u53D1\u914D\u7F6E",
3509
+ fields: {},
3510
+ readonly: true,
3511
+ result: result(ok),
3512
+ verify: (r) => r.ok === true
3513
+ },
3514
+ {
3515
+ id: "config-show",
3516
+ command: ["config", "show"],
3517
+ description: "\u8BFB\u53D6\u6E38\u620F\u5206\u53D1\u914D\u7F6E",
3518
+ fields: {},
3519
+ readonly: true,
3520
+ result: result({ projectRoot: text }),
3521
+ verify: (r) => typeof r.projectRoot === "string"
3522
+ },
3523
+ {
3524
+ id: "steam-vdf",
3525
+ command: ["steam", "vdf"],
3526
+ description: "\u751F\u6210 Steam \u6784\u5EFA\u6E05\u5355",
3527
+ fields: { desc: text, "set-live": text, preview: bool },
3528
+ result: result({
3529
+ appBuild: text,
3530
+ depots: { type: "array" },
3531
+ preview: bool
3532
+ }),
3533
+ verify: (r) => typeof r.appBuild === "string" && fs7.existsSync(r.appBuild)
3534
+ },
3535
+ ...["preview", "push"].map((action) => ({
3536
+ id: `steam-${action}`,
3537
+ command: ["steam", action],
3538
+ description: action === "push" ? "\u4E0A\u4F20 Steam \u6D4B\u8BD5\u6784\u5EFA" : "\u9884\u6F14 Steam \u6784\u5EFA",
3539
+ fields: {
3540
+ desc: text,
3541
+ ...action === "push" ? {
3542
+ "set-live": {
3543
+ type: "string",
3544
+ minLength: 1,
3545
+ pattern: "^(?!default$).+"
3546
+ }
3547
+ } : {}
3548
+ },
3549
+ network: action === "push",
3550
+ machine: true,
3551
+ result: result({
3552
+ ...ok,
3553
+ mode: text,
3554
+ appId: { type: "integer" },
3555
+ buildId: { type: "string", nullable: true },
3556
+ logPath: text
3557
+ }),
3558
+ verify: (r) => r.ok === true && r.mode === (action === "push" ? "build" : "preview (no upload)")
3559
+ })),
3560
+ {
3561
+ id: "steam-test",
3562
+ command: ["steam", "test"],
3563
+ description: "\u6821\u9A8C Steam \u8FD0\u884C\u4EA7\u7269",
3564
+ fields: { "write-appid": bool },
3565
+ result: result(ok),
3566
+ verify: (r) => r.ok === true
3567
+ },
3568
+ {
3569
+ id: "wx-validate",
3570
+ command: ["wx", "validate"],
3571
+ description: "\u6821\u9A8C\u5FAE\u4FE1\u5C0F\u6E38\u620F\u5305",
3572
+ fields: {},
3573
+ readonly: true,
3574
+ result: result(ok),
3575
+ verify: (r) => r.ok === true
3576
+ },
3577
+ ...["preview", "push"].map((action) => ({
3578
+ id: `wx-${action}`,
3579
+ command: ["wx", action],
3580
+ description: action === "push" ? "\u4E0A\u4F20\u5FAE\u4FE1\u5C0F\u6E38\u620F\u5F00\u53D1\u7248" : "\u751F\u6210\u5FAE\u4FE1\u5C0F\u6E38\u620F\u9884\u89C8\u4E8C\u7EF4\u7801",
3581
+ fields: {
3582
+ desc: text,
3583
+ robot: { type: "integer", minimum: 1, maximum: 30 },
3584
+ ...action === "push" ? { version: text } : { "qr-out": text }
3585
+ },
3586
+ required: action === "push" ? ["version"] : [],
3587
+ network: true,
3588
+ machine: true,
3589
+ result: result({
3590
+ ...ok,
3591
+ mode: text,
3592
+ appid: text,
3593
+ robot: { type: "integer" },
3594
+ qrOut: { type: "string", nullable: true }
3595
+ }),
3596
+ verify: (r) => r.ok === true && r.mode === (action === "push" ? "upload" : "preview") && (action !== "preview" || typeof r.qrOut === "string" && fs7.existsSync(r.qrOut))
3597
+ }))
3598
+ ];
3599
+ var definitions = commands.map((d) => ({
3600
+ ...d,
3601
+ args: (input, ctx) => {
3602
+ if (d.dispatch) return [d.command[0] === "steam" ? "builds" : "mp"];
3603
+ const args = ["--project", ctx.bindingDirs.projectDir, "--json"];
3604
+ for (const [key, value] of Object.entries(input)) {
3605
+ if (value === false) continue;
3606
+ args.push(`--${key}`);
3607
+ if (value !== true)
3608
+ args.push(
3609
+ key === "qr-out" ? resolveInsideProject(
3610
+ ctx.projectAnchor,
3611
+ String(value),
3612
+ "ship.qr-out"
3613
+ ).path : String(value)
3614
+ );
3615
+ }
3616
+ return args;
3617
+ }
3618
+ }));
3619
+ var createShipProvider = (deps) => projectCommandProvider("ship", definitions, deps);
3620
+
3621
+ // src/providers/xlmerge/index.ts
3622
+ import fs8 from "fs";
3623
+ import path7 from "path";
3624
+ var text2 = { type: "string", minLength: 1 };
3625
+ var ok2 = {
3626
+ type: "object",
3627
+ required: ["ok"],
3628
+ properties: { ok: { type: "boolean" } },
3629
+ additionalProperties: true
3630
+ };
3631
+ var commands2 = [
3632
+ {
3633
+ id: "detect",
3634
+ command: ["detect"],
3635
+ description: "\u68C0\u6D4B Git \u8868\u683C\u51B2\u7A81",
3636
+ fields: {},
3637
+ readonly: true,
3638
+ result: {
3639
+ type: "object",
3640
+ required: ["ok", "count", "conflicts"],
3641
+ properties: {
3642
+ ok: { type: "boolean" },
3643
+ count: { type: "integer", minimum: 0 },
3644
+ conflicts: { type: "array" }
3645
+ },
3646
+ additionalProperties: true
3647
+ },
3648
+ verify: (r) => r.ok === true
3649
+ },
3650
+ {
3651
+ id: "filter-add",
3652
+ command: ["filter", "add"],
3653
+ description: "\u767B\u8BB0\u91C7\u7528\u8FDC\u7AEF\u7248\u672C\u7684\u8868\u683C\u8DEF\u5F84",
3654
+ fields: { path: text2 },
3655
+ required: ["path"],
3656
+ result: ok2,
3657
+ verify: (r) => r.ok === true
3658
+ },
3659
+ {
3660
+ id: "prepare",
3661
+ command: ["prepare"],
3662
+ description: "\u51C6\u5907\u4E09\u65B9\u8868\u683C\u5BA1\u9605\u6E05\u5355",
3663
+ fields: { path: text2 },
3664
+ result: {
3665
+ type: "object",
3666
+ required: ["ok", "manifest"],
3667
+ properties: { ok: { type: "boolean" }, manifest: text2 },
3668
+ additionalProperties: true
3669
+ },
3670
+ verify: (r) => r.ok === true && typeof r.manifest === "string" && fs8.existsSync(r.manifest)
3671
+ },
3672
+ ...["launch", "resolve"].map((action) => ({
3673
+ id: action,
3674
+ command: ["launch"],
3675
+ description: "\u542F\u52A8\u8868\u683C\u51B2\u7A81\u5BA1\u9605\u670D\u52A1",
3676
+ fields: { path: text2, "no-browser": { type: "boolean" } },
3677
+ result: ok2,
3678
+ verify: (r) => r.ok === true && (r.url === null || typeof r.pid === "number" && typeof r.url === "string"),
3679
+ pending: (r) => typeof r.pid === "number" && typeof r.url === "string" ? r.pid : null
3680
+ })),
3681
+ ...["status", "cancel"].map((action) => ({
3682
+ id: action,
3683
+ command: [action],
3684
+ description: action === "cancel" ? "\u505C\u6B62\u539F\u8868\u683C\u5BA1\u9605\u670D\u52A1" : "\u67E5\u8BE2\u539F\u8868\u683C\u5BA1\u9605\u670D\u52A1",
3685
+ fields: { handle: { type: "object", additionalProperties: true } },
3686
+ required: ["handle"],
3687
+ control: true,
3688
+ readonly: action === "status",
3689
+ result: {
3690
+ type: "object",
3691
+ required: ["ok", "state", "stopConfirmed"],
3692
+ properties: {
3693
+ ok: { type: "boolean" },
3694
+ state: text2,
3695
+ stopConfirmed: { type: "boolean" }
3696
+ },
3697
+ additionalProperties: true
3698
+ },
3699
+ verify: (r) => r.ok === true,
3700
+ settlement: (r) => ({
3701
+ lifecycle: r.stopConfirmed === true ? r.state === "completed" ? "completed" : r.state === "cancelled" ? "cancelled" : "failed" : r.state === "unknown" ? "unknown" : "running",
3702
+ acceptance: r.state === "completed" && r.stopConfirmed === true && r.result?.success === true ? "passed" : ["failed", "unknown"].includes(String(r.state)) ? "failed" : "not-run",
3703
+ pending: r.stopConfirmed !== true && r.state !== "unknown"
3704
+ })
3705
+ })),
3706
+ {
3707
+ id: "apply",
3708
+ command: ["apply"],
3709
+ description: "\u6309\u660E\u786E\u51B3\u7B56\u5199\u56DE\u51B2\u7A81\u8868\u683C",
3710
+ fields: {
3711
+ manifest: text2,
3712
+ decisions: text2,
3713
+ "no-commit": { type: "boolean" },
3714
+ push: { type: "boolean" },
3715
+ message: text2
3716
+ },
3717
+ required: ["manifest", "decisions"],
3718
+ network: true,
3719
+ result: {
3720
+ type: "object",
3721
+ required: ["success"],
3722
+ properties: { success: { type: "boolean" } },
3723
+ additionalProperties: true
3724
+ },
3725
+ verify: (r) => r.success === true
3726
+ }
3727
+ ];
3728
+ var createXlmergeProvider = (deps) => projectCommandProvider(
3729
+ "xlmerge",
3730
+ commands2.map((d) => ({
3731
+ ...d,
3732
+ args: (input, ctx) => {
3733
+ const args = [
3734
+ "--repo",
3735
+ ctx.bindingDirs.projectDir,
3736
+ "--runtime-dir",
3737
+ path7.join(ctx.projectRoot, ".vant/state/xlmerge", ctx.operationId)
3738
+ ];
3739
+ if (d.control) {
3740
+ const checked = verifyExecutionHandle({
3741
+ project: ctx.projectAnchor,
3742
+ handle: input.handle,
3743
+ expectProviderId: "xlmerge"
3744
+ });
3745
+ if (!checked.ok) throw Error(checked.errors.join("\uFF1B"));
3746
+ const origin = JSON.parse(
3747
+ fs8.readFileSync(
3748
+ resolveInsideProject(
3749
+ ctx.projectAnchor,
3750
+ checked.record.recordDir + "/result.json",
3751
+ "xlmerge.origin"
3752
+ ).path,
3753
+ "utf8"
3754
+ )
3755
+ );
3756
+ if (!["xlmerge.launch", "xlmerge.resolve"].includes(
3757
+ origin.capability?.id
3758
+ ) || origin.project?.bindingDirs?.xlmerge?.projectDir !== ctx.bindingDirs.projectDir)
3759
+ throw Error("\u539F\u5BA1\u9605\u4E0D\u5C5E\u4E8E\u5F53\u524D\u4ED3\u5E93\u7ED1\u5B9A");
3760
+ const manifest = origin.output?.result?.manifest;
3761
+ if (typeof manifest !== "string") throw Error("\u539F\u5BA1\u9605\u7F3A\u5C11\u6E05\u5355\u8EAB\u4EFD");
3762
+ const relative = path7.relative(ctx.projectRoot, manifest);
3763
+ resolveInsideProject(ctx.projectAnchor, relative, "xlmerge.session");
3764
+ return [
3765
+ "--repo",
3766
+ ctx.bindingDirs.projectDir,
3767
+ ...d.command,
3768
+ "--manifest",
3769
+ manifest
3770
+ ];
3771
+ }
3772
+ const values = [];
3773
+ for (const [key, value] of Object.entries(input)) {
3774
+ if (value === false) continue;
3775
+ if (key === "path") {
3776
+ resolveInsideProject(
3777
+ ctx.projectAnchor,
3778
+ String(value),
3779
+ "xlmerge.path"
3780
+ );
3781
+ if (d.id === "filter-add") values.push(String(value));
3782
+ else values.push("--path", String(value));
3783
+ continue;
3784
+ }
3785
+ let actual = String(value);
3786
+ if (["manifest", "decisions"].includes(key)) {
3787
+ actual = resolveInsideProject(
3788
+ ctx.projectAnchor,
3789
+ actual,
3790
+ `xlmerge.${key}`
3791
+ ).path;
3792
+ if (key === "manifest") {
3793
+ const manifest = JSON.parse(fs8.readFileSync(actual, "utf8"));
3794
+ if (typeof manifest.repoRoot !== "string" || comparePathForm(fs8.realpathSync(manifest.repoRoot)) !== comparePathForm(fs8.realpathSync(ctx.bindingDirs.projectDir)))
3795
+ throw Error("\u5408\u5E76\u6E05\u5355\u4E0D\u5C5E\u4E8E\u5F53\u524D\u4ED3\u5E93");
3796
+ }
3797
+ }
3798
+ values.push(`--${key}`);
3799
+ if (value !== true) values.push(actual);
3800
+ }
3801
+ return [...args, ...d.command, ...values];
3802
+ },
3803
+ sourceCommands: [d.id === "filter-add" ? ["filter", "add"] : [d.id]],
3804
+ command: []
3805
+ })),
3806
+ deps
3807
+ );
3808
+
3809
+ // src/providers/unity/commands.ts
3810
+ var text3 = { type: "string", minLength: 1 };
3811
+ var flag = { type: "boolean" };
3812
+ var result2 = (fields) => ({
3813
+ type: "object",
3814
+ required: Object.keys(fields),
3815
+ properties: fields,
3816
+ additionalProperties: true
3817
+ });
3818
+ var definitions2 = [
3819
+ {
3820
+ id: "routes",
3821
+ command: ["routes"],
3822
+ description: "\u8BFB\u53D6 Unity \u7CBE\u786E\u7248\u672C\u8DEF\u7531",
3823
+ fields: { editor: text3 },
3824
+ readonly: true,
3825
+ result: {
3826
+ type: "object",
3827
+ required: ["routes"],
3828
+ properties: { routes: { type: "array" } },
3829
+ additionalProperties: true
3830
+ },
3831
+ verify: (r) => Array.isArray(r.routes)
3832
+ },
3833
+ {
3834
+ id: "cli-install",
3835
+ command: ["cli", "install"],
3836
+ description: "\u5B89\u88C5\u5E76\u6821\u9A8C Unity CLI",
3837
+ fields: { editor: text3, force: flag },
3838
+ machine: true,
3839
+ network: true,
3840
+ result: result2({ cacheDir: text3, results: { type: "array" } }),
3841
+ verify: (r) => Array.isArray(r.results) && r.results.length > 0 && r.results.every(
3842
+ (x) => x !== null && typeof x === "object" && ["valid", "downloaded"].includes(String(x.state))
3843
+ )
3844
+ },
3845
+ ...["pipeline-install", "setup"].map(
3846
+ (id) => ({
3847
+ id,
3848
+ command: id === "setup" ? ["setup"] : ["pipeline", "install"],
3849
+ description: "\u5B89\u88C5\u5E76\u6821\u9A8C Unity Pipeline",
3850
+ engine: true,
3851
+ fields: {
3852
+ force: flag,
3853
+ "allow-running-editor": flag,
3854
+ "dry-run": flag,
3855
+ ...id === "setup" ? { "skip-cli": flag } : {}
3856
+ },
3857
+ machine: true,
3858
+ network: id === "setup",
3859
+ result: id === "setup" ? result2({
3860
+ install: {
3861
+ type: "object",
3862
+ required: ["status"],
3863
+ properties: { status: text3 },
3864
+ additionalProperties: true
3865
+ }
3866
+ }) : result2({
3867
+ status: text3,
3868
+ fileCount: { type: "integer", minimum: 1 }
3869
+ }),
3870
+ verify: (r) => ["Installed", "AlreadyInstalled", "DryRun"].includes(
3871
+ String(
3872
+ id === "setup" ? r.install?.status : r.status
3873
+ )
3874
+ )
3875
+ })
3876
+ ),
3877
+ {
3878
+ id: "cache-clean",
3879
+ command: ["cache", "clean"],
3880
+ description: "\u6E05\u7406 Unity \u5DE5\u5177\u7F13\u5B58",
3881
+ fields: { all: flag },
3882
+ machine: true,
3883
+ result: result2({ cacheRoot: text3, removed: { type: "array" } }),
3884
+ verify: (r) => Array.isArray(r.removed)
3885
+ }
3886
+ ];
3887
+ var unityCommandRegistrations = (deps) => commandRegistrations(
3888
+ "unity",
3889
+ definitions2.map((d) => ({
3890
+ ...d,
3891
+ args: (input, ctx) => {
3892
+ const args = ["pipeline-install", "setup"].includes(d.id) ? [ctx.bindingDirs.projectDir] : [];
3893
+ for (const [key, value] of Object.entries(input)) {
3894
+ if (value === false) continue;
3895
+ args.push(`--${key}`);
3896
+ if (value !== true) args.push(String(value));
3897
+ }
3898
+ return args;
3899
+ }
3900
+ })),
3901
+ deps
3902
+ );
3903
+
3904
+ // src/providers/unity/catalog.ts
3905
+ var PIPELINE_COMMANDS = {
3906
+ "add_component": "\u6DFB\u52A0\u7EC4\u4EF6\u3002",
3907
+ "create_gameobject": "\u521B\u5EFA\u573A\u666F\u5BF9\u8C61\u3002",
3908
+ "create_gameobjects": "\u6279\u91CF\u521B\u5EFA\u573A\u666F\u5BF9\u8C61\u3002",
3909
+ "delete_gameobject": "\u5220\u9664\u573A\u666F\u5BF9\u8C61\uFF0C\u652F\u6301\u64A4\u9500\u3002",
3910
+ "find_gameobjects": "\u6309\u540D\u79F0\u3001\u6807\u7B7E\u3001\u7EC4\u4EF6\u6216\u5C42\u7EA7\u8DEF\u5F84\u67E5\u627E\u573A\u666F\u5BF9\u8C61\u3002",
3911
+ "get_component_properties": "\u8BFB\u53D6\u7EC4\u4EF6\u5E8F\u5217\u5316\u5C5E\u6027\u3002",
3912
+ "remove_component": "\u79FB\u9664\u6307\u5B9A\u7EC4\u4EF6\u3002",
3913
+ "rename_gameobject": "\u91CD\u547D\u540D\u573A\u666F\u5BF9\u8C61\u3002",
3914
+ "set_active": "\u8BBE\u7F6E\u5BF9\u8C61\u6FC0\u6D3B\u72B6\u6001\u3002",
3915
+ "set_component_properties": "\u8BBE\u7F6E\u7EC4\u4EF6\u5E8F\u5217\u5316\u5C5E\u6027\uFF0C\u652F\u6301 ObjectRef \u5F15\u7528\u3002",
3916
+ "set_layer": "\u8BBE\u7F6E\u5BF9\u8C61\u5C42\uFF0C\u7F16\u53F7\u8303\u56F4 0\u201331\u3002",
3917
+ "set_parent": "\u8BBE\u7F6E\u7236\u5BF9\u8C61\uFF1B\u672A\u6307\u5B9A\u7236\u5BF9\u8C61\u65F6\u79FB\u81F3\u573A\u666F\u6839\u3002",
3918
+ "set_tag": "\u8BBE\u7F6E\u5DE5\u7A0B\u4E2D\u5DF2\u5B58\u5728\u7684\u6807\u7B7E\u3002",
3919
+ "set_transform": "\u8BBE\u7F6E\u5C40\u90E8\u5750\u6807\u3001\u6B27\u62C9\u65CB\u8F6C\u548C\u7F29\u653E\uFF0C\u7701\u7565\u9879\u4E0D\u53D8\u3002",
3920
+ "add_scene_to_build": "\u5C06\u573A\u666F\u52A0\u5165\u6784\u5EFA\u5217\u8868\u3002",
3921
+ "create_scene": "\u521B\u5EFA\u5E76\u4FDD\u5B58\u573A\u666F\u3002",
3922
+ "get_scene_hierarchy": "\u8BFB\u53D6\u573A\u666F\u5C42\u7EA7\u53CA instanceId\u3001hierarchyPath\u3002",
3923
+ "list_open_scenes": "\u5217\u51FA\u5DF2\u6253\u5F00\u573A\u666F\u53CA\u52A0\u8F7D\u3001\u6FC0\u6D3B\u3001\u672A\u4FDD\u5B58\u72B6\u6001\u3002",
3924
+ "open_scene": "\u6253\u5F00\u573A\u666F\u3002",
3925
+ "remove_scene_from_build": "\u4ECE\u6784\u5EFA\u5217\u8868\u79FB\u9664\u573A\u666F\u3002",
3926
+ "save_all": "\u4FDD\u5B58\u6240\u6709\u5DF2\u4FEE\u6539\u573A\u666F\u548C\u8D44\u6E90\u3002",
3927
+ "save_scene": "\u4FDD\u5B58\u573A\u666F\u3002",
3928
+ "set_active_scene": "\u8BBE\u7F6E\u6D3B\u52A8\u573A\u666F\u3002",
3929
+ "copy_asset": "\u590D\u5236\u8D44\u6E90\u3002",
3930
+ "create_asset": "\u521B\u5EFA\u6307\u5B9A\u7C7B\u578B\u7684\u8D44\u6E90\u3002",
3931
+ "create_folder": "\u521B\u5EFA\u76EE\u5F55\u3002",
3932
+ "delete_asset": "\u5220\u9664\u8D44\u6E90\u3002\u9700\u8981 confirm=true\u3002",
3933
+ "find_assets": "\u67E5\u627E\u8D44\u6E90\u3002",
3934
+ "get_import_settings": "\u8BFB\u53D6\u8D44\u6E90\u5BFC\u5165\u8BBE\u7F6E\u3002",
3935
+ "import_asset": "\u5BFC\u5165\u6216\u91CD\u65B0\u5BFC\u5165\u8D44\u6E90\u3002",
3936
+ "move_asset": "\u79FB\u52A8\u8D44\u6E90\u3002",
3937
+ "read_text_file": "\u8BFB\u53D6\u6587\u672C\u6587\u4EF6\u3002",
3938
+ "rename_asset": "\u91CD\u547D\u540D\u8D44\u6E90\u3002",
3939
+ "set_import_settings": "\u8BBE\u7F6E\u8D44\u6E90\u5BFC\u5165\u53C2\u6570\u3002",
3940
+ "write_text_file": "\u5199\u5165\u6587\u672C\u6587\u4EF6\u3002\u9700\u8981 confirm=true\u3002",
3941
+ "apply_prefab_overrides": "\u5C06\u5B9E\u4F8B\u8986\u76D6\u5E94\u7528\u5230\u9884\u5236\u4F53\u3002",
3942
+ "create_prefab": "\u4ECE\u573A\u666F\u5BF9\u8C61\u521B\u5EFA\u9884\u5236\u4F53\u3002",
3943
+ "create_prefab_variant": "\u521B\u5EFA\u9884\u5236\u4F53\u53D8\u4F53\u3002",
3944
+ "instantiate_prefab": "\u5C06\u9884\u5236\u4F53\u5B9E\u4F8B\u5316\u5230\u573A\u666F\u3002",
3945
+ "revert_prefab_overrides": "\u8FD8\u539F\u9884\u5236\u4F53\u5B9E\u4F8B\u8986\u76D6\u3002",
3946
+ "save_prefab_contents": "\u4FDD\u5B58\u9884\u5236\u4F53\u5185\u5BB9\u3002",
3947
+ "unpack_prefab": "\u89E3\u5305\u9884\u5236\u4F53\u5B9E\u4F8B\u3002",
3948
+ "get_material_properties": "\u8BFB\u53D6\u6750\u8D28\u5C5E\u6027\u3002",
3949
+ "get_shader_properties": "\u8BFB\u53D6\u7740\u8272\u5668\u5C5E\u6027\u3002",
3950
+ "list_shaders": "\u5217\u51FA\u7740\u8272\u5668\u3002",
3951
+ "set_material_properties": "\u8BBE\u7F6E\u6750\u8D28\u5C5E\u6027\u3002",
3952
+ "attach_script": "\u5C06\u811A\u672C\u7EC4\u4EF6\u6DFB\u52A0\u5230\u5BF9\u8C61\u3002",
3953
+ "cleanup_hotreload": "\u6E05\u7406\u70ED\u91CD\u8F7D\u8D44\u6E90\u3002",
3954
+ "create_script": "\u521B\u5EFA\u811A\u672C\u6587\u4EF6\u3002",
3955
+ "eval": "\u6267\u884C C# \u8868\u8FBE\u5F0F\u6216\u4EE3\u7801\u3002",
3956
+ "eval_file": "\u6267\u884C\u6587\u4EF6\u4E2D\u7684 C# \u4EE3\u7801\u3002",
3957
+ "get_serialized_fields": "\u8BFB\u53D6\u5E8F\u5217\u5316\u5B57\u6BB5\u3002",
3958
+ "hotreload_status": "\u67E5\u8BE2\u70ED\u91CD\u8F7D\u72B6\u6001\u3002",
3959
+ "recompile": "\u89E6\u53D1\u7F16\u8BD1\u5E76\u8FD4\u56DE\u8FD0\u884C\u8EAB\u4EFD\u3002",
3960
+ "recompile_status": "\u6309 run_id \u67E5\u8BE2\u7F16\u8BD1\uFF1B\u65E0\u6CD5\u5173\u8054\u65F6\u8FD4\u56DE unknown_run\u3002",
3961
+ "reload_file": "\u91CD\u8F7D\u811A\u672C\u6587\u4EF6\u3002",
3962
+ "reload_file_override": "\u91CD\u8F7D\u811A\u672C\u5E76\u660E\u786E\u5E94\u7528\u8986\u76D6\u3002",
3963
+ "set_serialized_field": "\u8BBE\u7F6E\u5E8F\u5217\u5316\u5B57\u6BB5\u3002",
3964
+ "add_animator_layer": "\u6DFB\u52A0\u52A8\u753B\u63A7\u5236\u5668\u5C42\u3002",
3965
+ "add_animator_parameter": "\u6DFB\u52A0\u52A8\u753B\u53C2\u6570\u3002",
3966
+ "add_animator_state": "\u6DFB\u52A0\u52A8\u753B\u72B6\u6001\u3002",
3967
+ "add_animator_transition": "\u6DFB\u52A0\u52A8\u753B\u8FC7\u6E21\u3002",
3968
+ "add_timeline_clip": "\u6DFB\u52A0 Timeline \u7247\u6BB5\u3002",
3969
+ "add_timeline_track": "\u6DFB\u52A0 Timeline \u8F68\u9053\u3002",
3970
+ "create_animation_clip": "\u521B\u5EFA\u52A8\u753B\u7247\u6BB5\u3002",
3971
+ "create_animator_controller": "\u521B\u5EFA\u52A8\u753B\u63A7\u5236\u5668\u3002",
3972
+ "create_timeline": "\u521B\u5EFA Timeline\u3002",
3973
+ "get_animation_clip": "\u8BFB\u53D6\u52A8\u753B\u7247\u6BB5\u3002",
3974
+ "get_animator_controller": "\u8BFB\u53D6\u52A8\u753B\u63A7\u5236\u5668\u3002",
3975
+ "get_timeline": "\u8BFB\u53D6 Timeline\u3002",
3976
+ "remove_animation_curve": "\u79FB\u9664\u52A8\u753B\u66F2\u7EBF\u3002\u9700\u8981 confirm=true\u3002",
3977
+ "set_animation_curve": "\u8BBE\u7F6E\u52A8\u753B\u66F2\u7EBF\u3002",
3978
+ "build": "\u6267\u884C\u6784\u5EFA\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002",
3979
+ "build_status": "\u67E5\u8BE2\u6784\u5EFA\u72B6\u6001\u3002",
3980
+ "get_build_settings": "\u8BFB\u53D6\u6784\u5EFA\u8BBE\u7F6E\u3002",
3981
+ "list_build_profiles": "\u5217\u51FA\u6784\u5EFA\u914D\u7F6E\u3002",
3982
+ "list_build_targets": "\u5217\u51FA\u6784\u5EFA\u76EE\u6807\u3002",
3983
+ "set_build_settings": "\u8BBE\u7F6E\u6784\u5EFA\u53C2\u6570\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002",
3984
+ "switch_build_target": "\u5207\u6362\u6784\u5EFA\u76EE\u6807\u3002\u9700\u8981 confirm=true\u3002",
3985
+ "switch_build_target_status": "\u67E5\u8BE2\u6784\u5EFA\u76EE\u6807\u5207\u6362\u7ED3\u679C\u3002",
3986
+ "package_add": "\u6DFB\u52A0 UPM \u5305\u3002\u9700\u8981 confirm=true\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002\u5F02\u6B65\u64CD\u4F5C\u67E5\u8BE2 package_status\uFF1B\u6D89\u53CA\u7F16\u8BD1\u65F6\u7EE7\u7EED\u67E5\u8BE2 recompile_status\u3002",
3987
+ "package_list": "\u5217\u51FA\u5DF2\u5B89\u88C5\u6216\u6CE8\u518C\u8868\u4E2D\u7684 UPM \u5305\u3002",
3988
+ "package_remove": "\u79FB\u9664 UPM \u5305\u3002\u9700\u8981 confirm=true\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002\u5F02\u6B65\u64CD\u4F5C\u67E5\u8BE2 package_status\uFF1B\u6D89\u53CA\u7F16\u8BD1\u65F6\u7EE7\u7EED\u67E5\u8BE2 recompile_status\u3002",
3989
+ "package_resolve": "\u89E3\u6790\u5DE5\u7A0B\u5305\u4F9D\u8D56\u3002\u5F02\u6B65\u64CD\u4F5C\u67E5\u8BE2 package_status\uFF1B\u6D89\u53CA\u7F16\u8BD1\u65F6\u7EE7\u7EED\u67E5\u8BE2 recompile_status\u3002",
3990
+ "package_search": "\u641C\u7D22\u6CE8\u518C\u8868\u5305\u3002",
3991
+ "package_status": "\u67E5\u8BE2\u5305\u64CD\u4F5C\u72B6\u6001\u3002",
3992
+ "cancel_tests": "\u6309 run_id \u53D6\u6D88\u6D4B\u8BD5\uFF1B\u4E0D\u5339\u914D\u65F6\u4E0D\u4EA7\u751F\u526F\u4F5C\u7528\u3002",
3993
+ "list_tests": "\u5217\u51FA EditMode \u6216 PlayMode \u6D4B\u8BD5\u3002",
3994
+ "run_tests": "\u6309\u8FC7\u6EE4\u6761\u4EF6\u6267\u884C\u6D4B\u8BD5\uFF1B\u5168\u91CF\u4F7F\u7528 --async_tests\u3002",
3995
+ "test_status": "\u6309 run_id \u67E5\u8BE2\u6D4B\u8BD5\uFF1B\u65E0\u6CD5\u5173\u8054\u65F6\u8FD4\u56DE unknown_run\u3002",
3996
+ "bake_lighting": "\u5F02\u6B65\u70D8\u7119\u5149\u7167\u3002",
3997
+ "bake_navmesh": "\u5F02\u6B65\u70D8\u7119\u5BFC\u822A\u7F51\u683C\u3002",
3998
+ "bake_navmesh_surfaces": "\u70D8\u7119 NavMeshSurface\uFF1B\u7F3A\u5C11 AI Navigation \u5305\u65F6\u8FD4\u56DE package_not_found\u3002",
3999
+ "bake_occlusion_culling": "\u5F02\u6B65\u70D8\u7119\u906E\u6321\u5254\u9664\u3002",
4000
+ "cancel_lighting_bake": "\u53D6\u6D88\u5149\u7167\u70D8\u7119\u3002",
4001
+ "cancel_navmesh_bake": "\u53D6\u6D88\u5BFC\u822A\u7F51\u683C\u70D8\u7119\u3002",
4002
+ "cancel_occlusion_bake": "\u53D6\u6D88\u906E\u6321\u5254\u9664\u70D8\u7119\u3002",
4003
+ "clear_baked_lighting": "\u6E05\u7406\u70D8\u7119\u5149\u7167\u6570\u636E\u3002\u9700\u8981 confirm=true\u3002",
4004
+ "clear_navmesh": "\u6E05\u7406\u5BFC\u822A\u7F51\u683C\u3002\u9700\u8981 confirm=true\u3002",
4005
+ "clear_occlusion_culling": "\u6E05\u7406\u906E\u6321\u5254\u9664\u6570\u636E\u3002\u9700\u8981 confirm=true\u3002",
4006
+ "get_lighting_settings": "\u8BFB\u53D6\u5149\u7167\u70D8\u7119\u8BBE\u7F6E\u3002",
4007
+ "get_navmesh_settings": "\u8BFB\u53D6\u5BFC\u822A\u7F51\u683C\u8BBE\u7F6E\u3002",
4008
+ "lighting_bake_status": "\u67E5\u8BE2\u5149\u7167\u70D8\u7119\u72B6\u6001\u3002",
4009
+ "navmesh_bake_status": "\u67E5\u8BE2\u5BFC\u822A\u7F51\u683C\u70D8\u7119\u72B6\u6001\u3002",
4010
+ "occlusion_bake_status": "\u67E5\u8BE2\u906E\u6321\u5254\u9664\u70D8\u7119\u72B6\u6001\u3002",
4011
+ "set_lighting_settings": "\u8BBE\u7F6E\u5149\u7167\u70D8\u7119\u53C2\u6570\uFF0C\u8FD4\u56DE applied \u548C unknown\u3002",
4012
+ "set_navmesh_settings": "\u8BBE\u7F6E\u5BFC\u822A\u7F51\u683C\u53C2\u6570\u3002",
4013
+ "capture_editor_element": "\u622A\u53D6\u7F16\u8F91\u5668 UI Toolkit \u5143\u7D20\u3002",
4014
+ "capture_game_view": "\u622A\u53D6\u6E38\u620F\u89C6\u56FE\uFF1Bsource=screen \u9700\u8981\u8FD0\u884C\u6A21\u5F0F\u5E76\u5305\u542B\u53E0\u52A0\u753B\u5E03\uFF0Csource=camera \u6309\u76F8\u673A\u6E32\u67D3\u3002\u8BBE\u7F6E save_path \u65F6\u9ED8\u8BA4\u53EA\u8FD4\u56DE\u8DEF\u5F84\uFF0Cinclude_inline_image=true \u53EF\u540C\u65F6\u8FD4\u56DE\u56FE\u7247\u3002",
4015
+ "capture_runtime_element": "\u622A\u53D6\u8FD0\u884C\u65F6 UI Toolkit \u5143\u7D20\u3002",
4016
+ "capture_scene_view": "\u622A\u53D6\u5F53\u524D\u573A\u666F\u89C6\u56FE\u3002\u8BBE\u7F6E save_path \u65F6\u9ED8\u8BA4\u53EA\u8FD4\u56DE\u8DEF\u5F84\uFF0Cinclude_inline_image=true \u53EF\u540C\u65F6\u8FD4\u56DE\u56FE\u7247\u3002",
4017
+ "screenshot": "\u622A\u53D6\u573A\u666F\u6216\u6E38\u620F\u89C6\u56FE\u5E76\u8FD4\u56DE\u6587\u4EF6\u8DEF\u5F84\u3002",
4018
+ "editor_focus": "\u6FC0\u6D3B Unity Editor \u7A97\u53E3\u3002",
4019
+ "editor_pause": "\u5207\u6362\u8FD0\u884C\u6A21\u5F0F\u7684\u6682\u505C\u72B6\u6001\u3002",
4020
+ "editor_play": "\u8FDB\u5165\u8FD0\u884C\u6A21\u5F0F\u3002",
4021
+ "editor_status": "\u8BFB\u53D6\u7F16\u8F91\u5668\u72B6\u6001\u3002",
4022
+ "editor_stop": "\u9000\u51FA\u8FD0\u884C\u6A21\u5F0F\u3002",
4023
+ "menu": "\u6267\u884C\u6216\u5217\u51FA\u83DC\u5355\u9879\u3002",
4024
+ "set_autotick": "\u5728\u7A97\u53E3\u5931\u7126\u65F6\u4FDD\u6301\u7F16\u8F91\u5668\u5468\u671F\u66F4\u65B0\u3002",
4025
+ "audit": "\u8BB0\u5F55\u6216\u67E5\u8BE2\u7F16\u8F91\u5668\u5BA1\u8BA1\u4FE1\u606F\u3002",
4026
+ "audit_status": "\u67E5\u8BE2\u5BA1\u8BA1\u72B6\u6001\u3002",
4027
+ "clear_console": "\u6E05\u7A7A Console\u3002",
4028
+ "console": "\u8BFB\u53D6\u56DE\u8C03\u6355\u83B7\u7684\u65E5\u5FD7\u6D41\uFF0C\u652F\u6301\u6E38\u6807\u8DDF\u968F\u3002",
4029
+ "get_console_logs": "\u8BFB\u53D6\u539F\u751F Console \u65E5\u5FD7\u3002",
4030
+ "read_console": "\u8BFB\u53D6\u539F\u751F Console \u65E5\u5FD7\uFF0C\u6309\u7C7B\u578B\u548C\u6570\u91CF\u8FC7\u6EE4\u3002",
4031
+ "get_performance_stats": "\u8BFB\u53D6\u6027\u80FD\u7EDF\u8BA1\u3002",
4032
+ "log": "\u5199\u5165 Console \u65E5\u5FD7\u3002",
4033
+ "get_audio_settings": "\u8BFB\u53D6\u97F3\u9891\u8BBE\u7F6E\u3002",
4034
+ "get_graphics_settings": "\u8BFB\u53D6\u56FE\u5F62\u8BBE\u7F6E\u3002",
4035
+ "get_input_settings": "\u8BFB\u53D6\u8F93\u5165\u8BBE\u7F6E\u3002",
4036
+ "get_physics_settings": "\u8BFB\u53D6\u7269\u7406\u8BBE\u7F6E\u3002",
4037
+ "get_player_settings": "\u8BFB\u53D6\u5E94\u7528\u8BBE\u7F6E\u3002",
4038
+ "get_quality_settings": "\u8BFB\u53D6\u8D28\u91CF\u8BBE\u7F6E\u3002",
4039
+ "get_tags_layers": "\u8BFB\u53D6\u6807\u7B7E\u4E0E\u5C42\u3002",
4040
+ "get_time_settings": "\u8BFB\u53D6\u65F6\u95F4\u8BBE\u7F6E\u3002",
4041
+ "set_audio_settings": "\u4FEE\u6539\u97F3\u9891\u8BBE\u7F6E\u3002\u9700\u8981 confirm=true\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002",
4042
+ "set_graphics_settings": "\u4FEE\u6539\u56FE\u5F62\u8BBE\u7F6E\u3002\u9700\u8981 confirm=true\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002",
4043
+ "set_input_settings": "\u4FEE\u6539\u8F93\u5165\u8BBE\u7F6E\u3002\u9700\u8981 confirm=true\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002",
4044
+ "set_physics_settings": "\u4FEE\u6539\u7269\u7406\u8BBE\u7F6E\u3002\u9700\u8981 confirm=true\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002",
4045
+ "set_player_settings": "\u4FEE\u6539\u5E94\u7528\u8BBE\u7F6E\u3002\u9700\u8981 confirm=true\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002",
4046
+ "set_quality_settings": "\u4FEE\u6539\u8D28\u91CF\u8BBE\u7F6E\u3002\u9700\u8981 confirm=true\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002",
4047
+ "set_tags_layers": "\u4FEE\u6539\u6807\u7B7E\u4E0E\u5C42\u3002\u9700\u8981 confirm=true\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002",
4048
+ "set_time_settings": "\u4FEE\u6539\u65F6\u95F4\u8BBE\u7F6E\u3002\u9700\u8981 confirm=true\u3002\u53EF\u7528 dry_run \u9884\u6F14\u3002",
4049
+ "quit": "\u6B63\u5E38\u9000\u51FA Unity \u5E94\u7528\u3002",
4050
+ "runtime_status": "\u8BFB\u53D6\u8FD0\u884C\u65F6\u72B6\u6001\u3002",
4051
+ "set_target_framerate": "\u8BBE\u7F6E\u76EE\u6807\u5E27\u7387\u3002",
4052
+ "set_timescale": "\u8BBE\u7F6E\u65F6\u95F4\u7F29\u653E\u3002",
4053
+ "simulate_key": "\u6A21\u62DF\u952E\u76D8\u4E8B\u4EF6\u3002",
4054
+ "simulate_pointer": "\u6A21\u62DF\u6307\u9488\u4E8B\u4EF6\u3002",
4055
+ "get_selection": "\u8BFB\u53D6\u5F53\u524D\u9009\u62E9\u7684\u5BF9\u8C61\u8EAB\u4EFD\u3002",
4056
+ "search": "\u6267\u884C Unity Search \u67E5\u8BE2\u3002",
4057
+ "set_selection": "\u8BBE\u7F6E\u5F53\u524D\u9009\u62E9\u3002",
4058
+ "get_authoring_root": "\u8BFB\u53D6\u8D44\u6E90\u7F16\u8F91\u6839\u76EE\u5F55\u3002",
4059
+ "set_authoring_root": "\u8BBE\u7F6E\u5E76\u7EA6\u675F\u8D44\u6E90\u7F16\u8F91\u6839\u76EE\u5F55\u3002"
4060
+ };
4061
+
4062
+ // src/providers/unity/index.ts
4063
+ import fs9 from "fs";
4064
+ import path8 from "path";
4065
+
2988
4066
  // src/providers/unity/protocol.ts
2989
4067
  function isPlainObject7(v) {
2990
4068
  return typeof v === "object" && v !== null && !Array.isArray(v);
2991
4069
  }
2992
4070
  function parseToolStdout(stdout) {
2993
- const text = stdout.trim();
2994
- if (text.length === 0) return { parsed: null, parseError: "stdout \u4E3A\u7A7A" };
4071
+ const text5 = stdout.trim();
4072
+ if (text5.length === 0) return { parsed: null, parseError: "stdout \u4E3A\u7A7A" };
2995
4073
  try {
2996
- return { parsed: JSON.parse(text), parseError: null };
4074
+ return { parsed: JSON.parse(text5), parseError: null };
2997
4075
  } catch (err) {
2998
- const start = text.indexOf("{");
4076
+ const start = text5.indexOf("{");
2999
4077
  if (start >= 0) {
3000
- for (let end = text.lastIndexOf("}"); end > start; end = text.lastIndexOf("}", end - 1)) {
4078
+ for (let end = text5.lastIndexOf("}"); end > start; end = text5.lastIndexOf("}", end - 1)) {
3001
4079
  try {
3002
- return { parsed: JSON.parse(text.slice(start, end + 1)), parseError: null };
4080
+ return { parsed: JSON.parse(text5.slice(start, end + 1)), parseError: null };
3003
4081
  } catch {
3004
4082
  }
3005
4083
  }
@@ -3077,9 +4155,9 @@ var FAIL_COUNT_PATHS = [
3077
4155
  ];
3078
4156
  function extractFailCount(payload) {
3079
4157
  if (!isPlainObject7(payload)) return { count: null, source: null };
3080
- for (const path8 of FAIL_COUNT_PATHS) {
4158
+ for (const path11 of FAIL_COUNT_PATHS) {
3081
4159
  let current = payload;
3082
- for (const segment of path8) {
4160
+ for (const segment of path11) {
3083
4161
  if (!isPlainObject7(current)) {
3084
4162
  current = void 0;
3085
4163
  break;
@@ -3087,16 +4165,16 @@ function extractFailCount(payload) {
3087
4165
  current = current[segment];
3088
4166
  }
3089
4167
  if (typeof current === "number" && Number.isSafeInteger(current) && current >= 0) {
3090
- return { count: current, source: path8.join(".") };
4168
+ return { count: current, source: path11.join(".") };
3091
4169
  }
3092
4170
  }
3093
4171
  return { count: null, source: null };
3094
4172
  }
3095
4173
  function extractTotal(payload) {
3096
4174
  if (!isPlainObject7(payload)) return { total: null, source: null };
3097
- for (const path8 of [["summary", "total"]]) {
4175
+ for (const path11 of [["summary", "total"]]) {
3098
4176
  let current = payload;
3099
- for (const segment of path8) {
4177
+ for (const segment of path11) {
3100
4178
  if (!isPlainObject7(current)) {
3101
4179
  current = void 0;
3102
4180
  break;
@@ -3104,7 +4182,7 @@ function extractTotal(payload) {
3104
4182
  current = current[segment];
3105
4183
  }
3106
4184
  if (typeof current === "number" && Number.isSafeInteger(current) && current >= 0) {
3107
- return { total: current, source: path8.join(".") };
4185
+ return { total: current, source: path11.join(".") };
3108
4186
  }
3109
4187
  }
3110
4188
  return { total: null, source: null };
@@ -3155,16 +4233,16 @@ function readBoolean(source, key) {
3155
4233
  return typeof value === "boolean" ? value : null;
3156
4234
  }
3157
4235
  function normalizeDoctor(parsed) {
3158
- const root = isPlainObject7(parsed) ? parsed : {};
3159
- const cli = isPlainObject7(root.cli) ? root.cli : {};
3160
- const pipeline = isPlainObject7(root.pipeline) ? root.pipeline : {};
3161
- const processes = root.unityProcesses;
3162
- const supported = root.supportedVersions;
4236
+ const root2 = isPlainObject7(parsed) ? parsed : {};
4237
+ const cli = isPlainObject7(root2.cli) ? root2.cli : {};
4238
+ const pipeline = isPlainObject7(root2.pipeline) ? root2.pipeline : {};
4239
+ const processes = root2.unityProcesses;
4240
+ const supported = root2.supportedVersions;
3163
4241
  return {
3164
- editorVersion: readString(root, "editorVersion"),
3165
- editorRevision: readString(root, "editorRevision"),
3166
- routeSupported: readBoolean(root, "routeSupported"),
3167
- routeRevision: readString(root, "routeRevision"),
4242
+ editorVersion: readString(root2, "editorVersion"),
4243
+ editorRevision: readString(root2, "editorRevision"),
4244
+ routeSupported: readBoolean(root2, "routeSupported"),
4245
+ routeRevision: readString(root2, "routeRevision"),
3168
4246
  cliState: readString(cli, "state"),
3169
4247
  pipelineState: readString(pipeline, "state"),
3170
4248
  pipelineInstalled: readBoolean(pipeline, "installed"),
@@ -3394,6 +4472,7 @@ var TRIGGER_RETRY = {
3394
4472
  description: "\u89E6\u53D1\u7C7B\u64CD\u4F5C\u4E0D\u81EA\u52A8\u91CD\u8BD5\uFF1B\u7528\u5BF9\u5E94\u72B6\u6001\u80FD\u529B\u8F6E\u8BE2\u540E\u7EED\u7ED3\u679C"
3395
4473
  };
3396
4474
  var EXEC_RESOURCES = [
4475
+ { kind: "user-cache", key: "unity", mode: "shared", scope: "machine", description: "\u6267\u884C\u671F\u95F4\u4FDD\u7559\u5DF2\u6821\u9A8C\u5DE5\u5177\u7F13\u5B58" },
3397
4476
  {
3398
4477
  kind: "engine-editor",
3399
4478
  mode: "exclusive",
@@ -3408,6 +4487,7 @@ var EXEC_RESOURCES = [
3408
4487
  }
3409
4488
  ];
3410
4489
  var READONLY_RESOURCES = [
4490
+ { kind: "user-cache", key: "unity", mode: "shared", scope: "machine", description: "\u8BFB\u53D6\u671F\u95F4\u4FDD\u7559\u5DE5\u5177\u7F13\u5B58" },
3411
4491
  {
3412
4492
  kind: "engine-editor",
3413
4493
  mode: "shared",
@@ -3511,7 +4591,7 @@ function unityPathsEqual(a, b) {
3511
4591
  const norm = comparePathForm;
3512
4592
  if (norm(a) === norm(b)) return true;
3513
4593
  try {
3514
- return norm(fs6.realpathSync(a)) === norm(fs6.realpathSync(b));
4594
+ return norm(fs9.realpathSync(a)) === norm(fs9.realpathSync(b));
3515
4595
  } catch {
3516
4596
  return false;
3517
4597
  }
@@ -3654,8 +4734,8 @@ function createUnityProvider(deps) {
3654
4734
  if (!dir) {
3655
4735
  return { id: "unity.project-version-file", status: "violated", detail: "\u7F3A\u5C11\u5DE5\u7A0B\u76EE\u5F55\u7ED1\u5B9A" };
3656
4736
  }
3657
- const versionFile = path5.join(dir, "ProjectSettings", "ProjectVersion.txt");
3658
- if (fs6.existsSync(versionFile)) {
4737
+ const versionFile = path8.join(dir, "ProjectSettings", "ProjectVersion.txt");
4738
+ if (fs9.existsSync(versionFile)) {
3659
4739
  return {
3660
4740
  id: "unity.project-version-file",
3661
4741
  status: "satisfied",
@@ -3676,9 +4756,9 @@ function createUnityProvider(deps) {
3676
4756
  return { id: "unity.pipeline-ready", status: "violated", detail: "\u7F3A\u5C11\u5DE5\u7A0B\u76EE\u5F55\u7ED1\u5B9A" };
3677
4757
  }
3678
4758
  const argv = buildDoctorArgv({ projectDir: dir, allowRunningEditor: true });
3679
- let result;
4759
+ let result4;
3680
4760
  try {
3681
- result = await invoke(argv, ctx, DEFAULT_WAIT_SECONDS["unity.doctor"], dir);
4761
+ result4 = await invoke(argv, ctx, DEFAULT_WAIT_SECONDS["unity.doctor"], dir);
3682
4762
  } catch (err) {
3683
4763
  return {
3684
4764
  id: "unity.pipeline-ready",
@@ -3686,23 +4766,23 @@ function createUnityProvider(deps) {
3686
4766
  detail: `doctor \u65E0\u6CD5\u6267\u884C: ${err instanceof Error ? err.message : String(err)}`
3687
4767
  };
3688
4768
  }
3689
- const exec = executionFromProcess(result.outcome);
4769
+ const exec = executionFromProcess(result4.outcome);
3690
4770
  if (exec.status !== "succeeded") {
3691
4771
  return {
3692
4772
  id: "unity.pipeline-ready",
3693
4773
  status: "unknown",
3694
4774
  detail: `doctor \u672A\u6210\u529F\uFF08${exec.status}\uFF09\uFF1A${exec.error?.message ?? "\u672A\u77E5"}`,
3695
- evidence: [evidenceExit(result.outcome)]
4775
+ evidence: [evidenceExit(result4.outcome)]
3696
4776
  };
3697
4777
  }
3698
- if (result.tool.parseError !== null) {
4778
+ if (result4.tool.parseError !== null) {
3699
4779
  return {
3700
4780
  id: "unity.pipeline-ready",
3701
4781
  status: "unknown",
3702
- detail: `doctor \u8F93\u51FA\u65E0\u6CD5\u89E3\u6790\u4E3A JSON: ${result.tool.parseError}`
4782
+ detail: `doctor \u8F93\u51FA\u65E0\u6CD5\u89E3\u6790\u4E3A JSON: ${result4.tool.parseError}`
3703
4783
  };
3704
4784
  }
3705
- const doctor = normalizeDoctor(result.tool.parsed);
4785
+ const doctor = normalizeDoctor(result4.tool.parsed);
3706
4786
  const readiness = doctorReadiness(doctor);
3707
4787
  const pin = unityBinding(ctx)?.editorVersion;
3708
4788
  const pinMismatch = pin !== void 0 && doctor.editorVersion !== pin;
@@ -3761,8 +4841,8 @@ function createUnityProvider(deps) {
3761
4841
  description: "exec \u5C31\u7EEA\u5224\u636E\uFF08\u81EA\u52A8 doctor\uFF1ArouteSupported=true\u3001cli.state=valid\u3001pipeline.installed=true\u3001pipeline.state=current\uFF09"
3762
4842
  }
3763
4843
  ];
3764
- function failedBeforeRun(result, label, followUpCapabilityId = null) {
3765
- const exec = executionFromProcess(result.outcome);
4844
+ function failedBeforeRun(result4, label, followUpCapabilityId = null) {
4845
+ const exec = executionFromProcess(result4.outcome);
3766
4846
  const pending = followUpCapabilityId !== null;
3767
4847
  return {
3768
4848
  execution: exec,
@@ -3770,25 +4850,25 @@ function createUnityProvider(deps) {
3770
4850
  status: "not-run",
3771
4851
  reason: `${label} \u672A\u6210\u529F\uFF08${exec.status}\uFF09\uFF0C\u65E0\u9A8C\u6536\u7ED3\u8BBA`,
3772
4852
  pending,
3773
- evidence: [evidenceExit(result.outcome)]
4853
+ evidence: [evidenceExit(result4.outcome)]
3774
4854
  },
3775
4855
  followUp: pending && followUpCapabilityId !== null ? [{ capabilityId: followUpCapabilityId, hint: `\u8C03\u7528\u672A\u53D6\u5F97\u7ED3\u8BBA\uFF08\u8D85\u65F6/\u4E2D\u65AD\u53EA\u8BF4\u660E\u8C03\u7528\u7ED3\u675F\uFF0C\u4E0D\u63A8\u65AD\u5E95\u5C42\u5DF2\u505C\u6B62\uFF09\uFF1A\u91CD\u8BD5\u6216\u8F6E\u8BE2` }] : void 0,
3776
- command: result.command,
3777
- tool: result.toolInfo,
3778
- rawOutput: result.rawOutput
4856
+ command: result4.command,
4857
+ tool: result4.toolInfo,
4858
+ rawOutput: result4.rawOutput
3779
4859
  };
3780
4860
  }
3781
- function toolReportedFailure(result, label) {
4861
+ function toolReportedFailure(result4, label) {
3782
4862
  return {
3783
4863
  execution: {
3784
4864
  status: "failed",
3785
4865
  lifecycle: "completed",
3786
- exitCode: result.outcome.exitCode,
3787
- signal: result.outcome.signal,
4866
+ exitCode: result4.outcome.exitCode,
4867
+ signal: result4.outcome.signal,
3788
4868
  error: structuredError(
3789
4869
  "tool-reported-failure",
3790
4870
  "process",
3791
- result.tool.errorMessage ?? `${label}: Unity CLI \u62A5\u544A success=false`
4871
+ result4.tool.errorMessage ?? `${label}: Unity CLI \u62A5\u544A success=false`
3792
4872
  )
3793
4873
  },
3794
4874
  acceptance: {
@@ -3797,74 +4877,74 @@ function createUnityProvider(deps) {
3797
4877
  pending: false,
3798
4878
  evidence: [evidenceField("\u4FE1\u5C01 success", false)]
3799
4879
  },
3800
- command: result.command,
3801
- tool: result.toolInfo,
3802
- rawOutput: result.rawOutput
4880
+ command: result4.command,
4881
+ tool: result4.toolInfo,
4882
+ rawOutput: result4.rawOutput
3803
4883
  };
3804
4884
  }
3805
- function unparseable(result, label, capabilityId) {
4885
+ function unparseable(result4, label, capabilityId) {
3806
4886
  return {
3807
4887
  execution: {
3808
4888
  status: "unknown",
3809
4889
  lifecycle: "unknown",
3810
- exitCode: result.outcome.exitCode,
3811
- signal: result.outcome.signal,
4890
+ exitCode: result4.outcome.exitCode,
4891
+ signal: result4.outcome.signal,
3812
4892
  error: structuredError(
3813
4893
  "output-unparseable",
3814
4894
  "protocol",
3815
- `${label} \u8F93\u51FA\u65E0\u6CD5\u89E3\u91CA: ${result.tool.parseError ?? "\u65E0\u6CD5\u8BFB\u53D6\u54CD\u5E94"}`,
3816
- { details: { stderrTail: result.outcome.stderr.slice(-800) } }
4895
+ `${label} \u8F93\u51FA\u65E0\u6CD5\u89E3\u91CA: ${result4.tool.parseError ?? "\u65E0\u6CD5\u8BFB\u53D6\u54CD\u5E94"}`,
4896
+ { details: { stderrTail: result4.outcome.stderr.slice(-800) } }
3817
4897
  )
3818
4898
  },
3819
4899
  acceptance: {
3820
4900
  status: "not-run",
3821
4901
  reason: "\u5DE5\u5177\u8F93\u51FA\u4E0D\u53EF\u89E3\u91CA\uFF0C\u65E0\u9A8C\u6536\u7ED3\u8BBA\uFF1B\u91CD\u65B0\u6267\u884C\u672C\u80FD\u529B\u53D6\u5F97\u7ED3\u8BBA",
3822
4902
  pending: true,
3823
- evidence: [evidenceExit(result.outcome)]
4903
+ evidence: [evidenceExit(result4.outcome)]
3824
4904
  },
3825
4905
  followUp: [{ capabilityId, hint: "\u91CD\u65B0\u6267\u884C\u672C\u80FD\u529B\u4EE5\u53D6\u5F97\u7ED3\u8BBA" }],
3826
- command: result.command,
3827
- tool: result.toolInfo,
3828
- rawOutput: result.rawOutput
4906
+ command: result4.command,
4907
+ tool: result4.toolInfo,
4908
+ rawOutput: result4.rawOutput
3829
4909
  };
3830
4910
  }
3831
- function statusHandoffOutcome(result, label, capabilityId) {
4911
+ function statusHandoffOutcome(result4, label, capabilityId) {
3832
4912
  return {
3833
4913
  execution: {
3834
4914
  status: "unknown",
3835
4915
  lifecycle: "unknown",
3836
- exitCode: result.outcome.exitCode,
3837
- signal: result.outcome.signal,
4916
+ exitCode: result4.outcome.exitCode,
4917
+ signal: result4.outcome.signal,
3838
4918
  error: structuredError(
3839
4919
  "status-unconfirmed",
3840
4920
  "protocol",
3841
4921
  `${label} \u7B49\u5F85\u9884\u7B97\u8017\u5C3D\uFF1A\u5305\u88C5\u5668\u5DF2\u8BA9\u51FA\u63A7\u5236\u6743\uFF0C\u672A\u53D6\u5F97\u72B6\u6001\u7ED3\u8BBA`,
3842
- { details: { stderrTail: result.outcome.stderr.slice(-800) } }
4922
+ { details: { stderrTail: result4.outcome.stderr.slice(-800) } }
3843
4923
  )
3844
4924
  },
3845
4925
  acceptance: {
3846
4926
  status: "not-run",
3847
4927
  reason: `${label} \u672A\u53D6\u5F97\u72B6\u6001\u7ED3\u8BBA\uFF08\u5DE5\u5177\u4ECD\u5728 Editor \u5185\u6267\u884C\uFF09\uFF1B\u8BF7\u91CD\u65B0\u6267\u884C\u672C\u72B6\u6001\u80FD\u529B`,
3848
4928
  pending: true,
3849
- evidence: [evidenceExit(result.outcome)]
4929
+ evidence: [evidenceExit(result4.outcome)]
3850
4930
  },
3851
4931
  followUp: [{ capabilityId, hint: "\u91CD\u65B0\u6267\u884C\u672C\u72B6\u6001\u80FD\u529B\u4EE5\u53D6\u5F97\u7ED3\u8BBA" }],
3852
- command: result.command,
3853
- tool: result.toolInfo,
3854
- rawOutput: result.rawOutput
4932
+ command: result4.command,
4933
+ tool: result4.toolInfo,
4934
+ rawOutput: result4.rawOutput
3855
4935
  };
3856
4936
  }
3857
- function targetMismatchOutcome(result) {
4937
+ function targetMismatchOutcome(result4) {
3858
4938
  return {
3859
4939
  execution: {
3860
4940
  status: "failed",
3861
4941
  lifecycle: "unknown",
3862
- exitCode: result.outcome.exitCode,
3863
- signal: result.outcome.signal,
4942
+ exitCode: result4.outcome.exitCode,
4943
+ signal: result4.outcome.signal,
3864
4944
  error: structuredError(
3865
4945
  "unity-target-mismatch",
3866
4946
  "protocol",
3867
- `Editor \u56DE\u663E\u76EE\u6807\u5DE5\u7A0B ${result.targetMismatch.echoed} \u4E0E\u7ED1\u5B9A ${result.targetMismatch.expected} \u4E0D\u4E00\u81F4\uFF1A\u54CD\u5E94\u4E0D\u88AB\u91C7\u4FE1`,
4947
+ `Editor \u56DE\u663E\u76EE\u6807\u5DE5\u7A0B ${result4.targetMismatch.echoed} \u4E0E\u7ED1\u5B9A ${result4.targetMismatch.expected} \u4E0D\u4E00\u81F4\uFF1A\u54CD\u5E94\u4E0D\u88AB\u91C7\u4FE1`,
3868
4948
  { retryable: false }
3869
4949
  )
3870
4950
  },
@@ -3872,18 +4952,18 @@ function createUnityProvider(deps) {
3872
4952
  status: "not-run",
3873
4953
  reason: "\u76EE\u6807\u5DE5\u7A0B\u8EAB\u4EFD\u6838\u5BF9\u5931\u8D25\uFF0C\u672A\u91C7\u4FE1\u54CD\u5E94\uFF08\u4E0D\u56DE\u9000\u5176\u4ED6\u5DE5\u7A0B\uFF09",
3874
4954
  pending: false,
3875
- evidence: [evidenceField("data.target.projectPath \u56DE\u663E", result.targetMismatch.echoed)]
4955
+ evidence: [evidenceField("data.target.projectPath \u56DE\u663E", result4.targetMismatch.echoed)]
3876
4956
  },
3877
- command: result.command,
3878
- tool: result.toolInfo,
3879
- rawOutput: result.rawOutput
4957
+ command: result4.command,
4958
+ tool: result4.toolInfo,
4959
+ rawOutput: result4.rawOutput
3880
4960
  };
3881
4961
  }
3882
4962
  async function invokeOrUnavailable(argv, ctx, waitSeconds, dir) {
3883
4963
  try {
3884
- const result = await invoke(argv, ctx, waitSeconds, dir);
3885
- if (result.targetMismatch !== null) return targetMismatchOutcome(result);
3886
- return result;
4964
+ const result4 = await invoke(argv, ctx, waitSeconds, dir);
4965
+ if (result4.targetMismatch !== null) return targetMismatchOutcome(result4);
4966
+ return result4;
3887
4967
  } catch (err) {
3888
4968
  return backendUnavailableOutcome(err instanceof Error ? err.message : String(err));
3889
4969
  }
@@ -3900,35 +4980,35 @@ function createUnityProvider(deps) {
3900
4980
  });
3901
4981
  const invoked = await invokeOrUnavailable(argv, ctx, inputWaitSeconds(input, "unity.doctor"), dir);
3902
4982
  if (isOutcome(invoked)) return invoked;
3903
- const result = invoked;
3904
- const exec = executionFromProcess(result.outcome, { failureCode: "doctor-exit-nonzero" });
3905
- const base = { command: result.command, tool: result.toolInfo, rawOutput: result.rawOutput };
4983
+ const result4 = invoked;
4984
+ const exec = executionFromProcess(result4.outcome, { failureCode: "doctor-exit-nonzero" });
4985
+ const base = { command: result4.command, tool: result4.toolInfo, rawOutput: result4.rawOutput };
3906
4986
  if (exec.status !== "succeeded") {
3907
4987
  return {
3908
4988
  ...base,
3909
- ...failedBeforeRun(result, "doctor"),
4989
+ ...failedBeforeRun(result4, "doctor"),
3910
4990
  execution: exec,
3911
4991
  sideEffects: [
3912
4992
  { kind: "process-exec", description: `\u542F\u52A8 ${UNITY_BACKEND_COMMAND} doctor`, reversible: false, details: { argv } }
3913
4993
  ]
3914
4994
  };
3915
4995
  }
3916
- const parse = parseToolStdout(result.outcome.stdout);
4996
+ const parse = parseToolStdout(result4.outcome.stdout);
3917
4997
  if (parse.parsed === null) {
3918
4998
  return {
3919
4999
  ...base,
3920
5000
  execution: {
3921
5001
  status: "unknown",
3922
5002
  lifecycle: "unknown",
3923
- exitCode: result.outcome.exitCode,
3924
- signal: result.outcome.signal,
5003
+ exitCode: result4.outcome.exitCode,
5004
+ signal: result4.outcome.signal,
3925
5005
  error: structuredError("output-unparseable", "protocol", `doctor \u8F93\u51FA\u65E0\u6CD5\u89E3\u6790\u4E3A JSON: ${parse.parseError}`)
3926
5006
  },
3927
5007
  acceptance: {
3928
5008
  status: "not-run",
3929
5009
  reason: "doctor \u8F93\u51FA\u4E0D\u53EF\u89E3\u6790\uFF0C\u65E0\u9A8C\u6536\u7ED3\u8BBA",
3930
5010
  pending: false,
3931
- evidence: [evidenceExit(result.outcome)]
5011
+ evidence: [evidenceExit(result4.outcome)]
3932
5012
  }
3933
5013
  };
3934
5014
  }
@@ -3936,7 +5016,7 @@ function createUnityProvider(deps) {
3936
5016
  const readiness = doctorReadiness(doctor);
3937
5017
  const output = { ...doctor, ready: readiness.ready, reasons: readiness.reasons };
3938
5018
  const evidence = [
3939
- evidenceExit(result.outcome),
5019
+ evidenceExit(result4.outcome),
3940
5020
  evidenceField("doctor.routeSupported", doctor.routeSupported),
3941
5021
  evidenceField("doctor.cli.state", doctor.cliState),
3942
5022
  evidenceField("doctor.pipeline.installed", doctor.pipelineInstalled),
@@ -3971,14 +5051,14 @@ function createUnityProvider(deps) {
3971
5051
  const argv = buildExecArgv({ projectDir: dir, waitSeconds, pipelineCommand: "editor_status" });
3972
5052
  const invoked = await invokeOrUnavailable(argv, ctx, waitSeconds, dir);
3973
5053
  if (isOutcome(invoked)) return invoked;
3974
- const result = invoked;
3975
- const exec = executionFromProcess(result.outcome);
3976
- const base = { command: result.command, tool: result.toolInfo, rawOutput: result.rawOutput };
3977
- if (exec.status !== "succeeded") return failedBeforeRun(result, "editor_status", "unity.editor-status");
3978
- if (result.tool.success === false) return toolReportedFailure(result, "editor_status");
3979
- if (result.handoff) return statusHandoffOutcome(result, "editor_status", "unity.editor-status");
3980
- if (result.tool.parseError !== null) return unparseable(result, "editor_status", "unity.editor-status");
3981
- const { status, source } = extractStatus(result.tool.payload);
5054
+ const result4 = invoked;
5055
+ const exec = executionFromProcess(result4.outcome);
5056
+ const base = { command: result4.command, tool: result4.toolInfo, rawOutput: result4.rawOutput };
5057
+ if (exec.status !== "succeeded") return failedBeforeRun(result4, "editor_status", "unity.editor-status");
5058
+ if (result4.tool.success === false) return toolReportedFailure(result4, "editor_status");
5059
+ if (result4.handoff) return statusHandoffOutcome(result4, "editor_status", "unity.editor-status");
5060
+ if (result4.tool.parseError !== null) return unparseable(result4, "editor_status", "unity.editor-status");
5061
+ const { status, source } = extractStatus(result4.tool.payload);
3982
5062
  const ready = status === "ready";
3983
5063
  const output = { status, statusSource: source, ready };
3984
5064
  return {
@@ -4005,36 +5085,36 @@ function createUnityProvider(deps) {
4005
5085
  const argv = buildExecArgv({ projectDir: dir, waitSeconds, pipelineCommand: "recompile" });
4006
5086
  const invoked = await invokeOrUnavailable(argv, ctx, waitSeconds, dir);
4007
5087
  if (isOutcome(invoked)) return invoked;
4008
- const result = invoked;
4009
- const exec = executionFromProcess(result.outcome);
4010
- const base = { command: result.command, tool: result.toolInfo, rawOutput: result.rawOutput };
4011
- const extracted = result.tool.parseError === null ? extractStatus(result.tool.payload) : { status: null, source: null };
4012
- const output = { accepted: false, recompileStatus: extracted.status, waitBudgetExpired: result.handoff };
5088
+ const result4 = invoked;
5089
+ const exec = executionFromProcess(result4.outcome);
5090
+ const base = { command: result4.command, tool: result4.toolInfo, rawOutput: result4.rawOutput };
5091
+ const extracted = result4.tool.parseError === null ? extractStatus(result4.tool.payload) : { status: null, source: null };
5092
+ const output = { accepted: false, recompileStatus: extracted.status, waitBudgetExpired: result4.handoff };
4013
5093
  if (exec.status !== "succeeded") {
4014
- return { ...failedBeforeRun(result, "recompile \u89E6\u53D1", "unity.compile-status"), output };
5094
+ return { ...failedBeforeRun(result4, "recompile \u89E6\u53D1", "unity.compile-status"), output };
4015
5095
  }
4016
- if (result.tool.success === false) return { ...toolReportedFailure(result, "recompile \u89E6\u53D1"), output };
4017
- if (result.handoff || result.tool.parseError !== null) {
5096
+ if (result4.tool.success === false) return { ...toolReportedFailure(result4, "recompile \u89E6\u53D1"), output };
5097
+ if (result4.handoff || result4.tool.parseError !== null) {
4018
5098
  return {
4019
5099
  ...base,
4020
5100
  output,
4021
5101
  execution: {
4022
5102
  status: "unknown",
4023
5103
  lifecycle: "unknown",
4024
- exitCode: result.outcome.exitCode,
4025
- signal: result.outcome.signal,
5104
+ exitCode: result4.outcome.exitCode,
5105
+ signal: result4.outcome.signal,
4026
5106
  error: structuredError(
4027
5107
  "trigger-unconfirmed",
4028
5108
  "protocol",
4029
5109
  "\u7B49\u5F85\u9884\u7B97\u8017\u5C3D/\u8F93\u51FA\u4E0D\u53EF\u89E3\u6790\uFF1A\u65E0\u6CD5\u786E\u8BA4 recompile \u5DF2\u88AB\u63A5\u53D7\uFF08\u5305\u88C5\u5668\u5DF2\u8BA9\u51FA\u63A7\u5236\u6743\uFF0CEditor \u4FA7\u5DE5\u4F5C\u53EF\u80FD\u4ECD\u5728\u8FDB\u884C\uFF09",
4030
- { details: { stderrTail: result.outcome.stderr.slice(-800) } }
5110
+ { details: { stderrTail: result4.outcome.stderr.slice(-800) } }
4031
5111
  )
4032
5112
  },
4033
5113
  acceptance: {
4034
5114
  status: "not-run",
4035
5115
  reason: "\u89E6\u53D1\u7ED3\u679C\u672A\u786E\u8BA4\uFF1B\u8BF7\u7528 unity.compile-status \u8F6E\u8BE2\uFF08pending\uFF09",
4036
5116
  pending: true,
4037
- evidence: [evidenceExit(result.outcome)]
5117
+ evidence: [evidenceExit(result4.outcome)]
4038
5118
  },
4039
5119
  followUp: [
4040
5120
  { capabilityId: "unity.compile-status", hint: "\u8F6E\u8BE2 recompile_status \u76F4\u5230 completed/up_to_date" }
@@ -4056,7 +5136,7 @@ function createUnityProvider(deps) {
4056
5136
  notes: [
4057
5137
  "recompile \u53EA\u8868\u793A\u5DF2\u8BF7\u6C42\u91CD\u7F16\u8BD1\uFF1B\u5B8C\u6210\u53CA\u9519\u8BEF\u9A8C\u6536\u7531 unity.compile-status\uFF08\u89C2\u5BDF\uFF09\u6216 unity.compile-query\uFF08\u6309\u53E5\u67C4\u5173\u8054\uFF09\u7ED9\u51FA"
4058
5138
  ],
4059
- handle: { backendTaskId: extractRunId(result.tool.payload).runId }
5139
+ handle: { backendTaskId: extractRunId(result4.tool.payload).runId }
4060
5140
  };
4061
5141
  };
4062
5142
  const compileStatusExecute = async (input, ctx) => {
@@ -4066,36 +5146,36 @@ function createUnityProvider(deps) {
4066
5146
  const argv = buildExecArgv({ projectDir: dir, waitSeconds, pipelineCommand: "recompile_status" });
4067
5147
  const invoked = await invokeOrUnavailable(argv, ctx, waitSeconds, dir);
4068
5148
  if (isOutcome(invoked)) return invoked;
4069
- const result = invoked;
4070
- const exec = executionFromProcess(result.outcome);
4071
- const base = { command: result.command, tool: result.toolInfo, rawOutput: result.rawOutput };
4072
- if (exec.status !== "succeeded") return failedBeforeRun(result, "recompile_status", "unity.compile-status");
4073
- if (result.tool.success === false) return toolReportedFailure(result, "recompile_status");
4074
- if (result.handoff) {
4075
- return statusHandoffOutcome(result, "recompile_status", "unity.compile-status");
4076
- }
4077
- if (result.tool.parseError !== null) return unparseable(result, "recompile_status", "unity.compile-status");
4078
- if (result.tool.payloadParseError !== null) {
5149
+ const result4 = invoked;
5150
+ const exec = executionFromProcess(result4.outcome);
5151
+ const base = { command: result4.command, tool: result4.toolInfo, rawOutput: result4.rawOutput };
5152
+ if (exec.status !== "succeeded") return failedBeforeRun(result4, "recompile_status", "unity.compile-status");
5153
+ if (result4.tool.success === false) return toolReportedFailure(result4, "recompile_status");
5154
+ if (result4.handoff) {
5155
+ return statusHandoffOutcome(result4, "recompile_status", "unity.compile-status");
5156
+ }
5157
+ if (result4.tool.parseError !== null) return unparseable(result4, "recompile_status", "unity.compile-status");
5158
+ if (result4.tool.payloadParseError !== null) {
4079
5159
  return {
4080
5160
  ...base,
4081
5161
  output: { status: null, statusSource: null },
4082
5162
  execution: { ...exec, lifecycle: "unknown" },
4083
5163
  acceptance: {
4084
5164
  status: "not-run",
4085
- reason: `recompile_status \u8F7D\u8377\u4E0D\u53EF\u89E3\u6790: ${result.tool.payloadParseError}`,
5165
+ reason: `recompile_status \u8F7D\u8377\u4E0D\u53EF\u89E3\u6790: ${result4.tool.payloadParseError}`,
4086
5166
  pending: true,
4087
- evidence: [evidenceExit(result.outcome)]
5167
+ evidence: [evidenceExit(result4.outcome)]
4088
5168
  },
4089
5169
  followUp: [{ capabilityId: "unity.compile-status", hint: "\u91CD\u65B0\u6267\u884C\u672C\u80FD\u529B\u4EE5\u53D6\u5F97\u7ED3\u8BBA" }]
4090
5170
  };
4091
5171
  }
4092
- const { status, source } = extractStatus(result.tool.payload);
5172
+ const { status, source } = extractStatus(result4.tool.payload);
4093
5173
  const output = { status, statusSource: source };
4094
5174
  const klass = classifyRecompileStatus(status);
4095
5175
  const normalized = status?.trim().toLowerCase().replace(/[\s-]/g, "_") ?? null;
4096
5176
  switch (klass) {
4097
5177
  case "completed":
4098
- const compileReport = result.tool.payload;
5178
+ const compileReport = result4.tool.payload;
4099
5179
  if (compileReport.failed !== false || !Array.isArray(compileReport.errors) || compileReport.errors.length !== 0) {
4100
5180
  return { ...base, output, execution: { ...exec, lifecycle: "failed" }, acceptance: { status: "failed", reason: "\u7F16\u8BD1\u72B6\u6001\u5DF2\u7ED3\u675F\uFF0C\u4F46\u9519\u8BEF\u62A5\u544A\u7F3A\u5931\u6216\u5B58\u5728\u7F16\u8BD1\u9519\u8BEF", pending: false, evidence: [evidenceField("\u7F16\u8BD1\u9519\u8BEF\u62A5\u544A", compileReport)] } };
4101
5181
  }
@@ -4172,42 +5252,42 @@ function createUnityProvider(deps) {
4172
5252
  const argv = buildExecArgv({ projectDir: dir, waitSeconds, pipelineCommand: "run_tests", pipelineArgs });
4173
5253
  const invoked = await invokeOrUnavailable(argv, ctx, waitSeconds, dir);
4174
5254
  if (isOutcome(invoked)) return invoked;
4175
- const result = invoked;
4176
- const exec = executionFromProcess(result.outcome);
4177
- const base = { command: result.command, tool: result.toolInfo, rawOutput: result.rawOutput };
4178
- const extracted = result.tool.parseError === null ? extractStatus(result.tool.payload) : { status: null, source: null };
5255
+ const result4 = invoked;
5256
+ const exec = executionFromProcess(result4.outcome);
5257
+ const base = { command: result4.command, tool: result4.toolInfo, rawOutput: result4.rawOutput };
5258
+ const extracted = result4.tool.parseError === null ? extractStatus(result4.tool.payload) : { status: null, source: null };
4179
5259
  const output = {
4180
5260
  accepted: false,
4181
5261
  mode,
4182
5262
  filter,
4183
5263
  testStatus: extracted.status,
4184
- waitBudgetExpired: result.handoff
5264
+ waitBudgetExpired: result4.handoff
4185
5265
  };
4186
5266
  if (exec.status !== "succeeded") {
4187
- return { ...failedBeforeRun(result, "run_tests \u542F\u52A8", "unity.test-status"), output };
5267
+ return { ...failedBeforeRun(result4, "run_tests \u542F\u52A8", "unity.test-status"), output };
4188
5268
  }
4189
- if (result.tool.success === false) return { ...toolReportedFailure(result, "run_tests \u542F\u52A8"), output };
4190
- if (result.handoff || result.tool.parseError !== null) {
5269
+ if (result4.tool.success === false) return { ...toolReportedFailure(result4, "run_tests \u542F\u52A8"), output };
5270
+ if (result4.handoff || result4.tool.parseError !== null) {
4191
5271
  return {
4192
5272
  ...base,
4193
5273
  output,
4194
5274
  execution: {
4195
5275
  status: "unknown",
4196
5276
  lifecycle: "unknown",
4197
- exitCode: result.outcome.exitCode,
4198
- signal: result.outcome.signal,
5277
+ exitCode: result4.outcome.exitCode,
5278
+ signal: result4.outcome.signal,
4199
5279
  error: structuredError(
4200
5280
  "trigger-unconfirmed",
4201
5281
  "protocol",
4202
5282
  "\u7B49\u5F85\u9884\u7B97\u8017\u5C3D/\u8F93\u51FA\u4E0D\u53EF\u89E3\u6790\uFF1A\u65E0\u6CD5\u786E\u8BA4\u6D4B\u8BD5\u542F\u52A8\u5DF2\u88AB\u63A5\u53D7\uFF08\u5305\u88C5\u5668\u5DF2\u8BA9\u51FA\u63A7\u5236\u6743\uFF09",
4203
- { details: { stderrTail: result.outcome.stderr.slice(-800) } }
5283
+ { details: { stderrTail: result4.outcome.stderr.slice(-800) } }
4204
5284
  )
4205
5285
  },
4206
5286
  acceptance: {
4207
5287
  status: "not-run",
4208
5288
  reason: "\u6D4B\u8BD5\u542F\u52A8\u672A\u786E\u8BA4\uFF1B\u8BF7\u7528 unity.test-status \u8F6E\u8BE2\uFF08pending\uFF09",
4209
5289
  pending: true,
4210
- evidence: [evidenceExit(result.outcome)]
5290
+ evidence: [evidenceExit(result4.outcome)]
4211
5291
  },
4212
5292
  followUp: [{ capabilityId: "unity.test-status", hint: "\u8F6E\u8BE2 test_status \u76F4\u5230 completed \u5E76\u6838\u5BF9\u5931\u8D25\u6570" }]
4213
5293
  };
@@ -4228,7 +5308,7 @@ function createUnityProvider(deps) {
4228
5308
  "\u672C\u80FD\u529B\u56FA\u5B9A\u8FFD\u52A0 --async_tests\uFF08Unity CLI \u540C\u6B65\u547D\u4EE4\u6709 30s \u786C\u4E0A\u9650\uFF0C\u5168\u91CF\u540C\u6B65\u5FC5\u7136\u8D85\u65F6\uFF09",
4229
5309
  "\u53E5\u67C4 backendTaskId=RunId\uFF08\u540E\u7AEF patchVersion 3\uFF09\uFF1A\u7528 unity.test-query / unity.test-cancel-run \u6309\u53E5\u67C4\u5173\u8054\u67E5\u8BE2/\u53D6\u6D88"
4230
5310
  ],
4231
- handle: { backendTaskId: extractRunId(result.tool.payload).runId }
5311
+ handle: { backendTaskId: extractRunId(result4.tool.payload).runId }
4232
5312
  };
4233
5313
  };
4234
5314
  const testStatusExecute = async (input, ctx) => {
@@ -4238,33 +5318,33 @@ function createUnityProvider(deps) {
4238
5318
  const argv = buildExecArgv({ projectDir: dir, waitSeconds, pipelineCommand: "test_status" });
4239
5319
  const invoked = await invokeOrUnavailable(argv, ctx, waitSeconds, dir);
4240
5320
  if (isOutcome(invoked)) return invoked;
4241
- const result = invoked;
4242
- const exec = executionFromProcess(result.outcome);
4243
- const base = { command: result.command, tool: result.toolInfo, rawOutput: result.rawOutput };
4244
- if (exec.status !== "succeeded") return failedBeforeRun(result, "test_status", "unity.test-status");
4245
- if (result.tool.success === false) return toolReportedFailure(result, "test_status");
4246
- if (result.handoff) {
4247
- return statusHandoffOutcome(result, "test_status", "unity.test-status");
4248
- }
4249
- if (result.tool.parseError !== null) return unparseable(result, "test_status", "unity.test-status");
4250
- if (result.tool.payloadParseError !== null) {
5321
+ const result4 = invoked;
5322
+ const exec = executionFromProcess(result4.outcome);
5323
+ const base = { command: result4.command, tool: result4.toolInfo, rawOutput: result4.rawOutput };
5324
+ if (exec.status !== "succeeded") return failedBeforeRun(result4, "test_status", "unity.test-status");
5325
+ if (result4.tool.success === false) return toolReportedFailure(result4, "test_status");
5326
+ if (result4.handoff) {
5327
+ return statusHandoffOutcome(result4, "test_status", "unity.test-status");
5328
+ }
5329
+ if (result4.tool.parseError !== null) return unparseable(result4, "test_status", "unity.test-status");
5330
+ if (result4.tool.payloadParseError !== null) {
4251
5331
  return {
4252
5332
  ...base,
4253
5333
  output: { status: null, statusSource: null, completed: false, failCount: null, failCountSource: null, total: null, reportPresent: false, reportSources: [] },
4254
5334
  execution: { ...exec, lifecycle: "unknown" },
4255
5335
  acceptance: {
4256
5336
  status: "not-run",
4257
- reason: `test_status \u8F7D\u8377\u4E0D\u53EF\u89E3\u6790: ${result.tool.payloadParseError}`,
5337
+ reason: `test_status \u8F7D\u8377\u4E0D\u53EF\u89E3\u6790: ${result4.tool.payloadParseError}`,
4258
5338
  pending: true,
4259
- evidence: [evidenceExit(result.outcome)]
5339
+ evidence: [evidenceExit(result4.outcome)]
4260
5340
  },
4261
5341
  followUp: [{ capabilityId: "unity.test-status", hint: "\u91CD\u65B0\u6267\u884C\u672C\u80FD\u529B\u4EE5\u53D6\u5F97\u7ED3\u8BBA" }]
4262
5342
  };
4263
5343
  }
4264
- const { status, source } = extractStatus(result.tool.payload);
4265
- const fails = extractFailCount(result.tool.payload);
4266
- const totals = extractTotal(result.tool.payload);
4267
- const report = detectTestReport(result.tool.payload);
5344
+ const { status, source } = extractStatus(result4.tool.payload);
5345
+ const fails = extractFailCount(result4.tool.payload);
5346
+ const totals = extractTotal(result4.tool.payload);
5347
+ const report = detectTestReport(result4.tool.payload);
4268
5348
  const klass = classifyTestStatus(status);
4269
5349
  const output = {
4270
5350
  status,
@@ -4322,7 +5402,7 @@ function createUnityProvider(deps) {
4322
5402
  }
4323
5403
  };
4324
5404
  }
4325
- const summary = result.tool.payload.summary;
5405
+ const summary = result4.tool.payload.summary;
4326
5406
  if (!Number.isSafeInteger(summary.passed) || summary.passed !== totals.total) {
4327
5407
  return { ...base, output, execution: exec, acceptance: { status: "failed", reason: "\u6D4B\u8BD5\u62A5\u544A\u7F3A\u5C11\u6709\u6548\u901A\u8FC7\u6570\uFF0C\u6216\u672A\u5168\u90E8\u901A\u8FC7", pending: false, evidence } };
4328
5408
  }
@@ -4397,30 +5477,30 @@ function createUnityProvider(deps) {
4397
5477
  const argv = buildExecArgv({ projectDir: dir, waitSeconds, pipelineCommand: "cancel_tests" });
4398
5478
  const invoked = await invokeOrUnavailable(argv, ctx, waitSeconds, dir);
4399
5479
  if (isOutcome(invoked)) return invoked;
4400
- const result = invoked;
4401
- let exec = executionFromProcess(result.outcome);
4402
- const stdoutParts = [result.outcome.stdout];
4403
- const stderrParts = [result.outcome.stderr];
5480
+ const result4 = invoked;
5481
+ let exec = executionFromProcess(result4.outcome);
5482
+ const stdoutParts = [result4.outcome.stdout];
5483
+ const stderrParts = [result4.outcome.stderr];
4404
5484
  const rawOutput = () => ({
4405
5485
  stdout: stdoutParts.join("\n"),
4406
5486
  stderr: stderrParts.join("\n"),
4407
- stdoutTruncated: result.outcome.stdoutTruncated,
4408
- stderrTruncated: result.outcome.stderrTruncated
5487
+ stdoutTruncated: result4.outcome.stdoutTruncated,
5488
+ stderrTruncated: result4.outcome.stderrTruncated
4409
5489
  });
4410
- const base = { command: result.command, tool: result.toolInfo };
5490
+ const base = { command: result4.command, tool: result4.toolInfo };
4411
5491
  if (exec.status !== "succeeded") {
4412
- return { ...failedBeforeRun(result, "cancel_tests", "unity.test-status"), rawOutput: rawOutput() };
5492
+ return { ...failedBeforeRun(result4, "cancel_tests", "unity.test-status"), rawOutput: rawOutput() };
4413
5493
  }
4414
- if (result.tool.success === false) {
4415
- return { ...toolReportedFailure(result, "cancel_tests"), rawOutput: rawOutput() };
5494
+ if (result4.tool.success === false) {
5495
+ return { ...toolReportedFailure(result4, "cancel_tests"), rawOutput: rawOutput() };
4416
5496
  }
4417
5497
  let confirmed = false;
4418
5498
  let confirmationSource = null;
4419
5499
  let probeStatus = null;
4420
5500
  let probeStatusSource = null;
4421
5501
  const evidence = [evidenceField("\u4FE1\u5C01 success", true)];
4422
- if (result.tool.parseError === null) {
4423
- const direct = detectCancellationConfirmation(result.tool.payload);
5502
+ if (result4.tool.parseError === null) {
5503
+ const direct = detectCancellationConfirmation(result4.tool.payload);
4424
5504
  if (direct.confirmed) {
4425
5505
  confirmed = true;
4426
5506
  confirmationSource = direct.source;
@@ -4480,7 +5560,7 @@ function createUnityProvider(deps) {
4480
5560
  }
4481
5561
  };
4482
5562
  }
4483
- exec = executionFromProcess(result.outcome);
5563
+ exec = executionFromProcess(result4.outcome);
4484
5564
  const klass = classifyTestStatus(probeStatus);
4485
5565
  if (klass === "running") {
4486
5566
  return {
@@ -4597,8 +5677,8 @@ function createUnityProvider(deps) {
4597
5677
  })
4598
5678
  ];
4599
5679
  }
4600
- function parsePayload(result) {
4601
- return { payload: result.tool.payload, parseError: result.tool.payloadParseError };
5680
+ function parsePayload(result4) {
5681
+ return { payload: result4.tool.payload, parseError: result4.tool.payloadParseError };
4602
5682
  }
4603
5683
  const compileQueryExecute = async (input, ctx) => {
4604
5684
  const dir = findUnityDir(ctx);
@@ -4610,14 +5690,14 @@ function createUnityProvider(deps) {
4610
5690
  const argv = buildExecArgv({ projectDir: dir, waitSeconds, pipelineCommand: "recompile_status", pipelineArgs: runId ? ["--run_id", runId] : [] });
4611
5691
  const invoked = await invokeOrUnavailable(argv, ctx, waitSeconds, dir);
4612
5692
  if (isOutcome(invoked)) return invoked;
4613
- const result = invoked;
4614
- const exec = executionFromProcess(result.outcome);
4615
- const base = { command: result.command, tool: result.toolInfo, rawOutput: result.rawOutput };
4616
- if (exec.status !== "succeeded") return failedBeforeRun(result, "recompile_status --run_id", "unity.compile-query");
4617
- if (result.tool.success === false) return toolReportedFailure(result, "recompile_status --run_id");
4618
- if (result.handoff) return statusHandoffOutcome(result, "recompile_status --run_id", "unity.compile-query");
4619
- if (result.tool.parseError !== null) return unparseable(result, "recompile_status --run_id", "unity.compile-query");
4620
- const { payload, parseError } = parsePayload(result);
5693
+ const result4 = invoked;
5694
+ const exec = executionFromProcess(result4.outcome);
5695
+ const base = { command: result4.command, tool: result4.toolInfo, rawOutput: result4.rawOutput };
5696
+ if (exec.status !== "succeeded") return failedBeforeRun(result4, "recompile_status --run_id", "unity.compile-query");
5697
+ if (result4.tool.success === false) return toolReportedFailure(result4, "recompile_status --run_id");
5698
+ if (result4.handoff) return statusHandoffOutcome(result4, "recompile_status --run_id", "unity.compile-query");
5699
+ if (result4.tool.parseError !== null) return unparseable(result4, "recompile_status --run_id", "unity.compile-query");
5700
+ const { payload, parseError } = parsePayload(result4);
4621
5701
  const evidence = [...identityEvidence(checked.verification)];
4622
5702
  const output = (extra) => ({
4623
5703
  runId,
@@ -4692,14 +5772,14 @@ function createUnityProvider(deps) {
4692
5772
  const argv = buildExecArgv({ projectDir: dir, waitSeconds, pipelineCommand: "test_status", pipelineArgs: runId ? ["--run_id", runId] : [] });
4693
5773
  const invoked = await invokeOrUnavailable(argv, ctx, waitSeconds, dir);
4694
5774
  if (isOutcome(invoked)) return invoked;
4695
- const result = invoked;
4696
- const exec = executionFromProcess(result.outcome);
4697
- const base = { command: result.command, tool: result.toolInfo, rawOutput: result.rawOutput };
4698
- if (exec.status !== "succeeded") return failedBeforeRun(result, "test_status --run_id", "unity.test-query");
4699
- if (result.tool.success === false) return toolReportedFailure(result, "test_status --run_id");
4700
- if (result.handoff) return statusHandoffOutcome(result, "test_status --run_id", "unity.test-query");
4701
- if (result.tool.parseError !== null) return unparseable(result, "test_status --run_id", "unity.test-query");
4702
- const { payload, parseError } = parsePayload(result);
5775
+ const result4 = invoked;
5776
+ const exec = executionFromProcess(result4.outcome);
5777
+ const base = { command: result4.command, tool: result4.toolInfo, rawOutput: result4.rawOutput };
5778
+ if (exec.status !== "succeeded") return failedBeforeRun(result4, "test_status --run_id", "unity.test-query");
5779
+ if (result4.tool.success === false) return toolReportedFailure(result4, "test_status --run_id");
5780
+ if (result4.handoff) return statusHandoffOutcome(result4, "test_status --run_id", "unity.test-query");
5781
+ if (result4.tool.parseError !== null) return unparseable(result4, "test_status --run_id", "unity.test-query");
5782
+ const { payload, parseError } = parsePayload(result4);
4703
5783
  const evidence = [...identityEvidence(checked.verification)];
4704
5784
  const output = (extra) => ({
4705
5785
  runId,
@@ -4786,14 +5866,14 @@ function createUnityProvider(deps) {
4786
5866
  const argv = buildExecArgv({ projectDir: dir, waitSeconds, pipelineCommand: "cancel_tests", pipelineArgs: runId ? ["--run_id", runId] : [] });
4787
5867
  const invoked = await invokeOrUnavailable(argv, ctx, waitSeconds, dir);
4788
5868
  if (isOutcome(invoked)) return invoked;
4789
- const result = invoked;
4790
- const exec = executionFromProcess(result.outcome);
4791
- const base = { command: result.command, tool: result.toolInfo, rawOutput: result.rawOutput };
4792
- if (exec.status !== "succeeded") return failedBeforeRun(result, "cancel_tests --run_id", "unity.test-cancel-run");
4793
- if (result.tool.success === false) return toolReportedFailure(result, "cancel_tests --run_id");
4794
- if (result.handoff) return statusHandoffOutcome(result, "cancel_tests --run_id", "unity.test-cancel-run");
4795
- if (result.tool.parseError !== null) return unparseable(result, "cancel_tests --run_id", "unity.test-cancel-run");
4796
- const { payload } = parsePayload(result);
5869
+ const result4 = invoked;
5870
+ const exec = executionFromProcess(result4.outcome);
5871
+ const base = { command: result4.command, tool: result4.toolInfo, rawOutput: result4.rawOutput };
5872
+ if (exec.status !== "succeeded") return failedBeforeRun(result4, "cancel_tests --run_id", "unity.test-cancel-run");
5873
+ if (result4.tool.success === false) return toolReportedFailure(result4, "cancel_tests --run_id");
5874
+ if (result4.handoff) return statusHandoffOutcome(result4, "cancel_tests --run_id", "unity.test-cancel-run");
5875
+ if (result4.tool.parseError !== null) return unparseable(result4, "cancel_tests --run_id", "unity.test-cancel-run");
5876
+ const { payload } = parsePayload(result4);
4797
5877
  const evidence = [...identityEvidence(checked.verification)];
4798
5878
  const output = (extra) => ({
4799
5879
  runId,
@@ -4847,6 +5927,44 @@ function createUnityProvider(deps) {
4847
5927
  ...execPreconditions,
4848
5928
  { id: "unity.handle-valid", description: "\u53E5\u67C4\u901A\u8FC7\u5185\u6838\u6821\u9A8C\uFF08\u8EAB\u4EFD\u4E00\u81F4 + \u843D\u76D8\u8BC1\u636E\u56DE\u8BFB\uFF1B\u89E6\u53D1\u80FD\u529B\u5339\u914D\uFF09" }
4849
5929
  ];
5930
+ const dedicatedPipelineCommands = /* @__PURE__ */ new Set(["editor_status", "recompile", "recompile_status", "run_tests", "test_status", "cancel_tests"]);
5931
+ const pipelineParametersCheck = (input) => {
5932
+ const parameters = input.parameters;
5933
+ const invalid = Object.entries(parameters ?? {}).some(([key, value]) => !/^[a-z][a-z0-9_]*$/.test(key) || /project_?path/i.test(key) || value === void 0 || value === null);
5934
+ return { id: "unity.parameters-valid", status: invalid ? "violated" : "satisfied", detail: invalid ? "\u53C2\u6570\u540D\u975E\u6CD5\u6216\u8BD5\u56FE\u8986\u76D6\u5DE5\u7A0B\u8DEF\u5F84" : "\u7ED3\u6784\u5316\u53C2\u6570\u901A\u8FC7\u68C0\u67E5\uFF1B\u5177\u4F53\u53C2\u6570\u5951\u7EA6\u7531 Unity \u5DE5\u5177\u6821\u9A8C" };
5935
+ };
5936
+ const pipelineRegistration = {
5937
+ descriptor: {
5938
+ id: "unity.command",
5939
+ commands: [["exec"]],
5940
+ version: "0.1.0",
5941
+ description: "\u6267\u884C\u5DF2\u767B\u8BB0\u7684 Unity Pipeline \u5DE5\u5177\uFF1B\u7F16\u8BD1\u548C\u6D4B\u8BD5\u4F7F\u7528\u4E13\u7528\u53E5\u67C4\u80FD\u529B",
5942
+ inputSchema: execInputSchema({ command: { type: "string", enum: Object.keys(PIPELINE_COMMANDS).filter((name) => !dedicatedPipelineCommands.has(name)) }, parameters: { type: "object", additionalProperties: true } }, ["command"]),
5943
+ outputSchema: { type: "object", required: ["result"], properties: { result: { type: "object", additionalProperties: true } }, additionalProperties: false },
5944
+ preconditions: [...execPreconditions, { id: "unity.parameters-valid", description: "\u53C2\u6570\u540D\u79F0\u5408\u6CD5\u4E14\u4E0D\u80FD\u8986\u76D6\u7ED1\u5B9A\u5DE5\u7A0B" }],
5945
+ sideEffects: execSideEffects(true),
5946
+ resources: EXEC_RESOURCES,
5947
+ retry: { safe: false, maxAttempts: 1, strategy: "none", description: "\u4E0D\u81EA\u52A8\u91CD\u653E\u5F15\u64CE\u64CD\u4F5C" }
5948
+ },
5949
+ implementation: { preconditions: { ...execChecks, "unity.parameters-valid": pipelineParametersCheck }, execute: async (input, ctx) => {
5950
+ const dir = findUnityDir(ctx);
5951
+ const pipelineArgs = Object.entries(input.parameters ?? {}).flatMap(([key, value]) => [`--${key}`, typeof value === "object" ? JSON.stringify(value) : String(value)]);
5952
+ const waitSeconds = inputWaitSeconds(input, "unity.command");
5953
+ const invoked = await invokeOrUnavailable(buildExecArgv({ projectDir: dir, waitSeconds, pipelineCommand: String(input.command), pipelineArgs }), ctx, waitSeconds, dir);
5954
+ if (isOutcome(invoked)) return invoked;
5955
+ const execution = executionFromProcess(invoked.outcome);
5956
+ const parsed = interpretToolOutput(invoked.outcome.stdout);
5957
+ const passed = execution.status === "succeeded" && parsed.success === true && !parsed.parseError && !parsed.payloadParseError;
5958
+ return {
5959
+ execution: { ...execution, ...!parsed.parseError && !parsed.payloadParseError ? {} : { lifecycle: "unknown" } },
5960
+ acceptance: { status: passed ? "passed" : "not-run", reason: passed ? "\u5DE5\u5177\u4FE1\u5C01\u786E\u8BA4\u6267\u884C\u6210\u529F\uFF0C\u5177\u4F53\u4EA7\u7269\u89C1 result" : "\u5DE5\u5177\u672A\u786E\u8BA4\u5B8C\u6210\uFF0C\u4E0D\u63A8\u65AD\u6210\u529F", evidence: [{ kind: "protocol-field", description: "Unity \u5DE5\u5177\u539F\u59CB\u7ED3\u679C", data: parsed.parsed }] },
5961
+ output: { result: { command: input.command, data: parsed.payload } },
5962
+ rawOutput: invoked.rawOutput,
5963
+ command: invoked.command,
5964
+ tool: invoked.toolInfo
5965
+ };
5966
+ } }
5967
+ };
4850
5968
  const registrations = [
4851
5969
  {
4852
5970
  descriptor: {
@@ -5070,8 +6188,8 @@ function createUnityProvider(deps) {
5070
6188
  binding: unityBindingContract,
5071
6189
  defaultBinding: (project) => {
5072
6190
  const warnings = [];
5073
- const declared = path5.join(project.root, "Client");
5074
- if (!fs6.existsSync(declared)) {
6191
+ const declared = path8.join(project.root, "Client");
6192
+ if (!fs9.existsSync(declared)) {
5075
6193
  warnings.push(
5076
6194
  `bindings.unity.projectDir="Client" \u5F53\u524D\u4E0D\u5B58\u5728\uFF1A\u8BF7\u6309\u5DE5\u7A0B\u5B9E\u9645\u76EE\u5F55\u4FEE\u6539 ${PROJECT_CLI_CONFIG_RELATIVE} \u6216\u7528 --binding unity='{...}' \u8986\u76D6`
5077
6195
  );
@@ -5090,12 +6208,12 @@ function createUnityProvider(deps) {
5090
6208
  const state = backend.info.status === "platform-mismatch" ? "platform-mismatch" : backend.info.status === "invalid" ? "invalid" : "missing";
5091
6209
  return { state, detail: backend.detail };
5092
6210
  },
5093
- capabilities: () => registrations
6211
+ capabilities: () => [...registrations.map((r) => ({ ...r, descriptor: { ...r.descriptor, commands: [r.descriptor.id === "unity.doctor" ? ["doctor"] : ["exec"]] } })), pipelineRegistration, ...unityCommandRegistrations(deps)]
5094
6212
  };
5095
6213
  }
5096
6214
 
5097
6215
  // src/providers/art/index.ts
5098
- import path6 from "path";
6216
+ import path9 from "path";
5099
6217
  import { readFileSync } from "fs";
5100
6218
  var identifier = {
5101
6219
  type: "string",
@@ -5143,7 +6261,24 @@ var artBindingContract = {
5143
6261
  }
5144
6262
  };
5145
6263
  var objectFields = { id: identifier, revision, input: file };
5146
- var definitions = [
6264
+ var definitions3 = [
6265
+ { id: "help", command: ["help"], fields: {}, readonly: true, text: true, global: true },
6266
+ ...["path", "show", "init", "validate"].map((action) => ({ id: "config-" + action, command: ["config", action], fields: {}, readonly: action !== "init", text: action === "path", global: true })),
6267
+ { id: "refs-guide", command: ["refs", "guide"], fields: {}, readonly: true, text: true, global: true },
6268
+ { id: "agent-index", command: ["agent", "index"], fields: {}, readonly: true, global: true },
6269
+ { id: "agent-docs", command: ["agent", "docs"], fields: {}, readonly: true, text: true, global: true },
6270
+ { id: "agent-init", command: ["agent", "init"], fields: { directory: file, dry: { type: "boolean" } }, required: ["directory"], global: true },
6271
+ { id: "list", command: ["list"], fields: {}, readonly: true, global: true },
6272
+ { id: "style-validate", command: ["style", "validate"], fields: { report: file }, readonly: true },
6273
+ { id: "style-show", command: ["style", "show"], fields: { core: identifier }, readonly: true },
6274
+ ...["generate", "edit"].map((kind) => ({ id: kind + "-show", command: [kind, "show"], fields: { job: identifier }, required: ["job"], readonly: true })),
6275
+ { id: "check", command: ["check"], fields: { run: file }, required: ["run"], positional: ["run"], readonly: true, global: true },
6276
+ { id: "compare", command: ["compare"], fields: { before: file, after: file }, required: ["before", "after"], positional: ["before", "after"], readonly: true, global: true },
6277
+ { id: "run-wait", command: ["task", "wait"], fields: { handle: { type: "object", additionalProperties: true }, timeout: { type: "integer", minimum: 1, maximum: 60 } }, required: ["handle"], control: true, readonly: true },
6278
+ { id: "shutdown", command: ["shutdown"], fields: {}, network: true, global: true },
6279
+ { id: "doctor", command: ["doctor"], fields: { backend: identifier, start: { type: "boolean" } }, network: true, global: true },
6280
+ { id: "workflow-list", command: ["workflow", "list"], fields: {}, readonly: true, global: true },
6281
+ { id: "project-upgrade", command: ["project", "upgrade"], fields: { dry: { type: "boolean" }, mapping: file } },
5147
6282
  { id: "job-template", command: ["job", "template"], fields: { kind: { type: "string", enum: ["generate", "edit"] }, core: identifier }, required: ["kind"], readonly: true },
5148
6283
  { id: "job-from-candidate", command: ["job", "from-candidate"], fields: { id: identifier, run: identifier, candidate: { type: "string", pattern: "^[a-f0-9]{64}$" } }, required: ["id", "run", "candidate"] },
5149
6284
  { id: "deployment-plan", command: ["deployment", "plan"], fields: { directory: { type: "string", minLength: 1 }, endpoint: { type: "string", minLength: 1 } }, required: ["directory"], readonly: true },
@@ -5296,9 +6431,10 @@ function createArtProvider(deps) {
5296
6431
  const discover = deps.discoverBackend ?? (() => discoverOfficialPlugin(
5297
6432
  OFFICIAL_PLUGINS.find((s) => s.command === "art")
5298
6433
  ));
5299
- const registrations = definitions.map((d) => ({
6434
+ const registrations = definitions3.map((d) => ({
5300
6435
  descriptor: {
5301
6436
  id: "art." + d.id,
6437
+ commands: [d.command],
5302
6438
  version: "0.1.0",
5303
6439
  description: "\u7F8E\u672F\u5DE5\u574A " + d.command.join(" ") + "\uFF1B\u5BF9\u8C61\u7248\u672C\u4E0E\u505C\u6B62\u8BC1\u636E\u7531\u5DE5\u5177\u6838\u9A8C",
5304
6440
  inputSchema: {
@@ -5393,9 +6529,9 @@ function createArtProvider(deps) {
5393
6529
  "--cache-dir",
5394
6530
  ctx.bindingDirs.cache,
5395
6531
  "--config",
5396
- path6.join(ctx.bindingDirs.workspace, "settings.json")
6532
+ path9.join(ctx.bindingDirs.workspace, "settings.json")
5397
6533
  ];
5398
- if (!d.control && !(d.command[1] === "run" && input.plan))
6534
+ if (!d.global && !d.control && !(d.command[1] === "run" && input.plan))
5399
6535
  argv.push("--project", String(ctx.binding.projectId));
5400
6536
  if (d.control) {
5401
6537
  const verification = verifyExecutionHandle({
@@ -5411,9 +6547,11 @@ function createArtProvider(deps) {
5411
6547
  if (origin.output?.result?.project !== ctx.binding.projectId || ["workspace", "output", "cache"].some((key) => origin.project?.bindingDirs?.art?.[key] !== ctx.bindingDirs?.[key])) return fail("art-handle-binding-changed", "\u8FD0\u884C\u8EAB\u4EFD\u4E0E\u5F53\u524D\u5DE5\u7A0B\u7ED1\u5B9A\u4E0D\u540C\uFF1B\u8BF7\u6062\u590D\u539F\u7ED1\u5B9A\u540E\u64CD\u4F5C");
5412
6548
  argv.splice(2, 0, verification.record.backendTaskId);
5413
6549
  }
6550
+ if (d.id === "run-wait" && input.timeout === void 0) argv.push("--timeout", "30");
6551
+ for (const key of d.positional ?? []) argv.push(resolveInsideProject(ctx.projectAnchor, String(input[key]), "art." + key).path);
5414
6552
  for (const [key, value] of Object.entries(input)) {
5415
- if (key === "handle" || value === false) continue;
5416
- const actual = ["input", "source", "plan", "out"].includes(key) ? resolveInsideProject(
6553
+ if (key === "handle" || d.positional?.includes(key) || value === false) continue;
6554
+ const actual = ["input", "source", "plan", "out", "report", "mapping", ...d.id === "agent-init" ? ["directory"] : []].includes(key) ? resolveInsideProject(
5417
6555
  ctx.projectAnchor,
5418
6556
  String(value),
5419
6557
  "art." + key
@@ -5434,7 +6572,7 @@ function createArtProvider(deps) {
5434
6572
  });
5435
6573
  let output;
5436
6574
  try {
5437
- const parsed = JSON.parse(outcome.stdout);
6575
+ const parsed = d.text ? { text: outcome.stdout } : JSON.parse(outcome.stdout);
5438
6576
  output = Array.isArray(parsed) ? { items: parsed } : parsed;
5439
6577
  if (!output || typeof output !== "object") throw new Error();
5440
6578
  } catch {
@@ -5500,9 +6638,133 @@ function createArtProvider(deps) {
5500
6638
  };
5501
6639
  }
5502
6640
 
6641
+ // src/providers/figma/commands.ts
6642
+ var text4 = { type: "string", minLength: 1 };
6643
+ var flag2 = { type: "boolean" };
6644
+ var result3 = (fields) => ({
6645
+ type: "object",
6646
+ required: Object.keys(fields),
6647
+ properties: fields,
6648
+ additionalProperties: true
6649
+ });
6650
+ var commands3 = [
6651
+ {
6652
+ id: "agent-docs",
6653
+ command: ["agent", "docs"],
6654
+ description: "\u8BFB\u53D6 Figma Agent \u6587\u6863",
6655
+ fields: {},
6656
+ readonly: true,
6657
+ result: result3({ bytes: { type: "integer", minimum: 1 }, content: text4 }),
6658
+ verify: (r) => typeof r.bytes === "number" && r.bytes > 0
6659
+ },
6660
+ ...["setup", "config-init", "config-migrate"].map(
6661
+ (id) => ({
6662
+ id,
6663
+ command: id === "setup" ? ["setup"] : ["config", id.slice(7)],
6664
+ description: "\u914D\u7F6E Figma \u5DE5\u7A0B",
6665
+ fields: { force: flag2 },
6666
+ machine: true,
6667
+ result: result3({ configPath: text4, projectKey: text4 }),
6668
+ verify: (r) => typeof r.configPath === "string" && typeof r.projectKey === "string"
6669
+ })
6670
+ ),
6671
+ {
6672
+ id: "config-validate",
6673
+ command: ["config", "validate"],
6674
+ description: "\u6821\u9A8C Figma \u5DE5\u7A0B\u914D\u7F6E",
6675
+ fields: {},
6676
+ readonly: true,
6677
+ result: result3({ valid: flag2 }),
6678
+ verify: (r) => r.valid === true
6679
+ },
6680
+ {
6681
+ id: "export",
6682
+ command: ["export"],
6683
+ description: "\u5BFC\u51FA Figma \u6E90\u6E05\u5355\u4E0E\u56FE\u7247",
6684
+ fields: {
6685
+ fileKey: { type: "string", pattern: "^[A-Za-z0-9_-]+$" },
6686
+ "discovery-only": flag2,
6687
+ "discovery-document": text4,
6688
+ "node-documents": text4,
6689
+ "image-scale": { type: "number", minimum: 0.01, maximum: 4 }
6690
+ },
6691
+ required: ["fileKey"],
6692
+ network: true,
6693
+ result: result3({
6694
+ rootCount: { type: "integer", minimum: 0 },
6695
+ writtenFiles: { type: "array" }
6696
+ }),
6697
+ verify: (r) => typeof r.rootCount === "number" && r.rootCount > 0
6698
+ },
6699
+ ...["install", "status", "uninstall"].map(
6700
+ (action) => ({
6701
+ id: `unity-${action}`,
6702
+ command: ["unity", action],
6703
+ description: `Figma Unity \u8F6C\u6362\u5668${action === "install" ? "\u5B89\u88C5" : action === "uninstall" ? "\u5378\u8F7D" : "\u68C0\u67E5"}`,
6704
+ fields: action === "status" ? {} : { "dry-run": flag2, force: flag2 },
6705
+ readonly: action === "status",
6706
+ result: result3(
6707
+ action === "status" ? { installed: flag2, modified: flag2 } : { status: text4 }
6708
+ ),
6709
+ verify: (r) => action === "status" ? r.modified === false : typeof r.status === "string" && !/Rejected|Failed/.test(r.status)
6710
+ })
6711
+ ),
6712
+ {
6713
+ id: "build",
6714
+ command: ["build"],
6715
+ description: "\u901A\u8FC7 Unity \u8F6C\u6362\u5668\u6784\u5EFA\u6682\u5B58\u9884\u5236\u4F53",
6716
+ engine: true,
6717
+ fields: { index: text4, "allow-running-editor": flag2 },
6718
+ result: result3({
6719
+ report: {
6720
+ type: "object",
6721
+ required: ["entries", "issues"],
6722
+ properties: {
6723
+ entries: { type: "array", minItems: 1 },
6724
+ issues: { type: "array" }
6725
+ },
6726
+ additionalProperties: true
6727
+ },
6728
+ reportPath: text4
6729
+ }),
6730
+ verify: (r) => {
6731
+ const report = r.report;
6732
+ return Array.isArray(report?.entries) && report.entries.length > 0 && report.entries.every((e) => !e.errorCode) && Array.isArray(report.issues) && report.issues.every((e) => e.severity !== "error");
6733
+ }
6734
+ }
6735
+ ];
6736
+ function figmaCommandRegistrations(deps) {
6737
+ return commandRegistrations(
6738
+ "figma",
6739
+ commands3.map((d) => ({
6740
+ ...d,
6741
+ args: (input, ctx) => {
6742
+ if (d.id === "agent-docs") return ["--json"];
6743
+ const args = d.id === "setup" ? [ctx.bindingDirs.projectDir] : ["--project", ctx.bindingDirs.projectDir];
6744
+ if (d.id === "export") args.unshift(String(input.fileKey));
6745
+ args.push("--json");
6746
+ for (const [key, value] of Object.entries(input)) {
6747
+ if (key === "fileKey" || value === false) continue;
6748
+ args.push(`--${key}`);
6749
+ if (value !== true)
6750
+ args.push(
6751
+ ["index", "discovery-document", "node-documents"].includes(key) ? resolveInsideProject(
6752
+ ctx.projectAnchor,
6753
+ String(value),
6754
+ `figma.${key}`
6755
+ ).path : String(value)
6756
+ );
6757
+ }
6758
+ return args;
6759
+ }
6760
+ })),
6761
+ deps
6762
+ );
6763
+ }
6764
+
5503
6765
  // src/providers/figma/index.ts
5504
- import fs7 from "fs";
5505
- import path7 from "path";
6766
+ import fs10 from "fs";
6767
+ import path10 from "path";
5506
6768
 
5507
6769
  // src/providers/figma/protocol.ts
5508
6770
  var VALID_LINE = /^(?:\[figma-to-uprefab\] )?Contract valid: (\d+) root\(s\)\.$/;
@@ -5605,8 +6867,8 @@ var figmaBindingContract = {
5605
6867
  if (errors.length > 0) return { ok: false, errors };
5606
6868
  const projectDir = resolve(project, section.projectDir, "bindings.figma.projectDir");
5607
6869
  const stagingRoot = resolve(project, section.stagingRoot, "bindings.figma.stagingRoot");
5608
- const rel = path7.relative(projectDir.path, stagingRoot.path);
5609
- if (rel === "" || rel === ".." || rel.startsWith(`..${path7.sep}`) || path7.isAbsolute(rel)) {
6870
+ const rel = path10.relative(projectDir.path, stagingRoot.path);
6871
+ if (rel === "" || rel === ".." || rel.startsWith(`..${path10.sep}`) || path10.isAbsolute(rel)) {
5610
6872
  return {
5611
6873
  ok: false,
5612
6874
  errors: [`bindings.figma.stagingRoot \u5FC5\u987B\u4F4D\u4E8E bindings.figma.projectDir\uFF08${section.projectDir}\uFF09\u5185\uFF08\u6536\u5230 ${section.stagingRoot}\uFF09`]
@@ -5627,7 +6889,7 @@ function figmaBinding(ctx) {
5627
6889
  return binding;
5628
6890
  }
5629
6891
  function normalizeProjectKey(projectPath) {
5630
- let key = path7.resolve(projectPath).replace(/\\/g, "/");
6892
+ let key = path10.resolve(projectPath).replace(/\\/g, "/");
5631
6893
  if (process.platform === "win32") key = key.toLowerCase();
5632
6894
  if (key.length > 3 && key.endsWith("/")) key = key.slice(0, -1);
5633
6895
  return key;
@@ -5663,23 +6925,23 @@ function createFigmaProvider(deps) {
5663
6925
  };
5664
6926
  }
5665
6927
  function writeManagedConfig(ctx, unityDir, stagingRootAbs) {
5666
- const configPath = path7.join(ctx.projectAnchor.root, ...MANAGED_CONFIG_RELATIVE.split("/"));
5667
- const stagingRelativeToUnity = path7.relative(unityDir, stagingRootAbs).split(path7.sep).join("/");
6928
+ const configPath = path10.join(ctx.projectAnchor.root, ...MANAGED_CONFIG_RELATIVE.split("/"));
6929
+ const stagingRelativeToUnity = path10.relative(unityDir, stagingRootAbs).split(path10.sep).join("/");
5668
6930
  const payload = {
5669
6931
  schemaVersion: 1,
5670
6932
  projects: {
5671
6933
  [normalizeProjectKey(unityDir)]: { uiSystem: "UGUI", staging: { root: stagingRelativeToUnity } }
5672
6934
  }
5673
6935
  };
5674
- fs7.mkdirSync(path7.dirname(configPath), { recursive: true });
6936
+ fs10.mkdirSync(path10.dirname(configPath), { recursive: true });
5675
6937
  const tmpPath = `${configPath}.${process.pid}.${Date.now()}.tmp`;
5676
6938
  try {
5677
- fs7.writeFileSync(tmpPath, `${JSON.stringify(payload, null, 2)}
6939
+ fs10.writeFileSync(tmpPath, `${JSON.stringify(payload, null, 2)}
5678
6940
  `, "utf-8");
5679
- fs7.renameSync(tmpPath, configPath);
6941
+ fs10.renameSync(tmpPath, configPath);
5680
6942
  } catch (err) {
5681
6943
  try {
5682
- fs7.rmSync(tmpPath, { force: true });
6944
+ fs10.rmSync(tmpPath, { force: true });
5683
6945
  } catch {
5684
6946
  }
5685
6947
  throw err;
@@ -6069,10 +7331,10 @@ function createFigmaProvider(deps) {
6069
7331
  binding: figmaBindingContract,
6070
7332
  defaultBinding: (project) => {
6071
7333
  const warnings = [];
6072
- const declared = path7.join(project.root, "Client");
6073
- if (!fs7.existsSync(declared)) {
7334
+ const declared = path10.join(project.root, "Client");
7335
+ if (!fs10.existsSync(declared)) {
6074
7336
  warnings.push('bindings.figma.projectDir="Client" \u5F53\u524D\u4E0D\u5B58\u5728\uFF1A\u8BF7\u6309\u5DE5\u7A0B\u5B9E\u9645\u76EE\u5F55\u4FEE\u6539 .vant/config/v-cli.json \u6216\u7528 --binding figma \u8986\u76D6');
6075
- } else if (!fs7.existsSync(path7.join(declared, ...DEFAULT_STAGING_ROOT_SEGMENTS.split("/")))) {
7337
+ } else if (!fs10.existsSync(path10.join(declared, ...DEFAULT_STAGING_ROOT_SEGMENTS.split("/")))) {
6076
7338
  warnings.push(`\u9ED8\u8BA4 staging \u6839 Client/${DEFAULT_STAGING_ROOT_SEGMENTS} \u5F53\u524D\u4E0D\u5B58\u5728\uFF1Afigma.contract \u5C06\u6309 CON_INDEX_MISSING \u660E\u786E\u5931\u8D25\uFF08staging \u7531 Figma \u5BFC\u51FA\u6D41\u7A0B\u4EA7\u51FA\uFF09`);
6077
7339
  }
6078
7340
  return { section: { projectDir: "Client", stagingRoot: `Client/${DEFAULT_STAGING_ROOT_SEGMENTS}` }, warnings };
@@ -6089,7 +7351,7 @@ function createFigmaProvider(deps) {
6089
7351
  const state = backend.info.status === "platform-mismatch" ? "platform-mismatch" : backend.info.status === "invalid" ? "invalid" : "missing";
6090
7352
  return { state, detail: backend.detail };
6091
7353
  },
6092
- capabilities: () => registrations
7354
+ capabilities: () => [...registrations.map((r) => ({ ...r, descriptor: { ...r.descriptor, commands: [[r.descriptor.id.slice(6)]] } })), ...figmaCommandRegistrations(deps)]
6093
7355
  };
6094
7356
  }
6095
7357
 
@@ -6115,11 +7377,45 @@ function createDefaultRegistry(options = {}) {
6115
7377
  })
6116
7378
  );
6117
7379
  registry.registerProvider(createArtProvider({ executor, discoverBackend: options.artDiscoverBackend, env: options.artEnv }));
7380
+ registry.registerProvider(createShipProvider({ executor, discoverBackend: options.shipDiscoverBackend }));
7381
+ registry.registerProvider(createXlmergeProvider({ executor, discoverBackend: options.xlmergeDiscoverBackend }));
6118
7382
  return registry;
6119
7383
  }
6120
7384
 
6121
7385
  // src/version.ts
6122
- var VERSION = "0.4.6";
7386
+ var VERSION = "0.4.7";
7387
+
7388
+ // src/capability-coverage.ts
7389
+ function capabilityCoverage(registry) {
7390
+ const providers = OFFICIAL_PLUGINS.map((spec) => {
7391
+ const plugin = discoverOfficialPlugin(spec);
7392
+ const capabilities = registry.list().filter((c) => c.provider.id === spec.command).map((c) => registry.describe(c.id));
7393
+ const commands4 = (plugin.commands ?? []).map((command) => {
7394
+ const ids = capabilities.filter(
7395
+ (c) => c.commands?.some(
7396
+ (p) => JSON.stringify(p) === JSON.stringify(command.path)
7397
+ )
7398
+ ).map((c) => c.id);
7399
+ return {
7400
+ command: command.path,
7401
+ capabilities: ids,
7402
+ covered: ids.length > 0
7403
+ };
7404
+ });
7405
+ return {
7406
+ provider: spec.command,
7407
+ package: spec.package,
7408
+ version: plugin.version,
7409
+ state: plugin.status,
7410
+ commands: commands4,
7411
+ missing: commands4.filter((c) => !c.covered).map((c) => c.command)
7412
+ };
7413
+ });
7414
+ return {
7415
+ ok: providers.every((p) => p.commands.length > 0 && p.missing.length === 0),
7416
+ providers
7417
+ };
7418
+ }
6123
7419
  export {
6124
7420
  CapabilityError,
6125
7421
  CapabilityRegistrationError,
@@ -6144,6 +7440,7 @@ export {
6144
7440
  buildExecArgv,
6145
7441
  buildExecutionHandle,
6146
7442
  canonicalize,
7443
+ capabilityCoverage,
6147
7444
  createArtProvider,
6148
7445
  createDefaultRegistry,
6149
7446
  createFigmaProvider,