ワンクリックで
nightshift
// Autonomous overnight code quality bot. 68 tasks across 7 categories with plan-implement-review architecture. 26 PR tasks + 42 issue tasks.
// Autonomous overnight code quality bot. 68 tasks across 7 categories with plan-implement-review architecture. 26 PR tasks + 42 issue tasks.
| name | nightshift |
| description | Autonomous overnight code quality bot. 68 tasks across 7 categories with plan-implement-review architecture. 26 PR tasks + 42 issue tasks. |
| trigger | nightshift |
Full implementation of marcus/nightshift for Hermes Agent. 68 task types, plan-implement-review architecture, budget tracking. 26 PR tasks + 42 issue tasks.
~/.nightshift/ (config + run history)~/nightshift-workspace/ (temp clones)~/nightshift-workspace/nightshift.py~/nightshift-workspace/nightshift_tasks.json~/nightshift-workspace/glm_quota.pyapi.z.ai (model ID: glm-5.1, verified working on the Api.z.ai provider)python3 ~/nightshift-workspace/nightshift.py --list-categories # 7 categories
python3 ~/nightshift-workspace/nightshift.py --list-tasks # All 61 tasks
python3 ~/nightshift-workspace/nightshift.py --dry-run # Preview
python3 ~/nightshift-workspace/nightshift.py # Select + clone + output
python3 ~/nightshift-workspace/glm_quota.py --check # Quota gate
| Category | Tasks | Output Mode | Review Loop |
|---|---|---|---|
| pr | 24 | PR (24) | Yes |
| analysis | 17 | Issue | No |
| options | 13 | Issue | No |
| safe | 5 | Issue | No |
| map | 7 | PR (1) + Issue (6) | Yes (1 task) |
| emergency | 3 | Issue | No |
| review | 1 | PR | Yes |
26 tasks create PRs (actual code/artifact changes). 42 tasks create issues (findings, reports, suggestions). The output_mode field determines the output type, independent of the task category.
lint-fix, bug-finder, auto-dry, skill-groom, api-contract-verify, backward-compat, build-optimize, docs-backfill, commit-normalize, changelog-synth, release-notes, adr-draft, ci-fixes, dependency-updates, readme-improvements, dead-code, code-quality, code-review, visibility-instrument, perf-audit, autoresearch, react-effect-cleanup, react-image-fix, lint-doctor-fix, best-practice-fix, optimo
doc-drift, semantic-diff, dependency-risk, test-gap, test-flakiness, logging-audit, metrics-coverage, perf-regression, cost-attribution, security-footgun, pii-scanner, privacy-policy, schema-evolution, event-taxonomy, roadmap-entropy, bus-factor, knowledge-silo, tech-debt-classify, why-annotator, edge-case-enum, error-msg-improve, slo-suggester, ux-copy-sharpener, a11y-lint, service-advisor, ownership-boundary, oncall-estimator, idea-generator, migration-rehearsal, contract-fuzzer, golden-path, perf-profile, allocation-profile, repo-topology, permissions-mapper, data-lifecycle, feature-flag-monitor, ci-signal-noise, historical-context, runbook-gen, rollback-plan, postmortem-gen
PR category (24): lint-fix, bug-finder, auto-dry, skill-groom, api-contract-verify, backward-compat, build-optimize, docs-backfill, commit-normalize, changelog-synth, release-notes, adr-draft, ci-fixes, dependency-updates, readme-improvements, dead-code, code-quality, perf-audit, autoresearch, react-effect-cleanup, react-image-fix, lint-doctor-fix, best-practice-fix, optimo
Analysis category (17): doc-drift, semantic-diff, dependency-risk, test-gap, test-flakiness, logging-audit, metrics-coverage, perf-regression, cost-attribution, security-footgun, pii-scanner, privacy-policy, schema-evolution, event-taxonomy, roadmap-entropy, bus-factor, knowledge-silo
Options category (13): task-groomer, guide-improver, tech-debt-classify, why-annotator, edge-case-enum, error-msg-improve, slo-suggester, ux-copy-sharpener, a11y-lint, service-advisor, ownership-boundary, oncall-estimator, idea-generator
Safe category (5): migration-rehearsal, contract-fuzzer, golden-path, perf-profile, allocation-profile
Map category (7): visibility-instrument (PR), repo-topology, permissions-mapper, data-lifecycle, feature-flag-monitor, ci-signal-noise, historical-context
Emergency category (3): runbook-gen, rollback-plan, postmortem-gen
Review category (1): code-review — Expert review + fixes using SOLID, security, perf, error handling checklists (references/ directory). Creates PR with fixes.
From nightshift orchestrator.go. Three prompt templates:
Agent analyzes the repo and outputs JSON:
{"steps": ["step1", "step2"], "files": ["file1.go"], "description": "approach"}
Agent executes the plan. On iteration >1, includes review feedback. Outputs JSON:
{"files_modified": ["file1.go"], "summary": "what was done"}
Agent checks correctness. Outputs JSON:
{"passed": true, "feedback": "detailed feedback", "issues": ["issue1"]}
If review fails → back to implement with feedback (max 3 iterations).
| Tier | Tokens | Example Tasks |
|---|---|---|
| low | 10-50k | lint-fix, ci-fixes, readme, changelog |
| medium | 50-150k | bug-finder, dead-code, test-gap, most analysis |
| high | 150-500k | auto-dry, build-optimize, service-advisor |
| very_high | 500k-1M | migration-rehearsal, contract-fuzzer |
python3 ~/nightshift-workspace/glm_quota.py --check
If SKIP → report and stop.
python3 ~/nightshift-workspace/nightshift.py
Parse NIGHTSHIFT_TASKS_START/NIGHTSHIFT_TASKS_END JSON array. Each task has:
"pr" (creates pull request) or "issue" (creates GitHub issue)output_mode = "pr" (21 tasks):
prompt_type = "plan_implement_review":
git -c user.name="Nightshift" -c user.email="contact+nightshift@micr.dev" commit. Must use --head BRANCH_NAME because the main agent's working directory may not be on the feature branch (subagent commits on it).code-review task (plan_implement_review):
output_mode = "issue" (42 tasks):
GH_TOKEN=<NIGHTSHIFT_GH_TOKEN> gh issue create --repo {repo} --title "nightshift: {task_name}" --body {findings_markdown}Git commit author (PR tasks only): Nightshift <contact+nightshift@micr.dev> (use -c user.name="Nightshift" -c user.email="contact+nightshift@micr.dev").
import shutil; shutil.rmtree("{clone_dir}")
For each task: repo, task_name, category, output_mode, result (PR URL / Issue URL / "no changes" / "review failed"). PR tasks should have a PR URL. Issue tasks should have an issue URL.
open.bigmodel.cn, auth: Authorization: <GLM_API_KEY> (no Bearer prefix)GET /api/monitor/usage/quota/limit — returns reset_utc in TOKENS_LIMITreset_utc — not a fixed timeThe GitHub monitor script (~/alive/scripts/github_monitor.py) fetches open [nightshift] PRs and appends them to ~/alive/github/YYYY-MM-DD.md under a "Nightshift PRs" section. This feeds into the daily brief automatically.
Verified working on api.z.ai with the regular GLM_API_KEY. Model ID: glm-5.1. The coding plan supports switching models via Claude Code settings (see https://docs.z.ai/devpack/using5.1).
*/15 * * * * (every 15 min — but only actually runs during burn window)Nightshift <contact+nightshift@micr.dev> (all commits)isFork=truepublic_only=true)max_inactive_days=30)The cron runs every 15 min, but glm_quota.py --check gates execution to a burn window of 5-50 min before the 5h quota reset. This ensures nightshift burns remaining budget right before expiry.
How it works:
glm_quota.py --checkreset_utc from the quota APIThe 5h window resets multiple times per day. The reset time drifts, so fixed cron times don't work — the dynamic approach reads reset_utc from the API each invocation.
true) — only open PRs on public repos. Set to false to include private repos.30) — skip repos with no pushes in the last X days. Uses the pushed_at field from GitHub API. Set to 0 to disable.| File | Purpose |
|---|---|
| solid-checklist.md | SOLID smells + refactor heuristics |
| security-checklist.md | XSS, injection, auth, race conditions, crypto |
| code-quality-checklist.md | Error handling, performance, boundary conditions |
| removal-plan.md | Deletion candidate template |
| react-patterns.md | React anti-patterns: useEffect, images, hooks (Ralph loop inspired) |
| opinionated-patterns.md | Language-agnostic best practices for non-React repos |
Inspired by @humanlayer_dev's Ralph loop pattern: pair each task with a best-practice reference doc, then make one targeted fix per run.
react-patterns.md. Skips non-JS/TS repos.react-patterns.md. Skips non-JS/TS repos.react-patterns.md for JS/TS repos, opinionated-patterns.md for others. Fixes one pattern per run.Tasks that have a reference field also include reference_content in the task JSON output — the cron agent injects this into plan/implement prompts so the subagent has the best-practice guidance inline.
gh pr create requires --head BRANCH_NAME — the main agent runs from a different directory than the subagent that created the branch.git status --porcelain — check git log main..HEAD --oneline instead to verify commits exist.#[allow(dead_code)], unused imports, unreachable code). Then proceed to the check phase or report "no changes" if the codebase is clean.python3 nightshift.py (even --dry-run) times out after 60-120s. Workaround: run --list-tasks separately (works), then manually select repos using gh repo list, check sizes with gh repo view --json diskUsage, git clone each repo yourself, and dispatch tasks via delegate_task. Read ~/.nightshift/state.json to check recent runs and avoid cooldown violations.CMakeLists.txt, go.mod, package.json, Cargo.toml before choosing.output_mode field determines this. PR tasks (21) go through plan→implement→review→commit→PR flow. Issue tasks (42) analyze and create GitHub issues with findings. Do NOT commit files or create branches for issue tasks.tasks array to a single delegate_task call. This runs them concurrently, cutting total time roughly in half (e.g. 2 tasks in ~15 min instead of ~25 min sequential). Only do this for analysis/options tasks or simple PR tasks where you don't need to iterate on results between tasks. Caveat: GLM 5.1 rate limits can cause one parallel task to fail with HTTP 429 while the other succeeds. Recovery: do the failed task's analysis directly (read_file the source files, write the markdown report with write_file, then commit and PR). This fallback is fast and avoids burning another delegate_task call.grep -rn 'path/to/file' --include='*.ts') before deleting one. The file that's actually imported is the canonical one; delete the unreferenced copy. Deleting the wrong one breaks the build.npm install on a pnpm project generates package-lock.json. Always git checkout -- pnpm-lock.yaml package-lock.json before committing, or better: install with pnpm install if available. Check which package manager the project uses (pnpm-lock.yaml vs package-lock.json vs yarn.lock) before running install.set-state-in-effect and immutability rules flag legitimate async data fetching in useEffect. Fix by moving function declarations above useEffect (solves immutability/before-declaration) and adding // eslint-disable-next-line react-hooks/set-state-in-effect on the line BEFORE the violation (not after — the disable must precede the flagged line).allowConstantExport: true does NOT fix re-exports of Radix primitives (export const Dialog = DialogPrimitive.Root). Must fully disable react-refresh/only-export-components for src/components/ui/** files.int() cast) can silently break compilation. Run go build ./... after every patch set before committing.