mio-agent-runtime 0.3.10 → 0.3.12

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.
@@ -11,6 +11,23 @@ function hermesHome() {
11
11
  return process.env.HERMES_HOME || path.join(os.homedir(), 'AppData', 'Local', 'hermes')
12
12
  }
13
13
 
14
+ function hermesConfigPath() {
15
+ return path.join(hermesHome(), 'config.yaml')
16
+ }
17
+
18
+ function configNeedsRepair() {
19
+ const cfg = hermesConfigPath()
20
+ if (!fs.existsSync(cfg)) return false
21
+ try {
22
+ const src = fs.readFileSync(cfg, 'utf8')
23
+ // Legacy installs stored the env pairs as plain args (--env KEY=VALUE)
24
+ // because --env came after --args; Hermes now stores them under env:.
25
+ return /- MIO_DATA_DIR=/.test(src) || /- MIO_CONTEXT=/.test(src)
26
+ } catch (_) {
27
+ return false
28
+ }
29
+ }
30
+
14
31
  function hermesBin() {
15
32
  if (process.env.HERMES_BIN && fs.existsSync(process.env.HERMES_BIN)) return process.env.HERMES_BIN
16
33
  const home = hermesHome()
@@ -61,7 +78,10 @@ function install({ node, serverScript, home, workspace, project }) {
61
78
  }
62
79
  }
63
80
  if (isInstalled()) {
64
- return { changed: false, message: 'Hermes Mio MCP already installed.', configPath: null }
81
+ if (!configNeedsRepair()) {
82
+ return { changed: false, message: 'Hermes Mio MCP already installed.', configPath: null }
83
+ }
84
+ runHermes(['mcp', 'remove', SERVER_NAME])
65
85
  }
66
86
 
67
87
  const context = JSON.stringify({
@@ -71,11 +91,12 @@ function install({ node, serverScript, home, workspace, project }) {
71
91
  sessionId: 'hermes-session',
72
92
  })
73
93
 
94
+ // Hermes requires --env before --args: --args swallows everything after it.
74
95
  const args = [
75
96
  'mcp', 'add', SERVER_NAME,
76
97
  '--command', node,
77
- '--args', serverScript,
78
98
  '--env', 'MIO_DATA_DIR=' + home, 'MIO_CONTEXT=' + context,
99
+ '--args', serverScript,
79
100
  ]
80
101
  const out = runHermes(args)
81
102
  const installed = isInstalled()
@@ -604,17 +604,37 @@ function findOpencodeBin() {
604
604
  const resolved = path.resolve(c)
605
605
  if (fs.existsSync(resolved)) return resolved
606
606
  }
607
+ // Resolve from PATH so the SQL is never passed through cmd.exe, where
608
+ // '>' in the query is interpreted as output redirection and creates
609
+ // stray files (e.g. "WHERE p.rowid > 0" -> a file named "0").
610
+ try {
611
+ const finder = process.platform === 'win32' ? 'where' : 'which'
612
+ const res = spawnSync(finder, ['opencode'], { encoding: 'utf8', windowsHide: true, timeout: 15000 })
613
+ if (res.status === 0 && res.stdout) {
614
+ const lines = res.stdout
615
+ .split(/\r?\n/)
616
+ .map((s) => s.trim())
617
+ .filter(Boolean)
618
+ const preferred =
619
+ process.platform === 'win32'
620
+ ? lines.filter((p) => /\.(exe|cmd|bat)$/i.test(p))
621
+ : lines
622
+ const first = (preferred.length > 0 ? preferred : lines).find((p) => fs.existsSync(p))
623
+ if (first) return first
624
+ }
625
+ } catch (_) {}
607
626
  return null
608
627
  }
609
628
 
610
629
  function runOpencodeQuery(sql) {
611
630
  const bin = findOpencodeBin()
631
+ // Never shell the SQL through cmd.exe: '>' in the query would be parsed
632
+ // as output redirection, creating files named after the redirect target.
633
+ if (!bin) return null
612
634
  const args = ['db', sql, '--format', 'json']
613
635
  let res
614
636
  try {
615
- res = bin
616
- ? spawnSync(bin, args, { encoding: 'utf8', timeout: 90000, windowsHide: true, maxBuffer: 256 * 1024 * 1024 })
617
- : spawnSync('opencode', args, { encoding: 'utf8', timeout: 90000, shell: true, windowsHide: true, maxBuffer: 256 * 1024 * 1024 })
637
+ res = spawnSync(bin, args, { encoding: 'utf8', timeout: 90000, windowsHide: true, maxBuffer: 256 * 1024 * 1024 })
618
638
  } catch (_) {
619
639
  return null
620
640
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mio-agent-runtime",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "description": "Mio Agent Runtime installer and MCP intelligence layer",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",