Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
| } | ||
|
|
||
| function under(paths: string[], directory: string): string[] { | ||
| const prefix = `${directory.replace(/\/+$/, "")}/`; |
|
|
||
| /** A directory view, two levels deep, as the SDK's local memory tool lists one (no sizes). */ | ||
| function listing(shown: string, directory: string, paths: string[]): string { | ||
| const base = directory.replace(/\/+$/, ""); |
| `Invalid \`insert_line\` parameter: ${line}. It should be within the range [0, ${lines.length}].`, | ||
| ); | ||
| } | ||
| lines.splice(line, 0, insert.replace(/\n+$/, "")); |
…eletes 500 a call, hides nested hidden files, and resolves paths alike in both SDKs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
…ed rename leaves Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: zlareb1 <lareb.zafar@clickhouse.com>
This branch has not been deployed
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.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
The Python and TypeScript SDKs run the Claude API memory tool's commands against Loom: the files Claude keeps under
/memoriesare Loom documents, shared by every agent of the namespace and found byknowledge.search(pip install 'clickhouse-loom[claude-memory]';@clickhouse/loom/integrations/claude-memory).Why
The Claude API memory tool (
memory_20250818) leaves storage to the application: the model sendsview,create,str_replace,insert,deleteandrenamecommands on paths under/memories, and the SDKs ship base classes to implement them (BetaAbstractMemoryTool/BetaAsyncAbstractMemoryToolinanthropic,betaMemoryToolwithMemoryToolHandlersin@anthropic-ai/sdk). Their reference backend writes local files, so a Claude app's memory sits on one host and one agent. This PR implements those interfaces over Loom, so the memory tool's files live in the user's Loom deployment, every agent of the namespace reads the same files, and Loom's document search finds what they say. No store, vector database or cache is added.Design (interfaces read from
anthropic2.8.0 and@anthropic-ai/sdk1.8.0):memory.set, two files with the same text would merge into one row and a near-identical file would be flagged as a conflict, since every searchable memory type goes through the write-time conflict check; a file store must never do either. Loom's documents plane fits a file:knowledge.upsertreplaces a document by URI,knowledge.getreturns its exact text (checked against a running server: whitespace, blank lines and trailing newlines come back byte for byte),knowledge.bulk_deleteremoves documents, andknowledge.searchchunks and finds them./memories/<path>is the documentloom-memory://<store>/memories/<path>, taggedclaude-memory:<store>. Directories are the paths' prefixes;viewof a directory lists the store's documents (knowledge.listby the tag, paged) two levels deep.store(defaultdefault) is one path segment: one tree per application, or per user. Every path must be/memoriesor under it after.and..are resolved over the whole path (as POSIX normpath:/memories/a/../../memories/bis/memories/bin both SDKs), or the command is refused before Loom is called (the SDK's reference also accepts/memoriesX; this does not)..) are left out at every level. An emptyold_stris refused (counting empty matches would hang in JavaScript), andcreateis refused on a path that is a directory. A refusal is the SDK'sToolError, which the tool runner returns to the model as an error result.str_replace,insert);renamecopies each file under the old path to the new one, then deletes the old; a failure partway leaves the copies made so far (the docs say so). Deletes go out 500 URIs a call,knowledge.bulk_delete's cap. Two agents editing one file at once keep the later write, as the SDK's local tool does;knowledge.upserthas no compare-and-set.AsyncLoomMemoryToolover aloom.Agent(async tool runner) andLoomMemoryToolover aloom.SyncAgent(sync runner); each refuses the other agent kind. The command logic is shared pure functions; the two classes only differ in awaiting the client.loomMemoryHandlers(agent, { store })returnsMemoryToolHandlers, andloomMemoryTool(agent, { store }, extras)wraps them inbetaMemoryTool, passingextras(such ascache_control) through, as the Python classes pass their keyword arguments to the base. Both SDKs read and write the same documents.clickhouse-loom[claude-memory]pinsanthropic>=2.8,<3(2.8 has the async base) and joinsSDK_ADAPTER_EXTRAS;anthropicjoins the root mypy overrides, since the SDK gate runs without the extra.@anthropic-ai/sdkis an optional peer dependency (>=1.8.0 <2.0.0, dev-pinned to 1.8.0), with its own export entry, build entry, README section and dist test.Scope and risk
SDK-only: two modules, an extra, a peer dependency, docs. No server, wire or schema change; documents are already covered by erasure.
uv.lockis unchanged;sdk/typescript/package-lock.jsonadds@anthropic-ai/sdk1.8.0 as a dev dependency.Compatibility, rollout and rollback
Tests
sdk/python/tests/test_claude_memory.pythroughmake test-sdk-adapter-claude-memory(28 tests, each command test run on both the async and the sync tool;mypy --stricton the module): the classes are the SDK's memory tool bases and declarememory_20250818; create then view with line numbers and a range, and create refused when the file exists; a directory view two levels deep across list pages, hidden files left out; str_replace of one occurrence, refused for none or many; insert and its range; delete of a file or a directory (/pis not a prefix of/pq); rename of a file or a directory and its refusals; every path kept under/memories(/memoriesx,../) with no call to Loom, anda/../../memories/baccepted; an emptyold_strrefused; nested hidden files left out;createon a directory refused; 501 files deleted as 500 + 1; a store sees only its own files; bad stores and the wrong agent kind refused; the import error names the extra; a realloom.Agentpostsknowledge.getandknowledge.upsertwith the URI and tag.SDK_ADAPTERS_RESOLUTION=lowest-directon Python 3.11 (anthropic2.8.0).sdk/typescript/src/integrations/claude-memory.test.ts(10 tests, through a realAgentover a fetch stub): the same commands, refusals, paging, stores and path resolution, the emptyold_str, nested hidden files,createon a directory, the batched delete,extraspassed through, and a replacement text with$&kept literal. The TS SDK's own gates:biome check,tsc --noEmit,vitest run(356 passed),check:readme,check:version, andcheck:dist(build, the dist exports test with the new subpath, publint, attw).tests/integration/test_sdk_claude_memory_tool.pyagainst a local server (fake embedder): a file created, edited, inserted into, viewed, found byknowledge.search, renamed into a directory, hidden from another store, and deleted, with the document read back after each step. 1 passed withanthropicinstalled; without it the module skips, as in CI's integration jobs.make format lint; the unit tests that name the integrations, the extras, the framework docs, doc links and public copy (978 passed).AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. Checked: the memory tool bases, command types and the SDKs' local reference implementation (
anthropic2.8.0_beta_builtin_memory_tool.py,@anthropic-ai/sdk1.8.0helpers/beta/memory), and the tools against a running Loom.I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass (locally the named unit tests; the full suite in CI'spytest unitparts); the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code