Skip to content

docx-grader: docx model, checks and spec CLI (AI-Assisted) - #386

Open
bh0fer wants to merge 7 commits into
mainfrom
feature/docx-grader-checks
Open

bh0fer wants to merge 7 commits into
mainfrom
feature/docx-grader-checks

Conversation

@bh0fer

@bh0fer bh0fer commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Part 1 of 3 for #385. It adds the @hfr/docx-grader package with the docx model, the checks and the spec CLI.

Behavior

  • yarn workspace @hfr/docx-grader create-spec <original.docx> reads a model Word document and extracts every formatting that differs from a blank document (Normal.dotm defaults in baseline/wordDefaults.ts).
  • The teacher picks checks in an interactive list, then gets <original>.docx-spec.yaml. --all skips the list.
  • Running it again preselects the previous choice and keeps the hint/docs fields teachers add by hand.
  • gradeDocument(spec, docModel) grades another document against the spec. The DocxGrader component in PR 2 will use it in the browser.

Check kinds:

  • paragraph style
  • paragraph format
  • character format
  • numbering
  • section/page setup
  • header/footer
  • image (width ±0.3 cm, wrapping, caption grouped or adjacent)
  • directories (TOC / table of figures / bibliography)
  • auto hyphenation

Design decisions (agreed with the maintainer before implementing):

  • Effective values: grading compares the resolved values (docDefaults → style chain → numbering → direct formatting, theme fonts). Only the use of a style is checked as such.
  • Anchors: checks find paragraphs by their normalized text. Generated content (TOC entries, the TOC building block heading) is excluded, and captions match by description. Dashes, quotes and whitespace count as equal; this is configurable per spec.
  • Spec validation: the spec is validated structurally at runtime because it is edited by hand. A broken check fails on its own instead of stopping the grading.
  • No table checks: none of the samples has a table, so tables are only stripped in the raw document (PR 3).

Added after the first review round

  • Tabs: the new check tabs requires tabs where the original has them. Spaces still locate the paragraph but fail the check.
  • Formatting via styles: paragraph and character format checks get source: style where the original got those properties from its style, so the student must set them through the style, not directly. A spec-wide defaultSource: style | any (default any) applies to checks without their own source, which can override it. Overrides survive re-running the CLI.
  • Typed numbers: numbers typed by hand (1.1 Text) are found and reported by the numbering check.
  • CLI prompt: uses prompts instead of @inquirer/*, which needs Node ≥ 24.15 (the repo pins 24.13 and Netlify failed).

Follow-ups

  • PR 2: the DocxGrader component and a demo page
  • PR 3: generating the raw (unformatted) docx

Validation

  • yarn test --run packages/hfr/docx-grader: 39 tests pass. The fixtures are the issue's sample documents with emptied images (184 KB). Each original passes all of its own checks, each RAW file fails the formatting checks, and inline-XML regression tests cover nested tables, text-box pictures, unterminated fields and spec validation.
  • yarn typecheck, yarn format:check (package), yarn build: pass
  • CLI run with --all on the three samples, plus a re-run that kept the hints. The interactive checkbox was not exercised in CI.
  • Design review with the design-reviewer skill on the plan and on this branch; all findings fixed.

🤖 Generated with Claude Code

lebalz and others added 2 commits November 18, 2026 21:47
Extracts the formatting of a model Word document as checks into a
docx-spec and grades other documents against it (#385).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- validate the structure of hand-edited specs and fail single checks
  instead of the whole grading
- hash long ids so they stay stable when titles share a prefix
- read nested tables and pictures in text boxes once
- drop fields left unterminated at the end of a paragraph

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bh0fer
bh0fer requested a review from a team November 18, 2026 20:54
@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@netlify

netlify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for teaching-dev ready!

Name Link
🔨 Latest commit d22f7dc
🔍 Latest deploy log https://app.netlify.com/projects/teaching-dev/deploys/6afe1cb45b97d838e1bac216
😎 Deploy Preview https://deploy-preview-386--teaching-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lebalz and others added 4 commits November 18, 2026 22:30
Spaces count like tabs to locate paragraphs; the new tabs check reports
paragraphs where a student typed spaces instead of a tab.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@inquirer/* requires node >=24.15, the repository pins 24.13.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Format checks get source: style when the original's style gives the
expected properties; defaultSource sets it for the whole spec. Numbers
typed by hand are found and reported by the numbering check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

2 participants