openviking-opencode 0.2.0 → 0.2.2

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.mjs +20 -22
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -15,18 +15,9 @@ async function run(cmd, opts = {}) {
15
15
  return execAsync(cmd, { timeout: 10000, ...opts })
16
16
  }
17
17
 
18
- async function isInstalled() {
19
- try {
20
- await run("openviking --version")
21
- return true
22
- } catch {
23
- return false
24
- }
25
- }
26
-
27
18
  async function isHealthy() {
28
19
  try {
29
- await run("openviking health")
20
+ await run("openviking health", { timeout: 3000 })
30
21
  return true
31
22
  } catch {
32
23
  return false
@@ -95,25 +86,29 @@ async function init(client) {
95
86
  body: { title: "OpenViking", message, variant, duration: 8000 },
96
87
  }).catch(() => {})
97
88
 
98
- // 1. openviking 没装
99
- if (!(await isInstalled())) {
89
+ // 服务已在跑,直接返回
90
+ if (await isHealthy()) return true
91
+
92
+ // 没跑,先看是哪种情况
93
+ try {
94
+ await run("command -v openviking", { timeout: 2000 })
95
+ } catch {
96
+ // command not found → 没装
100
97
  await toast("openviking 未安装,请运行: pip install openviking", "error")
101
98
  return false
102
99
  }
103
100
 
104
- // 2. ov.conf 不存在(装了但没配置)
101
+ // 装了但没有配置文件 无法启动
105
102
  if (!existsSync(OV_CONF)) {
106
103
  await toast("未找到 ~/.openviking/ov.conf,请先配置 API keys 后再启动服务", "warning")
107
104
  return false
108
105
  }
109
106
 
110
- // 3. 服务没跑 → 静默自动启动
111
- if (!(await isHealthy())) {
112
- const started = await startServer()
113
- if (!started) {
114
- await toast("openviking 服务启动失败,查看日志: /tmp/openviking.log", "error")
115
- return false
116
- }
107
+ // 装了有配置,服务没跑 → 静默自动启动
108
+ const started = await startServer()
109
+ if (!started) {
110
+ await toast("openviking 服务启动失败,查看日志: /tmp/openviking.log", "error")
111
+ return false
117
112
  }
118
113
 
119
114
  return true
@@ -127,8 +122,11 @@ async function init(client) {
127
122
  export async function OpenVikingPlugin({ client }) {
128
123
  installSkill()
129
124
 
130
- const ready = await init(client)
131
- if (ready) await loadRepos()
125
+ // 后台初始化,不阻塞 opencode 启动
126
+ Promise.resolve().then(async () => {
127
+ const ready = await init(client)
128
+ if (ready) await loadRepos()
129
+ })
132
130
 
133
131
  return {
134
132
  "experimental.chat.system.transform": (_input, output) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openviking-opencode",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "OpenCode plugin for OpenViking — injects indexed repo context into the AI assistant and auto-installs the openviking skill",
5
5
  "type": "module",
6
6
  "main": "index.mjs",