Commit Graph

50 Commits

Author SHA1 Message Date
Ralph Chang 4309cb855f fix: promotion accounting, sessionID extraction, and strengthened regression tests
Architecture review fixes:

- Promotion accounting: only clear pending memories that survived
  workspace memory normalization/cap limits. Use retainedKeys from
  the returned normalized store instead of attemptedKeys.

- Shared sessionID extraction: add sessionIDFromEventProperties()
  helper and use it in both session.compacted and session.deleted,
  fixing the previous gap where session.deleted only read info.id.

- Strengthen compaction refresh test: seed workspace memory before
  first transform so firstSystem1 is non-empty, then assert
  refreshed system[1] preserves existing entries AND contains
  promoted memories.
2026-04-27 10:02:18 +08:00
Ralph Chang 2437a9dc71 fix: clarify cache epoch semantics and add regression tests
- Update plugin.ts comments to describe 'session cache epoch' instead
  of misleading 'session lifetime' wording
- Add regression test: same-session explicit memory does not mutate
  frozen system[1]; pending memory goes to ephemeral system[2+]
- Add regression test: session.compacted intentionally refreshes
  system[1] as a new cache epoch boundary (promotes pending memories,
  clears frozen cache, next transform re-renders workspace memory)
- Both tests use one plugin instance with mutable mock client to
  preserve in-memory frozen cache across turns
2026-04-27 09:55:03 +08:00
Ralph Chang 3560868f52 release: v1.2.3 v1.2.3 2026-04-27 02:24:48 +08:00
Ralph Chang e7c7a5cfb2 feat: add durable pending memory journal 2026-04-27 02:20:26 +08:00
Ralph Chang 026c75a5e4 feat: freeze rendered workspace memory snapshot 2026-04-27 01:57:41 +08:00
Ralph Chang eb74a9f03e docs: add workspace memory cache optimization plan 2026-04-27 01:55:48 +08:00
Ralph Chang f6f35e87c1 feat: release v1.2.2 with multilingual memory hardening v1.2.2 2026-04-27 00:21:18 +08:00
Ralph Chang 6603fe869d docs: add v1.2.1 release notes v1.2.1 2026-04-26 16:58:14 +08:00
Ralph Chang 3d44269228 fix: resolve remaining architect issues - split feedback keys, remove generic config key, supersession mode
- Split feedbackTopicKey: server-error now separate from port-occupied-environment
- Remove generic plugin.*config entity key (too broad), fall back to canonical dedup
- Feedback topic conflicts now use supersession mode (newer beats longer)
- Add 3 regression tests: English port/split, unrelated configs, feedback supersession

70/70 tests pass.
2026-04-26 16:54:24 +08:00
Ralph Chang a154139b27 fix: P0c/P0d architect review corrections
P0c fixes:
- Chinese file count regex now accepts 個/个 between number and 文件
- Admin PIN short reference (<20 chars) passes via config value allowlist
- Phase snapshot uses semantic window (.{0,20}) instead of absolute position

P0d fixes:
- Feedback key split: 500 error and port issue remain separate entries
- extractEntityKey avoids over-merging unrelated plugin configs
- chooseBetterMemory supports supersession mode (newer beats longer)
- Sort comparator now includes source priority as secondary tie-breaker

New regression tests (11 total):
- Real Admin PIN short reference passes
- Real Chinese 37 個文件 snapshot rejected
- Real pathology Phase 1-4 snapshot rejected
- Feedback 500 vs port entries not collapsed
- Unrelated plugin configs not collapsed
- Supersession prefers newer shorter over older longer

67/67 tests pass.
2026-04-26 16:50:58 +08:00
Ralph Chang 7527765207 feat: storage-time dedupe, stale pruning, and supersession (P0d)
- Project/reference entries dedupe by entity key (bilingual aware)
- Decision entries supersede by topic key (parser formats, template, etc)
- Feedback entries supersede by topic key (same issue, newer fix wins)
- Stale compaction/manual entries pruned after staleAfterDays + 30
- Explicit and feedback entries never age-pruned
- Freshness used as tie-breaker in priority-based trimming
- Adds 10 new tests covering dedup, supersession, staleness, and freshness
2026-04-26 16:37:18 +08:00
Ralph Chang f9acfd6136 fix: parser accepts bracketless format, rejects project snapshots, adds durable-content prompt
P0a: Parser now accepts both - [type] text and - type text formats
P0b: Prompt adds durable-content guidance to avoid session-specific snapshots
P0c: Parser quality gate rejects exact test counts, file counts, phase progress
- Only rejects phase progress when it appears early in the string (snapshot)
- Stable config values with numbers (Admin PIN, Scrypt) still pass
- Adds 7 new tests covering bracketless parsing and snapshot rejection
2026-04-26 16:28:55 +08:00
Ralph Chang ca71c20a8f docs: add memory dedup & staleness architecture analysis 2026-04-26 16:20:29 +08:00
Ralph Chang 5e9ada6859 fix: replace default compaction template to prevent purple italic rendering
Root cause: OpenCode's default compaction template uses --- separators.
When our plugin adds structured context (Memory candidates: format), the
model strictly follows the template, outputting --- at position 0. The
markdown textmate grammar treats this as YAML frontmatter, applying the
'comment' syntax scope (purple + italic in themes like palenight).

Fix: Set output.prompt in the compacting hook to replace the entire
template with a ---free version. Uses only ## Markdown headings and
explicitly forbids YAML frontmatter, horizontal rules, and delimiter
lines. Preserves context from other plugins by merging output.context.

- Replace compactionContextHeader() with buildCompactionPrompt()
- Set output.prompt instead of pushing to output.context
- Merge existing output.context from other plugins before clearing
- Add 'Instructions' section to the template (per architect review)
- Update tests: verify output.prompt, ---free format, context merging
2026-04-26 15:46:41 +08:00
Ralph Chang 721544e7a8 fix: use plain text labels instead of Markdown headers
- Changed '## Memory Candidates' to 'Memory candidates:' in compaction context
- Changed '## Pending Todos' to 'Pending todos:' in todo rendering
- Updated extractCandidateBlock() to parse plain text format (primary)
- Removed stripXmlTags() function (no longer needed)
- All 42 tests pass

Root cause: Markdown headings (##) render as purple in OpenCode UI,
same issue as XML tags and HTML comments. Plain text labels avoid
all special markup rendering.
2026-04-26 15:13:58 +08:00
Ralph Chang 32fa2bd454 chore: keep version at 1.2.1 2026-04-26 14:50:19 +08:00
Ralph Chang af539a42f3 chore: bump version to 1.2.2 for HTML comment output format 2026-04-26 14:49:46 +08:00
Ralph Chang eff0d3784c fix: change compaction output to HTML comment, prevent Markdown rendering issues
Root cause: Model was instructed to output <workspace_memory_candidates> XML
tags in the user-visible compaction summary, causing purple/italic rendering
when combined with --- delimiters in Markdown.

Fixes:
- compactionContextHeader(): Now instructs model to use HTML comment format
  <!-- workspace_memory_candidates ... --> which is hidden from users
- extractCandidateBlock(): New function supports 3 formats:
  1. HTML comment (preferred, hidden from user)
  2. Markdown section (visible but clean)
  3. Legacy XML (backward compatible)
- Added "DO NOT use XML tags" and "DO NOT start with ---" instructions

Tests:
- Verify compaction context header uses HTML comment format
- Test parser accepts all 3 formats (HTML comment, Markdown, legacy XML)
2026-04-26 14:49:38 +08:00
Ralph Chang 2354b62350 chore: bump version to 1.2.1 for compaction context fix 2026-04-26 14:35:18 +08:00
Ralph Chang 92e90124de fix: prevent XML tags in compaction context from causing Markdown rendering issues
- Add stripXmlTags() to convert <workspace_memory>, <hot_session_state>, <pending_todos> to Markdown headers for compaction context
- Add [PRIVATE COMPACTION CONTEXT - DO NOT OUTPUT] wrapper to prevent model from copying input context to output
- Rename renderTodos to renderTodosForCompaction for clarity
- Add test to verify compaction context contains no XML tags

This fixes the issue where compaction summary would render with purple italic text
due to --- delimiters interacting with XML-like tags in Markdown.
2026-04-26 14:34:55 +08:00
Ralph Chang 22774c5ed2 docs: add RELEASE_NOTES.md for v1.2.0 v1.2.0 2026-04-26 14:18:34 +08:00
Ralph Chang 9892012d8b chore: prepare for v1.2.0 release
- Bump version to 1.2.0
- Add package.json exports and files whitelist
- Update .gitignore to exclude .opencode/ and .opencode-agenthub/
- Fix docs: active files tracked in tool.execute.after (not before)
- Fix docs: exitCode undefined is ignored (not success)
- Fix docs: session ID is hashed in storage path
- Fix docs: workspace memory survives within same workspace
2026-04-26 14:17:54 +08:00
Ralph Chang f988af4453 docs: enhance README with visual three-layer architecture diagram
- Add table showing layer scope, tracking, and persistence
- Add visual ASCII diagram emphasizing cross-session capability
- Add compaction flow diagram showing no extra API call
- Highlight piggyback on existing compaction summary
2026-04-26 13:43:06 +08:00
Ralph Chang 606dcfac12 docs: fix hook names and prompt tags in documentation
- Fix outdated hook names: prompt:before → experimental.chat.system.transform
- Fix outdated hook names: tool.execute.before → (removed, file tracking is in tool.execute.after)
- Fix outdated hook names: compaction:before → experimental.session.compacting
- Add missing event hook documentation
- Fix README example to show correct <hot_session_state> tag instead of <workspace_memory_candidates>
2026-04-26 13:36:49 +08:00
Ralph Chang 802ef62636 docs: update documentation to Memory V2 architecture
- Replace four-tier architecture with three-layer Memory V2
- Remove references to non-existent tools (core_memory_*, working_memory_*)
- Update storage paths to ~/.local/share/opencode-working-memory/
- Update configuration to LONG_TERM_LIMITS and HOT_STATE_LIMITS
- Fix installation verification to check system prompt instead of tools
2026-04-26 13:27:14 +08:00
Ralph Chang ff4639d153 fix: PR-2 memory plugin behavior improvements
## Task 5: Canonical exact dedupe
- Already implemented in PR-1 with enforceLongTermLimits()
- Source priority: explicit > manual > compaction
- Same source: higher confidence wins

## Task 6: Structured negative guard
- Add isNegatedMemoryRequest() for adjacency detection
- "不要記住" / "don't remember" are now properly ignored
- "not forget to remember" no longer false positive (not a directive)
- Restrict patterns to line-start (^|\n) to avoid mid-sentence matches

## Task 7: Compaction quality gate
- Add shouldAcceptWorkspaceMemoryCandidate() predicate
- Reject low-quality candidates: git hashes, errors, stack traces
- Reject temporary progress, code signatures, path-heavy facts
- Only accept entries with >= 20 chars

## Pattern improvements
- All patterns use matchAll() with proper g flag
- Dedupe by canonical text in extractExplicitMemories()
- Line-start anchor prevents "to remember" mid-sentence matches
- Add more trigger patterns: save/add to memory, commit to memory

Tests: 36 passing
2026-04-26 13:06:36 +08:00
Ralph Chang 1bba0511bb fix: PR-1 memory plugin quality fixes
## Task 1: Fix exitCode undefined false positive
- Add `typeof exitCode !== "number"` check in plugin.ts
- Only extract errors when exitCode is explicitly non-zero
- Prevent git-log/cat with "errors" text from creating false positives

## Task 2: Fix workspace memory XML truncation
- Budget-aware line-by-line rendering
- Always include closing </workspace_memory> tag
- Return empty string when budget too small
- Bonus: canonical exact deduplication with source priority

## Task 3: Remove "always" as trigger
- Replace "always" with "going forward" in patterns
- Add word boundary via `g` flag and matchAll loop
- "from now on" still works as expected

## Task 4: Verification
- 22 tests passing
- typecheck passing

Tests cover:
- git log/cat with loose "errors" ignored
- TS2345/TypeError strong signals captured
- undefined exitCode: no create, no clear
- exitCode 0: clears errors
- exitCode non-zero: creates error
- XML never truncated mid-tag
- "always" not a trigger
2026-04-26 12:52:21 +08:00
Ralph Chang 2d7cb6cdf4 fix: strengthen plugin regression test with strong error signals
- Use TS2345 error instead of loose 'errors' word
- Add try/finally for temp directory cleanup
- Remove duplicate placeholder test block
- Clarify quality gate placement in parseWorkspaceMemoryCandidates()
2026-04-26 12:26:42 +08:00
Ralph Chang 9f9763c0e1 docs: add comprehensive memory plugin quality fixes plan
- PR-1: Fix bash error false positive, XML truncation, remove always trigger
- PR-2: Canonical exact dedupe, structured negative guard, quality gate
- Add executable plugin hook regression tests
- Add source priority for explicit > manual > compaction
- Define quality gate predicates with test matrix
2026-04-26 12:23:39 +08:00
Ralph Chang df54232fb9 refactor: simplify entry point to v2 architecture
- Replace 2000+ line monolithic index.ts with thin wrapper importing MemoryV2Plugin
- Update package.json description to reflect three-layer architecture
- Add test script for Node.js built-in test runner
2026-04-26 11:13:57 +08:00
Ralph Chang 72dc919ece chore: ignore worktrees directory 2026-04-25 18:20:42 +08:00
Ralph Chang 4832b382b6 fix: silence memory load errors in working-memory v1.1.2 2026-02-19 21:13:20 +08:00
Ralph Chang 17258ce60f fix: use SDK API instead of sqlite3 CLI for cross-platform compatibility
- Replace sqlite3 CLI with client.session.messages() and client.session.todo()
- Fix message scan order: API returns oldest-first, now scans backwards
- Include cache.read in total token calculation
- Skip in-progress messages with zero tokens
- Silent error handling (no console.error for expected failures)
v1.1.1
2026-02-19 13:43:26 +08:00
Ralph Chang 6fad91953c docs: improve token-usage section readability 2026-02-18 16:59:47 +08:00
Ralph Chang 7b33b51c1e docs: add token-usage guidance for session patterns 2026-02-18 16:57:40 +08:00
Ralph Chang 2edb643667 chore: bump version to v1.1.0 v1.1.0 2026-02-18 16:44:17 +08:00
Ralph Chang d7302e531a perf: move core memory guidelines from system prompt to tool description 2026-02-18 16:39:21 +08:00
Ralph Chang bb929fc578 Clean up comments, fix docs, bump to v1.0.1 v1.0.1 2026-02-18 14:13:37 +08:00
Ralph Chang 98e5ecaa91 Fix installation: no npm install needed, OpenCode auto-installs from config 2026-02-18 11:08:09 +08:00
Ralph Chang c008fb860f Fix Quick Start: agent prompts instead of CLI commands 2026-02-18 10:59:22 +08:00
Ralph Chang c743ddb331 Restore Quick Start example commands 2026-02-18 10:58:15 +08:00
Ralph Chang 0631286962 Improve README: simplify Quick Start and remove Phase labels 2026-02-18 10:51:01 +08:00
Ralph Chang 75c89747d8 Fix typecheck errors and update install docs for npm release 2026-02-18 10:46:03 +08:00
Ralph Chang 605524b674 Improve ASCII diagram alignment in README
- Fine-tuned spacing and padding for better visual alignment
- Ensured consistent right border alignment across all boxes
v1.0.0
2026-02-18 10:15:53 +08:00
Ralph Chang 22cfd6ee3a Fix pressure thresholds and ASCII diagram alignment
- Corrected pressure levels: 75% (moderate) / 90% (high)
- Removed incorrect 'critical' level (95%)
- Fixed ASCII diagram alignment in README
- Updated all documentation to match actual code implementation
- Pruning modes: < 75% (normal), 75-89% (aggressive), ≥ 90% (hyper-aggressive)
2026-02-18 10:13:28 +08:00
Ralph Chang 4b862ee79c Fix ASCII diagram alignment in README
- Adjusted box borders for proper alignment
- Fixed spacing and padding
- Ensures monospace font rendering consistency
2026-02-18 10:10:56 +08:00
Ralph Chang 5c7dd0f421 Update GitHub URLs: yourusername → sdwolf4103
- Updated package.json repository URLs
- Updated README.md installation and support links
- Updated docs/installation.md clone URL
- Updated AGENTS.md clone URL
2026-02-18 10:10:03 +08:00
Ralph Chang 484cb420ca Revert "Rename project: opencode-working-memory → oh-my-memory"
This reverts commit bf11c9d55c.
2026-02-18 10:06:20 +08:00
Ralph Chang bf11c9d55c Rename project: opencode-working-memory → oh-my-memory
- Updated package.json name and URLs
- Updated README.md title and references
- Updated docs/installation.md install commands
- Updated AGENTS.md project name
- Follows oh-my-opencode naming convention
2026-02-18 09:57:46 +08:00
Ralph Chang 32d5ddfb50 Initial commit: OpenCode Working Memory Plugin v1.0.0
- Four-tier memory architecture (Core, Working, Pruning, Pressure)
- Phase 1: Core Memory blocks (goal/progress/context)
- Phase 2: Smart Pruning with adaptive thresholds
- Phase 3: Working Memory with slots + pool decay
- Phase 4: Pressure monitoring with interventions
- Phase 4.5: Storage governance (session cleanup + cache sweep)
- Complete documentation (README, AGENTS, installation, architecture, configuration)
- MIT licensed
2026-02-18 09:49:09 +08:00