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
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
collectLocalProfileSignals,
|
|
mergeUserMemorySections,
|
|
persistUserProfileHarvest,
|
|
} from "./user-profile-harvest";
|
|
|
|
describe("user-profile-harvest", () => {
|
|
it("collects timezone and locale signals", () => {
|
|
const signals = collectLocalProfileSignals({
|
|
name: "Ingo",
|
|
email: "ingo@example.com",
|
|
defaultProvider: "openrouter",
|
|
defaultModel: "gpt-4",
|
|
computerHost: "docker",
|
|
});
|
|
expect(signals.timezone).toBeTruthy();
|
|
expect(signals.locale).toBeTruthy();
|
|
expect(signals.name).toBe("Ingo");
|
|
expect(signals.harvestedAt).toMatch(/^\d{4}-/);
|
|
});
|
|
|
|
it("keeps existing notes and leaves profile data to the user profile", () => {
|
|
const merged = mergeUserMemorySections("# Space memory\n\nExisting note.\n");
|
|
expect(merged).toContain("Existing note.");
|
|
expect(merged).not.toContain("## User profile (auto-harvested)");
|
|
});
|
|
|
|
it("persists help vibe via memory.update on user scope without profile data", async () => {
|
|
const updates: Array<{ documentId: string; content: string }> = [];
|
|
const hints = await persistUserProfileHarvest(
|
|
{
|
|
memory: {
|
|
list: async () => [{ id: "mem1", path: "MEMORY.md", content: "# Space memory\n" }],
|
|
update: async (input) => {
|
|
updates.push(input);
|
|
},
|
|
},
|
|
},
|
|
collectLocalProfileSignals({
|
|
name: "Ingo",
|
|
email: "ingo@example.com",
|
|
defaultProvider: null,
|
|
defaultModel: null,
|
|
computerHost: "docker",
|
|
}),
|
|
);
|
|
expect(updates).toHaveLength(1);
|
|
expect(updates[0]?.content).toContain("## Help & vibe (inferred)");
|
|
expect(updates[0]?.content).not.toContain("Ingo");
|
|
expect(updates[0]?.content).not.toContain("ingo@example.com");
|
|
expect(hints.suggestedLanes).toContain("builder");
|
|
});
|
|
});
|