SIGN IN SIGN UP

feat: add multi-user attribution and team sync schema (v29) (#468)

## Summary

Adds migration v29 with columns for multi-user attribution, promotion
workflow, approval workflow, and team sync scaffolding. This is Phase 0
of the multi-DB sync architecture (see #467 for full RFC).

## Changes

### Migration v29 (`packages/core/src/db.ts`)

**11 new columns on `knowledge` table:**
- `created_by`, `updated_by` — user attribution
- `sensitivity` — auto-promotion product hint
(`normal`/`sensitive`/`restricted`)
- `promotion_status`, `promoted_at` — personal → team promotion flow
- `approval_status`, `approved_by`, `approved_at` — team admin approval
workflow
- `source_user_id`, `source_entry_id` — team DB origin tracking
- `last_accessed_at` — access tracking

**2 new tables:**
- `team_knowledge` — local read-only cache for approved team entries
(empty scaffolding)
- `team_config` — team credentials and sync state (empty scaffolding)

All columns nullable/defaulted for backward compat. Zero impact on
local-only users.

> **Security note**: These columns are sync metadata and product UX
hints, NOT access control. Isolation is enforced at the DB level
(database-per-user/team via Turso). See #467.

### Additional cleanup
- Removed stale `SCHEMA_VERSION = 16` dead code constant
- Added `team_knowledge`/`team_config` to `recoverMissingObjects()` for
partial migration recovery

### Type & CRUD updates (`packages/core/src/ltm.ts`)

- `KnowledgeEntry` type: 11 new fields using named types
- Named types: `Sensitivity`, `PromotionStatus`, `ApprovalStatus`
(exported, compile-time validated)
- `KNOWLEDGE_COLS` / `KNOWLEDGE_COLS_K`: 11 new columns
- `create()`: accepts optional `createdBy` and `sensitivity` params
- `update()`: accepts optional `updatedBy` and `sensitivity` params
- Synthetic lat.md entry: all 11 new fields with defaults

### Tests

- `db.test.ts`: schema version assertion → 29
- `ltm.test.ts`: 8 new tests covering default values,
`createdBy`/`sensitivity` on create, `updatedBy`/`sensitivity` on
update, and `team_knowledge`/`team_config` table existence

## What is NOT changed (scope boundaries)

- `forSession()` team merging — Phase 2
- `forSession()` personal preference boost — Phase 2
- `last_accessed_at` writes — deferred (hot path)
- `agents-file.ts` — `.lore.md` format unchanged
- `curator.ts` / `distillation.ts` — callers use defaults
- Gateway sync module — Phase 1+
- CLI team commands — Phase 1+

## Verification

- Typecheck: 4/4 packages clean
- Tests: 120/120 pass (db + ltm targeted)

Closes phase 0 of #467.
B
Burak Yigit Kaya committed
e47d305f9780da856622be6c8629f459231d8f52
Parent: 9150492
Committed by GitHub <noreply@github.com> on 5/28/2026, 5:26:54 PM