Commit Graph

8 Commits

Author SHA1 Message Date
roboomp 34005e6656 fix(coding-agent/hindsight): reacted to live bank scope changes and flushed before dispose
Mid-session edits to hindsight.bankId / bankIdPrefix / scoping kept the
active HindsightSessionState pinned to the bank selected at session
start, so retain/recall/reflect calls landed in the stale bank. Settings
hooks now fire onHindsightScopeChanged; the backend rebuilds the
primary state against the recomputed scope, disposing the previous one
after flushing its queue so queued tool-initiated retains still land in
the bank they were enqueued for.

Also:
- Renamed ensureBankMission to ensureBankExists. The old version
  skipped creation entirely when bankMission was blank, so the first
  mental-model POST (auto-seed) could land against a never-PUT bank.
  Bank creation is now idempotent and unconditional, and runs before
  mental-model bootstrap.
- Fixed AgentSession.dispose to flush the retain queue BEFORE clearing
  the session state pointer. Reversed, HindsightRetainQueue.#doFlush's
  identity guard would see the cleared pointer and drop the spliced
  batch with a 'session vanished' warning.
- Snapshotted hindsightScopeCallbacks before iterating because each
  rebuild subscribes a fresh callback inside the same fire; iterating
  the live Set would spin.

Fixes #1902
2026-06-05 05:25:45 +00:00
roboomp 66b6597829 fix(mnemopi): populated memory_embeddings on remember and auto-derived queryEmbedding on recall
The beam backend never invoked the embedding pipeline during normal
operation: `remember()`/`rememberBatch()`/`updateWorking()` skipped `embed()`
entirely and `recall()`/`recallEnhanced()` never called `embedQuery()` on
the query text. As a result `memory_embeddings` stayed empty in every
deployment and recall silently degraded to FTS-only regardless of the
configured provider (fastembed, OpenAI-compatible API, custom).

- Added `scheduleEmbedding` on `beam.pendingExtractions` (mirroring
  `scheduleFactExtraction`) and wired it from `remember`, `rememberBatch`,
  `updateWorking`, and `consolidateToEpisodic`. Writes
  `INSERT OR REPLACE INTO memory_embeddings(memory_id, embedding_json, model)`
  with the active runtime-options model, captured before the AsyncLocalStorage
  scope exits and re-entered inside the task.
- Auto-derived `queryEmbedding` inside `recall()` via `embedQuery(query)` when
  the caller did not pass one. `queryEmbedding: null` is preserved as the
  explicit FTS-only opt-out; `undefined` triggers auto-derive.
- Propagated `queryEmbedding` through `Mnemopi`'s `toRecallOptions` so the
  facade no longer strips the override on the way to the beam layer.
- Made `Mnemopi.recall`/`recallEnhanced`/`search`/`query`, the module-level
  exports, `BeamMemory.recall`/`recallEnhanced`, the free `recall`/`recallEnhanced`,
  and `orchestrateRecall` async. MCP `handleToolCall`/`callToolJson`/`handleJsonRpc`
  follow suit so the recall handler can await.
- Fixed `withBeam`/`withSharedBeam` to defer `beam.close()` until the async
  handler resolves; otherwise the new async recall hit
  `RangeError: Cannot use a closed database`.
- Updated CLI, MCP entrypoints, coding-agent `MnemopiSessionState`, and every
  affected test to await the new shapes.

Verified with a new regression suite (`test/issue-1832-embedding-population.test.ts`)
exercising both ends of the bug: empty `memory_embeddings` and zero
`dense_score`.

Fixes #1832
2026-06-04 09:22:07 +00:00
can1357 68430dee5c chore: renamed mnemosyne package to mnemopi
- Updated package name, directory, and binary from mnemosyne to mnemopi.
- Updated all lockfile references and workspace paths accordingly.
2026-05-31 08:45:12 +02:00
can1357 6d5aba8397 feat: implemented Mnemosyne memory state typing for prompt generation
- Resolved memory backend before instruction assembly and used it to build developer instructions.
- Added a `memoryRootEnabled` prompt option when the memory backend id is `local`.
- Typed Mnemosyne memory state types and updated `registerMnemosyneState()` to call `setMnemosyneSessionState()`.
- Documented that `@oh-my-pi/pi-mnemosyne/diagnose` export was added in the mnemosyne changelog.
2026-05-30 16:55:53 +02:00
can1357 6b4accd05e feat(memory): added memory_edit tool and stats/diagnose commands
- Added `memory_edit` tool for update, forget, and invalidate operations on Mnemosyne memories by id.
- Added `stats` and `diagnose` methods to `MemoryBackend` interface with Mnemosyne implementations.
- Exposed `/memory stats` and `/memory diagnose` slash commands in TUI and ACP modes.
- Refactored recall output to include memory ids via `formatScopedRecallWithIds`.
2026-05-30 16:48:02 +02:00
can1357 515887fc31 test(testing): added Mnemosyne lifecycle and render-call suppression tests
- Added tests for `MnemosyneSessionState` lifecycle, including turn-based auto-retain.
- Added tests covering scoped Mnemosyne database clearing and per-project bank derivation.
- Added a task renderer test to suppress per-task previews when `renderContext.hasResult` is true.
2026-05-30 16:22:12 +02:00
can1357 395dddbc69 feat(mnemosyne): added fallback recall query for shared bank in per-project-tagged mode
- Strips project-bank tokens from the query before a second recall pass on the global bank.
- Prevents broad user-preference memories from being missed when the query is packed with project-specific tokens.
- Added helper functions for bank name tokenization, phrase stripping, and query normalization.
2026-05-30 14:47:54 +02:00
can1357 6618bfb4f4 refactor(tools): renamed Hindsight tools to Memory and fixed per-bank db paths
- Renamed HindsightRecall/Reflect/RetainTool classes and files to Memory* for backend-neutral naming.
- Fixed Mnemosyne state to resolve separate db paths per bank instead of sharing one file.
- Updated test file and all imports to reflect the new names.
2026-05-30 14:47:54 +02:00