Skip to content

feat(extension): add "Add to memory" capture, settings list, and agent memory tools - #4762

Merged
iscekic merged 5 commits into
mainfrom
ext-add-to-memory
Jul 25, 2026
Merged

feat(extension): add "Add to memory" capture, settings list, and agent memory tools#4762
iscekic merged 5 commits into
mainfrom
ext-add-to-memory

Conversation

@iscekic

@iscekic iscekic commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an "Add to memory" right-click context-menu action to the Kilo browser extension (Chrome MV3 + Firefox MV3). Highlight text on any page → Add to memory opens the side panel with a save card (optional ≤200-char note). Saved memories live extension-locally (same lifecycle as conversations: per-browser, wiped on sign-out), are listed in a Memories section of the settings dialog, and are surfaced to the side-panel agent through (a) a compact capped index inside the hidden <system_environment> message suffix and (b) two new read-only safe tools, search_memories and get_memory, so the agent can look memories up without their contents polluting the context.

How it works

  • Capture: contextMenus registration (selection-only) in the background; a click builds a sanitized draft synchronously (trim, 8,000-char cap with truncated flag, query/hash-stripped URL, capture-time createdAt), opens the side panel first (user-gesture contract — Chrome sidePanel.open is gesture-gated and must not cross an await), then persists the pending draft. Open failures degrade gracefully: the draft survives and the card appears the next time the panel opens.
  • Save card: compact strip above the chat panel with selection preview, optional note, and a fully derived state machine — hidden while loading, draft form, persistent Saved to memory confirmation (explicit Done, no timed fade), retryable save error (Couldn't save memory. Try again. + Retry), non-retryable full state at 200 memories (Memory is full. + Manage memories, no Retry), and load-error retry. The full state is reactive: deleting below 200 restores the draft form.
  • Settings: <section aria-label="Memories"> mounted directly below the "Signed in" card — newest-first list with per-item immediate delete (unique Delete memory "<preview>" accessible names), Loading… row, retryable load error, and an empty state with guidance text and no CTA.
  • Agent access: memories are never inlined into the prompt beyond a 20-entry capped index (- [id] preview (domain, YYYY-MM-DD) + "N more" note, ~400 tokens worst case) inside the single <system_environment> wrapper — omitted entirely when the store is empty and byte-for-byte identical to today's suffix otherwise. search_memories (AND of case-insensitive tokens over text + note + title + URL, newest-first, ≤10 results with snippets, explicit No memories matched. ok-result) and get_memory (full memory or Memory not found.) are read-only safe tools, available in both modes; deletion stays UI-only.
  • Storage: zod-validated browser.storage.local with an injected-area module (same convention as remote-mcp-storage.ts); invalid drafts/entries are normalized away; store-full is a discriminated AgentMemoryStoreFullError; sign-out's existing storage.clear('local') wipes memories and drafts.

Commits

  1. extension: add agent memory store and Add-to-memory context menu capture — data model, storage binding, watcher hook with latest-only refresh reconciliation, background capture flow, contextMenus permission, manifest assertions.
  2. extension: add memory save card and settings memories section — save card + pure state machine, settings section, settings-dialog jotai atom.
  3. extension: add search_memories/get_memory tools and memory index context — full lockstep (enums, gateway allowlists, runtime early branches, persistence round-trip incl. memoryId, compaction detail, system-prompt + AGENTS.md carve-outs) plus the sweep of every exact tool-name assertion to the canonical orders, and the memory-index injection via the single formatSystemEnvironment builder.
  4. extension: cover memories feature in Chrome and Firefox E2E — 8 new Chrome Playwright tests and 5 mirrored Firefox Selenium scenarios (plus seedFirefoxStorage, a seenChatBodies seam, and expandToolExchange helpers).
  5. Merge of latest main (session-cost popover feat(extension): show session cost in the context popover #4751, collapsible code blocks feat(extension): collapse long assistant code blocks #4750, empty-arguments fix fix(extension): treat empty streamed tool-call arguments as empty object #4753) with the tool-list sweep extended to the new tests.

Testing

  • pnpm --filter kilo-extension verify — typecheck + lint + format:check + 333 Vitest pass.
  • pnpm --filter kilo-extension build / build:firefox — pass; both manifests carry contextMenus, host permissions unchanged, Firefox still has no debugger.
  • pnpm --filter kilo-extension e2e:chrome63 passed, 10 skipped (local-backend gated).
  • pnpm --filter kilo-extension e2e:firefox32/32 passed.
  • Two independent reviewer rounds over the combined diff (round 1: 4 findings — 2 repaired, 2 rejected with documented rationale; round 2: No findings) plus a fresh merge-resolution review (No findings).

Not E2E-reproducible, Vitest-only with recorded rationale: retryable storage write/read failures (cannot deterministically force chrome.storage failure). Native context-menu click is not automatable; covered by manifest + service-worker listener assertions with the post-click flow driven by seeded drafts (recorded limitation).

Notes for reviewers / release

  • New contextMenus permission on both browsers (no host-permission change). Chrome shows no extra warning; a store re-review note may be warranted on submission.
  • The outbound tool arrays gain search_memories/get_memory in safe and dangerous modes (canonical order pinned in tests).

@iscekic iscekic self-assigned this Jul 24, 2026
Comment thread apps/extension/src/shared/agent-memories-storage.ts
Comment thread apps/extension/entrypoints/sidepanel/pending-memory-save-card.tsx
@kilo-code-bot

kilo-code-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Executive Summary

The agent-memory storage layer (agent-memories-storage.ts) uses a non-atomic read-modify-write against browser.storage.local, which can silently drop concurrent memory adds/deletes and cause a downstream stale-"full"-state save failure with no user feedback.

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/extension/src/shared/agent-memories-storage.ts 82 Non-atomic read-modify-write on browser.storage.local in addAgentMemory/deleteAgentMemory can lose concurrent writes across contexts (background script vs. side panel)
apps/extension/entrypoints/sidepanel/pending-memory-save-card.tsx 104 Save can silently fail with no user-visible error if the memory store fills to 200 from another context between renders
Files Reviewed (47 files)
  • apps/extension/AGENTS.md
  • apps/extension/entrypoints/background.ts
  • apps/extension/wxt.config.ts
  • apps/extension/src/shared/agent-memories-storage.ts - 1 issue
  • apps/extension/src/shared/agent-memories-storage.test.ts
  • apps/extension/src/shared/agent-memories.ts
  • apps/extension/src/shared/agent-memories.test.ts
  • apps/extension/entrypoints/sidepanel/agent-conversation-storage.ts
  • apps/extension/entrypoints/sidepanel/agent-conversation-storage.test.ts
  • apps/extension/entrypoints/sidepanel/pending-memory-save-card.tsx - 1 issue
  • apps/extension/entrypoints/sidepanel/pending-memory-save-card-state.ts
  • apps/extension/entrypoints/sidepanel/pending-memory-save-card-state.test.ts
  • apps/extension/entrypoints/sidepanel/memory-settings.tsx
  • apps/extension/entrypoints/sidepanel/memory-settings-state.ts
  • apps/extension/entrypoints/sidepanel/memory-settings-state.test.ts
  • apps/extension/entrypoints/sidepanel/use-agent-memories.ts
  • apps/extension/entrypoints/sidepanel/settings-dialog-state.ts
  • apps/extension/entrypoints/sidepanel/settings-dialog-state.test.ts
  • apps/extension/entrypoints/sidepanel/agent-safe-tool-runtime.ts
  • apps/extension/src/shared/agent-safe-tool-runtime.test.ts
  • apps/extension/entrypoints/sidepanel/agent-tool-call-events.ts
  • apps/extension/src/shared/agent-context-compaction.ts
  • apps/extension/src/shared/agent-context-compaction.test.ts
  • apps/extension/src/shared/side-panel.ts
  • apps/extension/src/shared/side-panel.test.ts
  • apps/extension/src/shared/tab-context-sanitize.ts
  • apps/extension/src/shared/tab-context-sanitize.test.ts
  • apps/extension/entrypoints/sidepanel/agent-chat-panel.tsx
  • apps/extension/entrypoints/sidepanel/agent-chat-panel.test.ts
  • apps/extension/src/shared/agent-llm-harness.ts
  • apps/extension/src/shared/agent-llm-harness.test.ts
  • apps/extension/src/shared/kilo-gateway-chat-client.ts
  • apps/extension/src/shared/kilo-gateway-chat-stream-client.ts
  • apps/extension/entrypoints/sidepanel/latest-only-refresh.ts
  • apps/extension/entrypoints/sidepanel/latest-only-refresh.test.ts
  • apps/extension/entrypoints/sidepanel/auth-shell.tsx
  • apps/extension/entrypoints/sidepanel/auth-views.tsx
  • apps/extension/tests/e2e/memories.test.ts
  • apps/extension/tests/e2e/firefox-extension.test.ts
  • apps/extension/tests/e2e/firefox-selenium-e2e.ts
  • apps/extension/tests/e2e/context-usage.test.ts
  • apps/extension/tests/e2e/conversation-scroll.test.ts
  • apps/extension/tests/e2e/conversation-spacing.test.ts
  • apps/extension/tests/e2e/conversation-tabs.test.ts
  • apps/extension/tests/e2e/kilo-api-fixture.ts
  • apps/extension/tests/e2e/remote-mcp-settings.test.ts
  • apps/extension/tests/e2e/run-abort.test.ts
  • apps/extension/tests/e2e/safe-mode.test.ts
  • apps/extension/tests/e2e/sidebar.test.ts

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5 · Input: 34 · Output: 21.2K · Cached: 934.6K

Review guidance: REVIEW.md from base branch main

@iscekic
iscekic merged commit ce243aa into main Jul 25, 2026
19 checks passed
@iscekic
iscekic deleted the ext-add-to-memory branch July 25, 2026 06:43
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.

2 participants