Skip to content

Commit eba921f

Browse files
authored
docs: fix execution file parsing example (#1297)
1 parent 36617bd commit eba921f

1 file changed

Lines changed: 36 additions & 9 deletions

File tree

base-action/README.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ Do not set `anthropic_api_key` or `claude_code_oauth_token` alongside the federa
147147

148148
## Outputs
149149

150-
| Output | Description |
151-
| ---------------- | ---------------------------------------------------------- |
152-
| `conclusion` | Execution status of Claude Code ('success' or 'failure') |
153-
| `execution_file` | Path to the JSON file containing Claude Code execution log |
150+
| Output | Description |
151+
| ------------------- | ------------------------------------------------------------------------------------------------- |
152+
| `conclusion` | Execution status of Claude Code ('success' or 'failure') |
153+
| `execution_file` | Path to the JSON file containing Claude Code execution log |
154+
| `structured_output` | JSON string containing structured output fields when `--json-schema` is provided in `claude_args` |
155+
| `session_id` | The Claude Code session ID that can be used with `--resume` to continue this conversation |
154156

155157
## Environment Variables
156158

@@ -395,18 +397,39 @@ jobs:
395397
const executionFile = '${{ steps.code-review.outputs.execution_file }}';
396398
const executionLog = JSON.parse(fs.readFileSync(executionFile, 'utf8'));
397399
398-
// Extract the review content from the execution log
399-
// The execution log contains the full conversation including Claude's responses
400+
// Extract the review content from the execution log.
401+
// The SDK writes top-level events with `type`; assistant text is nested
402+
// under `message.content`.
400403
let review = '';
401404

402-
// Find the last assistant message which should contain the review
405+
// Prefer the final result event when it is available.
403406
for (let i = executionLog.length - 1; i >= 0; i--) {
404-
if (executionLog[i].role === 'assistant') {
405-
review = executionLog[i].content;
407+
const entry = executionLog[i];
408+
if (entry?.type === 'result' && typeof entry.result === 'string') {
409+
review = entry.result;
406410
break;
407411
}
408412
}
409413

414+
// Fallback to the last assistant text block if no result event was written.
415+
if (!review) {
416+
for (let i = executionLog.length - 1; i >= 0; i--) {
417+
const entry = executionLog[i];
418+
if (entry?.type !== 'assistant' || !Array.isArray(entry.message?.content)) {
419+
continue;
420+
}
421+
422+
review = entry.message.content
423+
.filter((block) => block?.type === 'text' && typeof block.text === 'string')
424+
.map((block) => block.text)
425+
.join('\n');
426+
427+
if (review) {
428+
break;
429+
}
430+
}
431+
}
432+
410433
if (review) {
411434
github.rest.issues.createComment({
412435
issue_number: context.issue.number,
@@ -417,6 +440,10 @@ jobs:
417440
}
418441
```
419442

443+
For typed automation output, prefer passing `--json-schema` in `claude_args`
444+
and reading `steps.<id>.outputs.structured_output` instead of parsing the full
445+
execution log.
446+
420447
Check out additional examples in [`./examples`](./examples).
421448

422449
## Using Cloud Providers

0 commit comments

Comments
 (0)