feat: add ctx_forget for per-source knowledge-base eviction#939
Open
KoscheiiB wants to merge 2 commits into
Open
feat: add ctx_forget for per-source knowledge-base eviction#939KoscheiiB wants to merge 2 commits into
KoscheiiB wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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" andctx_purge's session/project-wide wipe.Motivation
ctx_purgeonly 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
ctx_forgettool rather than asourceparam onctx_purge, for discoverability and a clean read-only list mode. Open to folding it intoctx_purgeif preferred.ContentStore.deleteSource(label)reuses the existing dedup-by-label delete statements inside awithRetrytransaction; returns{ existed, deletedChunks }.API
ctx_forget()-> lists indexed source labels + chunk counts (read-only).ctx_forget(source)withoutconfirm: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_forgetadded to the annotations contract map (destructiveHint:true, idempotentHint:true, readOnlyHint:false, openWorldHint:false).tests/opencode-plugin.test.ts:ctx_forgetin the native plugin tool map ([Feature]: Plugin-only tool registration for ts-plugin adapters (OpenCode, KiloCode, OpenClaw) #574).WHEN / WHEN NOT / RETURNS / EXAMPLE).Docs
Notes
index --source <label>stores a bare label (inconsistent with indexDirectory) — is a fix welcome? #914).