Repository navigation
feat(anki): pull reviews from Anki over AnkiConnect (#264) - #327
Merged
Merged
Conversation
Step 1 of the build order in the sync spike. A page at /vocabulary/anki/sync reads every review of LWT's notes from Anki through AnkiConnect on the learner's machine, maps cards to terms by the LwtId field, and posts them to POST /api/v1/anki/reviews in batches. Anki is only read; it asks once whether to trust the page (requestPermission). The server merges each term's reviews with MergeReviewHistory: reviews LWT already has (same second and grade) are dropped, so pulling twice is harmless; newer ones are appended from the stored state; and a review older than LWT's latest is fitted in where it happened, with the later history recomputed in one transaction. The .apkg importer now merges the same way, which fixes its old limit of skipping such reviews. The state a rebuild starts from is reconstructed exactly from the log; only a review predating a seeded term's whole history falls back to a fresh seed of its current status (seedFor). connect-src gains AnkiConnect on loopback. Strings in all 11 locales. Co-Authored-By: Claude <noreply@anthropic.com>
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.
Step 1 of the build order in the sync spike (
docs-src/developer/anki-sync-conflicts.md, #326): reviews done in Anki come into LWT without a file. Steps 2 (push LWT reviews to Anki) and 3 (fields, tags, flags, existence) are not in this PR, so #264 stays open.What the learner gets
A page at
/vocabulary/anki/sync, linked from the.apkgimport page:127.0.0.1:8765, starting withrequestPermission, so Anki asks once whether to trust the page. Nobody has to editwebCorsOriginList.LWT Termnote (findNotes+notesInfo), maps cards to terms through theLwtIdfield, and reads their reviews (getReviewsOfCards).POST /api/v1/anki/reviewsin batches of up to 5,000, then shows what was merged, already known, recomputed or skipped.Anki is only read. Pulling twice is harmless.
How reviews merge:
MergeReviewHistory(Review module)replaceHistoryFrom). A test checks that the result equals doing all the reviews in one app.review_log, which stores stability, difficulty and interval after each row; reps, lapses and state follow from the grades. The one approximation: a review older than a seeded term's entire history starts from a fresh seed of its current status (seedFor, anchored atWoCreated), because the original seed isn't stored.The
.apkgimporter (ScheduleReplay) now merges the same way. That fixes its documented limit of skipping an Anki review that predates LWT's last one.Other changes
connect-srcgainshttp://127.0.0.1:8765andhttp://localhost:8765(loopback, AnkiConnect's port only).check-localesreports 100%.Limits
.apkground trip. A local install is unaffected.cardReviewsfrom a high-water mark is the optimisation if large collections turn out slow.yanki-connect4.0.6's types, since the official README was unreachable. Worth one manual run before release.Tests
MergeReviewHistoryTest(9): duplicates, milliseconds, same-second grades, append from the stored state, rebuild, starting from nothing or from a seed, repository refusal.ScheduleReplayTest: interleaving, plus an equality check against a single history.AnkiReviewPullTest(6) andAnkiApiHandlerTest(5).seedFor.anki_sync.test.ts(6) covers the client, card-to-term mapping, chunking, unreachable versus refused, and batching.21-anki-importgains four tests: the page loads translated, it's linked, the unreachable message shows, and stubbed AnkiConnect data is posted and summarised.22,23,06and09still pass.composer test:no-coverage(9213),npm test(4437), Psalm (no errors), phpcs, typecheck, lint,build:allanddocs:buildall pass.🤖 Generated with Claude Code