Skip to content

Add load_area and a JSON CLI; fix section skipping and record diagnostics - #19

Merged
ctoth merged 5 commits into
masterfrom
fix/core-cli-diagnostics
Sep 24, 2026
Merged

ctoth merged 5 commits into
masterfrom
fix/core-cli-diagnostics

Conversation

@ctoth

@ctoth ctoth commented Sep 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • cli.load_area(path, dialect=None) (fixes the red CI: test_medievia.py calls it). dialect is a DIALECTS key (rom, merc, smaug, circle, tba, medievia, godwars, swr, coffeemud), an area-file class, or None. An explicit dialect is parsed as-is and its errors propagate. With None, the detected dialect runs first, then ROM, Merc and SMAUG (files only). The first parse with rooms wins. If no parse has rooms, the first parse that succeeded is returned. If nothing parses, the detected dialect's error is raised. If detection itself failed, its ValueError is raised, chained from the fallback error that got furthest into the file.
  • CLI: area-reader [--type auto|rom|merc|smaug|circle|tba|medievia|godwars|swr|coffeemud] <path>. On success it prints JSON to stdout and exits 0. On failure it prints one JSON line to stderr and exits 1: {"error", "file", "line", "column", "section"}. python -m area_reader.cli works, and logging goes to stderr.
  • ParseError now has reason, filename, and 1-based line/column fields, plus section for the text readers. The formatted message is unchanged.
  • Unknown sections (skip_section truncates unrecognized sections at the first '#' in their body (silent data loss / misparse) #5): a section is skipped up to the next line that starts with # plus an uppercase name (or #$), so a # inside the body no longer cuts it short.
  • Diagnostics (Repeating vnums between rooms/npcs/objects #2, partial): a duplicate vnum in rooms/mobs/objects still overwrites the earlier record, but each overwrite is now recorded as {"kind": "duplicate_vnum", "family", "vnum"}. Each skipped section is recorded as {"kind": "skipped_section", "section"}. Every reader serializes the list as "diagnostics" in as_dict/as_json. skipped_sections stays as it was. Duplicate detection covers the text readers (ROM/Merc/SMAUG/SWR/GodWars); the Circle-family and CoffeeMud readers emit an empty list.
  • Dead code (Dead loader code: SmaugAreaFile.load_room calls nonexistent read_room_data; jump_to_section mispositions on missing section #10): removed SmaugAreaFile.load_room (it called a nonexistent read_room_data) and its read_line. jump_to_section now matches the header at a line start and raises ParseError when the section is missing. Merc and SWR share model.native_reset_arg2_suffix. The Medievia suffix behaves differently, so it is kept.

detect_area_type is unchanged.

Fixes #5
Fixes #10
Partially addresses #2 (records duplicates; does not change overwrite behaviour)

Verification

  • Full suite: 1077 passed
  • Corpus sweep (321 files): 221 ok / 100 fail, the same as master. load_area returns the same parser as the sweep's fallback loop for every file (0 mismatches).

🤖 Generated with Claude Code

https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN

ctoth and others added 5 commits September 23, 2026 19:37
ParseError now carries reason, filename, 1-based line and column, and
section fields alongside the unchanged formatted message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN
load_area parses with an explicit dialect, or tries the detected dialect
and then the ROM, Merc and SMAUG readers, returning the first parse with
rooms. The CLI accepts --type, prints JSON to stdout, reports failures as
one JSON line on stderr with exit status 1, and runs via python -m.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN
skip_section stopped at the first "#" anywhere in the body, truncating
sections such as #SOCIALS and inventing bogus sections from the rest.
It now skips to the next line that starts with "#" and an uppercase
section name (or "#$"), keeping the whole body.

Fixes #5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN
Text readers still let a later record replace an earlier one with the
same vnum, but now note each replacement as a duplicate_vnum diagnostic
per family, and each skipped section as a skipped_section diagnostic.
Every reader serializes the list under "diagnostics" in as_dict/as_json.

Refs #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN
Delete SmaugAreaFile.load_room, which called a nonexistent
read_room_data, and its read_line helper. jump_to_section now finds the
header at a line start and raises ParseError when it is absent instead
of moving to a meaningless offset. Merc and SWR resets share the model's
arg2 suffix helper instead of byte-identical copies.

Fixes #10

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsTyuYeZHogKAnGhufs9gN
@ctoth
ctoth merged commit a4f459c into master Sep 24, 2026
4 checks passed
@ctoth
ctoth deleted the fix/core-cli-diagnostics branch September 24, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant