@oh-my-tool/cli 0.3.5 → 0.3.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oh-my-tool/cli",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "description": "Oh My Tool CLI - local and enterprise tools for agents",
6
6
  "keywords": [
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "@clack/prompts": "^1.7.0",
31
31
  "@modelcontextprotocol/client": "2.0.0",
32
- "@oh-my-tool/sdk": "0.3.5",
32
+ "@oh-my-tool/sdk": "0.3.6",
33
33
  "open": "11.0.0"
34
34
  },
35
35
  "engines": {
@@ -37,6 +37,7 @@ export function discoverExtensions(home: string): InstalledExtension[] {
37
37
  for (const id of readdirSync(root)) {
38
38
  const idDir = join(root, id);
39
39
  if (!statSync(idDir).isDirectory()) continue;
40
+ const candidates: InstalledExtension[] = [];
40
41
  for (const version of readdirSync(idDir)) {
41
42
  const versionDir = join(idDir, version);
42
43
  if (!statSync(versionDir).isDirectory()) continue;
@@ -46,7 +47,7 @@ export function discoverExtensions(home: string): InstalledExtension[] {
46
47
  const manifest = parseManifest(readFileSync(manifestPath, "utf8"));
47
48
  validateManifest(manifest);
48
49
  checkSdkCompatibility(manifest.sdkVersion);
49
- out.push({
50
+ candidates.push({
50
51
  id,
51
52
  version,
52
53
  dir: versionDir,
@@ -57,6 +58,13 @@ export function discoverExtensions(home: string): InstalledExtension[] {
57
58
  // skip invalid or incompatible manifests
58
59
  }
59
60
  }
61
+ const active = candidates.reduce<InstalledExtension | undefined>((current, candidate) => {
62
+ if (current === undefined || Bun.semver.order(candidate.manifest.version, current.manifest.version) > 0) {
63
+ return candidate;
64
+ }
65
+ return current;
66
+ }, undefined);
67
+ if (active !== undefined) out.push(active);
60
68
  }
61
69
  return out;
62
- }
70
+ }
@@ -1,4 +1,4 @@
1
- import { cp, mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
1
+ import { cp, mkdir, mkdtemp, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
2
2
  import { execFile as execFileCallback } from "node:child_process";
3
3
  import { promisify } from "node:util";
4
4
  import { tmpdir } from "node:os";
@@ -88,9 +88,39 @@ async function installExtensionDirectory(home: string, srcDir: string, expectedP
88
88
  force: true,
89
89
  filter: (s: string) => basename(s) !== "node_modules",
90
90
  });
91
+ await retireInactiveVersions(home, manifest.id, manifest.version);
91
92
  return { id: manifest.id, version: manifest.version, target };
92
93
  }
93
94
 
95
+ async function retireInactiveVersions(home: string, id: string, activeVersion: string): Promise<void> {
96
+ const extensionRoot = join(home, "extensions", id);
97
+ let entries: string[];
98
+ try {
99
+ entries = await readdir(extensionRoot);
100
+ } catch (error) {
101
+ if (isMissingPathError(error)) return;
102
+ const message = error instanceof Error ? error.message : String(error);
103
+ throw new ExtensionInstallError(`failed to inspect installed versions for '${id}': ${message}`);
104
+ }
105
+
106
+ for (const entry of entries) {
107
+ if (entry === activeVersion || !EXACT_VERSION_RE.test(entry)) continue;
108
+ const entryPath = join(extensionRoot, entry);
109
+ try {
110
+ if ((await stat(entryPath)).isDirectory()) {
111
+ await rm(entryPath, { recursive: true, force: true });
112
+ }
113
+ } catch (error) {
114
+ const message = error instanceof Error ? error.message : String(error);
115
+ throw new ExtensionInstallError(`failed to retire inactive extension '${id}/${entry}': ${message}`);
116
+ }
117
+ }
118
+ }
119
+
120
+ function isMissingPathError(error: unknown): boolean {
121
+ return error instanceof Error && "code" in error && error.code === "ENOENT";
122
+ }
123
+
94
124
  export async function installLocalExtension(home: string, srcDir: string): Promise<InstalledRef> {
95
125
  return installExtensionDirectory(home, srcDir);
96
126
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.3.5";
1
+ export const VERSION = "0.3.6";