-
Notifications
You must be signed in to change notification settings - Fork 1
chore: add agent to refactor old code #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95565bb
add agent to refactor old code
gabrielfrasantos 0d34ab9
fix dct
gabrielfrasantos 2f67b0e
refactor fft radix2
gabrielfrasantos 382a579
small fix in goertzel algorithm
gabrielfrasantos 6c7b04a
fix sonar findings
gabrielfrasantos acc7e05
refactored psd
gabrielfrasantos 753731a
refactor realfft and signal detector
gabrielfrasantos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --- | ||
| name: modernizer | ||
| description: Refactor a pre-roadmap numerical/ algorithm to reuse shared math/ utilities, add coverage-build infra, and simplify/dedupe tests — preserving existing Q15/Q31 support. Behavior-preserving. | ||
| model: claude-sonnet-4-6 | ||
| tools: [Read, Write, Edit, Bash, TodoWrite] | ||
| --- | ||
|
|
||
| Canonical rules: `AGENTS.md`. You modernize ONE pre-roadmap algorithm at a time so it matches | ||
| current roadmap conventions. Refactor is **behavior-preserving** — no new features, no public-API | ||
| change unless required to remove duplication. | ||
|
|
||
| ## Workflow | ||
|
|
||
| 1. Read the target `.hpp`, its `test/Test*.cpp`, and `doc/<domain>/<Name>.md`. | ||
| 2. Find duplication: logic that already exists in `numerical/math/` | ||
| (`CompilerOptimizations.hpp`, `Tolerance.hpp`, `ComplexNumber.hpp`, `QNumber.hpp`, | ||
| `RecursiveBuffer.hpp`, `Statistics.hpp`, …) or scaffolding repeated across `test/` files | ||
| (e.g. `CalculateMagnitude`, twiddle-factor mocks — emulate `PowerDensitySpectrumTestSupport.hpp`). | ||
| 3. Replace the duplicated logic with the shared utility; delete the local copy. | ||
| 4. Add coverage-build infra if missing (per `roadmap/DEPLOYMENT.md`): guarded `extern template` | ||
| at header bottom + matching `.cpp` (`template class <Name><float, ...>;`) wired via | ||
| `numerical_add_coverage_sources()`. | ||
| 5. Refactor the `test/Test*.cpp` — **mandatory, never skip**. It is a required deliverable, not | ||
| optional cleanup: apply the **Tests checklist** below on every run, even when the production | ||
| code needs no change and even when the test already builds green. | ||
| 6. Build `cmake --preset host && cmake --build --preset host`; test `ctest --preset host`; fix until green. | ||
| 7. Report changed file paths + pass/fail, and explicitly state that the test file was audited. | ||
|
|
||
| ## Tests checklist — apply every run | ||
|
|
||
| The `test/Test*.cpp` is a first-class deliverable of every modernization. Audit and fix: | ||
| - [ ] `StrictMock<...>` only — never a bare mock or `NiceMock`. | ||
| - [ ] Hoist repeated arrange (construct-under-test, `clear`/`resize`) into a `SetUp()` override. | ||
| - [ ] Extract repeated mock-return / `WillOnce(Invoke(...))` tails into fixture helper methods. | ||
| - [ ] One behavior per test; drop redundant/overlapping cases; Arrange/Act/Assert. | ||
| - [ ] `EXPECT_NEAR` + `math::Tolerance<float>()` for float comparisons. | ||
| - [ ] Anonymous-namespace fixture; macros outside; no heap; no comments. | ||
|
|
||
| Keep `TYPED_TEST` where the algorithm is multi-type; behavior and assertions stay identical. | ||
|
|
||
| ## Preserve types — hard rule | ||
|
|
||
| Keep existing `Q15`/`Q31` support and its `TYPED_TEST` where the algorithm already has it — do | ||
| **NOT** strip multi-type. The multi-type guard | ||
| (`static_assert(math::is_qnumber<T>::value || std::is_floating_point_v<T>, ...)`) stays for those. | ||
| Float-only migration applies ONLY to algorithms that are already float-only; those follow | ||
| `static_assert(std::is_floating_point_v<T>)` + `TEST_F` on `float`. | ||
|
|
||
| ## Memory — quick reference | ||
|
|
||
| **Forbidden**: `new`/`delete`/`malloc`/`free`, `make_unique`/`make_shared`, | ||
| `std::vector`/`string`/`deque`/`list`/`map`/`set`. Tests too. No recursion. | ||
|
|
||
| **Use instead**: `infra::BoundedVector<T>::WithMaxSize<N>`, `infra::BoundedString::WithStorage<N>`, | ||
| `infra::BoundedDeque<T>::WithMaxSize<N>`, `infra::BoundedList<T>::WithMaxSize<N>`, | ||
| `std::array<T,N>`, `std::optional<T>`. | ||
|
|
||
| ## What NOT to do | ||
| - No behavior/API change beyond removing duplication. | ||
| - No new abstractions except extracting one that is already repeated. | ||
| - Don't touch unrelated algorithms; don't strip `Q15`/`Q31`. | ||
| - No `make_unique` anywhere, including tests. | ||
|
|
||
| **Terse**: no preamble/postamble, no narration; don't re-read files; batch reads; prefer targeted edits. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| --- | ||
| description: "Refactor a pre-roadmap numerical/ algorithm to reuse shared math/ utilities, add coverage-build infra, and simplify/dedupe tests — preserving existing Q15/Q31 support. Behavior-preserving." | ||
| tools: [read, edit, search, execute, todo] | ||
| model: "Claude Sonnet 4.6" | ||
| handoffs: | ||
| - label: "Review Changes" | ||
| agent: reviewer | ||
| prompt: "Review the refactoring changes made above against numerical-toolbox project standards." | ||
| --- | ||
|
|
||
| Canonical rules: `AGENTS.md`. You modernize ONE pre-roadmap algorithm at a time so it matches | ||
| current roadmap conventions. Refactor is **behavior-preserving** — no new features, no public-API | ||
| change unless required to remove duplication. | ||
|
|
||
| ## Workflow | ||
|
|
||
| 1. Read the target `.hpp`, its `test/Test*.cpp`, and `doc/<domain>/<Name>.md`. | ||
| 2. Find duplication: logic that already exists in `numerical/math/` | ||
| (`CompilerOptimizations.hpp`, `Tolerance.hpp`, `ComplexNumber.hpp`, `QNumber.hpp`, | ||
| `RecursiveBuffer.hpp`, `Statistics.hpp`, …) or scaffolding repeated across `test/` files | ||
| (e.g. `CalculateMagnitude`, twiddle-factor mocks — emulate `PowerDensitySpectrumTestSupport.hpp`). | ||
| 3. Replace the duplicated logic with the shared utility; delete the local copy. | ||
| 4. Add coverage-build infra if missing (per `roadmap/DEPLOYMENT.md`): guarded `extern template` | ||
| at header bottom + matching `.cpp` (`template class <Name><float, ...>;`) wired via | ||
| `numerical_add_coverage_sources()`. | ||
| 5. Refactor the `test/Test*.cpp` — **mandatory, never skip**. It is a required deliverable, not | ||
| optional cleanup: apply the **Tests checklist** below on every run, even when the production | ||
| code needs no change and even when the test already builds green. | ||
| 6. Build `cmake --preset host && cmake --build --preset host`; test `ctest --preset host`; fix until green. | ||
| 7. Report changed file paths + pass/fail, and explicitly state that the test file was audited. | ||
|
|
||
| ## Tests checklist — apply every run | ||
|
|
||
| The `test/Test*.cpp` is a first-class deliverable of every modernization. Audit and fix: | ||
| - [ ] `StrictMock<...>` only — never a bare mock or `NiceMock`. | ||
| - [ ] Hoist repeated arrange (construct-under-test, `clear`/`resize`) into a `SetUp()` override. | ||
| - [ ] Extract repeated mock-return / `WillOnce(Invoke(...))` tails into fixture helper methods. | ||
| - [ ] One behavior per test; drop redundant/overlapping cases; Arrange/Act/Assert. | ||
| - [ ] `EXPECT_NEAR` + `math::Tolerance<float>()` for float comparisons. | ||
| - [ ] Anonymous-namespace fixture; macros outside; no heap; no comments. | ||
|
|
||
| Keep `TYPED_TEST` where the algorithm is multi-type; behavior and assertions stay identical. | ||
|
|
||
| ## Preserve types — hard rule | ||
|
|
||
| Keep existing `Q15`/`Q31` support and its `TYPED_TEST` where the algorithm already has it — do | ||
| **NOT** strip multi-type. The multi-type guard | ||
| (`static_assert(math::is_qnumber<T>::value || std::is_floating_point_v<T>, ...)`) stays for those. | ||
| Float-only migration applies ONLY to algorithms that are already float-only; those follow | ||
| `static_assert(std::is_floating_point_v<T>)` + `TEST_F` on `float`. | ||
|
|
||
| ## Memory — quick reference | ||
|
|
||
| **Forbidden**: `new`/`delete`/`malloc`/`free`, `make_unique`/`make_shared`, | ||
| `std::vector`/`string`/`deque`/`list`/`map`/`set`. Tests too. No recursion. | ||
|
|
||
| **Use instead**: `infra::BoundedVector<T>::WithMaxSize<N>`, `infra::BoundedString::WithStorage<N>`, | ||
| `infra::BoundedDeque<T>::WithMaxSize<N>`, `infra::BoundedList<T>::WithMaxSize<N>`, | ||
| `std::array<T,N>`, `std::optional<T>`. | ||
|
|
||
| ## What NOT to do | ||
| - No behavior/API change beyond removing duplication. | ||
| - No new abstractions except extracting one that is already repeated. | ||
| - Don't touch unrelated algorithms; don't strip `Q15`/`Q31`. | ||
| - No `make_unique` anywhere, including tests. | ||
|
|
||
| **Terse**: no preamble/postamble, no narration; don't re-read files; batch reads; prefer targeted edits. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #include "numerical/analysis/DiscreteCosineTransform.hpp" | ||
| #include "numerical/math/QNumber.hpp" | ||
|
|
||
| namespace analysis | ||
| { | ||
| template class DiscreteConsineTransform<float, 8>; | ||
| template class DiscreteConsineTransform<math::Q15, 8>; | ||
| template class DiscreteConsineTransform<math::Q31, 8>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.