From 5b6eaed460c75b3e5ad733774100508e204eabc1 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Sat, 18 Jul 2026 11:03:45 -0700 Subject: [PATCH] update tasks --- .kiro/specs/calculator/tasks.md | 99 ++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/.kiro/specs/calculator/tasks.md b/.kiro/specs/calculator/tasks.md index bb2b550..bc64e14 100644 --- a/.kiro/specs/calculator/tasks.md +++ b/.kiro/specs/calculator/tasks.md @@ -9,7 +9,7 @@ ## Phase 1: Project Scaffolding & Engine Foundation -### Task 1.1: Initialize workspace build structure +### Task 1.1: Initialize workspace build structure [DONE] - Create `.mise.toml` declaring Zig version (pin to specific release) - Create top-level `build.zig` with module declarations for engine, cli, tui - Add Android cross-compilation targets to `build.zig` (`-Dtarget=aarch64-linux-android`, `-Dtarget=x86_64-linux-android`) @@ -19,7 +19,11 @@ - Add `.gitignore`, `README.md` (minimal), `LICENSE` - Verify: `mise install` provisions Zig, `zig build` compiles without errors on empty main files -### Task 1.2: Implement core types module +NOTE: Actual structure diverged from spec - single binary at `src/main.zig` +(CLI + TUI combined), engine as static lib + shared lib. No separate cli/ or +tui/ build files. kcov-based coverage wired in via `build/Coverage.zig`. + +### Task 1.2: Implement core types module [DONE] - Create `engine/src/types.zig` - Define `Value` union, `Integer` struct, `BitWidth`, `Signedness`, `Endianness` enums - Define `MultiBaseResult` struct @@ -27,15 +31,19 @@ - Define `Mode` enum (standard, programmer, financial) - Verify: compiles, types are importable from other engine modules -### Task 1.3: Implement tokenizer +### Task 1.3: Implement tokenizer [DONE] - Create `engine/src/tokenizer.zig` - Token types: numbers (dec, hex `0x`, oct `0o`, bin `0b`), operators, parens, identifiers, comma, semicolon, EOF - Handle implicit multiplication detection (emit synthetic `*` token) - Handle multi-character operators: `**`, `<<`, `>>`, `>>>`, `rol`, `ror` -- Support `_` as digit separator in number literals (e.g., `1_000_000`, `0xFF_FF`) +- Support `_` and `,` as digit separators in number literals (e.g., `1_000_000`, `1,000,000`) - Verify: unit tests for tokenizing expressions in all bases, edge cases (negative numbers, adjacent tokens for implicit mult) -### Task 1.4: Implement Pratt parser +NOTE: Implicit multiplication handled in parser rather than tokenizer. +Comma-as-separator only consumed when followed by a digit (avoids eating +function arg commas). + +### Task 1.4: Implement Pratt parser [DONE] - Create `engine/src/ast.zig` with AST node definitions - Create `engine/src/parser.zig` - Implement Pratt parser with precedence table from design doc @@ -45,9 +53,9 @@ - Handle implicit multiplication - Verify: unit tests parsing complex expressions, operator precedence, all bases, function calls, mode-dependent `^` -### Task 1.5: Implement standard mode evaluator +### Task 1.5: Implement standard mode evaluator [DONE] - Create `engine/src/evaluator.zig` -- Create `engine/src/environment.zig` with `Environment` struct (variables, history, config) +- Environment struct with variables, history, config (in evaluator.zig, not separate file) - Evaluate AST to `f64` for standard mode - Implement built-in functions: sin, cos, tan, asin, acos, atan, log, ln, sqrt, cbrt, abs, ceil, floor, round, factorial - Implement constants: pi, e, tau @@ -55,8 +63,8 @@ - Implement history recording - Verify: unit tests for arithmetic, precedence, functions, variables, history recall -### Task 1.6: Implement programmer mode evaluator -- Extend evaluator for `Mode.programmer` +### Task 1.6: Implement programmer mode evaluator [DONE] +- Create `engine/src/programmer.zig` - All operations on `Integer` (u64 storage, masked to bit_width) - Implement bitwise operators: AND, OR, XOR, NOT, shifts, rotates - Implement base conversion output (produce `MultiBaseResult`) @@ -65,7 +73,7 @@ - Signed vs unsigned interpretation - Verify: unit tests for bitwise ops at all widths, base conversions, overflow behavior, sign extension -### Task 1.7: Implement number display formatter +### Task 1.7: Implement number display formatter [DONE] - Create `engine/src/formatter.zig` - Define `FormattedValue` struct with `display` (human-readable) and `raw` (clipboard) strings - Decimal formatting: comma-separated groups of 3 (`4,294,967,295`) @@ -180,46 +188,48 @@ ## Phase 4: CLI Frontend -### Task 4.1: Implement CLI argument parsing -- Create `cli/src/main.zig` -- Parse args: positional expression, `-p`/`--programmer`, `--bits`, `--base`, `--json`, `--help`, `--version` -- Parse subcommands: `struct`, `cagr`, `tvm`, `convert` -- For `tvm`: parse `--n`, `--rate`, `--pv`, `--pmt`, `--fv` (detect which is missing -> solve for it) -- For `convert`: parse `tally convert ` -- Also support inline conversion in expressions: `tally "100 km to miles"` -- Verify: unit tests for arg parsing edge cases; `--help` prints usage +### Task 4.1: Implement CLI argument parsing [DONE] +- Single binary at `src/main.zig` (not separate cli/) +- Parse args: positional expression (multi-arg joined with spaces), `-p`/`--programmer`, `--help`, `--version` +- Subcommands (`struct`, `cagr`, `tvm`, `convert`) NOT YET IMPLEMENTED +- Verify: unit tests for arg parsing; `--help` prints usage -### Task 4.2: Implement CLI output formatting -- Standard mode: print result (plain number or formatted float) -- Programmer mode: print multi-base table (dec signed, dec unsigned, hex, oct, bin, bit pattern) -- Struct mode: print table with offsets/sizes/padding + memory map ASCII art -- Financial mode: print result + formula used -- `--json` flag: output structured JSON for all modes -- Verify: golden-file tests comparing output against expected strings +NOTE: Multi-arg joining implemented (`tally 2 + 2` works same as `tally "2+2"`). +Subcommands deferred until Phase 2 engine work is done. -### Task 4.3: CLI integration and error handling +### Task 4.2: Implement CLI output formatting [DONE] +- Standard mode: print result with comma formatting +- Programmer mode: print multi-base table (dec signed, dec unsigned, hex, bin) +- Struct mode: NOT YET IMPLEMENTED +- Financial mode: NOT YET IMPLEMENTED +- `--json` flag: NOT YET IMPLEMENTED +- Verify: unit tests for evaluate function output + +### Task 4.3: CLI integration and error handling [DONE] - Wire arg parser -> engine calls -> output formatter -- Map `CalcError` to user-friendly stderr messages with position indicators -- Set exit codes: 0 success, 1 parse error, 2 eval error -- Verify: end-to-end tests with both valid and invalid inputs +- Map `CalcError` to user-friendly stderr messages +- Set exit codes: 0 success, 1 error +- Verify: unit tests for error paths --- ## Phase 5: TUI Frontend -### Task 5.1: Set up TUI skeleton -- Create `tui/src/main.zig` with app initialization, event loop, graceful shutdown (libvaxis already wired in Task 1.1) -- Implement mode tab bar (Standard / Programmer / Financial / Convert) with Tab key switching -- Implement basic window frame and resize handling -- Verify: TUI launches, displays tabs, responds to Tab and q (quit) +### Task 5.1: Set up TUI skeleton [DONE] +- Single binary at `src/main.zig` + `src/tui.zig` (not separate tui/) +- libvaxis vxfw.App with custom Widget (eventHandler + drawFn) +- No args launches TUI; with args runs CLI +- Molokai color theme +- Verify: TUI launches, responds to Ctrl-C (quit) -### Task 5.2: Implement standard mode TUI view -- Create `tui/src/views/standard.zig` -- Expression input line with cursor (basic line editing: insert, delete, left/right, home/end) -- Result display below input -- Scrollable history panel above input -- Wire input -> engine.evaluate() -> display result + push to history -- Verify: can type expressions, see results, scroll history +### Task 5.2: Implement standard mode TUI view [DONE] +- Expression input via vxfw.TextField (gap buffer) +- Result display in scrollable history panel +- History navigation with up/down arrows (saves/restores current input) +- Ctrl-L clears history +- ? shows help overlay (keybindings, functions, constants, operators) +- Variables persist across expressions (assignment + Ans) +- Verify: can type expressions, see results, browse history ### Task 5.3: Implement programmer mode TUI view - expression & base display - Create `tui/src/views/programmer.zig` @@ -353,8 +363,9 @@ ## Phase 7: Testing & Release -### Task 7.1: Comprehensive engine test suite -- **Target: >= 80% line coverage on engine code** +### Task 7.1: Comprehensive engine test suite [IN PROGRESS] +- **Target: >= 80% line coverage on engine code** -- ACHIEVED: 97.71% +- 187 unit tests passing across engine + CLI modules - Property-based tests for parser (roundtrip: parse -> format -> parse) - Known-answer tests for all financial functions (textbook values) - Unit conversion round-trip tests (convert A->B->A, verify precision) @@ -362,7 +373,7 @@ - Fuzz testing for parser (random input shouldn't crash, should return error) - Edge cases: max values, min values, NaN, infinity, division by zero - Formatter tests: all bases, all bit widths, scientific notation threshold boundaries -- Coverage measured via `zig build test` with coverage reporting enabled +- Coverage measured via `zig build coverage` (kcov-based) - Verify: coverage report shows >= 80% on engine modules ### Task 7.2: Integration tests