/** * User Profile (read-time synthesized daemon-wide profile) — FEAT-451 slice 1. * Answers: "what does this daemon's owner keep coming back to" — rolled up * from the existing 7 local atom kinds, zero schema change (design doc §1, * `docs/specs/FEAT-451-profile-design.md`). * * v1 rollup mapping (source type -> profile section), per the design doc: * fact -> standing_facts * note -> preferences (extract.ts's own type-priority doc calls note * out for "opinions, preferences, or style * remarks" — the closest existing semantic match) * lesson -> recurring_lessons * decision -> recent_decisions * memory_entities (kind IN actor/tech/product/tool) -> known_entities * * Shared between GET /profile (server/routes/profile.ts) and the MCP * user_profile tool (mcp/server.ts) so both transports stay in sync — same * pattern as buildAgentProfile/buildSessionDigest. * * Scope: ACTIVE memories only (valid_to IS NULL AND archived = 0, the same * "currently valid" predicate every other read surface uses), no `agent` * filter — this profile is daemon-wide, not per-agent. Defaults to * scope='private' per ADR-009; an explicit `scope` of 'team'/'org'/'all' * widens the filter (design doc §3 — no per-caller authz exists to check * beyond the single global Bearer, so this is the caller's own choice, not a * privilege escalation). * * Live-computed, no cache, no persisted document (design doc §2) — every * call is a fresh SQL read, so there is no staleness window and no rebuild * step to keep in sync. * * Ranking: the three scored sections (standing_facts/preferences/ * recurring_lessons) reuse usefulnessScores() (src/storage/usefulness.ts, * ADR-010 Laplace-smoothed (used+1)/(used+corrected+2)) — the same formula * agent-profile.ts's top_lessons and the fusion epsilon component use, not a * reinvented one. Sort key is `usefulness DESC, importance DESC, id ASC` — * the trailing `id ASC` is a total tie-break required for ADR-005 eval-gate * determinism (design doc §5): ties are common on freshly-distilled atoms * that still sit at the neutral 0.5 usefulness default. recent_decisions and * known_entities carry their own deterministic tie-breaks for the same * reason (created_at/id and mention_count/name respectively) even though the * design doc only calls out the three scored sections by name — a partial * order anywhere in the response would still make AC-6 flaky. */ import type { DB } from '../../storage/db.js'; export type ProfileScope = 'private' | 'team' | 'org' | 'all'; export declare function isValidProfileScope(value: string): value is ProfileScope; export interface ProfileScoredItem { id: string; text: string; importance: number; usefulness: number; evidence: string | null; created_at: number; } export interface ProfileDecisionItem { id: string; text: string; importance: number; created_at: number; } export interface ProfileEntity { name: string; kind: string; mention_count: number; } export interface UserProfile { scope: ProfileScope; generated_at: number; standing_facts: ProfileScoredItem[]; preferences: ProfileScoredItem[]; recurring_lessons: ProfileScoredItem[]; recent_decisions: ProfileDecisionItem[]; known_entities: ProfileEntity[]; /** Active-memory counts for the four source types this profile rolls up. */ counts: Record; /** Sum of `counts`. */ total: number; } /** * Builds the daemon-wide user profile for `scope` (defaults to 'private', * ADR-009's own default). Pure SQL aggregation, no embedding/LLM call in the * read path (design doc §5/§6) — deterministic under the ADR-005 fake-embedder * eval harness by construction. */ export declare function buildUserProfile(db: DB, scope?: ProfileScope): UserProfile;