refactor(memory): run agent recall, memory tools and the server on the memory contract (P1.5)

- Orchestrator, memory tools, context loader and pattern write-back use a
  MemoryStore and a workspace scope instead of MindDB layers; the knowledge
  graph tools, cognify, memory linker and feedback handler are gone (graph
  hidden in v1, ADR-0002).
- The server opens one mem0 store in <dataDir>/memory/, embedded by the
  in-process model on first use, and extracts facts about the user in the
  background with the model the user chose (memoryExtraction setting).
- Legacy .mind memories are copied into the store once, in the background;
  the legacy files are only read.
- Weaver consolidation, harvest, wiki, memory import, memory lanes, vector
  backfill and index reconciliation are removed; agent runs, loops, sub-agent
  results, connector fetch and the failed-turn capture write through the
  contract. Workspace sessions no longer hold a mind handle.
- FileIndexer and the install audit move to waggle.db; recall date helpers and
  the reranker are copied into core.
- The CLI REPL opens the same memory store.
This commit is contained in:
shumeiko.it
2026-10-24 11:56:26 +02:00
parent f3eb6b6652
commit 784ca770b1
86 changed files with 2520 additions and 8444 deletions

View File

@@ -5,10 +5,10 @@
* failed) so there is a verifiable history of what was installed, when, why,
* and by whom.
*
* Operates on the .mind DB like the other stores in this package.
* Lives in waggle.db with Waggle's other own data (ADR-0007).
*/
import type { MindDB } from '@waggle/hive-mind-core';
import type { WaggleDB } from './waggle-db.js';
import {
sqlInList, RISK_LEVELS, APPROVAL_CLASSES, AUDIT_ACTIONS,
AUDIT_CAPABILITY_TYPES, AUDIT_INITIATORS, TRUST_SOURCES,
@@ -63,10 +63,7 @@ export interface RecordAuditInput {
// P7/D15 A3: the CHECK lists are generated from the canonical @waggle/shared
// arrays via sqlInList, so the SQLite constraint and the TS union can no longer
// drift (divergence #14 — the old comment admitted "drift silently crashes
// record()"). The matching DDL in hive-mind-core/src/mind/schema.ts stays a
// standalone private-monorepo literal and is locked to these same canonical
// lists by install-audit-check-parity.test.ts. It is stripped from the curated
// OSS export.
// record()").
// P7/D15 #15: trust_source now also carries a CHECK (was unconstrained at the DB
// while the TS type claimed a closed set). Every historical value came from the
// typed AuditTrustSource (the pre-security-gate 6-set ⊂ the current 7-set), so
@@ -93,9 +90,9 @@ CREATE INDEX IF NOT EXISTS idx_audit_timestamp ON install_audit (timestamp DESC)
// ── Store ──────────────────────────────────────────────────────────────
export class InstallAuditStore {
private db: MindDB;
private db: WaggleDB;
constructor(db: MindDB) {
constructor(db: WaggleDB) {
this.db = db;
this.ensureTable();
}
@@ -127,13 +124,13 @@ export class InstallAuditStore {
* Classic SQLite 12-step table redefinition, wrapped in a transaction so a
* crash mid-rebuild leaves the original table intact.
*/
private rebuildForWidenedActionCheck(raw: ReturnType<MindDB['getDatabase']>): void {
private rebuildForWidenedActionCheck(raw: ReturnType<WaggleDB['getDatabase']>): void {
const migrate = raw.transaction(() => {
raw.exec('ALTER TABLE install_audit RENAME TO install_audit_legacy');
// SQLite carries indexes along with RENAME (still named idx_audit_*), so
// INSTALL_AUDIT_TABLE_SQL's CREATE INDEX IF NOT EXISTS would no-op and the
// DROP below would take the indexes with the legacy table. Drop them first
// (mirrors hive-mind-core db.ts) so they get recreated on the new table.
// so they get recreated on the new table.
raw.exec('DROP INDEX IF EXISTS idx_audit_capability');
raw.exec('DROP INDEX IF EXISTS idx_audit_timestamp');
raw.exec(INSTALL_AUDIT_TABLE_SQL);