nightytidy 0.3.7 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/bin/nightytidy.js +1 -1
  2. package/package.json +1 -1
  3. package/src/agent/git-integration.js +4 -1
  4. package/src/claude.js +1 -1
  5. package/src/prompts/manifest.json +138 -138
  6. package/src/prompts/steps/02-test-coverage.md +181 -181
  7. package/src/prompts/steps/03-test-hardening.md +181 -181
  8. package/src/prompts/steps/04-test-architecture.md +130 -130
  9. package/src/prompts/steps/05-test-consolidation.md +165 -165
  10. package/src/prompts/steps/06-test-quality.md +211 -211
  11. package/src/prompts/steps/07-api-design.md +165 -165
  12. package/src/prompts/steps/08-security-sweep.md +207 -207
  13. package/src/prompts/steps/09-dependency-health.md +217 -217
  14. package/src/prompts/steps/10-codebase-cleanup.md +189 -189
  15. package/src/prompts/steps/11-crosscutting-concerns.md +196 -196
  16. package/src/prompts/steps/12-file-decomposition.md +263 -263
  17. package/src/prompts/steps/13-code-elegance.md +329 -329
  18. package/src/prompts/steps/14-architectural-complexity.md +297 -297
  19. package/src/prompts/steps/15-type-safety.md +192 -192
  20. package/src/prompts/steps/16-logging-error-message.md +173 -173
  21. package/src/prompts/steps/17-data-integrity.md +139 -139
  22. package/src/prompts/steps/18-performance.md +183 -183
  23. package/src/prompts/steps/19-cost-resource-optimization.md +136 -136
  24. package/src/prompts/steps/20-error-recovery.md +145 -145
  25. package/src/prompts/steps/21-race-condition-audit.md +178 -178
  26. package/src/prompts/steps/22-bug-hunt.md +229 -229
  27. package/src/prompts/steps/23-frontend-quality.md +210 -210
  28. package/src/prompts/steps/24-uiux-audit.md +284 -284
  29. package/src/prompts/steps/25-state-management.md +170 -170
  30. package/src/prompts/steps/26-perceived-performance.md +190 -190
  31. package/src/prompts/steps/27-devops.md +165 -165
  32. package/src/prompts/steps/28-scheduled-job-chron-jobs.md +141 -141
  33. package/src/prompts/steps/29-observability.md +152 -152
  34. package/src/prompts/steps/30-backup-check.md +155 -155
  35. package/src/prompts/steps/31-product-polish-ux-friction.md +122 -122
  36. package/src/prompts/steps/32-feature-discovery-opportunity.md +128 -128
  37. package/src/prompts/steps/33-strategic-opportunities.md +217 -217
@@ -1,183 +1,183 @@
1
- You are running an overnight performance analysis and optimization pass. Identify bottlenecks, optimize what's safe, and document everything else.
2
-
3
- Branch: `performance-optimization-[date]`
4
-
5
- ## General Rules
6
- - Run tests after every change
7
- - DO NOT change behavior — only performance characteristics
8
- - Database migrations: write files but DO NOT run them (need human review)
9
- - Caching: document opportunities, don't implement complex infrastructure overnight
10
- - Only parallelize provably independent operations
11
- - Frontend: no new dependencies. Attributes (`loading="lazy"`, `font-display: swap`, `async`, `defer`) are fine
12
- - Only add `React.memo`/`useMemo`/`useCallback` where unnecessary re-renders are demonstrable
13
- - Focus on hot paths. Be honest about impact — a query on 50 rows once/day isn't worth optimizing
14
- - Commit format: `perf: [action] in [location]` or `fix: [issue] in [module]`
15
-
16
- ## Phase 1: Database & Query Performance
17
-
18
- **Step 1: Inventory all database queries**
19
- For each query, note: calling endpoint/function, tables hit, joins/subqueries/aggregations, WHERE clauses, and whether results are paginated or unbounded.
20
-
21
- **Step 2: Fix N+1 queries**
22
- Look for: loops executing per-iteration queries, ORM lazy loading, endpoints fetching lists then querying details per item, GraphQL resolvers fetching nested data one-by-one. Fix with eager loading, joins, or batch queries.
23
-
24
- **Step 3: Identify missing indexes**
25
- Check every WHERE, JOIN, and ORDER BY column for index coverage. Consider single-column, composite, and partial indexes. Write migration files with documented expected impact.
26
-
27
- **Step 4: Other query issues**
28
- - `SELECT *` when few columns needed
29
- - Unbounded queries on large tables / missing pagination
30
- - Queries inside unnecessary transaction blocks
31
- - Duplicate queries within a single request
32
- - Sorting/filtering in app code that should be in the DB
33
-
34
- ## Phase 2: Application-Level Performance
35
-
36
- **Step 1: Expensive operations**
37
- - Nested loops (O(n²)+) on large datasets
38
- - Synchronous/blocking operations on hot paths
39
- - Large per-request data transformations that should be cached
40
- - Missing memoization of repeated deterministic computations
41
- - String concatenation in loops; unnecessary JSON.parse/stringify in hot paths
42
-
43
- **Step 2: Caching opportunities**
44
- Identify data that is: read-heavy/write-rare, expensive but deterministic, fetched from slow/rate-limited external APIs, or computed identically across requests. Document: what to cache, strategy (in-memory/Redis/HTTP headers), invalidation approach, estimated impact.
45
-
46
- **Step 3: Async/concurrency improvements**
47
- - Sequential calls that could be parallelized (`Promise.all` / `asyncio.gather`)
48
- - Blocking I/O that could be async
49
- - Missing connection pooling
50
- - Missing request throttling for external APIs
51
- - Heavy processing that should be a background job
52
-
53
- ## Phase 3: Memory & Resource Performance
54
-
55
- **Step 1: Memory leak patterns**
56
- - Event listeners added but never removed
57
- - Growing collections never pruned (in-memory caches without eviction)
58
- - Closures capturing large objects unnecessarily
59
- - Unclosed streams/connections (especially in error paths)
60
- - Uncleared intervals/timers
61
- - Circular references; large objects in module-level variables
62
-
63
- **Step 2: Resource management issues**
64
- - DB connections not returned to pool (especially on error)
65
- - File handles without guaranteed close (missing finally/using/with)
66
- - Unterminated HTTP connections; unmanaged child processes; orphaned temp files
67
-
68
- **Step 3: Fix safe issues** — add missing cleanup (event listeners, timers, finally blocks, connection handling). Test after each fix.
69
-
70
- ## Phase 4: Frontend Performance
71
-
72
- **Skip entirely if no frontend exists.**
73
-
74
- **Step 1: Render performance**
75
-
76
- *React (adapt for other frameworks):*
77
- - Unnecessary re-renders (missing `React.memo`, `useMemo`/`useCallback`)
78
- - State stored too high in the tree
79
- - Large lists (50+ items) without virtualization
80
- - Expensive computations in render bodies, unmemoized
81
- - Context providers with inline object/array values causing consumer re-renders
82
- - `useEffect` syncing derived state that should be `useMemo`
83
- - Components subscribing to full global state but using a small slice
84
-
85
- *Framework-agnostic:*
86
- - Layout thrashing (interleaved DOM reads/writes in loops)
87
- - Forced synchronous layouts (reading computed styles after mutations)
88
- - Expensive CSS selectors in frequently re-rendered areas
89
- - CSS animations on layout-triggering properties (`top`/`left`/`width`/`height`) instead of `transform`/`opacity`
90
- - Large DOM trees (>1500 nodes)
91
-
92
- **Step 2: Loading performance**
93
-
94
- *Critical rendering path:* What blocks first paint? Synchronous `<head>` scripts, render-blocking CSS, large synchronous imports. Check for `async`/`defer`, inline critical CSS, meaningful loading states.
95
-
96
- *Code splitting:* Are routes lazy-loaded? Heavy components (editors, charts, PDF viewers)? Modals/dialogs? Appropriate `Suspense` boundaries?
97
-
98
- *Fonts:* Check `font-display` (should be `swap`/`optional`). Preloaded? Count and size of font files. System font fallback to prevent FOIT?
99
-
100
- *Images:* `loading="lazy"` below fold? `srcset`/`sizes` for responsive images? Appropriately sized? Modern formats (WebP/AVIF)? Compressed? SVGs for icons where appropriate?
101
-
102
- *Third-party scripts:* Inventory all (analytics, chat, A/B, ads, embeds). Loaded async? Blocking main thread? Deferrable? Total weight vs first-party?
103
-
104
- **Step 3: Runtime event handlers**
105
- - Scroll/resize handlers without throttle/debounce
106
- - Input handlers triggering expensive ops per keystroke (search, API validation)
107
- - Mouse move handlers on large areas
108
- - Missing `passive: true` on scroll/touch listeners
109
-
110
- **Step 4: Animation performance**
111
- - JS animations that could be CSS transitions (compositor thread)
112
- - `setInterval` instead of `requestAnimationFrame`
113
- - Animations triggering layout recalc — use `transform`/`opacity` instead
114
- - Missing `will-change` on confirmed-animated elements (use sparingly)
115
-
116
- ## Phase 5: Quick Performance Wins
117
- Implement as you go: replace `Array.find` in loops with Map/Set, move invariants out of loops, replace sync file reads with async on hot paths, add early returns, debounce/throttle noisy handlers.
118
-
119
- ## Output
120
-
121
- Save as `audit-reports/18_PERFORMANCE_REPORT_[run-number]_[date]_[time in user's local time].md`. Create directory if needed. Increment run number based on existing reports.
122
-
123
- ### Report Structure
124
-
125
- 1. **Executive Summary** — Top 5 issues, severity (critical/high/medium/low), quick wins implemented vs larger efforts needed
126
-
127
- 2. **Database Performance** — N+1s fixed (with before/after) and unfixed (with reasons). Missing indexes table: Table | Column(s) | Query Location | Migration File. Other query issues with recommendations.
128
-
129
- 3. **Application Performance** — Expensive operations: Location | Issue | Complexity | Recommendation. Caching: Data | Strategy | Invalidation | Impact. Parallelization implemented/documented.
130
-
131
- 4. **Memory & Resources** — Leaks fixed, potential leaks needing investigation, resource management gaps.
132
-
133
- 5. **Frontend Performance** (skip if no frontend)
134
- - Render: fixes applied (Component | Issue | Fix) and documented for review (Component | Issue | Impact | Effort)
135
- - Loading: what blocks first paint, fixes applied (Area | Before | After), larger recommendations (Opportunity | Impact | Effort)
136
- - Bundle: top 10 largest items (if analyzable)
137
- - Images: Image/Pattern | Issue | Recommendation
138
- - Third-party: Script | Purpose | Size | Async? | Deferrable?
139
- - Event handler and animation fixes applied
140
-
141
- 6. **Optimizations Implemented** — Every change with before/after. All tests passing: yes/no.
142
-
143
- 7. **Optimization Roadmap** — Larger efforts ordered by impact with rough effort estimates.
144
-
145
- 8. **Monitoring Recommendations** — Key metrics, alert-worthy queries, frontend vitals (LCP, INP, CLS, TTI, bundle size), suggested perf testing approach.
146
-
147
- ## Chat Output Requirement
148
-
149
- In addition to writing the full report file, you MUST print a summary directly in the conversation when you finish. Do not make the user open the report to get the highlights. The chat summary should include:
150
-
151
- ### 1. Status Line
152
- One sentence: what you did, how long it took, and whether all tests still pass.
153
-
154
- ### 2. Key Findings
155
- The most important things discovered — bugs, risks, wins, or surprises. Each bullet should be specific and actionable, not vague. Lead with severity or impact.
156
-
157
- **Good:** "CRITICAL: No backup configuration found for the primary Postgres database — total data loss risk."
158
- **Bad:** "Found some issues with backups."
159
-
160
- ### 3. Changes Made (if applicable)
161
- Bullet list of what was actually modified, added, or removed. Skip this section for read-only analysis runs.
162
-
163
- ### 4. Recommendations
164
-
165
- If there are legitimately beneficial recommendations worth pursuing right now, present them in a table. Do **not** force recommendations — if the audit surfaced no actionable improvements, simply state that no recommendations are warranted at this time and move on.
166
-
167
- When recommendations exist, use this table format:
168
-
169
- | # | Recommendation | Impact | Risk if Ignored | Worth Doing? | Details |
170
- |---|---|---|---|---|---|
171
- | *Sequential number* | *Short description (≤10 words)* | *What improves if addressed* | *Low / Medium / High / Critical* | *Yes / Probably / Only if time allows* | *1–3 sentences explaining the reasoning, context, or implementation guidance* |
172
-
173
- Order rows by risk descending (Critical → High → Medium → Low). Be honest in the "Worth Doing?" column — not everything flagged is worth the engineering time. If a recommendation is marginal, say so.
174
-
175
- ### 5. Report Location
176
- State the full path to the detailed report file for deeper review.
177
-
178
- ---
179
-
180
- **Formatting rules for chat output:**
181
- - Use markdown headers, bold for severity labels, and bullet points for scannability.
182
- - Do not duplicate the full report contents — just the highlights and recommendations.
183
- - If you made zero findings in a phase, say so in one line rather than omitting it silently.
1
+ You are running an overnight performance analysis and optimization pass. Identify bottlenecks, optimize what's safe, and document everything else.
2
+
3
+ Branch: `performance-optimization-[date]`
4
+
5
+ ## General Rules
6
+ - Run tests after every change
7
+ - DO NOT change behavior — only performance characteristics
8
+ - Database migrations: write files but DO NOT run them (need human review)
9
+ - Caching: document opportunities, don't implement complex infrastructure overnight
10
+ - Only parallelize provably independent operations
11
+ - Frontend: no new dependencies. Attributes (`loading="lazy"`, `font-display: swap`, `async`, `defer`) are fine
12
+ - Only add `React.memo`/`useMemo`/`useCallback` where unnecessary re-renders are demonstrable
13
+ - Focus on hot paths. Be honest about impact — a query on 50 rows once/day isn't worth optimizing
14
+ - Commit format: `perf: [action] in [location]` or `fix: [issue] in [module]`
15
+
16
+ ## Phase 1: Database & Query Performance
17
+
18
+ **Step 1: Inventory all database queries**
19
+ For each query, note: calling endpoint/function, tables hit, joins/subqueries/aggregations, WHERE clauses, and whether results are paginated or unbounded.
20
+
21
+ **Step 2: Fix N+1 queries**
22
+ Look for: loops executing per-iteration queries, ORM lazy loading, endpoints fetching lists then querying details per item, GraphQL resolvers fetching nested data one-by-one. Fix with eager loading, joins, or batch queries.
23
+
24
+ **Step 3: Identify missing indexes**
25
+ Check every WHERE, JOIN, and ORDER BY column for index coverage. Consider single-column, composite, and partial indexes. Write migration files with documented expected impact.
26
+
27
+ **Step 4: Other query issues**
28
+ - `SELECT *` when few columns needed
29
+ - Unbounded queries on large tables / missing pagination
30
+ - Queries inside unnecessary transaction blocks
31
+ - Duplicate queries within a single request
32
+ - Sorting/filtering in app code that should be in the DB
33
+
34
+ ## Phase 2: Application-Level Performance
35
+
36
+ **Step 1: Expensive operations**
37
+ - Nested loops (O(n²)+) on large datasets
38
+ - Synchronous/blocking operations on hot paths
39
+ - Large per-request data transformations that should be cached
40
+ - Missing memoization of repeated deterministic computations
41
+ - String concatenation in loops; unnecessary JSON.parse/stringify in hot paths
42
+
43
+ **Step 2: Caching opportunities**
44
+ Identify data that is: read-heavy/write-rare, expensive but deterministic, fetched from slow/rate-limited external APIs, or computed identically across requests. Document: what to cache, strategy (in-memory/Redis/HTTP headers), invalidation approach, estimated impact.
45
+
46
+ **Step 3: Async/concurrency improvements**
47
+ - Sequential calls that could be parallelized (`Promise.all` / `asyncio.gather`)
48
+ - Blocking I/O that could be async
49
+ - Missing connection pooling
50
+ - Missing request throttling for external APIs
51
+ - Heavy processing that should be a background job
52
+
53
+ ## Phase 3: Memory & Resource Performance
54
+
55
+ **Step 1: Memory leak patterns**
56
+ - Event listeners added but never removed
57
+ - Growing collections never pruned (in-memory caches without eviction)
58
+ - Closures capturing large objects unnecessarily
59
+ - Unclosed streams/connections (especially in error paths)
60
+ - Uncleared intervals/timers
61
+ - Circular references; large objects in module-level variables
62
+
63
+ **Step 2: Resource management issues**
64
+ - DB connections not returned to pool (especially on error)
65
+ - File handles without guaranteed close (missing finally/using/with)
66
+ - Unterminated HTTP connections; unmanaged child processes; orphaned temp files
67
+
68
+ **Step 3: Fix safe issues** — add missing cleanup (event listeners, timers, finally blocks, connection handling). Test after each fix.
69
+
70
+ ## Phase 4: Frontend Performance
71
+
72
+ **Skip entirely if no frontend exists.**
73
+
74
+ **Step 1: Render performance**
75
+
76
+ *React (adapt for other frameworks):*
77
+ - Unnecessary re-renders (missing `React.memo`, `useMemo`/`useCallback`)
78
+ - State stored too high in the tree
79
+ - Large lists (50+ items) without virtualization
80
+ - Expensive computations in render bodies, unmemoized
81
+ - Context providers with inline object/array values causing consumer re-renders
82
+ - `useEffect` syncing derived state that should be `useMemo`
83
+ - Components subscribing to full global state but using a small slice
84
+
85
+ *Framework-agnostic:*
86
+ - Layout thrashing (interleaved DOM reads/writes in loops)
87
+ - Forced synchronous layouts (reading computed styles after mutations)
88
+ - Expensive CSS selectors in frequently re-rendered areas
89
+ - CSS animations on layout-triggering properties (`top`/`left`/`width`/`height`) instead of `transform`/`opacity`
90
+ - Large DOM trees (>1500 nodes)
91
+
92
+ **Step 2: Loading performance**
93
+
94
+ *Critical rendering path:* What blocks first paint? Synchronous `<head>` scripts, render-blocking CSS, large synchronous imports. Check for `async`/`defer`, inline critical CSS, meaningful loading states.
95
+
96
+ *Code splitting:* Are routes lazy-loaded? Heavy components (editors, charts, PDF viewers)? Modals/dialogs? Appropriate `Suspense` boundaries?
97
+
98
+ *Fonts:* Check `font-display` (should be `swap`/`optional`). Preloaded? Count and size of font files. System font fallback to prevent FOIT?
99
+
100
+ *Images:* `loading="lazy"` below fold? `srcset`/`sizes` for responsive images? Appropriately sized? Modern formats (WebP/AVIF)? Compressed? SVGs for icons where appropriate?
101
+
102
+ *Third-party scripts:* Inventory all (analytics, chat, A/B, ads, embeds). Loaded async? Blocking main thread? Deferrable? Total weight vs first-party?
103
+
104
+ **Step 3: Runtime event handlers**
105
+ - Scroll/resize handlers without throttle/debounce
106
+ - Input handlers triggering expensive ops per keystroke (search, API validation)
107
+ - Mouse move handlers on large areas
108
+ - Missing `passive: true` on scroll/touch listeners
109
+
110
+ **Step 4: Animation performance**
111
+ - JS animations that could be CSS transitions (compositor thread)
112
+ - `setInterval` instead of `requestAnimationFrame`
113
+ - Animations triggering layout recalc — use `transform`/`opacity` instead
114
+ - Missing `will-change` on confirmed-animated elements (use sparingly)
115
+
116
+ ## Phase 5: Quick Performance Wins
117
+ Implement as you go: replace `Array.find` in loops with Map/Set, move invariants out of loops, replace sync file reads with async on hot paths, add early returns, debounce/throttle noisy handlers.
118
+
119
+ ## Output
120
+
121
+ Save as `audit-reports/18_PERFORMANCE_REPORT_[run-number]_[date]_[time in user's local time].md`. Create directory if needed. Increment run number based on existing reports.
122
+
123
+ ### Report Structure
124
+
125
+ 1. **Executive Summary** — Top 5 issues, severity (critical/high/medium/low), quick wins implemented vs larger efforts needed
126
+
127
+ 2. **Database Performance** — N+1s fixed (with before/after) and unfixed (with reasons). Missing indexes table: Table | Column(s) | Query Location | Migration File. Other query issues with recommendations.
128
+
129
+ 3. **Application Performance** — Expensive operations: Location | Issue | Complexity | Recommendation. Caching: Data | Strategy | Invalidation | Impact. Parallelization implemented/documented.
130
+
131
+ 4. **Memory & Resources** — Leaks fixed, potential leaks needing investigation, resource management gaps.
132
+
133
+ 5. **Frontend Performance** (skip if no frontend)
134
+ - Render: fixes applied (Component | Issue | Fix) and documented for review (Component | Issue | Impact | Effort)
135
+ - Loading: what blocks first paint, fixes applied (Area | Before | After), larger recommendations (Opportunity | Impact | Effort)
136
+ - Bundle: top 10 largest items (if analyzable)
137
+ - Images: Image/Pattern | Issue | Recommendation
138
+ - Third-party: Script | Purpose | Size | Async? | Deferrable?
139
+ - Event handler and animation fixes applied
140
+
141
+ 6. **Optimizations Implemented** — Every change with before/after. All tests passing: yes/no.
142
+
143
+ 7. **Optimization Roadmap** — Larger efforts ordered by impact with rough effort estimates.
144
+
145
+ 8. **Monitoring Recommendations** — Key metrics, alert-worthy queries, frontend vitals (LCP, INP, CLS, TTI, bundle size), suggested perf testing approach.
146
+
147
+ ## Chat Output Requirement
148
+
149
+ In addition to writing the full report file, you MUST print a summary directly in the conversation when you finish. Do not make the user open the report to get the highlights. The chat summary should include:
150
+
151
+ ### 1. Status Line
152
+ One sentence: what you did, how long it took, and whether all tests still pass.
153
+
154
+ ### 2. Key Findings
155
+ The most important things discovered — bugs, risks, wins, or surprises. Each bullet should be specific and actionable, not vague. Lead with severity or impact.
156
+
157
+ **Good:** "CRITICAL: No backup configuration found for the primary Postgres database — total data loss risk."
158
+ **Bad:** "Found some issues with backups."
159
+
160
+ ### 3. Changes Made (if applicable)
161
+ Bullet list of what was actually modified, added, or removed. Skip this section for read-only analysis runs.
162
+
163
+ ### 4. Recommendations
164
+
165
+ If there are legitimately beneficial recommendations worth pursuing right now, present them in a table. Do **not** force recommendations — if the audit surfaced no actionable improvements, simply state that no recommendations are warranted at this time and move on.
166
+
167
+ When recommendations exist, use this table format:
168
+
169
+ | # | Recommendation | Impact | Risk if Ignored | Worth Doing? | Details |
170
+ |---|---|---|---|---|---|
171
+ | *Sequential number* | *Short description (≤10 words)* | *What improves if addressed* | *Low / Medium / High / Critical* | *Yes / Probably / Only if time allows* | *1–3 sentences explaining the reasoning, context, or implementation guidance* |
172
+
173
+ Order rows by risk descending (Critical → High → Medium → Low). Be honest in the "Worth Doing?" column — not everything flagged is worth the engineering time. If a recommendation is marginal, say so.
174
+
175
+ ### 5. Report Location
176
+ State the full path to the detailed report file for deeper review.
177
+
178
+ ---
179
+
180
+ **Formatting rules for chat output:**
181
+ - Use markdown headers, bold for severity labels, and bullet points for scannability.
182
+ - Do not duplicate the full report contents — just the highlights and recommendations.
183
+ - If you made zero findings in a phase, say so in one line rather than omitting it silently.