opencode-growth 0.1.2 → 0.1.74
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 +72 -13
- package/package.json +1 -1
- package/src/adapter-opencode/curator-runner.mjs +257 -0
- package/src/adapter-opencode/index.mjs +309 -19
- package/src/adapter-opencode/install.mjs +329 -52
- 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 +180 -37
- package/src/adapter-opencode/session-search-tool.mjs +66 -0
- package/src/adapter-opencode/skill-tool.mjs +221 -0
- package/src/cli/commands.mjs +98 -5
- package/src/cli/curator-cmd.mjs +149 -0
- package/src/cli/journey-cmd.mjs +61 -0
- package/src/cli/journey-view.mjs +174 -0
- package/src/cli/main.mjs +173 -26
- package/src/cli/memory-cmd.mjs +165 -0
- package/src/cli/session-index-cmd.mjs +87 -0
- package/src/cli/skill-cmd.mjs +194 -0
- package/src/core/approve.mjs +295 -0
- package/src/core/audit.mjs +51 -0
- package/src/core/background-review.mjs +114 -2
- 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 +215 -10
- package/src/core/memory-actions.mjs +73 -18
- package/src/core/paths.mjs +0 -1
- package/src/core/session-freshness.mjs +201 -0
- package/src/core/session-index.mjs +508 -0
- package/src/core/session-query.mjs +161 -0
- package/src/core/session-source.mjs +209 -0
- package/src/core/session-tool.mjs +189 -0
- package/src/core/skill-actions.mjs +391 -0
- package/src/core/skill-backup.mjs +95 -0
- package/src/core/skill-lifecycle.mjs +277 -0
- package/src/core/skill-usage.mjs +119 -0
- package/src/core/skills.mjs +30 -3
- 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/index.mjs +0 -1
- 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
- package/src/core/budget.mjs +0 -64
- package/src/core/retrieve.mjs +0 -127
package/src/core/retrieve.mjs
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// 检索层:把常驻/会话原文按需召回,**返回逐字原文**(不摘要、不重排)。
|
|
2
|
-
//
|
|
3
|
-
// 对齐依据(读 Hermes 源码得到,非猜测):
|
|
4
|
-
// · `hermes_state_common.py:720` 建 `messages_fts USING fts5(...)`;`:840` 另建 `... tokenize='trigram'`
|
|
5
|
-
// · `hermes_state_fts.py:32-37`:**trigram 每个查询词要 ≥3 字符 ⇒ 中文 1–2 字查不到**(CJK 上 session_search 的主要失效面),
|
|
6
|
-
// 所以 Hermes 用自带的可加载 tokenizer `cjk_unicode61`(`native/fts5_cjk/`,约 250 行)——
|
|
7
|
-
// 把**最长的 CJK 连续串重发成重叠字符 bigram**(Lucene CJKAnalyzer 语义),其余交给 unicode61;
|
|
8
|
-
// FTS5 的短语语义把"连续 bigram"变成**精确子串匹配**(下到 2 字)。
|
|
9
|
-
// · `hermes_state_fts.py:112` 明确是**best-effort 加载**:加载不了就退回 trigram(能力缺失要可见,不能假装)。
|
|
10
|
-
//
|
|
11
|
-
// 我们的等价做法:**不引入编译型 tokenizer**(插件里装不了、也不该让宿主去编译),
|
|
12
|
-
// 改成在 **JS 侧做同一套 bigram 变换**,写进一个独立的 `grams` 列,FTS5 用自带的 `unicode61`。
|
|
13
|
-
// 语义与 Hermes 对齐:≥2 字的 CJK 查询走 bigram 精确子串;**1 字** CJK 用 bigram 表达不出来(Hermes 同病),
|
|
14
|
-
// 故显式走子串回退并**如实标注**(见 `search()` 返回行里的 `matchedBy`),不假装是索引命中。
|
|
15
|
-
import fs from "node:fs"
|
|
16
|
-
import path from "node:path"
|
|
17
|
-
|
|
18
|
-
const CJK = /[\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\u3040-\u30ff\uac00-\ud7af]/
|
|
19
|
-
|
|
20
|
-
/** 打开本地 SQLite:宿主是 Bun(`bun:sqlite`),测试跑 Node(`node:sqlite`)。找不到就明确失败。 */
|
|
21
|
-
async function openDb(file) {
|
|
22
|
-
for (const spec of ["bun:sqlite", "node:sqlite"]) {
|
|
23
|
-
try {
|
|
24
|
-
const mod = await import(spec)
|
|
25
|
-
const C = mod.DatabaseSync ?? mod.Database ?? mod.default?.Database ?? mod.default
|
|
26
|
-
if (typeof C === "function") return new C(file)
|
|
27
|
-
} catch { /* 换下一个运行时 */ }
|
|
28
|
-
}
|
|
29
|
-
throw new Error("找不到可用的本地 SQLite(试过 bun:sqlite 与 node:sqlite)")
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** CJK 连续串 ⇒ 重叠 bigram;其余(拉丁词、数字)原样保留。 */
|
|
33
|
-
export function bigrams(text) {
|
|
34
|
-
const out = []
|
|
35
|
-
const runs = String(text ?? "").match(/\S+/g) ?? []
|
|
36
|
-
for (const tok of runs) {
|
|
37
|
-
if (!CJK.test(tok)) { out.push(tok.toLowerCase()); continue }
|
|
38
|
-
// 以 CJK 为单位切段:CJK 段做重叠 bigram,非 CJK 段原样
|
|
39
|
-
let buf = ""
|
|
40
|
-
const flush = () => { if (buf) { out.push(buf.toLowerCase()); buf = "" } }
|
|
41
|
-
const chars = [...tok]
|
|
42
|
-
for (const ch of chars) {
|
|
43
|
-
if (CJK.test(ch)) buf += ch
|
|
44
|
-
else { flush() /* 非 CJK 片段先落 */ }
|
|
45
|
-
}
|
|
46
|
-
flush()
|
|
47
|
-
// 单独对整串做重叠 bigram(混合串也这么做,长度 ≥2 才有 bigram)
|
|
48
|
-
const cjkOnly = chars.filter((c) => CJK.test(c))
|
|
49
|
-
for (let i = 0; i + 1 < cjkOnly.length; i += 1) out.push(cjkOnly[i] + cjkOnly[i + 1])
|
|
50
|
-
}
|
|
51
|
-
return [...new Set(out)]
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** 查询变换:与写入同一套;返回 { match, fallback }。 */
|
|
55
|
-
export function queryPlan(query) {
|
|
56
|
-
const q = String(query ?? "").trim()
|
|
57
|
-
const cjkChars = [...q].filter((c) => CJK.test(c))
|
|
58
|
-
// 1 个 CJK 字:bigram 表达不出来 ⇒ 子串回退(Hermes 的 trigram/bigram 同样下不到 1 字)
|
|
59
|
-
if (cjkChars.length === 1 && q.length === 1) return { match: null, fallback: q }
|
|
60
|
-
const grams = bigrams(q)
|
|
61
|
-
if (!grams.length) return { match: null, fallback: q }
|
|
62
|
-
// 用短语(引号)表达"连续"⇒ 精确子串语义(与 Hermes 的 FTS5 短语语义一致)
|
|
63
|
-
return { match: grams.map((g) => `"${g.replace(/"/g, '""')}"`).join(" "), fallback: q }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function createRetriever({ root } = {}) {
|
|
67
|
-
if (!root) throw new Error("createRetriever 需要 root(D 目录)")
|
|
68
|
-
const dir = path.join(root, "index")
|
|
69
|
-
fs.mkdirSync(dir, { recursive: true })
|
|
70
|
-
const db = await openDb(path.join(dir, "retrieve.db"))
|
|
71
|
-
|
|
72
|
-
db.exec(`
|
|
73
|
-
CREATE TABLE IF NOT EXISTS docs (
|
|
74
|
-
id TEXT PRIMARY KEY,
|
|
75
|
-
text TEXT NOT NULL,
|
|
76
|
-
source TEXT,
|
|
77
|
-
indexed_at TEXT NOT NULL
|
|
78
|
-
);
|
|
79
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS docs_fts USING fts5(grams, id UNINDEXED, tokenize='unicode61');
|
|
80
|
-
`)
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
/** 建索引:只存原文(text 逐字保留)+ 由原文派生的 bigram 列。 */
|
|
84
|
-
async index({ id, text, source = null } = {}) {
|
|
85
|
-
if (!id || typeof text !== "string") throw new Error("index 需要 { id, text }")
|
|
86
|
-
const grams = bigrams(text).join(" ")
|
|
87
|
-
db.exec("BEGIN")
|
|
88
|
-
try {
|
|
89
|
-
db.prepare("INSERT INTO docs(id, text, source, indexed_at) VALUES(?,?,?,datetime('now')) " +
|
|
90
|
-
"ON CONFLICT(id) DO UPDATE SET text=excluded.text, source=excluded.source, indexed_at=excluded.indexed_at")
|
|
91
|
-
.run(String(id), text, source)
|
|
92
|
-
db.prepare("DELETE FROM docs_fts WHERE id = ?").run(String(id))
|
|
93
|
-
db.prepare("INSERT INTO docs_fts(grams, id) VALUES(?,?)").run(grams, String(id))
|
|
94
|
-
db.exec("COMMIT")
|
|
95
|
-
} catch (e) { db.exec("ROLLBACK"); throw e }
|
|
96
|
-
return { id: String(id), grams: grams ? grams.split(" ").length : 0 }
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
async remove({ id } = {}) {
|
|
100
|
-
db.prepare("DELETE FROM docs_fts WHERE id = ?").run(String(id))
|
|
101
|
-
return { removed: db.prepare("DELETE FROM docs WHERE id = ?").run(String(id)).changes }
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
/** 检索:命中返回**原文**(`text` 逐字来自 docs.text)。 */
|
|
105
|
-
async search({ query, limit = 5 } = {}) {
|
|
106
|
-
const plan = queryPlan(query)
|
|
107
|
-
const rows = []
|
|
108
|
-
if (plan.match) {
|
|
109
|
-
try {
|
|
110
|
-
const stmt = db.prepare(
|
|
111
|
-
"SELECT d.id, d.text, d.source FROM docs_fts f JOIN docs d ON d.id = f.id " +
|
|
112
|
-
"WHERE docs_fts MATCH ? ORDER BY rank LIMIT ?")
|
|
113
|
-
for (const r of stmt.all(plan.match, Number(limit))) rows.push({ ...r, matchedBy: "fts-bigram" })
|
|
114
|
-
} catch { /* 查询语法异常 ⇒ 落到子串回退,不假装命中 */ }
|
|
115
|
-
}
|
|
116
|
-
if (!rows.length && plan.fallback) {
|
|
117
|
-
const stmt = db.prepare(
|
|
118
|
-
"SELECT id, text, source FROM docs WHERE instr(lower(text), lower(?)) > 0 LIMIT ?")
|
|
119
|
-
for (const r of stmt.all(plan.fallback, Number(limit)))
|
|
120
|
-
rows.push({ ...r, matchedBy: "substring-fallback" })
|
|
121
|
-
}
|
|
122
|
-
return rows
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
async close() { db.close() },
|
|
126
|
-
}
|
|
127
|
-
}
|