|
84 | 84 | const output = process.env.AGENT_OUTPUT; |
85 | 85 | let result; |
86 | 86 | try { |
87 | | - result = JSON.parse(output); |
| 87 | + // The agent outputs streaming JSON format with multiple lines |
| 88 | + // We need to extract the last line with type:"agent" and parse its text field |
| 89 | + const lines = output.trim().split('\n'); |
| 90 | + let agentResponse = null; |
| 91 | + for (const line of lines) { |
| 92 | + const parsed = JSON.parse(line); |
| 93 | + if (parsed.type === 'agent') { |
| 94 | + agentResponse = parsed.text; |
| 95 | + } |
| 96 | + } |
| 97 | + if (!agentResponse) { |
| 98 | + core.setFailed('No agent response found in output'); |
| 99 | + return; |
| 100 | + } |
| 101 | + result = JSON.parse(agentResponse); |
88 | 102 | } catch (e) { |
89 | 103 | core.setFailed(`Failed to parse agent output: ${e.message}`); |
90 | 104 | return; |
@@ -134,11 +148,33 @@ jobs: |
134 | 148 |
|
135 | 149 | - name: Write result to summary |
136 | 150 | if: steps.agent.outputs.agent_output |
| 151 | + uses: actions/github-script@v7 |
137 | 152 | env: |
138 | 153 | AGENT_OUTPUT: ${{ steps.agent.outputs.agent_output }} |
139 | | - run: | |
140 | | - echo "## Clarity Label" >> $GITHUB_STEP_SUMMARY |
141 | | - echo "" >> $GITHUB_STEP_SUMMARY |
142 | | - echo '```json' >> $GITHUB_STEP_SUMMARY |
143 | | - echo "$AGENT_OUTPUT" >> $GITHUB_STEP_SUMMARY |
144 | | - echo '```' >> $GITHUB_STEP_SUMMARY |
| 154 | + with: |
| 155 | + script: | |
| 156 | + const output = process.env.AGENT_OUTPUT; |
| 157 | +
|
| 158 | + try { |
| 159 | + // The agent outputs streaming JSON format with multiple lines |
| 160 | + // We need to extract the last line with type:"agent" and parse its text field |
| 161 | + const lines = output.trim().split('\n'); |
| 162 | + let agentText = null; |
| 163 | + for (const line of lines) { |
| 164 | + try { |
| 165 | + const parsed = JSON.parse(line); |
| 166 | + if (parsed.type === 'agent' && parsed.text) { |
| 167 | + agentText = parsed.text; |
| 168 | + } |
| 169 | + } catch (e) {} |
| 170 | + } |
| 171 | + |
| 172 | + if (agentText) { |
| 173 | + await core.summary |
| 174 | + .addHeading('Clarity Label') |
| 175 | + .addCodeBlock(agentText, 'json') |
| 176 | + .write(); |
| 177 | + } |
| 178 | + } catch (e) { |
| 179 | + core.setFailed(`Failed to write summary: ${e.message}`); |
| 180 | + } |
0 commit comments