DocsEnforcement: PRs, issues and reviews

Enforcement: PRs, issues and reviews

The kit checks three things: the PR (size, scope, pattern checks, title and body), the issue (title and body), and the review (the kit writes the review body itself). The same code runs in three places. Only the CI check blocks a merge for everyone.

Where What it covers Who it covers Can it be skipped?
CI: the desk workflow PR gates and PR format (a required check); issue format (a label and a comment) Everyone: every client, gh, the GitHub web page No, when the branch rule requires desk / pr
Client hooks gh pr create, gh pr edit --body, gh issue create, gh issue edit from an AI agent; every git, jj and `gh issue pr label
The issue form The fields of a new issue on the web page Everyone who uses the web page No: blank_issues_enabled: false turns off blank issues
git push hook The gates, before a push A person who ran desk install --git-hook Yes: git push --no-verify

The guard

desk install writes one hook in each client: desk hook guard --client <id>. The guard runs the gh checks first, then five rules for an agent session. It reads the tool call once and makes no network call. desk hook gh stays as an alias.

Each rule is on or off for you (#205). The table shows the rules and their defaults. The codeindex rule is off by default; every other rule is on.

Rule Default What it does
desk-store on refuses a git, jj or gh call that goes around the desk server of a repository (see "A repository on the desk server")
git-mcp on refuses a tool of a git or GitHub MCP server where a shell git or gh call is refused
workspace on refuses a write in a checkout that the workspace rule does not allow (see "The workspace")
gh-format on checks the body of a PR or an issue that gh creates or edits (see "PRs" and "Issues")
hooks, wait, codeindex, role, context on, on, off, on, on the rules in the table below
decisions on refuses a code write or a commit before the session read the decisions of the owner (#178)
local-test on refuses a full test, lint or build in a desk work folder, and names desk try (#234)
landing on tells the session that a landing of its work folder did not stay on main (#166)

Set a rule in one of these places. All of them change the same setting of your identity on the desk server:

  1. The CLI: desk guard rules lists the rules, and desk guard set <rule> on|off|default changes one.
  2. The MCP server: the tools guard_rules and guard_set.
  3. The UI: the page Hook rules (/settings/guard).
  4. The HTTP API: GET /v1/me/guard, and PUT /v1/me/guard with {"rules": {"<rule>": true | false | null}}. null removes the setting.

The hook runs on every tool call, so it never calls the server. It reads a local copy, $XDG_STATE_HOME/desk/guard-rules.json. desk guard set and desk guard sync write the copy. When the copy is older than 10 minutes, the hook starts desk guard sync in the background, and a later call uses the new copy. A change in the UI or with MCP thus reaches a session in 10 minutes, or at once after desk guard sync. With no desk server, the key guard of ~/.config/desk/policy.json holds the setting, for example {"guard": {"codeindex": true}}, and desk guard set writes it there. The order is: the copy of the server setting, then the policy, then the default. An unknown rule name in the policy is an error, and the hook refuses each call with a message that names it.

The folder of a session for codeindex is the work of codeindex itself: its plugin hook writes it (munhq/codeindex#2).

Rule Refuses The message names
wait a shell command with sleep N where N is more than 30 s, sleep infinity, or a loop (until, while or for) that has sleep in its body the background run of the client, desk land --wait, kubectl rollout status --timeout=<t>, gh run watch
codeindex when the client has codeindex: a search (grep, rg) of a source path, a whole-file cat, less, more, bat, nl or tac of a source file, a whole-file Read of a source file, and the Claude Grep tool on a source path, in the session folder or in any project find_symbol, find_callers, read_symbol, get_outline, search; for a project outside the session folder, also index_workspace with the project folder
role in a manager session: a build or a test (cargo, buck2, go test, bun test, npm test, npm run build), a file edit tool, and ssh with an inline script (python3 -, sh -c, a heredoc) give the task to a worker, or read a check with desk runs list, desk runs view <id> and desk runs log <id>
hooks a write into the hook or plugin files of the clients: the folder ~/.config/opencode/plugins, the settings.json of each Claude Code home, ~/.codex/hooks.json, ~/.cursor/hooks.json, ~/.gemini/config/hooks.json, and the Hermes config.yaml test a plugin in a private copy with XDG_CONFIG_HOME=<temp folder> opencode run --standalone, and change a hook with desk install, chat-recall install-hooks or sealkeep install
local-test in a folder under a desk work folder (a folder that holds .desk-work): a full test, lint or build (npm test, pnpm test, yarn test, bun test, node --test of a folder, cargo test, cargo clippy, cargo build, buck2 test, buck2 build, go test ./..., pytest with no file, zig build test) run desk try in the work folder: the runners of the repository run the checks of its tree with no landing, and desk try --only <check> runs one check. One test of one file stays allowed.
context nothing: it adds a notice above 200k tokens, once for each 50k step write the state to the issue and the board, then continue in a new session from recall_smart_resume

sed -n a,bp, head -n, a Read with an offset or a limit, and a file that is not source (a log, JSON or Markdown) are allowed. A path is source when it has a source extension or a part that is a source folder (src, lib, app, test and others). The codeindex rule acts only in a client whose config registers codeindex. It acts on a source path inside the folder where the session started (the cwd of the hook input, and the session folder in OpenCode), and on a source path in any project: a folder with .git, .desk-work or a build file (Cargo.toml, package.json, go.mod, pyproject.toml, build.zig, pom.xml, deno.json). A session moves to another project, so the start folder is no exemption. A path in a dependency or build folder (node_modules, .cargo, target, vendor, .venv) and a path that no project holds pass. A command passes as a whole when one of its source paths is in no project.

The role of a session. Run desk role manager, desk role worker or desk role none. The command takes --session <id> and --client <id>. Without --session it writes no state, because only the guard knows the session of the call. The guard sees the command in a tool call, records the role before the command runs, and keeps it in $XDG_STATE_HOME/desk/roles/<client>-<session>.json. The default of a session is none.

The context notice. Claude Code and Codex give the transcript path and a non-blocking output (hookSpecificOutput.additionalContext). The guard reads the newest usage line in the last 512 KB of the transcript. The other clients have no non-blocking output, so the context rule is off there.

The hooks rule. A plugin in a client hook folder runs in every new session of that client. A plugin that never returns stops the client, so the guard refuses the write instead of the next session. It reads the write target of the edit tools, and of the shell commands >, >>, tee, cp and mv. The installer commands desk install, chat-recall install-hooks and sealkeep install are allowed. Test a new plugin in a private copy of the config: XDG_CONFIG_HOME=<temp folder> opencode run --standalone. A whole client file is protected, and not only its hooks key, because a redirection replaces the file.

The deny log. Each deny appends one JSON line to $XDG_STATE_HOME/desk/guard.log. The line holds the time, the rule, the client and the session. The owner can count the refusals of each rule each week.

A company folder. The key company in ~/.config/desk/policy.json lists the folders of a company or a client, for example {"company": ["/home/user/code/company"]}. In a folder under one of them, the guard runs only the gh checks. The wait, codeindex, role, local-test, hooks and context rules do not act there.

OpenCode. OpenCode has no hook file. desk install writes $XDG_CONFIG_HOME/opencode/plugins/desk-guard.js (by default ~/.config/opencode/plugins/desk-guard.js). The plugin sends {tool, args, sessionID, cwd} to the guard from tool.execute.before and throws the message when the guard refuses the call.

PRs

  1. desk init writes .github/workflows/desk.yml. On each PR event it runs the munhq/desk action, which runs desk ci:
    • the size gate (CHK-C3): the changed lines in existing files, warning at 1,500 and failure at 5,000 by default. New files and tests do not count, unless size.newFilesFail or size.testsFail sets a limit for them. The size/override label turns the failure into a warning;
    • the mixed-scope gate (CHK-C4) and every check in config.json, on the added lines;
    • the PR format: <type>(<scope>): <summary>, **Type:**, Why, What, How tested, Review focus, and Split above the size warning. With pr.requireIssueState: true, a PR that links an issue (**Issue:** #n or a closing word) also needs ## Current state of the issue and ## Blockers and decisions, each with text; desk pr template writes both;
    • an annotation on each failed line, and a summary in the run.
  2. In the branch rules of the default branch, make desk / pr a required check. A PR then cannot merge until the gates and the format pass.
  3. pr-format: warn in the workflow reports the format and does not block, for a first trial.

A maintainer adds the size/override label to a PR that cannot be split; the check runs again on the label event.

Issues

GitHub cannot refuse an issue, so the kit makes the format the easy path and marks the rest:

  1. .github/ISSUE_TEMPLATE/task.yml is an issue form: Type, Priority and Size are drop-downs, and Why, Goal, Proposal and plan, and Done when are required fields. config.yml turns off blank issues on the web page.
  2. On each opened or edited issue, the workflow checks the body. An issue that does not follow the format gets the needs-format label and one comment that lists the problems. When the author fixes the issue, the label goes away and the comment says that the format is right. A correct issue gets the label type: <type>.
  3. desk issue create checks the issue before gh issue create, and the client hooks refuse gh issue create with a bad body.

Four settings of issue in config.json make the check stricter. Each one lists the issue types that it applies to, and all of them default to none:

Key An issue of these types needs
requirePriority **Priority:** High|Medium|Low in the header (or the Priority field of the form), so that desk state can rank it
requireEpic its goal: **Epic:** <name> in the header, a field Epic, or a line Part of #<n>
requireResearch the section ## Research with a source (a link, an issue or PR number, [code: file :: symbol]), or the line No research needed: <reason>
gatePrs (true or false) a PR that links an open issue with a fault fails its own check, and names the issue

The owner's policy file takes the first three keys under issue, for every repository under its paths. desk init writes requirePriority for feature, bug and design issues and gatePrs: true into a new config. issue.stallDays is the days after which a report of work done that no session validated comes back among the work to do in desk state, and the close sweep validates the landing and closes the issue: 3 by default, and 0 turns the guard off.

desk issue audit [--repo <owner/repo>] [--json] [--fail] lists the open issues that do not follow the format, with the faults and the number of issues for each fault. desk state marks such an issue "not ready", with its rank kept, and an agent fixes the issue before it builds. The MCP tool is issue_audit.

The format follows the owner's backlog format: **Type:** (or the Type field), Why, Goal, Options, Proposal and plan, Done when, Links. issue.types and issue.sections in config.json change the types and the required sections.

Reviews

The kit writes the review body, so it is always in one format: the verdict, the counts, the checks, and each finding with severity, rule id, file and line, proof, and the verification result. post sends only that body and its inline comments, as a COMMENT review that never approves or blocks. Human review comments are not checked.

The owner's words

With review.requirements.enforce on, the PR check and the hook require the section ## Owner's request in a PR of a type in review.requirements.prTypes, and they check each quote against the owner's prompts on the machine. A CI runner has no prompts, so it checks the section and not the quotes. The review then checks the change against the owner's prompts, the linked issues and the specs. See requirements.md.

The merge

desk merge --pr <n> (MCP tool merge) merges a PR only when all of these hold, and it names each rule that fails:

Rule What it checks
review A review run exists for the current head of the PR, and its reviewer is not the author: a headless engine, or a name in the findings that is not the PR author and not "author", "self", "session", "main", "main session", "pr author" or "me". A new commit makes the run stale.
verdict The verdict of the run is "Ready to merge", with the decisions of the owner applied.
findings No finding is open. Decide each one with desk decide <id> --accept or --reject --reason <text>.
quotes The PR body has the section "Owner's request" when its type needs one, and each quote in it is found in the owner's words (the check of desk pr check).
checks The checks of the PR passed or were skipped, and none is running. A check that ran more than once counts by its newest run, so a cancelled or failed older run does not block the merge; when two runs start together, the worse one counts. A PR with no checks fails, because its checks may not have started; merge.requireChecks: false allows it for a repository that has no CI.

The run folder is searched in .desk/out/pr-<n>/ of this checkout and of the main checkout. --run <dir> names a run folder in another place. The merge uses --match-head-commit <head>, so GitHub refuses it when a commit arrived after the review. merge.method (merge, squash or rebase; default merge) sets the method.

A repository on the desk server has no pull requests and no desk merge. desk land puts a change on main, the checks with stage: "land" run before it, and the other checks run after it; a check that fails on main starts a bisect and an automatic revert. docs/runs.md describes the flow.

desk merge reads .desk/config.json at the base branch (origin/main by default) and not in the working tree, so a PR cannot turn off a rule of its own merge or add a command that runs after it. A base branch with no config gives the defaults: no command after the merge.

After a merge, the commands of merge.after in .desk/config.json run, one after the other, in the main checkout of the repository. For desk itself they update the checkout and run ./install.sh. A command that fails stops the rest and gives exit code 1; the PR stays merged. The command writes merge.json into the run folder with what ran. --dry-run checks the rules and merges nothing.

The workspace

A repository can ask that all work happens in linked git worktrees, so that a session never writes into the checkout that other sessions read from. Set workspace.worktrees in .desk/config.json:

Value Rule
off No check. This is the default.
auto The rule applies when the repository has a linked worktree already.
required The rule applies to every checkout of the repository.

The owner's policy file ~/.config/desk/policy.json takes the same key, {"workspace": {"worktrees": "auto"}}, for every repository under its paths. The stricter value of the config and the policy applies.

When the rule applies:

  1. desk workspace fails on a detached HEAD, except while a rebase or a bisect is in progress: git detaches HEAD in both, and the commands that continue them must run. In the primary checkout it also fails when the checkout holds work: a branch other than the base branch, a change in a tracked file, or commits that the base does not have. Untracked files do not count.
  2. desk preflight adds the blocking check CHK-WT with the same text.
  3. The hook desk hook workspace refuses the tools Write, Edit, MultiEdit and NotebookEdit of Claude Code for a file in a detached checkout (outside a rebase or a bisect) or in the primary checkout. desk install adds it to settings.json.
  4. The hook desk hook guard also refuses a shell command that changes a checkout with git (commit, add, merge, rebase, cherry-pick, am, apply, stash, revert, restore, rm, mv, reset --hard, checkout -b, switch -c, branch -f) when the command runs in such a checkout. It follows cd <folder>, git -C <folder>, a subshell and the text of sh -c "...", and it skips the options of git that take a value, such as -c. A leading ~, $HOME and ${HOME} in a folder are written out.

If .desk/config.json does not load, the file hook lets the edit through, so that the file can be repaired; desk doctor and desk preflight report the error. In the primary checkout desk workspace prints "workspace ok" when the checkout holds no work, and the hooks still refuse an edit and a git commit there.

Each refusal names the command that makes the worktree: git worktree add -b <new-branch> <folder> origin/main. The hook reads the folder of the command. It does not read a folder that a variable or a command substitution builds.

A repository on the desk server

A repository with "store": "server" in .desk/config.json, and a work folder of the desk client (a folder with .desk-work), keep their code and issues on the desk server. GitHub holds only a copy. The rules:

  1. The hook desk hook guard refuses every git and jj call, and gh issue, gh pr, gh label, gh api and gh project. Each refusal names the desk command to use. A git checkout of such a repository is a copy: the agent makes a work folder with desk checkout and works there.
  2. The hook finds a program in the place of a command: at the start, or after ;, &, |, (, a backtick or a line break, after any VAR=value. grep git is not a git call. The hook reads the folder where the command starts, so a command that starts there and runs git in another folder is refused too: start it in that folder.
  3. The CLI refuses the commands that read GitHub: state, merge, threads, decisions, questions, learn, ci, requirements, and pr except pr template and pr check.
  4. desk review --pr <n>, desk report, desk verify and desk post run on a proposal of the server. docs/server.md gives the steps.
  5. The issue commands run on the server: desk issue view, list, create, edit, comment, attach, attachment, questions and check. desk feedback --issue <n> posts its comment on the server, and desk feedback --pr <n> is refused, because a proposal on the server holds reviews and no comments. desk pr create, desk pr view and desk pr merge run on the server: a proposal is the PR of the server (#61).
  6. The skill desk-work gives the agents the steps: desk checkout, desk status, desk change, desk land and desk sync.
  7. The paths of ~/.config/desk/policy.json extend rule 1 to the repositories of those folders with no store server config yet: the hook refuses the same calls there and names the desk server and desk checkout. The point is the copy step: an agent that reaches for git in a repository that the policy puts on desk makes a tree that no one sees. A repository of serverExclude stays on GitHub, and the policy keys paths, server and serverExclude are the authority, also when .desk/config.json is absent.
  8. A folder of the policy paths resolves the server of the policy itself, so the commands of rules 3 and 5 work there with no work record: the repository name comes from the origin remote. A folder that has neither a work record nor a server in the policy gets a refusal that names desk checkout and repo_path, not "needs a subcommand".
  9. The tools of a git or GitHub MCP server (mcp__git__*, mcp__github__*, mcp__gitlab__* in Claude Code, Codex and Hermes; github_* in OpenCode) are the same calls as a shell git or gh with another name, so the hook refuses them where it refuses the shell: in a work folder, in a repository with store server, and under the policy paths. A git tool is judged by its repo_path, else by the folder. A GitHub tool is judged by the repository that its owner and repo (or repo:owner/name in a query) name, and a repository of serverExclude goes through. A GitHub tool that names no repository (a search, a user lookup) is a read and goes through; create_repository and fork_repository are refused. The refusal names the desk command to use. desk install writes the tool names into the matcher of Claude Code and Hermes, so the guard sees these calls; OpenCode and Codex send every tool. Cursor and Antigravity hook the shell only, so these tools are not checked there.

The AI review in CI

.github/workflows/desk-ai.yml runs the munhq/desk/review action on each ready PR, with the secret OPENROUTER_API_KEY and the variable DESK_MODEL (an OpenRouter model id).

  1. The action installs OpenCode (the opencode-version input, default 1.18.33) and runs desk review --pr <n> --profile all --engine opencode --repo-access --model openrouter/<model>. Each profile and each part of the diff gets its own OpenCode reviewer, and a verifier checks each blocker and important finding. The reviewers can use the read, grep, glob and list tools in a read-only checkout of the PR head. The shell, edits, web fetch and MCP tools are off.
  2. If the OpenCode run fails, the action runs --engine openai against base-url (default OpenRouter) with the same model. That model gets the diff and the review packet as text only.
  3. engine: openai skips OpenCode.

The judge. Before the review, one call to a decision model (judge-model, default typesafe/jev-1.13 on OpenRouter's Decisions API, about $0.00002 a call) reads the PR title, the body and the changed paths with their line counts. It gets no code. It rates the risk (none, low, medium, high) and gives each profile except full the probability that the PR needs it. The judge input sets what happens next:

judge What runs
shadow (default) full and every profile whose paths match. The review shows the judge's choice under the title, and judge.json in the run folder records it, so its choices can be compared with the reviews.
decide full and each profile with a probability of 0.5 or more. A PR with a probability of 0.85 or more for "no risk" gets no model review.
off No judge call. full and every profile whose paths match.

If the judge call fails, every matching profile runs. Use shadow until the recorded choices show that decide drops no profile that found a real problem.

The job writes the report to the job summary, uploads the run folder as the desk-ai-review artifact, and runs desk post --ai. That posts one GitHub review (event COMMENT, marked <!-- desk:ai-review -->):

  1. One numbered line for each finding, blockers first: the severity, a title of at most 150 characters, a link to the line, and a link to the full report.
  2. The full text of each finding, folded under "Details".
  3. An inline comment on each finding in the diff.

A finding that an earlier review of the kit holds is not posted again, and a push with no new finding posts nothing. OpenCode gets small_model set to the review model, so it calls no other model. Findings do not fail the job. A failed model call does. The job is not a required check.

The GitHub setting for the action

munhq/desk is private. For other repositories of the organization to use its action, its Actions settings must allow access from repositories in the organization (Settings → Actions → General → Access). An organization admin sets it once.