diff --git a/README.md b/README.md index e900d943..95901d5f 100644 --- a/README.md +++ b/README.md @@ -660,17 +660,21 @@ Kixel Quest's queue lands by fast-forwarding the base and drops once the head moves, so it takes no `--squash`, `--rebase`, or `--direct`. `quest review` records its rounds in the PR body there too. -Where `gh` cannot reach, `quest pr` opens, edits, and comments on PRs and -resolves review threads, with `gh pr`'s flags; it works on GitHub too: +Where `gh` cannot reach, `quest pr` reads, opens, edits, and comments on PRs +and resolves review threads, with `gh pr`'s flags; it works on GitHub too. +`quest pr view` prints a PR's body, comments, reviews, and every review thread +with its comments, read from the forge itself rather than an index: ```sh +quest pr view 12 quest pr create --title "Plan the forge" --body-file .tmp/body.md --draft quest pr edit 12 --body-file .tmp/body.md quest pr comment 12 --thread --body "Fixed in the head." quest pr resolve 12 ``` -The writes are `POST /forge/`, beside the reads: `open`, `close`, +Its read is `POST /forge/view`, answering the same `{"value", "asOf"}`. The +writes are `POST /forge/`, beside the reads: `open`, `close`, `edit`, `comment`, `resolve`, `hold`, `ready`, `release`, and `pick`, each answering `{"value", "asOf"}` with `asOf` null. A 409 with `{"error"}` refuses the write as things stand, such as a PR another session holds, a second open @@ -2428,7 +2432,14 @@ hook on shell commands and file edits denies, with the rule as the reason: or `comment`, or `gh api` with a `body` field) without a `(Written by ...)` line; - a scratch file written under `/tmp`, outside the checkout, by a redirection, - `tee`, `mkdir`, `mktemp`, `git clone` or `worktree add`, or a file edit. + `tee`, `mkdir`, `mktemp`, `git clone` or `worktree add`, or a file edit; +- in a checkout whose origin is on [Kixel Quest](#work-on-a-repository-kixel-quest-hosts), + a `gh pr` or `gh api` call aimed at that repository, which `gh` cannot reach: + one naming no repository, through `--repo`, `GH_REPO`, a PR URL, or an + endpoint's `repos//`, or naming that one by its owner and name + or on Kixel Quest; a URL or host elsewhere, such as github.com, names + another repository. The reason names the `quest` command to run, such as + `quest pr view`. For Claude Code, `Stop` and `SubagentStop` hooks refuse to end an agent's turn while a `quest gate` command it started still runs in the background, naming diff --git a/docs/context.md b/docs/context.md index 2e9be509..32ed19a4 100644 --- a/docs/context.md +++ b/docs/context.md @@ -93,3 +93,4 @@ When the repository has a `quest/` directory, it plans work as quests: Markdown - Push with an explicit refspec, `git push refs/heads/:refs/heads/`: a bare branch name can push to the base instead, as under `push.default=upstream` when the branch tracks it. - Never rebase or force-push, even a branch only you hold; merge the base instead, when the branch conflicts with it or a landing step refuses the head. - Put scratch files, such as PR bodies, logs, patches, helper scripts, and temporary clones, in the checkout's `.tmp/`, never `/tmp`, so they disappear with the worktree. +- On a repository Kixel Quest hosts, `gh` cannot reach its PRs: use `quest pr view`, `create`, `edit`, `comment`, and `resolve`, and `quest status`, `ready`, and `merge`. diff --git a/quest/m1/kixel-pull-files.md b/quest/m1/kixel-pull-files.md new file mode 100644 index 00000000..7d51d8cd --- /dev/null +++ b/quest/m1/kixel-pull-files.md @@ -0,0 +1,19 @@ +# [S] Open PRs' changed files for repositories Kixel Quest hosts + +## Goal + +Before making a new quest on a repository Kixel Quest hosts, an agent lists +the files each open PR changes through `quest`, as the guide's Creation +section asks, without `gh`. + +## Plan + +The guide (`assets/AGENTS.md`, Creation) has agents list open PRs' files with +`gh pr list --limit 1000 --json number,url,files` and `gh api` for the rest. +On a repository Kixel Quest hosts, `quest hook` denies both, and no `quest` +command lists them. + +Recommendation: give the `pulls` read each open PR's changed paths, print +them with a `quest pr list --files` modeled on `gh pr list`, and have the +guide name it in place of the `gh` commands. Keeping this quest authorizes +that guide edit. diff --git a/quest/m1/kixel-pull-reads.md b/quest/m1/kixel-pull-reads.md deleted file mode 100644 index 40401d41..00000000 --- a/quest/m1/kixel-pull-reads.md +++ /dev/null @@ -1,32 +0,0 @@ -# [M] PR bodies and comments for repositories Kixel Quest hosts - -## Goal - -An agent working on a repository Kixel Quest hosts reads a PR's body, -comments, and reviews through `quest`, and is steered to `quest pr` when it -reaches for `gh`, so `/quest-iterate` and `/quest-review` run there without -`gh`. - -## Plan - -The forge writes gave `quest pr` its create, edit, comment, and resolve, but -an agent still reads a PR's body and discussion with `gh pr view`, which -cannot reach Kixel Quest, and nothing tells it to use `quest pr` instead. - -- Add a `view` read to the forge interface and its wire, typed in - `quest/core` like the others: the body, title, comments, and reviews, as - `quest pr view ` prints them. GitHub's backend reads them as `gh pr view - --comments` shows them. -- `quest hook` denies `gh pr` and `gh api` calls in a checkout whose origin - is on Kixel Quest, naming the `quest pr` command to run, through a checked - rule in `src/cli/rules.ts` that adds one line to the Checked section `quest - context` prints: ✅ hook denial with a Checked line (rejected: a prose rule in - `quest context` only; neither). The maintainer settled this in - [moq-dev/quest#769](https://github.com/moq-dev/quest/pull/769#issuecomment-6944655958), - since an agent without it tries `gh`, fails, and has no pointer to the - command that works. - -Tests: against the fake Kixel Quest, `quest pr view` prints a PR's body and -comments; and the hook denies `gh pr view` in a checkout whose origin is on -Kixel Quest while it lets the same call through on a GitHub checkout. - diff --git a/src/cli/forge.ts b/src/cli/forge.ts index 465734bc..b1741954 100644 --- a/src/cli/forge.ts +++ b/src/cli/forge.ts @@ -17,6 +17,7 @@ import { type Opening, type Pick, type PullRequest, + type PullView, type Repository, type Status, type Watch, @@ -305,6 +306,10 @@ export class KixelQuestForge implements Forge, ForgeWrites { }; } + view(pull: PullRequest): Promise> { + return this.kixel.call("view", { pull }); + } + async open(opening: Opening): Promise { return (await this.kixel.call("open", { opening })).value; } diff --git a/src/cli/hooks.ts b/src/cli/hooks.ts index 04db36ab..12d81961 100644 --- a/src/cli/hooks.ts +++ b/src/cli/hooks.ts @@ -341,7 +341,7 @@ export function hook(input: unknown, deps: HookDependencies = { env: process.env ) throw new Error("expected a PreToolUse hook's JSON input with tool_name and tool_input"); if (!usesQuest(value.cwd)) return ""; - const rules = broken({ tool: value.tool_name, input: value.tool_input, cwd: value.cwd }); + const rules = broken({ tool: value.tool_name, input: value.tool_input, cwd: value.cwd }, deps.env); if (rules.length === 0) { if (value.tool_name === "Bash" && typeof value.tool_input.command === "string") logCall( diff --git a/src/cli/main.ts b/src/cli/main.ts index c6bc9012..208fbf0c 100644 --- a/src/cli/main.ts +++ b/src/cli/main.ts @@ -45,6 +45,7 @@ import { } from "./agent"; import type { ForgeWrites, Hold, Repository } from "../core"; import { GitHubWrites } from "./writes"; +import { GitHubForge } from "../github/forge"; import { type ClaimDependencies, held, openDrafts, reach, target, upstream, upstreamRefs } from "./claims"; import { type ForgeDependencies, @@ -114,7 +115,7 @@ import { KIXEL_QUEST_URL, kixelUrl, 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"; -import { statusLines } from "./status"; +import { statusLines, viewLines } from "./status"; import { TOKEN_MAX_MISSING, daysBefore, runTokenMax, usage, usageDependencies, usageLines } from "./usage"; import { waitForActivity, WaitTimeout } from "./wait"; import { version } from "./version"; @@ -946,13 +947,33 @@ export function main(argv: string[], out: Output): number | Promise { const pr = program .command("pr") - .summary("Open, edit, and comment on pull requests, and resolve their review threads") + .summary("Read, open, edit, and comment on pull requests, and resolve their review threads") .description( - "Open, edit, and comment on pull requests, and resolve their review threads, on GitHub or on a " + + "Read, open, edit, and comment on pull requests, and resolve their review threads, on GitHub or on a " + "repository Kixel Quest hosts, where gh cannot reach. Flags follow gh pr's.\n\n" + FORGE_WRITES + "Exits 0 when done, 3 when refused, 2 for invalid arguments, and 1 for other failures.", ); + pr.command("view") + .description( + "Print a PR's title, body, comments, reviews, and review threads with their comments, resolved ones " + + "included. Plain output prints url, state, draft, author, and title lines; then each post after a -- " + + "line, as a header line and its text: the body under a body line, each comment " + + "(comment