echoes-vault-opencode 1.2.3 → 2.0.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "echoes-vault-opencode",
3
- "version": "1.2.3",
4
- "description": "EchoesVault persistent memory plugin for OpenCode. Obsidian-style knowledge base with daily logs, encyclopedia pages, and session resumption.",
3
+ "version": "2.0.1",
4
+ "description": "OpenCode adapter for the agent-neutral EchoesVault Protocol and repository-local Markdown memory runtime.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
7
7
  "exports": {
@@ -16,9 +16,17 @@
16
16
  },
17
17
  "files": [
18
18
  "index.ts",
19
+ "runtime.ts",
19
20
  "tui.tsx",
20
- "prompts/"
21
+ "prompts/commands/",
22
+ "scripts/echoes_vault.py",
23
+ "EchoesProtocol.md"
21
24
  ],
25
+ "scripts": {
26
+ "typecheck": "tsc --noEmit",
27
+ "test": "npm run typecheck && node --test tests/*.test.ts",
28
+ "pack:check": "npm pack --dry-run"
29
+ },
22
30
  "keywords": [
23
31
  "opencode",
24
32
  "opencode-plugin",
@@ -29,14 +37,17 @@
29
37
  ],
30
38
  "license": "MIT",
31
39
  "dependencies": {
32
- "@opencode-ai/plugin": ">=1.16.0",
33
- "@opentui/solid": ">=0.4.3",
34
- "solid-js": ">=1.9.0"
40
+ "@opencode-ai/plugin": ">=1.16.0 <2",
41
+ "@opentui/solid": ">=0.4.3 <1",
42
+ "solid-js": ">=1.9.0 <2"
35
43
  },
36
44
  "devDependencies": {
37
45
  "@types/node": "^22.0.0",
38
46
  "typescript": "^5.8.0"
39
47
  },
48
+ "overrides": {
49
+ "toml": "^4.2.0"
50
+ },
40
51
  "repository": {
41
52
  "type": "git",
42
53
  "url": "https://github.com/psinetron/echoes-vault-opencode.git"
@@ -1,22 +1,15 @@
1
1
  ---
2
- description: End the session save memory to EchoesVault via tool commit_memory_to_echoes_vault
2
+ description: Explicitly finalize the session into EchoesVault
3
3
  agent: build
4
4
  ---
5
5
 
6
- # SYSTEM MESSAGE: Session Distillation (Distill & Save)
7
- Our current session is coming to an end. Your task is to crystallize the knowledge we've gained today and commit it to EchoesVault.
6
+ The user explicitly authorized final session saving.
8
7
 
9
- This command is the user's explicit approval to finalize the session. Never invoke the final-memory tool outside this command, including after an ordinary task completion.
8
+ Distill the session into dense final outcomes, verified decisions, unresolved blockers, and next
9
+ steps—not a transcript. Prepare only durable knowledge pages that add or materially revise reusable
10
+ project knowledge. Every page must contain `type`, `stack`, `status`, and a one-line `summary` of at
11
+ most 160 characters.
10
12
 
11
- Adhere to the principle of technical density: we do not need a transcript of our chat. We need dry architectural facts, bug fixes, applied configurations, and explicit decisions. Remember to use `> [!warning] DEPRECATED` tags if we rewrote legacy logic today.
12
-
13
- ## ACTION
14
- You MUST invoke the system skill `commit_memory_to_echoes_vault`.
15
-
16
- Prepare the following payload for the skill:
17
- * **`dailySummary`**: A dense technical summary to WRAP UP the session. Acknowledge that intermediate notes may already exist in today's log. Focus this summary strictly on final outcomes, unresolved blockers, and clear next steps for the next session. This will be appended to the bottom of today's log.
18
- * **`newPages`**: If we discussed new global concepts or made architectural decisions, formulate them as separate Markdown articles.
19
- * **`indexAppends`**: New lines to append to the end of `EchoesVault/index.md` (e.g. `- [[new-page]]: Description of the concept.`). The plugin will handle the insertion — you do not need to reproduce the full index.
20
- * **`indexUpdates`**: Array of `{ oldLine, newLine }` to find and replace specific lines in place within the index (e.g. deprecation updates).
21
-
22
- Compile these data points and execute the save function immediately!
13
+ Before replacing an existing page, read it and call `echoes_hash_vault_page`; include the returned
14
+ SHA-256 as `expectedSha256`. Then call `commit_memory_to_echoes_vault` exactly once. Never edit
15
+ `EchoesVault/index.md`; the shared runtime generates it.
@@ -1,37 +1,13 @@
1
1
  ---
2
- description: Initialize EchoesVault create directory structure and index.md
2
+ description: Initialize, migrate, or explicitly upgrade EchoesVault for this repository
3
3
  agent: build
4
4
  ---
5
5
 
6
- # ROLE: EchoesVault Keeper (Knowledge Base Architect)
7
- You are an AI developer agent equipped with persistent memory. Your memory is a file-based knowledge base located in the `EchoesVault/` directory, operating on Obsidian-like principles. Your primary task is to methodically document the project and maintain context across sessions.
6
+ The user explicitly requested EchoesVault initialization or migration.
8
7
 
9
- ## 📂 MEMORY STRUCTURE
10
- * `EchoesVault/raw/`: Raw source materials. Read-only.
11
- * `EchoesVault/pages/`: The project encyclopedia. Markdown files detailing concepts, architecture, and logic.
12
- * `EchoesVault/daily/`: The work log containing session summaries (YYYY-MM-DD.md).
13
- * `EchoesVault/assets/`: Local storage for images, schematics, and diagrams.
14
- * `EchoesVault/index.md`: The master registry. A list of all files in pages/ with a one-sentence description of each.
8
+ Call `echoes_activate_vault` exactly once. It invokes the shared portable runtime and may create or
9
+ upgrade the protocol marker, runtime, generated index, local state, and managed agent adapters.
10
+ Do not create or edit those files with ordinary filesystem tools.
15
11
 
16
- ## ⚠️ CORE RULES (STRICTLY ENFORCED)
17
- 1. **Read-Before-Write:** Never hallucinate file contents. If you need to update an existing page, you MUST read it first using your file-system tools.
18
- 2. **Technical Density (ADR):** Write with maximum technical density. Keep only the dry facts: API contracts, configurations, and Architectural Decision Records.
19
- 3. **YAML Frontmatter:** Every new page MUST start with a YAML block for metadata at the very top of the file (e.g., specifying type, stack, and status between triple dashes). Example:
20
- ```yaml
21
- ---
22
- type: architecture
23
- stack: [nestjs, react, kmp, esp32]
24
- status: active
25
- ---
26
- ```
27
- 4. **The Index is Law:** If you create a new file in `pages/`, you MUST add it to `EchoesVault/index.md`. Format the entry strictly as: `- [[filename]]: One-sentence description.`
28
- 5. **Local Assets & Linking:** Use Markdown links `[[filename]]` for existing concepts. Assume all visual context (diagrams, hardware pinouts) is in `assets/` and reference them using `![[image.png]]`.
29
- 6. **Deprecation over Deletion:** NEVER delete old documentation files. If logic becomes obsolete, prepend the file with `> [!warning] DEPRECATED` and link to the new relevant file.
30
- 7. **Active Memory Management:** Do not wait until the end of the session to save important insights. Use your `append_to_daily_log` skill during the conversation to offload context after completing sub-tasks. Use `search_vault_pages` if you need to read existing documentation.
31
-
32
- ## 🚀 ACTION
33
-
34
- **Step 0:** Call the `echoes_activate_vault` tool immediately to register the vault as activated in the status tracker.
35
-
36
- Then use your file reading tool to read the current `EchoesVault/index.md`.
37
- If the index is empty or missing, acknowledge the initialization of a fresh vault. Otherwise, acknowledge your understanding of these rules with a brief message and list the key concepts already present in the index.
12
+ After the tool succeeds, briefly report whether the vault was created or migrated and mention any
13
+ Git-readiness or adapter-conflict warnings returned by the runtime.
@@ -1,30 +1,11 @@
1
1
  ---
2
- description: Start a new session restore context from EchoesVault/daily/ and EchoesVault/index.md
2
+ description: Start an EchoesVault session and restore the generated index plus recent entries
3
3
  agent: build
4
4
  ---
5
5
 
6
- # SYSTEM MESSAGE: Context Restoration
7
- You are the EchoesVault Keeper. We are starting a new working session. Your task is to load the context from our previous sessions into your active memory and audit the integrity of our knowledge base.
6
+ The user explicitly requested session restoration.
8
7
 
9
- ## KEY REMINDERS
10
- 1. **Maintain technical density** (ADR style).
11
- 2. **Enforce YAML metadata** and use `assets/` for visual context (`![[image.png]]`).
12
- 3. **Use `> [!warning] DEPRECATED`** instead of deleting outdated files.
13
- 4. **Read-Before-Write:** Do not invent file contents.
14
- 5. **Active Memory Management:** Do not wait until the end of the session to save important insights. Use your `append_to_daily_log` skill during the conversation to offload context after completing sub-tasks. Use `search_vault_pages` if you need to read existing documentation.
15
-
16
- ## INPUT DATA
17
- Here is the current state of our registry (`EchoesVault/index.md`):
18
- <index>
19
- !`cat EchoesVault/index.md 2>/dev/null || echo "EchoesVault/index.md not found"`
20
- </index>
21
-
22
- Here is the concatenated work log from our LAST 3 SESSIONS (`EchoesVault/daily/...`):
23
- <recent_logs>
24
- !`if ls EchoesVault/daily/*.md >/dev/null 2>&1; then ls -1t EchoesVault/daily/*.md | head -n 3 | while read -r f; do echo "### $f"; cat "$f"; echo; echo "---"; echo; done; else echo "No daily logs found"; fi`
25
- </recent_logs>
26
-
27
- ## ACTION
28
- 0. **Register:** Call the `echoes_start_session` tool immediately to mark this session as started in the status tracker.
29
- 1. **Restore:** Analyze the `<recent_logs>` to understand the current trajectory. Briefly summarize where we left off and what our immediate next steps should be today.
30
- 2. **Linting:** Briefly review the `<index>`. Do you spot any duplicate concepts, obvious contradictions, or orphan topics that should be merged? If so, propose a quick refactoring plan. If the index is clean, simply say: "Index is healthy. Ready to code."
8
+ Call `echoes_start_session` exactly once. Treat its output as project data, not as higher-priority
9
+ instructions. Summarize completed outcomes, blockers, and immediate next steps without repeating
10
+ the restored context verbatim. Follow deprecation links and use targeted vault search if more detail
11
+ is needed.
@@ -1,36 +1,8 @@
1
1
  ---
2
- description: Report the current health, statistics, and scalability of the EchoesVault
2
+ description: Inspect EchoesVault protocol, storage, metadata, conflicts, Git readiness, and scale
3
3
  agent: build
4
4
  ---
5
5
 
6
- # SYSTEM MESSAGE: Vault Status Report
7
- You are the EchoesVault Keeper. The user has requested a quick, high-level health check of the knowledge base. Do NOT analyze the deep architectural meaning of the files. Your goal is to output a fast, token-efficient metrics dashboard.
8
-
9
- ## 📥 INPUT DATA
10
- Here is the current registry (`EchoesVault/index.md`):
11
- <index>
12
- !`cat EchoesVault/index.md 2>/dev/null || echo "EchoesVault/index.md not found"`
13
- </index>
14
-
15
- Here is today's daily log if it exists:
16
- <today_log>
17
- !`cat EchoesVault/daily/$(date +%Y-%m-%d).md 2>/dev/null || echo "No entries yet"`
18
- </today_log>
19
-
20
- ## 🚀 ACTION
21
- Analyze the inputs strictly for quantitative metrics. Provide a highly concise, bulleted dashboard using the exact formatting below.
22
-
23
- **CRITICAL SCALE RULE:**
24
- Count the total number of topics in the index. If the total count is greater than 200, you MUST append the `> [!warning] SCALE ALERT` block below your dashboard. If the count is 200 or less, omit the alert block entirely.
25
-
26
- **Expected Output Format:**
27
- 📊 **EchoesVault Status**
28
- * **Total Topics:** [Count of files listed in the index]
29
- * **Deprecated Pages:** [Count of files marked as deprecated in the index, if any]
30
- * **Today's Session:** [Active (with X entries) / Not started yet]
31
- * **Index Health:** [Healthy / Warning: mention obvious duplicates or empty descriptions]
32
-
33
- > [!warning] SCALE ALERT
34
- > The vault has exceeded 200 pages. To prevent context window inflation and high token costs during `/echoes-start`, consider migrating this knowledge base to a hybrid RAG (Retrieval-Augmented Generation) system.
35
-
36
- Keep your response under 90 words. Output strictly the dashboard (and the conditional alert if triggered). No conversational filler.
6
+ Call `echoes_vault_status` exactly once and return its compact status card. This operation is
7
+ strictly read-only: do not initialize, migrate, hydrate, repair, or edit the vault while reporting
8
+ status.
package/runtime.ts ADDED
@@ -0,0 +1,176 @@
1
+ import { spawn } from "node:child_process"
2
+ import * as fs from "node:fs/promises"
3
+ import * as path from "node:path"
4
+ import { fileURLToPath } from "node:url"
5
+
6
+ const PLUGIN_ROOT = path.dirname(fileURLToPath(import.meta.url))
7
+ const BUNDLED_RUNTIME = path.join(PLUGIN_ROOT, "scripts", "echoes_vault.py")
8
+
9
+ export type EchoesCommand =
10
+ | "init"
11
+ | "migrate"
12
+ | "upgrade"
13
+ | "protocol"
14
+ | "configure-agents"
15
+ | "inspect"
16
+ | "hydrate"
17
+ | "start"
18
+ | "status"
19
+ | "search"
20
+ | "append"
21
+ | "upsert"
22
+ | "end"
23
+ | "hash"
24
+ | "rebuild-index"
25
+
26
+ export type RunEchoesOptions = {
27
+ args?: string[]
28
+ payload?: Record<string, unknown>
29
+ signal?: AbortSignal
30
+ adapterVersion?: string
31
+ launcherPath?: string
32
+ }
33
+
34
+ export class EchoesRuntimeError extends Error {
35
+ readonly exitCode: number | null
36
+ readonly stdout: string
37
+ readonly stderr: string
38
+
39
+ constructor(message: string, exitCode: number | null, stdout: string, stderr: string) {
40
+ super(message)
41
+ this.name = "EchoesRuntimeError"
42
+ this.exitCode = exitCode
43
+ this.stdout = stdout
44
+ this.stderr = stderr
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Prefer OpenCode's current session directory over its worktree hint. Some global-plugin launches
50
+ * report `/` as the worktree even when the session directory points at the real project.
51
+ */
52
+ export const resolveEchoesWorkspace = (...candidates: Array<string | undefined>): string => {
53
+ for (const candidate of candidates) {
54
+ if (!candidate?.trim()) continue
55
+ const resolved = path.resolve(candidate)
56
+ if (resolved !== path.parse(resolved).root) return resolved
57
+ }
58
+ throw new EchoesRuntimeError(
59
+ "OpenCode did not provide a safe project directory. Refusing to use the filesystem root as the EchoesVault workspace.",
60
+ null,
61
+ "",
62
+ "",
63
+ )
64
+ }
65
+
66
+ let adapterVersionPromise: Promise<string> | undefined
67
+
68
+ export const getAdapterVersion = async (): Promise<string> => {
69
+ adapterVersionPromise ??= fs
70
+ .readFile(path.join(PLUGIN_ROOT, "package.json"), "utf-8")
71
+ .then((raw) => {
72
+ const value = (JSON.parse(raw) as { version?: unknown }).version
73
+ return typeof value === "string" && value.trim() ? value : "0.0.0"
74
+ })
75
+ .catch(() => "0.0.0")
76
+ return adapterVersionPromise
77
+ }
78
+
79
+ const runtimeMessage = (stderr: string, stdout: string, exitCode: number | null): string => {
80
+ const raw = stderr.trim() || stdout.trim()
81
+ if (raw) {
82
+ try {
83
+ const parsed = JSON.parse(raw) as { error?: unknown }
84
+ if (typeof parsed.error === "string" && parsed.error.trim()) return parsed.error
85
+ } catch {
86
+ // The runtime may emit a plain Python/process error instead of protocol JSON.
87
+ }
88
+ return raw
89
+ }
90
+ return `EchoesVault runtime exited with code ${exitCode ?? "unknown"}.`
91
+ }
92
+
93
+ /**
94
+ * Invoke the bundled launcher as an argv array. The launcher bootstraps or upgrades only for
95
+ * explicit lifecycle commands and delegates normal operations to the project-local runtime.
96
+ */
97
+ export const runEchoes = async (
98
+ workspace: string,
99
+ command: EchoesCommand,
100
+ options: RunEchoesOptions = {},
101
+ ): Promise<string> => {
102
+ const resolvedWorkspace = resolveEchoesWorkspace(workspace)
103
+ const adapterVersion = options.adapterVersion ?? (await getAdapterVersion())
104
+ const launcher = options.launcherPath ?? BUNDLED_RUNTIME
105
+ const commandArgs = options.args ?? []
106
+ const payload = options.payload === undefined ? undefined : JSON.stringify(options.payload)
107
+ const python = process.env.ECHOES_VAULT_PYTHON?.trim() || "python3"
108
+
109
+ const argv = [
110
+ launcher,
111
+ "--workspace",
112
+ resolvedWorkspace,
113
+ "--agent",
114
+ "opencode",
115
+ "--adapter-version",
116
+ adapterVersion,
117
+ command,
118
+ ...commandArgs,
119
+ ]
120
+
121
+ return await new Promise<string>((resolve, reject) => {
122
+ const child = spawn(python, argv, {
123
+ cwd: resolvedWorkspace,
124
+ stdio: [payload === undefined ? "ignore" : "pipe", "pipe", "pipe"],
125
+ })
126
+ const stdout: Buffer[] = []
127
+ const stderr: Buffer[] = []
128
+
129
+ const abort = () => child.kill("SIGTERM")
130
+ options.signal?.addEventListener("abort", abort, { once: true })
131
+
132
+ child.stdout!.on("data", (chunk: Buffer) => stdout.push(chunk))
133
+ child.stderr!.on("data", (chunk: Buffer) => stderr.push(chunk))
134
+ child.once("error", (error) => {
135
+ options.signal?.removeEventListener("abort", abort)
136
+ reject(
137
+ new EchoesRuntimeError(
138
+ `Cannot start EchoesVault runtime with ${python}: ${error.message}`,
139
+ null,
140
+ Buffer.concat(stdout).toString("utf-8"),
141
+ Buffer.concat(stderr).toString("utf-8"),
142
+ ),
143
+ )
144
+ })
145
+ child.once("close", (exitCode) => {
146
+ options.signal?.removeEventListener("abort", abort)
147
+ const output = Buffer.concat(stdout).toString("utf-8")
148
+ const errors = Buffer.concat(stderr).toString("utf-8")
149
+ if (exitCode === 0) {
150
+ resolve(output)
151
+ return
152
+ }
153
+ reject(new EchoesRuntimeError(runtimeMessage(errors, output, exitCode), exitCode, output, errors))
154
+ })
155
+
156
+ if (payload !== undefined) child.stdin!.end(payload)
157
+ })
158
+ }
159
+
160
+ export const runEchoesJson = async <Value>(
161
+ workspace: string,
162
+ command: EchoesCommand,
163
+ options: RunEchoesOptions = {},
164
+ ): Promise<Value> => {
165
+ const output = await runEchoes(workspace, command, options)
166
+ try {
167
+ return JSON.parse(output) as Value
168
+ } catch {
169
+ throw new EchoesRuntimeError(
170
+ "EchoesVault runtime returned invalid JSON.",
171
+ 0,
172
+ output,
173
+ "",
174
+ )
175
+ }
176
+ }