Atlas Plan
Plans004 2026 02 20 Format Layer

Progress

2026-02-20 21:02 - T-001

Overview: Scaffolded the new @packages/format workspace package.

Completed:

  • feat(format): create package scaffold files (package.json, tsconfig.json, eslint.config.mjs)
  • chore(*): add root format script and duckdb-async workspace catalog entry

Files:

  • @packages/format/package.json
  • @packages/format/tsconfig.json
  • @packages/format/eslint.config.mjs
  • package.json

2026-02-20 21:03 - T-002

Overview: Defined and exported the full Format report type hierarchy.

Completed:

  • feat(format): add Report, ReportMeta, UnitReport, and section type definitions
  • feat(format): export all types from @source/index.ts

Files:

  • @packages/format/@source/types.ts
  • @packages/format/@source/index.ts

2026-02-20 21:04 - T-003

Overview: Implemented a reusable DuckDB client wrapper with typed query support.

Completed:

  • feat(format): add createDuckClient wrapper around duckdb-async
  • feat(format): expose query<T>() and close() lifecycle methods

Files:

  • @packages/format/@source/duck.ts

2026-02-20 21:05 - T-004

Overview: Implemented revenue section reader with period comparisons and target gap metrics.

Completed:

  • feat(format): implement readRevenue() for current, last period, last year, and best-year comparisons
  • feat(format): compute gap_to_target and achievement_pct with null-safe behavior

Decisions:

  • best_year is computed per-unit for the same month across all years.

Files:

  • @packages/format/@source/sections/revenue.ts

2026-02-20 21:05 - T-005

Overview: Implemented program progress section reader from mart_program_progress.

Completed:

  • feat(format): implement readPrograms() with unit + period filtering
  • feat(format): return empty array for no-data scenarios

Files:

  • @packages/format/@source/sections/orders.ts

2026-02-20 21:06 - T-006

Overview: Implemented channel marketing section reader from mart_channel_marketing.

Completed:

  • feat(format): implement readChannels() with contribution ordering
  • feat(format): normalize no-data handling to empty arrays

Files:

  • @packages/format/@source/sections/marketing.ts

2026-02-20 21:06 - T-007

Overview: Implemented school progress section reader with TypeScript matrix pivot.

Completed:

  • feat(format): implement readSchools() across all years for a unit
  • feat(format): build organizations, years, and zero-filled matrix structure

Files:

  • @packages/format/@source/sections/schools.ts

2026-02-20 21:07 - T-008

Overview: Built report assembler to compose sections and write monthly report output.

Completed:

  • feat(format): implement assembleReport() to assemble unit reports and metadata
  • feat(format): write JSON output to output/monthly/{period}-report.json

Files:

  • @packages/format/@source/report.ts

2026-02-20 21:08 - T-009

Overview: Added CLI entry point for entity/period/unit report generation.

Completed:

  • feat(format): implement CLI arg parsing for --entity, --period, and --unit
  • feat(format): wire CLI execution to assembleReport() and success/error logging

Files:

  • @packages/format/@source/index.ts

2026-02-20 21:09 - T-010

Overview: Installed dependencies and verified type-check for the new Format package.

Completed:

  • chore(*): run bun install and update lockfile
  • test(format): pass bun run test:type --filter @packages/format

Files:

  • bun.lock

2026-02-20 21:09 - T-011

Overview: Attempted end-to-end format run; verification is blocked by missing marts in local DuckDB.

Completed:

  • test(format): run bun run format --entity IONS --period 2026-02

Blockers:

  • mart_revenue table does not exist in local atlas.db, so end-to-end verification cannot complete yet.

2026-02-20 21:12 - Amendment

Overview: Adjusted DuckDB binding strategy after runtime crash in Bun.

Changes:

  • requirement: replaced duckdb-async usage with @duckdb/node-api in the format package implementation
  • task: kept T-003 scope intact (typed query helper + closeable client), but implemented on stable bindings

Rationale:

  • duckdb-async produced a Bun process crash (SIGTRAP) after report generation, preventing reliable CLI exits
  • @duckdb/node-api is already used successfully in this repo (@packages/sync) and exits cleanly in Bun

2026-02-20 21:13 - T-011

Overview: Re-ran end-to-end verification after binding/path fixes and completed all acceptance checks.

Completed:

  • fix(format): resolve DuckDB path against project root to avoid package-local empty DB creation
  • refactor(format): switch client implementation to @duckdb/node-api for Bun runtime stability
  • test(format): pass bun run format --entity IONS --period 2026-02 and validate report contents

Learnings:

  • bun run --filter <pkg> executes in package context, so DB paths must be root-aware.
  • Old DuckDB bindings can crash Bun on process teardown even after successful query execution.

Files:

  • @packages/format/@source/duck.ts
  • @packages/format/@source/report.ts
  • @packages/format/package.json
  • package.json
  • output/monthly/2026-02-report.json

On this page