Skip to content

feat(nightshift): add automated codebase maintenance system#122

Open
Loa212 wants to merge 3 commits intocoollabsio:mainfrom
Loa212:feat/nightshift
Open

feat(nightshift): add automated codebase maintenance system#122
Loa212 wants to merge 3 commits intocoollabsio:mainfrom
Loa212:feat/nightshift

Conversation

@Loa212
Copy link
Copy Markdown
Contributor

@Loa212 Loa212 commented Feb 24, 2026

Summary

Adds Nightshift — an automated codebase maintenance system that runs configurable checks in the background using real Claude CLI sessions.

What's included

Rust backend (src-tauri/src/nightshift/)

  • Engine with sequential check execution per project, concurrent across projects
  • 10 built-in checks: lint-fix, dead-code removal, doc-drift, security audit, test gaps, dependency audit, type safety, error handling, performance review, config hygiene
  • Per-project configuration: enable/disable checks, schedule time (HH:MM cron), post-action (nothing / commit / commit & PR), model/provider/backend overrides, per-check custom prompts and cooldown overrides
  • Atomic JSON storage with lock protection, max 50 runs per project, per-check cooldown tracking
  • RUNNING_PROJECTS guard prevents concurrent runs on the same project

Frontend (src/)

  • NightshiftPane in Project Settings with experimental banner, enable toggle, "Run Now" button, per-check config
  • NightshiftRunsModal with run history and collapsible check results
  • useNightshiftEvents hook: listens for nightshift:execute-check, sends messages to CLI sessions, reports completion back to engine
  • Zustand store + TanStack Query service layer

Integration points

(NICE-TO-HAVE) Token usage / cost tracking

Token usage tracking and budget limits are not yet implemented. Citing the inspiration (see below):

Budget-aware: Uses remaining daily allotment, never exceeds configurable max (default 75%)

Inspiration

Inspired by marcus/nightshift

@Loa212 Loa212 force-pushed the feat/nightshift branch 3 times, most recently from 23caf52 to cf65998 Compare March 3, 2026 15:49
@andrasbacsai
Copy link
Copy Markdown
Member

Oh wow, nightshift sounds pretty good! Thanks I will take a look at it!

@Loa212
Copy link
Copy Markdown
Contributor Author

Loa212 commented Mar 4, 2026

@andrasbacsai sorry I have to make some changes. I will tag you later once I feel it is ready for review again. Thanks !

@Loa212 Loa212 marked this pull request as draft March 4, 2026 08:26
@Loa212 Loa212 force-pushed the feat/nightshift branch 3 times, most recently from c2724c7 to de3b00f Compare March 6, 2026 16:26
@Loa212 Loa212 marked this pull request as ready for review March 6, 2026 16:30
@Loa212
Copy link
Copy Markdown
Contributor Author

Loa212 commented Mar 6, 2026

@andrasbacsai tested this with both Claude and Codex. It's marked as experimental, living in each project's settings under a "Nightshift" tab. You can hit Run Now to try it out immediately.

Built-in checks (8 enabled by default, 2 opt-in):

  • Lint Fix — auto-fix linting and code style violations (24h cooldown)
  • Dead Code Removal — find and remove unused imports, functions, variables (72h)
  • Documentation Drift — fix stale/missing/inaccurate docs and comments (48h)
  • Security Audit — OWASP top 10, hardcoded secrets, injection vulnerabilities (7d)
  • Test Coverage Gaps — write tests for untested code paths and edge cases (72h)
  • Dependency Audit — update outdated/deprecated/vulnerable dependencies (7d)
  • Type Safety — replace any types, add missing annotations (48h)
  • Error Handling — fix empty catches, swallowed errors, poor messages (48h)
  • Performance Review — N+1 queries, memory leaks, unnecessary re-renders (7d, opt-in)
  • Config Hygiene — clean up unused config keys, env gaps (7d, opt-in)

-> Each check has its own cooldown, can be individually enabled/disabled, and you can override the prompt per-check.

-> You can set a schedule time for automatic overnight runs, and choose what happens after: leave changes staged, commit, or commit & open a PR.

Since Codex now has usage tracking we could hook this up to show nightshift costs, or we can wait for stable Claude usage support. Let me know what you'd prefer.

Overall let me know what you think. I believe this can be a nice addition but you decide :)

If you want it shaped differently I'm open to suggestions.

Loa212 added 3 commits March 20, 2026 19:28
Nightshift runs configurable maintenance checks (lint, dead code, security,
tests, etc.) on a schedule or manually. Each check creates a timestamped
session in a dedicated "nightshift" worktree and executes via Claude CLI.

- Backend engine with sequential check execution and per-project guards
- 10 built-in checks with customizable prompts and cooldowns
- Scheduler (60s interval) with manual trigger support
- Frontend event orchestration and settings UI (marked experimental)
- Uses save_empty_index() and worktrees:changed from refactor PR
- Fix get_last_check_run_time() to use the run's started_at for the
  matching check result, not the max started_at across all runs
- Fix Codex detached tail to treat process exit with content as
  completed rather than cancelled (yolo mode may not emit turn.completed)
…ream compat

- Drop RunGuard before emitting run-completed event to prevent race
  where user clicks Run Now before RUNNING_PROJECTS is cleared
- Use has_content (text + tool_calls + content_blocks) instead of just
  full_content for Codex error/fallback checks — prevents false
  chat:error when Codex works via tools with no text output
- Add nightshift fields to new upstream Session constructor site
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants