Skip to content

Add pcf-debug: inspection and visualization tool for PCF files#7

Merged
kduma merged 2 commits into
masterfrom
claude/modest-einstein-7zVDt
Jun 2, 2026
Merged

Add pcf-debug: inspection and visualization tool for PCF files#7
kduma merged 2 commits into
masterfrom
claude/modest-einstein-7zVDt

Conversation

@kduma

@kduma kduma commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR introduces pcf-debug, a comprehensive read-only inspection and visualization tool for Partitioned Container Format (PCF) files. The tool walks a file's physical structure defensively, renders layouts and partition tables as text or self-contained HTML, and decodes partition contents through a plugin system.

Key Changes

  • New pcf-debug binary crate with minimal dependencies (no external argument parsing or rendering libraries)

    • Defensive file walking that tolerates corruption and surfaces anomalies as diagnostics rather than errors
    • Physical byte-layout modeling with gap and overlap detection
    • Plugin-based partition decoder system for format-specific interpretation
  • Core modules:

    • model/walk.rs: Defensive, read-only traversal of the table-block chain with per-block validation
    • model/layout.rs: Physical region mapping (header, table blocks, entries, data, slack, gaps)
    • model/diag.rs: Diagnostic types for structural anomalies (overlaps, truncation, hash mismatches, cycles)
    • plugin/mod.rs: Object-safe decoder trait and registry system
    • plugin/pfs.rs: Decoders for PFS-MS records (PFS_NODE and PFS_SESSION partitions per spec v1.0)
    • plugin/raw.rs: Fallback decoder for any partition type
  • Rendering backends:

    • render/text.rs: CLI/ASCII output with byte-map strip, layout, partition table, block chain tree
    • render/html.rs: Self-contained HTML report with inline CSS, collapsible sections, no JavaScript
    • render/hexdump.rs: Classic 16-column hexdump with file offsets
    • render/color.rs: Minimal ANSI coloring with NO_COLOR and TTY detection support
  • CLI interface (cli/mod.rs):

    • Subcommands: inspect (default), layout, table, chain, hexdump, decode
    • Global flags: --html, --no-color, --verify/--no-verify
    • Hexdump filtering by region/range with byte limits
    • Decode filtering by UID/label/decoder name
  • Comprehensive test suite:

    • tests/decode_pfs.rs: PFS-MS decoder validation (fields, ranges, warnings)
    • tests/diagnostics.rs: Structural anomaly detection (overlaps, truncation, cycles)
    • tests/cli_snapshot.rs: Text renderer output validation
    • tests/html_smoke.rs: HTML report structural integrity
    • tests/common/mod.rs: Shared test fixtures (canonical PCF, PFS records)

Notable Implementation Details

  • Defensive design: The walk tolerates file corruption that pcf::Container would reject, capturing anomalies as diagnostics for debugging broken files
  • No re-implementation: Reuses the reference crate's public byte parsers (FileHeader::from_bytes, etc.) to stay in sync with the spec
  • Renderer independence: Decoders produce a format-agnostic field tree (FieldNode) consumed by both text and HTML renderers, ensuring consistency
  • PFS-MS spec compliance: PFS_NODE and PFS_SESSION decoders mirror the spec's byte tables field-for-field, reporting violations as warnings rather than failing
  • Workspace integration: Added root Cargo.toml workspace configuration linking the reference crate and new tool

Files Modified

  • .gitignore: Expanded with Rust/Cargo, editor, and OS-specific patterns
  • .github/workflows/ci.yml: Updated coverage command formatting
  • Cargo.toml (new): Workspace root configuration
  • tools/pcf-debug/Cargo.toml (new): Binary crate manifest

https://claude.ai/code/session_012g2y2iK7i18XEMYEdQugLK

claude and others added 2 commits June 2, 2026 14:49
…gins

Introduce a read-only debugging tool for PCF files that visualises the
physical layout (header, table-block chain, entries, data regions, slack,
gaps) and decodes partition contents into field trees via a static plugin
registry. Ships built-in PFS-MS decoders (PFS_NODE, PFS_SESSION) and a raw
fallback.

- Add a root Cargo workspace tying the reference crate and the new tool.
- tools/pcf-debug: defensive chain walk, layout model with gap/overlap
  diagnostics, text and self-contained HTML renderers, hexdump, and a
  PartitionDecoder plugin trait.
- Tests: canonical 395-byte vector snapshot, HTML smoke, PFS decoder field
  trees, and diagnostics for corrupted files.
- CI: scope reference coverage to the pcf package and add a pcf-debug
  build/clippy/test/fmt job.

https://claude.ai/code/session_012g2y2iK7i18XEMYEdQugLK
@kduma
kduma merged commit 863a1db into master Jun 2, 2026
@kduma
kduma deleted the claude/modest-einstein-7zVDt branch June 2, 2026 15:07
kduma pushed a commit that referenced this pull request Jun 2, 2026
PR #7 added pcf-debug with a PFS-MS decoder plugin, but its DIRECT/DELTA
content-section parsing predates the compression extension. Bring it in sync
with the revised spec (Section 7.3 / 9.5):

- Decode the new compression_algo_id byte (0=none, 1=DEFLATE, 2=zstd,
  3=brotli) in both DIRECT (now 91 bytes) and DELTA (now 165 bytes) content
  sections, and shift all subsequent field offsets accordingly.
- Update the test fixture (pfs_node_direct) to the new 91-byte DIRECT layout
  and assert the decoded compression_algo_id field and its byte range.

Also add reference/PFS-MS-v1.0 to the workspace members introduced by PR #7,
so the crate builds within the workspace (it otherwise errors as a non-member).

Verified end to end: a real DEFLATE-compressed archive built with `pfs put`
now shows `compression_algo_id = 1 (DEFLATE)` under `pcf-debug decode`. Whole
workspace passes fmt, clippy -D warnings, and all tests (pcf, pfs-ms, pcf-debug).
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