Skip to content

About

A personal coding agent that sleeps on a Fly.io Sprite, wakes when you label an issue, and merges only on your /merge.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Night Shift

A coding agent that works your issues at night and asks before it merges.

CI License: MIT

Night Shift

Night Shift is a personal coding agent that sleeps on a Fly.io Sprite, wakes when you label a GitHub issue, and turns it into a tested pull request. It asks you once, and merges only on your /merge.

Built for Fly.io's Hacksgiving 2026. Plain JavaScript for Node 22 or later, no npm dependencies.

Demo

night-shift-demo.mp4

A real run on 27 November 2026 against xgame92/night-shift-demo, with nothing staged:

  • Issue #12 asked for digits to stay in slugs. From the label to a tested pull request took 33 s, and to the question 36 s: the coder ran for 11 s and the tests for 1.1 s. The second reader listed no problems, and the pull request merged 5 s after the /merge comment from the owner's account.
  • Issue #13 asked for slugs of exactly maxLength characters, which the repository's own tests forbid, and said not to change the tests. The coder changed nothing in either attempt and said why. Night Shift restored the checkpoint after each attempt (the next checkpoint came 15 s after the failure, the Sprite's restore and restart included), gave up after 46 s and wrote down what it learned instead of opening a pull request.

What it does

flowchart TD
    A["You label an issue"] --> B["Signed webhook to the Sprite's public URL"]
    B --> C["Claim: the issue is read again on GitHub"]
    C --> D["Checkpoint"]
    D --> E["Coder makes the change"]
    E --> F{"Tests pass?"}
    F -->|no| G["Record the lesson, then restore the checkpoint"]
    G -->|try again| D
    F -->|yes| H["Second reader lists problems"]
    H --> I["Pull request"]
    I --> J["Ask you once"]
    J -->|"/merge"| K["Squash-merge the head you were shown"]
    J -->|"/close"| L["Close, delete the branch, record the lesson"]
Loading
  1. You label an issue. GitHub's signed webhook wakes the Sprite. Night Shift checks the signature, then reads the issue again on GitHub before it claims it.
  2. It takes a checkpoint, has a coding agent make the change in a fresh working copy, and runs the repository's tests.
  3. A failed attempt is undone by restoring the checkpoint. What it learned survives in the issue thread, which is Night Shift's log.
  4. A model of another family reads the diff and lists problems. It never approves.
  5. It opens a pull request and asks you once. Your yes merges it. Your no closes it.

Sprites features it uses

Checkpoints and restore

Before each attempt Night Shift takes a checkpoint (sprite-env checkpoints create), and a second one once the tests pass. When an attempt fails, it posts the lesson to the issue first, then restores the checkpoint.

A restore rolls back the Sprite's disk: the working copy, the saved change, Night Shift's local journal and anything else the coder wrote there. It also restarts the environment, so every process ends. It does not undo GitHub. The lessons in the issue thread survive, and the next attempt reads them.

The service

setup creates the service with sprite-env services create night-shift --cmd node --args <path>/bin/night-shift.js,serve --http-port 8080. Sprites runs night-shift serve and sends the Sprite's URL to port 8080. While an issue is worked, Night Shift holds a Sprites task, so the Sprite stays awake; it ends the task before a restore. A Sprite sleeps when no request is open, so Night Shift takes a keep-awake task before it answers a webhook and ends it when the work is done.

Gateway connectors

  • No key on the Sprite. Night Shift finds each connector's base URL with GET /v1/gateway/list and calls https://api.sprites.dev/v1/gateway/<provider>/<connection_id>/.... Its own calls, the list included, send no Authorization header: the gateway knows which Sprite is calling and adds the stored key.
  • Claude Code needs some token, so it gets the placeholder sprites-gateway with the connector's base URL. The gateway replaces the placeholder with the real key.
  • OpenRouter. On our account the dashboard offered only a bring-your-own-key OpenRouter connector. A managed OpenRouter connector works too: Night Shift finds the connector by its provider name.
  • GitHub, OAuth. The connector acts as your own GitHub account.
  • Label-scoped access policy. Each connector serves only Sprites with the label night-shift.
  • Endpoint allow and block lists. The GitHub connector allows only the issues, pull requests and Git data of one repository, and blocks direct writes to main's ref. The pull request merge endpoint stays allowed, because that is how Night Shift merges on your /merge. From our Sprite, the repository root, its hooks, environments, Actions secrets, invitations and contents, /user and another repository all answered 403, and so did a PATCH to git/refs/heads/main.

Public URL with signed webhooks

The Sprite's URL is public, because GitHub cannot send a Sprites token. The signature is the gate: a delivery needs a valid X-Hub-Signature-256, an HMAC-SHA256 of the raw body with the webhook secret, compared in constant time. Anything else gets 401. Delivery ids are kept on the Sprite's disk, so a restore forgets the ids recorded after its checkpoint. A repeated delivery is still harmless, because Night Shift reads GitHub again before it acts.

Run your own

You need a Sprite, a GitHub repository, and your own keys for the model providers.

1. Connectors

Create these connectors in the Sprites dashboard. Night Shift reaches each one at https://api.sprites.dev/v1/gateway/<provider>/<connection_id>/... and sends no Authorization header, because the gateway knows which Sprite is calling.

Connector What it holds
GitHub OAuth for your own GitHub account.
OpenRouter Your own OpenRouter key, or a managed OpenRouter connector if your account offers one. Night Shift finds it by the provider name openrouter.

With your own key, give the connector a normal inference key with a spend limit. A management key cannot run models, and through the gateway it would let any process on the Sprite manage your keys.

The GitHub connector acts as you. Night Shift's pull request and comments are posted under your login, and so are your own. The GitHub OAuth grant covers your whole account, so narrow it.

2. The policy JSON

Each connector's access policy names the sprite label night-shift, and Night Shift's Sprite carries that label. For the GitHub connector, also set an endpoint allow-list through the Sprites API. A block list always misses something, so the allow-list names only what Night Shift's code calls: issues and their comments, pull requests and their merge, and the Git data API for refs, commits, trees and blobs. Nothing else is reachable:

{
  "access_policy": {
    "sprite_labels": ["night-shift"],
    "allowed_endpoints": [
      "/repos/OWNER/REPO/issues", "/repos/OWNER/REPO/issues/*",
      "/repos/OWNER/REPO/pulls", "/repos/OWNER/REPO/pulls/*",
      "/repos/OWNER/REPO/git/*"
    ],
    "blocked_endpoints": ["/repos/OWNER/REPO/git/refs/heads/main"]
  }
}

The block keeps the agent from moving or deleting main directly; main still moves when a pull request is merged on your /merge. Use your repository's default branch name. Send it with PUT /v1/oauth/connections/<connection_id>, for example with sprite api. Block rules are checked before allow rules. For the model connector, the policy is the label and a block on key management:

{ "access_policy": { "sprite_labels": ["night-shift"], "blocked_endpoints": ["/v1/keys", "/v1/keys/*", "/v1/byok", "/v1/byok/*"] } }

Then check from the Sprite, through the gateway:

  • 200: the issue list with a query string, one issue and its comments, the pull list and one pull, git/ref/heads/main, and the model list.
  • 403: the repository root, hooks, environments, actions/secrets, invitations and contents, /user, another repository, and the model connector's /v1/keys and /v1/byok.
  • 403 for a PATCH to git/refs/heads/main.

3. setup

On the Sprite, in a checkout of this repository:

node bin/night-shift.js setup --repo OWNER/REPO --owner-login YOUR_LOGIN --url https://YOUR_SPRITE_URL \
  --coder-model anthropic/claude-sonnet-5.5 --reader-model openai/gpt-5.6-luna

node bin/night-shift.js setup --help lists every option, and node src/setup.js ... runs the same code. setup:

  • makes ~/.night-shift/webhook-secret: 32 random bytes as hex, mode 600, with no trailing newline. It is never printed, and a second run keeps it.
  • writes ~/.night-shift/config.json. It holds no secret. Both paths are resolved to absolute paths on the Sprite, whatever the working directory is.
  • creates the service with sprite-env services create night-shift ... --http-port 8080.
  • prints the webhook URL and a command that gives GitHub the secret over a pipe, so it never shows on screen. The command runs on your machine: sprite exec makes the Sprite run node to read the secret file by its absolute path and trim it at both ends, as the signature check does, so gh receives exactly the hex that the signature check uses. It leaves active out, because a webhook is active by default. Make the Sprite's URL public: GitHub cannot send a Sprites token, so the signature check is the gate. The command subscribes the webhook to the issues and issue_comment events.

On the first setup, pass --coder-model and --reader-model. The models must be of different families. The defaults are anthropic for the coder and openai for the reader. Repeat setup keeps saved settings. When you change a model's provider, also set its family. Set --coder-kind if you switch coder binaries. Use --coder-base-url https://… to pin the coder's model endpoint. Supply it again when you change coder kind. To clear the pin by hand, remove coder.baseUrl from config.json.

4. doctor

node bin/night-shift.js doctor fails when a key-shaped value sits in the environment, or when a coding agent is signed in on the Sprite. Never sign claude or codex in there: their credentials would stay in the Sprite and in its checkpoints. Where a tool needs a key variable, use the placeholder sprites-gateway.

Then label an issue.

How the ask works

GitHub is the truth, and a webhook is only a hint to look. Before Night Shift claims an issue, it reads the issue again: it must be open, carry the label and not be a pull request. A webhook about a comment makes Night Shift read the pull request's comments on GitHub, but only when the signed payload passes the first filters: a new comment on a pull request in the configured repository, written and sent by you, that holds a command. The command is then taken from GitHub, never from the webhook body. If GitHub cannot be read, nothing is claimed and nothing is merged.

Night Shift asks once for each pull request, whatever its head is by then. The ledger comes first: an asked marker on the issue is checked before anything is posted, so a restart or a second wake posts nothing more. If the Sprite dies after the ask went out but before its marker was written, the retry finds the comment that already went out by its hidden last line, which carries the head that was asked about. The marker records that head, never the pull request's current one, so a push in between cannot slip past your answer. A push after the ask does not trigger a second ask.

The ask is one comment on the pull request that mentions you. It says:

  • what changed and what ran, including failed attempts that were rolled back
  • what the second reader listed, with the words "This is not an approval"
  • how to answer

Answer in one of these ways:

  • Comment /merge on the pull request. Night Shift squash-merges it, pinned to the head it asked about.
  • Comment /close. Night Shift closes the pull request and deletes its branch. It records the decline and a lesson only after it has checked that the branch is gone. If GitHub answers 422 and a read shows the branch is still there, Night Shift says so in a note, and tries again when you answer again. Any other failure, such as a 403, gets no note: the command stays unanswered and is tried again on the next check. A reason after /close goes into the lesson; it is a public comment already.

If the head moved after the ask, nothing is merged, and Night Shift comments that a new ask is needed. This version has no command that asks again, so merge such a pull request yourself or answer /close.

Which answer counts:

  • It comes from your login, and its first non-empty line (lines end at CRLF, LF, CR, U+2028 or U+2029; surrounding whitespace and letter case do not matter) is one of these:

    • /merge alone merges. The lines below it change nothing.
    • /merge followed by whitespace and more text (/merge later) is answered and not carried out: Night Shift posts a note that starts with "Not merged:", says a merge needs /merge alone on the first line and that nothing was done, and names that comment, so it is not used again.
    • /close closes when it stands alone or is followed by whitespace and more text (/close too thin). The rest of its line and the lines below, except quoted (>) lines, are your reason.
    • Anything else (/merged, /merge., /merge?) is not a command and is ignored.

    Night Shift's own comments come from the same login, but none of them starts with a command, and each ends with a hidden marker line.

  • It is newer than the ask, and newer than every command Night Shift has already answered. When a command cannot be carried out (the head moved, GitHub refused the merge), Night Shift says so in a note that names that command, so it is never used again. If there are several new commands, the newest one counts.

  • It survives a restart. The same check runs after a comment webhook that passed the first filters, at start-up, and right after the ask is recorded. The start-up scan looks at every asked pull request that has no final entry yet (merged, declined or gave up) and whose issue is still open and still carries the label. So an answer posted while the service was down, or before the ask was recorded, is still found.

  • After a restore, the service takes no new work and writes nothing until it restarts. A webhook that arrives then gets 503 and is not recorded as handled. The start-up check finds the answer anyway.

The GitHub connector acts as your own account, so GitHub sends you no notification for Night Shift's comments, and the mention in the ask does not notify you either. Watch the pull request.

Email is planned, not shipped. A later version may send the ask by mail and take a reply as the answer. Today the comment is the only way to ask, and /merge and /close are the only answers.

Safety model

  • The webhook secret is the only secret on the Sprite. Every key stays in a Sprites connector.
  • The coder can run any code, because the tests it runs are code it may change. So the coder and every test run go through one sandbox. It runs them as the dedicated user night-shift-coder, in new network and mount namespaces:
    • Network: loopback only. The model is reached through a proxy that Night Shift holds. A small bridge inside the sandbox listens on 127.0.0.1 and pipes to the proxy's Unix socket. The proxy forwards only to the model connector's base URL. It refuses any other path, absolute-form targets and CONNECT, and drops the coder's Authorization header, because the gateway adds the key. Test runs get no bridge, and an empty tmpfs covers the proxy's socket directory, so they cannot reach the proxy at all.
    • Files: the coder cannot read the webhook secret or the config. Working copies live outside the service user's home, in /var/lib/night-shift/workspaces. The coder writes there, but .git stays Night Shift's, so the coder cannot plant a hook or a setting that git would run as Night Shift.
    • The Sprite: the management socket /.sprite/api.sock is masked with /dev/null, and /run and the Sprite's other mounts get a fresh tmpfs.
    • Privileges: no supplementary groups and no new privileges, so sudo fails. The environment is built from nothing: the coder's HOME, a PATH, and only the variables Night Shift passes on purpose.
  • So the coder cannot call the GitHub connector, the merge endpoint included, cannot read the webhook secret, and cannot use the management socket. Night Shift merges only on your /merge.
  • setup does the one-time work with sudo, and can be run again. It creates the user, copies the configured coder's binary (claude or codex) into /opt/night-shift/bin and creates the workspace root. It writes nothing as root inside the coder's home: the coder's git config is written as the coder. Run it again after you update that binary: doctor says when the copy is older.
  • It fails closed. At start-up serve runs a self-test through the sandbox, and refuses to start unless every check holds: the secret and the config cannot be read, only loopback interfaces exist and api.sprites.dev:443 cannot be reached, the management socket does not answer, sudo -n true fails, a request through the bridge reaches the proxy, no mount is shared with the host, the Sprite's mounts are empty tmpfs, there are no supplementary groups, and no new privileges can be gained. The answer counts only from a self-test that exited cleanly. doctor prints each check with its result.
  • A second serve never takes over the proxy socket of one that is running, and a serve that cannot start closes the proxy it opened.
  • The sandbox setting is on by default on Linux and cannot be turned off there. On other platforms the sandbox cannot run, so it is off, for development only, and serve logs a warning.
  • GitHub, not the webhook, still decides what is claimed and what is merged.
  • Comments, titles, bodies and commit messages are cleaned of the secret and key-shaped values. File content and paths are never rewritten; one that holds the exact secret is refused. This only guards against accidental leaks.
  • What is left:
    • the coder can still spend the model budget through the proxy;
    • the change itself is untrusted, so the second reader and you review it before your /merge;
    • a kernel escape is out of scope.
  • npm test uses fakes only. npm run test:sandbox runs the real sandbox on Linux with passwordless sudo; CI runs it on its Ubuntu runner.
  • The full threat model is in AGENTS.md.

Development

npm test

The tests use fakes only: no Sprite, no network, no keys. See AGENTS.md for the layout and the contracts between modules.

Author

Yiğit Tanrıverdi (@xgame92)

License

MIT

About

A personal coding agent that sleeps on a Fly.io Sprite, wakes when you label an issue, and merges only on your /merge.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages