logo
Published on

CH9. lms-sync: Keeping the school LMS in step with local folders and the calendar

Authors
  • avatar
    Name
    seren-wib
    Twitter
Contents

0. Introduction

Part 9 of the skills series. What a skill is and why these rules moved out of the instruction files is in CH0. Skills overview.

During the semester, lecture files, assignment attachments and notices keep appearing on the school LMS for every course. I collect these files in iCloud under UNIV/<semester>/<course>/ and write my notes there. The problem was that a person had to check by eye, every time, what had not been downloaded yet. Assignment deadlines were also often on the LMS only, not on my calendar.

In restaurant terms, the LMS is a kitchen pass where order slips keep piling up, and I am the waiter who walks past it each time and picks up only the plates I have not taken yet. I check whether a plate is one I already have by its contents, not by the name tag on it, bind loose plates into one course set, and copy the booking times into a reservation book. The pass is the course page of a Moodle-based LMS, the plates are the lecture files, checking contents is a SHA-1 hash comparison, binding into a course set is converting PPT to PDF, and the reservation book is Google Calendar.

lms-sync is the skill that hands this job to the agent. When I say "get the LMS files", it runs three steps per course: download missing files, convert PPT to PDF, and add deadlines to the calendar. The skill is one SKILL.md and one helper script, pagecount.mjs. Sizes and run records are in the tables of 5. Reporting and closing to-dos. The sources are the 3 commits to this skill in my dotfiles repo, the worklog for school work, and the memory change log. Where a reason is not written down anywhere, the post says "no record". Values that must not be public, such as course numbers, the school account and the login steps, are left out.

1. Reading the LMS through Chrome

One lms-sync run: LMS course page, Files, Convert, Calendar

One lms-sync run: LMS course page, Files, Convert, Calendar

The course page of a Moodle-based LMS holds the modules: ubfile for lecture files, assign for assignment attachments, ubboard for notice attachments. Deadlines go to Google Calendar.

The agent does not use an LMS API. On top of the session I am already logged into in Chrome, it opens a new tab through the Claude in Chrome extension and runs JavaScript fetch inside the page. The limits that come with this approach are written at the top of the skill.

  • School notice (2026-11-09): abnormal heavy access can get an account restricted. So the skill goes one course at a time, pauses between requests, never runs fetch in parallel, and fetches only what is missing.
  • Extension limits: a JavaScript call is cut off after about 45 seconds (the script keeps running), and results are truncated at about 1000 characters. One course per call; results are stored on window and read back in pieces.
  • Query string masking: if a result contains a URL query string, the extension replaces it with [BLOCKED: Cookie/query string data]. So only file names are returned.
  • Approval scope: the request to fetch is itself the approval to download the missing files. The agent does not ask per file; it lists what it saved in the report.

At first this was not a skill but a memory file (notes on collecting LMS files). On 2026-11-17, when task-specific rules were moved from memory into skills, lms-sync was born at 46 lines. Why a skill rather than memory is the same story as in CH0: this is not needed in every session, only when looking at the LMS.

2. Recognizing files already downloaded

I often rename the files I download, so comparing names alone would fetch the same file again. So the skill decides whether a file is the same by its SHA-1 hash, not its name, and keeps the list of what was taken in the course folder's manifest file, .lms-sync.json.

Deciding whether one LMS item is already there: manifest, name match, SHA-1

Deciding whether one LMS item is already there: manifest, name match, SHA-1

The first version (2026-11-17) compared by file name only (or by title when the name could not be read). Two days later, the 2026-11-19 commit turned this into three steps.

  1. Manifest: each course folder keeps .lms-sync.json, one entry per LMS module id: {"title", "name", "sha1", "size", "path"}. An item in the manifest counts as already there whatever its local name is now. It is fetched again only when its path is gone and no local file has the same sha1.
  2. Name comparison: items not in the manifest are matched by name against the whole course folder, recursively and across every file type, including jpgs attached to notices.
  3. Hash comparison: if no name matches, the page fetches the file without saving it and hashes it with crypto.subtle.digest("SHA-1", ...). Local files of the same extension are hashed with crypto.createHash("sha1") in node -e. A match means the file was only renamed, so it is recorded in the manifest and not saved.

Why SHA-1 and not MD5 is in the worklog: the browser's Web Crypto crypto.subtle has no MD5. The browser and the local side have to use the same algorithm, so it became SHA-1. The local side uses node because the command is the same on macOS and Windows.

The hash comparison also catches duplicate posts. In one course, the file posted under "Chapter 15" was actually the same file as the Chapter 14 pptx. The skill keeps this as one line: when a fetched file looks like one already there, compare SHA-1 and drop the duplicate.

Only files that are truly missing get saved. The fetched blob is clicked through <a download>, lands in ~/Downloads, and is moved with mv into the course folder. For lecture files, GET /mod/ubfile/view.php redirects to the file, but HEAD returns 404, so the file name is taken from the last path segment of r.url after fetch. If the redirect goes to another host, fetch throws a TypeError, and the item is matched by title instead. Items that only have an 열기 (Open) button go to a viewer and cannot be downloaded; the report counts them as viewer-only.

The same commit also fixed where files go. The folder's existing layout comes first; these defaults apply only when it has none.

KindPlace
Lecture files (ubfile)pdf/, with the original pptx next to its pdf
Assignment attachments (assign)hw/hw<N>/, or hw/<assignment title>/ when unnumbered
Notice attachments (ubboard)공고문/ (notices folder)
SyllabusCourse folder root, as <course name>-강의계획서.pdf
Anything elseCourse folder root, and the report says where it went

The 2026-11-27 run created 4 new manifests, and from then on items in a manifest are not fetched again.

3. PDF conversion and page count check

Two ways to count PDF pages: /Count of the root Pages and the number of /Type /Page objects

Two ways to count PDF pages: /Count of the root Pages and the number of /Type /Page objects

Conversion is soffice --headless --convert-to pdf. Pages are counted either from the /Count at the root of the PDF page tree or from the number of /Type /Page objects.

ppt, pptx, doc and docx are converted with LibreOffice's soffice --headless --convert-to pdf --outdir <same folder> <file>, and the original stays next to the pdf. The Mac has LibreOffice from Homebrew. Windows has none (checked 2026-11-19), so the agent converts with the installed PowerPoint, or asks me before installing LibreOffice with winget. hwp files are left alone and only listed, because LibreOffice cannot read current HWP.

After conversion, the page count must match the slide count. The slide count is the number of ppt/slides/slide*.xml files inside the pptx zip. Counting pages turned out to be the tricky part. The first version said to use mupdf's mutool info or count /Type /Page objects, but Windows has no mutool, and mdls on the Mac returned null for the page count.

So on 2026-11-19 a dependency-free Node script, pagecount.mjs, was added. It does two things.

  • It reads the PDF as latin1 and collects the N 0 obj objects. Compressed object streams (/Type /ObjStm) are decompressed with zlib.inflateSync so the objects inside are collected too. When an object number appears again, the later definition wins (incremental update).
  • The first column is the largest /Count among /Type /Pages objects, the page count the root page tree states. The second column is the number of /Type /Page objects, marked OBJ+ when it differs from the first.

Why the first column is trusted is recorded with numbers in the script comment and the worklog. Checked against the Windows PDF API page count on 110 course PDFs, the root /Count matched on all 110. The object count was higher on 2 of the 110. Those PDFs keep orphan pages that are not linked into the page tree, so OBJ+ is only a flag, not an error. If LibreOffice breaks the layout, the agent converts again with PowerPoint and says so in the report.

There were few actual conversions. The first run on 2026-11-17 converted one pptx, and its 48 slides matched 48 PDF pages. The 2026-11-20 run re-counted one existing PDF (35 pages, 35 slides).

4. Adding deadlines to the calendar

Deciding whether one deadline goes on the calendar: submitted, past, same date + course

Deciding whether one deadline goes on the calendar: submitted, past, same date + course

Deadlines are read from the assignment page's .submissionstatustable (end time, submission status) and from notice board posts. They go into the school-schedule calendar in Google Calendar, and list_events checks what is already on the day.

  • Submitted assignments are skipped. Past dates are skipped too.
  • Duplicates are matched by date and course, not by title. Some existing events were added by hand, so title formats vary. The same deadline can be there as "assignment due" or "[Submit] …".
  • Exam dates come from notices only. This semester's syllabi list exams by week ("week 15") with no date. So the agent does not guess; it reports "no date yet".
  • Search scope: the calendar connector's search_events only searches the primary calendar. So the agent finds the school calendar's id with list_calendars and runs list_events on that calendar around the date.
  • A new event gets the title [course short name] <assignment> due, the LMS end time, and the LMS item title as its description. The list (title, date, reminder) is shown before writing, unless the request already said to add them.

The reminder time once caused a rule conflict. My general calendar rule was "always ask for the reminder time first". On the first run, 2026-11-17, it collided with the LMS deadline default (9 a.m. the day before; 900 minutes before for all-day events as a popup). That day a line saying "LMS assignment deadlines are the exception" went into the memory change log, and the skill now says this default is my standing answer for LMS deadlines, so the general rule does not apply.

5. Reporting and closing to-dos

What a run leaves behind: report, worklog/univ/WORK.md, worklog/*/WORK.md

What a run leaves behind: report, worklog/univ/WORK.md, worklog/*/WORK.md

A run leaves records in three places: the report, my logbook worklog/univ/WORK.md, and the other logbooks, which are every worklog key (worklog/*/WORK.md). The worklog structure is covered in CH6. session-flow.

The report is in numbers per course: downloaded, already there, viewer-only, failed (with the reason), converted, events added, skipped as duplicates. The same numbers go as one dated line under ## 한 일 (done) in worklog/univ/WORK.md. New LMS facts, such as a new course or a changed page structure, go into the school file in memory.

The last rule was added on 2026-11-27. That day the LMS sync session confirmed two assignments as submitted and closed only the to-dos in worklog/univ/WORK.md. The same assignments were also open to-dos under the worklog key for the virtual machine labs, and the session did not look there. So the skill gained a line: for each assignment confirmed as submitted, grep every key's WORK.md for the course short name and the assignment number (like HW7) and close its to-dos. The shared instructions and the session-flow skill got the same kind of rule that day.

As of 2026-11-28. Sources: git log -- claude/skills/lms-sync and wc -c -l in the dotfiles repo, and the run records in the school worklog.

ItemValue
Commits to the skill3 (11-17, 11-19, 11-27)
SKILL.md58 lines, 6,983 B
SKILL.md, first version46 lines, 5,045 B
pagecount.mjs56 lines, 2,361 B, 0 dependencies
Page check (root /Count matched)110 / 110
Page check (more objects than pages)2 / 110

Runs recorded in the worklog:

DateScopeDownloadedAlready thereViewer-onlyFailedConvertedEvents addedSkipped
2026-11-178 courses15no record10112
2026-11-201 course21410000
2026-11-231 course01700020
2026-11-276 courses7no recordno record0025

On 2026-11-20 the request narrowed the run to one course (one more course was only compared, and all 15 of its items were already there). Of the 2 events on 2026-11-23, one was not an LMS deadline but an event asked for in the same request.

6. Reflection

A sync that compared names only became one that recognizes the same file even after I rename it.