Skip to content

feat: add ctx_forget for per-source knowledge-base eviction#939

Open
KoscheiiB wants to merge 2 commits into
mksglu:mainfrom
KoscheiiB:feat/ctx-forget
Open

feat: add ctx_forget for per-source knowledge-base eviction#939
KoscheiiB wants to merge 2 commits into
mksglu:mainfrom
KoscheiiB:feat/ctx-forget

Conversation

@KoscheiiB

Copy link
Copy Markdown

Summary

Adds ctx_forget, a tool to evict a single indexed source from the project knowledge base by label, or to list current source labels. Fills the gap between "keep everything" and ctx_purge's session/project-wide wipe.

Motivation

ctx_purge only clears a whole session or the entire project. There is no surgical way to drop one indexed source (e.g. to re-index a cleaner version of a single doc). This is distinct from the session-scoped purge in #520.

Design

  • New ctx_forget tool rather than a source param on ctx_purge, for discoverability and a clean read-only list mode. Open to folding it into ctx_purge if preferred.
  • ContentStore.deleteSource(label) reuses the existing dedup-by-label delete statements inside a withRetry transaction; returns { existed, deletedChunks }.

API

  • ctx_forget() -> lists indexed source labels + chunk counts (read-only).
  • ctx_forget(source) without confirm:true -> cancelled, nothing deleted.
  • ctx_forget(source, confirm:true) -> deletes that source's chunks; an unknown label returns the available labels.

Tests

  • tests/store.test.ts: delete + verify removal, unknown label -> existed:false, sibling sources unaffected.
  • tests/core/server.test.ts: ctx_forget added to the annotations contract map (destructiveHint:true, idempotentHint:true, readOnlyHint:false, openWorldHint:false).
  • tests/opencode-plugin.test.ts: ctx_forget in the native plugin tool map ([Feature]: Plugin-only tool registration for ts-plugin adapters (OpenCode, KiloCode, OpenClaw) #574).
  • Description conforms to ADR-0002 (WHEN / WHEN NOT / RETURNS / EXAMPLE).

Docs

  • README tool table row + registered-tool count updated (11 -> 12).

Notes

KoscheiiB added 2 commits July 9, 2026 20:42
ctx_purge clears a whole session or the entire project; there is no way to
evict a single indexed source. ctx_forget deletes one source by label
(confirm:true required) or lists indexed source labels when called with no
argument.

- ContentStore.deleteSource(label): removes the source's chunks, trigrams,
  and row in a withRetry transaction; returns { existed, deletedChunks }.
- ctx_forget tool: list mode (no source), cancel without confirm, delete
  with confirm; an unknown label returns the available labels.
- Description follows ADR-0002 (WHEN / WHEN NOT / RETURNS / EXAMPLE);
  annotations registered in the server contract test and the opencode
  native tool map.
- Vitest coverage for deleteSource: delete + verify, unknown label, and
  sibling-source isolation.
- README tool table and tool count updated.

Refs mksglu#914
Exercises the ctx_forget tool handler through the native opencode tool map:
empty-list, seeded-list, cancel-without-confirm, unknown-label (which the
opencode adapter maps to a throw), delete-with-confirm, and the post-delete
listing. Complements the store-level deleteSource tests.
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.

1 participant