cardspecter
# CardSpecter — Hollerith 80-Column Keypunch & Mainframe COBOL `EBCDIC` / `COMP-3` Resurrection Studio + MCP Server
[](./LICENSE)
[](https://z121245017-ai.github.io/cardspecter/)
[](./package.json)
[](./package.json)
> **Kiroween 2026 (`Resurrection` Category)** — Bringing **1928 IBM 029 80-Column × 12-Row Hollerith Punched Cards** and **1959 COBOL `DATA DIVISION` Fixed-Width `CP037` EBCDIC / `COMP-3` Copybooks** back from the crypt to solve modern legacy batch modernization with **Kiro Spec-Driven Development, Property-Based Testing, and the Model Context Protocol (MCP)**.
- **Live Interactive Keypunch & Hex X-Ray Studio**: **https://z121245017-ai.github.io/cardspecter/** (zero API keys, zero external CDN calls, instant 1-click historical mainframe decks)
- **Kiro Workspace Artifacts**: [`.kiro/specs/hollerith-copybook-engine/`](./.kiro/specs/hollerith-copybook-engine/), [`.kiro/steering/`](./.kiro/steering/), [`.kiro/hooks/`](./.kiro/hooks/), [`.kiro/agents/`](./.kiro/agents/), [`.kiro/settings/mcp.json`](./.kiro/settings/mcp.json)
---
## Why Resurrect 80-Column Cards & `COMP-3` Copybooks in 2026?
Every night across banking ACH wire clearinghouses, Medicaid institutional adjudication feeds, airline telemetry archives, and state tax pipelines, trillions of dollars still move inside fixed-width binary files shaped by two dead technologies:
1. **1928 IBM 80-Column × 12-Row Punched Cards** (`Cols 1–6` sequence numbers, `Col 7` indicator, `Cols 8–72` Areas A/B, `Cols 73–80` deck ID, and 12-row zone+digit overpunches).
2. **1959 Mainframe COBOL Copybooks** (`IBM CP037` EBCDIC, `COMP-3` Packed Decimal BCD nybbles, `COMP-4` big-endian binary words, `OCCURS n TIMES` repeating tables, `88`-level condition flags, and `REDEFINES` memory unions).
When modern engineering teams or AI coding agents inspect these files without a deterministic compiler, three failure modes strike immediately:
- **The Overpunch Trap**: A negative zoned decimal like `-$48,250.75` (`PIC S9(7)V99 DISPLAY`) overpunches `0xD0` onto the final digit `5`, producing byte `0xD5`—which decodes in `CP037` as `'N'` (`"00482507N"`), silently corrupting signs or crashing numeric parsers.
- **Off-by-One Byte Drift**: `PIC S9(9)V99 COMP-3` occupies `floor(11 / 2) + 1 = 6` bytes (not `11`), while `REDEFINES` unions overlay previous siblings without advancing the cursor unless wider. A single 1-byte miscalculation shifts every subsequent field in the record.
- **IEEE-754 Float Corruption**: Scaling `123.45 * 100` in standard floating point yields `12344.999999999998`, and 18-digit sovereign settlement amounts exceed `Number.MAX_SAFE_INTEGER`.
**CardSpecter** resurrects the physical tactile clarity of an **IBM 029 Keypunch + 3278 Phosphor X-Ray Terminal** and pairs it with a **zero-dependency `BigInt` binary codec and MCP Server** so humans and AI agents decode, verify, re-encode, and migrate legacy feeds with mathematical certainty.
---
## Architecture
```mermaid
flowchart LR
subgraph Legacy["Dead Tech Artifacts (1928–1983)"]
DECK["80-Col × 12-Row\nIBM 029 Card Deck"]
CPY["COBOL DATA DIVISION\nCopybook (.cpy)"]
BIN["Raw IBM CP037 +\nCOMP-3 / COMP-4 Dump"]
end
subgraph Engine["CardSpecter Zero-Dep Isomorphic Core (src/)"]
HOL["hollerith.mjs\n12-Bit Optical Reader &\nLace/Sequence Auditor"]
AST["copybook.mjs\nHierarchy + OCCURS +\nREDEFINES Offset Solver"]
COD["codec.mjs\nBigInt COMP-3 / Zoned /\nCOMP-4 + Forensics"]
MIG["migrator.mjs\nJSON Schema + TS +\nPostgreSQL NUMERIC DDL"]
end
subgraph Surfaces["Modern Developer & Agent Surfaces"]
WEB["Live Web Studio\n(docs/index.html)"]
MCP["MCP JSON-RPC Server\n(stdio + --http)"]
CLI["CLI Tool\n(bin/cardspecter.mjs)"]
end
DECK --> HOL --> AST
CPY --> AST --> COD
BIN --> COD --> MIG
HOL --> WEB
COD --> WEB
COD --> MCP
MIG --> MCP
COD --> CLI
```
---
## Quick Start (Zero Install Needed Beyond Node.js >= 20)
```bash
git clone https://github.com/z121245017-ai/cardspecter.git
cd cardspecter
# 1. Run full unit + Property-Based Testing (PBT) + live MCP test suite (20 tests, >1,700 generated PBT inputs)
npm test
# 2. Run CLI demo on the 1974 Core Banking ACH Wire & Overdraft deck
npm run demo
# 3. Inspect forensic diagnostics on a damaged lace-punched & BCD-corrupted deck
node bin/cardspecter.mjs demo corrupted_forensic_deck
# 4. Launch the MCP server (stdio by default, or loopback HTTP on port 3849)
node src/mcp-server.mjs --http 3849
```
---
## MCP Tools Exposed (`cardspecter-mcp`)
Configured automatically for Kiro IDE & Kiro CLI via [`.kiro/settings/mcp.json`](./.kiro/settings/mcp.json):
| Tool | Purpose |
| :--- | :--- |
| `compile_copybook` | Compiles fixed-80 or free-format COBOL Copybooks into exact byte offsets, record width, Draft 2020-12 JSON Schema, TypeScript types, and PostgreSQL/SQLite `NUMERIC(p, s)` DDL. |
| `decode_ebcdic_record` | Decodes raw `CP037` / `COMP-3` / `COMP-4` hex bytes into JSON, active `88`-level condition flags, `REDEFINES` union views, byte-aligned spans, and non-throwing forensic anomalies. |
| `encode_ebcdic_record` | Encodes modern JSON into exact fixed-width mainframe wire bytes + formatted 16-column `CP037` hex dump. |
| `inspect_hollerith_deck` | Punches text into 80×12 IBM 029 column bitmasks or optically reads punched cards while auditing sequence monotonicity (`cols 1–6`) and physical lace-card tear hazards. |
| `list_legacy_fixtures` | Lists and retrieves 4 built-in historical scenarios (`banking_ach_1974`, `apollo_telem_1969`, `medicaid_claim_1983`, `corrupted_forensic_deck`). |
---
## How Kiro Powered This Build (`/.kiro` Deep Dive)
1. **Spec-Driven Development ([`.kiro/specs/hollerith-copybook-engine/`](./.kiro/specs/hollerith-copybook-engine/))**:
- Formalized 6 EARS requirements in [`requirements.md`](./.kiro/specs/hollerith-copybook-engine/requirements.md) before writing binary parsers, deriving explicit `REDEFINES` high-water-mark offset equations and 6 formal `Correctness Properties` in [`design.md`](./.kiro/specs/hollerith-copybook-engine/design.md).
2. **Property-Based Testing with Shrinking ([`tests/pbt.test.mjs`](./tests/pbt.test.mjs))**:
- Directly executes Properties 1–6 across **1,700+ deterministically seeded random cases** (`CP037` 256-byte bijection, 80-column Hollerith round-trip, `COMP-3` odd/even nybble widths & `-0` normalization, Zoned overpunch/separate signs, `REDEFINES` union high-water marks, and composite `OCCURS` record round-trips).
3. **Layered Steering ([`.kiro/steering/`](./.kiro/steering/))**:
- Combines `always`-included foundation docs (`product.md`, `tech.md`, `structure.md` with `#[[file:src/index.mjs]]` live references), `fileMatch` binary guardrails (`binary-ebcdic-rules.md`), and `auto`-activated migration playbooks (`legacy-migration-playbook.md`).
4. **Event-Driven Agent Hooks ([`.kiro/hooks/`](./.kiro/hooks/)) & Custom Agent ([`.kiro/agents/copybook-archaeologist.json`](./.kiro/agents/copybook-archaeologist.json))**:
- `PostFileSave` hooks automatically run `npm test` and rebuild `docs/index.html` via `npm run build:studio` so the live browser studio never drifts from `src/`.
---
## License
Released under the [MIT License](./LICENSE).
TDQS
Scored across 5 tools
Each tool targets a distinct artifact and direction: copybook compilation, EBCDIC encode, EBCDIC decode, Hollerith card punch/read, and fixture listing. The encode/decode pair is inverse rather than overlapping, and the copybook compiler is clearly a schema-generation step feeding the others. No two tools could plausibly be selected for the same task.
All five names follow a strict verb_noun snake_case pattern (compile_copybook, decode_ebcdic_record, encode_ebcdic_record, inspect_hollerith_deck, list_legacy_fixtures). The verbs are well-chosen and the nouns identify the resource unambiguously.
Five tools is a tight, well-scoped surface for a mainframe data-interchange domain, with each tool mapping to a distinct step (compile schema, encode, decode, inspect deck, load fixtures). Nothing feels padded or redundant.
The set covers a full round-trip: compile copybook to schema, encode JSON to wire format, decode wire format back to JSON, plus card-level inspection and sample fixtures. Minor gaps remain, such as validating a record against a copybook without full decode, batch/multi-record processing, or generating a copybook from an existing schema, but these are workaroundable.