feat: add claude_args passthrough and structured_output (closes #1)
Bring the upstream v1 `claude_args` input and `structured_output` output
into this Gitea fork so downstream workflows can run the agent with
arbitrary Claude CLI flags (notably `--json-schema`) and read the
schema-validated verdict back as an action output, without an
agent-written file.
Approach (issue Option B, ported rather than bumped): the production
"Run Claude Code" step previously delegated to the external
anthropics/claude-code-base-action@v0.0.63, which has neither input.
Upstream base-action main has them but has migrated to the Claude Agent
SDK — a wholesale divergence that would change v0.0.63 behavior every
downstream step relies on. Instead this invokes the vendored base-action
directly via `bun run ${github.action_path}/base-action/src/index.ts`
(the same github.action_path pattern prepare.ts already uses, reliable
on Gitea), and ports only the two features onto the v0.0.63 process-spawn
engine.
- base-action/src/run-claude.ts: tokenize claude_args with shell-quote
(comment-line stripping; quoted/file-path schemas survive intact) and
append after the byte-identical BASE_ARGS, so empty claude_args yields
an unchanged arg list; extract structured_output from the stream-json
result event when --json-schema is present, failing loudly if absent.
- base-action/src/index.ts: forward INPUT_CLAUDE_ARGS.
- base-action/action.yml: add claude_args input + structured_output output.
- action.yml: add claude_args input + structured_output output; replace
the external base-action delegation with a direct bun-run of the
vendored copy (full INPUT_*/provider env contract derived from the
vendored validate-env/index); bump the default Claude CLI install to
2.1.160 (--json-schema requires a newer CLI than 1.0.117).
- shell-quote added to both package.json files; root bun.lock reconciled
(it was stale vs package.json — non-frozen installs already resolved
the newer tree).
- Tests for tokenizer, hasJsonSchema, and structured-output extraction.
- README: inputs/outputs tables, "Structured output" + "Version pins".
- examples/gitea-structured-output.yml.
Follow-up (cannot be done from this repo): consumers using a pre-baked
runner image (path_to_claude_code_executable) must rebuild that image
with a --json-schema-capable Claude CLI and restart the runner.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
# Example: schema-validated PR review verdict via `claude_args` + `structured_output`.
|
||||
#
|
||||
# Instead of having the agent write its verdict to a file, this asks Claude for a
|
||||
# result that conforms to a JSON Schema and reads it back from the action output.
|
||||
# Requires a Claude CLI new enough to support `--json-schema` (see README →
|
||||
# "Structured output"). If you consume this action through a pre-baked runner
|
||||
# image (path_to_claude_code_executable), that image's CLI must be bumped too.
|
||||
|
||||
name: Claude PR Review (structured output)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
|
||||
jobs:
|
||||
review:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
issues: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
# The schema the verdict must conform to. Using a file (rather than an
|
||||
# inline string) keeps the value free of spaces and `$` characters, so a
|
||||
# schema with $ref/$defs survives shell tokenization intact.
|
||||
- name: Write review schema
|
||||
shell: bash
|
||||
run: |
|
||||
mkdir -p .gitea
|
||||
cat > .gitea/review-schema.json <<'JSON'
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["decision", "summary"],
|
||||
"properties": {
|
||||
"decision": { "type": "string", "enum": ["approve", "request_changes", "comment"] },
|
||||
"summary": { "type": "string" }
|
||||
}
|
||||
}
|
||||
JSON
|
||||
|
||||
- name: Run Claude review
|
||||
id: review
|
||||
uses: ryan/claude-code-gitea-action@gitea
|
||||
with:
|
||||
gitea_token: ${{ secrets.GITEA_TOKEN }}
|
||||
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
direct_prompt: |
|
||||
Review the changes in this pull request and return your verdict
|
||||
strictly matching the provided JSON schema.
|
||||
claude_args: --json-schema ${{ github.workspace }}/.gitea/review-schema.json
|
||||
|
||||
- name: Act on the verdict
|
||||
shell: bash
|
||||
env:
|
||||
VERDICT: ${{ steps.review.outputs.structured_output }}
|
||||
run: |
|
||||
echo "Decision: $(echo "$VERDICT" | jq -r '.decision')"
|
||||
echo "Summary: $(echo "$VERDICT" | jq -r '.summary')"
|
||||
Reference in New Issue
Block a user