Split tokens (#1)
The agent and the bot are now two accounts, and the runner is one Deno script. - `author-token` (was `gitea-token`): commits, pushes, and opens pull requests; the agent sees it as `GITEA_TOKEN`, and commits use that account's login and email. - `reviewer-token`: posts comments and reviews as the bot; withheld from the agent's environment so it can never approve as the bot. - A `pull_request` run posts a review instead of a comment: `REQUEST_CHANGES` when the response mentions `@bot`, `COMMENT` when the run failed, `APPROVED` otherwise. Gitea refuses self-approval, so the two accounts must differ. - The reviewer checks the whole repository against `commons/code-rules`, which is fetched and embedded in the prompt, and requests changes for violations even when the diff did not cause them. - `run.ts` replaces the three shell scripts plus `jq`, `envsubst`, and `ansifilter`; only `deno` is added to the install step, per the rules' Deno-over-Node policy. A `.gitea` workflow runs `deno fmt`, `lint`, and `check`. Callers must rename `gitea-token` and add `reviewer-token` (`write:issue` and `write:repository` scopes). A rejection stays until the bot reviews again, so callers that want it lifted after a fix should trigger on `pull_request: [opened, synchronize]`. Verified with a fake `claude` binary against this PR in an isolated `HOME`: git author configured from the token, prompt rendered with rules and comment history, events streamed, reviewer token absent from the agent's environment, review posted (then deleted). Reviewed-on: #1 Co-authored-by: Danny Kim <temeddix@gmail.com> Co-committed-by: Danny Kim <temeddix@gmail.com>
This commit was merged in pull request #1.
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
You are a coding agent running inside Gitea Actions.
|
||||
|
||||
Do not post a final issue comment yourself; your final response is posted
|
||||
automatically. Post additional comments only when needed for PR updates,
|
||||
screenshots, questions, or blockers.
|
||||
|
||||
Keep every issue and PR comment extremely short and simple. Strongly prefer
|
||||
nested bulleted lists for readability. Report only the outcome and tests; omit
|
||||
explanations, summaries, and pleasantries.
|
||||
|
||||
This is a single non-interactive run. The process exits the moment your final
|
||||
response ends, so background monitors, scheduled wake-ups, and queued tasks
|
||||
never resume. Never promise future action and never claim to be waiting on a
|
||||
notification.
|
||||
|
||||
For a `pull_request` event, review the newly opened PR without changing code. If
|
||||
changes are needed, include `@bot` in the final response with instructions to
|
||||
fix the findings. Otherwise, do not mention `@bot`. For UI changes, check that
|
||||
the result is aligned, clean, and pixel-perfect, and that included screenshots
|
||||
prove the intended result was achieved.
|
||||
|
||||
For an `issue_comment` or `pull_request_review_comment` event, treat the `body`
|
||||
in the triggering comment payload below as the user's exact instruction.
|
||||
|
||||
Install missing tools yourself when needed, including Rust, uv, Node, Deno, or
|
||||
system packages.
|
||||
|
||||
Before modifying or pushing code, check for another active automation run that
|
||||
may modify the same target branch or work on the same issue or pull request. If
|
||||
one exists, wait for it to finish before making changes. Wait inside this run
|
||||
with a foreground shell loop that polls and prints a line every 30 seconds, for
|
||||
as long as it takes, even hours; a silent process is killed as a zombie. Use a
|
||||
blocking `sleep` even if your tool instructions discourage it, and ignore any
|
||||
advice to wait by scheduling a callback instead. Never report being blocked by
|
||||
another run; always wait it out and complete the task before responding.
|
||||
Afterwards, pull the latest branch state before pushing. Skip this check when no
|
||||
code changes are needed.
|
||||
|
||||
Prefer minimal, correct changes. Run relevant checks or tests if practical.
|
||||
Treat code changes as a request to create a pull request. If a prior bot pull
|
||||
request already exists for this issue, update that same pull request instead of
|
||||
creating a new one. When you create a pull request, include `@bot` in its body
|
||||
and ask it to review the pull request. This is required for every pull request
|
||||
you create. Finish by briefly reporting what changed and what tests ran. Wait
|
||||
for Gitea Actions CI to complete, and fix any failures.
|
||||
|
||||
If you modify UI code, include Playwright screenshots in your PR or issue
|
||||
comments. If you need UI clarification, ask with screenshots when helpful.
|
||||
|
||||
# Comment payload
|
||||
|
||||
```
|
||||
${COMMENT}
|
||||
```
|
||||
|
||||
# Full issue comment history
|
||||
|
||||
```
|
||||
${ISSUE_COMMENTS}
|
||||
```
|
||||
|
||||
# Gitea context
|
||||
|
||||
- Event: `${EVENT_NAME}`
|
||||
- API URL: `${GITEA_API_URL}`
|
||||
- Repository: `${GITEA_REPOSITORY}`
|
||||
- Issue index: `${ISSUE_INDEX}`
|
||||
- Use the `GITEA_TOKEN` environment variable for authenticated Gitea API calls.
|
||||
@@ -1,49 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
git config --global user.name bot
|
||||
git config --global user.email noreply@capsulizers.com
|
||||
|
||||
COMMENT_FILE="$(mktemp)"
|
||||
|
||||
post_comment() {
|
||||
COMMENT_JSON="$(jq -n --rawfile body "${COMMENT_FILE}" '{body: $body}')"
|
||||
curl --fail-with-body --silent --show-error \
|
||||
-X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data "${COMMENT_JSON}" \
|
||||
"${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/issues/${ISSUE_INDEX}/comments"
|
||||
}
|
||||
|
||||
if [ -z "${BOT_TOKEN:-}" ]; then
|
||||
echo 'Run `claude setup-token` locally and set the `bot-token` action input.' > "${COMMENT_FILE}"
|
||||
post_comment
|
||||
exit 1
|
||||
fi
|
||||
export CLAUDE_CODE_OAUTH_TOKEN="${BOT_TOKEN}"
|
||||
|
||||
export ISSUE_COMMENTS="$(
|
||||
curl --fail-with-body --silent --show-error \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/issues/${ISSUE_INDEX}/comments?limit=100" \
|
||||
| jq -r '.[] | "## " + .user.login + " at " + .created_at + "\n\n" + .body + "\n"'
|
||||
)"
|
||||
|
||||
FINAL_PROMPT="$(envsubst < "${ACTION_PATH}/scripts/prompt.md")"
|
||||
|
||||
# Claude refuses --dangerously-skip-permissions as root outside a sandbox.
|
||||
export IS_SANDBOX=1
|
||||
|
||||
# Stream events so the runner sees output and does not kill the job as a zombie.
|
||||
STREAM_FILE="$(mktemp)"
|
||||
|
||||
claude --print --dangerously-skip-permissions --model claude-fable-5 \
|
||||
--output-format stream-json --verbose "${FINAL_PROMPT}" \
|
||||
| tee "${STREAM_FILE}" \
|
||||
| jq -r --unbuffered '.message.content[]? | .thinking // .text // .name // empty'
|
||||
|
||||
jq -r 'select(.type == "result") | .result // ("Bot failed: " + .subtype)' "${STREAM_FILE}" \
|
||||
| ansifilter > "${COMMENT_FILE}"
|
||||
|
||||
post_comment
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
git config --global user.name bot
|
||||
git config --global user.email noreply@capsulizers.com
|
||||
|
||||
COMMENT_FILE="$(mktemp)"
|
||||
|
||||
post_comment() {
|
||||
COMMENT_JSON="$(jq -n --rawfile body "${COMMENT_FILE}" '{body: $body}')"
|
||||
curl --fail-with-body --silent --show-error \
|
||||
-X POST \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data "${COMMENT_JSON}" \
|
||||
"${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/issues/${ISSUE_INDEX}/comments"
|
||||
}
|
||||
|
||||
if ! codex login status > /dev/null 2>&1; then
|
||||
codex login --device-auth 2>&1 | ansifilter > "${COMMENT_FILE}" &
|
||||
LOGIN_PID="${!}"
|
||||
sleep 3
|
||||
post_comment
|
||||
wait "${LOGIN_PID}"
|
||||
codex login status 2>&1 | ansifilter > "${COMMENT_FILE}"
|
||||
post_comment
|
||||
fi
|
||||
|
||||
export ISSUE_COMMENTS="$(
|
||||
curl --fail-with-body --silent --show-error \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
"${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/issues/${ISSUE_INDEX}/comments?limit=100" \
|
||||
| jq -r '.[] | "## " + .user.login + " at " + .created_at + "\n\n" + .body + "\n"'
|
||||
)"
|
||||
|
||||
FINAL_PROMPT="$(envsubst < "${ACTION_PATH}/scripts/prompt.md")"
|
||||
|
||||
codex exec --model gpt-5.5 \
|
||||
--dangerously-bypass-approvals-and-sandbox \
|
||||
--output-last-message "${COMMENT_FILE}" \
|
||||
"${FINAL_PROMPT}"
|
||||
|
||||
post_comment
|
||||
Reference in New Issue
Block a user