mio-agent-runtime 0.3.11 → 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.
- package/observe/observer.js +23 -3
- package/package.json +1 -1
package/observe/observer.js
CHANGED
|
@@ -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
|
}
|