feat: context store, lazy recall, hooks, and self-documenting hints#6
Merged
santoshkumarradha merged 17 commits intomainfrom Mar 26, 2026
Merged
feat: context store, lazy recall, hooks, and self-documenting hints#6santoshkumarradha merged 17 commits intomainfrom
santoshkumarradha merged 17 commits intomainfrom
Conversation
New commands: plandb context "what you learned" --type discovery # attach context to project graph plandb search "query" # BM25-ranked search across everything plandb contexts [--kind decision] # list context entries plandb prune <id> # remove context entry Context entries are project-wide knowledge that persists across sessions, searchable via SQLite FTS5 (BM25 ranking). Unlike task notes (scoped to one task), context is queryable across the entire project graph. Types: discovery, decision, pattern, blocker, reference Optional: --task (link to task), --tags (comma-separated) Search returns ranked results from both context entries AND task descriptions, giving agents a unified knowledge base across the project graph. Zero dependencies — FTS5 is built into SQLite (bundled with rusqlite).
Previously context entries were limited to 5 hardcoded types: discovery, decision, pattern, blocker, reference. Now --type is a freeform string — agents define their own types based on their domain: constraint, observation, bug, milestone, hypothesis, metric, api-change, etc. This makes the context store domain-agnostic and extensible without code changes. IDs now use c- prefix (ctx-). Also fixed search output display (showed [?] instead of [ctx]).
Changes based on AI agent + product designer critique:
1. --type renamed to --kind (consistency with PlanDB conventions)
2. Auto-link to current running task when adding context
(agents no longer need to pass --task explicitly)
3. Fixed search output source tag ("context" → [ctx])
4. IDs now use c- prefix for context entries
The auto-link feature is the key ergonomic improvement: agents
adding context mid-task get automatic task association without
tracking IDs. This mirrors how humans naturally annotate work.
When an agent claims a task with `plandb go`, the response now automatically includes relevant context entries from the project's knowledge base. BM25 search extracts key terms from the task title and description, returning up to 3 matching context entries. This eliminates the need for agents to explicitly search before starting work — discoveries, decisions, and constraints are surfaced proactively. Applied to all three interfaces: CLI, MCP, and HTTP.
Shell commands that execute at task state transitions:
- pre_hook fires when task transitions to running (plandb go)
- post_hook fires when task transitions to done (plandb done)
Environment variables set for hooks:
PLANDB_TASK_ID, PLANDB_PROJECT_ID, PLANDB_TASK_TITLE, PLANDB_AGENT_ID
Hooks are advisory — failures print warnings but never block operations.
Included in export/import templates for replayable procedures.
Usage:
plandb add "Run linter" --pre-hook 'echo "starting $PLANDB_TASK_TITLE"' \
--post-hook 'echo "done: $PLANDB_TASK_ID"'
Every CLI response now teaches the agent what it can do next: - init: shows dependency syntax and core loop - go: shows context, split, search, and done commands - done: shows reassess, next task, insert, and parallel options The primary user of PlanDB is the agent, not the human. CLI output is self-documenting — agents auto-discover features.
…scovery The prompt now covers all new features: - Lazy recall: plandb go auto-surfaces relevant context - Hooks: --pre-hook/--post-hook for task automation - Context store: discovery/decision/pattern with BM25 search - Templates: export/import with context entries - Self-documenting: "every command shows hints — read them" Prompt stays compact at 120 lines (was 110 before new features).
MCP prompt now includes context store, lazy recall, hooks, and templates so Claude Code / Cursor / Windsurf users get the same feature awareness.
Hints shown after claiming a task are now tailored to the task kind: - research: record discoveries and decisions - code: record design choices, split if complex - test: record test gaps/bugs, check known issues - review: record findings, annotate tasks with feedback - generic: general-purpose hints Also adds task kind to go response JSON for downstream use.
Prompt now teaches agents about recursive decomposition and cross-level dependencies — the most powerful and unique PlanDB features. Agents learn they can: split to any depth, zoom with use/use.., and create dependencies between tasks at different hierarchy levels.
Three new HTTP endpoints: POST /context — create context entry (auto-links to running task) GET /contexts?project_id=X&kind=Y — list context entries GET /search?project_id=X&q=query — BM25 search across context + tasks All three interfaces now have full context/search support: CLI, MCP (pending), and HTTP.
Three new MCP tools for Claude Code / Cursor / Windsurf users: plandb_context_create — add context entry (auto-links to running task) plandb_search — BM25 search across context + tasks plandb_context_list — list context entries with optional kind filter All three interfaces now have complete context/search support: CLI: plandb context / plandb search / plandb contexts MCP: plandb_context_create / plandb_search / plandb_context_list HTTP: POST /context / GET /search / GET /contexts
The help output now covers all features: - Context store & search (BM25, lazy recall, auto-link) - Templates as learning framework (browse, import, export, compound) - Resume for session continuity Agents reading --help get the complete picture.
Fixes: - P0: Context --kind default changed from "note" to "discovery" (consistent) - P0: Fixed --type references in help text → --kind (correct flag name) - Slimmed go_cmd hints from 9 lines to 2 (token efficient) - Slimmed done_cmd hints from 8 lines to 1-2 Removed: - 4 redundant security audit templates (kept simple + comprehensive) - 6 redundant examples (kept 5 that each show unique capability) Templates: 12 → 8 (each adds unique value) Examples: 11 → 5 (no redundancy)
Review findings: - README copy-paste prompt was missing context/search/hooks — agents copying it got no awareness of the most valuable new features - README CLI Reference had no context store or hooks section - examples/PLANDB_PROMPT.md had no context/search commands - --help referenced plandb resume and plandb templates (nonexistent in this branch) Fixes: - README copy-paste: added context, search, lazy recall mention - README CLI Reference: added Context Store & Search + Hooks sections - PLANDB_PROMPT.md: added context/search commands + lazy recall note - --help: removed resume/templates references, kept import/export
Member
Author
Code ReviewWhat's in this PR (features 1-4 + prompt sync)
What's NOT in this PR (confirmed absent)
Review findings (all fixed)
Code quality
8/8 tests pass, clean build. Ship it. |
Templates (browse, learning framework) are a separate feature not in this PR. export/import commands exist but the template workflow shouldn't be taught to agents in prompts for features that don't include it. Removed from: - CLI prompt: Templates (Replayable Procedures) section - MCP prompt: templates line in Key Concepts - --help: TEMPLATES section - done_cmd: "plandb export > template.yaml" completion hint export/import commands still exist and work — just not advertised in prompts until the template feature PR lands.
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
Four agent-facing platform features that make PlanDB self-discoverable and knowledge-persistent. No templates, no examples, no docs — pure infrastructure that every downstream feature builds on.
1. Context Store with BM25 Search
Graph-native knowledge base. Agents record what they discover mid-task, and it persists across sessions.
--kindis freeform (not an enum) — agents define their own taxonomy--taskflag needed)2. Lazy Recall
When
plandb goclaims a task, BM25 auto-searches context using the task's title+description and injects up to 3 relevant entries. Agents get knowledge without explicitly searching.Zero prompt tokens needed to teach this — it just appears in the
goresponse.3. Task Lifecycle Hooks
--pre-hookand--post-hookshell commands on tasks. Fire at state transitions with env vars (PLANDB_TASK_ID,PLANDB_TASK_TITLE, etc.). Advisory — failures warn but never block. Included in template export/import.4. Contextual Action Hints
Every CLI response teaches the agent what to do next. Kind-aware:
researchtasks hint "record discoveries",codetasks hint "split if complex". Also teaches compound graph features (recursive split, cross-level deps).+ Prompt Sync
All 3 interface prompts (CLI, MCP, HTTP) and
--helpupdated to cover these features. Includes bug fixes:--kinddefault corrected to "discovery", help text references fixed from--typeto--kind, hints slimmed from 9 lines to 1-2.Validation
Files changed (14 source files, 1147 lines)
db/learnings.rs,db/schema.rs,db/mod.rscli/task/helpers.rs,cli/task/commands.rsgodb/tasks.rs,db/templates.rs,models/task.rs,db/tests.rscli/task/commands.rs,cli/mod.rsmcp/tools.rsserver/routes.rsmain.rsTest plan
cargo build— cleancargo test— 8/8 passplandb gogo, slimmed output ondone