night-shift
Run the computer while the human sleeps, but keep the loop bounded, auditable, and reversible.
night-shift is an unattended analysis skill. It fans out read-only workers across recently active repositories, captures findings, synthesizes architectural leverage, and produces a morning HTML report. It is not a license to edit production code or burn unlimited model quota.
Core Contract
Every run must have:
- a time box;
- a worker cap;
- a repo cap;
- a provider fallback policy;
- a failure ledger;
- a self-contained HTML report;
- no writes to production code unless the user explicitly starts a follow-up AOSwarm execution phase.
AOSwarm SDLC
Use AOSwarm as the SDLC shape:
- Scout swarm: read-only workers inspect independent repos or domains.
- Synthesis lead: one agent clusters findings, identifies themes, and writes the morning report.
- Human gate: the user reviews the report and chooses follow-up work.
- Execution swarm: approved code-changing work is dispatched through
ao spawn or ao batch-spawn, one PR/MR per task.
- Verification: merged only after normal repo verification and review gates.
The nightly phase is phases 1 and 2 only. Phases 3 to 5 require explicit human approval.
The bundled nightly runner uses direct read-only CLI scouts (claude, codex, gemini) for phases 1 and 2 so it can collect local Markdown artifacts deterministically. Use ao spawn / ao batch-spawn for phase 4 code-changing execution after the human gate.
Worker Types
Run workers as independent scouts. Assign each worker one repo and one lens unless the repo is small.
| Worker |
Looks for |
Output |
| Architecture mapper |
module boundaries, dependency direction, data flow, service boundaries, ownership gaps |
boundary map, coupling risks, missing docs |
| Testability auditor |
missing contracts, brittle fixtures, flaky setup, unverified workflows |
highest-value tests and exact invariants |
| Performance scout |
N+1 queries, redundant IO, cache gaps, bundle size, long jobs |
bottleneck hypotheses and verification commands |
| Tooling/DX auditor |
broken scripts, unclear setup, missing one-command checks |
repo setup friction and script candidates |
| Security/data-flow reviewer |
secrets handling, auth checks, tenant boundaries, unsafe input |
risk scenarios and mitigation candidates |
| Agent-readiness reviewer |
AGENTS.md quality, codebase maps, local commands, acceptance criteria |
what future agents need to move faster |
| Cross-repo pattern miner |
duplicated helpers, divergent APIs, repeated architecture motifs |
consolidation or standardization candidates |
| Research scout |
current docs, GitHub examples, X/Twitter leads, AOSwarm patterns |
verified external ideas and links |
Preflight
Before launching workers:
- Print repo root, output directory, time window, repo cap, worker cap, and provider order.
- Confirm tools when available:
claude, codex, gemini, ao, tmux.
- Ensure at least two default Claude CLI remote-control sessions are running:
ps -axo command | grep -F "claude --remote-control" | grep -v grep
If fewer than two are found and tmux is installed, start missing sessions with the default claude binary:
tmux new-session -d -s agentic-nightly-remote-1 "claude --remote-control agentic-nightly-remote-1"
tmux new-session -d -s agentic-nightly-remote-2 "claude --remote-control agentic-nightly-remote-2"
Record the before/after count in the report.
Repo Selection
Rank repositories by:
- dirty worktree state;
- commits in the selected time window;
- recently modified
.planning, .gsd, .omc, reports, or skill files;
- current branch not being the default branch;
- explicit user-provided repo list.
Skip dependency directories, generated artifacts, archived repos, and repos without readable project context.
Provider Fallback Protocol
Default provider order:
- Claude CLI: best first pass for repo-aware analysis.
- Codex CLI: fallback for hard engineering reasoning and current OpenAI-side availability.
- Gemini CLI: fallback for long-context synthesis and external research.
Use CLIs only. Never call model REST APIs directly.
Rate-limit and failure handling:
- Detect provider failures from exit code plus error text containing
rate limit, quota, overloaded, 429, insufficient_quota, authentication, invalid api key, or usage limit.
- After one failure, retry once with exponential backoff.
- After three consecutive failures for a provider, mark it unavailable for the rest of the run.
- When falling back, reduce concurrency by half for the next provider when the runner supports dynamic throttling; otherwise cap the next run and record the requested lower concurrency.
- If all providers fail, stop launching model workers and produce an evidence-only HTML report.
- Always preserve partial findings. A partial report is better than a hidden failed run.
Do not spin. Do not keep re-authenticating unattended. Do not print secrets.
Worker Prompt Contract
Each worker prompt must include:
- repo path and lens;
- read-only rule;
- explicit files to inspect first;
- max time or max command count;
- output schema;
- "do not modify files";
- "do not run network or credentials-heavy commands unless the prompt says so";
- fallback instruction: if blocked, write what was checked and what evidence is missing.
Worker output schema:
# <repo> - <lens>
## Highest-Leverage Finding
<one paragraph>
## Evidence
- <file/command/log references>
## Architecture or Workflow Insight
<compound lesson>
## Follow-Up AOSwarm Candidate
<prompt-ready task, or "none">
## Verification Command
<command or "not applicable">
## Confidence
High | Medium | Low, with reason
Morning HTML Report
Write outputs to:
reports/nightly/YYYY-MM-DD/
index.html
dreaming.md
night-shift-summary.md
workers/
<repo>-<lens>.md
run.json
index.html must be self-contained, light-mode, and open automatically at the end of the run on macOS with open <path> unless disabled.
Required report sections:
- Run status: completed, partial, or failed.
- Provider health: Claude, Codex, Gemini availability, fallbacks used, rate limits.
- Claude remote-control health: before count, after count, sessions started.
- Repo coverage: selected repos, skipped repos, reason.
- Top insights: cross-repo compound findings.
- Architecture findings: grouped by repo and severity.
- AOSwarm queue: candidate
ao spawn or ao batch-spawn prompts, gated for human approval.
- Research leads: docs, GitHub, X/Twitter categories worth studying, with verification status.
- Failure ledger: every partial or failed worker.
X/Twitter Study Categories
Use X/Twitter only as a discovery index. Study these categories, then verify elsewhere:
- Karpathy-style autoresearch loops: editable surface, locked metric, results log, keep/revert.
- Parallel experiment waves: many hypotheses per decision instead of serial hill-climbing.
- Worktree-isolated coding agents: separate branches/worktrees to prevent file collisions.
- Reflection/heartbeat loops: agents summarize progress and recover from crashes or compaction.
- Strategy evolution:
program.md, strategy.md, results.tsv, and prompt-as-parameter systems.
- Non-ML transfers: growth, market analysis, prompt optimization, product architecture, backtesting.
- Goodhart defenses: independent evaluators, anti-reward-hacking checks, evaluator audits.
- Human approval gates: morning review before ticket creation or code execution.
- Knowledge stores: markdown memories, BM25/vector retrieval, and curated reusable lessons.
What Not To Do
- Do not run destructive commands.
- Do not push, merge, deploy, or create tickets unattended.
- Do not let workers edit code in the main checkout.
- Do not run unlimited workers because the machine is idle.
- Do not trust X/Twitter claims without verification.
- Do not hide rate-limit failures; they belong in the report.
Completion Criteria
A night-shift run is complete when:
- at least one scout worker or evidence-only scan has run;
- provider and Claude remote-session health are recorded;
- partial failures are captured;
- a morning HTML report exists and opens;
- AOSwarm follow-up candidates are prompt-ready but not dispatched without approval.
1---2name: night-shift3description: Run a bounded overnight AOSwarm-style analysis across recently active repos, using isolated workers to inspect architecture, tests, tooling, performance, safety, and agent-readiness, then synthesize a self-contained morning HTML report. Use for unattended nightly work blocks, architecture review swarms, cross-repo improvement mining, and robust fallback execution across Claude, Codex, and Gemini.4---56# night-shift78Run the computer while the human sleeps, but keep the loop bounded, auditable, and reversible.910`night-shift` is an unattended analysis skill. It fans out read-only workers across recently active repositories, captures findings, synthesizes architectural leverage, and produces a morning HTML report. It is not a license to edit production code or burn unlimited model quota.1112## Core Contract1314Every run must have:1516- a time box;17- a worker cap;18- a repo cap;19- a provider fallback policy;20- a failure ledger;21- a self-contained HTML report;22- no writes to production code unless the user explicitly starts a follow-up AOSwarm execution phase.2324## AOSwarm SDLC2526Use AOSwarm as the SDLC shape:27281. Scout swarm: read-only workers inspect independent repos or domains.292. Synthesis lead: one agent clusters findings, identifies themes, and writes the morning report.303. Human gate: the user reviews the report and chooses follow-up work.314. Execution swarm: approved code-changing work is dispatched through `ao spawn` or `ao batch-spawn`, one PR/MR per task.325. Verification: merged only after normal repo verification and review gates.3334The nightly phase is phases 1 and 2 only. Phases 3 to 5 require explicit human approval.3536The bundled nightly runner uses direct read-only CLI scouts (`claude`, `codex`, `gemini`) for phases 1 and 2 so it can collect local Markdown artifacts deterministically. Use `ao spawn` / `ao batch-spawn` for phase 4 code-changing execution after the human gate.3738## Worker Types3940Run workers as independent scouts. Assign each worker one repo and one lens unless the repo is small.4142| Worker | Looks for | Output |43|---|---|---|44| Architecture mapper | module boundaries, dependency direction, data flow, service boundaries, ownership gaps | boundary map, coupling risks, missing docs |45| Testability auditor | missing contracts, brittle fixtures, flaky setup, unverified workflows | highest-value tests and exact invariants |46| Performance scout | N+1 queries, redundant IO, cache gaps, bundle size, long jobs | bottleneck hypotheses and verification commands |47| Tooling/DX auditor | broken scripts, unclear setup, missing one-command checks | repo setup friction and script candidates |48| Security/data-flow reviewer | secrets handling, auth checks, tenant boundaries, unsafe input | risk scenarios and mitigation candidates |49| Agent-readiness reviewer | AGENTS.md quality, codebase maps, local commands, acceptance criteria | what future agents need to move faster |50| Cross-repo pattern miner | duplicated helpers, divergent APIs, repeated architecture motifs | consolidation or standardization candidates |51| Research scout | current docs, GitHub examples, X/Twitter leads, AOSwarm patterns | verified external ideas and links |5253## Preflight5455Before launching workers:56571. Print repo root, output directory, time window, repo cap, worker cap, and provider order.582. Confirm tools when available: `claude`, `codex`, `gemini`, `ao`, `tmux`.593. Ensure at least two default Claude CLI remote-control sessions are running:6061```bash62ps -axo command | grep -F "claude --remote-control" | grep -v grep63```6465If fewer than two are found and `tmux` is installed, start missing sessions with the default `claude` binary:6667```bash68tmux new-session -d -s agentic-nightly-remote-1 "claude --remote-control agentic-nightly-remote-1"69tmux new-session -d -s agentic-nightly-remote-2 "claude --remote-control agentic-nightly-remote-2"70```7172Record the before/after count in the report.7374## Repo Selection7576Rank repositories by:77781. dirty worktree state;792. commits in the selected time window;803. recently modified `.planning`, `.gsd`, `.omc`, reports, or skill files;814. current branch not being the default branch;825. explicit user-provided repo list.8384Skip dependency directories, generated artifacts, archived repos, and repos without readable project context.8586## Provider Fallback Protocol8788Default provider order:89901. Claude CLI: best first pass for repo-aware analysis.912. Codex CLI: fallback for hard engineering reasoning and current OpenAI-side availability.923. Gemini CLI: fallback for long-context synthesis and external research.9394Use CLIs only. Never call model REST APIs directly.9596Rate-limit and failure handling:9798- Detect provider failures from exit code plus error text containing `rate limit`, `quota`, `overloaded`, `429`, `insufficient_quota`, `authentication`, `invalid api key`, or `usage limit`.99- After one failure, retry once with exponential backoff.100- After three consecutive failures for a provider, mark it unavailable for the rest of the run.101- When falling back, reduce concurrency by half for the next provider when the runner supports dynamic throttling; otherwise cap the next run and record the requested lower concurrency.102- If all providers fail, stop launching model workers and produce an evidence-only HTML report.103- Always preserve partial findings. A partial report is better than a hidden failed run.104105Do not spin. Do not keep re-authenticating unattended. Do not print secrets.106107## Worker Prompt Contract108109Each worker prompt must include:110111- repo path and lens;112- read-only rule;113- explicit files to inspect first;114- max time or max command count;115- output schema;116- "do not modify files";117- "do not run network or credentials-heavy commands unless the prompt says so";118- fallback instruction: if blocked, write what was checked and what evidence is missing.119120Worker output schema:121122```markdown123# <repo> - <lens>124125## Highest-Leverage Finding126<one paragraph>127128## Evidence129- <file/command/log references>130131## Architecture or Workflow Insight132<compound lesson>133134## Follow-Up AOSwarm Candidate135<prompt-ready task, or "none">136137## Verification Command138<command or "not applicable">139140## Confidence141High | Medium | Low, with reason142```143144## Morning HTML Report145146Write outputs to:147148```text149reports/nightly/YYYY-MM-DD/150 index.html151 dreaming.md152 night-shift-summary.md153 workers/154 <repo>-<lens>.md155 run.json156```157158`index.html` must be self-contained, light-mode, and open automatically at the end of the run on macOS with `open <path>` unless disabled.159160Required report sections:1611621. Run status: completed, partial, or failed.1632. Provider health: Claude, Codex, Gemini availability, fallbacks used, rate limits.1643. Claude remote-control health: before count, after count, sessions started.1654. Repo coverage: selected repos, skipped repos, reason.1665. Top insights: cross-repo compound findings.1676. Architecture findings: grouped by repo and severity.1687. AOSwarm queue: candidate `ao spawn` or `ao batch-spawn` prompts, gated for human approval.1698. Research leads: docs, GitHub, X/Twitter categories worth studying, with verification status.1709. Failure ledger: every partial or failed worker.171172## X/Twitter Study Categories173174Use X/Twitter only as a discovery index. Study these categories, then verify elsewhere:175176- Karpathy-style autoresearch loops: editable surface, locked metric, results log, keep/revert.177- Parallel experiment waves: many hypotheses per decision instead of serial hill-climbing.178- Worktree-isolated coding agents: separate branches/worktrees to prevent file collisions.179- Reflection/heartbeat loops: agents summarize progress and recover from crashes or compaction.180- Strategy evolution: `program.md`, `strategy.md`, `results.tsv`, and prompt-as-parameter systems.181- Non-ML transfers: growth, market analysis, prompt optimization, product architecture, backtesting.182- Goodhart defenses: independent evaluators, anti-reward-hacking checks, evaluator audits.183- Human approval gates: morning review before ticket creation or code execution.184- Knowledge stores: markdown memories, BM25/vector retrieval, and curated reusable lessons.185186## What Not To Do187188- Do not run destructive commands.189- Do not push, merge, deploy, or create tickets unattended.190- Do not let workers edit code in the main checkout.191- Do not run unlimited workers because the machine is idle.192- Do not trust X/Twitter claims without verification.193- Do not hide rate-limit failures; they belong in the report.194195## Completion Criteria196197A `night-shift` run is complete when:198199- at least one scout worker or evidence-only scan has run;200- provider and Claude remote-session health are recorded;201- partial failures are captured;202- a morning HTML report exists and opens;203- AOSwarm follow-up candidates are prompt-ready but not dispatched without approval.