akm-opencode 0.0.19 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/index.ts +68 -39
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -75,7 +75,7 @@ At least one of `ref` or `query` is required.
75
75
 
76
76
  ## Prerequisites
77
77
 
78
- The plugin prefers an existing `akm` on PATH. If `akm` is missing and `bun` is available, it will attempt `bun install -g akm-cli` automatically. It does not run the standalone shell installers automatically. If Bun is not available, install `akm` from the [agentikit repo](https://github.com/itlackey/agentikit).
78
+ When the plugin loads, it runs `bun install -g akm-cli@latest` so it always picks up the latest published npm package. It then prefers the Bun-installed binary and falls back to an existing `akm` on PATH when needed. It does not run the standalone shell installers automatically.
79
79
 
80
80
  ```sh
81
81
  # macOS / Linux
@@ -84,7 +84,7 @@ curl -fsSL https://raw.githubusercontent.com/itlackey/agentikit/main/install.sh
84
84
  irm https://raw.githubusercontent.com/itlackey/agentikit/main/install.ps1 -OutFile install.ps1; ./install.ps1
85
85
 
86
86
  # Or via Bun
87
- bun install -g akm-cli
87
+ bun install -g akm-cli@latest
88
88
  ```
89
89
 
90
90
  ## Stash model
package/index.ts CHANGED
@@ -3,7 +3,7 @@ import { execFileSync, execSync } from "node:child_process"
3
3
  import path from "node:path"
4
4
 
5
5
  let resolvedAkmCommand = "akm"
6
- let attemptedAutoInstall = false
6
+ const autoInstallPackageRef = "akm-cli@latest"
7
7
 
8
8
  type LogLevel = "debug" | "info" | "warn" | "error"
9
9
 
@@ -77,59 +77,84 @@ function getCommandStatus(command: string): "ok" | "missing" | "error" {
77
77
  }
78
78
  }
79
79
 
80
- function resolveAkmCommand(): string | CliError {
81
- const currentStatus = getCommandStatus(resolvedAkmCommand)
82
- if (currentStatus === "ok" || currentStatus === "error") return resolvedAkmCommand
83
-
84
- if (attemptedAutoInstall) {
85
- return { ok: false, error: "The 'akm' CLI was not found on PATH and automatic installation was unsuccessful." }
80
+ function getBunGlobalAkmCommand(): string | null {
81
+ try {
82
+ const globalBin = execFileSync("bun", ["pm", "bin", "-g"], {
83
+ encoding: "utf8",
84
+ timeout: 10_000,
85
+ }).trim()
86
+ if (!globalBin || !path.isAbsolute(globalBin)) return null
87
+ return process.platform === "win32"
88
+ ? path.join(globalBin, "akm.exe")
89
+ : path.join(globalBin, "akm")
90
+ } catch {
91
+ return null
86
92
  }
87
- attemptedAutoInstall = true
93
+ }
88
94
 
95
+ async function ensureLatestAkmInstalled(client: LogCapableClient): Promise<void> {
89
96
  try {
90
97
  execFileSync("bun", ["--version"], {
91
98
  encoding: "utf8",
92
99
  timeout: 10_000,
93
100
  })
94
- } catch {
95
- return {
96
- ok: false,
97
- error: "The 'akm' CLI was not found on PATH, and Bun is not available for automatic installation. Install akm from https://github.com/itlackey/agentikit.",
98
- }
101
+ } catch (error: unknown) {
102
+ await writePluginLog(client, "warn", "AKM auto-install skipped", {
103
+ subsystem: "akm",
104
+ installer: "bun",
105
+ error: `Bun is not available: ${formatCliError(error)}`,
106
+ })
107
+ return
99
108
  }
100
109
 
101
110
  try {
102
- execFileSync("bun", ["install", "-g", "akm-cli"], {
111
+ execFileSync("bun", ["install", "-g", autoInstallPackageRef], {
103
112
  encoding: "utf8",
104
113
  timeout: 120_000,
105
114
  stdio: "pipe",
106
115
  })
107
116
 
108
- const globalBin = execFileSync("bun", ["pm", "bin", "-g"], {
109
- encoding: "utf8",
110
- timeout: 10_000,
111
- }).trim()
112
-
113
- const candidate = path.join(globalBin, process.platform === "win32" ? "akm.exe" : "akm")
114
- if (getCommandStatus(candidate) === "ok") {
115
- resolvedAkmCommand = candidate
116
- return resolvedAkmCommand
117
- }
118
-
119
- if (getCommandStatus("akm") === "ok") {
117
+ const bunGlobalAkm = getBunGlobalAkmCommand()
118
+ if (bunGlobalAkm && getCommandStatus(bunGlobalAkm) === "ok") {
119
+ resolvedAkmCommand = bunGlobalAkm
120
+ } else if (getCommandStatus("akm") === "ok") {
120
121
  resolvedAkmCommand = "akm"
121
- return resolvedAkmCommand
122
122
  }
123
123
 
124
- return {
125
- ok: false,
126
- error: "Installed 'akm-cli' via Bun, but the 'akm' executable could not be resolved. Check your Bun global bin directory and PATH.",
127
- }
124
+ await writePluginLog(client, "info", "AKM CLI install check completed", {
125
+ subsystem: "akm",
126
+ installer: "bun",
127
+ package: autoInstallPackageRef,
128
+ command: resolvedAkmCommand,
129
+ })
128
130
  } catch (error: unknown) {
129
- return {
130
- ok: false,
131
- error: `Failed to auto-install 'akm-cli' via Bun: ${formatCliError(error)}`,
132
- }
131
+ await writePluginLog(client, "warn", "AKM auto-install failed", {
132
+ subsystem: "akm",
133
+ installer: "bun",
134
+ package: autoInstallPackageRef,
135
+ error: formatCliError(error),
136
+ })
137
+ }
138
+ }
139
+
140
+ function resolveAkmCommand(): string | CliError {
141
+ const currentStatus = getCommandStatus(resolvedAkmCommand)
142
+ if (currentStatus === "ok" || currentStatus === "error") return resolvedAkmCommand
143
+
144
+ const bunGlobalAkm = getBunGlobalAkmCommand()
145
+ if (bunGlobalAkm && getCommandStatus(bunGlobalAkm) === "ok") {
146
+ resolvedAkmCommand = bunGlobalAkm
147
+ return resolvedAkmCommand
148
+ }
149
+
150
+ if (getCommandStatus("akm") === "ok") {
151
+ resolvedAkmCommand = "akm"
152
+ return resolvedAkmCommand
153
+ }
154
+
155
+ return {
156
+ ok: false,
157
+ error: `The 'akm' CLI could not be resolved after attempting to install '${autoInstallPackageRef}' with Bun. Install akm from https://github.com/itlackey/agentikit.`,
133
158
  }
134
159
  }
135
160
 
@@ -454,8 +479,11 @@ type PluginClient = {
454
479
  }
455
480
  }
456
481
 
457
- export const AgentikitPlugin: Plugin = async ({ client }) => ({
458
- tool: {
482
+ export const AgentikitPlugin: Plugin = async ({ client }) => {
483
+ await ensureLatestAkmInstalled(client as unknown as LogCapableClient)
484
+
485
+ return {
486
+ tool: {
459
487
  akm_search: tool({
460
488
  description: "Search your local stash or the akm registry for scripts, skills, commands, agents, and knowledge. Use source='registry' or akm_registry_search for installable community kits.",
461
489
  args: {
@@ -862,5 +890,6 @@ export const AgentikitPlugin: Plugin = async ({ client }) => ({
862
890
  return runCli(client as unknown as LogCapableClient, args, { toolName: "akm_upgrade" })
863
891
  },
864
892
  }),
865
- },
866
- })
893
+ },
894
+ }
895
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akm-opencode",
3
- "version": "0.0.19",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin for Agentikit - search and show extension assets via the akm CLI.",
6
6
  "keywords": [