← Back to PRs

#10591: feat(hooks): add session-start-memory bundled hook

by morningstar-daemon open 2026-02-06 18:04 View on GitHub →
stale
## Summary Adds a new internal hook that loads workspace memory files into session context at agent bootstrap, making memory loading **structural** instead of **optional**. ## Problem Agents often suffer from "amnesia" - they forget to read their memory files at session start, losing continuity across sessions. Manual memory loading is voluntary and easily skipped. ## Solution This hook runs at `agent:bootstrap` (before any user messages are processed) and automatically injects workspace memory into session context. Memory loading becomes **unskippable**. ## What It Does 1. **Loads configured paths** - Default: `MEMORY.md`, `memory/continuity-test.md` 2. **Loads recent memory** - Finds `memory/YYYY-MM-DD*.md` files from last N days 3. **Injects into context** - Creates `CURRENT_SESSION_MEMORY.md` in bootstrap files 4. **Runs before first message** - Memory is already loaded before agent processes anything ## Configuration ```json { "hooks": { "internal": { "entries": { "session-start-memory": { "enabled": true, "paths": ["MEMORY.md", "memory/continuity-test.md"], "recentDays": 2 } } } } } ``` | Option | Type | Default | Description | |--------|------|---------|-------------| | `paths` | `string[]` | `["MEMORY.md", "memory/continuity-test.md"]` | Files to always load | | `recentDays` | `number` | `2` | Days of recent memory to load | ## Use Cases - **Continuity testing** - Load test questions that verify agent remembers recent work - **Long-term memory** - Inject curated `MEMORY.md` every session - **Recent context** - Auto-surface last few days of work - **Session checklists** - Ensure critical context is always present ## Design Decisions - **Optional by default** - Users opt-in via config - **Graceful degradation** - Missing files are skipped silently - **Generic implementation** - Works with any markdown-based memory system - **No external dependencies** - Pure Node.js fs operations - **Follows existing patterns** - Matches `session-memory` and `boot-md` structure ## Testing Tests cover: - Event type filtering (only runs on `agent:bootstrap`) - Default path loading - Recent file discovery and date filtering - Configuration options (`paths`, `recentDays`) - Missing file handling - File sorting (newest-first) - Edge cases (missing workspace dir, empty memory) ## Related PRs - #9677 - Exposes `incomingMessage` to bootstrap hooks (complementary) - #9782 - Adds `session:start`/`session:end` hooks (different scope - command lifecycle) This PR focuses on making workspace memory loading automatic and structural, solving the amnesia problem for agents that maintain markdown-based memory systems. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> - Adds `session-start-memory` bundled internal hook that runs on `agent:bootstrap` and injects a generated `CURRENT_SESSION_MEMORY.md` bootstrap file with content loaded from workspace paths and recent `memory/YYYY-MM-DD*.md` files. - Introduces Vitest coverage for default paths, recent file discovery/sorting, config overrides, and missing-file scenarios. - Updates Slack extension read action to pass `threadId` through to runtime Slack handler. - The hook implementation currently has correctness/security gaps around config enablement, path confinement, and date handling that should be addressed before merge. <h3>Confidence Score: 2/5</h3> - This PR should not be merged as-is due to a path traversal risk and config/behavior mismatches in the new bundled hook. - The new hook reads user-configured paths and joins them directly to `workspaceDir`, allowing `../`/absolute-path reads outside the workspace and injecting their contents into session context. Additionally, the hook ignores its own `enabled` flag (conflicts with the documented disabling behavior) and has timezone-sensitive date filtering that can misclassify recent files. Slack change looks straightforward, but the hook issues are blocking. - src/hooks/bundled/session-start-memory/handler.ts <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs