Repo owners can now mint a token limited to ONE repo and a chosen scope (read / pr / full) instead of handing an agent their full account token -- via one MCP tool call (mint_agent_token) or the plain /agent-tokens settings page. scopeGuard.mjs enforces the fence on every request before it reaches the real Rithub API; a pr-scope token can open branches/PRs/ issues/comments but never merge, touch another repo, or mint itself a broader token (the 5 token-management tools are ownerOnly and refused outright for an agent-scoped session). enable_agent_on_repo turns on the second half: labelling any open issue "agent" makes bin/agent-worker.mjs (a separate pm2 poller) read the issue, call the Anthropic Messages API for a structured fix, commit it on a new branch, and open a pull request that closes the issue -- commenting on the issue when it starts and when it opens the PR. The worker uses the same scope-guarded client a human-held token would be, so it can't exceed the fence either. Verified end to end against production: a throwaway mail.tm user, a real one-line bug, mint/list/revoke (plus a confirmed-blocked self-escalation attempt), enable_agent_on_repo, an agent-labelled issue, one real pollOnce() run against the live Anthropic API that produced a correct one-line fix, a PR that closed the issue on merge, and the REST /agent-tokens mint/list routes -- all cleaned up after (repo deleted, user purged, token deleted, mail.tm inbox deleted). 27/27 unit tests pass. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
72 lines
3.4 KiB
HTML
72 lines
3.4 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Rithub — new agent token</title>
|
|
<style>
|
|
:root { color-scheme: light dark; }
|
|
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; max-width: 480px; margin: 64px auto; padding: 0 20px; color: #1d1d1f; }
|
|
h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
|
|
p.sub { color: #6e6e73; font-size: 14px; margin: 0 0 28px; }
|
|
label { display: block; font-size: 13px; font-weight: 500; margin: 16px 0 6px; }
|
|
input, select { width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1px solid #d2d2d7; border-radius: 10px; font-size: 14px; background: transparent; color: inherit; }
|
|
button { width: 100%; margin-top: 24px; padding: 12px; border: none; border-radius: 10px; background: #0071e3; color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; }
|
|
button:disabled { opacity: 0.5; cursor: default; }
|
|
#result { margin-top: 20px; font-size: 13px; white-space: pre-wrap; word-break: break-all; }
|
|
#result.error { color: #d70015; }
|
|
code { background: rgba(0, 0, 0, 0.06); padding: 2px 6px; border-radius: 6px; font-size: 12px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>New agent token</h1>
|
|
<p class="sub">Limited to one repo and a chosen scope. Hand this to an agent instead of your full account token.</p>
|
|
<form id="f">
|
|
<label for="rtoken">Your Rithub token</label>
|
|
<input id="rtoken" type="password" autocomplete="off" required placeholder="your existing Rithub access token" />
|
|
<label for="owner">Repo owner</label>
|
|
<input id="owner" type="text" required placeholder="e.g. caelum0x" />
|
|
<label for="repo">Repo name</label>
|
|
<input id="repo" type="text" required placeholder="e.g. railyard" />
|
|
<label for="scope">Scope</label>
|
|
<select id="scope">
|
|
<option value="read">read — view only</option>
|
|
<option value="pr" selected>pr — view + open branches/PRs/issues/comments</option>
|
|
<option value="full">full — everything except delete/transfer/settings</option>
|
|
</select>
|
|
<label for="ttl">Expires in (hours)</label>
|
|
<input id="ttl" type="number" value="168" min="1" max="2160" />
|
|
<button type="submit">Create token</button>
|
|
</form>
|
|
<div id="result"></div>
|
|
<script>
|
|
const form = document.getElementById("f");
|
|
const result = document.getElementById("result");
|
|
form.addEventListener("submit", async (e) => {
|
|
e.preventDefault();
|
|
result.className = "";
|
|
result.textContent = "Creating...";
|
|
const rtoken = document.getElementById("rtoken").value;
|
|
try {
|
|
const res = await fetch("/agent-tokens", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json", authorization: "Bearer " + rtoken },
|
|
body: JSON.stringify({
|
|
owner: document.getElementById("owner").value,
|
|
repo: document.getElementById("repo").value,
|
|
scope: document.getElementById("scope").value,
|
|
ttl_hours: Number(document.getElementById("ttl").value) || 168,
|
|
}),
|
|
});
|
|
const body = await res.json();
|
|
if (!res.ok) throw new Error(body.error || "HTTP " + res.status);
|
|
result.innerHTML = "Token (copy now, shown once):<br><code>" + body.token + "</code><br>Expires: " + body.expires_at;
|
|
} catch (err) {
|
|
result.className = "error";
|
|
result.textContent = err.message;
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|