mio-agent-runtime 0.1.0 → 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.
@@ -1,14 +1,75 @@
1
1
  'use strict'
2
2
 
3
+ const fs = require('fs')
4
+ const path = require('path')
5
+ const os = require('os')
6
+
7
+ function configPath() {
8
+ return path.join(os.homedir(), '.config', 'opencode', 'opencode.json')
9
+ }
10
+
11
+ function readConfig() {
12
+ const target = configPath()
13
+ if (!fs.existsSync(target)) return null
14
+ try {
15
+ return JSON.parse(fs.readFileSync(target, 'utf8'))
16
+ } catch (_) {
17
+ return null
18
+ }
19
+ }
20
+
3
21
  function isInstalled() {
4
- return false
22
+ const config = readConfig()
23
+ return Boolean(config && config.mcp && config.mcp['mio-intelligence'])
5
24
  }
6
25
 
7
- function install() {
26
+ function install({ node, serverScript, home, workspace }) {
27
+ const target = configPath()
28
+ if (isInstalled()) {
29
+ return {
30
+ changed: false,
31
+ configPath: target,
32
+ message: 'OpenCode Mio MCP already installed.',
33
+ }
34
+ }
35
+
36
+ const backup = `${target}.bak-mio-${Date.now()}`
37
+ if (fs.existsSync(target)) {
38
+ fs.copyFileSync(target, backup)
39
+ }
40
+
41
+ const config = readConfig() || {}
42
+ const existingMcp = config.mcp && typeof config.mcp === 'object' ? config.mcp : {}
43
+ const context = JSON.stringify({
44
+ agentId: 'opencode',
45
+ workspace: workspace || process.cwd(),
46
+ sessionId: 'opencode-session',
47
+ })
48
+ const next = {
49
+ ...config,
50
+ mcp: {
51
+ ...existingMcp,
52
+ 'mio-intelligence': {
53
+ enabled: true,
54
+ type: 'local',
55
+ command: [node, serverScript],
56
+ environment: {
57
+ MIO_DATA_DIR: home,
58
+ MIO_CONTEXT: context,
59
+ },
60
+ },
61
+ },
62
+ }
63
+
64
+ fs.mkdirSync(path.dirname(target), { recursive: true })
65
+ fs.writeFileSync(target, `${JSON.stringify(next, null, 2)}\n`, 'utf8')
66
+
8
67
  return {
9
- changed: false,
10
- message: 'OpenCode adapter is not implemented yet.',
68
+ changed: true,
69
+ configPath: target,
70
+ backup,
71
+ message: 'OpenCode Mio MCP installed. Restart OpenCode to load it.',
11
72
  }
12
73
  }
13
74
 
14
- module.exports = { isInstalled, install }
75
+ module.exports = { configPath, isInstalled, install }
@@ -1,14 +1,90 @@
1
1
  'use strict'
2
2
 
3
+ const fs = require('fs')
4
+ const path = require('path')
5
+ const os = require('os')
6
+
7
+ function configPath() {
8
+ return path.join(os.homedir(), '.workbuddy', 'mcp.json')
9
+ }
10
+
11
+ function legacyConfigPath() {
12
+ return path.join(os.homedir(), '.workbuddy', '.mcp.json')
13
+ }
14
+
15
+ function readJson(file) {
16
+ if (!fs.existsSync(file)) return null
17
+ try {
18
+ return JSON.parse(fs.readFileSync(file, 'utf8'))
19
+ } catch (_) {
20
+ return null
21
+ }
22
+ }
23
+
3
24
  function isInstalled() {
4
- return false
25
+ const config = readJson(configPath())
26
+ return Boolean(config && config.mcpServers && config.mcpServers['mio-intelligence'])
5
27
  }
6
28
 
7
- function install() {
29
+ function install({ node, serverScript, home, workspace }) {
30
+ const target = configPath()
31
+ if (isInstalled()) {
32
+ return {
33
+ changed: false,
34
+ configPath: target,
35
+ message: 'WorkBuddy Mio MCP already installed.',
36
+ }
37
+ }
38
+
39
+ const backup = `${target}.bak-mio-${Date.now()}`
40
+ if (fs.existsSync(target)) {
41
+ fs.copyFileSync(target, backup)
42
+ }
43
+
44
+ const canonical = readJson(target) || {}
45
+ const legacy = readJson(legacyConfigPath()) || {}
46
+ const canonicalServers =
47
+ canonical.mcpServers && typeof canonical.mcpServers === 'object' ? canonical.mcpServers : {}
48
+ const legacyServers =
49
+ legacy.mcpServers && typeof legacy.mcpServers === 'object' ? legacy.mcpServers : {}
50
+
51
+ const config = {
52
+ ...legacy,
53
+ ...canonical,
54
+ mcpServers: {
55
+ ...legacyServers,
56
+ ...canonicalServers,
57
+ },
58
+ }
59
+
60
+ const context = JSON.stringify({
61
+ agentId: 'workbuddy',
62
+ workspace: workspace || process.cwd(),
63
+ sessionId: 'workbuddy-session',
64
+ })
65
+
66
+ config.mcpServers = {
67
+ ...config.mcpServers,
68
+ 'mio-intelligence': {
69
+ type: 'stdio',
70
+ command: node,
71
+ args: [serverScript],
72
+ env: {
73
+ MIO_DATA_DIR: home,
74
+ MIO_CONTEXT: context,
75
+ },
76
+ },
77
+ }
78
+
79
+ fs.mkdirSync(path.dirname(target), { recursive: true })
80
+ fs.writeFileSync(target, `${JSON.stringify(config, null, 2)}\n`, 'utf8')
81
+
8
82
  return {
9
- changed: false,
10
- message: 'WorkBuddy adapter is not implemented yet.',
83
+ changed: true,
84
+ configPath: target,
85
+ backup,
86
+ message: 'WorkBuddy Mio MCP installed. Restart WorkBuddy to load it.',
11
87
  }
12
88
  }
13
89
 
14
- module.exports = { isInstalled, install }
90
+ module.exports = { configPath, isInstalled, install }
package/bin/mio.js CHANGED
@@ -53,15 +53,20 @@ function initCommand() {
53
53
 
54
54
  function statusCommand(useJson) {
55
55
  const config = readConfig()
56
- const codex = adapters.codex
57
- const installed = codex.isInstalled()
56
+ const installed = {
57
+ codex: adapters.codex.isInstalled(),
58
+ opencode: adapters.opencode.isInstalled(),
59
+ workbuddy: adapters.workbuddy.isInstalled(),
60
+ }
58
61
  const payload = {
59
62
  version: config.version,
60
63
  home: MIO_HOME,
61
64
  serverScript: SERVER_SCRIPT,
62
65
  serverScriptExists: fs.existsSync(SERVER_SCRIPT),
63
66
  agents: config.agents || {},
64
- codexInstalled: installed,
67
+ codexInstalled: installed.codex,
68
+ opencodeInstalled: installed.opencode,
69
+ workbuddyInstalled: installed.workbuddy,
65
70
  }
66
71
  if (useJson) {
67
72
  jsonOrText(payload, true)
@@ -69,7 +74,9 @@ function statusCommand(useJson) {
69
74
  }
70
75
  console.log(`MIO_HOME: ${MIO_HOME}`)
71
76
  console.log(`MCP Server: ${SERVER_SCRIPT}`)
72
- console.log(`Codex MCP: ${installed ? 'installed' : 'not installed'}`)
77
+ console.log(`Codex MCP: ${installed.codex ? 'installed' : 'not installed'}`)
78
+ console.log(`OpenCode MCP: ${installed.opencode ? 'installed' : 'not installed'}`)
79
+ console.log(`WorkBuddy MCP: ${installed.workbuddy ? 'installed' : 'not installed'}`)
73
80
  }
74
81
 
75
82
  function agentsCommand(useJson) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mio-agent-runtime",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Mio Agent Runtime installer and MCP intelligence layer",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -20,4 +20,4 @@
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  }
23
- }
23
+ }