Skip to content

feat: unify archive metadata storage#94

Merged
Moskize91 merged 1 commit into
mainfrom
codex/unify-archive-metadata
Jul 4, 2026
Merged

feat: unify archive metadata storage#94
Moskize91 merged 1 commit into
mainfrom
codex/unify-archive-metadata

Conversation

@Moskize91

Copy link
Copy Markdown
Contributor

Summary

  • migrate archive metadata from book-meta.json into the unified object metadata store
  • make archive root get return only the archive marker or URI JSON
  • render object metadata as text by default and keep JSON only behind --json
  • remove legacy book-meta.json archive handling and update tests

Tests

  • pnpm run lint:fix
  • pnpm run verify
  • pnpm run test:run

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Archive metadata is now shown and edited more consistently from the command line, including clearer root archive handling and text or JSON output.
    • Metadata entries can now be listed, updated, deleted, or cleared with improved command support.
  • Bug Fixes

    • Fixed archive root requests so they return the archive root instead of trying to read a page.
    • Updated missing-metadata and existing-metadata messages for clearer error reporting.
  • Documentation

    • Clarified help text and examples for archive and metadata commands.

Walkthrough

This PR migrates archive/book metadata persistence from a file-based book-meta.json to the database-backed object metadata store. Document.readBookMeta/writeBookMeta/replaceBookMeta now use this.metadata with ObjectMetadataKind.Archive. Archive path allowlists (WIKG_ARCHIVE_PATTERNS, LEGACY_SDPUB_PATTERNS) no longer reference book-meta.json. A new archive-root get flow (isArchiveRootGet, writeArchiveRoot) returns a root marker instead of reading a page. CLI metadata commands (get/set/put/delete/clear) now support both text and --json output via an expanded writeMetadataMap, and --json is no longer rejected for delete/clear. Error messages, help text, and UI title strings referencing "book meta" were updated to "archive metadata." Tests were updated/added accordingly.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant runArchiveCommand
  participant writeArchiveRoot
  participant readArchivePage

  CLI->>runArchiveCommand: get objectId
  runArchiveCommand->>runArchiveCommand: isArchiveRootGet(args)
  alt targets archive root
    runArchiveCommand->>writeArchiveRoot: writeArchiveRoot(args)
    writeArchiveRoot-->>CLI: JSON {uri} or "<archive>\n"
  else targets specific page
    runArchiveCommand->>readArchivePage: readArchivePage(uri)
    readArchivePage-->>runArchiveCommand: page data
    runArchiveCommand-->>CLI: writePage(data)
  end
Loading
sequenceDiagram
  participant Document
  participant MetadataStore

  Document->>MetadataStore: getMap("")
  MetadataStore-->>Document: metadata map (or empty)
  Document->>Document: parse via bookMetaSchema
  Document->>MetadataStore: replaceMap({kind: Archive, objectPath: ""}, meta)
Loading

Compact metadata

  • Type: Feature / refactor
  • Scope: CLI archive/metadata commands, document persistence, help docs, tests
  • Breaking change: No (internal storage change; <object-uri>/meta/<key> remains rejected)

Related issues: None specified

Related PRs: None specified

Suggested labels: refactor, cli, documentation, tests

Suggested reviewers: None specified

🐰 A rabbit dug where book-meta lay,
and found the database instead of clay.
Now archive roots reply in kind,
and metadata text and JSON align.
Hop, hop — the old file's put away. 🥕

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows a conventional commit style and clearly matches the main change to archive metadata storage.
Description check ✅ Passed The description is directly related to the changeset and accurately summarizes the migration and CLI behavior updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/unify-archive-metadata

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
test/cli/object-metadata.test.ts (1)

170-206: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding execution-level coverage for delete/clear output formatting.

This suite verifies get/put text vs. JSON rendering end-to-end, but for delete/clear only CLI argument parsing is tested (not runObjectMetadataCommand itself producing text/JSON output). Given writeMetadataMap is now invoked identically after delete/clear, a short execution test would close this gap.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/cli/object-metadata.test.ts` around lines 170 - 206, Add execution-level
test coverage for the object-metadata delete/clear paths in
runObjectMetadataCommand, since the current test only checks parseCLIArguments.
Extend the existing object-metadata CLI tests to assert the actual output
produced after delete/clear for both text and JSON modes, similar to the get/put
coverage, and verify that writeMetadataMap is exercised consistently for both
actions.
src/cli/object-metadata.ts (1)

161-179: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Keep metadata key order consistent across text and JSON output
formatMetadataText preserves insertion order, while formatCLIJSON applies the CLI key-priority ordering. That makes fields like title or description move when toggling --json; use the same ordering in both branches.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/object-metadata.ts` around lines 161 - 179, The metadata text
formatter currently iterates Object.entries(map) directly, so its key order can
differ from the CLI JSON output ordering. Update formatMetadataText to use the
same key-ordering logic as formatCLIJSON, reusing the shared ordering helper or
extracting one if needed, so fields like title and description stay in a
consistent position across both output modes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/cli/object-metadata.ts`:
- Around line 161-179: The metadata text formatter currently iterates
Object.entries(map) directly, so its key order can differ from the CLI JSON
output ordering. Update formatMetadataText to use the same key-ordering logic as
formatCLIJSON, reusing the shared ordering helper or extracting one if needed,
so fields like title and description stay in a consistent position across both
output modes.

In `@test/cli/object-metadata.test.ts`:
- Around line 170-206: Add execution-level test coverage for the object-metadata
delete/clear paths in runObjectMetadataCommand, since the current test only
checks parseCLIArguments. Extend the existing object-metadata CLI tests to
assert the actual output produced after delete/clear for both text and JSON
modes, similar to the get/put coverage, and verify that writeMetadataMap is
exercised consistently for both actions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d2e24300-2cca-4d4e-8154-6e44a40b04c1

📥 Commits

Reviewing files that changed from the base of the PR and between f310143 and adbee8e.

📒 Files selected for processing (24)
  • data/help/commands/archive/get.jinja
  • data/help/commands/maintenance/meta.jinja
  • src/archive/query/archive-view.ts
  • src/cli/archive-maintenance.ts
  • src/cli/archive.ts
  • src/cli/args.ts
  • src/cli/help.ts
  • src/cli/object-metadata.ts
  • src/document/document.ts
  • src/facade/import.ts
  • src/legacy-sdpub/upgrade.ts
  • src/output/epub/book.ts
  • src/wikg/archive.ts
  • test/cli/archive-maintenance.test.ts
  • test/cli/archive.test.ts
  • test/cli/object-metadata.test.ts
  • test/document/directory-document.test.ts
  • test/facade/digest.test.ts
  • test/facade/import.test.ts
  • test/gc/gc.test.ts
  • test/legacy-sdpub/upgrade.test.ts
  • test/output/epub-book.test.ts
  • test/wikg/archive.test.ts
  • test/wikg/spine-digest-file.test.ts
💤 Files with no reviewable changes (3)
  • src/wikg/archive.ts
  • src/legacy-sdpub/upgrade.ts
  • test/legacy-sdpub/upgrade.test.ts

@Moskize91 Moskize91 merged commit 2d318ae into main Jul 4, 2026
3 checks passed
@Moskize91 Moskize91 deleted the codex/unify-archive-metadata branch July 4, 2026 04:09
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