echoes-vault-opencode 1.2.1 → 1.2.3

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
@@ -100,6 +100,8 @@ Reads the last 3 daily logs and the full index, then summarizes where you left o
100
100
  ```
101
101
  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.
102
102
 
103
+ Vault status is never automatic: the user controls its transitions with `/echoes-init`, `/echoes-start`, and `/echoes-end`. In particular, `Memory Saved` is shown only after `/echoes-end`. Agents may add intermediate scratchpad notes during work, but those notes do not change the session status.
104
+
103
105
  ---
104
106
 
105
107
  ### Slash commands reference
package/index.ts CHANGED
@@ -151,206 +151,6 @@ const toPageFilename = (name: string): string => {
151
151
 
152
152
  const toPageSlug = (filename: string): string => filename.replace(/\.md$/, "")
153
153
 
154
- const ECHOES_INIT_FALLBACK = `---
155
- description: Initialize EchoesVault — create directory structure and index.md
156
- agent: build
157
- ---
158
-
159
- # ROLE: EchoesVault Keeper (Knowledge Base Architect)
160
- 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.
161
-
162
- ## \ud83d\udcc2 MEMORY STRUCTURE
163
- * \`EchoesVault/raw/\`: Raw source materials. Read-only.
164
- * \`EchoesVault/pages/\`: The project encyclopedia. Markdown files detailing concepts, architecture, and logic.
165
- * \`EchoesVault/daily/\`: The work log containing session summaries (YYYY-MM-DD.md).
166
- * \`EchoesVault/assets/\`: Local storage for images, schematics, and diagrams.
167
- * \`EchoesVault/index.md\`: The master registry. A list of all files in pages/ with a one-sentence description of each.
168
-
169
- ## \u26a0\ufe0f CORE RULES (STRICTLY ENFORCED)
170
- 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.
171
- 2. **Technical Density (ADR):** Write with maximum technical density. Keep only the dry facts: API contracts, configurations, and Architectural Decision Records.
172
- 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:
173
- \`\`\`yaml
174
- ---
175
- type: architecture
176
- stack: [nestjs, react, kmp, esp32]
177
- status: active
178
- ---
179
- \`\`\`
180
- 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.\`
181
- 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]]\`.
182
- 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.
183
- 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.
184
-
185
- ## \ud83d\ude80 ACTION
186
-
187
- **Step 0:** Call the \`echoes_activate_vault\` tool immediately to register the vault as activated in the status tracker.
188
-
189
- Then use your file reading tool to read the current \`EchoesVault/index.md\`.
190
- 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.
191
- `
192
-
193
- const ECHOES_START_FALLBACK = `---
194
- description: Start a new session — restore context from EchoesVault/daily/ and EchoesVault/index.md
195
- agent: build
196
- ---
197
-
198
- # SYSTEM MESSAGE: Context Restoration
199
- 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.
200
-
201
- ## KEY REMINDERS
202
- 1. **Maintain technical density** (ADR style).
203
- 2. **Enforce YAML metadata** and use \`assets/\` for visual context (\`![[image.png]]\`).
204
- 3. **Use \`> [!warning] DEPRECATED\`** instead of deleting outdated files.
205
- 4. **Read-Before-Write:** Do not invent file contents.
206
- 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.
207
-
208
- ## INPUT DATA
209
- Here is the current state of our registry (\`EchoesVault/index.md\`):
210
- <index>
211
- !\`cat EchoesVault/index.md 2>/dev/null || echo "EchoesVault/index.md not found"\`
212
- </index>
213
-
214
- Here is the concatenated work log from our LAST 3 SESSIONS (\`EchoesVault/daily/...\`):
215
- <recent_logs>
216
- !\`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\`
217
- </recent_logs>
218
-
219
- ## ACTION
220
- 0. **Register:** Call the \`echoes_start_session\` tool immediately to mark this session as started in the status tracker.
221
- 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.
222
- 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."
223
- `
224
-
225
- const ECHOES_END_FALLBACK = `---
226
- description: End the session — save memory to EchoesVault via tool commit_memory_to_echoes_vault
227
- agent: build
228
- ---
229
-
230
- # SYSTEM MESSAGE: Session Distillation (Distill & Save)
231
- Our current session is coming to an end. Your task is to crystallize the knowledge we've gained today and commit it to EchoesVault.
232
-
233
- 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.
234
-
235
- ## ACTION
236
- You MUST invoke the system skill \`commit_memory_to_echoes_vault\`.
237
-
238
- Prepare the following payload for the skill:
239
- * **\`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.
240
- * **\`newPages\`**: If we discussed new global concepts or made architectural decisions, formulate them as separate Markdown articles.
241
- * **\`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.
242
- * **\`indexUpdates\`**: Array of \`{ oldLine, newLine }\` to find and replace specific lines in place within the index (e.g. deprecation updates).
243
-
244
- Compile these data points and execute the save function immediately!
245
- `
246
-
247
- const ECHOES_STATUS_FALLBACK = `---
248
- description: Report the current health, statistics, and scalability of the EchoesVault
249
- agent: build
250
- ---
251
-
252
- # SYSTEM MESSAGE: Vault Status Report
253
- 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.
254
-
255
- ## \ud83d\udce5 INPUT DATA
256
- Here is the current registry (\`EchoesVault/index.md\`):
257
- <index>
258
- !\`cat EchoesVault/index.md 2>/dev/null || echo "EchoesVault/index.md not found"\`
259
- </index>
260
-
261
- Here is today's daily log if it exists:
262
- <today_log>
263
- !\`cat EchoesVault/daily/$(date +%Y-%m-%d).md 2>/dev/null || echo "No entries yet"\`
264
- </today_log>
265
-
266
- ## \ud83d\ude80 ACTION
267
- Analyze the inputs strictly for quantitative metrics. Provide a highly concise, bulleted dashboard using the exact formatting below.
268
-
269
- **CRITICAL SCALE RULE:**
270
- 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.
271
-
272
- **Expected Output Format:**
273
- \ud83d\udcca **EchoesVault Status**
274
- * **Total Topics:** [Count of files listed in the index]
275
- * **Deprecated Pages:** [Count of files marked as deprecated in the index, if any]
276
- * **Today's Session:** [Active (with X entries) / Not started yet]
277
- * **Index Health:** [Healthy / Warning: mention obvious duplicates or empty descriptions]
278
-
279
- > [!warning] SCALE ALERT
280
- > 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.
281
-
282
- Keep your response under 90 words. Output strictly the dashboard (and the conditional alert if triggered). No conversational filler.
283
- `
284
-
285
- const APPEND_TO_DAILY_LOG_FALLBACK = `---
286
- name: echoes_append_to_daily_log
287
- description: Append an intermediate technical note or decision to today's daily log immediately after completing a sub-task.
288
- ---
289
-
290
- # TOOL USAGE: echoes_append_to_daily_log
291
- 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\`.
292
-
293
- ## \ud83c\udfaf EXACT TRIGGER CONDITIONS (WHEN TO CALL THIS TOOL)
294
- Do NOT use this tool randomly. You MUST invoke this tool IMMEDIATELY in the current response if ANY of the following specific events occur:
295
- 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.
296
- 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).
297
- 3. **Architectural Agreement:** We just agreed on a core rule, library choice, database schema, or API contract.
298
- 4. **Explicit User Command:** The user explicitly tells you to "take a note", "remember this", "save our progress", or "log this".
299
-
300
- ## \u26a0\ufe0f RULES
301
- 1. **Be Concise:** Write ONLY dry facts and bullet points (e.g., "Refactored AuthGuard to use JWT refresh tokens"). No conversational filler.
302
- 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."*
303
- 3. **No File Overwrites:** This tool ONLY appends to the end of today's file.
304
-
305
- ## \ud83d\udce5 PAYLOAD PARAMETERS
306
- - \`logEntry\`: (String) The markdown-formatted bullet points to append.
307
- `
308
-
309
- const SEARCH_VAULT_PAGES_FALLBACK = `---
310
- name: echoes_search_vault_pages
311
- description: Search the EchoesVault for specific concepts, keywords, or implementation details.
312
- ---
313
-
314
- # TOOL USAGE: echoes_search_vault_pages
315
- 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.
316
-
317
- ## \ud83c\udfaf WHEN TO USE
318
- - The user asks to modify an existing component, but its structure is not in your current context window.
319
- - You need to verify if an Architectural Decision Record (ADR) exists for a specific technology.
320
- - You want to fulfill the "Read-Before-Write" core rule.
321
-
322
- ## \u26a0\ufe0f RULES
323
- 1. **Targeted Queries:** Use specific technical keywords (e.g., "AuthGuard", "esp32 pinout", "database schema") rather than natural language questions.
324
- 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.
325
-
326
- ## \ud83d\udce5 PAYLOAD PARAMETERS
327
- - \`query\`: (String) The specific keyword or short phrase to search for across the \`pages/\` directory.
328
- `
329
-
330
- const CREATE_OR_UPDATE_PAGE_FALLBACK = `---
331
- name: echoes_create_or_update_page
332
- description: Atomically create a new markdown page or update an existing one in EchoesVault/pages/, automatically updating the index.
333
- ---
334
-
335
- # TOOL USAGE: echoes_create_or_update_page
336
- 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.
337
-
338
- ## \ud83c\udfaf WHEN TO USE
339
- - We finalized a new database schema or API contract.
340
- - A major refactoring occurred, rendering previous documentation inaccurate.
341
- - You need to document a newly integrated library or hardware component.
342
-
343
- ## \u26a0\ufe0f RULES
344
- 1. **Strict YAML Frontmatter:** Every page MUST include a YAML metadata block at the top (type, stack, status).
345
- 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\`.
346
- 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.
347
-
348
- ## \ud83d\udce5 PAYLOAD PARAMETERS
349
- - \`filename\`: (String) The exact filename without paths (e.g., \`auth-architecture.md\`).
350
- - \`content\`: (String) The full markdown content of the page, starting with the YAML frontmatter.
351
- - \`indexDescription\`: (String) A one-sentence description of the file. Required if this is a newly created file. Format: "- [[filename]]: description".
352
- `
353
-
354
154
  const ensureCommands = async (directory: string, commands: Record<string, string>): Promise<void> => {
355
155
  const cmdDir = path.join(directory, ".opencode", "commands")
356
156
  await fs.mkdir(cmdDir, { recursive: true })
@@ -388,25 +188,29 @@ const parseCommandFrontmatter = (cmd: string): { template: string; description?:
388
188
  return { template: match[2], description: frontmatter.description, agent: frontmatter.agent }
389
189
  }
390
190
 
191
+ const statusActions = {
192
+ "echoes-init": "init",
193
+ "echoes-start": "start",
194
+ "echoes-end": "end",
195
+ } as const
196
+
197
+ type StatusAction = (typeof statusActions)[keyof typeof statusActions]
198
+
391
199
  const OpenCodeEchoes: Plugin = async ({ directory }) => {
392
200
  const pluginDir = path.dirname(new URL(import.meta.url).pathname)
393
201
 
394
- const readPromptFile = async (relativePath: string, fallback: string): Promise<string> => {
395
- try {
396
- return await fs.readFile(path.join(pluginDir, "prompts", relativePath), "utf-8")
397
- } catch {
398
- return fallback
399
- }
202
+ const readPromptFile = async (relativePath: string): Promise<string> => {
203
+ return await fs.readFile(path.join(pluginDir, "prompts", relativePath), "utf-8")
400
204
  }
401
205
 
402
- const ECHOES_INIT = await readPromptFile("commands/echoes-init.md", ECHOES_INIT_FALLBACK)
403
- const ECHOES_START = await readPromptFile("commands/echoes-start.md", ECHOES_START_FALLBACK)
404
- const ECHOES_END = await readPromptFile("commands/echoes-end.md", ECHOES_END_FALLBACK)
405
- const ECHOES_STATUS = await readPromptFile("commands/echoes-status.md", ECHOES_STATUS_FALLBACK)
206
+ const ECHOES_INIT = await readPromptFile("commands/echoes-init.md")
207
+ const ECHOES_START = await readPromptFile("commands/echoes-start.md")
208
+ const ECHOES_END = await readPromptFile("commands/echoes-end.md")
209
+ const ECHOES_STATUS = await readPromptFile("commands/echoes-status.md")
406
210
 
407
- const APPEND_TO_DAILY_LOG = await readPromptFile("skills/echoes-append-to-daily-log.md", APPEND_TO_DAILY_LOG_FALLBACK)
408
- const SEARCH_VAULT_PAGES = await readPromptFile("skills/echoes-search-vault-pages.md", SEARCH_VAULT_PAGES_FALLBACK)
409
- const CREATE_OR_UPDATE_PAGE = await readPromptFile("skills/echoes-create-or-update-page.md", CREATE_OR_UPDATE_PAGE_FALLBACK)
211
+ const APPEND_TO_DAILY_LOG = await readPromptFile("skills/echoes-append-to-daily-log.md")
212
+ const SEARCH_VAULT_PAGES = await readPromptFile("skills/echoes-search-vault-pages.md")
213
+ const CREATE_OR_UPDATE_PAGE = await readPromptFile("skills/echoes-create-or-update-page.md")
410
214
 
411
215
  const commands: Record<string, string> = {
412
216
  "echoes-init.md": ECHOES_INIT,
@@ -433,10 +237,11 @@ const OpenCodeEchoes: Plugin = async ({ directory }) => {
433
237
  await ensureCommands(directory, commands)
434
238
  await ensureSkills(directory, skills)
435
239
 
240
+ // Sidebar status can change only through the matching user-invoked command.
241
+ const authorizedStatusActions = new Map<string, StatusAction>()
242
+
436
243
  const state = await readState(directory)
437
244
  state.pluginVersion = await getPluginVersion()
438
- state.session.started = false
439
- state.session.saved = false
440
245
  state.stats = await collectStats(paths)
441
246
  await writeState(directory, state)
442
247
 
@@ -448,10 +253,17 @@ const OpenCodeEchoes: Plugin = async ({ directory }) => {
448
253
  input.command[name.replace(".md", "")] = { template, description, agent }
449
254
  }
450
255
  },
256
+ "command.execute.before": async (input) => {
257
+ const command = input.command.replace(/^\//, "") as keyof typeof statusActions
258
+ const action = statusActions[command]
259
+ if (action) {
260
+ authorizedStatusActions.set(input.sessionID, action)
261
+ }
262
+ },
451
263
  tool: {
452
264
  commit_memory_to_echoes_vault: tool({
453
265
  description:
454
- "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.",
266
+ "Save final session memory to EchoesVault. This succeeds only after the user explicitly runs /echoes-end; never call it merely because a task is complete.",
455
267
  args: {
456
268
  dailySummary: tool.schema
457
269
  .string()
@@ -489,7 +301,14 @@ const OpenCodeEchoes: Plugin = async ({ directory }) => {
489
301
  .optional()
490
302
  .describe("Lines to find and replace in place within EchoesVault/index.md"),
491
303
  },
492
- async execute(args, _ctx) {
304
+ async execute(args, ctx) {
305
+ if (authorizedStatusActions.get(ctx.sessionID) !== "end") {
306
+ return [
307
+ "Final memory was not saved.",
308
+ "Only an explicit user /echoes-end command can save final memory and set the status to Memory Saved.",
309
+ ].join("\n")
310
+ }
311
+
493
312
  const today = getDateStr()
494
313
 
495
314
  await ensureVaultDirs(paths)
@@ -538,6 +357,7 @@ const OpenCodeEchoes: Plugin = async ({ directory }) => {
538
357
  st.session.lastSave = new Date().toISOString()
539
358
  st.stats = await collectStats(paths)
540
359
  await writeState(directory, st)
360
+ authorizedStatusActions.delete(ctx.sessionID)
541
361
 
542
362
  return [
543
363
  `✅ Memory committed to EchoesVault.`,
@@ -658,26 +478,36 @@ const OpenCodeEchoes: Plugin = async ({ directory }) => {
658
478
  }),
659
479
  echoes_activate_vault: tool({
660
480
  description:
661
- "Mark the EchoesVault as activated. Called automatically during /echoes-init to register the vault in the status tracker.",
481
+ "Mark the EchoesVault as activated. This succeeds only after the user explicitly runs /echoes-init.",
662
482
  args: {},
663
- async execute(_args, _ctx) {
483
+ async execute(_args, ctx) {
484
+ if (authorizedStatusActions.get(ctx.sessionID) !== "init") {
485
+ return "Vault status was not changed. Only an explicit user /echoes-init command can activate EchoesVault."
486
+ }
487
+
664
488
  const st = await readState(directory)
665
489
  st.initialized = true
666
490
  st.stats = await collectStats(paths)
667
491
  await writeState(directory, st)
492
+ authorizedStatusActions.delete(ctx.sessionID)
668
493
  return "EchoesVault activated."
669
494
  },
670
495
  }),
671
496
  echoes_start_session: tool({
672
497
  description:
673
- "Mark the current EchoesVault session as started. Called automatically during /echoes-start to update the status tracker.",
498
+ "Mark the current EchoesVault session as started. This succeeds only after the user explicitly runs /echoes-start.",
674
499
  args: {},
675
- async execute(_args, _ctx) {
500
+ async execute(_args, ctx) {
501
+ if (authorizedStatusActions.get(ctx.sessionID) !== "start") {
502
+ return "Vault status was not changed. Only an explicit user /echoes-start command can start an EchoesVault session."
503
+ }
504
+
676
505
  const st = await readState(directory)
677
506
  st.session.started = true
678
507
  st.session.saved = false
679
508
  st.session.lastStart = new Date().toISOString()
680
509
  await writeState(directory, st)
510
+ authorizedStatusActions.delete(ctx.sessionID)
681
511
  return "EchoesVault session started."
682
512
  },
683
513
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoes-vault-opencode",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "EchoesVault — persistent memory plugin for OpenCode. Obsidian-style knowledge base with daily logs, encyclopedia pages, and session resumption.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -6,6 +6,8 @@ agent: build
6
6
  # SYSTEM MESSAGE: Session Distillation (Distill & Save)
7
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.
8
8
 
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.
10
+
9
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.
10
12
 
11
13
  ## ACTION
package/tui.tsx CHANGED
@@ -74,7 +74,7 @@ const tui: TuiPlugin = async (api) => {
74
74
  const statusDesc = () => {
75
75
  const s = state()
76
76
  if (!s || !s.initialized) return null
77
- if (s.session.saved) return "Vault memorized session data"
77
+ if (s.session.saved) return "Final memory saved by /echoes-end"
78
78
  if (s.session.started) return null
79
79
  return null
80
80
  }