From 0cc18bd30a43d0c9c5f4ce84104902b7c4a15b07 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 17 Nov 2026 01:20:55 -0800 Subject: [PATCH 1/4] chore(quest): claim quest/m0/benchmark/records-endpoint.md Quest-Claim: 4897fa8818512cf3 From 3b92719a281039662bf9c2f28022c36971c9258c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 17 Nov 2026 01:34:19 -0800 Subject: [PATCH 2/4] feat(records)!: send records to Kixel Quest by repository name The sender and `quest records incident` post to Kixel Quest's /records (https://kixel.quest, or QUEST_KIXEL_URL), naming the repository from the checkout's origin, with the token ~/.config/quest/records.json pairs with that URL. The committed .quest.json reader is gone. The sender asks GET /forge which repositories Kixel Quest serves and leaves the rest queued, since it refuses a whole upload naming one it does not index. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 43 +++-- quest/m0/benchmark/records-endpoint.md | 67 ------- quest/m0/github-quota/README.md | 3 +- src/cli/forge.ts | 12 +- src/cli/main.ts | 36 ++-- src/cli/send.ts | 212 ++++++++++------------- src/cli/tokens.ts | 49 ++++++ test/send.test.ts | 230 ++++++++++++++++--------- 8 files changed, 331 insertions(+), 321 deletions(-) delete mode 100644 quest/m0/benchmark/records-endpoint.md create mode 100644 src/cli/tokens.ts diff --git a/README.md b/README.md index c0755cf7..de322473 100644 --- a/README.md +++ b/README.md @@ -1856,23 +1856,20 @@ are read from the transcript on this host, and only their names and times leave it. The split's notes are lines a model wrote, told to name no one and quote no message. -A checkout names its endpoint in a committed `.quest.json`: - -```json -{ "records": "https://kixel.example/records" } -``` - -and each user pairs a token with it in `$XDG_CONFIG_HOME/quest/records.json` -(`~/.config`), so a checkout naming another endpoint, as a hostile branch -might, is never sent the token or a record: - -```json -{ "https://kixel.example/records": "token" } -``` - -The endpoint must be HTTPS, or HTTP to `localhost`. A checkout naming none, or -an endpoint the user holds no token for, sends nothing, and the hook says so -once as a system message. +Records go to [Kixel Quest](https://kixel.quest), the same one the +[forge reads](#read-through-kixel-quest) use, at its `/records`, with the token +`$XDG_CONFIG_HOME/quest/records.json` (`~/.config`) pairs with its URL. No +repository commits a config file: a record names its repository by `owner/repo` +from its checkout's `origin` (the repository its PRs open on, for a fork), and +the token is sent only to the URL the user's own file pairs it with. The URL is +`https://kixel.quest`, or HTTPS (HTTP to `localhost`) `QUEST_KIXEL_URL` for +another Kixel Quest, such as one running locally. A user holding no token for +it sends nothing, and the hook says so once as a system message. + +Kixel Quest refuses a whole upload naming a repository it does not index or +the sender cannot read, so the sender asks `GET /forge` which repositories it +serves and sends only those. The rest stay queued on this host, unsent, and the +next stop says so once. The `Stop` hook [`quest setup`](#configure-your-agent) installs for Claude Code and Codex only queues the session under `$XDG_STATE_HOME/quest/records`. One @@ -1894,23 +1891,23 @@ once per outage. Each pass runs token-max on this host from the earliest queued session's first instant, reads the PRs updated since then, or since its last upload for that -endpoint and repository read them, if earlier, so a fix merged after its +repository read them, if earlier, so a fix merged after its sessions were sent still goes with the next one, labels each session's new steps for its [time split](#time-splits), and posts `{"records": [...], "breakages": [...]}`, the breakages being those the merged PRs among them name under `## Caused by`, as `quest usage` reports them, with -`Authorization: Bearer `, one upload per endpoint and repository, each +`Authorization: Bearer `, one upload per repository, each queued session with its sub-agents, which stop without the hook naming them. Each upload is checked with `parseUpload` before it is posted. A 2xx drops the sessions from the queue, unless the hook queued one again meanwhile. A 401 or -403 drops them and sends that endpoint nothing more until the token changes. +403 drops them and sends Kixel Quest nothing more until the token changes. Any other failure keeps them queued, and the next stop says so once. A failing -endpoint and repository back off, waiting a minute and doubling up to six -hours, and sit out the passes meanwhile, so they never widen the others' +repository backs off, waiting a minute and doubling up to six +hours, and sits out the passes meanwhile, so it never widens the others' window. token-max missing is retried each pass. A deploy or alert reports what it found with `quest records incident`, which -posts one breakage at once to the checkout's endpoint and fails loud on any +posts one breakage at once to Kixel Quest and fails loud on any answer but a 2xx, since nothing retries it: ```console diff --git a/quest/m0/benchmark/records-endpoint.md b/quest/m0/benchmark/records-endpoint.md deleted file mode 100644 index c6f246cf..00000000 --- a/quest/m0/benchmark/records-endpoint.md +++ /dev/null @@ -1,67 +0,0 @@ -# [S] Send records to Kixel Quest by repository name - -## Goal - -quest sends each session's record, and the breakages its PRs name, to Kixel -Quest's built-in URL, naming the repository by `owner/repo` from its remote, -for every repository Kixel Quest serves. No repository commits a config file. -The maintainer's hosts hold their Kixel Quest token, and one real session on -a moq-dev/quest PR shows in Kixel Quest's store, its record equal to what -`quest usage --json` prints for it. - -## Plan - -`quest` sends the records since -[moq-dev/quest#718](https://github.com/moq-dev/quest/pull/718): it posts -`{"records": [...]}`, each a `SessionRecord` from `quest/core`, with the -user's token as a bearer token, and takes a 401 or 403 as no access. - -Decided 2026-11-15 (maintainer, `/quest-plan`, the -[GitHub quota](/quest/m0/github-quota/README.md) epic): ✅ a built-in Kixel -Quest URL, overridable by an environment variable for development, with the -repository named by its remote (rejected: a committed `.quest.json`, which -no repository had committed yet). - -- Delete the `.quest.json` reader (`CHECKOUT_CONFIG` in `src/cli/send.ts`) - and the help text naming it. Send to the Kixel Quest that - `kixelQuest()` in `src/cli/forge.ts` names, `https://kixel.quest` or - `QUEST_KIXEL_URL`, with the token the forge reads use: the one - `~/.config/quest/records.json` pairs with that URL. -- Kixel Quest refuses a whole upload naming a repository it does not index - or the sender cannot read, so the sender sends only the repositories - Kixel Quest says it serves, `KixelQuest.serves()`, the same answer the - forge reads use, and keeps the rest on the host as it does today for a - checkout with no endpoint. -- Put the token on each host, and start its sender with `quest records - install`, through kixel-ai/dotfiles, which owns the maintainer's host - configuration, not by hand. Only once Kixel Quest serves `GET /forge` - (kixel-ai/kixel.quest's `quest/m0/read-api.md`): with that token, every - forge read goes to Kixel Quest and fails until it answers. - -Tests: a session in a checkout whose remote Kixel Quest serves is sent with -its `owner/repo`; one it refuses stays queued on the host; and the override -variable redirects both records and breakages. - -Decided 2026-11-15 (maintainer, `/quest-plan` of `/quest-run`'s -follow-ups): ✅ hold this quest until the forge reads land, and name the -deploy it waits on (rejected: only the Required link, leaving the deploy to -the Goal's end check; neither, relying on coordinators to know). - -Decided 2026-11-15 (same interview): ✅ the record wire stays lockstep for -now, revisited if records sit queued for days (rejected: the parser -ignoring unknown keys, which silently drops new fields at an older store -and still leaves a newer store refusing older hosts; ignoring them and -making new fields optional, which leaves every field optional for good). -`parseRecord` keeps rejecting any key it does not know, so Kixel Quest's -store and the hosts must run quest versions with the same record format; a -refused upload stays queued and retries each pass, so a lagging side delays -records rather than losing them. - -## Waiting - -- kixel-ai/kixel.quest: deploy `main`, so the store serves the record - endpoint. Check that `curl -s -A quest -X POST -H 'Authorization: Bearer - bogus' -H 'Content-Type: application/json' -d '{}' - https://kixel.quest/records -o /dev/null -w '%{http_code}'` prints `401`, - not `404`; its `quest/m0/deploy.md` automates deploys, and the maintainer - can run `just deploy` there meanwhile. diff --git a/quest/m0/github-quota/README.md b/quest/m0/github-quota/README.md index bddd69ae..5c49b25a 100644 --- a/quest/m0/github-quota/README.md +++ b/quest/m0/github-quota/README.md @@ -27,8 +27,7 @@ Decided 2026-11-15 (maintainer, `/quest-plan` here): remote (rejected: a committed `.quest.json` naming the endpoint, which no repository had committed yet and which could drift from what Kixel Quest indexes). Kixel Quest says which repositories it serves; the rest use - GitHub. Session records route the same way - ([records endpoint](/quest/m0/benchmark/records-endpoint.md)). + GitHub. Session records route the same way. - ✅ Kixel Quest is used only by a person holding a Kixel Quest token, which its admin-managed allow-list gives out; outside contributors stay a non-goal for now (rejected: a self-serve contributor role, picked and then diff --git a/src/cli/forge.ts b/src/cli/forge.ts index ff43d7f3..009d46ab 100644 --- a/src/cli/forge.ts +++ b/src/cli/forge.ts @@ -21,12 +21,8 @@ import { } from "../core"; import type { GitHubDependencies } from "../github/client"; import { GitHubForge } from "../github/forge"; -import { checkedEndpoint, tokenFor, tokensPath } from "./send"; +import { kixelUrl, tokenFor, tokensPath } from "./tokens"; -/** Kixel Quest's own URL. */ -export const KIXEL_QUEST = "https://kixel.quest"; -/** The variable naming another Kixel Quest, such as one running locally. */ -export const KIXEL_QUEST_URL = "QUEST_KIXEL_URL"; /** The variable that, set to `github`, reads GitHub even where Kixel Quest serves the repository. */ export const FORGE = "QUEST_FORGE"; @@ -37,6 +33,8 @@ export interface ForgeDependencies { now(): number; /** Called only once a read goes to GitHub, so Kixel Quest's reads need no GitHub token. */ github(): GitHubDependencies; + /** What a Kixel Quest failure tells the person to do; by default, to read GitHub instead. */ + remedy?: string; } /** The Kixel Quest `env` names, with the person's token for it; null without a token, or when reads are on GitHub. */ @@ -45,7 +43,7 @@ export function kixelQuest(deps: ForgeDependencies): KixelQuest | null { if (forced !== undefined && forced !== "" && forced !== "github") throw new Error(`${FORGE} is ${forced}; set it to github to read GitHub, or leave it unset`); if (forced === "github") return null; - const url = checkedEndpoint(deps.env[KIXEL_QUEST_URL] || KIXEL_QUEST, KIXEL_QUEST_URL).replace(/\/+$/, ""); + const url = kixelUrl(deps.env); const token = tokenFor(url, deps.env); return token === null ? null : new KixelQuest(url, token, deps); } @@ -117,7 +115,7 @@ export class KixelQuest { /** A failed request, naming the setting that reads GitHub instead. */ #failed(method: string, path: string, why: string): Error { return new Error( - `Kixel Quest (${this.url}) failed ${method} ${path}: ${why}; set ${FORGE}=github to read GitHub`, + `Kixel Quest (${this.url}) failed ${method} ${path}: ${why}; ${this.deps.remedy ?? `set ${FORGE}=github to read GitHub`}`, ); } diff --git a/src/cli/main.ts b/src/cli/main.ts index f2b9d20c..f8593964 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -96,18 +96,11 @@ import { import { CHECKED_CONTEXT, USER_ASKED, questRoot } from "./rules"; import { messageLines, messages } from "./messages"; import { logWait, pullWaitKind, readWaits } from "./waits"; -import { - CHECKOUT_CONFIG, - SEND_INTERVAL, - background, - parseInstant, - reportIncident, - runSender, - tokensPath, -} from "./send"; +import { SEND_INTERVAL, background, parseInstant, reportIncident, runSender } from "./send"; import { installSender, uninstallSender } from "./service"; import { heal, init, stubFindings, uninstall } from "./setup"; import { Refusal, describe, notUpstream, releaseQuest, startQuest } from "./start"; +import { KIXEL_QUEST_URL, tokensPath } from "./tokens"; import { CONTEXT, GUIDE, GUIDE_SECTIONS, SKILLS, guideSections, sectionHeading, skill } from "./skills"; import { type Terminal, Theme } from "./theme"; import { type Snapshot, checkout, collect, load, snapshot, under } from "./tree"; @@ -1274,21 +1267,20 @@ export function main(argv: string[], out: Output): number | Promise { ); }); - const recordsCommand = program - .command("records") - .summary("Send agent sessions' records to the Kixel Code endpoint their checkout names"); + const recordsCommand = program.command("records").summary("Send agent sessions' records to Kixel Quest"); recordsCommand .command("sender") .summary("Run the user's record sender until stopped, as its service does") .description( - "Send each session record the stop hook queued, with the records of its sub-agents on this host, to the " + - `endpoint its checkout's ${CHECKOUT_CONFIG} names as records, posting {"records": [...], "breakages": [...]}, the breakages the merged PRs among them name under ## Caused by, with the token ` + - `${tokensPath()} pairs with that endpoint as a bearer token, one upload per endpoint and repository, ` + + "Send each session record the stop hook queued, with the records of its sub-agents on this host, to " + + `Kixel Quest's /records (https://kixel.quest, or the one ${KIXEL_QUEST_URL} names), posting {"records": [...], "breakages": [...]}, the breakages the merged PRs among them name under ## Caused by, with the token ` + + `${tokensPath()} pairs with its URL as a bearer token, one upload per repository, ` + `then again every ${SEND_INTERVAL / 1000} seconds until stopped, at low priority. A record is built as quest usage ` + "builds it, from token-max's sessions on this host since the earliest queued session's first instant and " + - "the PRs updated since then, and replaces its earlier copy, so a resend never doubles. A sent session whose " + + "the PRs updated since then, and replaces its earlier copy, so a resend never doubles. A repository Kixel " + + "Quest does not serve, as it says on GET /forge, stays queued, unsent. A sent session whose " + "latest branch, or a sub-agent's, heads no PR yet is sent again, with its sub-agents, once a pass for its " + - "repository reads a PR opened on that branch, until its transcript is gone. An endpoint that " + + "repository reads a PR opened on that branch, until its transcript is gone. A Kixel Quest that " + "refuses the token (401 or 403) is sent nothing more until the token changes; any other failure keeps the " + "sessions queued, retried after a minute and then twice as long each time up to six hours, and the next " + "stop hook says so once. Before a record is built, a cheap model, " + @@ -1328,13 +1320,13 @@ export function main(argv: string[], out: Output): number | Promise { "A stable ID for the incident, such as the alert's URL; a later report with it replaces this one", ) .description( - "Post one breakage to the endpoint this checkout's " + - `${CHECKOUT_CONFIG} names, with the token ${tokensPath()} pairs with it, as {"records": [], "breakages": [...]}. ` + + "Post one breakage to Kixel Quest's /records " + + `(https://kixel.quest, or the one ${KIXEL_QUEST_URL} names), with the token ${tokensPath()} pairs with its URL, as {"records": [], "breakages": [...]}. ` + "Without --pr the incident is open, its culprit unknown; report the same ID again with --pr to close it on " + "its culprit, whose tier, size, writers, and local reviewers are read from its PR body, or name it on the " + "culprit's ## Caused by line of the fix, as (incident ), whose record then replaces it. It posts at once " + "and retries nothing, for a deploy or alert to call.\n\nUses GH_TOKEN, GITHUB_TOKEN, or gh auth token. " + - "Exits 0 when the endpoint took it, 2 for invalid arguments, and 1 for other failures, refusal included.", + "Exits 0 when Kixel Quest took it, 2 for invalid arguments, and 1 for other failures, refusal included.", ) .addOption(new Option("--found ", "Who or what found it").choices(FINDERS).makeOptionMandatory()) .option("--pr ", "The PR that caused it", positiveInteger("--pr")) @@ -1964,8 +1956,8 @@ export function main(argv: string[], out: Output): number | Promise { `user asked for passes with the \`${USER_ASKED}\` prefix. Stop and SubagentStop refuse to end the ` + "turn, naming each command, while a `quest gate` command the ending agent started runs in Claude " + "Code's background: one whose background ID its transcript holds. Otherwise Claude Code's and Codex's Stop " + - `queue the session's record for the endpoint the checkout's ${CHECKOUT_CONFIG} names, for quest records ` + - "sender to send; a checkout naming none, an endpoint the user holds no token for, or a host whose sender " + + "queue the session's record for Kixel Quest, for quest records " + + "sender to send; a user holding no token for it, or a host whose sender " + "does not run says so once as a system message, as does a sender's failure. Exits 1 on malformed input or an event it " + "does not handle.", ) diff --git a/src/cli/send.ts b/src/cli/send.ts index 811f3489..781b6017 100644 --- a/src/cli/send.ts +++ b/src/cli/send.ts @@ -1,4 +1,4 @@ -// Sending each session's record, and the breakages its PRs name, to the Kixel Code endpoint its checkout names. The stop hook only queues the session; +// Sending each session's record, and the breakages its PRs name, to Kixel Quest, for each repository it serves. The stop hook only queues the session; // one sender per user, run by its service manager, rebuilds each queued session's record, with its sub-agents', and // posts them, keeping what failed for the next pass, and queues a sent session again once a PR opens on a branch its // record could not name a PR for. A record replaces its earlier copy, so a resend never doubles. @@ -8,10 +8,11 @@ import { homedir, setPriority } from "node:os"; import { dirname, join, resolve } from "node:path"; import { createHash, randomUUID } from "node:crypto"; -import { type BreakageRecord, type Finder, type RecordUpload, parseUpload } from "../core"; +import { type BreakageRecord, type Finder, type RecordUpload, type Repository, parseUpload } from "../core"; import { culpritOf } from "./breakage"; import { CLOCK_SKEW, type GitHubDependencies, GitHub } from "../github/client"; import { baseRepository } from "./claims"; +import { KixelQuest } from "./forge"; import { discoveryEnv } from "./git"; import { readRemote, remoteRepository } from "./github"; import { eachLine } from "./messages"; @@ -30,11 +31,9 @@ import { unheaded, updatedPulls, } from "./usage"; +import { kixelUrl, tokenFor, tokensPath } from "./tokens"; import { type LoggedWait } from "./waits"; -/** The checkout's file naming its record endpoint, as `{"records": "https://..."}`. */ -export const CHECKOUT_CONFIG = ".quest.json"; - /** One session the stop hook queued. */ export interface Pending { harness: string; @@ -47,7 +46,6 @@ export interface Pending { root: string; origin: string; prefix: string; - endpoint: string; /** * On a resend, the instant, epoch ms, its earlier upload read PRs from, so the resend reads at least as far back and * names every PR that upload did. @@ -60,70 +58,13 @@ export function stateDirectory(env: NodeJS.ProcessEnv): string { return join(env.XDG_STATE_HOME || join(homedir(), ".local", "state"), "quest", "records"); } -/** The user's tokens, by the endpoint each may be sent to: `{"https://...": "token"}`. */ -export function tokensPath(env: NodeJS.ProcessEnv = process.env): string { - return join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "quest", "records.json"); -} - -/** The endpoint `root`'s checkout names, or null; a malformed file or endpoint throws. */ -export function checkoutEndpoint(root: string): string | null { - const path = join(root, CHECKOUT_CONFIG); - if (!existsSync(path)) return null; - let config: unknown; - try { - config = JSON.parse(readFileSync(path, "utf8")); - } catch (error) { - throw new Error(`${path} is not JSON: ${(error as Error).message}`); - } - const endpoint = (config as { records?: unknown } | null)?.records; - if (endpoint === undefined) return null; - if (typeof endpoint !== "string") throw new Error(`${path}: records is not a URL`); - return checkedEndpoint(endpoint, path); -} - -/** `endpoint` when it is HTTPS, or HTTP to this host for a local store; anything else would send records in clear. */ -export function checkedEndpoint(endpoint: string, where: string): string { - let url: URL; - try { - url = new URL(endpoint); - } catch { - throw new Error(`${where}: ${endpoint} is not a URL`); - } - const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname); - if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) - throw new Error(`${where}: ${endpoint} is not an HTTPS URL`); - return endpoint; -} - -/** - * The token the user paired with `endpoint`, or null. The token is bound to its endpoint in the user's own file, so - * a checkout naming another endpoint, as a hostile branch might, never receives it. - */ -export function tokenFor(endpoint: string, env: NodeJS.ProcessEnv = process.env): string | null { - const path = tokensPath(env); - if (!existsSync(path)) return null; - let tokens: unknown; - try { - tokens = JSON.parse(readFileSync(path, "utf8")); - } catch (error) { - throw new Error(`${path} is not JSON: ${(error as Error).message}`); - } - if (typeof tokens !== "object" || tokens === null || Array.isArray(tokens)) - throw new Error(`${path} does not hold an object of tokens by endpoint`); - const token = (tokens as Record)[endpoint]; - if (token === undefined) return null; - if (typeof token !== "string" || token === "") - throw new Error(`${path}: the token for ${endpoint} is not a string`); - return token; -} - -/** The marker of an endpoint that refused a token, which a new token clears. */ -const refusal = (env: NodeJS.ProcessEnv, endpoint: string, token: string) => - join(stateDirectory(env), "refused", digest(`${endpoint}\0${token}`)); +/** The marker of a Kixel Quest that refused a token, which a new token clears. */ +const refusal = (env: NodeJS.ProcessEnv, url: string, token: string) => + join(stateDirectory(env), "refused", digest(`${url}\0${token}`)); -function refuse(env: NodeJS.ProcessEnv, endpoint: string, token: string): void { +function refuse(env: NodeJS.ProcessEnv, url: string, token: string): void { mkdirSync(join(stateDirectory(env), "refused"), { recursive: true, mode: 0o700 }); - writeFileSync(refusal(env, endpoint, token), ""); + writeFileSync(refusal(env, url, token), ""); } /** Say `notice` the first time only, by `key`, returning it then and null after. */ @@ -168,9 +109,8 @@ export interface Queued { } /** - * Queue the stopped session's record for its checkout's endpoint, in a checkout that uses Quest. A checkout naming - * no endpoint, or one the user holds no token for, queues nothing and says so once. A sender's last failure, if the - * person has not seen it, is said too. + * Queue the stopped session's record for Kixel Quest, in a checkout that uses Quest. A user holding no token for it + * queues nothing and is told once. A sender's last failure, if the person has not seen it, is said too. */ export function queue(stopped: Stopped, env: NodeJS.ProcessEnv = process.env): Queued { const notices: string[] = []; @@ -189,19 +129,14 @@ export function queue(stopped: Stopped, env: NodeJS.ProcessEnv = process.env): Q // A checkout off GitHub has no PRs for a record to name. if (origin === null) return { notices, queued: false }; const repository = `${origin.owner}/${origin.repo}`.toLowerCase(); - const endpoint = checkoutEndpoint(root); - if (endpoint === null) - return said( - `none:${repository}`, - `quest: ${repository} names no Kixel Code endpoint in ${CHECKOUT_CONFIG}, so its sessions' records stay on this host.`, - ); - const token = tokenFor(endpoint, env); + const url = kixelUrl(env); + const token = tokenFor(url, env); if (token === null) return said( - `token:${endpoint}`, - `quest: ${tokensPath(env)} holds no token for ${endpoint}, so this host sends it no session records.`, + `token:${url}`, + `quest: ${tokensPath(env)} holds no token for ${url}, so this host sends it no session records.`, ); - if (existsSync(refusal(env, endpoint, token))) return { notices, queued: false }; + if (existsSync(refusal(env, url, token))) return { notices, queued: false }; const start = transcriptStart(stopped.transcript); if (start === null) throw new Error(`${stopped.transcript} records no instant, so its session cannot be read`); const dir = enqueue(env, { @@ -212,7 +147,6 @@ export function queue(stopped: Stopped, env: NodeJS.ProcessEnv = process.env): Q root, origin: repository, prefix: run(["rev-parse", "--show-prefix"]).stdout.trim(), - endpoint, }); const sender = senderRuns(env); if (!sender.runs) @@ -331,10 +265,10 @@ export async function runSender(deps: SendDependencies, log: (line: string) => v } /** - * Send every queued session's record once, with those of its sub-agents on this host, one upload per endpoint and - * repository. A record goes only to the endpoint its token is paired with. An upload refused for access drops its - * sessions and says so once; any other failure keeps them queued for the next pass, records it for the stop hook, - * and throws. A session queued again while an upload ran stays queued. + * Send every queued session's record once, with those of its sub-agents on this host, one upload per repository, to + * the Kixel Quest the user's token is paired with. A repository Kixel Quest does not serve stays queued, unsent. An + * upload refused for access drops its sessions and says so once; any other failure keeps them queued for the next + * pass, records it for the stop hook, and throws. A session queued again while an upload ran stays queued. */ export async function sendPass(deps: SendDependencies): Promise { const dir = stateDirectory(deps.env); @@ -356,15 +290,64 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { const path = join(dir, "pending", name); return { path, pending: JSON.parse(readFileSync(path, "utf8")) as Pending }; }); + const url = kixelUrl(deps.env); + const token = tokenFor(url, deps.env); + // The user removed the token since the session was queued, or Kixel Quest refused it: nothing is sent. + if (token === null || existsSync(refusal(deps.env, url, token))) { + for (const q of queued) settle(q); + return []; + } const groups = new Map(); for (const q of queued) { - const id = JSON.stringify([q.pending.endpoint, q.pending.origin, q.pending.prefix]); + const id = JSON.stringify([q.pending.origin, q.pending.prefix]); groups.set(id, [...(groups.get(id) ?? []), q]); } // A group backing off sits the pass out, so it neither reruns token-max nor widens the others' window. for (const id of [...groups.keys()]) if ((readBackoff(deps.env, id)?.next ?? 0) > deps.now()) groups.delete(id); + const client = new GitHub(deps.github()); + const sent: Sent[] = []; + const failures: string[] = []; + const notes: string[] = []; + const failed = (id: string, origin: string, error: unknown) => { + const wait = backOff(deps, id); + failures.push( + `${origin} to ${url}: ${error instanceof Error ? error.message : String(error)} (tried again in ${Math.round(wait / 60_000)} minutes)`, + ); + }; + // Records name the repository PRs open on, which a fork's is not. Kixel Quest refuses a whole upload naming one it + // does not index, so a group it does not serve stays queued and sits the pass out, without running token-max. + const kixel = new KixelQuest(url, token, { + env: deps.env, + fetch: deps.fetch, + now: deps.now, + github: deps.github, + remedy: "its records stay queued", + }); + const bases = new Map(); + for (const [id, group] of [...groups]) { + const { origin, prefix } = group[0]!.pending; + try { + const [owner, repo] = origin.split("/") as [string, string]; + const repository = await baseRepository(client, { owner, repo }, prefix); + if (await kixel.serves(repository)) { + bases.set(id, repository); + continue; + } + const unserved = once( + deps.env, + `unserved:${key(repository)}`, + `${url} does not serve ${key(repository)}, so its sessions' records stay queued on this host.`, + ); + if (unserved !== null) notes.push(unserved); + } catch (error) { + failed(id, origin, error); + } + groups.delete(id); + } const active = [...groups.values()].flat(); - if (active.length === 0) return []; + // A pass with nothing to say leaves the last failure for the stop hook, which a quiet group's backoff still owes. + if (active.length === 0) + return failures.length > 0 || notes.length > 0 ? finish(deps, dir, sent, failures, notes) : sent; const since = Math.min(...active.map((q) => q.pending.start)); const exported = deps.sessions(new Date(since)); if (exported === null) @@ -374,22 +357,11 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { const { kept } = fold(exported); const byId = new Map(kept.flatMap((s) => (s.id === null ? [] : [[`${s.harness}\0${s.id}`, s] as const]))); const waits = deps.waits(since); - const client = new GitHub(deps.github()); - const sent: Sent[] = []; - const failures: string[] = []; - const notes: string[] = []; for (const [id, group] of groups) { - const { endpoint, origin, prefix } = group[0]!.pending; + const { origin } = group[0]!.pending; const roots = new Set(group.map((q) => q.pending.root)); try { - const token = tokenFor(endpoint, deps.env); - // The user removed the token since the session was queued, or the endpoint refused it: it sends nothing. - if (token === null || existsSync(refusal(deps.env, endpoint, token))) { - for (const q of group) settle(q); - continue; - } - const [owner, repo] = origin.split("/") as [string, string]; - const repository = await baseRepository(client, { owner, repo }, prefix); + const repository = bases.get(id)!; // PRs are read from the last upload's read, if earlier, so a fix that merged after its sessions were sent, // as through the merge queue, still reaches the store with the next session. A resend reads from its earlier // upload's read too, if earlier, so it drops no PR that upload named. @@ -420,7 +392,7 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { const repositories = new Set([origin, key(repository)]); // A sub-agent stops without the stop hook naming it, so each queued session brings its own, routed as its // own checkout routes it, found from the nearest folder still there: a checkout must be a queued one's, or - // name the same origin and endpoint. With no checkout left, every repository token-max resolved for it + // name the same origin. With no checkout left, every repository token-max resolved for it // must be this group's. const routed = (s: Session): boolean => { // Repositories token-max resolved that are none of this group's, as for a deleted nested clone of @@ -437,12 +409,7 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { if (roots.has(own)) return true; const remote = readRemote(own, "origin"); const named = remote === null ? null : remoteRepository(remote).repository; - try { - return named !== null && key(named) === origin && checkoutEndpoint(own) === endpoint; - } catch { - // A malformed .quest.json routes nowhere, as its own stop would say. - return false; - } + return named !== null && key(named) === origin; } return ( s.repositories !== null && @@ -501,9 +468,10 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { records: [...records.values()], breakages: await fixBreakages({ client, repository, pulls }), }; + const endpoint = `${url}/records`; const response = await post(deps.fetch, endpoint, token, upload); if (response.status === 401 || response.status === 403) { - refuse(deps.env, endpoint, token); + refuse(deps.env, url, token); clearBackoff(deps.env, id); for (const q of group) settle(q); notes.push( @@ -534,12 +502,14 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { refused: false, }); } catch (error) { - const wait = backOff(deps, id); - failures.push( - `${origin} to ${endpoint}: ${error instanceof Error ? error.message : String(error)} (tried again in ${Math.round(wait / 60_000)} minutes)`, - ); + failed(id, origin, error); } } + return finish(deps, dir, sent, failures, notes); +} + +/** End a pass: throw its failures, else leave its notes for the stop hook to say, or clear the last failure. */ +function finish(deps: SendDependencies, dir: string, sent: Sent[], failures: string[], notes: string[]): Sent[] { if (failures.length) throw new Error([...notes, ...failures].join("; ")); if (notes.length) writeFailure(deps.env, notes.join("; ")); else rmSync(join(dir, "failure"), { force: true }); @@ -565,7 +535,7 @@ export function parseInstant(text: string): number | null { /** An incident to report, as a deploy or alert hands it to `quest records incident`. */ export interface Incident { - /** A directory in the checkout whose endpoint and repository it is reported for. */ + /** A directory in the checkout whose repository it is reported for. */ cwd: string; /** The reporter's stable ID for it, such as the alert's URL; reporting the same ID again replaces it. */ id: string; @@ -577,9 +547,9 @@ export interface Incident { } /** - * Post `incident` as a breakage to the endpoint the checkout's `${CHECKOUT_CONFIG}` names, with the token the user - * paired with it, and return it. Unlike the sender, it posts at once and fails loud on anything the endpoint does not - * take, refusal included, since a deploy or alert calls it once and nothing retries. + * Post `incident` as a breakage to Kixel Quest, with the token the user paired with it, and return it. Unlike the + * sender, it posts at once and fails loud on anything Kixel Quest does not take, refusal and an unserved repository + * included, since a deploy or alert calls it once and nothing retries. */ export async function reportIncident( incident: Incident, @@ -587,10 +557,9 @@ export async function reportIncident( ): Promise { const root = questRoot(resolve(incident.cwd)); if (root === null) throw new Error(`${incident.cwd} is not in a checkout that uses Quest`); - const endpoint = checkoutEndpoint(root); - if (endpoint === null) throw new Error(`${join(root, CHECKOUT_CONFIG)} names no record endpoint`); - const token = tokenFor(endpoint, deps.env); - if (token === null) throw new Error(`${tokensPath(deps.env)} holds no token for ${endpoint}`); + const url = kixelUrl(deps.env); + const token = tokenFor(url, deps.env); + if (token === null) throw new Error(`${tokensPath(deps.env)} holds no token for ${url}`); const remote = readRemote(root, "origin"); const origin = remote === null ? null : remoteRepository(remote).repository; if (origin === null) throw new Error("origin is not on GitHub"); @@ -614,6 +583,7 @@ export async function reportIncident( found: incident.found, at: new Date(incident.at).toISOString(), }; + const endpoint = `${url}/records`; const response = await post(deps.fetch, endpoint, token, { records: [], breakages: [breakage] }); if (!response.ok) throw new Error(`${endpoint} answered ${response.status}: ${(await response.text()).slice(0, 500)}`); diff --git a/src/cli/tokens.ts b/src/cli/tokens.ts new file mode 100644 index 00000000..a44a1dff --- /dev/null +++ b/src/cli/tokens.ts @@ -0,0 +1,49 @@ +// The user's Kixel Quest tokens, and the Kixel Quest they pair with: one built-in URL, or the one `QUEST_KIXEL_URL` +// names. The forge reads and the record sender both send a token only to the URL their user's file pairs it with. +import { existsSync, readFileSync } from "node:fs"; +import { homedir } from "node:os"; +import { join } from "node:path"; + +/** Kixel Quest's own URL. */ +export const KIXEL_QUEST = "https://kixel.quest"; +/** The variable naming another Kixel Quest, such as one running locally. */ +export const KIXEL_QUEST_URL = "QUEST_KIXEL_URL"; + +/** The user's tokens, by the Kixel Quest URL each may be sent to: `{"https://...": "token"}`. */ +export function tokensPath(env: NodeJS.ProcessEnv = process.env): string { + return join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "quest", "records.json"); +} + +/** The Kixel Quest `env` names, without a trailing slash; a malformed or clear-text URL throws. */ +export function kixelUrl(env: NodeJS.ProcessEnv): string { + const named = env[KIXEL_QUEST_URL] || KIXEL_QUEST; + let url: URL; + try { + url = new URL(named); + } catch { + throw new Error(`${KIXEL_QUEST_URL}: ${named} is not a URL`); + } + // Anything but HTTPS, or HTTP to this host for a local store, would send the token in clear. + const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname); + if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) + throw new Error(`${KIXEL_QUEST_URL}: ${named} is not an HTTPS URL`); + return named.replace(/\/+$/, ""); +} + +/** The token the user paired with `url`, or null. */ +export function tokenFor(url: string, env: NodeJS.ProcessEnv = process.env): string | null { + const path = tokensPath(env); + if (!existsSync(path)) return null; + let tokens: unknown; + try { + tokens = JSON.parse(readFileSync(path, "utf8")); + } catch (error) { + throw new Error(`${path} is not JSON: ${(error as Error).message}`); + } + if (typeof tokens !== "object" || tokens === null || Array.isArray(tokens)) + throw new Error(`${path} does not hold an object of tokens by URL`); + const token = (tokens as Record)[url]; + if (token === undefined) return null; + if (typeof token !== "string" || token === "") throw new Error(`${path}: the token for ${url} is not a string`); + return token; +} diff --git a/test/send.test.ts b/test/send.test.ts index ee7cecd1..8832f5c0 100644 --- a/test/send.test.ts +++ b/test/send.test.ts @@ -6,38 +6,32 @@ import { expect, test } from "vitest"; import { REFERENCE_LINE, parseUpload } from "../src/core"; import { hook } from "../src/cli/hooks"; -import { - type SendDependencies, - parseInstant, - queue, - reportIncident, - runSender, - sendPass, - tokensPath, -} from "../src/cli/send"; +import { type SendDependencies, parseInstant, queue, reportIncident, runSender, sendPass } from "../src/cli/send"; +import { tokensPath } from "../src/cli/tokens"; import type { Session } from "../src/cli/usage"; import { tempDir } from "./fixture"; -const ENDPOINT = "https://kixel.example/records"; +/** The Kixel Quest the tests' users hold a token for, as `QUEST_KIXEL_URL` names it, and where it takes records. */ +const URL_ = "https://kixel.example"; +const ENDPOINT = `${URL_}/records`; -/** A checkout that uses Quest, with a GitHub origin, naming `endpoint` when given. */ -function checkout(endpoint?: unknown): string { +/** A checkout that uses Quest, with a GitHub origin. */ +function checkout(): string { const dir = tempDir(); execFileSync("git", ["init", "-q", dir]); execFileSync("git", ["-C", dir, "remote", "add", "origin", "https://github.com/acme/proj.git"]); writeFileSync(join(dir, "AGENTS.md"), `${REFERENCE_LINE}\n`); - if (endpoint !== undefined) writeFileSync(join(dir, ".quest.json"), JSON.stringify({ records: endpoint })); return dir; } -/** A user's state and config, with a token for `ENDPOINT` unless told otherwise, and a sender running. */ +/** A user's state and config, with a token for `URL_` unless told otherwise, and a sender running. */ function home(token: string | null = "secret"): NodeJS.ProcessEnv { - const env = { XDG_STATE_HOME: tempDir(), XDG_CONFIG_HOME: tempDir() }; + const env = { XDG_STATE_HOME: tempDir(), XDG_CONFIG_HOME: tempDir(), QUEST_KIXEL_URL: URL_ }; mkdirSync(join(env.XDG_STATE_HOME, "quest", "records"), { recursive: true }); writeFileSync(senderPid(env), String(process.pid)); if (token !== null) { mkdirSync(join(env.XDG_CONFIG_HOME, "quest")); - writeFileSync(tokensPath(env), JSON.stringify({ [ENDPOINT]: token })); + writeFileSync(tokensPath(env), JSON.stringify({ [URL_]: token })); } return env; } @@ -52,27 +46,27 @@ const senderPid = (env: NodeJS.ProcessEnv) => join(env.XDG_STATE_HOME!, "quest", const stopped = (cwd: string) => ({ harness: "claude", session: "s1", transcript: transcript(), cwd }); -test("a checkout naming no endpoint, or one without the user's token, queues nothing and says so once", () => { +test("a user without a token queues nothing and is told once", () => { const env = home(null); - const bare = checkout(); - expect(queue(stopped(bare), env)).toEqual({ - notices: [expect.stringContaining("acme/proj names no Kixel Code endpoint in .quest.json")], - queued: false, - }); - expect(queue(stopped(bare), env)).toEqual({ notices: [], queued: false }); - const named = checkout(ENDPOINT); - expect(queue(stopped(named), env).notices).toEqual([expect.stringContaining(`holds no token for ${ENDPOINT}`)]); - expect(queue(stopped(named), env).notices).toEqual([]); + const root = checkout(); + expect(queue(stopped(root), env).notices).toEqual([expect.stringContaining(`holds no token for ${URL_}`)]); + expect(queue(stopped(root), env)).toEqual({ notices: [], queued: false }); // Outside a checkout that uses Quest, nothing is said. expect(queue(stopped(tempDir()), env)).toEqual({ notices: [], queued: false }); }); -test("a checkout's endpoint must be HTTPS, or HTTP to this host", () => { - const env = home(); - expect(() => queue(stopped(checkout("http://kixel.example/records")), env)).toThrow("not an HTTPS URL"); - expect(() => queue(stopped(checkout(7)), env)).toThrow("not a URL"); - expect(queue(stopped(checkout("http://127.0.0.1:8080/records")), env).notices).toEqual([ - expect.stringContaining("holds no token for http://127.0.0.1:8080/records"), +test("the Kixel Quest URL defaults to kixel.quest, and must be HTTPS, or HTTP to this host", () => { + const root = checkout(); + const env = home(null); + delete env.QUEST_KIXEL_URL; + expect(queue(stopped(root), env).notices).toEqual([ + expect.stringContaining("holds no token for https://kixel.quest"), + ]); + expect(() => queue(stopped(root), { ...env, QUEST_KIXEL_URL: "http://kixel.example" })).toThrow("not an HTTPS URL"); + expect(() => queue(stopped(root), { ...env, QUEST_KIXEL_URL: "kixel" })).toThrow("not a URL"); + // A trailing slash names the same Kixel Quest, so the token pairs with it. + expect(queue(stopped(root), { ...env, QUEST_KIXEL_URL: "http://127.0.0.1:8080/" }).notices).toEqual([ + expect.stringContaining("holds no token for http://127.0.0.1:8080,"), ]); }); @@ -110,8 +104,10 @@ function sender( sessions: Session[] | null, during: () => void = () => {}, pulls: object[] = [], + served: string[] = ["acme/proj"], ) { const uploads: { token: string; body: unknown }[] = []; + const asked: string[] = []; const windows: Date[] = []; const slept: number[] = []; const clock = clockOf(env); @@ -119,15 +115,17 @@ function sender( new Response(JSON.stringify(value), { headers: { "content-type": "application/json" } }); const github = async (input: string | URL | Request) => { const url = new URL(String(input)); - if (url.pathname === "/repos/acme/proj") + const named = /^\/repos\/acme\/(proj|other)$/.exec(url.pathname)?.[1]; + if (named) return json({ owner: { login: "acme" }, - name: "proj", + name: named, default_branch: "main", - clone_url: "https://github.com/acme/proj.git", - ssh_url: "git@github.com:acme/proj.git", + clone_url: `https://github.com/acme/${named}.git`, + ssh_url: `git@github.com:acme/${named}.git`, fork: false, }); + if (url.pathname === "/repos/acme/other/pulls") return json([]); if (url.pathname === "/repos/acme/proj/pulls/3") return json(CULPRIT); if (url.pathname === "/repos/acme/proj/pulls") return json([ @@ -173,6 +171,12 @@ function sender( }, interval: 60_000, fetch: (async (input: string | URL | Request, init?: RequestInit) => { + // Kixel Quest says which repositories it serves, at GET /forge, before anything is posted. + if (String(input) === `${URL_}/forge`) { + expect(init?.method).toBe("GET"); + asked.push(String((init?.headers as Record).Authorization)); + return json({ login: "me", repositories: served }); + } expect(String(input)).toBe(ENDPOINT); uploads.push({ token: String((init?.headers as Record).authorization), @@ -182,7 +186,7 @@ function sender( return new Response("", { status: typeof status === "number" ? status : status() }); }) as typeof fetch, }; - return { deps, uploads, windows, slept, clock }; + return { deps, uploads, asked, windows, slept, clock }; } /** A merged PR older than any window, which later PRs name as a culprit. */ @@ -204,7 +208,7 @@ const pending = (env: NodeJS.ProcessEnv) => readdirSync(join(env.XDG_STATE_HOME! test("the sender posts each queued session with its sub-agents, from its transcript's start", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); expect(queue(stopped(root), env)).toEqual({ notices: [], queued: true }); const sessions = [ session("s1", "quest/m0/a"), @@ -226,9 +230,76 @@ test("the sender posts each queued session with its sub-agents, from its transcr expect(pending(env)).toEqual([]); }); +test("a repository Kixel Quest does not serve stays queued, unsent and without token-max, and is said once", async () => { + const env = home(); + const root = checkout(); + queue(stopped(root), env); + const refusing = sender(env, 200, [session("s1", "quest/m0/a")], undefined, [], ["acme/other"]); + expect(await sendPass(refusing.deps)).toEqual([]); + expect(refusing.asked).toEqual(["Bearer secret"]); + expect(refusing.uploads).toEqual([]); + expect(refusing.windows).toEqual([]); + expect(pending(env)).toHaveLength(1); + expect(queue(stopped(root), env).notices).toEqual([ + expect.stringContaining(`${URL_} does not serve acme/proj, so its sessions' records stay queued`), + ]); + // Said once, and it stays queued while Kixel Quest does not serve it; once it does, the session is sent. + await sendPass(refusing.deps); + expect(queue(stopped(root), env).notices).toEqual([]); + const serving = sender(env, 200, [session("s1", "quest/m0/a")]); + expect(await sendPass(serving.deps)).toEqual([ + { endpoint: ENDPOINT, repository: "acme/proj", records: 1, breakages: 0, refused: false }, + ]); + expect(pending(env)).toEqual([]); +}); + +test("a repository Kixel Quest serves is matched by the base its PRs open on, not a fork's origin", async () => { + const env = home(); + const root = checkout(); + execFileSync("git", ["-C", root, "remote", "set-url", "origin", "https://github.com/me/proj.git"]); + queue(stopped(root), env); + const pass = sender(env, 200, [session("s1", "quest/m0/a", { repositories: ["me/proj"] })]); + const github = pass.deps.github; + pass.deps.github = () => ({ + ...github(), + fetch: (async (input: string | URL | Request, init?: RequestInit) => { + const url = new URL(String(input)); + if (url.pathname === "/repos/me/proj") + return new Response( + JSON.stringify({ + owner: { login: "me" }, + name: "proj", + default_branch: "main", + clone_url: "https://github.com/me/proj.git", + ssh_url: "git@github.com:me/proj.git", + fork: true, + parent: { owner: { login: "acme" }, name: "proj" }, + }), + ); + if (url.pathname === "/repos/acme/proj/contents/quest/README.md") return new Response("{}"); + return (github().fetch as typeof fetch)(input, init); + }) as typeof fetch, + }); + const [sent] = await sendPass(pass.deps); + expect(sent).toMatchObject({ repository: "acme/proj", records: 1 }); +}); + +test("a Kixel Quest that cannot say what it serves fails the pass, keeping the queue", async () => { + const env = home(); + queue(stopped(checkout()), env); + const down = sender(env, 200, [session("s1", "quest/m0/a")]); + const fetch = down.deps.fetch; + down.deps.fetch = (async (input: string | URL | Request, init?: RequestInit) => + String(input) === `${URL_}/forge` + ? new Response("", { status: 503 }) + : fetch(input, init)) as typeof globalThis.fetch; + await expect(sendPass(down.deps)).rejects.toThrow("failed GET /forge: HTTP 503; its records stay queued"); + expect(pending(env)).toHaveLength(1); +}); + test("the sender labels each session's steps and sends its split; one no model could label is sent unsplit", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); const file = join(tempDir(), "s1.jsonl"); writeFileSync( @@ -275,7 +346,7 @@ test("the sender labels each session's steps and sends its split; one no model c test("a failed upload stays queued and is said once; a refused token stops sending", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); const failing = sender(env, 500, [session("s1", "quest/m0/a")]); await expect(sendPass(failing.deps)).rejects.toThrow("answered 500"); @@ -295,20 +366,20 @@ test("a failed upload stays queued and is said once; a refused token stops sendi queued: false, }); // A new token is tried again. - writeFileSync(tokensPath(env), JSON.stringify({ [ENDPOINT]: "fresh" })); + writeFileSync(tokensPath(env), JSON.stringify({ [URL_]: "fresh" })); expect(queue(stopped(root), env).queued).toBe(true); }); test("the sender fails loud without token-max, keeping the queue", async () => { const env = home(); - queue(stopped(checkout(ENDPOINT)), env); + queue(stopped(checkout()), env); await expect(sendPass(sender(env, 200, null).deps)).rejects.toThrow("token-max is not installed"); expect(pending(env)).toHaveLength(1); }); test("a failing group backs off, doubling, without widening the others' window", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); const failing = sender(env, 500, [session("s1", "quest/m0/a")]); await expect(sendPass(failing.deps)).rejects.toThrow("tried again in 1 minutes"); @@ -321,25 +392,31 @@ test("a failing group backs off, doubling, without widening the others' window", failing.clock.now += 60_000; expect(await sendPass(failing.deps)).toEqual([]); // Another repository's stop, queued later, is sent from its own start meanwhile. - const other = checkout(ENDPOINT); + const other = checkout(); execFileSync("git", ["-C", other, "remote", "set-url", "origin", "https://github.com/acme/other.git"]); writeFileSync(join(other, "later.jsonl"), `{"type":"user","timestamp":"2026-11-06T11:00:00Z"}\n`); queue({ ...stopped(other), session: "s2", transcript: join(other, "later.jsonl") }, env); - const others = sender(env, 200, [session("s2", "main", { repositories: ["acme/other"] })]); - // The stand-in GitHub knows no acme/other, so that group fails too, after token-max read only its window. - await expect(sendPass(others.deps)).rejects.toThrow("acme/other"); + const others = sender( + env, + 200, + [session("s2", "main", { repositories: ["acme/other"] })], + undefined, + [], + ["acme/proj", "acme/other"], + ); + expect(await sendPass(others.deps)).toHaveLength(1); expect(others.windows).toEqual([new Date("2026-11-06T11:00:00Z")]); - // Once its wait ends, the first group is tried again and sent, and only the other's stop stays queued. + // Once its wait ends, the first group is tried again and sent. failing.clock.now += 60_000; const fixed = sender(env, 200, [session("s1", "quest/m0/a")]); - await expect(sendPass(fixed.deps)).rejects.toThrow("acme/other"); + expect(await sendPass(fixed.deps)).toHaveLength(1); expect(fixed.uploads).toHaveLength(1); - expect(pending(env)).toHaveLength(1); + expect(pending(env)).toEqual([]); }); test("an unreadable backoff file reads as none, so it blocks no group", async () => { const env = home(); - queue(stopped(checkout(ENDPOINT)), env); + queue(stopped(checkout()), env); const failing = sender(env, 500, [session("s1", "quest/m0/a")]); await expect(sendPass(failing.deps)).rejects.toThrow("tried again in 1 minutes"); const dir = join(env.XDG_STATE_HOME!, "quest", "records", "backoff"); @@ -354,7 +431,7 @@ test("an unreadable backoff file reads as none, so it blocks no group", async () test("an upload this version's own parseUpload refuses fails on the host, never posted", async () => { const env = home(); - queue(stopped(checkout(ENDPOINT)), env); + queue(stopped(checkout()), env); const { deps, uploads } = sender(env, 200, [session("s1", "quest/m0/a", { cost: -1 })]); await expect(sendPass(deps)).rejects.toThrow("its own parseUpload refuses"); expect(uploads).toEqual([]); @@ -363,7 +440,7 @@ test("an upload this version's own parseUpload refuses fails on the host, never test("a session token-max no longer lists is dropped and said, without holding back the rest", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); queue({ ...stopped(root), session: "gone" }, env); const { deps, uploads } = sender(env, 200, [session("s1", "quest/m0/a")]); @@ -379,19 +456,17 @@ test("a session token-max no longer lists is dropped and said, without holding b test("a sub-agent is sent only where its own checkout routes it", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); - const other = checkout(ENDPOINT); + const other = checkout(); execFileSync("git", ["-C", other, "remote", "set-url", "origin", "https://github.com/acme/fork.git"]); const sessions = [ session("s1", "quest/m0/a"), - // Live checkouts: this one, another of the same origin and endpoint, one opted out, and another origin's. + // Live checkouts: this one, another of the same origin, and another origin's. session("here", "quest/m0/a", { parent: "s1", cwd: root }), - session("twin", "quest/m0/a", { parent: "s1", cwd: checkout(ENDPOINT) }), - session("optedOut", "quest/m0/a", { parent: "s1", cwd: checkout() }), + session("twin", "quest/m0/a", { parent: "s1", cwd: checkout() }), // A deleted folder routes by the checkout still holding its nearest existing parent. session("hereGone", "quest/m0/a", { parent: "s1", cwd: join(root, "deleted", "sub") }), - session("optedOutGone", "quest/m0/a", { parent: "s1", cwd: join(checkout(), "deleted", "sub") }), // A deleted nested clone of another repository, inside this checkout. session("nestedGone", "main", { parent: "s1", @@ -417,7 +492,7 @@ test("a sub-agent is sent only where its own checkout routes it", async () => { test("an origin that a URL rewrite points at GitHub is read as configured", () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); execFileSync("git", ["-C", root, "remote", "set-url", "origin", "gh:acme/proj"]); execFileSync("git", ["-C", root, "config", "url.https://github.com/.insteadOf", "gh:"]); expect(queue(stopped(root), env).queued).toBe(true); @@ -429,7 +504,7 @@ test("an origin that a URL rewrite points at GitHub is read as configured", () = test("Claude Code's and Codex's Stop queue the session", () => { const env = home(); - const cwd = checkout(ENDPOINT); + const cwd = checkout(); const deps = { env }; const base = { hook_event_name: "Stop", cwd, session_id: "c1", transcript_path: transcript() }; expect(hook({ ...base, background_tasks: [] }, deps)).toBe(""); @@ -439,7 +514,7 @@ test("Claude Code's and Codex's Stop queue the session", () => { expect(hook({ ...base, hook_event_name: "SubagentStop", background_tasks: [] }, deps)).toBe(""); expect(pending(env)).toHaveLength(2); // What it cannot queue, it says instead of failing the hook. - writeFileSync(join(cwd, ".quest.json"), "{"); + writeFileSync(tokensPath(env), "{"); expect(JSON.parse(hook({ ...base, background_tasks: [] }, deps)).systemMessage).toContain( "cannot queue this session's record", ); @@ -451,7 +526,7 @@ test("Claude Code's and Codex's Stop queue the session", () => { test("the sender passes every interval, records its PID, and outlives a failed pass", async () => { const env = home(); writeFileSync(senderPid(env), ""); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); let status = 500; const { deps, uploads, slept, clock } = sender(env, () => status, [session("s1", "quest/m0/a")]); @@ -476,7 +551,7 @@ test("the sender passes every interval, records its PID, and outlives a failed p test("a stop with no sender running queues the session and says so once per outage", () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); writeFileSync(senderPid(env), "999999999"); const down = queue(stopped(root), env); expect(down).toEqual({ @@ -495,7 +570,7 @@ test("a stop with no sender running queues the session and says so once per outa test("a stop queued while its earlier record uploads stays queued", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); const first = sender(env, 200, [session("s1", "quest/m0/a")], () => { if (first.uploads.length === 1) queue(stopped(root), env); @@ -510,7 +585,7 @@ test("a stop queued while its earlier record uploads stays queued", async () => test("a queued session for an endpoint that refused its token is dropped unsent", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); const refusing = sender(env, 403, [session("s1", "quest/m0/a")]); // Queued before the refusal, so queue() could not drop it. @@ -527,7 +602,7 @@ test("a queued session for an endpoint that refused its token is dropped unsent" test("the sender sends the breakages a merged fix in its window names, reading an older culprit", async () => { const env = home(); - queue(stopped(checkout(ENDPOINT)), env); + queue(stopped(checkout()), env); const fix = { ...CULPRIT, number: 8, @@ -563,7 +638,7 @@ test("the sender sends the breakages a merged fix in its window names, reading a test("an incident is posted at once, open until reported again with its culprit, and fails loud", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); const { deps, uploads } = sender(env, 200, []); const report = (pull: number | null) => reportIncident( @@ -600,14 +675,11 @@ test("an incident is posted at once, open until reported again with its culprit, await expect( reportIncident({ cwd: root, id: "x", found: "person", pull: null, at: 0 }, sender(home(null), 200, []).deps), ).rejects.toThrow("holds no token"); - await expect( - reportIncident({ cwd: checkout(), id: "x", found: "person", pull: null, at: 0 }, deps), - ).rejects.toThrow("names no record endpoint"); }); test("a fix that merges after its sessions were sent reaches the store with the next session", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); const fix = (merged: boolean) => ({ ...CULPRIT, @@ -640,7 +712,7 @@ test("a fix that merges after its sessions were sent reaches the store with the test("an incident reported from a subdirectory as `.`, as with no --root, finds its checkout", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); mkdirSync(join(root, "sub")); const { deps } = sender(env, 200, []); const before = process.cwd(); @@ -655,7 +727,7 @@ test("an incident reported from a subdirectory as `.`, as with no --root, finds test("a merged fix naming an open incident sends one record under the incident, once however many name it", async () => { const env = home(); - queue(stopped(checkout(ENDPOINT)), env); + queue(stopped(checkout()), env); const fix = (number: number, updated: string) => ({ ...CULPRIT, number, @@ -728,7 +800,7 @@ function later(env: NodeJS.ProcessEnv, root: string, id: string): Session { test("a session sent before its branch's PR opened is resent with the PR on its group's next pass", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); const first = session("s1", "fix/x", { files: [transcript()] }); const before = sender(env, 200, [first]); @@ -757,7 +829,7 @@ test("a session sent before its branch's PR opened is resent with the PR on its test("a pass that fails before its resends are queued reads their PRs again, even ones older than its sessions", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); const first = session("s1", "fix/x", { files: [transcript()] }); await sendPass(sender(env, 200, [first]).deps); @@ -793,7 +865,7 @@ test("a pass that fails before its resends are queued reads their PRs again, eve test("a resend names every PR its earlier upload did, even one its own window misses", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); const at = (time: string) => Date.parse(`2026-11-06T${time}:00Z`); // s0 starts at 10:00, so the first upload reads PR 7, last updated at 11:00; s1 starts after that update. queue({ ...stopped(root), session: "s0" }, env); @@ -835,7 +907,7 @@ test("a resend names every PR its earlier upload did, even one its own window mi test("a moved session and a sub-agent's fresh branch wait for their own PRs; a PR on an older branch triggers nothing", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); queue(stopped(root), env); const at = (time: string) => Date.parse(`2026-11-06T${time}:00Z`); // s1 moved from quest/m0/a, whose PR 7 is open, to fix/y; its sub-agent works on fix/sub. @@ -889,7 +961,7 @@ test("a moved session and a sub-agent's fresh branch wait for their own PRs; a P test("a remembered session is forgotten once its transcript is gone, unreadable, or unlisted, without a notice", async () => { const env = home(); - const root = checkout(ENDPOINT); + const root = checkout(); const files = [transcript(), transcript(), transcript()]; for (const id of ["gone", "garbled", "unlisted"]) queue({ ...stopped(root), session: id }, env); const sessions = ["gone", "garbled", "unlisted"].map((id, i) => session(id, `fix/${id}`, { files: [files[i]!] })); From c135ba40dcf1bf5f444560edf4ec74a291772e4a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 17 Nov 2026 01:38:03 -0800 Subject: [PATCH 3/4] fix(records): treat a refusal at GET /forge or any upload as the token's, for every group Co-Authored-By: Claude Sonnet 5.5 --- src/cli/forge.ts | 16 +++++++++++++++- src/cli/send.ts | 36 ++++++++++++++++++++---------------- test/send.test.ts | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 17 deletions(-) diff --git a/src/cli/forge.ts b/src/cli/forge.ts index 009d46ab..967ad944 100644 --- a/src/cli/forge.ts +++ b/src/cli/forge.ts @@ -59,6 +59,16 @@ export async function forgeFor(repository: Repository, deps: ForgeDependencies, : new GitHubForge(deps.github()); } +/** Kixel Quest refused the person's token, as a sender must tell from a failure that may pass. */ +export class Refused extends Error { + constructor( + message: string, + readonly status: number, + ) { + super(message); + } +} + /** Kixel Quest's read API, with a person's token. */ export class KixelQuest { #info: Promise | undefined; @@ -149,7 +159,11 @@ export class KixelQuest { throw failed(error instanceof Error ? error.message : String(error)); } if (response.status === 401 || response.status === 403) - throw failed(`it refused the token ${tokensPath(this.deps.env)} pairs with it (HTTP ${response.status})`); + throw new Refused( + failed(`it refused the token ${tokensPath(this.deps.env)} pairs with it (HTTP ${response.status})`) + .message, + response.status, + ); // A malformed wait point is the caller's to fix on any forge; the other reads take no free-form argument, so // their 400 means the CLI and Kixel Quest disagree on the wire, which reading GitHub sidesteps. if (response.status === 400 && path === "/forge/watch") diff --git a/src/cli/send.ts b/src/cli/send.ts index 781b6017..f2d48287 100644 --- a/src/cli/send.ts +++ b/src/cli/send.ts @@ -12,7 +12,7 @@ import { type BreakageRecord, type Finder, type RecordUpload, type Repository, p import { culpritOf } from "./breakage"; import { CLOCK_SKEW, type GitHubDependencies, GitHub } from "../github/client"; import { baseRepository } from "./claims"; -import { KixelQuest } from "./forge"; +import { KixelQuest, Refused } from "./forge"; import { discoveryEnv } from "./git"; import { readRemote, remoteRepository } from "./github"; import { eachLine } from "./messages"; @@ -283,6 +283,8 @@ export async function sendPass(deps: SendDependencies): Promise { } } +const groupId = (p: Pending) => JSON.stringify([p.origin, p.prefix]); + async function sendOnce(deps: SendDependencies, dir: string): Promise { const queued = readdirSync(join(dir, "pending")) .filter((name) => name.endsWith(".json")) @@ -299,7 +301,7 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { } const groups = new Map(); for (const q of queued) { - const id = JSON.stringify([q.pending.origin, q.pending.prefix]); + const id = groupId(q.pending); groups.set(id, [...(groups.get(id) ?? []), q]); } // A group backing off sits the pass out, so it neither reruns token-max nor widens the others' window. @@ -323,6 +325,16 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { github: deps.github, remedy: "its records stay queued", }); + /** Kixel Quest refused the token, which every group shares: nothing more is sent, and what is queued is dropped. */ + const refuseAll = (status: number, repository: string, records: number, breakages: number) => { + refuse(deps.env, url, token); + for (const q of queued) settle(q); + for (const q of queued) clearBackoff(deps.env, groupId(q.pending)); + notes.push( + `${url} refused this host's token (${status}), so it is sent no more session records until the token changes`, + ); + sent.push({ endpoint: `${url}/records`, repository, records, breakages, refused: true }); + }; const bases = new Map(); for (const [id, group] of [...groups]) { const { origin, prefix } = group[0]!.pending; @@ -340,6 +352,10 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { ); if (unserved !== null) notes.push(unserved); } catch (error) { + if (error instanceof Refused) { + refuseAll(error.status, origin, 0, 0); + return finish(deps, dir, sent, failures, notes); + } failed(id, origin, error); } groups.delete(id); @@ -471,20 +487,8 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { const endpoint = `${url}/records`; const response = await post(deps.fetch, endpoint, token, upload); if (response.status === 401 || response.status === 403) { - refuse(deps.env, url, token); - clearBackoff(deps.env, id); - for (const q of group) settle(q); - notes.push( - `${endpoint} refused this host's token (${response.status}), so it is sent no more session records until the token changes`, - ); - sent.push({ - endpoint, - repository: key(repository), - records: upload.records.length, - breakages: upload.breakages.length, - refused: true, - }); - continue; + refuseAll(response.status, key(repository), upload.records.length, upload.breakages.length); + break; } if (!response.ok) throw new Error(`${endpoint} answered ${response.status}: ${(await response.text()).slice(0, 500)}`); diff --git a/test/send.test.ts b/test/send.test.ts index 8832f5c0..3c9575c3 100644 --- a/test/send.test.ts +++ b/test/send.test.ts @@ -284,6 +284,45 @@ test("a repository Kixel Quest serves is matched by the base its PRs open on, no expect(sent).toMatchObject({ repository: "acme/proj", records: 1 }); }); +test("a token Kixel Quest refuses at GET /forge drops the queue and stops sending until it changes", async () => { + const env = home(); + const root = checkout(); + queue(stopped(root), env); + const refusing = sender(env, 200, [session("s1", "quest/m0/a")]); + const fetch = refusing.deps.fetch; + refusing.deps.fetch = (async (input: string | URL | Request, init?: RequestInit) => + String(input) === `${URL_}/forge` + ? new Response("", { status: 401 }) + : fetch(input, init)) as typeof globalThis.fetch; + expect(await sendPass(refusing.deps)).toEqual([ + { endpoint: ENDPOINT, repository: "acme/proj", records: 0, breakages: 0, refused: true }, + ]); + expect(pending(env)).toEqual([]); + expect(queue(stopped(root), env)).toEqual({ + notices: [expect.stringContaining("refused this host's token (401)")], + queued: false, + }); +}); + +test("a refusal at upload stops the pass's other repositories and drops what is queued", async () => { + const env = home(); + queue(stopped(checkout()), env); + const other = checkout(); + execFileSync("git", ["-C", other, "remote", "set-url", "origin", "https://github.com/acme/other.git"]); + queue({ ...stopped(other), session: "s2" }, env); + const refusing = sender( + env, + 403, + [session("s1", "quest/m0/a"), session("s2", "main", { repositories: ["acme/other"] })], + undefined, + [], + ["acme/proj", "acme/other"], + ); + expect(await sendPass(refusing.deps)).toHaveLength(1); + expect(refusing.uploads).toHaveLength(1); + expect(pending(env)).toEqual([]); +}); + test("a Kixel Quest that cannot say what it serves fails the pass, keeping the queue", async () => { const env = home(); queue(stopped(checkout()), env); From a6d744b3d445b66b79ca6c555f3f5c0d317c314e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 17 Nov 2026 01:56:13 -0800 Subject: [PATCH 4/4] fix(records): drop an unserved repository's records after a one-time notice An unserved repository's stops piled up in pending/ and cost a GitHub request every pass to resolve again. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 4 ++-- src/cli/main.ts | 2 +- src/cli/send.ts | 15 ++++++++++----- test/send.test.ts | 15 ++++++--------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e5ca008e..da90130d 100644 --- a/README.md +++ b/README.md @@ -1869,8 +1869,8 @@ it sends nothing, and the hook says so once as a system message. Kixel Quest refuses a whole upload naming a repository it does not index or the sender cannot read, so the sender asks `GET /forge` which repositories it -serves and sends only those. The rest stay queued on this host, unsent, and the -next stop says so once. +serves and sends only those. The rest are dropped from this host's queue, so an +unserved repository costs no GitHub requests, and the next stop says so once. The `Stop` hook [`quest setup`](#configure-your-agent) installs for Claude Code and Codex only queues the session under `$XDG_STATE_HOME/quest/records`. One diff --git a/src/cli/main.ts b/src/cli/main.ts index f245f504..6502615c 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -1280,7 +1280,7 @@ export function main(argv: string[], out: Output): number | Promise { `then again every ${SEND_INTERVAL / 1000} seconds until stopped, at low priority. A record is built as quest usage ` + "builds it, from token-max's sessions on this host since the earliest queued session's first instant and " + "the PRs updated since then, and replaces its earlier copy, so a resend never doubles. A repository Kixel " + - "Quest does not serve, as it says on GET /forge, stays queued, unsent. A sent session whose " + + "Quest does not serve, as it says on GET /forge, has its sessions dropped, said once. A sent session whose " + "latest branch, or a sub-agent's, heads no PR yet is sent again, with its sub-agents, once a pass for its " + "repository reads a PR opened on that branch, until its transcript is gone. A Kixel Quest that " + "refuses the token (401 or 403) is sent nothing more until the token changes; any other failure keeps the " + diff --git a/src/cli/send.ts b/src/cli/send.ts index f2d48287..bdf6d41c 100644 --- a/src/cli/send.ts +++ b/src/cli/send.ts @@ -266,9 +266,10 @@ export async function runSender(deps: SendDependencies, log: (line: string) => v /** * Send every queued session's record once, with those of its sub-agents on this host, one upload per repository, to - * the Kixel Quest the user's token is paired with. A repository Kixel Quest does not serve stays queued, unsent. An - * upload refused for access drops its sessions and says so once; any other failure keeps them queued for the next - * pass, records it for the stop hook, and throws. A session queued again while an upload ran stays queued. + * the Kixel Quest the user's token is paired with. A repository Kixel Quest does not serve has its sessions dropped, + * said once, so it costs no later request. An upload refused for access drops its sessions and says so once; any other + * failure keeps them queued for the next pass, records it for the stop hook, and throws. A session queued again while + * an upload ran stays queued. */ export async function sendPass(deps: SendDependencies): Promise { const dir = stateDirectory(deps.env); @@ -317,7 +318,7 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { ); }; // Records name the repository PRs open on, which a fork's is not. Kixel Quest refuses a whole upload naming one it - // does not index, so a group it does not serve stays queued and sits the pass out, without running token-max. + // does not index, so a group it does not serve is dropped without running token-max. const kixel = new KixelQuest(url, token, { env: deps.env, fetch: deps.fetch, @@ -345,10 +346,14 @@ async function sendOnce(deps: SendDependencies, dir: string): Promise { bases.set(id, repository); continue; } + // Dropped, not kept: an unserved repository's stops would otherwise pile up in `pending/` and cost a GitHub + // request every pass to resolve again. + for (const q of group) settle(q); + clearBackoff(deps.env, id); const unserved = once( deps.env, `unserved:${key(repository)}`, - `${url} does not serve ${key(repository)}, so its sessions' records stay queued on this host.`, + `${url} does not serve ${key(repository)}, so its sessions' records are dropped on this host.`, ); if (unserved !== null) notes.push(unserved); } catch (error) { diff --git a/test/send.test.ts b/test/send.test.ts index 3c9575c3..62e407ee 100644 --- a/test/send.test.ts +++ b/test/send.test.ts @@ -230,7 +230,7 @@ test("the sender posts each queued session with its sub-agents, from its transcr expect(pending(env)).toEqual([]); }); -test("a repository Kixel Quest does not serve stays queued, unsent and without token-max, and is said once", async () => { +test("a repository Kixel Quest does not serve is dropped, unsent and without token-max, and is said once", async () => { const env = home(); const root = checkout(); queue(stopped(root), env); @@ -239,18 +239,15 @@ test("a repository Kixel Quest does not serve stays queued, unsent and without t expect(refusing.asked).toEqual(["Bearer secret"]); expect(refusing.uploads).toEqual([]); expect(refusing.windows).toEqual([]); - expect(pending(env)).toHaveLength(1); + expect(pending(env)).toEqual([]); expect(queue(stopped(root), env).notices).toEqual([ - expect.stringContaining(`${URL_} does not serve acme/proj, so its sessions' records stay queued`), + expect.stringContaining(`${URL_} does not serve acme/proj, so its sessions' records are dropped`), ]); - // Said once, and it stays queued while Kixel Quest does not serve it; once it does, the session is sent. + // Said once, and a later stop is dropped without a notice. + queue(stopped(root), env); await sendPass(refusing.deps); - expect(queue(stopped(root), env).notices).toEqual([]); - const serving = sender(env, 200, [session("s1", "quest/m0/a")]); - expect(await sendPass(serving.deps)).toEqual([ - { endpoint: ENDPOINT, repository: "acme/proj", records: 1, breakages: 0, refused: false }, - ]); expect(pending(env)).toEqual([]); + expect(queue(stopped(root), env).notices).toEqual([]); }); test("a repository Kixel Quest serves is matched by the base its PRs open on, not a fork's origin", async () => {