zotero-roam-mcp: quality and correctness pass on the AI tools - #23
Open
mattakamatsu wants to merge 1 commit into
Open
zotero-roam-mcp: quality and correctness pass on the AI tools#23mattakamatsu wants to merge 1 commit into
mattakamatsu wants to merge 1 commit into
Conversation
Quality pass (reuse/simplification/efficiency/altitude): - use the existing getItemYear helper instead of a local copy - share the settings derivation with configRoamDepot as setup.ts's getCurrentSettings - resolve inGraph with one getCitekeyPages() query instead of one findRoamPage per result - merge the citekey lookup and children identification into findItemWithChildren; share the import-outcome epilogue - trim the test extension-API helper and dedupe the mock import outcomes Correctness fixes: - coerce handler arguments (handlers are callable directly from JS, where Roam's schema validation does not apply), so a bad citekey or query yields an instructive message rather than a raw TypeError - treat an uncertain outcome (success: null, which leaves an empty page) as a failure, and fold non-Error failure reasons into the message - match citekeys case-insensitively on import, as search already did - refresh the citekey-page map when an import creates a page, so headless imports cannot leave the UI believing the page is missing - add offset paging to the search tool - guard the experimental AI-tools calls in onload/onunload, and clear the stored API handle when registration fails Adds tests for the failure paths, which previously passed with the throw removed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Roam prototype previewsThe preview deployment is ready. Paste a URL below into Load Developer Extensions from URL in Roam: |
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.
Follow-up to #22 (merged). Single commit, confined to the
zotero-roam-mcpprototype, from a review pass on the AI-tools code before offering it upstream to 8bitgentleman/zotero-roam.Quality (reuse, simplification, efficiency, altitude)
getItemYearhelper instead of a local copy of the same ternary.configRoamDepot, as a newgetCurrentSettingsinsetup.ts, so "the extension's current settings" is defined in one place.inGraphwith a singlegetCitekeyPages()query instead of onefindRoamPageper result (that was up to 50 datalog round-trips per search).findItemWithChildren; share the import-outcome epilogue between the two import tools.Correctness
Found by review, each verified against the real code:
TypeErroron bad input. Handlers are callable directly from JS, where Roam's schema validation does not apply, so{citekey: null}producedCannot read properties of null (reading 'trim')instead of one of the instructive messages. Arguments are now coerced.addBlocksArrayresolves withsuccess: null(neverfalse) when the formatted output is empty, after creating the page. An agent callingzotero-import-metadatawith a custom formatter that returns nothing gotsuccess: nulland no error, leaving an empty ghost page behind while reporting success. Anything short of a confirmed import now throws, and a non-Errorfailure reason is folded into the message instead of discarded.RoamCitekeysContextwhen it creates a page; the AI tools could not, since that map is React state. The UI would then still consider the page missing, and a later "Import metadata" click would try to create a page whose title already exists. The provider now refreshes on the extension's ownmetadata-added/notes-addedevents, which fixes the staleness for any non-UI importer, not just these tools.addToolthrowing inonloadwould have preventedrender();removeToolthrowing inonunloadwould have skipped unmount anddeleteDatabase(). Both calls are now guarded.offsetpaging (previously an agent could seetotal: 185with no way to reach past the first 50), and a failed registration clears the stored API handle.Tests
38 tests in the service (up from 25). The failure paths were previously unverified: deleting the entire throw block from the outcome handling left every test green. They now cover failed, non-
Error, and empty-output imports, argument coercion, offset paging, case-insensitive lookup, and the registration lifecycle.pnpm testpasses 444/444 with no type errors;pnpm buildandpnpm prepare:artifactsare clean.🤖 Generated with Claude Code