nightytidy 0.1.0

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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +314 -0
  3. package/bin/nightytidy.js +3 -0
  4. package/package.json +55 -0
  5. package/src/checks.js +367 -0
  6. package/src/claude.js +655 -0
  7. package/src/cli.js +1012 -0
  8. package/src/consolidation.js +81 -0
  9. package/src/dashboard-html.js +496 -0
  10. package/src/dashboard-standalone.js +167 -0
  11. package/src/dashboard-tui.js +208 -0
  12. package/src/dashboard.js +427 -0
  13. package/src/env.js +100 -0
  14. package/src/executor.js +550 -0
  15. package/src/git.js +348 -0
  16. package/src/lock.js +186 -0
  17. package/src/logger.js +111 -0
  18. package/src/notifications.js +33 -0
  19. package/src/orchestrator.js +919 -0
  20. package/src/prompts/loader.js +55 -0
  21. package/src/prompts/manifest.json +138 -0
  22. package/src/prompts/specials/changelog.md +28 -0
  23. package/src/prompts/specials/consolidation.md +61 -0
  24. package/src/prompts/specials/doc-update.md +1 -0
  25. package/src/prompts/specials/report.md +95 -0
  26. package/src/prompts/steps/01-documentation.md +173 -0
  27. package/src/prompts/steps/02-test-coverage.md +181 -0
  28. package/src/prompts/steps/03-test-hardening.md +181 -0
  29. package/src/prompts/steps/04-test-architecture.md +130 -0
  30. package/src/prompts/steps/05-test-consolidation.md +165 -0
  31. package/src/prompts/steps/06-test-quality.md +211 -0
  32. package/src/prompts/steps/07-api-design.md +165 -0
  33. package/src/prompts/steps/08-security-sweep.md +207 -0
  34. package/src/prompts/steps/09-dependency-health.md +217 -0
  35. package/src/prompts/steps/10-codebase-cleanup.md +189 -0
  36. package/src/prompts/steps/11-crosscutting-concerns.md +196 -0
  37. package/src/prompts/steps/12-file-decomposition.md +263 -0
  38. package/src/prompts/steps/13-code-elegance.md +329 -0
  39. package/src/prompts/steps/14-architectural-complexity.md +297 -0
  40. package/src/prompts/steps/15-type-safety.md +192 -0
  41. package/src/prompts/steps/16-logging-error-message.md +173 -0
  42. package/src/prompts/steps/17-data-integrity.md +139 -0
  43. package/src/prompts/steps/18-performance.md +183 -0
  44. package/src/prompts/steps/19-cost-resource-optimization.md +136 -0
  45. package/src/prompts/steps/20-error-recovery.md +145 -0
  46. package/src/prompts/steps/21-race-condition-audit.md +178 -0
  47. package/src/prompts/steps/22-bug-hunt.md +229 -0
  48. package/src/prompts/steps/23-frontend-quality.md +210 -0
  49. package/src/prompts/steps/24-uiux-audit.md +284 -0
  50. package/src/prompts/steps/25-state-management.md +170 -0
  51. package/src/prompts/steps/26-perceived-performance.md +190 -0
  52. package/src/prompts/steps/27-devops.md +165 -0
  53. package/src/prompts/steps/28-scheduled-job-chron-jobs.md +141 -0
  54. package/src/prompts/steps/29-observability.md +152 -0
  55. package/src/prompts/steps/30-backup-check.md +155 -0
  56. package/src/prompts/steps/31-product-polish-ux-friction.md +122 -0
  57. package/src/prompts/steps/32-feature-discovery-opportunity.md +128 -0
  58. package/src/prompts/steps/33-strategic-opportunities.md +217 -0
  59. package/src/report.js +540 -0
  60. package/src/setup.js +133 -0
  61. package/src/sync.js +536 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 NightyTidy Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,314 @@
1
+ # NightyTidy
2
+
3
+ Automated overnight codebase improvement through [Claude Code](https://docs.anthropic.com/en/docs/claude-code). NightyTidy sequences 33 AI-driven improvement prompts against your codebase — handling git branching, retries, rate-limit recovery, notifications, and reporting. Kick it off before bed, review the results in the morning.
4
+
5
+ Built for vibe coders and small teams who want production-grade code quality without the grind.
6
+
7
+ ## Prerequisites
8
+
9
+ - **Node.js** >= 20.12.0
10
+ - **Git** installed and on your PATH
11
+ - **Claude Code CLI** installed and authenticated — [installation guide](https://docs.anthropic.com/en/docs/claude-code)
12
+ - **Google Chrome** (for the desktop GUI)
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ git clone https://github.com/dorianspitz23/NightyTidy.git
18
+ cd NightyTidy
19
+ npm install
20
+ ```
21
+
22
+ No build step — plain JavaScript ESM, runs directly.
23
+
24
+ ## Quick Start
25
+
26
+ Launch the desktop GUI:
27
+
28
+ ```bash
29
+ npm run gui
30
+ ```
31
+
32
+ This opens a Chrome app-mode window. From there:
33
+
34
+ 1. **Select your project folder** using the native folder picker
35
+ 2. **Pick which steps to run** — or Select All for all 33
36
+ 3. **Set the timeout** per step (default: 45 minutes)
37
+ 4. **Click Start Run** and walk away
38
+
39
+ NightyTidy handles everything from there: progress tracking, live Claude output, rate-limit pausing, report generation, and merging changes back to your branch.
40
+
41
+ ## Run Duration and Token Usage
42
+
43
+ A full 33-step run is a serious workload — expect **6 to 8 hours** with Claude running at full capacity the entire time. Each step gets its own Claude Code session, and many steps involve reading your entire codebase, making changes, running tests, and iterating. This adds up fast.
44
+
45
+ **You will likely hit usage limits** unless you're on Anthropic's Max plan. To avoid mid-run rate limits:
46
+
47
+ - **Max plan recommended** — A full run burns through a large number of tokens. The Max plan gives you the headroom to complete all 33 steps without interruption.
48
+ - **Run in batches** — If you're not on Max, run a quarter or half of the steps at a time (e.g., `--steps 1-8`, then `--steps 9-16` after your usage resets). The GUI's step picker makes this easy.
49
+ - **Use the rate-limit recovery** — If you do hit limits mid-run, NightyTidy pauses automatically and can resume later. Save & Close in the GUI, or use `--resume` in the CLI when your limits reset.
50
+
51
+ Running fewer steps per session is a perfectly valid workflow — you'll get the same results, just spread over multiple nights.
52
+
53
+ ## Desktop GUI
54
+
55
+ The GUI is the primary way to use NightyTidy. It wraps the CLI orchestrator in a five-screen visual workflow.
56
+
57
+ ### Screens
58
+
59
+ | Screen | What it does |
60
+ |--------|-------------|
61
+ | **Setup** | Pick a project folder via native file dialog. Validates git repo and Claude CLI. |
62
+ | **Step Selection** | Browse all 33 steps with checkboxes, Select All / Deselect All, set timeout. Detects and offers to resume paused runs. |
63
+ | **Running** | Live progress bar, per-step status indicators, real-time Claude output panel, elapsed time, cost/token tracking, Skip Step and Stop Run controls. |
64
+ | **Finishing** | Generates an AI-narrated report and merges changes back to your original branch. |
65
+ | **Summary** | Final results — steps completed/failed, total cost, token usage, duration. Click any step to review its full output. |
66
+
67
+ ### Features
68
+
69
+ - **Live output viewer** — Watch Claude work in real time. Markdown-rendered output panel with a "Claude is working" indicator during long tool executions.
70
+ - **Step output drawer** — Click any completed or failed step to open its full output in a side panel with markdown rendering and a copy button.
71
+ - **Rate-limit handling** — If you hit Claude's API usage limit, NightyTidy pauses automatically with a countdown timer. Three options: Resume Now, Finish with Partial Results, or Save & Close to resume later.
72
+ - **Pause and resume** — Close the GUI mid-run and come back later. Progress is saved to `nightytidy-run-state.json`. On next launch, the GUI detects the saved state and offers to resume.
73
+ - **Page refresh safe** — Accidentally refresh the browser? The GUI reconnects to the still-running backend process and picks up where it left off.
74
+ - **Background tab safe** — Alt-tab away without worry. A Web Worker heartbeat keeps the server connection alive even when Chrome throttles background tabs.
75
+ - **Skip and stop** — Skip the current step or stop the entire run at any time. A confirmation dialog prevents accidental stops. Completed work is always preserved.
76
+ - **Singleton guard** — Only one GUI instance can run at a time. Launching again focuses the existing window.
77
+
78
+ ## CLI Usage
79
+
80
+ For terminal users, scripting, or CI environments:
81
+
82
+ ```bash
83
+ # Interactive — pick steps from a checklist
84
+ npx nightytidy
85
+
86
+ # Run all 33 steps
87
+ npx nightytidy --all
88
+
89
+ # Run specific steps by number
90
+ npx nightytidy --steps 1,5,12
91
+
92
+ # List all available steps with descriptions
93
+ npx nightytidy --list
94
+
95
+ # Preview what would run without actually running
96
+ npx nightytidy --dry-run
97
+
98
+ # Set per-step timeout (default: 45 minutes)
99
+ npx nightytidy --timeout 60
100
+
101
+ # Resume a paused run (after rate limit or restart)
102
+ npx nightytidy --resume
103
+
104
+ # Sync prompts from the Google Doc
105
+ npx nightytidy --sync
106
+
107
+ # Preview what sync would change without writing
108
+ npx nightytidy --sync-dry-run
109
+
110
+ # Skip automatic prompt sync before a run
111
+ npx nightytidy --skip-sync
112
+
113
+ # Add NightyTidy integration to a project's CLAUDE.md
114
+ npx nightytidy --setup
115
+ ```
116
+
117
+ In environments without a TTY (CI, scripts), you must specify `--all` or `--steps` — interactive step selection is not available.
118
+
119
+ ### Orchestrator Mode
120
+
121
+ For use within Claude Code (no terminal). Outputs JSON for conversational workflows:
122
+
123
+ ```bash
124
+ npx nightytidy --list --json # List steps as JSON
125
+ npx nightytidy --init-run --steps 1,5,12 # Initialize a run
126
+ npx nightytidy --run-step 1 # Run one step
127
+ npx nightytidy --finish-run # Generate report + merge
128
+ ```
129
+
130
+ Run `npx nightytidy --setup` in your project to add a CLAUDE.md snippet that teaches Claude Code this workflow.
131
+
132
+ ## The 33 Improvement Steps
133
+
134
+ | # | Step | Focus |
135
+ |---|------|-------|
136
+ | 1 | Documentation | Coverage, accuracy, API docs |
137
+ | 2 | Test Coverage | Missing tests, untested paths |
138
+ | 3 | Test Hardening | Flaky tests, edge cases, error paths |
139
+ | 4 | Test Architecture | Structure, patterns, organization |
140
+ | 5 | Test Consolidation | Remove duplicates, merge related tests |
141
+ | 6 | Test Quality | Tautological tests, testing implementation details |
142
+ | 7 | API Design | Consistency, naming, contracts |
143
+ | 8 | Security Sweep | Auth, injection, OWASP top 10 |
144
+ | 9 | Dependency Health | Outdated, unused, vulnerable deps |
145
+ | 10 | Codebase Cleanup | Dead code, unused imports, lint |
146
+ | 11 | Cross-Cutting Concerns | Logging, error handling, validation patterns |
147
+ | 12 | File Decomposition | Large files, single-responsibility splits |
148
+ | 13 | Code Elegance | Readability, naming, simplification |
149
+ | 14 | Architectural Complexity | Over-engineering, unnecessary abstraction |
150
+ | 15 | Type Safety | Type assertions, null safety, contracts |
151
+ | 16 | Logging & Error Messages | Quality, consistency, actionability |
152
+ | 17 | Data Integrity | Validation, constraints, edge cases |
153
+ | 18 | Performance | N+1 queries, memory, algorithmic complexity |
154
+ | 19 | Cost & Resource Optimization | API calls, caching, efficiency |
155
+ | 20 | Error Recovery | Graceful degradation, retry logic |
156
+ | 21 | Race Condition Audit | Concurrency, atomicity, ordering |
157
+ | 22 | Bug Hunt | Logic errors, off-by-ones, silent failures |
158
+ | 23 | Frontend Quality | Components, rendering, accessibility |
159
+ | 24 | UI/UX Audit | Usability, consistency, friction |
160
+ | 25 | State Management | State flow, side effects, synchronization |
161
+ | 26 | Perceived Performance | Loading states, skeleton screens, responsiveness |
162
+ | 27 | DevOps | CI/CD, deployment, environment config |
163
+ | 28 | Scheduled Jobs & Cron | Reliability, idempotency, monitoring |
164
+ | 29 | Observability | Metrics, tracing, alerting |
165
+ | 30 | Backup Check | Data safety, recovery procedures |
166
+ | 31 | Product Polish & UX Friction | Edge cases, empty states, error UX |
167
+ | 32 | Feature Discovery & Opportunity | Missing features, quick wins |
168
+ | 33 | Strategic Opportunities | Architecture direction, scaling, roadmap |
169
+
170
+ Prompts auto-sync from a published Google Doc before every run. Use `--skip-sync` to skip, or `npx nightytidy --sync` to sync manually.
171
+
172
+ ## How It Works
173
+
174
+ ### Safety First
175
+
176
+ Every run is protected by git:
177
+
178
+ 1. **Safety tag** — `nightytidy-before-YYYY-MM-DD-HHMM` snapshots your current state before any changes
179
+ 2. **Dedicated branch** — All work happens on `nightytidy/run-YYYY-MM-DD-HHMM`, never on your working branch
180
+ 3. **Auto-merge** — On completion, changes merge back to your original branch with `--no-ff`
181
+ 4. **Conflict handling** — On merge conflict, the run branch is left intact for manual resolution
182
+ 5. **Undo** — Reset to the safety tag at any time: `git reset --hard nightytidy-before-<timestamp>`
183
+
184
+ ### Step Execution
185
+
186
+ Each step runs in its own Claude Code session:
187
+
188
+ 1. Claude receives the improvement prompt + your codebase context
189
+ 2. Claude makes changes, runs tests, iterates
190
+ 3. Changes are committed to the run branch
191
+ 4. If Claude doesn't commit, NightyTidy makes a fallback commit
192
+ 5. Branch guards ensure all commits land on the correct branch (Claude sometimes creates its own branches — NightyTidy catches this and merges them back)
193
+
194
+ ### 3-Tier Step Recovery
195
+
196
+ If a step fails, NightyTidy retries automatically with three escalating tiers:
197
+
198
+ - **Tier 1** — Normal retry (up to 4 attempts per tier)
199
+ - **Tier 2 (Prod)** — Resume the killed session via `--continue` to recover partial work. Claude Code saves session state to disk, so partial progress isn't lost.
200
+ - **Tier 3 (Fresh)** — Clean slate retry with a completely new session
201
+
202
+ Maximum 12 Claude invocations per step across all tiers.
203
+
204
+ ### Rate-Limit Recovery
205
+
206
+ If Claude's API usage limit is reached mid-run:
207
+
208
+ - **GUI** — A pause overlay appears with a countdown timer. Options: Resume Now (if you've added credits or upgraded), Finish with Partial Results, or Save & Close for later.
209
+ - **CLI** — Automatic exponential backoff (2 min, 5 min, 15 min, ... up to 2 hours per wait). API probes between waits. Total coverage: ~10 hours.
210
+ - **Resume later** — Close everything and run `npx nightytidy --resume`, or relaunch the GUI — it detects saved state and offers to continue.
211
+
212
+ ### Abort Handling
213
+
214
+ - **CLI**: Press `Ctrl+C` once to finish the current step and generate a partial report. Press again to force-exit.
215
+ - **GUI**: Click Stop Run (with confirmation dialog). Completed work is preserved and a report is generated.
216
+
217
+ Changes are always on the run branch — your original branch is safe.
218
+
219
+ ### Report Generation
220
+
221
+ After all steps complete, NightyTidy generates:
222
+
223
+ - **NIGHTYTIDY-REPORT.md** — AI-narrated run summary with per-step results, costs, token usage, duration, and a prioritized action plan
224
+ - **CLAUDE.md update** — Appends a "Last Run" section with the run date and undo instructions
225
+ - **Audit trail** — All 33 step prompts are copied to `audit-reports/refactor-prompts/` so you can see exactly what was asked
226
+
227
+ If the AI report fails verification (junk detection), NightyTidy falls back to a template-based report so you always get results.
228
+
229
+ ## Files Created in Your Project
230
+
231
+ | File | Committed? | Purpose |
232
+ |------|-----------|---------|
233
+ | `NIGHTYTIDY-REPORT_NN_YYYY-MM-DD-HHMM.md` | Yes | Run summary with step results + action plan |
234
+ | `CLAUDE.md` (appended section) | Yes | "NightyTidy — Last Run" with undo tag |
235
+ | `audit-reports/refactor-prompts/*.md` | Yes | All 33 prompts for audit trail |
236
+ | `nightytidy-before-*` git tag | Yes (tag) | Safety snapshot for rollback |
237
+ | `nightytidy/run-*` git branch | Yes (branch) | All changes from the run |
238
+ | `nightytidy-run.log` | No | Detailed timestamped run log |
239
+ | `nightytidy-progress.json` | No | Live progress state (read by GUI) |
240
+ | `nightytidy-run-state.json` | No | Saved state for pause/resume |
241
+ | `nightytidy.lock` | No | Prevents concurrent runs |
242
+ | `nightytidy-gui.log` | No | GUI session log (errors, API requests) |
243
+
244
+ ## Rollback
245
+
246
+ If you don't like the results:
247
+
248
+ ```bash
249
+ git reset --hard nightytidy-before-<timestamp>
250
+ ```
251
+
252
+ The safety tag created before each run makes rollback a one-liner.
253
+
254
+ ## Configuration
255
+
256
+ NightyTidy works with zero configuration. The only environment variable:
257
+
258
+ | Variable | Default | Description |
259
+ |----------|---------|-------------|
260
+ | `NIGHTYTIDY_LOG_LEVEL` | `info` | Log verbosity: `debug`, `info`, `warn`, `error` |
261
+
262
+ No API keys needed — Claude Code handles its own authentication.
263
+
264
+ ## Security
265
+
266
+ - All changes happen on a dedicated git branch with a pre-run safety tag
267
+ - Claude Code runs with `--dangerously-skip-permissions` — NightyTidy is the permission layer, controlling what prompts are sent and operating on a safety branch
268
+ - GUI server binds to `127.0.0.1` only (not exposed to the network)
269
+ - Dashboard endpoints use CSRF tokens and security headers (CSP, X-Frame-Options, X-Content-Type-Options)
270
+ - Lock file prevents concurrent runs (atomic via `O_EXCL`)
271
+ - Environment variables filtered through an explicit allowlist before passing to Claude Code
272
+ - `.npmrc` with `ignore-scripts=true` blocks malicious post-install scripts
273
+ - CI includes Gitleaks secret scanning and `npm audit`
274
+
275
+ Always review the run branch diff before merging to verify the changes.
276
+
277
+ ## Development
278
+
279
+ ```bash
280
+ npm test # All tests (40 files, ~900 tests)
281
+ npm run test:fast # Skip slow integration/git tests (~6s vs ~10s)
282
+ npm run test:watch # Watch mode
283
+ npm run test:ci # With coverage enforcement (90% stmts, 80% branches/functions)
284
+ npm run test:flaky # Run suite 3x to detect flaky tests
285
+ npm run check:docs # Verify documentation matches code
286
+ npm run check:security # npm audit — fails on high+ severity
287
+ ```
288
+
289
+ ### CI Pipeline
290
+
291
+ GitHub Actions on every push/PR to master:
292
+ - Test matrix across Ubuntu + Windows, Node.js 20 / 22 / 24
293
+ - Coverage threshold enforcement
294
+ - Documentation freshness check
295
+ - Gitleaks secret scan
296
+ - Security audit (`npm audit`)
297
+
298
+ ### Tech Stack
299
+
300
+ | Layer | Technology |
301
+ |-------|-----------|
302
+ | Runtime | Node.js (ESM) >= 20.12.0 |
303
+ | CLI | Commander v14, @inquirer/checkbox v5 |
304
+ | Terminal UX | ora v9 (spinners), chalk v5 (colors) |
305
+ | Git | simple-git v3 |
306
+ | AI Engine | Claude Code CLI (subprocess) |
307
+ | Notifications | node-notifier v10 |
308
+ | GUI | Node.js HTTP server + Chrome `--app` mode |
309
+ | GUI Markdown | marked v17 (vendored UMD) |
310
+ | Testing | Vitest v3 |
311
+
312
+ ## License
313
+
314
+ [MIT](LICENSE)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { run } from '../src/cli.js';
3
+ run();
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "nightytidy",
3
+ "version": "0.1.0",
4
+ "description": "Automated overnight codebase improvement through Claude Code",
5
+ "license": "MIT",
6
+ "author": "Dorian Spitz",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dorianspitz23/NightyTidy.git"
10
+ },
11
+ "keywords": [
12
+ "claude",
13
+ "claude-code",
14
+ "ai",
15
+ "codebase",
16
+ "automation",
17
+ "refactoring",
18
+ "code-quality"
19
+ ],
20
+ "type": "module",
21
+ "files": [
22
+ "bin/",
23
+ "src/",
24
+ "LICENSE",
25
+ "README.md"
26
+ ],
27
+ "bin": {
28
+ "nightytidy": "./bin/nightytidy.js"
29
+ },
30
+ "scripts": {
31
+ "test": "vitest run",
32
+ "test:fast": "vitest run --exclude test/git.test.js --exclude test/git-extended.test.js --exclude test/integration.test.js --exclude test/integration-extended.test.js",
33
+ "test:watch": "vitest",
34
+ "test:ci": "vitest run --coverage",
35
+ "test:flaky": "node scripts/run-flaky-check.js",
36
+ "check:docs": "node scripts/check-docs-freshness.js",
37
+ "check:security": "npm audit --audit-level=high",
38
+ "gui": "node gui/server.js"
39
+ },
40
+ "engines": {
41
+ "node": ">=20.12.0"
42
+ },
43
+ "dependencies": {
44
+ "@inquirer/checkbox": "^5.1.0",
45
+ "chalk": "^5.6.2",
46
+ "commander": "^14.0.3",
47
+ "node-notifier": "^10.0.1",
48
+ "ora": "^9.3.0",
49
+ "simple-git": "3.33.0"
50
+ },
51
+ "devDependencies": {
52
+ "@vitest/coverage-v8": "^3.2.4",
53
+ "vitest": "^3.2.4"
54
+ }
55
+ }