plugins icon indicating copy to clipboard operation
plugins copied to clipboard

continual-learning: write to user-scoped memory file by default

Open yuranich opened this issue 6 months ago • 0 comments

Summary

Make the continual-learning plugin safe to enable inside team repositories.

Today the plugin defaults to writing learned bullets into the workspace AGENTS.md and keeping its cadence + incremental-index state under .cursor/hooks/state/. On a shared repo both of those paths are owned by every contributor, so:

  • personal preferences end up committed into the team's instructions, and
  • the two state JSON files permanently show up in git status as untracked noise (or get committed by accident).

This PR moves the defaults to user-scoped locations under ~/.cursor/projects/<workspace-slug>/ — the same directory layout Cursor already uses for agent-transcripts/ — and keeps any write inside the repo strictly opt-in.

What changes

  • New defaults
    • Memory file: ~/.cursor/projects/<slug>/AGENTS.local.md (personal, never committed). Cursor's stacked AGENTS.md loading picks it up automatically.
    • State dir: ~/.cursor/projects/<slug>/continual-learning/ with cadence.json (hook state) and index.json (incremental index).
  • Opt-in shared file via CONTINUAL_LEARNING_WORKSPACE_FILE. If set, the hook runs git check-ignore against it and refuses to write when the file is inside a git repo and not gitignored. The check can be bypassed with CONTINUAL_LEARNING_ALLOW_SHARED=1.
  • Explicit section routing
    • ## Learned User Preferences → user file only.
    • ## Learned Workspace Facts → workspace file when configured and not blocked.
    • ## Learned Workspace Facts (local) → user file fallback heading when no workspace file is configured or the workspace file is blocked.
  • Hook embeds resolved paths in followup_message so the agents-memory-updater subagent gets concrete absolute paths and the block reason (if any) instead of having to recompute them.
  • First-run migration copies any pre-existing .cursor/hooks/state/continual-learning{,-index}.json into the new user-scoped location, keeps a backup under the user state dir, and removes the originals so they stop appearing in git status.
  • New env vars (all optional): CONTINUAL_LEARNING_USER_FILE, CONTINUAL_LEARNING_WORKSPACE_FILE, CONTINUAL_LEARNING_STATE_DIR, CONTINUAL_LEARNING_ALLOW_SHARED. Existing cadence vars and legacy CONTINUOUS_LEARNING_* aliases are unchanged.

Files

  • continual-learning/hooks/continual-learning-stop.ts — use resolved targets for state paths; build a structured followup message; migrate legacy state once on startup.
  • continual-learning/hooks/lib/memory-targets.ts (new) — slug computation, env-driven path resolution, git check-ignore safety check, legacy-state migration. ~180 lines, no new dependencies (node:fs, node:os, node:path, node:child_process only).
  • continual-learning/agents/agents-memory-updater.md — describe the dual-target write model, the section-routing rules, the safety check, and the local-fallback heading. Prefers the embedded paths from the hook when present.
  • continual-learning/skills/continual-learning/SKILL.md — header wording updated; orchestration unchanged.
  • continual-learning/README.md — new "Safe defaults for team repos" and expanded configuration sections.
  • continual-learning/CHANGELOG.md (new) — Unreleased entry following the format used by sibling plugins.

Backwards compatibility

  • Default memory file path changes from workspace AGENTS.md to ~/.cursor/projects/<slug>/AGENTS.local.md. Existing users who relied on the old behavior can restore it by setting CONTINUAL_LEARNING_WORKSPACE_FILE=<absolute path to AGENTS.md> and CONTINUAL_LEARNING_ALLOW_SHARED=1.
  • All existing env vars (CONTINUAL_LEARNING_MIN_TURNS, trial mode flags, the CONTINUOUS_LEARNING_* legacy aliases) keep their current meaning.
  • Existing cadence/index files in .cursor/hooks/state/ are migrated automatically on the next hook run.

Test plan

  • [x] node scripts/validate-plugins.mjs — passes (no manifest changes).
  • [x] bun build continual-learning/hooks/continual-learning-stop.ts — bundles cleanly.
  • [x] Cold run (no transcript advance) — hook outputs {} and does not trigger the followup.
  • [x] Forced trigger with no workspace file configured — followup message contains the resolved user file path and routes workspace facts to the user file under ## Learned Workspace Facts (local).
  • [x] Forced trigger with CONTINUAL_LEARNING_WORKSPACE_FILE pointing at a tracked file — followup message marks the workspace target as BLOCKED with the git-leak reason and routes workspace facts to the user file under ## Learned Workspace Facts (local).
  • [x] Same scenario with CONTINUAL_LEARNING_ALLOW_SHARED=1 — followup message labels the workspace target as shared, may be committed and allows the write.
  • [x] First-run migration on a workspace that has the old .cursor/hooks/state/ files — files are moved to the user-scoped location, a backup is left there, and the originals are removed from git status.

Made with Cursor

yuranich avatar May 23 '26 12:05 yuranich