feat: observational memory — programmatic extraction + observation block#70
Merged
platypusrex merged 7 commits intomainfrom Feb 23, 2026
Merged
feat: observational memory — programmatic extraction + observation block#70platypusrex merged 7 commits intomainfrom
platypusrex merged 7 commits intomainfrom
Conversation
…ractors, builder, tests Implements Phase 0 of observational memory (issue #65): - src/memory/types.ts: Observation type with source field for LLM fast-follow - src/memory/store.ts: SQLite-backed observation persistence - src/memory/extractors.ts: Programmatic extractors for 8 tool types - src/memory/working-memory.ts: Observation block builder with dedup + token budget - src/session/migrations.ts: Migration v5 adds observations table - src/session/db.ts: setDatabaseForTesting helper for test injection - tests/test-memory.ts: 37 tests covering extractors, store, and builder
…ompt Integration layer: - SystemPromptContext gains observationBlock field (shared.ts) - Build and plan mode prompts include observation block after env block - RunAgentArgs accepts observationBlock, passes to SystemPromptContext - use-agent-submit extracts observations after each tool result - use-agent-submit builds observation block before each runAgent call - Fixed lint: removed unused ObservationType import, replaced non-null assertion
…bservation storage W1: Use argsByIndex map to capture tool args at onToolCall time instead of fragile store.getPendingDisplayMessages() lookup. O(1) vs O(n), no coupling to store internals. W2: Wrap observation extraction + storage in try/catch so SQLite errors cannot crash the agent loop. Observational memory is non-critical.
Logs observation block char count to debug.log when present, making it visible during manual testing.
…mpt pipeline 7 integration tests proving observations flow through the complete pipeline: extractors → SQLite store → block builder → SystemPromptContext → system prompt. Validates block placement, deduplication, session isolation, read omission, denied/blocked handling, and both build + plan mode prompts.
🦋 Changeset detectedLatest commit: 0a0e8a5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Apply MAX_ERRORS=10 cap at render time so error-heavy sessions don't blow up the observation block. Fix blank line in build/plan prompts when observationBlock is null. Document staleness limitation in plan doc.
This was referenced Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds observational memory (Phase 0) — programmatic extraction of structured observations from tool calls, stored in SQLite, injected into the system prompt. Observations survive compaction because they live in a separate table, not in message history.
Closes #65. Follow-up LLM-based extraction tracked in #69.
What it does
After every tool call, pure-function extractors produce typed observations from the tool name, args, and result. These are stored in SQLite and formatted into an
<observations>block injected into the system prompt before each LLM call.Extracted observations:
edit_filefile_modifiedwrite_filefile_createdread_filefile_readrun_command(success)command_runrun_command(failure)command_errorglob/grepsearch_performedtodo_writetodo_updatedtasktask_delegatedObservation block in system prompt:
Key design decisions:
SystemPromptContext.observationBlockfield (not string concatenation) — prompt content belongs in the prompt layersource: "programmatic" | "llm"on the Observation type — future-proofs for LLM extraction (feat: Observational Memory v2 — Observer/Reflector context management #69)onToolCalltime via Map, not looked up from store at result timeFiles changed
New (6):
src/memory/types.ts— Observation type definitionssrc/memory/store.ts— SQLite persistence layersrc/memory/extractors.ts— Programmatic extractors for 8 tool typessrc/memory/working-memory.ts— Observation block builder with dedup + token budgettests/test-memory.ts— 37 unit teststests/test-memory-integration.ts— 7 integration tests (full pipeline)Modified (7):
src/session/migrations.ts— Migration v5: observations tablesrc/session/db.ts—setDatabaseForTestingfor test injectionsrc/agent/prompts/shared.ts—observationBlockon SystemPromptContextsrc/agent/prompts/build.ts+plan.ts— Include observation blocksrc/agent/index.ts—observationBlockon RunAgentArgs, debug loggingsrc/tui/hooks/use-agent-submit.ts— Extract observations + build blockTesting
Out of scope