Repository navigation
Fix(mcp): the new tools keep links, tasks and scopes straight - #46
Merged
Merged
Conversation
A review of the desktop's port of these tools found bugs that are in zn's too. A rename could take a name that link syntax reads as something else, such as b#c.png, and report success while every link to the file stopped resolving. Those names are now refused. An upload still cleans its name, as the app's import does. A note a rewrite could not change now comes back in linksNotUpdated, where it used to be silent. Finishing a recurring task ended the series, because zn had no recurrence at all, though the desktop's task-recurrence.ts says zn mirrors it. This ports it with the shared case table, and update_task, toggle_task and zn task toggle now write the next occurrence. This changes task-line behaviour for those three. ToggleTaskInBody itself is untouched, so zn tui and the editor still end a series. Task ids count position, so they move when the note above them changes. Nothing should call them stable, and update_task takes expectedText to refuse an id that now names another task. On a task note, waiting wrote a field the parser ignores and a status change left completedDate behind. State, status and waiting are one frontmatter field there, so asking for two is refused. Under a path scope, a rewrite writes a link's full path, since whether a bare name is still unique depends on files the client cannot see. move_asset checks the final path, numbered name included, and not only the folder. daily_note no longer names a hidden folder. The database check reads the whole listing, since a scope can share a CSV and hide its schema file. The numbered name a write gets beside a hidden file has no cheap complete fix, so the docs now say what it reveals. Smaller edges: a case-only rename no longer overwrites a file at a fixed temp name, a hard link or a link at the destination counts as taken, moving a file to its own folder under another spelling does nothing, a heading with only spaces keeps its first line of text, and list_assets leaves out what the app hides. The shared mcp-scope.json fixture changes two expectations, which the desktop's copy has to take.
This brings the tools in step with the desktop's port of them. A destination folder that exists now has to be a name its parent lists, as the desktop requires, and a folder name that ends in a dot or a space or holds a colon is refused, since it does not mean the same folder on every system. A new test checks that a folder link, a junction on Windows, shows nothing and takes no write. A rename also refuses a colon or a trailing dot. A name that reads as a note once a system drops the end of it counts as a note, and Windows' device names are refused. Refusals and descriptions use the desktop's words, so the two servers answer alike. expectedText now answers null like any id that no longer matches, where it was an error. update_task and edit_section said the rest of the note keeps its bytes, yet they turned a CRLF note into LF. update_task now leaves every other line as it was and edit_section keeps a note that is all CRLF that way. A note mixing endings still comes out of edit_section with plain newlines, as on the desktop. The read-only folder test is skipped on Windows, where such a folder does not refuse a write. That was the Windows failure in CI.
The two ports each took the other's wording at the same moment, so they swapped strings rather than meeting. The desktop now holds this branch's earlier text, so this goes back to it: the rename_asset, move_asset, list_assets and update_task descriptions, the task id lines in the instructions, and the task note refusal. expectedText fails again rather than answering null. Saying what the task now reads tells the assistant what happened, where null looks like a deleted task.
Tool calls are served concurrently, and parallel writes lost edits: a link rewrite could put back a note's old text, and a server's read and write could interleave. Writes now take turns, one turn per server rather than per note, since a rename rewrites any number of notes and on a server does so where zn cannot lock them. A path scope is now judged before anything looks at the disk, and a move's answers stay the same whatever lies behind a folder the client may not use. daily_note answers cannotCreate rather than offering to start a note it could only misfile. Links hold up in a folder whose name has link syntax in it. A Markdown link encodes it, and a wikilink keeps a bare name or is reported in linksNotUpdated. A bare link under a scope no longer depends on hidden notes or files. An upload now cleans a name that would not survive on every system, which reaches zn tui's imports too, and a rename refuses it. A move keeps a real folder under any name, writes it as its parent lists it, refuses a link in the path, and works across volumes. A failed case-only rename goes back. toggle_task and frontmatter edits keep a Windows note's line endings, and state done keeps a finished note's date. The recurrence port reads Unicode spaces and far-off years as the original does. The shared fixture gains a vault and three cases, and daily_note's expectation changes, so the desktop's copy has to take the new bytes.
1 task
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.
A review of the desktop's port of the new MCP tools found bugs that are in zn's too, and this also takes the later rounds of that review. This fixes them for zn 0.17.0. Please do not merge until Adib says so.
What changes
Writes take turns
zn mcpprocess.Links
rename_assetrefuses# ? | [ ] ^ % : * " < >, a backtick, control characters, a trailing dot and Windows device names, each of which stops links reaching the file or does not survive on every system. An upload cleans its name instead, as the app's import does.rename_assetandmove_assetreturnlinksNotUpdated, the notes a rewrite could not read or write, or whose wikilinks cannot hold the new path. This was silent before. It applies to a local vault only, because a server rewrites links itself and does not report.#and?in a folder's name. A wikilink cannot hold them, so it keeps a bare name where that resolves, and is reported where it does not.Tasks
@repeat:writes its next occurrence. zn had no recurrence code, sotoggle_taskended the series as well.internal/vault/task_recurrence.gois a port oftask-recurrence.tsand runs the same 23-case table.update_tasktakes optionalexpectedText: when a different task is at that id, the call fails, says what the task now reads, and changes nothing. Nothing calls task ids stable any more.update_task,toggle_taskand frontmatter edits keep a Windows note's line endings, andedit_sectionkeeps a note that is all CRLF that way. A note mixing endings comes out ofedit_sectionand frontmatter edits with plain newlines, as on the desktop.waitingnow setsstatus: waiting, which the parser reads.completedDateclears on leaving done, andstate: doneon a finished note keeps its date. Passing any two of state, status and waiting is refused.Scopes
daily_noteanswerscannotCreatein place ofcreateWithwhen the note's folder is not shared.Edges
edit_sectionkeeps a heading with only spaces apart from its text.list_assetsleaves out.csv.base.jsonand.csv.bakfiles, as the app does.Behaviour to check
vault.ToggleTaskandRemote.ToggleTasknow go throughToggleTaskRepeating, sozn task togglechanges too.ToggleTaskInBodykeeps each line's ending, which also reacheszn tui.sanitizeFileNamenow drops trailing dots and spaces and prefixes a device name with_, which also reacheszn tuiimports.internal/mcp/testdata/mcp-scope.jsonchanges expectations and gains a vault and three cases. The desktop's copy has to take them byte for byte.Not in this change
zn tuiand the editor still end a recurring series.toggle_taskhas noexpectedText.help.tsand the website docs.markdownandkindthatupload_assetgives PDF, audio and video on a local vault, which are behind the desktop's.zn mcpprocess or from the app are not covered by the write turn.Tests
Each fix has a test. The fixes were removed one at a time to check that its test fails.
ZN_MCP_E2E=1 ZENNOTES_SERVER_CONTRACT_BINARY=<server> go test ./...passes, with the server built from znservera2532b8, including stdio tests through the built binary on a local vault and on the server. Thevault,backendandmcptests also pass on a Windows 11 VM.Not tested: real assistant clients. Linux CI skips the tests that need a case-insensitive volume, so those ran on macOS and Windows.