Nightshift Factory: Install, Source and Security

Nightshift Factory

Published by tenjin-tech in nightshift-skills

Review recommended6 installs

What this skill does

Run the Night Shift factory for this repository - claim its background jobs, hand each to the minion for its role, deliver any edits as a pull request, and report results until nothing is left. Use for /nightshift-factory, $nightshift-factory, "start factory", or "run Night Shift".

Add Nightshift Factory to your agent

Review the source and files first. When you are ready, copy the prompt instruction or use the CLI command supported by your environment.

Install with a prompt

Paste this into a compatible coding agent:

add this skill "nightshift-factory" from https://github.com/tenjin-tech/nightshift-skills

Install with the CLI

Run this command in a controlled environment after reviewing the repository:

npx skills add https://github.com/tenjin-tech/nightshift-skills --skill nightshift-factory

Skill instructions

Night Shift hands out background jobs for AI agents. When asked to "start factory" (or run Night Shift), use the Night Shift MCP tools check_in, next_assignment, log_step and finish_assignment, from the nightshift server or the Night Shift connector. When both are connected, use the connector: it is signed in with GitHub, so the factory can merge merge = "auto" pull requests, which it cannot do for the access key. If they are missing but NIGHTSHIFT_TOKEN is set (Codex cloud loads no MCP server), call each tool over HTTP instead, with this shell function, its name as $1 and its arguments as a JSON object in $2:

ns() { curl -sS "${NIGHTSHIFT_URL:-https://nightshiftfactory.com}/mcp/" -H "Authorization: Bearer $NIGHTSHIFT_TOKEN" -H "Accept: application/json, text/event-stream" -H "Content-Type: application/json" -d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"$1\",\"arguments\":$2}}"; }

The tool's answer is the text of result.content; an error, or result.isError, is the tool failing. If neither the tools nor NIGHTSHIFT_TOKEN are there, stop and report that the server is not connected: check that the routine has the Night Shift connector, or that .mcp.json (Claude Code) or .codex/config.toml (Codex) lists nightshift and NIGHTSHIFT_TOKEN is set.

Reach GitHub with git and gh api (its REST API): cloud sessions reject GitHub's GraphQL API, which gh pr and gh issue use. <owner>/<repo> comes from git remote get-url origin, and N is the number at the end of a pull request URL. If the checkout has no origin remote (Codex cloud clones without one), run the git remote add origin command your prompt gives, if it gives one (the factory's own Codex starts do, with the command that sets origin/HEAD for default_branch); otherwise stop and report it: add git remote add origin <the repository's clone URL> to the environment's setup script.

  • PR state: gh api repos/<owner>/<repo>/pulls/N --jq '{state: (if .merged then "merged" else .state end), merge_commit: (if .merged then .merge_commit_sha else null end), mergeable_state, head: .head.sha, branch: .head.ref, base: .base.ref}'. state is open, merged or closed.
  • Failing checks on an open PR's head, through the Actions API, since the factory's token cannot read check runs: gh api "repos/<owner>/<repo>/actions/runs?head_sha=<head>&per_page=100" --jq '.workflow_runs | group_by(.workflow_id) | map(max_by(.run_number))[] | [.status, .conclusion, .name] | @tsv', each workflow's latest run, since a later run supersedes one it cancelled. While any run's status is not completed, the checks are still running. Otherwise the failing ones are the runs whose conclusion is failure, timed_out, cancelled, action_required or startup_failure.
  • Open a PR, in exactly this form: gh api repos/<owner>/<repo>/pulls -f title='<title>' -f head=<branch> -f base=<base branch> -F body=@- --jq .html_url <<'NIGHTSHIFT_BODY_<run_id>', then the body on the following lines and a last line NIGHTSHIFT_BODY_<run_id>, so no line of the report can end it early. Drop any ' from the title. The quoted heredoc keeps the shell from running a backtick or $(...) in the report, and an unattended Claude Code session only opens the pull request through the permission rule /nightshift-setup installs, which matches this text. Change nothing else, since each of these misses the rule: no cd ... &&, GH_TOKEN= or other command in front, no --method POST or -X POST (-f already makes it a POST), no other option, nothing after <<'NIGHTSHIFT_BODY_<run_id>' on its line, and the body only through that quoted heredoc (never $(...), a file or an unquoted heredoc). If it is refused, never retry it in another form: log delivery_failed with its first line exactly as you ran it, whole except any token or other secret value replaced by [redacted], and the refusal.
  • Label a PR, when the assignment has pr_labels: right after Open a PR printed its URL, in exactly this form, one -f per label: gh api repos/<owner>/<repo>/issues/<N>/labels -f 'labels[]=<label>'. Use the same gh sign-in that opened the pull request, never a workflow's GITHUB_TOKEN: events it creates start no other workflow, so a CI run waiting for the label would never start. An unattended Claude Code session runs it through the permission rule /nightshift-setup installs for a repository that sets pr_labels.
  1. Check in this checkout's committed jobs, so the factory runs this commit's .nightshift/ (like GitHub Actions reading .github/workflows/). Call check_in with:
    • repository: git remote get-url origin; commit: git rev-parse HEAD; branch: git rev-parse --abbrev-ref HEAD;
    • remote_branches: git branch -r --points-at HEAD, each without the origin/ prefix, skipping origin/HEAD -> ...;
    • default_branch: git symbolic-ref --short refs/remotes/origin/HEAD without the origin/ prefix; if that fails (a clone without origin/HEAD), gh api repos/<owner>/<repo> --jq .default_branch, and main only if that fails too;
    • trees: .nightshift: git rev-parse HEAD:.nightshift, so the factory can check the files are complete; and for each job's scope and watch paths, git rev-parse HEAD:<path>, or git rev-parse HEAD^{tree} for .. Send only ids these commands printed, never a placeholder; if one fails, stop and report it;
    • files: leave out at first: when you are signed in with GitHub, the factory reads .nightshift/ at this commit from GitHub itself. Only if check_in answers that it cannot read it (access key, or a commit not pushed), call again with every path from git ls-tree -r --name-only HEAD .nightshift and its exact content from git show HEAD:<path>, whole and unchanged (trailing newline included);
    • activate_branch: true only when the user asked to run this branch's jobs;
    • worker_name, agent and place: as in step 2, so a job that prefers your agent waits for your turn.
    • skill_version: 7, this skill's version, so the factory can flag a copy too old for it.
    • pull_requests: on the first call, none. check_in returns waiting_on, the pull requests write jobs opened that are still open, or merged ones whose packages wait for a checkout that contains the merge. If it lists any, read each one's PR state and call check_in once more with the same arguments plus pull_requests: one {url, state, merge_commit, in_checkout} per pull request, where in_checkout is whether git merge-base --is-ancestor <merge_commit> HEAD succeeds; for an open one, add its head, branch and base, and failing_checks, the names of its failing checks (leave it out while the checks are still running). A failing check queues a follow-up that fixes it. Leave out a pull request gh cannot read. Do not repeat this: waiting_on still lists open pull requests and merged ones not yet used. The factory activates the jobs when this commit is the latest commit of the repository's jobs branch on GitHub (its default branch unless changed in Settings), whatever this checkout's branch is called, so a session on its own branch cut from it (like claude/... in the cloud) runs them. Otherwise check_in returns active false with the reason and only validates them, and next_assignment hands out the jobs branch's jobs. If check_in fails, stop and report its error. If there is no .nightshift/ folder, still check in with files {} and trees {".nightshift": "4b825dc642cb6eb9a060e54bf8d69288fbee4904"} (Git's empty folder), so the factory drops jobs this repository no longer has. Minions work on this checkout, so only claim jobs that match it: when check_in returns active false, stop after it, report its reason and say to start a pass (/nightshift-factory) on the latest commit of the jobs branch.
  2. Call next_assignment with skill_version set to 7 and worker_name set to your agent and model (for example "claude-code sonnet" or "codex gpt-6.1"), agent set to claude (Claude Code) or codex (Codex), so you only claim jobs your agent may run, place set to cloud in a provider's sandbox (a Claude cloud session, where CLAUDE_CODE_REMOTE is true, or a Codex cloud task, where CAAS_IMAGE_VERSION is set), else computer (a machine a person owns, a VPS included), so Control Room shows a pass started on someone's computer as that computer, not as a cloud machine, labels set to $NIGHTSHIFT_LABELS split on commas and trimmed (leave it out when unset), so jobs with runs_on only go to the routines meant for them, repository set to the current checkout's origin remote (git remote get-url origin), so you only claim jobs for the repository you can read, commit set to the commit you checked in, so a job that needs a merged pull request only runs on a checkout that contains it, and skip set to the job ids you already finished in this session, so a failed job is not handed out again until the next session (step 6 says when a completed one leaves it). Send usage too, read fresh before each call, so jobs with priority = "if_budget", "optional" or "leftover" only spend allowance that is left: account is $NIGHTSHIFT_ACCOUNT when set, else anthropic (Claude Code) or openai (Codex); windows is each limit window you can read, with its name, used_percent (0-100) and resets_at (ISO time):
    • Codex: the last "rate_limits" line of the newest ~/.codex/sessions/*/*/*/rollout-*.jsonl; its primary and secondary give used_percent, window_minutes (300 is "5 hours", 10080 is "7 days") and resets_at (Unix seconds).
    • Claude Code: ~/.claude/rate-limits.json, if a status line saves its rate_limits there; its five_hour ("5 hours") and seven_day ("7 days") give used_percentage and resets_at (Unix seconds). Never guess a reading: if there is none, send the account with no windows. The factory then uses the account's last reading until its window resets; with none, optional and leftover jobs wait, and the reason says so. If it returns nothing_to_do, check step 6 first: when it does not start another round, stop and summarize the waiting reasons, as in "Reporting" below.
  3. When the assignment has follow_up, first prepare its existing PR branch as Reworking a PR below says. Then hand the assignment to its minion: the agent whose name is the assignment's role. Start it on the assignment's model and effort, whatever this session's model and the agent's own model: are; the factory already chose model for your agent. In Claude Code, call Agent with subagent_type set to the role, model set to the assignment's model when it is haiku, sonnet, opus or fable, or to the family a full model id names (claude-opus-5-5: opus), and effort set to the assignment's effort. In Codex, call spawn_agent with the custom agent of that name, fork_turns set to "none", so the minion starts with only its assignment, like a Claude Code subagent (the default copies this session's history, earlier assignments included), model set to the assignment's model when it is a full model id, or when it is a family (luna, terra, sol, astra) to the newest model of that family among the models it lists (highest version: gpt-6.1-sol before gpt-6-sol), and reasoning_effort set to the assignment's effort; if it lists no such model, leave model out. With no model or no effort in the assignment (an older factory), leave that one out. Only if there is no agent of that name, use a fresh subagent on the same model and effort, held to the same limits; if you cannot start subagents, do it yourself. For a follow_up, its prompt starts with the original follow_up.report, the conversation so far (follow_up.earlier) and the human's follow_up.body: revise that existing change, never pick new work or create another tracker issue. For a reply, a person answered a proposal this job made and is waiting: its prompt starts with the proposal (reply.title, reply.evidence, reply.acceptance_criteria), the conversation so far (reply.earlier) and their message (reply.body). Tell the minion to answer that message and do nothing else its instructions give: read what it needs, edit files inside scope_path only when the message changes them, and write its report as the answer, in plain words, for the person reading it next to the proposal. If the message changes the proposal, it returns the whole revised proposal (title, evidence, acceptance_criteria), which replaces this one under the same ticket; with a question to answer, it returns none. Never a different subject: a person who wants one rejects this one. Its prompt also includes the assignment's task, scope_path, permissions, instructions, expected_output (the job's output list), inputs and earlier_proposals; for each input package, fetch its run's report with run_report and include it, since the minion cannot reach the factory; when run_report refuses it (a package from another repository you cannot read), the package's data and content are all you get. An input named proposal holds proposals a person approved: tell the minion its title, evidence and acceptance_criteria are the work to do in this run, before the other work its instructions give, with the person's note, when it has one, as what they asked of it; with no packages, there is none. An input named ticket holds the one ticket of this run, from its hopper: its tracker (nightshift or linear), identifier, title and url, a Linear ticket's branch, and a Night Shift ticket's (an approved proposal) evidence, acceptance_criteria and, when the person added one, note, what they asked of it. Tell the minion it is the work of this run. For a Linear ticket, it starts its report with Linear: <identifier>, then Branch: <branch>. For a Night Shift ticket, it starts it with Night Shift: <identifier> and nothing else names the ticket: no Branch: line, and the identifier stays out of the pull request's title and of any Fixes line, since a Linear team with the same key would take the pull request as its own issue's and close it. Night Shift follows a Night Shift ticket through the run and its pull request itself: nothing is moved or commented. Tell it too not to propose again anything earlier_proposals lists: pending and approved ones are already in hand, rejected ones were refused, and an entry's note is what the person said when deciding. A rejected entry can also be a pull request a person closed, its title that run's summary: tell it not to redo that work either. scope_path is relative to the repository root. The minion only reads, unless permissions.source_access is write_in_scope: then it may edit, create or delete files inside scope_path and nowhere else. A minion never runs git beyond git status, commits or pushes. It returns the report Markdown, an outcome (completed, no_op or failed), a one-line factual summary of what it delivered, in plain words for someone who has not seen the code, with no branch, commit or URL (the Floor links the pull request), the packages its instructions ask it to return (each a name from the job's output list, its data and, when its instructions give one, its content), the blocked_hosts and output of the rule on refused hosts below when it applies, and, only for completed (or, for a reply, also no_op), an optional proposal (title, evidence, acceptance_criteria), unless permissions.proposals is forbidden: then it returns none, and the factory keeps only the title of one it is sent, in the run's steps. The run is unattended and any permission prompt blocks it, so add these rules to the minion's prompt as written (a minion without a shell has nothing to follow):
    • Run every shell command as its own call. Never join commands with &&, ;, || or |, and never use $(...), backticks or redirects. Do not pipe through head, tail or less. When you have Read, Grep and Glob tools (Claude Code), use them instead of cat, grep or find, and Edit or Write instead of sed or echo >.
    • To delete a file, run one plain rm ./<path>, its path from the repository root starting with ./ (rm ./backend/old.py.bak): the repository's permission rule allows only that form, so an absolute path or any option stops the run at a permission prompt. Never run a git command that changes the index, branch or history (git add, git rm, git reset, git checkout, git stash, git commit): the factory session runs git. To check your work, you may run git status --short on its own.
    • Edit, create or delete files only where your permissions allow: inside scope_path for write_in_scope, nowhere otherwise. Read and search anywhere in the repository.
    • Run the commands your instructions name, from the directory they name (a bootstrap from the repository root, a check from its package directory), even outside scope_path, as long as they change no file you may not edit, except caches and dependency or build directories the repository already ignores.
    • Use the network as your instructions need, unless permissions.network is forbidden: then reach it only for the repository's own bootstrap and checks. Create the tracker issue your instructions ask for, unless permissions.task_creation is human_approval_required or permissions.network is forbidden: then return it as your proposal instead. When permissions.proposals is forbidden, return no proposal: file any follow-up you find as a tracker issue. When you may create it, first search the tracker, before picking the work, in any status, for an issue naming the same file or helper: if one exists, with or without a pull request, never create another issue or redo the change; pick other work, or finish as no_op naming that issue. When you create an issue, make the report's first line <tracker>: <identifier> (for example Linear: IX-1234), and when the tracker gives the issue's branch name (Linear's gitBranchName), make the second line Branch: <branch name>. Never push, merge, open or comment on a pull request, since the factory session delivers your work. Reach GitHub with gh api (REST), not gh pr or gh issue, which cloud sessions reject. Do not install packages beyond the repository's own bootstrap, and do not change env files.
    • When your instructions name a tool from an MCP server you do not have (Codex cloud loads none), call that service's HTTP API with curl and the key the environment holds for it. For Linear: curl -sS https://api.linear.app/graphql -H "Authorization: $LINEAR_API_KEY" -H "Content-Type: application/json" -d '<the GraphQL query as JSON>'. For Sentry: curl -sS https://sentry.io/api/0/<endpoint> -H "Authorization: Bearer $SENTRY_AUTH_TOKEN". If there is no key or the call fails, put the service, the call and its error in the first sentence of your summary, and finish as failed when the job cannot be done without it.
    • Unless your instructions ask you to leave questions for a person, ask none: decide each open point yourself. Take the answer the repository's code, docs or conventions point to, and cite them; when nothing does, take the option easiest to undo, and say why. Then make that change if your permissions allow it, else return it as the rule above routes a follow-up: your proposal or a tracker issue. Never leave "confirm X", "X or Y" or "a judgment call" in the report. What your instructions do leave for a person about your own pull request goes under ## Needs a person, one bullet per question, in plain words, saying what to answer: the Floor shows that section above the pull request's actions, and the answer comes back as a follow-up, whose report lists only what is still open. A change that is not part of this pull request never goes there: it is a proposal or tracker issue.
    • A proposal or tracker issue states one change, the one you recommend, never a choice between options. A person decides a proposal from its title and the first sentence of its evidence: the title is the change itself in plain words, the first sentence says why it matters, and neither holds a file path, id or shorthand; those come after. Write each, and each question your instructions ask for, so someone who has not seen the code can act on it in one read, without shorthand: what you found and where, what you recommend, what it changes, and why. A question also asks one thing in plain words and gives each option with what it changes.
    • If a command is denied or waits on a permission prompt, do not retry it in another shape. Undo your changes and finish as failed, with the blocked command in the first sentence of the summary.
    • If a bootstrap step, check or test fails because the network refused a host (a proxy's 403, CONNECT tunnel failed, Tunnel connection failed, Could not resolve host and similar), do not work around it: undo your changes and finish as failed. Return blocked_hosts, one {"host", "needed_by"} per refused host, and output, the last 4,000 characters of the failing command's output. needed_by says what needed the host, from the failing command (the bootstrap step, check or test file), and what the host serves when the output shows it, for example The bootstrap step \uv sync` needs it: it serves the Python packages. An MCP server your instructions need counts too, when it fails to connect with a proxy error (ERR_PROXY_TUNNEL, a proxy's 403) and the HTTP fallback above has no key or is refused as well: its host is in its urlin.mcp.json(Linear's ismcp.linear.app`), needed_by names the server and what needed it, and output is its error.
    • If a call to a /dependabot/alerts endpoint answers 403 Resource not accessible by integration, the session's GitHub credential cannot read Dependabot alerts: never read it as an empty alert list or finish as no_op. Undo your changes and finish as failed, with a summary starting GitHub alert access missing: run /web-setup from Claude Code in a local terminal, or set a GH_TOKEN that can read Dependabot alerts in the routine's environment, then rerun., then the call that was refused. Log each step as it happens with log_step (run_id, lease_token, step, a one-line message), so the Floor shows the run before it finishes: minion_started when you hand it over, with message <role> on <model> · <effort> and data {"subagent_type": <role>, "model": <model passed, or "inherited">, "effort": <effort>}, plus "session_url": in a Claude cloud session (CLAUDE_CODE_REMOTE is true), the output of echo "https://claude.ai/code/${CLAUDE_CODE_REMOTE_SESSION_ID/#cse_/session_}"; on another provider, this session's URL when it exposes one. Then minion_returned with its outcome and summary, and when it returned blocked_hosts, data {"outcome": "failed", "blocked_hosts": <its blocked_hosts>, "output": <its output>}. For an assignment whose permissions.source_access is not write_in_scope, check the minion only read, since Codex does not hold it to that: a spawned agent gets this session's sandbox, whatever its role's sandbox_mode. Run git status --porcelain -uall and git rev-parse HEAD before handing it over and again after it returns. Each path in the second list that was not in the first is an edit it was not allowed to make, and a moved HEAD means it committed or switched branches. Log scope_check with those paths, both HEADs and the result. If there are any such paths, restore them (git checkout HEAD -- <path>, which also undoes a staged edit; leave a new file, which no rule lets the session delete, and name it in the report for a person to remove), and finish as failed with the paths in the report. If HEAD moved, finish as failed with git log --oneline <the first HEAD>..HEAD in the report, and claim no more assignments in this session, since its checkout is no longer the commit it checked in.
  4. For a write_in_scope assignment, deliver the minion's edits before finishing:
    • Before handing it over, git status --porcelain must be empty, so the pull request only holds the minion's edits. If it is not, finish as failed without starting the minion, and say the working tree has uncommitted changes.
    • After the minion returns, run git status --porcelain. Every changed path must be inside scope_path (. is the whole repository), and none may be the factory's own files, whatever the scope: .nightshift/, .claude/, .codex/, .agents/ and .mcp.json, so a job cannot widen its own permissions. Log scope_check with the changed paths and the result. If any path breaks either rule, restore those paths (git checkout -- <path>; a new file inside scope_path with one plain rm ./<path>, as a minion deletes, since any other form stops an unattended session at a permission prompt; leave a new file outside it, which no rule lets the session delete, and name it in the report for a person to remove), and finish as failed with the paths in the report.
    • Minion outcome failed, or the minion stopped without returning: restore every change it made, as above, and finish as failed with its report, even when the working tree changed.
    • No changes: for a follow_up, log pr_updated with its existing URL and full HEAD SHA, then finish as no_op; it still waits for human review. Otherwise finish as no_op.
    • Otherwise, for a follow_up, deliver to its existing branch as Reworking a PR says, then continue at step 5. For a normal assignment create the branch nightshift/<run_id> from the current branch, or nightshift/<branch name> when the report has a Branch: line (a tracker still links a branch name that contains its identifier), commit only the changed paths with the message <job_id>: <summary>, push it, and open a pull request into the default_branch check_in answered in step 1 whose title is that message and whose body is the report (Open a PR). When the report names a tracker issue on a line of its own (Linear: IX-1234, normally its first, but blocks you add go above it; never a Night Shift: ticket), start the title with its identifier (IX-1234 <job_id>: <summary>) and end the body with the line Fixes IX-1234: a tracker such as Linear links a pull request through its branch name, title or a magic-word line, not through the report's first line, and only a closing word such as Fixes lets it complete the issue when the pull request merges. Never write Part of or another non-closing word: the issue would stay open after the merge. Log branch_pushed with the branch after the push, and pr_opened with data {"url": <the html_url Open a PR printed>, "commit": <the full 40-character SHA from git rev-parse HEAD>}, for example {"url": "https://github.com/acme/notes/pull/12", "commit": "dd5066de73c073d27aa7b7db7caf0b16a7f2b272"}, never a short SHA. Then, when the assignment has pr_labels, add them (Label a PR). If that fails, log pr_labels_failed with the command and its error in one line and carry on: the pull request is open, and its checks start once a person adds the labels. If any of these fails (a failed push alone first goes to the factory, next point), never retry it in a form that skips a check (--no-verify, -n, SKIP=, HUSKY=0, another core.hooksPath, a force-push): a failed hook or check is the repository refusing the change. Log delivery_failed with the command that failed and its error in one line (for example git commit: pre-commit hook unit-tests failed, the proxy refused files.example.com (403)). When its output shows the network refused a host (a proxy's 403, CONNECT tunnel failed, Tunnel connection failed, Could not resolve host and similar), add data {"blocked_hosts": [{"host": <host>, "needed_by": <what needed it>}], "output": <the last 4,000 characters of the command's output>}, one entry per host: needed_by names what needed it from the failing command (the hook id, test file or bootstrap step) and what the host serves when the output shows it, for example The pre-commit hook \backend-unit-tests` needs it: its tests download the tiktoken tokenizer files from it. Then keep the work, since the edits are lost with this session: keep the local branch, add the error to the report, stage the changed paths (git add -- <paths>) so new files are included, and end the report with a section ## Undelivered diffholding the output ofgit diff --binary <the commit you checked in>, in a code fence with more backticks than the longest run of backticks in the diff (at least three). If that would take the report past 1,000,000 characters, the most finish_assignment accepts, put git diff --stat <the commit you checked in>` there instead and say the diff was too large. Only then finish as failed (step 5).
    • If only git push failed, for want of credentials or a route to GitHub (Authentication failed, could not read Username, a 403 from github.com, the proxy refusing github.com: Codex cloud holds no GitHub credentials), while the branch and the commit, hooks included, succeeded, the factory delivers the commit instead. A pre-push hook that failed is the repository refusing the change: fail as below. Do not log delivery_failed or blocked_hosts for the push yet. The factory delivers text only: first check git diff --summary <the commit you checked in> HEAD for a mode 100755 file created, a mode 120000 or a mode change, and git diff --numstat <the commit you checked in> HEAD for - (a binary file). If any appear, skip factory delivery for the whole change: log delivery_failed with the push error and the unsupported change, then use the failed-delivery instructions above to keep the push error and full ## Undelivered diff section in the report and finish as failed with no delivery. Otherwise, prepare the report without the push error or the ## Undelivered diff section. In its delivery lines, say the factory delivered the change; label the session's commit as Local commit it was built from: <SHA>, never as the delivered commit, since the factory creates a different commit on GitHub. Use the same wording in the summary, then finish in step 5 as completed with delivery: files, each path of git diff --name-only --no-renames <the commit you checked in> HEAD with its whole content from git show HEAD:<path>, or null for a path HEAD deleted; branch, the branch you created; title, the commit message; body, the body Open a PR would send (the report, then any Fixes line). The factory commits them on the commit you checked in as the GitHub user of the session's token, opens the pull request, adds the assignment's pr_labels to it, logs pr_opened and answers its URL as pull_request: add it to your closing summary. Over HTTP, write the whole JSON-RPC request to a file with a script (jq or python3), never pasting file contents into a command, and send it with curl as ns does but with -d @<file>: Linux refuses one argument over 128 KiB. If finish_assignment refuses the delivery with Not delivered:, it logged delivery_failed with why and finished nothing: log delivery_failed for the push as below (with blocked_hosts when a host was refused), then replace the report's factory-delivered lines with the push error and the factory's refusal, label its SHA Local commit, not delivered: <SHA>, and append the full ## Undelivered diff section using the failed-delivery instructions above (including their size limit and fence rule). Only then call it again as failed (step 5), with the updated report, a summary saying the change was not delivered, and no delivery. A timeout or another tool error is not a confirmed delivery refusal: inspect the run's state before reporting its outcome. It refuses unless the commit you checked in is already on the default branch, the job is a write job there on GitHub too, and every path is inside both its scopes and none of the factory's own files. Sessions whose push works keep pushing.
    • Never merge the pull request yourself. A follow_up always returns to human review, regardless of the job's usual merge policy. When permissions.merge is auto, or by_ticket and the ticket's Automerge label allows it at the risk you report, finish_assignment merges it, as the GitHub user this session is signed in as, once its own checks pass: your nightshift/ branch at the commit you pushed, into the default branch, changing only paths inside scope and no agent instructions, carrying the assignment's pr_labels, and clean on GitHub (checks and reviews passed). It waits up to 10 minutes while the checks run, so the call can take that long; do not call it again. Otherwise it stays open for a person.
    • Add the branch, commit and pull request URL to the report (for a factory delivery, keep the local-commit label above and put the URL finish_assignment answers in your closing summary), then switch back to the branch you started on.
  5. When the run finishes as failed, for any reason (the working tree, the scope check, the minion or the delivery), and the minion's report names a tracker issue on a line of its own (Linear: IX-1234; a Night Shift ticket has nobody to comment to: the Floor shows the failed run and offers the ticket again), first comment on that issue with the tracker's MCP server or CLI, since it may still say the change was made: start with the Blocked host blocks below when a host was refused, or the GitHub alert access block below when Dependabot alerts were refused, then say the change was not delivered, give the cause in one or two sentences, say whether a pull request exists (its URL if Open a PR printed one, else that none was opened, naming the branch if it was pushed), and give the run_id. Leave the issue's status as it is: when this repository's Linear workspace is connected to Night Shift, finish_assignment moves the run's own Linear issue (one it took or created) from In Progress back to Todo unless a pull request holds the work, and comments the failure on it itself when no comment says not delivered and names the run_id. If you cannot reach the tracker, say so in the summary and name the issue. When the run delivered a commit (a new pull request, a follow_up's push or a factory delivery; a follow_up that changed nothing did not) and that line names a tracker issue, document the issue before calling finish_assignment, since that call can merge the pull request and the merge completes the issue: comment on it the same way with the report as step 4 left it, without its <tracker>: and Branch: lines, so someone who reads only the ticket sees what changed, how it was checked, what is left and the pull request. A factory delivery of a normal assignment has no pull request URL yet: name the branch and say the factory opens the pull request (a follow_up's is follow_up.url, which it updates); if it refuses, the failed comment above follows. Leave the issue's status as it is: when this repository's Linear workspace is connected to Night Shift, finish_assignment moves the run's own Linear issue from a started status such as In Progress to In Review once the run opened a pull request. If you cannot reach the tracker, say so in the summary, name the issue and finish anyway: a missing comment never holds back a delivery. Call finish_assignment with run_id, lease_token and the minion's result, passing the report Markdown as report. When the run finishes completed or no_op and the minion returned packages, pass them as packages, data and content exactly as returned (a failed run passes none: the factory refuses them, and the failure must still be recorded); otherwise, if the job declares several outputs and the minion produced more than the report, pass them (name from the job's output list, data with a location or summary). The outcome decided in step 3's read check or in step 4 replaces the minion's. When permissions.merge is by_ticket and the run opened a pull request, read its diff and also pass risk: level low (small, easy to undo, covered by checks), medium (changes behaviour people rely on, within what the ticket asked) or high (auth, money, data, migrations, wide changes, or anything you are unsure of), and reason, one plain sentence naming what decided it. The factory compares it with the ticket's Automerge label, read again just before merging, which counts only if Linear records that someone who may assign work set it; rate the change, never the label. Its answer's merge says whether the factory merged the pull request (merged, with merge_commit) or left it open (refused, with the reason): give it in your summary. When merged, git fetch origin and git merge --ff-only <merge_commit>, then check in again (step 1) with the new HEAD, so dependents run in this session; if the fast-forward fails, carry on: the next session picks them up.
  6. Repeat from step 2 until nothing_to_do. Finish each assignment before claiming the next. Then, if a job finished completed since skip was last cleared of them, take every completed job out of skip and repeat from step 2 again, so a job due again (a backlog job with a short every) gets another round once every other due job had its turn. Failed and no_op jobs stay in skip for the whole session. Stop at a nothing_to_do with no completed job to take out.

Reworking a PR

An assignment's follow_up is a person's request to amend an existing PR. Its URL, branch, base and full head SHA are pinned by the factory. Preserve the original tracker issue and PR; never open another one. Keep the assignment's scope and every protected-path rule above.

Before starting its minion, save the current branch and commit and require a clean working tree. Run each command separately: git fetch origin <follow_up.branch>, then git rev-parse FETCH_HEAD; the SHA must equal follow_up.head. Check whether the local branch exists with git show-ref --verify refs/heads/<follow_up.branch>. If it exists, git checkout <follow_up.branch> and git merge --ff-only FETCH_HEAD; otherwise git checkout -b <follow_up.branch> FETCH_HEAD. git rev-parse HEAD must still equal the pinned head. Never reset or force a branch. Log revision_prepared with the PR and commit.

A minion cannot run git, so you bring the base in when the PR needs it. Read its mergeable_state (PR state above; while it is unknown or null, GitHub is still computing it: read it again a few seconds later, three times at most). Bring the base in when it is dirty (conflicts) or behind, or when follow_up.body asks to fix failing checks (CI, a build, a test) and the branch lacks commits of its base: the base may already fix what fails, often in a workflow or another file outside scope_path, which the minion cannot edit. Run git fetch origin <follow_up.base>; for failing checks, then git merge-base --is-ancestor FETCH_HEAD HEAD, and when it succeeds the branch already holds its base: merge nothing. Otherwise run git merge --no-edit --no-ff --no-commit FETCH_HEAD, never a rebase, so the merge stays open until the minion's work is checked. If it stops on conflicts, git diff --name-only --diff-filter=U lists the conflicted paths: when one is outside scope_path or one of the factory's own files, run git merge --abort, log revision_failed naming those paths, and finish as failed without starting a minion. Otherwise log base_merged with the base and the conflicted paths (none for a clean merge), and tell the minion the base was merged in, and when there are conflicted paths, first to resolve their conflict markers, keeping what both sides meant, then to do what the person asked. Run git status --porcelain -uall before handing it over: the merge leaves the base's changes staged, so step 4's clean working tree and scope checks apply only to the lines that changed between this list and the one after the minion, plus the conflicted paths. After the minion, git add -- <the conflicted paths and its changed paths>, then git grep --cached -n -E '^(<<<<<<<|>>>>>>>) ' -- <the same paths> must print nothing (a leftover conflict marker; skip both with no such paths), then git commit --no-edit concludes the merge with the repository's hooks. A minion that failed, a scope check that failed, or markers left behind: git merge --abort keeps the minion's other edits and refuses while a merged file has one, so first restore every path it changed that is not a conflicted path, as step 4 restores, then git merge --abort, then git status --porcelain must list nothing but the new files step 4 leaves for a person, and finish as failed. A merge counts as a change: it is committed and pushed below even when the minion changes nothing, which also reruns the checks. For failing checks, tell the minion to read their logs through the Actions API, since the factory's token cannot read check runs (commits/<sha>/check-runs answers 403): gh api 'repos/<owner>/<repo>/actions/runs?head_sha=<follow_up.head>' --jq '.workflow_runs[] | {id, name, conclusion}' lists the runs, gh api repos/<owner>/<repo>/actions/runs/<run_id>/jobs --jq '.jobs[] | {id, name, conclusion}' their jobs, and gh run view <run_id> --repo <owner>/<repo> --log-failed the failed ones' logs (gh api refuses a raw log for its terminal escape sequences). When the failure comes from a file outside scope_path and the merged base already fixes it, the minion changes nothing, starts its summary with Fixed on base: and what fixed it, and finishes completed: the merge is the fix. When no base was merged and the base already fixes it (gh api 'repos/<owner>/<repo>/contents/<path>?ref=<follow_up.base>' reads its copy), it finishes failed with a summary starting Fixed on base, needs a base merge:. When the base does not fix it either, it names the file and the change needed, and finishes failed. Any failure or permission prompt here gets its own revision_failed step naming the command and error, then finish as failed without starting a minion. Restore the starting branch when clean.

After the minion, apply step 4's outcome and scope checks. For changes, commit only its changed paths on this existing branch, with the repository's usual hooks and checks. Read the PR with gh api repos/<owner>/<repo>/pulls/N: it must still be open, its head SHA must equal follow_up.head, its head repository and branch must be this repository and follow_up.branch, and its base must be follow_up.base. Otherwise log delivery_failed and finish as failed, keeping the undelivered diff in the report. Push normally with git push origin <follow_up.branch>; never force-push. Log branch_pushed, then pr_updated with data {"url": <follow_up.url>, "commit": <full SHA from git rev-parse HEAD>}. Add the same PR URL and new commit to the report. The factory holds the amended outputs until a person merges.

If only pushing failed for credentials or a route to GitHub, use step 4's factory-delivery fallback, but compute every diff against follow_up.head rather than the initial check-in commit, and send delivery.branch = follow_up.branch. The factory fast-forwards that existing branch and logs pr_updated; it opens no PR. It cannot carry a merge of the base: then log delivery_failed and finish as failed, keeping the undelivered diff. A changed remote head refuses delivery. All original path, mode, check, report, and blocked-host rules still apply. Restore the starting branch after delivery or after recording failure; do not check in the PR branch as the jobs branch.

Blocked hosts: when a run fails because the sandbox refused a host (a step logged with blocked_hosts), the operator must read how to allow it before anything else. Start the report (above the minion's Linear: line), the tracker comment (step 5) and your closing summary with one block per host, in exactly this shape (blank lines included, so Markdown keeps its lines apart), and start finish_assignment's summary with Blocked host <host>: allow it in the routine's Network access, then rerun. (in Codex: in the Codex environment's internet access; plain text: the Floor shows it as is):

**Blocked host: `<host>`**

<needed_by> The sandbox refused it, so <the command that failed, for example the commit> failed.

**To fix:** in claude.ai, open the routine, then its cloud environment, then Network access. Choose Custom, check **Also include default list of common package managers**, keep the domains already listed, add `<host>` to Allowed domains, save, and rerun the job. If `<host>` is an MCP server, turn on that service's connector on the routine instead: a connector needs no allowed domain.

In Codex, the To fix: line reads instead: **To fix:** in chatgpt.com/codex, open Settings, then Environments, then this repository's environment. Turn Agent internet access on with the Common dependencies allowlist, add <host> to its additional allowed domains, save, and rerun the job. finish_assignment adds a block or summary start you left out, and accepts only the outcome failed for such a run.

GitHub alert access: when any step's /dependabot/alerts call got 403 Resource not accessible by integration (the minion's summary starts GitHub alert access missing:), the session reached GitHub through a GitHub App connection that cannot read Dependabot alerts. Finish the run as failed, never as no_op or as an empty alert list, even when the minion returned another outcome. Start the report (above the minion's Linear: line), the tracker comment (step 5) and your closing summary with this block, in exactly this shape, and start finish_assignment's summary with GitHub alert access missing: run /web-setup from Claude Code in a local terminal, then rerun.:

**GitHub alert access missing**

GitHub refused the Dependabot alerts call (403 `Resource not accessible by integration`): this session reaches GitHub through a GitHub App (in a Claude Code routine, the Claude GitHub App), which cannot read Dependabot alerts.

**To fix, either:**

1. In a local terminal where `gh auth status` is logged in, start `claude`, check that `/status` shows the claude.ai account that owns this routine, and type `/web-setup` (never in a cloud session, where it is not available). It must print `Connected as <github-user>` before opening claude.ai/code; if the browser opens without that line, `gh` was not found and the GitHub App was reconnected instead. It replaces the GitHub connection for every cloud session of the account. On Team and Enterprise plans an Owner must first turn on Quick setup (Organization settings > Claude Code).
2. Or (the only way in Codex cloud) set `GH_TOKEN` in the routine's cloud environment variables: a fine-grained token limited to `<owner>/<repo>` with Dependabot alerts: read, Pull requests: read and write, and Metadata: read. Anyone who uses the environment can read it.

**To check:** in a cloud session on the repository, `gh api "repos/<owner>/<repo>/dependabot/alerts?state=open&per_page=1" --jq length` prints a number; a 403 `Resource not accessible by integration` means the GitHub App is still in use, and `Resource not accessible by personal access token` means the `GH_TOKEN` lacks Dependabot alerts: read.

Then rerun the job.

Reporting: give each job's state as the factory states it, quoting its reason; never guess a cause. In factory_status, last_run is the job's latest run; a run named in eligibility (such as "counted from run …") is not. Never describe a job from an older run's report. Before naming a pull request in a summary, including one from a run report, read its PR state and give its current state: open, merged, or closed without merging. If the factory gives no reason, say the cause is unknown and what you checked.

Where instructions mention report_path or when_done, the report text goes to finish_assignment instead of a file or command.

If the factory reports that this repository's skills are out of date, run npx skills update, never copy the files by hand.

Files included

  • SKILL.md

More skills