diff --git a/build-history/v1.0.0/progress.md b/build-history/v1.0.0/progress.md index 25ccc18f..ab13af7a 100644 --- a/build-history/v1.0.0/progress.md +++ b/build-history/v1.0.0/progress.md @@ -68,9 +68,5 @@ CR1 and CR2 change the unreleased v1 schema. They must finish before v1.0.0 is published to npm. Release steps 11 and 12 remain blocked until CR1–CR9 and the cross-platform part of step 10 pass. -npm `athleticstandard@1.0.0` is published. 1.1.0 is a package release of this -format version: `ath migrate`, provider-import check, structured log envelope, -default model path (`athlete.ath.model` beside `athlete.ath.sqlite`, not -overwriting the database), and docs. The record format stays `1.0.0`. -Remaining contribution-readiness steps continue on later package versions of -the same format. +npm `athleticstandard@1.0.0` is published. The 1.1.0 package release on the same +format is tracked in [v1.1.0/progress.md](../v1.1.0/progress.md). diff --git a/build-history/v1.1.0/decisions.md b/build-history/v1.1.0/decisions.md new file mode 100644 index 00000000..1bfcda6d --- /dev/null +++ b/build-history/v1.1.0/decisions.md @@ -0,0 +1,126 @@ +# Athletic Standard v1.1.0 — Decision Log + +Decisions for this package release continue after D129 in +[v1.0.0](../v1.0.0/decisions.md). The record format version stays `1.0.0`. Rejected +alternatives are recorded because they are the part everyone forgets. + +## D130. Ship npm 1.1.0 without bumping the 1.0.0 record format + +`athleticstandard@1.1.0` publishes migrate, import-check, structured-log, docs, and +default-model fixes. `athleticstandard_version`, `sql_schema_version`, and generated +JSON Schema paths under `schema/1.0.0/` stay on `1.0.0` / `1`. + +`ATH_PACKAGE_VERSION` in `src/version.ts` is the single source for the CLI +`--version`, Skill metadata, and `tool_version` on tool actors. `ATHLETIC_STANDARD_VERSION` +in `src/v1/schema.ts` remains what `ath check` reports for the athlete record format. + +Rejected alternatives: + +- **Bump the record format to 1.1.0 for a tooling release.** Rejected because none of + the shipped changes alter normative Zod, SQL encoding, or portable JSON layout. +- **Hold npm at 1.0.0 after publish.** Rejected because users already have `1.0.0` on + npm and need a distinct package version for these fixes. + +## D131. Provider import parses `CurrentRecord` before typed-row and revision writes + +`checkDatabase` compares typed `data_json` to the current revision's `record_json` as +exact strings. Provider import previously wrote importer key order in one store and +`RecordRevision` normalization in the other, so a clean Apple Health, WHOOP, or Oura +import could still fail `ath check`. + +New and changed provider rows now call `CurrentRecord.parse` in `insertNewRecord` and +`insertChangedRecord` before `insertRevision` and `upsertTypedRecord`, matching the +library write path. + +Rejected alternatives: + +- **Relax `checkDatabase` to compare parsed objects instead of strings.** Rejected + because byte-identical copies are an explicit integrity rule (D103). +- **Normalize only the revision copy.** Rejected because the typed table would still + diverge from the revision athletes and exports rely on. + +## D132. Structured `ath log` uses a closed envelope with validated extensions + +`planStructured` accepts only `record_type`, `record_id`, `created_at`, +`current_revision`, `is_deleted`, `data`, and `extensions`. Any other top-level field +errors with the field names listed. Valid `extensions` are stored on write. Invalid +extensions, including forbidden `source_id` on athlete reports, error instead of +silently dropping data. + +Rejected alternatives: + +- **Ignore unknown envelope fields.** Rejected because agents could believe data was + stored when it was discarded. +- **Accept extensions without schema validation.** Rejected because invalid extension + shapes would corrupt the extension envelope contract (D118). + +## D133. Public docs match the implemented schema and export layout without a format bump + +SPEC.md, README.md, and `skill/references/format.md` now state **24** record types and +chunked series files named +`--000001.ath-series.json`. The schema and exporter already +behaved that way; only prose was wrong. + +`tests/v1-docs.test.ts` guards against regressions to 23 types or unchunked series +names. + +Rejected alternatives: + +- **Change export to match the old doc string.** Rejected because deterministic export + and existing packages already use numbered chunks. +- **Leave docs wrong until a format version bump.** Rejected because misleading public + reference text is worse than a doc-only fix on a patch package. + +## D134. The default model file is `athlete.ath.model` beside the database, with refused unsafe targets + +`defaultModelPath` maps `*.ath.sqlite` to `*.ath.model` in the same directory. The +previous `.json` suffix swap could resolve to the live database path for typical +layouts. + +`writeDefaultModel` refuses paths equal to the database, ending in `.ath.sqlite` or +`.ath.json`, symbolic links, or a realpath equal to the database realpath. It writes +through a private temp file in the same directory and `rename`s into place so the +write does not follow a symlink at the destination. + +Rejected alternatives: + +- **Keep the `.json` swap with a runtime warning.** Rejected because a mistaken default + overwrites the athlete record. +- **Write directly to the model path.** Rejected because replacing an existing symlink + could follow it to the database. + +## D135. Migration backups escape sqlite3 paths and reuse the previewed backup location + +`sqlite3BackupDotCommand` double-quotes the backup path and applies sqlite3 backslash +escapes for `\`, `"`, and newlines so `.backup` writes to the intended file when paths +contain quotes or backslashes. + +`ath migrate` passes `preview.planned_backup_path` into +`executeConfirmedDatabaseMigration` as `backupPath` so the file created matches the +preview. Backup files are created exclusively at mode `0600`; symlinks and existing +paths are refused; partial files are removed on failure. + +Rejected alternatives: + +- **Pass unescaped paths to sqlite3.** Rejected because special characters break or + redirect the backup command. +- **Generate a new backup path at execution time.** Rejected because the user confirms + a specific path from the preview (D124). + +## D136. Interactive migration asks before creating a backup + +On `ath migrate` with `--yes`, and on interactive database open when migration is +required, the tool asks for confirmation before `createVerifiedSqliteBackup` runs. +Declining leaves no backup file and does not modify the database. + +Non-interactive migration still requires `--yes` and `--confirm-migration ` +after reviewing the JSON preview. Non-interactive open still refuses to migrate and +points to `ath migrate`. + +Rejected alternatives: + +- **Create the backup before the prompt.** Rejected because declining would leave backup + files the user did not want. +- **Skip the prompt when `--yes` is set.** Rejected because `--yes` must not bypass the + migration-specific confirmation (D68 applies to write previews, not silent schema + upgrades). diff --git a/build-history/v1.1.0/progress.md b/build-history/v1.1.0/progress.md new file mode 100644 index 00000000..0d792404 --- /dev/null +++ b/build-history/v1.1.0/progress.md @@ -0,0 +1,31 @@ +# v1.1.0 Build Progress + +Tracks the work shipped in [pull request #25](https://github.com/mwhitham/ath/pull/25). +The v1.0.0 format and SQL schema are unchanged; this is an npm package release on top +of the plan in [spec.md](spec.md). + +| Step | Deliverable | Status | +|---|---|---| +| 1 | Record D130–D136 and this spec | ✅ done (retroactive build-history in follow-up PR) | +| 2 | `ath migrate` with preview, verified backup, `--confirm-migration`, interactive open | ✅ done — implements v1.0.0 CR4 / D124 | +| 3 | sqlite3 backup path escaping and previewed `planned_backup_path` handoff | ✅ done — D135 | +| 4 | Interactive migrate/open confirm before backup; no backup on decline | ✅ done — D136 | +| 5 | Provider import `CurrentRecord.parse` before typed row and revision | ✅ done — D131 | +| 6 | Structured `ath log` closed envelope and extensions | ✅ done — D132 | +| 7 | Docs: 24 record types and chunked series names | ✅ done — D133; `tests/v1-docs.test.ts` | +| 8 | Default model path `.ath.model` and safe `writeDefaultModel` | ✅ done — D134; `tests/models.test.ts` | +| 9 | npm `1.1.0`; CLI and `tool_version` use package version; format stays `1.0.0` | ✅ done — D130 | +| 10 | `pnpm check:public-data`, typecheck, test, build, `check:schema-drift` on merge | ✅ done per PR #25 | + +## Relation to v1.0.0 contribution readiness + +CR4 in [v1.0.0/progress.md](../v1.0.0/progress.md) is marked done. CR5–CR9 and release +steps 10–12 of the v1.0.0 plan remain open on later package versions of the same +format. + +## Known follow-ups (not in 1.1.0) + +- [Issue #26](https://github.com/mwhitham/ath/issues/26) — Oura member-portal CSV + layout drops readiness, scores, contributors, and SpO2 without skip lines. +- Databases provider-imported with npm `1.0.0` may remain INVALID after `ath migrate`; + repair is export, then `ath init --empty`, then import (see spec §8.2). diff --git a/build-history/v1.1.0/spec.md b/build-history/v1.1.0/spec.md new file mode 100644 index 00000000..09d3d1a9 --- /dev/null +++ b/build-history/v1.1.0/spec.md @@ -0,0 +1,209 @@ +# Athletic Standard v1.1.0 — Package Release Specification + +Status: shipped in [pull request #25](https://github.com/mwhitham/ath/pull/25) (npm +`athleticstandard@1.1.0`, merged 2026-10-23). + +This plan does not change `athleticstandard_version`, `sql_schema_version`, or the +generated JSON Schema under `schema/1.0.0/`. It ships tooling and documentation fixes +on top of the approved [v1.0.0 SQLite build plan](../v1.0.0/spec.md). + +Decisions for this release are D130 onward in [decisions.md](decisions.md). D124 in +v1.0.0 already required preview, backup, and confirmation for SQL migrations; this +release implements contribution-readiness step CR4. + +## 0. Why this version exists + +v1.0.0 landed the SQLite record, provider importers, and the contribution-readiness +plan. Before the remaining CR steps, four verification gaps and one safety bug +needed a published package fix without a format bump: + +1. **CR4 migrate** — SQL schema upgrades need a verified backup and explicit + confirmation; non-interactive opens must not migrate silently. +2. **Provider import vs `ath check`** — Apple Health, WHOOP, and Oura imports could + pass the importer yet fail integrity check because typed-row JSON and revision JSON + used different key order. +3. **Structured `ath log`** — Unknown envelope fields were dropped and `extensions` + never reached storage. +4. **Public docs** — README, SPEC, and the Skill format reference still described 23 + record types and unchunked series file names while the schema and exporter already + used 24 types and numbered chunks. +5. **Default model path** — `ath models --default` could target the live database when + the default path was derived by swapping a `.json` suffix. + +npm `1.0.0` was already published. The CLI, Skill metadata, and `tool_version` fields +now follow the package version (`src/version.ts` → `ATH_PACKAGE_VERSION` `1.1.0`). +`ath check` still reports Athletic Standard `1.0.0` for the record format +(`ATHLETIC_STANDARD_VERSION` in `src/v1/schema.ts`). + +## 1. What ships in this version + +| Area | Deliverable | +|---|---| +| Migrate | `ath migrate` with JSON preview, `--dry-run`, `--yes`, `--confirm-migration `, and verified SQLite backup via `sqlite3` `.backup` | +| Open | Interactive TTY open prompts for migration after preview; non-interactive open throws `MigrationRequiredError` and points to `ath migrate` | +| Backup safety | Backup files at mode `0600`; refuse symlinks and existing paths; cleanup on failure; `sqlite3BackupDotCommand` escapes quotes and backslashes in paths | +| Provider import | `CurrentRecord.parse` before typed-row and revision writes so `checkDatabase` byte comparison succeeds | +| Structured log | Closed envelope; refuse unknown top-level keys; store valid `extensions`; reject invalid extensions | +| Docs | 24 record types; chunked series path `--000001.ath-series.json` in SPEC, README, and `skill/references/format.md` | +| Default model | `defaultModelPath` maps `athlete.ath.sqlite` → `athlete.ath.model`; `writeDefaultModel` refuses database and portable JSON paths, symlinks, and realpaths equal to the database; write via temp file and `rename` | +| Tests | `tests/v1-migrate.test.ts`, `tests/v1-docs.test.ts`, `tests/models.test.ts`, provider-import check coverage, structured-log tests | +| Package | `package.json` version `1.1.0`; exports `ATH_PACKAGE_VERSION` from `src/index.ts` | + +Record format, SQL schema version (`SQL_SCHEMA_VERSION` `1`), and portable JSON layout +are unchanged from v1.0.0. + +## 2. `ath migrate` behavior + +### 2.1 Preview + +`inspectDatabase` opens read-only without enabling WAL (`deferWal`). The preview +includes: + +- `source_sql_schema_version` and `target_sql_schema_version` (target is + `SQL_SCHEMA_VERSION` from `src/db/client.ts`, currently `1`) +- `database_id` +- `planned_steps` from `MIGRATION_CHAIN` in `src/db/sql-contract.ts` +- `planned_backup_path` — `defaultMigrationBackupPath` → + `.migration-backup..sqlite` +- `compatibility_effect` text + +`--json` and `--dry-run` never apply a migration. Without `--yes`, the command prints +the preview and exits without writing. + +### 2.2 Confirmation and backup order + +Interactive flows ask whether to proceed **before** creating a backup: + +- `ath migrate` with `--yes` calls `confirmWrite` with + `Create a verified backup and apply this migration?` before + `executeConfirmedDatabaseMigration`. +- Interactive open uses `Apply this SQL schema migration?` before + `createVerifiedSqliteBackup`. + +Answering no prints `nothing migrated` (migrate) or fails with a message to run +`ath migrate` (open). No backup file is created. + +Non-interactive migration after `--yes` requires a second confirmation: pass +`--confirm-migration` with the exact `database_id`, or type it at the prompt when +stdin and stdout are TTYs. + +### 2.3 Verified backup and apply + +`createVerifiedSqliteBackup` in `src/db/backup.ts`: + +- Requires the `sqlite3` CLI (SQLite 3.45+ per `MINIMUM_SQLITE_VERSION`) +- Creates the backup path exclusively (`wx`, mode `0600`) +- Runs `.backup` with `sqlite3BackupDotCommand` quoting +- Verifies record count and metadata against the source + +Confirmed execution passes the previewed `planned_backup_path` into +`executeConfirmedDatabaseMigration` so the on-disk backup matches what the user +reviewed. WAL is enabled after backup and before `applyPendingDatabaseMigrations`. + +On this release, `MIGRATION_CHAIN` contains only the initial schema (version `1`). +Databases already at `sql_schema_version` `1` report `migration_needed: false`. The +command surface exists so later SQL migrations can ship without another CLI redesign. + +### 2.4 Non-interactive open + +`openDatabase` with default options refuses outdated schema and throws +`MigrationRequiredError` whose message includes `Run ath migrate`. Agents and scripts +must call `ath migrate` explicitly with `--yes` and `--confirm-migration`. + +## 3. Provider import and integrity check + +`checkDatabase` compares each typed table's `data_json` to the current revision's +`record_json` as strings (`src/db/check.ts`). + +Provider import now builds each new or changed record with `CurrentRecord.parse` in +`insertNewRecord` and `insertChangedRecord` (`src/db/provider-import.ts`) before +`insertRevision` and `upsertTypedRecord`, matching the library write path. + +Fixture imports for Apple Health, WHOOP, and Oura pass `checkDatabase` in +`tests/v1-provider-import.test.ts`. + +## 4. Structured `ath log` + +`planStructured` in `src/db/log-entry.ts` accepts only: + +`record_type`, `record_id`, `created_at`, `current_revision`, `is_deleted`, `data`, +`extensions`. + +Any other top-level key produces an error listing the unknown fields. Valid +`extensions` are stored; invalid extensions (including `source_id` on an athlete +report) error. + +`tool_version` on tool actors uses `ATH_PACKAGE_VERSION`. + +## 5. Documentation alignment + +No export format change. The exporter already wrote chunked series files; docs now +state: + +- **24** record types (`RecordType` in `src/v1/schema.ts`) +- Series chunk file name pattern `--000001.ath-series.json` + +`tests/v1-docs.test.ts` guards SPEC, README, and `skill/references/format.md` against +regression to 23 types or unchunked series names. + +## 6. Default model file + +`MODEL_SUFFIX` is `.ath.model` (`src/models.ts`). + +`defaultModelPath("athlete.ath.sqlite")` → `athlete.ath.model` (same directory stem, +not a `.json` swap). + +`writeDefaultModel` refuses when the target path is the database path, ends with +`.ath.sqlite` or `.ath.json`, is a symlink, or `realpathSync` equals the database +realpath. Contents are written to a pid-random temp file beside the model, then +`renameSync` replaces the destination without following a symlink. + +`readDefaultModel` reads the first line of the model file if present. + +## 7. Version fields + +| Field | Value on 1.1.0 | Where | +|---|---|---| +| npm / CLI | `1.1.0` | `package.json`, `ATH_PACKAGE_VERSION`, `ath --version` | +| Record format | `1.0.0` | `ATHLETIC_STANDARD_VERSION`, `ath check` metadata | +| SQL schema | `1` | `database_metadata.sql_schema_version`, `PRAGMA user_version` | +| `tool_version` / prediction agent version | `1.1.0` | provider import, structured log, grade, predict paths using `ATH_PACKAGE_VERSION` | + +`CORE_API_VERSION` remains decided (D128) but not implemented (CR8 pending). + +## 8. Known open items (not fixed in 1.1.0) + +### 8.1 Oura member-portal CSV layout ([#26](https://github.com/mwhitham/ath/issues/26)) + +The importer matches Oura fixtures with flattened comma columns (`readiness_score`, +`contributor_*`). Oura's current membership-hub export uses semicolon CSVs per API +model, a `score` column, and JSON object cells for contributors and SpO2. Readiness, +sleep score, contributors, and nightly SpO2 from that export can be silently omitted +(rows have a `day` so they are not counted as skips). Fixing detection, parsing, or +skip reporting is future work. + +### 8.2 Databases provider-imported with npm 1.0.0 may stay INVALID after `ath migrate` + +The 1.0.0 package could write mismatched `data_json` and `record_json` on provider +import. `ath migrate` only upgrades SQL schema; it does not rewrite existing record +payloads. `ath check` can still report INVALID after a successful no-op or future SQL +migration. + +Documented repair: + +1. `ath export ` — complete portable package +2. `ath init --empty` (with `-y` when non-interactive) in a new or empty folder +3. `ath import ` with preview, then `--yes` + +Re-import applies the 1.1.0 canonical write path. This path is not automated. + +## 9. Build verification + +Pull request #25 required: + +`pnpm check:public-data && pnpm typecheck && pnpm test && pnpm build && pnpm check:schema-drift` + +Docs regression: `tests/v1-docs.test.ts`. + +Contribution-readiness steps CR5–CR9 and v1.0.0 release steps 10–12 remain as tracked +in [v1.0.0/progress.md](../v1.0.0/progress.md).