Skip to content

feat: external data directory, layered config, and automatic git backup - #60

Merged
fdaviddpt merged 6 commits into
Digital-Process-Tools:mainfrom
codemedic:feature/external-data-dir
May 24, 2026
Merged

fdaviddpt merged 6 commits into
Digital-Process-Tools:mainfrom
codemedic:feature/external-data-dir

Conversation

@codemedic

@codemedic codemedic commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #59

Summary

  • Adds opt-in external storage mode: memory resolves to ~/.remember/<slug>/ (or any absolute path) instead of <project>/.remember/, keeping repos clean without per-project gitignore entries.
  • Introduces three-tier config merge (plugin defaults → user-global ~/.remember/config.json → per-project override), so settings no longer need to be repeated across projects.
  • Adds a background git backup hook (hooks.d/after_save/50-git-backup.sh) that auto-commits memory after each save, with cooldown, locking, and per-project isolation.
  • Fully backward-compatible: legacy mode remains the default.

Limitations

The git backup is designed as a single-machine backup, not a sync mechanism. There is no pull or rebase before pushing — if another machine has pushed commits to the same remote, the push will fail with a non-fast-forward error and silently defer (indistinguishable from a network failure). Local commits accumulate safely, but the divergence must be resolved manually. Cross-machine sync is out of scope for this implementation.

Changes

New files

  • scripts/lib-memory-dir.sh — REMEMBER_DIR resolution + config merge
  • hooks.d/after_save/50-git-backup.sh — async git backup
  • config.user.example.json — template for user-global config
  • tests/test_external_data_dir.py, tests/test_migration.py, tests/test_layered_config.py, tests/test_git_backup_hook.py

Modified files

  • scripts/bootstrap-dirs.sh — auto-migration, gitignore guard
  • scripts/session-start-hook.sh — identity tiers, handoff path signalling, REMEMBER_DIR-aware throughout
  • pipeline/extract.py, pipeline/shell.py — accept REMEMBER_DIR param
  • skills/remember/SKILL.md — read === HANDOFF === block instead of hardcoded path
  • README.md, config.example.json — document new options

codemedic added 6 commits May 23, 2026 12:04
Adds opt-in external memory storage mode where REMEMBER_DIR relocates to
~/.remember/<slug>/ (or any absolute path), enabling version-controlled
personal memory backups outside project trees.

Key changes:
- scripts/lib-memory-dir.sh (new): resolves REMEMBER_DIR from data_dir config
  and deep-merges config.json across three layers (plugin-bundled, user-global
  ~/.remember/config.json, per-project), so user config survives plugin updates
- scripts/bootstrap-dirs.sh: sources lib-memory-dir.sh; guards .gitignore write
  to legacy (project-internal) mode only; auto-migrates legacy .remember/ on
  first run, leaving a MIGRATED-TO.txt marker
- scripts/log.sh: deduplicated config() definition; sources lib-memory-dir.sh so
  REMEMBER_LOG_DIR follows REMEMBER_DIR; removed duplicate REMEMBER_CONFIG line
- All entry-point scripts: source order fixed to detect-tools → bootstrap → log;
  all ${PROJECT_DIR}/.remember literals replaced with $REMEMBER_DIR
- session-start-hook.sh: emits === HANDOFF === block with absolute path before
  === MEMORY ===; identity.md lookup now checks $REMEMBER_DIR/identity.md first
- pipeline/extract.py: _last_save_path() accepts remember_dir parameter (falls
  back to REMEMBER_DIR env var); extract_session() and get_last_save_line() pass
  it through
- pipeline/shell.py: cmd_extract() forwards REMEMBER_DIR env var to Python
- skills/remember/SKILL.md: uses HANDOFF path from session context instead of
  hardcoded project-relative path
- config.example.json: documents {slug} placeholder and absolute/~ rules
- config.user.example.json (new): ready-to-use template for ~/.remember/config.json
- save-session.sh: 12h time format now uppercases %p for Linux locale portability
- tests: 3 new test files (test_external_data_dir, test_migration,
  test_layered_config); updated test_extract and test_path_resolution for the
  new semantics; 347 tests pass
…allback in lib-memory-dir.sh

User's ~/.remember/config.json (external mode) was bleeding into tests
that assert legacy project-relative REMEMBER_DIR. Two root causes:
  1. lib-memory-dir.sh called session_dir_slug when detect-tools.sh
     hadn't been sourced — now has an inline fallback to prevent a
     silently empty slug.
  2. TestFreshProjectBootstrap and related tests inherited the real HOME,
     activating external mode. Fixed by setting HOME=tmp_path in each.
Adds hooks.d/after_save/50-git-backup.sh. When ~/.remember/ (or
data_dir's parent) is a git repo and not the project directory, the hook
commits the current project's slug subtree and pushes to the configured
remote after each successful save.

Key design decisions:
- Two-stage activation guard prevents memory commits landing in a
  project's own git history (legacy mode check + toplevel check).
- Global cooldown (cooldowns.git_backup_seconds, default 900s) throttles
  commits across all projects; clock resets only on actual commit.
- Global noclobber lock at <repo>/.git-backup.lock prevents concurrent
  git index corruption; stale-PID lock is detected and taken over.
- All git work runs in a detached background subshell — save-session.sh
  is never blocked.
- Per-slug .gitignore files containing only "*" (written by bootstrap in
  legacy mode) are automatically removed on first run.
- Slug paths starting with "-" are handled via "git add --" to prevent
  misinterpretation as flags.
- GIT_TERMINAL_PROMPT=0 on push ensures missing credentials fail fast.

Also: fix lib-memory-dir.sh double-source guard to use
${_LIB_MEMORY_DIR_LOADED:-} so scripts with set -u can source it safely.
Adds a middle tier in the identity resolution chain:
  per-project → <REMEMBER_ROOT>/identity.md → plugin-bundled

Only active in external mode (skipped in legacy mode where
REMEMBER_ROOT == PROJECT_DIR).

@fdaviddpt fdaviddpt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — really solid contribution. Clean decomposition, tests are meaningful (real bare remote, lock contention with live PID, per-slug isolation), 358/0 passing at 99% coverage, backward compatibility preserved. Approving and merging.

A few follow-ups I'll file as issues (none blocking):

  1. === HANDOFF === emitted in legacy mode — adds noise to every session prompt when the path is unchanged. Worth making conditional on external mode.
  2. --no-gpg-sign silently overrides user's commit.gpgSign — should probably be configurable.
  3. Push uses tracking branch implicitly — fine for origin main, brittle for multi-remote setups. Worth documenting or making explicit.
  4. _comments / _purpose keys flow through the merged config — harmless today, could confuse future validation. Convention worth establishing (strip _-prefixed keys at merge).
  5. README first-backup instructions — git add .gitignore config.json doesn't include slug dirs, so first-time users won't see memory in the backup repo until the hook runs. Worth a one-liner clarifying.

Will tag you on the follow-up issues so you can pick any up if you'd like — no pressure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: external data directory, layered config, and automatic git backup

2 participants