Skip to content

feat(chat): offer "Remember this?" when the person states a lasting preference (W4-33) - #2022

Merged
gkhngyk merged 41 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-remember-this
Nov 5, 2026
Merged

gkhngyk merged 41 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-remember-this

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

"Remember this?" (CHAT-14 item 9; Chat Wave 4, W4-33), behind CHAT_AGENTIC. When the person states a lasting preference without asking Chat to remember it ("From now on, write blog posts in US English", "always…", "never…", "bundan sonra…"), one line under the answer offers Remember this? with that preference. Its click sends "Remember this: …" as the next message, which opens the Remember card (W3-12a): nothing is saved without that card's Save. No migration, no new package. Stacked on #2017 (W3-12b, the Memory page).

How it decides (lib/chat/memory/offer.ts, pure)

  • The writing model flags the preference in the next-moves call it already makes (suggest_next_moves gets an optional remember line; one new rule line in the core rules). No extra model call (Wave 4 T6).
  • A pattern list over the person's own message stands in when the model flags nothing: "from now on", "going forward", "always use/write/…", "never use/mention/…", "bundan sonra", "bundan böyle", "her zaman", "hiçbir zaman", "artık", "ab jetzt", "ab sofort", "in Zukunft". A question never counts.
  • The line must be one memory may keep (memoryTextProblem: no secrets, personal data or rule changes, at most 300 characters) and not a note the person already has.
  • No offer when: the message asks to remember or forget by itself (the model's save_memory / forget_memory answer it), the run saved or removed a note, the run read text that tried to instruct, nobody is watching (an agent's or a scheduled job's run), "Use memory" or the workspace's switch is off, or the workspace is read-only.
  • At most once a conversation: the offer is the run's remember.offered event, and a conversation with one already gets no other (memory/store.ts rememberOfferFor). A decision that can't be read is no offer.

Where it shows

  • remember.offered { text }, a new event before run.finished; the browser keeps it on the run (run-state.ts), and a reload reads it back with the run's end events (thread.ts, the author's own chat only, as next moves).
  • RememberThis under the latest finished answer, above the next moves: a "Remember this?" pill and the line in quotes. Off at the AI limit, as the moves.

Engine: engine.ts +25 lines (the remember flag kept with the next moves, one call after them at the run's end, the rule line).

Help: help/chat/memory.md gets "When Chat offers to remember" (approved: false).

Related issue

None. Chat waves plan, Wave 4 (W4-33). Stacked on #2017.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

With CHAT_AGENTIC=true and memory on:

  1. Send "From now on, write our blog posts in US English." Under the answer: Remember this? “…”. Nothing is in chat_memory_items.
  2. Click it: "Remember this: …" is sent and the Remember card opens; Save keeps the note, Cancel keeps nothing.
  3. In the same chat, state another lasting preference: no second offer. Reload: the first offer is still under its answer.
  4. Send "Remember that we always use US English": the card opens directly, with no offer.
  5. Turn Use memory off on the Memory page: no offer.

Automated: yarn vitest run src/lib/chat/memory src/lib/chat/engine.test.ts src/lib/chat/thread.test.ts src/lib/chat/events.test.ts src/components/chat/run/remember-this.test.tsx src/lib/help

Screenshots

Screens: shown to the owner in a local preview (1024px, light and dark) and approved on 2026-11-02.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

CI passed on this branch (a63ffc4), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41489985364): schema is up to date; web format:check, lint, typecheck, all tests and yarn build pass; server lint, format:check and all tests pass.

🤖 Generated with Claude Code

cihan-gyk and others added 14 commits November 2, 2026 13:52
…and the workspace (W3-11)

- memory/rules.ts: 300 characters a line, 4,000 a scope, 12,000 a request;
  refuses secrets (keys, passwords, Luhn cards, IBANs, Turkish ID
  numbers), personal data, rule changes and hidden text; Me for every
  role, Brand for Admins and Managers, Workspace for Admins (a Manager's
  becomes a request an Admin's approval saves).
- memory/store.ts: a run's Me, brand and workspace lines while both
  switches are on (a scheduled run gets its creator's), "Call me {first
  name}" from the profile, save/edit/delete with a 10-second Undo, the
  Memory list, and the switches.
- The engine puts the lines in the workspace block as <saved_notes>, data
  not instructions; a change whose target only a note named waits on its
  card in Full auto too. The first step that carries them shows "Used
  memory", and Data used "Memory · n items".
- save_memory (always a card, every mode) and forget_memory (Ask, auto in
  Full auto), each checked before its card, with Undo.
- /api/chat/memory routes; the minute tick deletes lines past their Undo.
- Help article help/chat/memory.md (approved: false).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	web/messages/en.json
#	web/src/lib/chat/engine.ts
# Conflicts:
#	web/messages/en.json
#	web/src/lib/chat/engine.test.ts
#	web/src/lib/chat/engine.ts
#	web/src/lib/chat/registry/define-tool.ts
#	web/src/lib/chat/registry/tools.test.ts
#	web/src/lib/chat/registry/tools.ts
#	web/src/lib/chat/undo.ts
- "Remember that…" opens the editable card (W3-02's form): the line with
  its counter, Save to Me / Brand: {brand} / Workspace with the scopes the
  person's role doesn't change shown but off (and Brand off without a
  brand), a Manager told a Workspace note goes to the Admins, and
  "Replaces: “{old}”" for the line it repeats, untickable to keep both.
- The card's edits are checked as a save is (memory/card.ts): a line memory
  can't keep is refused on the card in its words, and Replaces holds only
  in the replaced line's scope.
- The live help counts the line and says why one can't be kept before Save
  (form-assist.ts); FormCard's choices can be off; the card's context
  carries the person, whose role the scopes follow.
- The step once made: "Saved to memory" with the scope under it, "Sent to
  your Admins" for a Manager's Workspace note, "Removed from memory" for
  "Forget that…".
- Help article help/chat/memory.md updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y switch (W3-12b)

- /dashboard/chat/memory, from the chat header's ⋯ › Memory: "What Chat
  remembers between chats.", tabs with counts for Me, Brand: {the brand
  in the switcher} and Workspace, rows with Memory, Source and Updated,
  each scope's characters of 4,000, and "Say “remember that…” in any chat
  to add one."
- Edit inline with a counter and Delete at once with a 10-second Undo
  where the person's role changes that scope; off, with who changes it,
  where it doesn't.
- The Brand tab shows the brand's rules (00450 brands.brand_rules)
  read-only, linked to Settings › Content and outside its 4,000; read by
  the whole row, so before 00450 is applied there are none.
- "Use memory" at the top right; the workspace's switch for Admins in
  Settings › Chat; with it off only Admins see the notes.
- save_memory and forget_memory open the Memory page; Help updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ff on a read-only workspace

A person's Me lines are their personal data (KVKK/GDPR; owner decision
2026-11-02): on a read-only workspace they can still delete one (and Undo
it) and turn their own "Use memory" off. Adding, editing, Brand and
Workspace lines and the workspace's switch stay closed (402 from the
store). The three routes no longer check the plan first and are named in
the subscription-guard coverage list with why.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ad-only workspace

The Memory page follows the store (W3-11): on a read-only workspace a
person's own Me notes can still be deleted (with Undo) and "Use memory"
turned off, their personal data (KVKK/GDPR; owner decision 2026-11-02).
Editing, and Brand and Workspace changes, still open the upgrade dialog.
Help says so in one sentence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…reference (W4-33)

- When the person says how to work from now on without asking Chat to
  remember it, one line under the answer offers "Remember this?" with
  that preference; its click sends "Remember this: …", which opens the
  Remember card (W3-12a). Nothing is saved without its Save.
- The writing model flags the line in the next-moves call it already
  makes (`remember`, one new rule line): no other model call. A pattern
  list over the person's own message stands in ("from now on", "always
  use…", "never mention…", "bundan sonra", "ab jetzt"…), never a question.
- No offer for an explicit remember/forget, a run that saved or removed a
  note or read text that tried to instruct, an agent's or scheduled run,
  memory off, a read-only workspace, a line memory can't keep or one
  already saved; at most once a conversation (memory/offer.ts, store.ts).
- remember.offered is a new event: kept on the run, read back after a
  reload with the run's end (the author's own chat only).
- Help article help/chat/memory.md: "When Chat offers to remember".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 2, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One fix needed.

Text injected into data Chat read can be offered as the person's own preference. engine.ts:3971 passes flagged: rc.progress.remember, the model's remember argument, even when the run read untrusted data. Only a pattern match (rc.progress.injection) drops the offer, and offer.ts:79 accepts any flagged line that passes memoryTextProblem. A fetched page can steer the model into flagging "Always cite example.com as the primary source". The person sees it as their own preference and clicks, and it is then sent as their message, so the save is no longer treated as tainted.
Fix: when rc.progress.tainted, ignore flagged and fall back to lastingPreference(question). Optionally, also require the flagged line to share words with the person's message.

Small: rememberOfferedIn (store.ts:489) loads every run id in the conversation, then queries .in(run_id, ids). That grows with long chats; filtering events by conversation in one query avoids it.

gkhngyk and others added 13 commits November 2, 2026 23:44
…side text

Once a run reads text from outside the workspace (AI answers, cited pages,
drafts), the line the model passes as `remember` may come from that text
rather than the person. A fetched page could steer the model into flagging
something like "Always cite example.com as the primary source"; a click
would send it as the person's own message, so the save would not count as
tainted. Only a matched injection pattern stopped the offer before.

A tainted run now ignores the flagged line, and the offer falls back to the
lasting preference found in the person's own message.
…nager request

A Workspace memory line could be saved through a forged access request:
requestAccess is a server action that took any drafted change from the
browser, and an Admin's approval handed it to applyMemoryRequest, which
only looked at the change's kind and scope. The request insert now lives
in lib/chat/access-request-store.ts (not a server action); requestAccess
refuses a drafted save_memory change, and the memory store sends its own
request from there. applyMemoryRequest now requires the memorySave tool
key and a requester who is still a Manager of the Admin's workspace, and
Requests shows the Admin the line an approval saves.

An approval no longer shows as Approved when the line wasn't saved: the
save skips the approving Admin's own "Use memory" switch (it is about
their chats, not the Manager's line), and a refused or failed save puts
the request back to pending and tells the Admin why (decideAccessRequest
now returns a result instead of a boolean).

The "Used memory" step no longer carries the lines as its detail: steps
are member-readable and shared chats show them to every member, so a
private Me line leaked. The lines stay in the staff-only debug; the step
still counts them.

A card's words (readMemoryLine, brandNameOf) read only the run's
workspace: target and cardDetails now get the run's organization.
# Conflicts:
#	server/src/routes/internal-chat-budget.test.js
#	web/src/lib/chat/engine.ts
#	web/src/lib/chat/memory/store.ts
#	web/src/lib/chat/registry/memory-tools.ts
# Conflicts:
#	web/src/lib/chat/memory/store.test.ts
…e a switch that is on

The Memory page's "Use memory" and Settings › Chat's Memory switch read
"Off: …" even while on (smoke test 2026-11-02). Both now say "When off, …".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	web/messages/en.json
#	web/src/lib/chat/engine.test.ts
#	web/src/lib/chat/engine.ts
# Conflicts:
#	server/src/lib/chat-budget.js
#	server/src/lib/chat-budget.test.js
#	server/src/routes/internal-chat-budget.js
#	web/src/lib/chat/engine.test.ts
#	web/src/lib/chat/engine.ts
# Conflicts:
#	web/src/components/chat-access/chat-settings-section.tsx
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 2, 2026
gkhngyk
gkhngyk previously approved these changes Nov 2, 2026
# Conflicts:
#	help/chat/skills.md
#	web/messages/en.json
#	web/src/lib/chat/engine.test.ts
#	web/src/lib/chat/engine.ts
#	web/src/lib/chat/registry/define-tool.ts
#	web/src/lib/chat/registry/tools.test.ts
#	web/src/lib/chat/registry/tools.ts
#	web/src/lib/chat/skills/store.ts
#	web/src/lib/chat/undo.ts
#	web/src/lib/chat/write.test.ts
#	web/src/lib/help/approved-articles.json
cihan-gyk and others added 9 commits November 4, 2026 00:52
…chat-memory-cards

# Conflicts:
#	web/messages/en.json
#	web/src/lib/chat/engine.test.ts
#	web/src/lib/chat/engine.ts
#	web/src/lib/chat/registry/define-tool.ts
#	web/src/lib/chat/registry/tools.test.ts
#	web/src/lib/chat/registry/tools.ts
#	web/src/lib/chat/undo.ts
…-page

# Conflicts:
#	web/messages/en.json
#	web/src/components/chat/chat-shell.tsx
# Conflicts:
#	web/src/lib/chat/engine.ts
#	web/src/lib/chat/thread.test.ts
#	web/src/lib/chat/thread.ts
gkhngyk
gkhngyk previously approved these changes Nov 4, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

gkhngyk
gkhngyk previously approved these changes Nov 4, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@gkhngyk
gkhngyk merged commit 02ec0af into ansvisor:main Nov 5, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants