managarten/services/mana-ai/src/crypto
Till JS a6d51afbc9 feat(mana-ai): encrypted resolver + tick uses Mission Grant to decrypt scoped inputs
Phase 2 of Mission Key-Grant. The tick loop now honours a mission's
grant by unwrapping the MDK and passing it + the record allowlist into
the resolvers. Encrypted modules (notes, tasks, calendar, journal,
kontext) resolve server-side instead of returning null.

- crypto/decrypt-value.ts: mirror of webapp AES-GCM wire format
  (enc:1:<iv>.<ct>) — read-only, server never wraps
- db/resolvers/encrypted.ts: factory + 5 concrete resolvers. Scope-
  violation bumps a metric + writes a structured audit row, decrypt
  failures same. Zero-decrypt (no grant, or record absent) = silent
  null, no audit noise.
- db/audit.ts: best-effort append to mana_ai.decrypt_audit; write
  failures never cascade into tick failures.
- cron/tick.ts: buildResolverContext unwraps grant per mission; MDK
  reference only lives for the scope of planOneMission.
- ResolverContext plumbed through resolveServerInputs; existing goals
  resolver unchanged semantically.
- Metrics: mana_ai_decrypts_total{table}, mana_ai_grant_skips_total
  {reason}, mana_ai_grant_scope_violations_total{table} (alert > 0).

Missions without a grant still run exactly as before — plaintext
resolvers fire, encrypted ones short-circuit to null. No behaviour
regression for existing users.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 13:42:31 +02:00
..
decrypt-value.test.ts feat(mana-ai): encrypted resolver + tick uses Mission Grant to decrypt scoped inputs 2026-04-15 13:42:31 +02:00
decrypt-value.ts feat(mana-ai): encrypted resolver + tick uses Mission Grant to decrypt scoped inputs 2026-04-15 13:42:31 +02:00
unwrap-grant.test.ts feat(ai,auth): Mission Grant endpoint + unwrap helper + audit table 2026-04-15 13:41:59 +02:00
unwrap-grant.ts feat(ai,auth): Mission Grant endpoint + unwrap helper + audit table 2026-04-15 13:41:59 +02:00