Repository navigation
feat(ci): reshape ClawReview 🦀 into an informative mascot (+ SDK fix) #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
KrasimirKralev
merged 5 commits into
ID-Robots:main
from
KrasimirKralev:feat/clawreview-mascot
Jul 5, 2026
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
62f5a45
fix(ci): lazy-load the Anthropic SDK so the OAuth path needs no SDK
KrasimirKralev f907ff8
feat(ci): reshape ClawReview into an informative mascot (not a reviewer)
KrasimirKralev 1142e7d
chore(assets): add square crab avatar for the ClawReview GitHub App
KrasimirKralev b63321c
fix(ci): apply CodeRabbit review — app-token if-guard + shared backend
KrasimirKralev 9fa5cf5
fix(ci): address CodeRabbit re-review — tolerant SDK parse + read-onl…
KrasimirKralev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Shared Claude backend for the ClawBox CI bots (pr-review + issue-triage). | ||
| // One place for the two transports so a change to either stays in sync: | ||
| // - CLAUDE_CODE_OAUTH_TOKEN set -> Claude Code CLI (`claude -p`), the | ||
| // official Pro/Max subscription path (same runtime as claude-code-action) | ||
| // - else -> the Anthropic SDK (API key) | ||
| // The SDK is imported lazily so the OAuth-only install (CLI, no SDK) doesn't | ||
| // crash at module load. | ||
| import { execFileSync } from "node:child_process"; | ||
|
|
||
| // Extract a JSON object from possibly-fenced/wrapped model text. | ||
| export function parseModelJson(text) { | ||
| const stripped = text.replace(/^```(?:json)?\s*/m, "").replace(/```\s*$/m, "").trim(); | ||
| try { return JSON.parse(stripped); } catch { /* fall through */ } | ||
| const m = stripped.match(/\{[\s\S]*\}/); | ||
| if (!m) throw new Error("no JSON object in model response"); | ||
| return JSON.parse(m[0]); | ||
| } | ||
|
|
||
| function viaClaudeCli({ system, schema, userContent, model, timeoutMs, maxBuffer }) { | ||
| const prompt = [ | ||
| system, | ||
| "\nRespond with ONLY a JSON object matching this schema (no prose, no fences):", | ||
| JSON.stringify(schema), | ||
| "\n---\n", | ||
| userContent, | ||
| ].join("\n"); | ||
| const out = execFileSync("claude", ["-p", "--model", model, "--output-format", "json"], { | ||
| encoding: "utf8", | ||
| input: prompt, | ||
| stdio: ["pipe", "pipe", "inherit"], | ||
| timeout: timeoutMs, | ||
| maxBuffer, | ||
| }); | ||
| const wrapper = JSON.parse(out); | ||
| if (wrapper.is_error) throw new Error(`claude cli error: ${String(wrapper.result).slice(0, 200)}`); | ||
| return parseModelJson(String(wrapper.result)); | ||
| } | ||
|
|
||
| async function viaSdk({ system, schema, userContent, model, maxTokens }) { | ||
| const { default: Anthropic } = await import("@anthropic-ai/sdk"); | ||
| const client = new Anthropic(); // reads ANTHROPIC_API_KEY from env | ||
| const resp = await client.messages.create({ | ||
| model, | ||
| max_tokens: maxTokens, | ||
| system, | ||
| output_config: { format: { type: "json_schema", schema } }, | ||
| messages: [{ role: "user", content: userContent }], | ||
| }); | ||
| const text = resp.content.find((b) => b.type === "text")?.text; | ||
| // Throw rather than default to "{}" — an empty object downstream would create | ||
| // and apply labels literally named "undefined". Callers' outer catch exits 0. | ||
| if (!text) throw new Error("no text block in model response"); | ||
| return JSON.parse(text); | ||
| } | ||
|
|
||
| // Run one structured-output call and return the validated JSON object. | ||
| // OAuth transport preferred; API-key SDK is the fallback. | ||
| export function callClaude(opts) { | ||
| if (process.env.CLAUDE_CODE_OAUTH_TOKEN) return viaClaudeCli(opts); | ||
| return viaSdk(opts); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.