Skip to content

Harden suggestChanges and add an experimental suggest_changes MCP tool - #70

Merged
aloth merged 1 commit into
mainfrom
feat/suggest-changes-followup
Nov 16, 2026
Merged

aloth merged 1 commit into
mainfrom
feat/suggest-changes-followup

Conversation

@aloth

@aloth aloth commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Follow-up to #66. Thanks to @fredericosantos for the original suggestChanges idea and implementation; this PR fixes issues found after merging it and exposes it through MCP.

Fixes in suggestChanges:

  • An edit with empty before, inserted and after made the search loop forever. It is now reported as invalid, and nearestIndex returns -1 for an empty needle.
  • Running the same edit twice tracked it twice, so the tracked deletion held the old text two times. An edit that is already tracked at that place is now reported as already-tracked and nothing is sent, also within one call.
  • After writing, the doc is read again; an edit without a tracked change at the expected place is reported as not-tracked instead of done.
  • With review-only access the call failed with "applyOtUpdate did not return an acknowledgement". It now throws SuggestionPermissionError, which says the account needs edit access, and nothing is written.
  • The meta.tc seed now follows the format of Overleaf's generateIdSeed (seconds since the epoch, then random digits) instead of 18 random hex digits.
  • inserted equal to deleted is reported as unchanged instead of not-pushed.

API changes, all additive:

  • SuggestionResult gains already-tracked, unchanged, invalid and not-tracked; hint is optional.
  • planSuggestions(projectId, path, edits) reports the outcome per edit without writing; suggestChanges accepts { expectedVersion } and refuses to write when the doc changed since.
  • SuggestionPermissionError, SuggestionPlan and SuggestionOutcome are exported.
  • suggestChanges is marked experimental: sharejs-text-ot docs only, history-ot docs are refused, and collaborators see the old text for about 0.2 seconds while an edit is undone and redone.

New MCP tool suggest_changes (experimental):

  • Calls suggestChanges behind the same confirmation as the other write tools. The dialog lists each edit with its location and the suggested deletion and insertion, or why it is left alone.
  • Asks nothing and writes nothing when no edit can become a suggestion, and refuses to write when the doc changed after the preview.
  • Returns one result per edit. Documented in docs/MCP.md and SKILL.md.

Tests: unit tests for each fix with a stubbed socket and no network, plus MCP tests for confirm, decline, already-tracked, version conflict, no elicitation, env opt-out and the tool schema. npm test 263/263, lint at the existing warning count.

suggestChanges no longer loops on an edit with empty before, inserted and after (reported as invalid, and nearestIndex returns -1 for an empty needle), skips edits that are already tracked (already-tracked) instead of tracking them twice, reads the doc again after writing and reports not-tracked when no tracked change shows up, reports unchanged when inserted equals deleted, and throws SuggestionPermissionError naming the missing edit access when the untracked undo is refused. The meta.tc seed now follows the format of Overleaf's generateIdSeed (timestamp plus random digits). planSuggestions reports the outcome per edit without writing, and an expectedVersion option refuses to write when the doc changed since. SuggestionResult only gains values; hint is optional.

The new MCP tool suggest_changes calls suggestChanges behind the same confirmation as the other write tools: the dialog lists each edit with its location and the suggested deletion and insertion, it asks nothing when no edit can become a suggestion, and it refuses to write when the doc changed after the preview. Marked experimental in the tool description, the JSDoc and docs/LIBRARY.md: sharejs-text-ot docs only, history-ot docs are refused, and collaborators see the old text for about 0.2 seconds.
@aloth
aloth merged commit cd6510a into main Nov 16, 2026
2 checks passed
aloth added a commit that referenced this pull request Nov 16, 2026
Set version 0.18.0 in package.json, package-lock.json, CITATION.cff and server.json, and fold the Unreleased CHANGELOG entries of #66, #70 and #71 and the CONTRIBUTING.md change into the 0.18.0 section dated 2026-11-16.
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