opencode-growth 0.1.1 → 0.1.59
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/README.md +60 -30
- package/package.json +3 -3
- package/src/adapter-opencode/curator-runner.mjs +254 -0
- package/src/adapter-opencode/index.mjs +305 -19
- package/src/adapter-opencode/install.mjs +63 -12
- package/src/adapter-opencode/journey-tool.mjs +57 -0
- package/src/adapter-opencode/memory-tool.mjs +57 -5
- package/src/adapter-opencode/provider-tools.mjs +237 -0
- package/src/adapter-opencode/review-runner.mjs +75 -21
- package/src/adapter-opencode/session-search-tool.mjs +66 -0
- package/src/adapter-opencode/skill-tool.mjs +221 -0
- package/src/cli/commands.mjs +74 -1
- package/src/cli/curator-cmd.mjs +147 -0
- package/src/cli/journey-cmd.mjs +61 -0
- package/src/cli/journey-view.mjs +174 -0
- package/src/cli/main.mjs +172 -25
- package/src/cli/memory-cmd.mjs +165 -0
- package/src/cli/session-index-cmd.mjs +74 -0
- package/src/cli/skill-cmd.mjs +192 -0
- package/src/core/approve.mjs +155 -0
- package/src/core/audit.mjs +51 -0
- package/src/core/background-review.mjs +88 -1
- package/src/core/home.mjs +56 -21
- package/src/core/journey.mjs +298 -0
- package/src/core/lock.mjs +6 -0
- package/src/core/memories.mjs +186 -9
- package/src/core/memory-actions.mjs +73 -18
- package/src/core/session-freshness.mjs +201 -0
- package/src/core/session-index.mjs +467 -0
- package/src/core/session-query.mjs +161 -0
- package/src/core/session-source.mjs +202 -0
- package/src/core/session-tool.mjs +181 -0
- package/src/core/skill-actions.mjs +372 -0
- package/src/core/skill-backup.mjs +95 -0
- package/src/core/skill-lifecycle.mjs +265 -0
- package/src/core/skill-usage.mjs +119 -0
- package/src/core/skills.mjs +28 -2
- package/src/core/sqlite-runtime.mjs +35 -0
- package/src/core/write-approval.mjs +13 -9
- package/src/host/rest-client.mjs +70 -0
- package/src/provider/config.mjs +187 -0
- package/src/provider/openviking-rest.mjs +742 -0
- package/src/provider/runtime.mjs +417 -0
- package/src/provider/wiring.mjs +164 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// W5 外部 provider · 配置面(§6.1/§6.2-15)。
|
|
2
|
+
// 三条既定口径:
|
|
3
|
+
// - 凭据只接受**环境变量名**(命令行永不收秘密值),照 Hermes 落 ocg home .env(原子写 0600)
|
|
4
|
+
// - 非秘密配置落 <store>/state/provider.json(原子写;--dry-run 与正式执行共享 validate)
|
|
5
|
+
// - 外部配置不可读 ⇒ 不猜 provider、不覆盖旧配置(读失败原样抛出,写路径不进)
|
|
6
|
+
import fs from "node:fs"
|
|
7
|
+
import os from "node:os"
|
|
8
|
+
import path from "node:path"
|
|
9
|
+
|
|
10
|
+
import { resolveStoreRoot } from "../core/home.mjs"
|
|
11
|
+
|
|
12
|
+
export const PROVIDERS = Object.freeze({
|
|
13
|
+
openviking: Object.freeze({
|
|
14
|
+
label: "openviking(REST,OpenViking 类后端)",
|
|
15
|
+
fields: Object.freeze({
|
|
16
|
+
endpoint: { type: "url", required: true, help: "后端 REST 根地址(https?://…)" },
|
|
17
|
+
account: { type: "string", required: false, default: "default" },
|
|
18
|
+
user: { type: "string", required: false },
|
|
19
|
+
actor: { type: "string", required: false, default: "agent" },
|
|
20
|
+
}),
|
|
21
|
+
}),
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* ③层的**能力面**(S3 四场景共存职责):`auto` 管自动面(起点/查询段召回 + 记忆写镜像),
|
|
26
|
+
* `tools` 管工具面(六件 `viking_*`)。
|
|
27
|
+
*
|
|
28
|
+
* 为什么必须在**同一份配置**里各开各的:官方插件接管 ③ 的自动面、或只有外部 MCP 提供工具时,
|
|
29
|
+
* 「谁负责哪一面」是**用户的显式声明**,不是我们猜出来的(不据包名、不据 MCP 连接推断)。
|
|
30
|
+
* 缺省=既有行为(两面都开);读不到/坏值 ⇒ fail-closed 两面皆关(重复自动处理正是本片要禁的)。
|
|
31
|
+
*/
|
|
32
|
+
export const CAPABILITIES = Object.freeze(["auto", "tools"])
|
|
33
|
+
export const DEFAULT_CAPABILITIES = Object.freeze({ auto: true, tools: true })
|
|
34
|
+
|
|
35
|
+
/** 解析 `capabilities`(file 里的原文)。**不猜**:未知键/非布尔一律报错。 */
|
|
36
|
+
export function parseCapabilities(raw) {
|
|
37
|
+
if (raw === undefined || raw === null) return { ok: true, capabilities: { ...DEFAULT_CAPABILITIES }, error: null }
|
|
38
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
39
|
+
return { ok: false, capabilities: { auto: false, tools: false }, error: "capabilities 必须是对象 {auto,tools}" }
|
|
40
|
+
}
|
|
41
|
+
const out = { ...DEFAULT_CAPABILITIES }
|
|
42
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
43
|
+
if (!CAPABILITIES.includes(k)) {
|
|
44
|
+
return { ok: false, capabilities: { auto: false, tools: false }, error: `capabilities 有未知键 '${k}'(只认 ${CAPABILITIES.join("/")})` }
|
|
45
|
+
}
|
|
46
|
+
if (typeof v !== "boolean") {
|
|
47
|
+
return { ok: false, capabilities: { auto: false, tools: false }, error: `capabilities.${k} 必须是布尔值(读到 ${JSON.stringify(v)})` }
|
|
48
|
+
}
|
|
49
|
+
out[k] = v
|
|
50
|
+
}
|
|
51
|
+
return { ok: true, capabilities: out, error: null }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 两个 provider 配置**是否指向同一个可共享的面**。
|
|
56
|
+
*
|
|
57
|
+
* 判据是四元组:endpoint + account(租户)+ user(命名空间)+ peer。
|
|
58
|
+
* **任何一项缺项一律返回 false** —— 同地址不同租户/peer 是最容易误报可共享的形状,
|
|
59
|
+
* 而 base_url 单独相同根本不构成共享(租户由 key 决定、命名空间由 user 决定)。
|
|
60
|
+
*/
|
|
61
|
+
export function shareable(a, b) {
|
|
62
|
+
const pick = (o, k) => {
|
|
63
|
+
const v = o?.[k]
|
|
64
|
+
return typeof v === "string" && v.trim() ? v.trim() : null
|
|
65
|
+
}
|
|
66
|
+
const pairs = ["endpoint", "account", "user", "peer"].map((k) => [pick(a, k), pick(b, k)])
|
|
67
|
+
if (pairs.some(([x, y]) => !x || !y)) return false
|
|
68
|
+
return pairs.every(([x, y]) => x === y)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* ocg home(=store 根,也是 provider `.env` 所在的那一层)。
|
|
73
|
+
* 走**三入口同一条规则**(`src/core/home.mjs::resolveStoreRoot`):显式没有这一层(provider 不给 store
|
|
74
|
+
* 就是「没配」),于是 `$OCG_STORE`(兼容覆盖)> `$OCG_HOME` > 平台默认 —— 与 CLI/安装器/插件同源,
|
|
75
|
+
* 免得出现「库在 A、凭据在 B」这种两套根。
|
|
76
|
+
*/
|
|
77
|
+
export function homeFor(env = process.env) {
|
|
78
|
+
const r = resolveStoreRoot({ env, homeDir: (() => { try { return os.homedir() || null } catch { return null } })() })
|
|
79
|
+
return r.store ?? path.join(os.homedir(), ".opencode-growth")
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 校验(类型/必填/default)——dry-run 与正式执行同一份。错误点名字段。 */
|
|
83
|
+
export function validate(provider, values) {
|
|
84
|
+
const spec = PROVIDERS[provider]
|
|
85
|
+
if (!spec) return { ok: false, error: `unknown provider '${provider}'`, fields: null }
|
|
86
|
+
const out = {}
|
|
87
|
+
for (const [k, f] of Object.entries(spec.fields)) {
|
|
88
|
+
const v = values[k]
|
|
89
|
+
if (v === undefined || v === "") {
|
|
90
|
+
if (f.required) return { ok: false, error: `missing required field '${k}'`, fields: null }
|
|
91
|
+
if (f.default !== undefined) out[k] = f.default
|
|
92
|
+
continue
|
|
93
|
+
}
|
|
94
|
+
if (f.type === "url") {
|
|
95
|
+
let u
|
|
96
|
+
try { u = new URL(v) } catch { return { ok: false, error: `field '${k}' is not a valid url`, fields: null } }
|
|
97
|
+
if (!["http:", "https:"].includes(u.protocol)) return { ok: false, error: `field '${k}' is not a valid url`, fields: null }
|
|
98
|
+
out[k] = v
|
|
99
|
+
} else if (f.type === "string") {
|
|
100
|
+
out[k] = v
|
|
101
|
+
} else {
|
|
102
|
+
return { ok: false, error: `field '${k}' has unsupported type '${f.type}'`, fields: null }
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
for (const k of Object.keys(values)) {
|
|
106
|
+
if (!(k in spec.fields)) return { ok: false, error: `unknown field '${k}'`, fields: null }
|
|
107
|
+
}
|
|
108
|
+
return { ok: true, error: null, fields: out }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function configPath(store) {
|
|
112
|
+
return path.join(store, "state", "provider.json")
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 读配置。文件损坏/不可读 ⇒ 抛出(fail visible),绝不猜、绝不覆盖。缺文件 = 未配置。 */
|
|
116
|
+
export function loadConfig(store) {
|
|
117
|
+
const p = configPath(store)
|
|
118
|
+
let raw
|
|
119
|
+
try { raw = fs.readFileSync(p, "utf8") } catch { return { active: null, providers: {}, secretEnvs: {} } }
|
|
120
|
+
let d
|
|
121
|
+
try { d = JSON.parse(raw) } catch {
|
|
122
|
+
const e = new Error("provider config is unreadable (corrupt) — refusing to guess or overwrite")
|
|
123
|
+
e.corrupt = true
|
|
124
|
+
throw e
|
|
125
|
+
}
|
|
126
|
+
// `capabilities` 按**原文**交出(不在这里解析):写路径要能原样回写,
|
|
127
|
+
// 「没写」与「显式写了默认值」在配置面上不是同一件事。解析见 parseCapabilities。
|
|
128
|
+
return { active: d.active ?? null, providers: d.providers ?? {}, secretEnvs: d.secretEnvs ?? {}, capabilities: d.capabilities }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function saveConfig(store, cfg) {
|
|
132
|
+
const p = configPath(store)
|
|
133
|
+
fs.mkdirSync(path.dirname(p), { recursive: true })
|
|
134
|
+
const tmp = `${p}.${process.pid}.tmp`
|
|
135
|
+
fs.writeFileSync(tmp, JSON.stringify(cfg, null, 2) + "\n")
|
|
136
|
+
fs.renameSync(tmp, p)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function envPath(home) {
|
|
140
|
+
return path.join(home, ".env")
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** 把环境变量 VAR 的值照 Hermes 方式存进 ocg home .env(原子写 0600);只收变量名。 */
|
|
144
|
+
export function requireEnv(varName) {
|
|
145
|
+
// fail-closed 守卫的唯一实现(setup 路径与 .env 写入共用;判据 = ④,变异 R220)
|
|
146
|
+
const value = process.env[varName]
|
|
147
|
+
if (!value) {
|
|
148
|
+
const e = new Error(`environment variable '${varName}' is not set or empty — refusing`)
|
|
149
|
+
e.code = "ENV_MISSING"
|
|
150
|
+
throw e
|
|
151
|
+
}
|
|
152
|
+
return value
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function saveSecretEnv(home, varName) {
|
|
156
|
+
const value = requireEnv(varName)
|
|
157
|
+
const p = envPath(home)
|
|
158
|
+
fs.mkdirSync(home, { recursive: true })
|
|
159
|
+
let lines = []
|
|
160
|
+
try { lines = fs.readFileSync(p, "utf8").split("\n").filter(Boolean) } catch { /* fresh */ }
|
|
161
|
+
lines = lines.filter((l) => !l.startsWith(`${varName}=`))
|
|
162
|
+
lines.push(`${varName}=${value}`)
|
|
163
|
+
const tmp = `${p}.${process.pid}.tmp`
|
|
164
|
+
fs.writeFileSync(tmp, lines.join("\n") + "\n")
|
|
165
|
+
fs.chmodSync(tmp, 0o600)
|
|
166
|
+
fs.renameSync(tmp, p)
|
|
167
|
+
fs.chmodSync(p, 0o600)
|
|
168
|
+
return value
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** 已存凭据的值集合(用于输出脱敏)。任何面向人的输出都要过一遍。 */
|
|
172
|
+
export function secretValues(home) {
|
|
173
|
+
const vals = []
|
|
174
|
+
try {
|
|
175
|
+
for (const l of fs.readFileSync(envPath(home), "utf8").split("\n")) {
|
|
176
|
+
const i = l.indexOf("=")
|
|
177
|
+
if (i > 0 && l.slice(i + 1)) vals.push(l.slice(i + 1))
|
|
178
|
+
}
|
|
179
|
+
} catch { /* none */ }
|
|
180
|
+
return vals
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function redact(text, secrets) {
|
|
184
|
+
let s = String(text)
|
|
185
|
+
for (const v of secrets) if (v) s = s.split(v).join("«secret»")
|
|
186
|
+
return s
|
|
187
|
+
}
|