echoes-vault-opencode 0.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/LICENSE +21 -0
- package/README.md +125 -0
- package/index.ts +472 -0
- package/package.json +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fail
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/psinetron/echoes-vault-opencode/main/images/EchoesVault.png" alt="EchoesVault" width="200" />
|
|
3
|
+
<h1>EchoesVault</h1>
|
|
4
|
+
<p>Persistent memory plugin for OpenCode. Obsidian-style knowledge base that survives across sessions.</p>
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/echoes-vault-opencode)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://opencode.ai/docs/ecosystem)
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
AI agents forget everything when a session ends. EchoesVault gives OpenCode a persistent, file-based memory: architectural decisions, daily work logs, and a searchable project encyclopedia — all stored as plain Markdown in your repository.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- **Zero context loss** — start every session exactly where you left off. `/echoes-resume` reads the last 3 daily logs and the full knowledge index and feeds them to the AI automatically.
|
|
18
|
+
- **Zero setup** — on first load the plugin creates the entire vault structure, slash commands, and agent skills by itself. Nothing to configure.
|
|
19
|
+
- **Obsidian-compatible vault** — `EchoesVault/` is a valid Obsidian vault. Open it in Obsidian at any time for visual navigation, graph view, and search.
|
|
20
|
+
- **ADR-style documentation** — the AI is instructed to write with maximum technical density: API contracts, configuration records, and Architectural Decision Records — not chat transcripts.
|
|
21
|
+
- **Active memory management** — the AI logs intermediate notes mid-session via `echoes_append_to_daily_log`, not just at the end. Context is never lost to a crash or accidental close.
|
|
22
|
+
- **Deprecation over deletion** — outdated pages are marked `> [!warning] DEPRECATED` and linked to their replacement. The full history is always preserved.
|
|
23
|
+
- **Safe and idempotent** — commands and skills are only created if they don't exist. Restarting OpenCode never overwrites user edits.
|
|
24
|
+
|
|
25
|
+
## Vault structure
|
|
26
|
+
|
|
27
|
+
The plugin creates and manages the following directory inside your project:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
EchoesVault/
|
|
31
|
+
├── index.md — master registry: one-line description of every page
|
|
32
|
+
├── pages/ — project encyclopedia (Markdown, YAML frontmatter, [[wikilinks]])
|
|
33
|
+
├── daily/ — session work logs (YYYY-MM-DD.md)
|
|
34
|
+
├── assets/ — diagrams, schematics, hardware pinouts
|
|
35
|
+
└── raw/ — read-only source materials
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Every page in `pages/` starts with YAML frontmatter:
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
---
|
|
42
|
+
type: architecture
|
|
43
|
+
stack: [nestjs, react]
|
|
44
|
+
status: active
|
|
45
|
+
---
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Requirements
|
|
49
|
+
|
|
50
|
+
- [OpenCode](https://opencode.ai) `>= 1.16.0`
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
Add the plugin to your `opencode.json`:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"$schema": "https://opencode.ai/config.json",
|
|
59
|
+
"plugin": ["echoes-vault-opencode"]
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
OpenCode installs the package automatically via Bun on next startup. On first run the plugin bootstraps the vault, registers the slash commands, and installs the agent skills — no manual steps required.
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
### Typical session workflow
|
|
68
|
+
|
|
69
|
+
**1. First time in a project — initialize the vault:**
|
|
70
|
+
```
|
|
71
|
+
/echoes-init
|
|
72
|
+
```
|
|
73
|
+
The AI reads `EchoesVault/index.md`, acknowledges the rules, and lists any existing knowledge. On a fresh vault it confirms initialization.
|
|
74
|
+
|
|
75
|
+
**2. Start of every subsequent session — restore context:**
|
|
76
|
+
```
|
|
77
|
+
/echoes-resume
|
|
78
|
+
```
|
|
79
|
+
Reads the last 3 daily logs and the full index, then summarizes where you left off and what the immediate next steps are. Also lints the index for duplicates or contradictions.
|
|
80
|
+
|
|
81
|
+
**3. Work normally.** During the session the AI uses the vault tools autonomously:
|
|
82
|
+
- logs intermediate decisions to the daily scratchpad,
|
|
83
|
+
- searches existing pages before writing new code,
|
|
84
|
+
- creates or updates encyclopedia pages when architecture changes.
|
|
85
|
+
|
|
86
|
+
**4. End of session — save everything:**
|
|
87
|
+
```
|
|
88
|
+
/echoes-save
|
|
89
|
+
```
|
|
90
|
+
The AI distills the session into a dense technical summary, writes new encyclopedia pages for any concepts decided today, and updates the index. All via a single tool call.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### Slash commands reference
|
|
95
|
+
|
|
96
|
+
| Command | Description |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `/echoes-init` | Initialize the vault and brief the AI on the knowledge base rules |
|
|
99
|
+
| `/echoes-resume` | Restore context from the last 3 daily logs and the index |
|
|
100
|
+
| `/echoes-save` | Distill and commit session memory to the vault |
|
|
101
|
+
|
|
102
|
+
### AI tools reference
|
|
103
|
+
|
|
104
|
+
These tools are available to the AI during any session.
|
|
105
|
+
|
|
106
|
+
| Tool | Description |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `commit_memory_to_echoes_vault` | Save a daily summary, create new pages, and update the index in one atomic call |
|
|
109
|
+
| `echoes_append_to_daily_log` | Append a timestamped note to today's daily log mid-session |
|
|
110
|
+
| `echoes_search_vault_pages` | Search `pages/` by keyword and return matching lines with file and line number |
|
|
111
|
+
| `echoes_create_or_update_page` | Atomically create or overwrite a page in `pages/`, auto-syncing the index |
|
|
112
|
+
|
|
113
|
+
### Agent skills reference
|
|
114
|
+
|
|
115
|
+
Skills guide the AI on *when* and *how* to use the tools above. They are loaded on-demand via the OpenCode `skill` tool.
|
|
116
|
+
|
|
117
|
+
| Skill | Description |
|
|
118
|
+
|---|---|
|
|
119
|
+
| `echoes_append_to_daily_log` | Exact trigger conditions and rules for mid-session logging |
|
|
120
|
+
| `echoes_search_vault_pages` | When to search the vault before generating code |
|
|
121
|
+
| `echoes_create_or_update_page` | When to create vs. update a page, deprecation rules |
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
[MIT](LICENSE)
|
package/index.ts
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import type { Plugin } from "@opencode-ai/plugin"
|
|
2
|
+
import { tool } from "@opencode-ai/plugin"
|
|
3
|
+
import * as fs from "node:fs/promises"
|
|
4
|
+
import * as path from "node:path"
|
|
5
|
+
|
|
6
|
+
const getDateStr = (): string => {
|
|
7
|
+
const d = new Date()
|
|
8
|
+
const year = d.getFullYear()
|
|
9
|
+
const month = String(d.getMonth() + 1).padStart(2, "0")
|
|
10
|
+
const day = String(d.getDate()).padStart(2, "0")
|
|
11
|
+
return `${year}-${month}-${day}`
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type VaultPaths = {
|
|
15
|
+
vault: string
|
|
16
|
+
raw: string
|
|
17
|
+
pages: string
|
|
18
|
+
daily: string
|
|
19
|
+
assets: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const resolveVaultPaths = (directory: string): VaultPaths => {
|
|
23
|
+
const vault = path.join(directory, "EchoesVault")
|
|
24
|
+
return {
|
|
25
|
+
vault,
|
|
26
|
+
raw: path.join(vault, "raw"),
|
|
27
|
+
pages: path.join(vault, "pages"),
|
|
28
|
+
daily: path.join(vault, "daily"),
|
|
29
|
+
assets: path.join(vault, "assets"),
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ensureVaultDirs = async (paths: VaultPaths): Promise<void> => {
|
|
34
|
+
await fs.mkdir(paths.raw, { recursive: true })
|
|
35
|
+
await fs.mkdir(paths.pages, { recursive: true })
|
|
36
|
+
await fs.mkdir(paths.daily, { recursive: true })
|
|
37
|
+
await fs.mkdir(paths.assets, { recursive: true })
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const DEFAULT_INDEX = `# EchoesVault Index
|
|
41
|
+
|
|
42
|
+
Welcome to the EchoesVault knowledge base.
|
|
43
|
+
|
|
44
|
+
This index tracks all structured pages in the vault.
|
|
45
|
+
`
|
|
46
|
+
|
|
47
|
+
const sanitizeFilename = (name: string): string => {
|
|
48
|
+
const cleaned = name.replace(/\.\./g, "").replace(/[\/\\]/g, "")
|
|
49
|
+
return cleaned || "untitled"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Normalizes any user/LLM-supplied page name to a safe `*.md` filename,
|
|
53
|
+
// ensuring we never produce duplicates like `foo.md.md`.
|
|
54
|
+
const toPageFilename = (name: string): string => {
|
|
55
|
+
const safe = sanitizeFilename(name)
|
|
56
|
+
return safe.endsWith(".md") ? safe : `${safe}.md`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const toPageSlug = (filename: string): string => filename.replace(/\.md$/, "")
|
|
60
|
+
|
|
61
|
+
const ECHOES_INIT_COMMAND = `---
|
|
62
|
+
description: Initialize EchoesVault — create directory structure and index.md
|
|
63
|
+
agent: build
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
# ROLE: EchoesVault Keeper (Knowledge Base Architect)
|
|
67
|
+
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.
|
|
68
|
+
|
|
69
|
+
## \ud83d\udcc2 MEMORY STRUCTURE
|
|
70
|
+
* \`EchoesVault/raw/\`: Raw source materials. Read-only.
|
|
71
|
+
* \`EchoesVault/pages/\`: The project encyclopedia. Markdown files detailing concepts, architecture, and logic.
|
|
72
|
+
* \`EchoesVault/daily/\`: The work log containing session summaries (YYYY-MM-DD.md).
|
|
73
|
+
* \`EchoesVault/assets/\`: Local storage for images, schematics, and diagrams.
|
|
74
|
+
* \`EchoesVault/index.md\`: The master registry. A list of all files in pages/ with a one-sentence description of each.
|
|
75
|
+
|
|
76
|
+
## \u26a0\ufe0f CORE RULES (STRICTLY ENFORCED)
|
|
77
|
+
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.
|
|
78
|
+
2. **Technical Density (ADR):** Write with maximum technical density. Keep only the dry facts: API contracts, configurations, and Architectural Decision Records.
|
|
79
|
+
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:
|
|
80
|
+
\`\`\`yaml
|
|
81
|
+
---
|
|
82
|
+
type: architecture
|
|
83
|
+
stack: [nestjs, react, kmp, esp32]
|
|
84
|
+
status: active
|
|
85
|
+
---
|
|
86
|
+
\`\`\`
|
|
87
|
+
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.\`
|
|
88
|
+
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]]\`.
|
|
89
|
+
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.
|
|
90
|
+
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.
|
|
91
|
+
|
|
92
|
+
## \ud83d\ude80 ACTION
|
|
93
|
+
|
|
94
|
+
The memory system has been initialized. Use your file reading tool to read the current \`EchoesVault/index.md\`.
|
|
95
|
+
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.
|
|
96
|
+
`
|
|
97
|
+
|
|
98
|
+
const ECHOES_RESUME_COMMAND = `---
|
|
99
|
+
description: Restore context from EchoesVault/daily/ and EchoesVault/index.md
|
|
100
|
+
agent: build
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
# SYSTEM MESSAGE: Context Restoration
|
|
104
|
+
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.
|
|
105
|
+
|
|
106
|
+
## KEY REMINDERS
|
|
107
|
+
1. **Maintain technical density** (ADR style).
|
|
108
|
+
2. **Enforce YAML metadata** and use \`assets/\` for visual context (\`![[image.png]]\`).
|
|
109
|
+
3. **Use \`> [!warning] DEPRECATED\`** instead of deleting outdated files.
|
|
110
|
+
4. **Read-Before-Write:** Do not invent file contents.
|
|
111
|
+
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.
|
|
112
|
+
|
|
113
|
+
## INPUT DATA
|
|
114
|
+
Here is the current state of our registry (\`EchoesVault/index.md\`):
|
|
115
|
+
<index>
|
|
116
|
+
!\`cat EchoesVault/index.md 2>/dev/null || echo "EchoesVault/index.md not found"\`
|
|
117
|
+
</index>
|
|
118
|
+
|
|
119
|
+
Here is the concatenated work log from our LAST 3 SESSIONS (\`EchoesVault/daily/...\`):
|
|
120
|
+
<recent_logs>
|
|
121
|
+
!\`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\`
|
|
122
|
+
</recent_logs>
|
|
123
|
+
|
|
124
|
+
## ACTION
|
|
125
|
+
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.
|
|
126
|
+
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."
|
|
127
|
+
`
|
|
128
|
+
|
|
129
|
+
const ECHOES_SAVE_COMMAND = `---
|
|
130
|
+
description: Save session memory to EchoesVault via tool commit_memory_to_echoes_vault
|
|
131
|
+
agent: build
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
# SYSTEM MESSAGE: Session Distillation (Distill & Save)
|
|
135
|
+
Our current session is coming to an end. Your task is to crystallize the knowledge we've gained today and commit it to EchoesVault.
|
|
136
|
+
|
|
137
|
+
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.
|
|
138
|
+
|
|
139
|
+
## ACTION
|
|
140
|
+
You MUST invoke the system skill \`commit_memory_to_echoes_vault\`.
|
|
141
|
+
|
|
142
|
+
Prepare the following payload for the skill:
|
|
143
|
+
* **\`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.
|
|
144
|
+
* **\`newPages\`**: If we discussed new global concepts or made architectural decisions, formulate them as separate Markdown articles.
|
|
145
|
+
* **\`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 \u2014 you do not need to reproduce the full index.
|
|
146
|
+
* **\`indexUpdates\`**: Array of \`{ oldLine, newLine }\` to find and replace specific lines in place within the index (e.g. deprecation updates).
|
|
147
|
+
|
|
148
|
+
Compile these data points and execute the save function immediately!
|
|
149
|
+
`
|
|
150
|
+
|
|
151
|
+
const APPEND_TO_DAILY_LOG_SKILL = `---
|
|
152
|
+
name: echoes_append_to_daily_log
|
|
153
|
+
description: Append an intermediate technical note or decision to today's daily log immediately after completing a sub-task.
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
# TOOL USAGE: echoes_append_to_daily_log
|
|
157
|
+
You are equipped with a scratchpad tool to manage your cognitive load. You MUST use this tool to offload important context into \`EchoesVault/daily/YYYY-MM-DD.md\`.
|
|
158
|
+
|
|
159
|
+
## \ud83c\udfaf EXACT TRIGGER CONDITIONS (WHEN TO CALL THIS TOOL)
|
|
160
|
+
Do NOT use this tool randomly. You MUST invoke this tool IMMEDIATELY in the current response if ANY of the following specific events occur:
|
|
161
|
+
1. **Task Completion:** We successfully finish a logical unit of work (e.g., a script works, a bug is verified as fixed, tests pass) BEFORE starting the next user request.
|
|
162
|
+
2. **Context Switch:** The user asks to change focus (e.g., "Now let's work on the frontend" after we just worked on the backend).
|
|
163
|
+
3. **Architectural Agreement:** We just agreed on a core rule, library choice, database schema, or API contract.
|
|
164
|
+
4. **Explicit User Command:** The user explicitly tells you to "take a note", "remember this", "save our progress", or "log this".
|
|
165
|
+
|
|
166
|
+
## \u26a0\ufe0f RULES
|
|
167
|
+
1. **Be Concise:** Write ONLY dry facts and bullet points (e.g., "Refactored AuthGuard to use JWT refresh tokens"). No conversational filler.
|
|
168
|
+
2. **Do Not Interrupt Flow:** Make the tool call silently or add a brief confirmation in your response like: *"Logged the AuthGuard update to the daily vault. Ready for the frontend."*
|
|
169
|
+
3. **No File Overwrites:** This tool ONLY appends to the end of today's file.
|
|
170
|
+
|
|
171
|
+
## \ud83d\udce5 PAYLOAD PARAMETERS
|
|
172
|
+
- \`logEntry\`: (String) The markdown-formatted bullet points to append.
|
|
173
|
+
`
|
|
174
|
+
|
|
175
|
+
const SEARCH_VAULT_PAGES_SKILL = `---
|
|
176
|
+
name: echoes_search_vault_pages
|
|
177
|
+
description: Search the EchoesVault for specific concepts, keywords, or implementation details.
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
# TOOL USAGE: echoes_search_vault_pages
|
|
181
|
+
You are the EchoesVault Keeper. If you encounter a concept, API, or architectural pattern in our conversation that you suspect is documented but you lack the full context, use this tool BEFORE generating code.
|
|
182
|
+
|
|
183
|
+
## \ud83c\udfaf WHEN TO USE
|
|
184
|
+
- The user asks to modify an existing component, but its structure is not in your current context window.
|
|
185
|
+
- You need to verify if an Architectural Decision Record (ADR) exists for a specific technology.
|
|
186
|
+
- You want to fulfill the "Read-Before-Write" core rule.
|
|
187
|
+
|
|
188
|
+
## \u26a0\ufe0f RULES
|
|
189
|
+
1. **Targeted Queries:** Use specific technical keywords (e.g., "AuthGuard", "esp32 pinout", "database schema") rather than natural language questions.
|
|
190
|
+
2. **Handle Deprecations:** If the search returns a file marked with \`> [!warning] DEPRECATED\`, look for the link to the new relevant file and read that instead.
|
|
191
|
+
|
|
192
|
+
## \ud83d\udce5 PAYLOAD PARAMETERS
|
|
193
|
+
- \`query\`: (String) The specific keyword or short phrase to search for across the \`pages/\` directory.
|
|
194
|
+
`
|
|
195
|
+
|
|
196
|
+
const CREATE_OR_UPDATE_PAGE_SKILL = `---
|
|
197
|
+
name: echoes_create_or_update_page
|
|
198
|
+
description: Atomically create a new markdown page or update an existing one in EchoesVault/pages/, automatically updating the index.
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
# TOOL USAGE: echoes_create_or_update_page
|
|
202
|
+
Use this tool when a new global concept has been defined or an existing component's architecture has fundamentally changed during our session. This allows you to update the encyclopedia immediately.
|
|
203
|
+
|
|
204
|
+
## \ud83c\udfaf WHEN TO USE
|
|
205
|
+
- We finalized a new database schema or API contract.
|
|
206
|
+
- A major refactoring occurred, rendering previous documentation inaccurate.
|
|
207
|
+
- You need to document a newly integrated library or hardware component.
|
|
208
|
+
|
|
209
|
+
## \u26a0\ufe0f RULES
|
|
210
|
+
1. **Strict YAML Frontmatter:** Every page MUST include a YAML metadata block at the top (type, stack, status).
|
|
211
|
+
2. **Index Sync:** When you create a new file, you must provide a one-sentence description for the index. The system will automatically append it to \`index.md\`.
|
|
212
|
+
3. **Deprecate, Don't Delete:** If you are rewriting an existing page completely because the logic changed, consider if you should instead create a new page (e.g., \`api-v2.md\`) and update the old one with a \`> [!warning] DEPRECATED\` callout via this tool.
|
|
213
|
+
|
|
214
|
+
## \ud83d\udce5 PAYLOAD PARAMETERS
|
|
215
|
+
- \`filename\`: (String) The exact filename without paths (e.g., \`auth-architecture.md\`).
|
|
216
|
+
- \`content\`: (String) The full markdown content of the page, starting with the YAML frontmatter.
|
|
217
|
+
- \`indexDescription\`: (String) A one-sentence description of the file. Required if this is a newly created file. Format: "- [[filename]]: description".
|
|
218
|
+
`
|
|
219
|
+
|
|
220
|
+
const ensureCommands = async (directory: string): Promise<void> => {
|
|
221
|
+
const commands: Record<string, string> = {
|
|
222
|
+
"echoes-init.md": ECHOES_INIT_COMMAND,
|
|
223
|
+
"echoes-resume.md": ECHOES_RESUME_COMMAND,
|
|
224
|
+
"echoes-save.md": ECHOES_SAVE_COMMAND,
|
|
225
|
+
}
|
|
226
|
+
const cmdDir = path.join(directory, ".opencode", "commands")
|
|
227
|
+
await fs.mkdir(cmdDir, { recursive: true })
|
|
228
|
+
for (const [name, content] of Object.entries(commands)) {
|
|
229
|
+
const cmdFile = path.join(cmdDir, name)
|
|
230
|
+
try {
|
|
231
|
+
await fs.access(cmdFile)
|
|
232
|
+
} catch {
|
|
233
|
+
await fs.writeFile(cmdFile, content)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const ensureSkills = async (directory: string): Promise<void> => {
|
|
239
|
+
const skills: Record<string, string> = {
|
|
240
|
+
"echoes-append-to-daily-log": APPEND_TO_DAILY_LOG_SKILL,
|
|
241
|
+
"echoes-search-vault-pages": SEARCH_VAULT_PAGES_SKILL,
|
|
242
|
+
"echoes-create-or-update-page": CREATE_OR_UPDATE_PAGE_SKILL,
|
|
243
|
+
}
|
|
244
|
+
for (const [name, content] of Object.entries(skills)) {
|
|
245
|
+
const skillDir = path.join(directory, ".opencode", "skills", name)
|
|
246
|
+
const skillFile = path.join(skillDir, "SKILL.md")
|
|
247
|
+
await fs.mkdir(skillDir, { recursive: true })
|
|
248
|
+
try {
|
|
249
|
+
await fs.access(skillFile)
|
|
250
|
+
} catch {
|
|
251
|
+
await fs.writeFile(skillFile, content)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export const OpenCodeEchoes: Plugin = async ({ directory }) => {
|
|
257
|
+
const paths = resolveVaultPaths(directory)
|
|
258
|
+
const indexFile = path.join(paths.vault, "index.md")
|
|
259
|
+
|
|
260
|
+
await ensureVaultDirs(paths)
|
|
261
|
+
try {
|
|
262
|
+
await fs.access(indexFile)
|
|
263
|
+
} catch {
|
|
264
|
+
await fs.writeFile(indexFile, DEFAULT_INDEX)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
await ensureCommands(directory)
|
|
268
|
+
await ensureSkills(directory)
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
tool: {
|
|
272
|
+
commit_memory_to_echoes_vault: tool({
|
|
273
|
+
description:
|
|
274
|
+
"Save session memory to EchoesVault. Writes a daily summary, creates new knowledge base pages, and updates the Vault index. Call this at session end to persist all context.",
|
|
275
|
+
args: {
|
|
276
|
+
dailySummary: tool.schema
|
|
277
|
+
.string()
|
|
278
|
+
.describe(
|
|
279
|
+
"Detailed summary of the current session: what was accomplished, bugs discovered, where you stopped, and what remains to be done."
|
|
280
|
+
),
|
|
281
|
+
newPages: tool.schema
|
|
282
|
+
.array(
|
|
283
|
+
tool.schema.object({
|
|
284
|
+
filename: tool.schema
|
|
285
|
+
.string()
|
|
286
|
+
.describe("Filename without .md extension (e.g. 'architecture-decisions')"),
|
|
287
|
+
content: tool.schema
|
|
288
|
+
.string()
|
|
289
|
+
.describe("Full markdown content of the knowledge base page"),
|
|
290
|
+
})
|
|
291
|
+
)
|
|
292
|
+
.optional()
|
|
293
|
+
.describe("Array of new knowledge base pages to create in EchoesVault/pages/"),
|
|
294
|
+
indexAppends: tool.schema
|
|
295
|
+
.array(tool.schema.string())
|
|
296
|
+
.optional()
|
|
297
|
+
.describe("Lines to append to the end of EchoesVault/index.md"),
|
|
298
|
+
indexUpdates: tool.schema
|
|
299
|
+
.array(
|
|
300
|
+
tool.schema.object({
|
|
301
|
+
oldLine: tool.schema
|
|
302
|
+
.string()
|
|
303
|
+
.describe("The exact line to find and replace in the index"),
|
|
304
|
+
newLine: tool.schema
|
|
305
|
+
.string()
|
|
306
|
+
.describe("The replacement line"),
|
|
307
|
+
})
|
|
308
|
+
)
|
|
309
|
+
.optional()
|
|
310
|
+
.describe("Lines to find and replace in place within EchoesVault/index.md"),
|
|
311
|
+
},
|
|
312
|
+
async execute(args, _ctx) {
|
|
313
|
+
const today = getDateStr()
|
|
314
|
+
|
|
315
|
+
await ensureVaultDirs(paths)
|
|
316
|
+
|
|
317
|
+
const dailyFile = path.join(paths.daily, `${today}.md`)
|
|
318
|
+
const timestamp = new Date().toISOString()
|
|
319
|
+
const header = `## Session — ${timestamp}\n\n`
|
|
320
|
+
await fs.appendFile(dailyFile, header + args.dailySummary + "\n\n")
|
|
321
|
+
|
|
322
|
+
let pagesCreated = 0
|
|
323
|
+
if (args.newPages && args.newPages.length > 0) {
|
|
324
|
+
for (const page of args.newPages) {
|
|
325
|
+
const fileName = toPageFilename(page.filename)
|
|
326
|
+
const pageFile = path.join(paths.pages, fileName)
|
|
327
|
+
await fs.writeFile(pageFile, page.content.trim() + "\n")
|
|
328
|
+
pagesCreated++
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const idxFile = path.join(paths.vault, "index.md")
|
|
333
|
+
|
|
334
|
+
let indexContent = ""
|
|
335
|
+
try {
|
|
336
|
+
indexContent = await fs.readFile(idxFile, "utf-8")
|
|
337
|
+
} catch {
|
|
338
|
+
indexContent = DEFAULT_INDEX
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (args.indexUpdates && args.indexUpdates.length > 0) {
|
|
342
|
+
for (const upd of args.indexUpdates) {
|
|
343
|
+
if (indexContent.includes(upd.oldLine)) {
|
|
344
|
+
indexContent = indexContent.replaceAll(upd.oldLine, upd.newLine)
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (args.indexAppends && args.indexAppends.length > 0) {
|
|
350
|
+
const toAppend = args.indexAppends.join("\n")
|
|
351
|
+
indexContent = indexContent.trimEnd() + "\n" + toAppend + "\n"
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
await fs.writeFile(idxFile, indexContent)
|
|
355
|
+
|
|
356
|
+
return [
|
|
357
|
+
`✅ Memory committed to EchoesVault.`,
|
|
358
|
+
`- Daily log: EchoesVault/daily/${today}.md`,
|
|
359
|
+
`- Pages created: ${pagesCreated}`,
|
|
360
|
+
`- Index: updated`,
|
|
361
|
+
].join("\n")
|
|
362
|
+
},
|
|
363
|
+
}),
|
|
364
|
+
echoes_append_to_daily_log: tool({
|
|
365
|
+
description:
|
|
366
|
+
"Append an intermediate technical note or decision to today's daily log without ending the session.",
|
|
367
|
+
args: {
|
|
368
|
+
logEntry: tool.schema
|
|
369
|
+
.string()
|
|
370
|
+
.describe(
|
|
371
|
+
"Markdown-formatted bullet points to append. Do not include date/time — the system adds a timestamp automatically."
|
|
372
|
+
),
|
|
373
|
+
},
|
|
374
|
+
async execute(args, _ctx) {
|
|
375
|
+
const today = getDateStr()
|
|
376
|
+
await ensureVaultDirs(paths)
|
|
377
|
+
const dailyFile = path.join(paths.daily, `${today}.md`)
|
|
378
|
+
const timestamp = new Date().toISOString()
|
|
379
|
+
const entry = `### Scratchpad — ${timestamp}\n\n${args.logEntry}\n\n`
|
|
380
|
+
await fs.appendFile(dailyFile, entry)
|
|
381
|
+
return `✅ Scratchpad note saved to EchoesVault/daily/${today}.md`
|
|
382
|
+
},
|
|
383
|
+
}),
|
|
384
|
+
echoes_search_vault_pages: tool({
|
|
385
|
+
description:
|
|
386
|
+
"Search the EchoesVault pages/ directory for specific concepts, keywords, or implementation details.",
|
|
387
|
+
args: {
|
|
388
|
+
query: tool.schema
|
|
389
|
+
.string()
|
|
390
|
+
.describe("Specific keyword or short phrase to search for across the pages/ directory."),
|
|
391
|
+
},
|
|
392
|
+
async execute(args, _ctx) {
|
|
393
|
+
await ensureVaultDirs(paths)
|
|
394
|
+
const results: string[] = []
|
|
395
|
+
try {
|
|
396
|
+
const files = (await fs.readdir(paths.pages)).filter((f) =>
|
|
397
|
+
f.endsWith(".md")
|
|
398
|
+
)
|
|
399
|
+
for (const file of files) {
|
|
400
|
+
const content = await fs.readFile(
|
|
401
|
+
path.join(paths.pages, file),
|
|
402
|
+
"utf-8"
|
|
403
|
+
)
|
|
404
|
+
const lines = content.split("\n")
|
|
405
|
+
for (let i = 0; i < lines.length; i++) {
|
|
406
|
+
if (
|
|
407
|
+
lines[i].toLowerCase().includes(args.query.toLowerCase())
|
|
408
|
+
) {
|
|
409
|
+
results.push(
|
|
410
|
+
`${file}:${i + 1}: ${lines[i].trim().slice(0, 200)}`
|
|
411
|
+
)
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
} catch {
|
|
416
|
+
return "_No pages found in EchoesVault/pages/_"
|
|
417
|
+
}
|
|
418
|
+
if (results.length === 0) {
|
|
419
|
+
return `No results found for "${args.query}" in EchoesVault/pages/.`
|
|
420
|
+
}
|
|
421
|
+
return results.join("\n")
|
|
422
|
+
},
|
|
423
|
+
}),
|
|
424
|
+
echoes_create_or_update_page: tool({
|
|
425
|
+
description:
|
|
426
|
+
"Atomically create a new markdown page or update an existing one in EchoesVault/pages/, automatically updating the index if the file is new.",
|
|
427
|
+
args: {
|
|
428
|
+
filename: tool.schema
|
|
429
|
+
.string()
|
|
430
|
+
.describe("Exact filename without paths (e.g. 'auth-architecture.md')."),
|
|
431
|
+
content: tool.schema
|
|
432
|
+
.string()
|
|
433
|
+
.describe("Full markdown content of the page, starting with YAML frontmatter."),
|
|
434
|
+
indexDescription: tool.schema
|
|
435
|
+
.string()
|
|
436
|
+
.optional()
|
|
437
|
+
.describe("One-sentence description for the index. Required for new files. Format: '- [[filename]]: description'."),
|
|
438
|
+
},
|
|
439
|
+
async execute(args, _ctx) {
|
|
440
|
+
await ensureVaultDirs(paths)
|
|
441
|
+
const fileName = toPageFilename(args.filename)
|
|
442
|
+
const pageFile = path.join(paths.pages, fileName)
|
|
443
|
+
|
|
444
|
+
const existed = await fs.access(pageFile).then(() => true).catch(() => false)
|
|
445
|
+
await fs.writeFile(pageFile, args.content.trim() + "\n")
|
|
446
|
+
|
|
447
|
+
if (!existed && args.indexDescription) {
|
|
448
|
+
const idxFile = path.join(paths.vault, "index.md")
|
|
449
|
+
let indexContent = ""
|
|
450
|
+
try {
|
|
451
|
+
indexContent = await fs.readFile(idxFile, "utf-8")
|
|
452
|
+
} catch {
|
|
453
|
+
indexContent = DEFAULT_INDEX
|
|
454
|
+
}
|
|
455
|
+
const link = `[[${toPageSlug(fileName)}]]`
|
|
456
|
+
if (!indexContent.includes(link)) {
|
|
457
|
+
indexContent = indexContent.trimEnd() + "\n" + args.indexDescription + "\n"
|
|
458
|
+
await fs.writeFile(idxFile, indexContent)
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const action = existed ? "updated" : "created"
|
|
463
|
+
const parts = [`✅ Page ${action}: EchoesVault/pages/${fileName}`]
|
|
464
|
+
if (!existed && args.indexDescription) {
|
|
465
|
+
parts.push(`📑 Index: synced`)
|
|
466
|
+
}
|
|
467
|
+
return parts.join("\n")
|
|
468
|
+
},
|
|
469
|
+
}),
|
|
470
|
+
},
|
|
471
|
+
}
|
|
472
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "echoes-vault-opencode",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "EchoesVault — persistent memory plugin for OpenCode. Obsidian-style knowledge base with daily logs, encyclopedia pages, and session resumption.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.ts"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"opencode",
|
|
12
|
+
"opencode-plugin",
|
|
13
|
+
"memory",
|
|
14
|
+
"knowledge-base",
|
|
15
|
+
"obsidian",
|
|
16
|
+
"vault"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^22.0.0",
|
|
21
|
+
"typescript": "^5.8.0"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/psinetron/echoes-vault-opencode.git"
|
|
26
|
+
}
|
|
27
|
+
}
|