feat(learn): learn team conventions from corrections and deliver them by retrieval
Issue for this PR
No issue: new feature. Design, research and benchmark results are in research/rsi-workspace-learning-2026-09-30/ (learn-v1-plan.md, learn-v1-results.md). The benchmark harness is in #1407, which should merge after this PR.
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Adds altimate-code learn: the agent learns team conventions from corrections and gets the relevant ones back in later sessions. Local mode only; nothing is shared with a workspace unless you run learn promote --publish.
How it works
- Capture (opt-in,
learn enable): user corrections, repeated tool failures, and review/CI feedback become redacted signals in.altimate-code/learn/. - Reflect: a model proposes lesson edits (add, edit, remove, supersede). The curator lints them, redacts secrets, dedupes, and refuses silent contradictions. Automatic after 3 signals, 10 idle minutes, or the end of
run. - Promote: a person reviews the diff (
learn show,learn promote). Nothing reaches the agent before this step.rollback,reject,pin/unpinare available. - Deliver: the harness, not a tool call, puts lessons in context. Up to 15 core and 15 retrieved lessons (BM25 over text and path triggers) form a session-start section frozen for the session, so the prompt cache holds. Per-request and per-file additions are appended to the message or tool result. All limits are configurable (
learn.*). - Seed:
learn bootstrapreads past sessions;learn import-reviewsreads human review comments on merged GitHub PRs. Both show the scope and ask before sending anything.
Kill switch: learn.enabled: false or ALTIMATE_LEARN=0 turns off lesson delivery, capture, auto-reflection and the TUI nudge together (default on). Explicit learn commands still run.
Behaviour change for existing users: none unless they opt in. Capture and auto-reflect default to off. Delivery runs only when a project already has an approved approved.json; it never blocks a session (lock wait capped at ~5 s, unreadable stores skipped) and does not rewrite approved.json (usage counters live in git-ignored usage.json). With learning off, the TUI may show one dismissible tip after two corrections in a session (at most 3 in total; learn nudge off).
Other changes:
skill publish --replaceupdates your own same-name skill published from another checkout.- Learn-managed skills are excluded from automatic skill loading, so lessons are not delivered twice.
learnconfig:capture,auto_reflect,modeland the session-start limits are in the shared config schema; the otherlearnkeys are file/env only. The SDK is unchanged.runwaits for its own session's reflection at exit for at most 60 seconds.import-reviewskeeps only comments by owners, members and collaborators made before merge (--any-authorwidens it).
Known limits (in the docs):
- Retrieval is keyword-based.
- A second, unrelated request in a session gets only about 60% of the lessons it needs.
- A keyword match occasionally applies a lesson outside its scope.
- Review import is GitHub only.
- Team sharing per lesson needs workspace-memory backend work (
backend-requirements.md).
How did you verify your code works?
- Unit tests: 1,818 tests in
test/altimate/learn/, including a frozen guard-rail corpus for redaction and lint, and regressions for every review finding (lock recovery, rejected-only reflections, malformed stores, redaction forms, publish adoption). - Checks on the current head: typecheck, Marker Guard and the tracker-leak check pass. The full suite was last run before the review fixes: 15,988 pass / 8 fail, the same 8 that fail on
main(mcp.headers ×5, HttpApi SDK, mcp status, v2 SDK error shape); CI runs it on this head. - Benchmarks: 610 agent runs on a dbt project (Gemini 3.5 Flash; Claude was unavailable to the benchmark project).
- No lessons → 4 real lessons: held-out tasks 2/9 → 9/9 (only runs whose agent turn completed count).
- Retrieval with 50, 300 and 1,000 stored lessons: every needed lesson shown, held-out 9/9 at each size, first call constant at ~21k tokens.
- Loading all 1,000 lessons instead costs 34% more per run.
- Outdated lessons are retired by learning: 0/9 → 9/9.
- Bootstrap from 8 past sessions → 9/9, for $0.20.
- Over-application: a staging-only lesson was applied to an analysis in 1 of 6 control runs in three retrieval arms.
- Full tables:
learn-v1-results.md.
- Smoke test: enable → correct the agent → reflect → promote → a new session receives the lesson.
- Reviews: an independent review (15 findings) and 130 bot comments, all fixed or answered on the threads.
Screenshots / recordings
No visual UI except the one-line TUI tip.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
🤖 Generated with Claude Code
[!NOTE]
Medium Risk
New prompt-injection surface (approved lessons in every session) and model calls during reflection/bootstrap, mitigated by curator lint, redaction, and mandatory promote; delivery is fail-soft but can affect agent behavior once lessons are approved.
Overview
Introduces altimate-code learn: an opt-in pipeline that turns corrections, repeated tool failures, and review/CI feedback into human-approved lessons stored under .altimate-code/learn/, then injects relevant rules into agent sessions without a tool call.
Pipeline: capture (pattern-based correction classifier + tool-retry signals, redacted) → reflect (model proposes edits; deterministic curator lints, dedupes, conflict handling via backtick anchors) → promote gate → delivery (frozen session-start “Team rules”, BM25 retrieval, per-request and per-file hooks, token budgets). Cross-process locks/claims protect concurrent reflection; bootstrap and import-reviews seed history with confirmation/dry-run.
Integration: learn settings added to shared config schema (packages/core); instance bootstrap starts capture/scheduler when enabled; run can auto-reflect on exit (bounded wait). TUI nudge when capture is off; ALTIMATE_LEARN master switch. Docs (configure/learn.md) and GitGuardian ignores for synthetic credential tests.
Reviewed by Cursor Bugbot for commit ceec300a69d71349576193305c2e785d7840a2f6. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
-
New Features
- Added
learnworkflows to capture corrections and repeated tool failures, reflect on feedback, and manage lessons through review, approval, search, pinning, and rollback. - Approved lessons can be delivered at session start and in response to relevant requests or files, with configurable limits.
- Added imports from historical sessions and GitHub reviews, and optional prompt inclusion in trajectory exports.
- Added a TUI reminder when learning is off after repeated corrections.
- Added
skill publish --replacefor eligible name conflicts.
- Added
-
Documentation
- Added a guide to configuring and using learning workflows.