opencode-supertask 0.1.23 → 0.1.24

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/cli/index.js CHANGED
@@ -24128,6 +24128,11 @@ function compareVersions(left, right) {
24128
24128
  function cacheRoot() {
24129
24129
  return process.env.SUPERTASK_OPENCODE_CACHE_DIR ?? join4(homedir4(), ".cache/opencode/packages");
24130
24130
  }
24131
+ function installedPlugins() {
24132
+ const root = cacheRoot();
24133
+ const packageDirs = existsSync6(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)) : [];
24134
+ return packageDirs.map(pluginAt).filter((plugin) => plugin !== null);
24135
+ }
24131
24136
  function resolveInstalledPlugin() {
24132
24137
  const override = process.env.SUPERTASK_PLUGIN_PACKAGE_DIR;
24133
24138
  if (override) {
@@ -24135,9 +24140,7 @@ function resolveInstalledPlugin() {
24135
24140
  if (!plugin) throw new Error(`[supertask] \u5B89\u88C5\u5305\u65E0\u6548\u6216\u7F3A\u5C11 Gateway \u6784\u5EFA\u4EA7\u7269: ${override}`);
24136
24141
  return plugin;
24137
24142
  }
24138
- const root = cacheRoot();
24139
- const packageDirs = existsSync6(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)) : [];
24140
- const installed = packageDirs.map(pluginAt).filter((plugin) => plugin !== null).sort((left, right) => compareVersions(right.version, left.version));
24143
+ const installed = installedPlugins().sort((left, right) => compareVersions(right.version, left.version));
24141
24144
  if (!installed[0]) {
24142
24145
  throw new Error(`[supertask] OpenCode \u63D2\u4EF6\u7F13\u5B58\u4E2D\u627E\u4E0D\u5230\u53EF\u8FD0\u884C\u7684 ${PACKAGE_NAME}`);
24143
24146
  }
@@ -24146,10 +24149,52 @@ function resolveInstalledPlugin() {
24146
24149
  function opencodeBin() {
24147
24150
  return process.env.SUPERTASK_OPENCODE_BIN ?? "opencode";
24148
24151
  }
24152
+ function npmBin() {
24153
+ return process.env.SUPERTASK_NPM_BIN ?? "npm";
24154
+ }
24155
+ function latestVersion() {
24156
+ const result = spawnSync3(npmBin(), [
24157
+ "view",
24158
+ PACKAGE_NAME,
24159
+ "dist-tags.latest",
24160
+ "--json"
24161
+ ], {
24162
+ encoding: "utf8",
24163
+ env: process.env,
24164
+ timeout: 3e4
24165
+ });
24166
+ const output = `${result.stdout ?? ""}`.trim();
24167
+ if (result.error) {
24168
+ throw new Error(`[supertask] \u67E5\u8BE2 npm latest \u5931\u8D25: ${result.error.message}`);
24169
+ }
24170
+ if (result.status !== 0) {
24171
+ const detail = `${result.stderr ?? ""}`.trim();
24172
+ throw new Error(`[supertask] \u67E5\u8BE2 npm latest \u5931\u8D25: ${detail || `\u9000\u51FA\u7801 ${result.status}`}`);
24173
+ }
24174
+ let version2;
24175
+ try {
24176
+ version2 = JSON.parse(output);
24177
+ } catch {
24178
+ throw new Error(`[supertask] npm latest \u8FD4\u56DE\u65E0\u6CD5\u89E3\u6790: ${output || "(empty)"}`);
24179
+ }
24180
+ if (typeof version2 !== "string" || versionParts(version2) === null) {
24181
+ throw new Error(`[supertask] npm latest \u7248\u672C\u65E0\u6548: ${String(version2)}`);
24182
+ }
24183
+ return version2;
24184
+ }
24185
+ function resolveInstalledVersion(expectedVersion) {
24186
+ const override = process.env.SUPERTASK_PLUGIN_PACKAGE_DIR;
24187
+ const installed = override ? [pluginAt(override)].filter((plugin) => plugin !== null) : installedPlugins();
24188
+ const matched = installed.find((plugin) => plugin.version === expectedVersion);
24189
+ if (matched) return matched;
24190
+ const actual = installed.length > 0 ? installed.map((plugin) => plugin.version).join(", ") : "\u672A\u627E\u5230\u53EF\u8FD0\u884C\u7F13\u5B58";
24191
+ throw new Error(`[supertask] OpenCode \u63D2\u4EF6\u7F13\u5B58\u7248\u672C\u4E0D\u5339\u914D\uFF1A\u671F\u671B ${expectedVersion}\uFF0C\u5B9E\u9645 ${actual}`);
24192
+ }
24149
24193
  function installLatestPlugin() {
24194
+ const version2 = latestVersion();
24150
24195
  const result = spawnSync3(opencodeBin(), [
24151
24196
  "plugin",
24152
- `${PACKAGE_NAME}@latest`,
24197
+ `${PACKAGE_NAME}@${version2}`,
24153
24198
  "--global",
24154
24199
  "--force"
24155
24200
  ], {
@@ -24164,7 +24209,7 @@ function installLatestPlugin() {
24164
24209
  if (result.status !== 0) {
24165
24210
  throw new Error(`[supertask] OpenCode \u63D2\u4EF6\u66F4\u65B0\u5931\u8D25: ${output || `\u9000\u51FA\u7801 ${result.status}`}`);
24166
24211
  }
24167
- return resolveInstalledPlugin();
24212
+ return resolveInstalledVersion(version2);
24168
24213
  }
24169
24214
  var PACKAGE_NAME;
24170
24215
  var init_update2 = __esm({
@@ -24536,7 +24581,7 @@ program2.command("upgrade").description("Update OpenCode plugin cache and restar
24536
24581
  installed = installLatestPlugin2();
24537
24582
  } catch (err) {
24538
24583
  console.error(err instanceof Error ? err.message : String(err));
24539
- console.error("Try manually: opencode plugin opencode-supertask@latest --global --force");
24584
+ console.error("Try manually: query npm dist-tags.latest, then install that exact version with opencode plugin.");
24540
24585
  process.exit(1);
24541
24586
  }
24542
24587
  try {