dsh-brain/docs/LOCAL_MEMORY_ACCEPTANCE.md

123 lines
7.2 KiB
Markdown

# Local Memory Phase 1 Acceptance
Date: 2026-11-24 (Asia/Shanghai)
Scope: the local-first phase described by `docs/plans/LOCAL_MEMORY_PLAN.md`.
Cloud synchronization is deliberately **not** implemented in this phase (plan
section 15); the local layer remains usable without an account, token or network.
## Commands and results
| Command | Result |
| --- | --- |
| `node verify-local-memory.mjs` | ALL 22 CHECKS PASSED |
| `node verify-local-memory-acceptance.mjs` | ALL 23 CHECKS PASSED |
| `node verify-local-memory-round3.mjs` | ALL 19 CHECKS PASSED |
| `node verify-auto-summary-round3.mjs` | ALL 7 CHECKS PASSED |
| `node verify-memory-switches-round3.mjs` | ALL 5 CHECKS PASSED |
| `node verify-skill-sync-round2.mjs` | ALL 13 CHECKS PASSED |
| `node verify-sync-resolve.mjs` | 23/23 passed |
| `node verify-skill-sync-scope-round3.mjs` | ALL 2 CHECKS PASSED |
| `node verify-skill-sync-conflict-round5.mjs` | ALL 19 CHECKS PASSED |
| `node verify-local-memory-round4.mjs` | ALL 12 CHECKS PASSED |
| `node verify-local-memory-round5.mjs` | ALL 6 CHECKS PASSED |
| `node verify-local-memory-round6.mjs` | ALL 8 CHECKS PASSED |
| `node verify-auto-summary-host-retry-round5.mjs` | ALL 3 CHECKS PASSED |
| `node verify-skill-update.mjs` | 16/16 passed |
| `node verify-mnemon-native.mjs` | ALL 6 CHECKS PASSED |
| `node verify-mnemon-fork.mjs` | ALL 23 CHECKS PASSED |
| `node verify-mnemon-provider.mjs` | ALL 14 CHECKS PASSED |
| `node scripts/verify-all.mjs` | 38 scripts: 38 passed (1 with environmental skips), all green |
## Acceptance mapping
| # | Criterion | Evidence |
| --- | --- | --- |
| 1 | Fresh environment can use memory without manual space creation | `verify-local-memory-acceptance.mjs` check 1 |
| 2 | One global and one current-project space are created automatically | check 2 |
| 3 | Restart / repeated initialization does not duplicate spaces | checks 3, 13 |
| 4 | Global and project directories follow `.dsh/brain`, no `.mnemon` | check 4 |
| 5 | Offline / no-account / no-cloud-config local use works | check 5 and `verify-local-memory.mjs` |
| 6 | Cloud adapter receives zero calls when sync is off | checks 16, 17 |
| 7 | Automatic summary is incremental, deduplicated, source-traceable and compactly projected | checks 10, 22 |
| 8 | Automatic profile stores only explicit preferences; one-off wording is ignored; correction invalidates the old text | checks 9, 11, 23 |
| 9 | Default search covers current project + global and caps results | checks 6, 7, 8 |
| 10 | Update / delete / concurrent writes / restart do not lose or duplicate records | checks 12, 13; tombstone check in `verify-local-memory.mjs` |
| 11 | Project `.dsh/brain` is not committed by default | check 19 |
| 12 | Existing Source / Provider / Strategy / Skill / public interfaces remain available | `verify-all.mjs`, `verify-mnemon-provider.mjs` |
| 13 | Settings page never accesses SQLite, CLI or Provider internals | check 18 |
| 14 | Legacy migration is verifiable and rollbackable, original files remain | check 15 |
| 15 | Automatic summary and manual writes never store secrets | checks 20, 21 |
## Fourth-round regression mapping
| Area | Assertions |
| --- | --- |
| Migration rollback | occupied destination failure leaves active records intact; retry restores and repeated rollback is safe; parallel migration receipts |
| Summary document transaction | corrupt index, index success + Markdown failure, retry, replay and duplicate prevention |
| Conflict scope | connection snapshot test plus existing account-isolation assertions |
| Profile validation | empty/secret update rejected without changing the old record |
| Skill rollback | added/changed/removed file statistics checked in `verify-skill-update.mjs` |
## Third-round regression mapping
| Area | Assertions |
| --- | --- |
| Workspace isolation | `verify-local-memory-round3.mjs` A/B writes, searches, reads and shared global state |
| Storage safety | concurrent first initialization; corrupt JSON preserved; projection retry; 1005-record pagination |
| Summary events | `verify-auto-summary-round3.mjs` structured text, injected-content exclusion, three replays, empty replay, one-off rule |
| Query scope | project filter before `k` truncation; filtered list total and offset |
| Memory switches | `verify-memory-switches-round3.mjs` local/cloud/all-off combinations and status without side effects |
| Skill sync | uploaded-file deletion, different local folder name, connection snapshot, existing account isolation |
## Fix found during acceptance
`LocalMemoryManager.createBackup()` originally asked `fs.cp` to copy the whole
global root into a subdirectory of itself, which fails with
`ERR_FS_CP_EINVAL` on Windows and Node 24. It now creates the backup directory
and copies each top-level entry except `backups` into it. The acceptance test
check 14 covers this regression.
## Fifth-round regression mapping
| Area | Assertions |
| --- | --- |
| Rollback final copy | destination child conflict fails before active mutation; retry and restore copy remain valid |
| Re-import after rollback | re-migration restores exactly one active record; repeated migration deduplicates |
| Host summary retry | host event failure keeps the pending turn; retry after document repair creates one summary |
| Conflict confirmation | conflict preview carries conflictId/scope/local/cloud versions; stale confirmation is rejected |
## Sixth-round regression mapping
| Area | Assertions |
| --- | --- |
| Migration ownership | content-only duplicate is not owned; mixed existing/new rollback removes only the new record |
| Restore safety | non-empty target rejected before active mutation; completed rollback copy path verified |
| Workspace-scoped rollback | migration initiated in A and rolled back from B uses A's receipt target |
| Conflict/alias | preview-bound confirmation; physical directory aliases preserved (round-5/round-2 scripts) |
## Environment limits
- Verified with Node 24.21.0 and the bundled TypeScript toolchain. Node 20 was
not installed in this environment; the package engine remains `>=20`.
- `pnpm install --lockfile-only --ignore-scripts` regenerated the lockfile with
the root Mnemon dependency removed. A clean frozen install was not re-run;
the offline mirror lacked the metadata needed for that check.
- Real DSH host MCP, a real Mnemon host process and a real cloud endpoint were
not exercised. `verify-mcp-bridge.mjs` is excluded from the default suite;
run it explicitly with `DSH_VERIFY_REAL_MCP=1`. The provider registration
test uses a host-shaped fake and temporary files.
- The host-event pending-summary queue is in-process only; restart persistence
is not implemented in this phase.
## Not covered in this phase
- Real cloud push/pull, cloud change cursors, remote conflict merge and external
Provider adapters (plan section 15; later cloud-sync).
- The full upstream Mnemon runtime is not loaded automatically as dsh-brain's
active engine: the complete source fork is in `vendor/dsh-mnemon`, the active
provider SDK subset is `src/mnemon/fork`, and the local native provider entry
is `src/mnemon/native.ts` (host registration covered by `verify-mnemon-native.mjs`).
- Cross-process file-lock behavior under adversarial operating-system failures;
normal concurrent writes and restart behavior are covered.