opencode-growth 0.1.59 → 0.1.75

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 CHANGED
@@ -9,13 +9,48 @@ review and withdrawal.
9
9
  >
10
10
  > ```bash
11
11
  > npm i -g opencode-growth # provides the `oc-grow` command
12
- > oc-grow install # writes the host plugin file, registers D/skills/
13
- > oc-grow --store ~/.opencode-growth status
14
- > oc-grow --store ~/.opencode-growth doctor # exits 5 when a capability is missing
12
+ > oc-grow install --dry-run # print the plan; writes nothing
13
+ > oc-grow install # plugin file, D/skills/, three command files
14
+ > oc-grow status # what is in effect, what is pending
15
+ > oc-grow doctor # exits 5 when a capability is missing
15
16
  > ```
16
17
  >
17
- > `install` and `uninstall` only add or remove the host plugin file. Nothing inside the store is
18
- > touched — your Markdown stays yours. Node >= 24.
18
+ > First install creates the two resident libraries as **empty** files (`MEMORY.md`, `USER.md`) so
19
+ > you can edit them straight away; later runs never write their content and never recreate a file
20
+ > you deleted. `install`/`uninstall` add or remove only what they registered — the host plugin,
21
+ > the `D/skills/` path and the command files. Your Markdown stays yours. Node >= 24, and no
22
+ > external memory service is required.
23
+
24
+ ## First run, end to end
25
+
26
+ 1. `oc-grow install --dry-run` — the plan names what will be created, filled in and kept; the
27
+ isolated tree is byte-identical afterwards.
28
+ 2. `oc-grow install` — then **restart OpenCode**: host configuration is not hot-reloaded.
29
+ 3. `oc-grow status` — the store path in use, resident entry counts, pending proposals.
30
+ 4. In a session, say one thing worth keeping ("always use pnpm here"); the `memory` tool writes it.
31
+ 5. Open a **different** project and ask about it — memory is global, so it answers there too.
32
+ 6. `oc-grow doctor` — if a capability is missing it exits 5 and names it, rather than reporting a
33
+ false green.
34
+
35
+ History search is optional and off until you bind a source: `oc-grow session-index status` says
36
+ which state it is in (`not-configured`, `source-missing`, `unsupported-schema`,
37
+ `source-unavailable`, a normal zero-hit result, or a degraded answer that carries `as_of`), and
38
+ `oc-grow session-index sync` / `rebuild` bind or repair the source. Memory and skills work whether
39
+ or not it is configured.
40
+
41
+ ### Reinstall and receipt recovery
42
+
43
+ A store has one current registered host configuration root. Reinstalling through a physical
44
+ alias keeps the original registration; changing to another root is refused before any write,
45
+ including in dry-run. Uninstall the old registration before installing a new root.
46
+
47
+ `oc-grow uninstall` uses the default receipt. For a saved receipt, explicitly use
48
+ `oc-grow uninstall --from /absolute/path/to/install-manifest.json` with the corresponding store.
49
+ Recovery accepts ownership version 2 with normalized absolute paths and valid ownership fields;
50
+ it removes only that receipt's original targets whose recorded contents still match. Modified
51
+ or unreadable files and all store data are kept. An invalid explicit receipt is refused, never
52
+ silently replaced by the default receipt. See `docs/RUNBOOK-agent.md` for the narrower moved-store
53
+ case and partial-uninstall checks.
19
54
 
20
55
  ## What it does
21
56
 
@@ -29,10 +64,27 @@ host.
29
64
  full.
30
65
  - **Retrieval over history.** Ask about something said in another project and get the original
31
66
  wording back — Chinese or English, down to two characters.
32
- - **Learns after your turns.** A background review runs between turns and turns your
33
- corrections into proposals, which are consumed at the session boundary.
67
+ - **Learns after your turns.** A background review runs between turns. When it finishes it
68
+ reports what it did as one line in the conversation you were already in — what it wrote, what
69
+ it staged, what it skipped — so nothing is learned behind your back. The report is part of the
70
+ transcript; it does not start another model turn and is never re-read as something you said.
34
71
  - **Safe when nobody is watching.** Unattended, additions apply directly while edits and
35
72
  removals are staged for your approval.
73
+ - **Pinned means pinned.** `oc-grow skill pin <name>` keeps a skill out of archiving at every
74
+ entry point — the lifecycle pass, the curator and the skill tool — and each refusal names the
75
+ skill and the reason. Editing a pinned skill still works; `oc-grow skill unpin <name>` makes
76
+ it archivable again.
77
+ - **The limits you set are the limits used.** `memory_limit` and `user_limit` under `memory` in
78
+ the store's `config.json` (defaults 2200 and 1375 characters) are read by every write path —
79
+ the tool, a batch, an approved proposal, the CLI and `oc-grow status`. Lowering a limit never
80
+ truncates or deletes what is already stored; raising it lets a write that previously failed
81
+ go through, without a reinstall.
82
+ - **Approval is optional, and off by default.** Turn on `memory.write_approval` or
83
+ `skills.write_approval` and create/patch stage a proposal instead of writing: the target file
84
+ stays byte-identical until you run `oc-grow memory pending` and
85
+ `oc-grow memory approve <id> --as <who-you-are>`, then read the result back. Rejecting means
86
+ deleting the proposal; nothing applies on its own. Background edits and removals are staged
87
+ whether or not the gate is on.
36
88
  - **Two stores.** Memory and user profile live in separate files (`MEMORY.md`, `USER.md`), each
37
89
  with its own limits.
38
90
  - **Addressable.** Edits and removals address an entry by a substring of its text; an ambiguous
@@ -51,9 +103,14 @@ host.
51
103
  - It does not touch OpenCode's source, and it does not assume Hermes is present.
52
104
  - It does not push or export memory to other agents or hosts: the store is plain text, and reading it is the other side's business.
53
105
 
54
- ## Not built yet
106
+ ## What exists, and what stays out of scope
55
107
 
56
- A timeline of what has been learned.
108
+ - A journey view of what has been learned exists (`oc-grow journey`, `oc-grow journey list`); it is
109
+ a timeline over recorded events, not a semantic summary of your sessions.
110
+ - Semantic retrieval over a large history is not claimed: history search is keyword-plus-index,
111
+ bound to an optional `session-index` source.
112
+ - No automatic registration in a skill marketplace, and no third-party distribution channel: the
113
+ package is the distribution, and external skill directories are read-only inputs.
57
114
 
58
115
  ## Platforms
59
116
 
@@ -62,10 +119,11 @@ Run and verified on Windows (native), WSL2, macOS (arm64) and Linux.
62
119
  ## Layout
63
120
 
64
121
  ```
65
- src/core/ storage, candidates, writer, audit, lock, budget, threats, retrieval
66
- src/core/snapshot.mjs the frozen per-session block (MEMORY.md / USER.md)
67
- src/core/skills.mjs skill index (always resident) vs. body (on demand)
68
- src/adapter-opencode/ the host plugin: memory tool, review runner, installer
122
+ src/core/ store, memory, skills, review, lifecycle, approval, audit, lock, index
123
+ src/adapter-opencode/ the host plugin: memory, skill and session tools, review + curator
124
+ runners, installer
125
+ src/provider/ optional semantic provider wiring (OpenViking over REST)
126
+ src/host/ the client used to reach a running host
69
127
  src/learn/ headless consume path (corrections -> candidates)
70
128
  src/cli/ `oc-grow` commands and the single JSON envelope
71
129
  test/contracts/ acceptance tests
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-growth",
3
- "version": "0.1.59",
3
+ "version": "0.1.75",
4
4
  "description": "OpenCode growth kit: cross-project memory (memory / capability / preference / fact) with evidence and withdrawal.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -16,7 +16,7 @@
16
16
  import fs from "node:fs"
17
17
  import path from "node:path"
18
18
 
19
- import { createHostReview } from "./review-runner.mjs"
19
+ import { createHostReview, REVIEW_READ_ONLY_TOOLS } from "./review-runner.mjs"
20
20
  import { stampCuratorClock, CLOCK_FILE, applyLifecycleTransitions } from "../core/skill-lifecycle.mjs"
21
21
  import { snapshotSkills } from "../core/skill-backup.mjs"
22
22
  import { skillsDir, SKILL_FILE, readExternalDirs, readCreatedBy } from "../core/skills.mjs"
@@ -26,6 +26,14 @@ import { appendAudit } from "../core/audit.mjs"
26
26
  import { layout } from "../core/paths.mjs"
27
27
 
28
28
  /** 照 Hermes `get_interval_hours()` 的默认(curator.interval_hours=7*24)。 */
29
+ /**
30
+ * 整理 pass 的工具面:只读 + **skill_manage**。
31
+ * 提示词要求「所有落盘都走 skill_manage(入账可回滚)」——若沿用复习面的只读白名单,
32
+ * 唯一落盘通道会被关掉,整理只剩报告(2026-11-20 实测:skill_manage=false)。
33
+ * 原生 `skill` 工具不放行:它绕过 OCG 的所有权/审批/审计。
34
+ */
35
+ export const CURATOR_TOOL_ALLOWLIST = Object.freeze([...REVIEW_READ_ONLY_TOOLS, "skill_manage"])
36
+
29
37
  export const DEFAULT_CURATOR_INTERVAL_HOURS = 168
30
38
 
31
39
  const iso = (d) => (d instanceof Date ? d : new Date(d)).toISOString()
@@ -190,7 +198,10 @@ export function wrapCuratorTrigger({ pipeline, client, root, now = () => new Dat
190
198
  }
191
199
  // 默认:确定性生命周期维护(零宿主零模型),与 `curator run`(无 --consolidate)同一个函数
192
200
  const mechanical = applyLifecycleTransitions({ root, now: now(), origin: "background" })
193
- audit({ mode: "mechanical", sessionId, ok: mechanical.ok, archived: mechanical.archived, error: mechanical.error ?? null })
201
+ audit({ mode: "mechanical", sessionId, ok: mechanical.ok, archived: mechanical.archived,
202
+ // 无人值守通道也要留下「哪些 pinned 被跳过」——否则插件静默运行时这个原因不可见(复核观察 5)
203
+ skipped_pinned: (mechanical.skipped_pinned ?? []).map((x) => x.name),
204
+ error: mechanical.error ?? null })
194
205
  if (typeof onDispatch === "function") onDispatch({ due, skills: null, mode: "mechanical", mechanical })
195
206
  } catch { /* 触发失败不影响复习链 */ }
196
207
  return r
@@ -235,6 +246,8 @@ export async function runCuratorPass({ client, sessionId, root = null, skills =
235
246
  const review = createHostReview({
236
247
  client,
237
248
  sessionId,
249
+ kind: "curator",
250
+ toolsAllow: CURATOR_TOOL_ALLOWLIST,
238
251
  ...(agent !== undefined ? { agent } : {}),
239
252
  onChild: (id) => { childId = id; if (signal?.aborted) abortChild(); if (typeof onChild === "function") onChild(id) },
240
253
  onRestriction,
@@ -23,13 +23,13 @@ import { homedir } from "node:os"
23
23
 
24
24
  import { layout } from "../core/paths.mjs"
25
25
  import { resolveStoreRoot } from "../core/home.mjs"
26
- import { resolveProject } from "../core/identity.mjs"
27
26
  import { frozenBlockFor, BLOCK_MARKER } from "../core/snapshot.mjs"
28
27
  import { bumpSkillUse } from "../core/skill-usage.mjs"
29
28
  import { formationGuidanceBlock, SKILL_FORMATION_FENCE } from "../core/skills.mjs"
30
29
  import { createMemoryStore } from "../core/memories.mjs"
31
30
  import { appendAudit } from "../core/audit.mjs"
32
31
  import { createReviewPipeline } from "./review-runner.mjs"
32
+ import { REVIEW_SURFACE_MARK } from "../core/background-review.mjs"
33
33
  import { wrapCuratorTrigger } from "./curator-runner.mjs"
34
34
  import { registerMemoryTool } from "./memory-tool.mjs"
35
35
  import { registerJourneyTool } from "./journey-tool.mjs"
@@ -71,24 +71,6 @@ export function isExplicitCorrection(text) {
71
71
  /** 家目录取不到就当没有(fail closed,解析会退回「拿不到唯一根」而不是猜一个)。 */
72
72
  const safeHomedir = () => { try { return homedir() || null } catch { return null } }
73
73
 
74
- function appendQueueLine(queuePath, entry) {
75
- fs.mkdirSync(path.dirname(queuePath), { recursive: true })
76
- // Append-only: two corrections are two entries, and a crash mid-append can at worst leave a
77
- // torn last line, which the consumer skips.
78
- fs.appendFileSync(queuePath, JSON.stringify(entry) + "\n")
79
- }
80
-
81
- function resolveProjectId(storeDir, directory) {
82
- try {
83
- const L = layout(storeDir)
84
- fs.mkdirSync(L.state, { recursive: true })
85
- const project = resolveProject(directory, L.projects)
86
- return project?.projectId ?? null
87
- } catch {
88
- return null
89
- }
90
- }
91
-
92
74
  /**
93
75
  * Build the hooks. `store` may be null — that is the "not configured" case, not an error.
94
76
  * Exported separately from the plugin factory so the behaviour above is testable without an
@@ -212,7 +194,7 @@ export function createAdapter({
212
194
  runtime = null,
213
195
  providerToolDefs = null,
214
196
  providerScenario = null,
215
- // ③层能力面(S3):`auto`=自动面(召回注入/写镜像),`tools`=工具面(六件 viking_*)。
197
+ // ③层能力面(S3):`auto`=自动面(召回注入/写镜像),`tools`=工具面(五件可用 viking_*)。
216
198
  // 缺省(null)=既有行为:两面都开。显式关哪一面只关哪一面 —— 让官方插件接管自动面、
217
199
  // 或把工具面交给外部 MCP,而不必连 ①② 与本地技能一起关掉。
218
200
  providerCapabilities = null,
@@ -234,12 +216,6 @@ export function createAdapter({
234
216
  interactive: binding?.interactive ?? null,
235
217
  queuePath: queuePath ?? null,
236
218
  })
237
- const resolvedQueue = queuePath
238
- ?? process.env.OCG_QUEUE
239
- ?? (storeDir ? path.join(storeDir, "state", "learn-queue.jsonl") : null)
240
-
241
- // One API call per session, not one per fire (the hook fires three times per run).
242
- const sessionDirs = new Map()
243
219
  // ③层查询段要「当前 query」,但 `experimental.chat.system.transform` 的 input **只有**
244
220
  // {sessionID, model}(1.18.30 实测;见本文件注入块的实测注记)⇒ 只能由 `chat.message`
245
221
  // 在每轮用户消息提交时供给。逐会话存最近一轮文本(照 H「检索只对当前 query」,:1553)。
@@ -252,8 +228,11 @@ export function createAdapter({
252
228
  while (latestTurn.size > TURN_CACHE_MAX) latestTurn.delete(latestTurn.keys().next().value)
253
229
  }
254
230
  /** 用户消息的可见文本(parts 里 type==="text" 的拼起来;拿不到就是空串,不猜)。 */
231
+ // 后台复习浮出的那一行也是 user 消息,但它不是用户说的话(ignored + metadata 标记)⇒
232
+ // 不能成为召回查询段,也不能顶掉上一轮的真实文本。
255
233
  const textFromParts = (parts) => (Array.isArray(parts) ? parts : [])
256
234
  .filter((part) => part && part.type === "text" && typeof part.text === "string")
235
+ .filter((part) => part.ignored !== true && part?.metadata?.ocg !== REVIEW_SURFACE_MARK)
257
236
  .map((part) => part.text)
258
237
  .join("\n")
259
238
  .trim()
@@ -274,23 +253,6 @@ export function createAdapter({
274
253
  onSkillUse: storeDir ? (n) => { bumpSkillUse(storeDir, n) } : null,
275
254
  })
276
255
 
277
- async function directoryForSession(sessionId) {
278
- if (!client?.session?.get || !sessionId) return null
279
- if (sessionDirs.has(sessionId)) return sessionDirs.get(sessionId)
280
- let dir = null
281
- try {
282
- const res = await client.session.get({ path: { id: sessionId } })
283
- const found = res?.data?.directory
284
- if (typeof found === "string" && found.trim()) dir = found
285
- } catch {
286
- // **不回退**(审计 A20):拿不到会话自己的目录时,答案只能是 null。
287
- // 原来这里回退到工厂的 directory —— 而工厂可能属于**另一个**实例/目录,
288
- // 于是 A 项目的记录会被算进 B 会话的账。宁可不知道,也不要猜错。
289
- }
290
- sessionDirs.set(sessionId, dir)
291
- return dir
292
- }
293
-
294
256
  return {
295
257
  /** C① 实例自证:这个适配器绑在哪个 D / 哪个目录 / 值哪来的(多实例并存时可核对)。 */
296
258
  binding: () => bindInfo,
@@ -376,33 +338,9 @@ export function createAdapter({
376
338
 
377
339
  event: async ({ event } = {}) => {
378
340
  if (idleWire) await idleWire({ event })
379
- try {
380
- const text = event?.properties?.text ?? event?.properties?.message?.text ?? null
381
- if (!text || !isExplicitCorrection(text)) return
382
- if (!resolvedQueue) return
383
- const sessionId = event?.properties?.sessionID ?? event?.sessionID ?? null
384
- // The message id, so the eventual candidate can be traced back to the utterance that
385
- // prompted it. Read from every shape OpenCode was seen to use rather than one guess; a
386
- // missing id is recorded as null, never invented (audit A16).
387
- const messageId =
388
- event?.properties?.messageID ??
389
- event?.properties?.message?.id ??
390
- event?.properties?.part?.messageID ??
391
- null
392
- appendQueueLine(resolvedQueue, {
393
- state: "pending",
394
- capturedAt: new Date().toISOString(),
395
- sessionId,
396
- messageId,
397
- projectId: storeDir ? resolveProjectId(storeDir, await directoryForSession(sessionId)) : null,
398
- excerpt: String(text).slice(0, 400),
399
- origin: "opencode-capture",
400
- })
401
- // Deliberately nothing else: no spawn, no candidate, no publish. The scheduler owns
402
- // what happens next, because an in-session child would be killed by the parent's exit.
403
- } catch {
404
- // Same rule as above: capture failing must not break the host.
405
- }
341
+ // 纠正捕获**已退役**(欠账收口 · S1):日常学习由回合后的后台复习承担,
342
+ // 旧队列不再接收新行(不再制造无人消费的 state:"pending")。
343
+ // 历史队列、游标、候选、audit 与旧读取器全部保留;升级不重放、不移动游标。
406
344
  },
407
345
  }
408
346
  }
@@ -444,7 +382,7 @@ export const OcgGrowth = async ({ directory, client, z, tool } = {}) => {
444
382
  }
445
383
  } catch { runtime = null }
446
384
  }
447
- // ③层工具面(六件 viking_*,形制逐字照 H `_TOOL_SCHEMAS`):**只在 provider 在场、
385
+ // ③层工具面(五件可用 viking_*;`viking_add_resource` 未实现不注册):**只在 provider 在场、
448
386
  // 且工具面归我们时**注册 ——provider 缺席/工具面外让时,宿主看到的工具面与从前逐字相同。
449
387
  let providerToolDefs = null
450
388
  if (runtime && providerCapabilities?.tools !== false && z?.string) {