evOo-local/packages/db/src/user-profile.test.ts
Claude 492de63c77
feat(profile): readable, writable and forgettable user model
The main agent is meant to know the user, but nothing could read or change
the user model the foundation added. Onboarding pasted the user's answers
into the first bot's instructions as a "User Context" block, and the user
had no way to see or remove what their bots knew about them.

This makes the user model a user-controlled resource:

- db: a profile repository scoped by user. One atomic update writes the
  account name, profile fields, new facts (deduplicated by normalized
  text, capped per user), fact edits including per-space visibility, and
  confirmations. Health and values facts wait for confirmation unless the
  user wrote them. Forgetting hard-deletes facts by id, category or all,
  clears the summary that may restate them and marks earlier chats as
  consolidated so they cannot teach them again; forgetting everything also
  clears the profile fields. Writes take a per-user advisory lock.
- api/contracts: profile.get, profile.update and profile.forget. Unknown
  fact ids are a 404 on update and ignored on forget; spaces outside the
  user's memberships are rejected.
- adapters: an update_user_profile tool for the main bot only, hidden from
  specialists and shared messaging channels and refused if called anyway.
  Facts carry source "conversation" and the bot, thread and message they
  came from. The scripted runtime records "learn about me: [category:]
  statement" for tests.
- web: onboarding writes the name, time zone (browser default, now
  prefilled and editable), locale, chosen language, communication style
  and the hobby and work-style answers to the profile instead of
  overwriting the bot's instructions, and the harvested memory section no
  longer repeats them. A new "About you" settings section lists profile
  fields and facts by category with their origin, confirms pending facts,
  and forgets one fact or everything.

Tests cover the contracts, the repository (unit and PostgreSQL), tool
selection and refusal, the scripted trigger, the onboarding mapping and
view helpers, an API suite that runs the tool through the executor with a
real main bot, authorization for the new procedures, and an E2E spec.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MRtGG9ARfqqhma3t85Ro2u
2026-10-02 22:41:07 +00:00

22 lines
997 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from "vitest";
import { isSensitiveUserFactCategory, normalizeUserFactValue } from "./user-profile.js";
describe("user facts", () => {
it("treats the same statement with different case, spacing or end punctuation as one", () => {
expect(normalizeUserFactValue(" Works as a Nurse. ")).toBe("works as a nurse");
expect(normalizeUserFactValue('"Works as a nurse!"')).toBe("works as a nurse");
expect(normalizeUserFactValue("Works as a nurse")).toBe("works as a nurse");
});
it("keeps symbols that change the meaning", () => {
expect(normalizeUserFactValue("Writes C++")).not.toBe(normalizeUserFactValue("Writes C"));
});
it("marks only health and values as sensitive", () => {
expect(isSensitiveUserFactCategory("health")).toBe(true);
expect(isSensitiveUserFactCategory("values")).toBe(true);
expect(isSensitiveUserFactCategory("work")).toBe(false);
expect(isSensitiveUserFactCategory("people")).toBe(false);
});
});