opencode-supertask 0.1.23 → 0.1.25

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.
@@ -27756,40 +27756,63 @@ function versionParts(version3) {
27756
27756
  const match = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(version3);
27757
27757
  return match ? match.slice(1).map(Number) : null;
27758
27758
  }
27759
- function compareVersions(left, right) {
27760
- const a = versionParts(left);
27761
- const b = versionParts(right);
27762
- if (!a || !b) return left.localeCompare(right);
27763
- for (let index2 = 0; index2 < 3; index2 += 1) {
27764
- if (a[index2] !== b[index2]) return a[index2] - b[index2];
27765
- }
27766
- return 0;
27767
- }
27768
27759
  function cacheRoot() {
27769
27760
  return process.env.SUPERTASK_OPENCODE_CACHE_DIR ?? join4(homedir4(), ".cache/opencode/packages");
27770
27761
  }
27771
- function resolveInstalledPlugin() {
27772
- const override = process.env.SUPERTASK_PLUGIN_PACKAGE_DIR;
27773
- if (override) {
27774
- const plugin = pluginAt(override);
27775
- if (!plugin) throw new Error(`[supertask] \u5B89\u88C5\u5305\u65E0\u6548\u6216\u7F3A\u5C11 Gateway \u6784\u5EFA\u4EA7\u7269: ${override}`);
27776
- return plugin;
27777
- }
27762
+ function installedPlugins() {
27778
27763
  const root = cacheRoot();
27779
27764
  const packageDirs = existsSync4(root) ? readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && (entry.name === PACKAGE_NAME || entry.name.startsWith(`${PACKAGE_NAME}@`))).map((entry) => join4(root, entry.name, "node_modules", PACKAGE_NAME)) : [];
27780
- const installed = packageDirs.map(pluginAt).filter((plugin) => plugin !== null).sort((left, right) => compareVersions(right.version, left.version));
27781
- if (!installed[0]) {
27782
- throw new Error(`[supertask] OpenCode \u63D2\u4EF6\u7F13\u5B58\u4E2D\u627E\u4E0D\u5230\u53EF\u8FD0\u884C\u7684 ${PACKAGE_NAME}`);
27783
- }
27784
- return installed[0];
27765
+ return packageDirs.map(pluginAt).filter((plugin) => plugin !== null);
27785
27766
  }
27786
27767
  function opencodeBin() {
27787
27768
  return process.env.SUPERTASK_OPENCODE_BIN ?? "opencode";
27788
27769
  }
27770
+ function npmBin() {
27771
+ return process.env.SUPERTASK_NPM_BIN ?? "npm";
27772
+ }
27773
+ function latestVersion() {
27774
+ const result = spawnSync2(npmBin(), [
27775
+ "view",
27776
+ PACKAGE_NAME,
27777
+ "dist-tags.latest",
27778
+ "--json"
27779
+ ], {
27780
+ encoding: "utf8",
27781
+ env: process.env,
27782
+ timeout: 3e4
27783
+ });
27784
+ const output = `${result.stdout ?? ""}`.trim();
27785
+ if (result.error) {
27786
+ throw new Error(`[supertask] \u67E5\u8BE2 npm latest \u5931\u8D25: ${result.error.message}`);
27787
+ }
27788
+ if (result.status !== 0) {
27789
+ const detail = `${result.stderr ?? ""}`.trim();
27790
+ throw new Error(`[supertask] \u67E5\u8BE2 npm latest \u5931\u8D25: ${detail || `\u9000\u51FA\u7801 ${result.status}`}`);
27791
+ }
27792
+ let version3;
27793
+ try {
27794
+ version3 = JSON.parse(output);
27795
+ } catch {
27796
+ throw new Error(`[supertask] npm latest \u8FD4\u56DE\u65E0\u6CD5\u89E3\u6790: ${output || "(empty)"}`);
27797
+ }
27798
+ if (typeof version3 !== "string" || versionParts(version3) === null) {
27799
+ throw new Error(`[supertask] npm latest \u7248\u672C\u65E0\u6548: ${String(version3)}`);
27800
+ }
27801
+ return version3;
27802
+ }
27803
+ function resolveInstalledVersion(expectedVersion) {
27804
+ const override = process.env.SUPERTASK_PLUGIN_PACKAGE_DIR;
27805
+ const installed = override ? [pluginAt(override)].filter((plugin) => plugin !== null) : installedPlugins();
27806
+ const matched = installed.find((plugin) => plugin.version === expectedVersion);
27807
+ if (matched) return matched;
27808
+ const actual = installed.length > 0 ? installed.map((plugin) => plugin.version).join(", ") : "\u672A\u627E\u5230\u53EF\u8FD0\u884C\u7F13\u5B58";
27809
+ throw new Error(`[supertask] OpenCode \u63D2\u4EF6\u7F13\u5B58\u7248\u672C\u4E0D\u5339\u914D\uFF1A\u671F\u671B ${expectedVersion}\uFF0C\u5B9E\u9645 ${actual}`);
27810
+ }
27789
27811
  function installLatestPlugin() {
27812
+ const version3 = latestVersion();
27790
27813
  const result = spawnSync2(opencodeBin(), [
27791
27814
  "plugin",
27792
- `${PACKAGE_NAME}@latest`,
27815
+ `${PACKAGE_NAME}@${version3}`,
27793
27816
  "--global",
27794
27817
  "--force"
27795
27818
  ], {
@@ -27804,7 +27827,7 @@ function installLatestPlugin() {
27804
27827
  if (result.status !== 0) {
27805
27828
  throw new Error(`[supertask] OpenCode \u63D2\u4EF6\u66F4\u65B0\u5931\u8D25: ${output || `\u9000\u51FA\u7801 ${result.status}`}`);
27806
27829
  }
27807
- return resolveInstalledPlugin();
27830
+ return resolveInstalledVersion(version3);
27808
27831
  }
27809
27832
 
27810
27833
  // plugin/supertask.ts
@@ -28222,7 +28245,7 @@ var SuperTaskPlugin = async () => {
28222
28245
  return JSON.stringify({
28223
28246
  success: false,
28224
28247
  error: updateError instanceof Error ? updateError.message : String(updateError),
28225
- hint: "Try manually: opencode plugin opencode-supertask@latest --global --force"
28248
+ hint: "Query npm dist-tags.latest, then install that exact version with opencode plugin."
28226
28249
  });
28227
28250
  }
28228
28251
  const result = upgrade(installed);