shmem-opencode 0.3.30 → 0.3.31

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 (2) hide show
  1. package/index.ts +21 -6
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -10,16 +10,31 @@ const ID = "shmem-opencode"
10
10
  const RESUBSCRIBE_MS = 1_000
11
11
 
12
12
  // shmemRoot is the data root `shmem install` wrote into shmem's MCP entry
13
- // when it was a custom one. OpenCode runs this plugin with its own
14
- // environment, which lacks a SHMEM_ROOT set only for install, so the hooks
15
- // take the root from the config instead. It is passed as an environment
16
- // variable rather than `--root`, which older shmem binaries reject.
13
+ // when it was a custom one: `--root DIR` in its command, or, from older
14
+ // installs, SHMEM_ROOT in its environment. OpenCode runs this plugin with
15
+ // its own environment, which lacks a SHMEM_ROOT set only for install, so
16
+ // the hooks take the root from the config instead. It is passed as an
17
+ // environment variable rather than `--root`, which older shmem binaries
18
+ // reject.
17
19
  let shmemRoot: string | undefined
18
20
 
19
- function rootFrom(entry: { type?: string; environment?: Record<string, string> } | undefined) {
21
+ type MCPEntry = { type?: string; command?: string[]; environment?: Record<string, string> }
22
+
23
+ function rootFrom(entry: MCPEntry | undefined) {
20
24
  if (entry?.type === "local") {
21
- shmemRoot = entry.environment?.SHMEM_ROOT || undefined
25
+ shmemRoot = rootArg(entry.command ?? []) || entry.environment?.SHMEM_ROOT || undefined
26
+ }
27
+ }
28
+
29
+ // rootArg is the value of --root (or --root=) in an MCP command line.
30
+ function rootArg(command: string[]): string | undefined {
31
+ for (let i = 1; i < command.length; i++) {
32
+ const a = command[i]
33
+ if (a === "--") return undefined
34
+ if (a.startsWith("--root=")) return a.slice("--root=".length)
35
+ if (a === "--root" && i + 1 < command.length) return command[i + 1]
22
36
  }
37
+ return undefined
23
38
  }
24
39
 
25
40
  function shmemHook(subcommand: string, payload: Record<string, string>): void {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shmem-opencode",
3
- "version": "0.3.30",
3
+ "version": "0.3.31",
4
4
  "description": "shmem memory hooks for OpenCode",
5
5
  "main": "index.ts",
6
6
  "scripts": {