Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions .github/workflows/respond-to-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,51 @@ jobs:
script: |
const raw = process.env.AGENT_OUTPUT || '';

// Walk JSONL lines and capture the last agent text message, if any.
let lastText = '';
// Walk JSONL lines and extract structured content.
// Priority: last `agent` text > last `agent_reasoning` text.
// Never fall back to dumping raw JSONL.
let lastAgentText = '';
let lastReasoning = '';
let runUrl = '';
let isJsonl = false;
for (const line of raw.split('\n')) {
const trimmed = line.trim();
if (!trimmed) continue;
try {
const obj = JSON.parse(trimmed);
isJsonl = true;
if (obj.type === 'agent' && typeof obj.text === 'string') {
lastText = obj.text;
lastAgentText = obj.text;
} else if (obj.type === 'agent_reasoning' && typeof obj.text === 'string') {
lastReasoning = obj.text;
} else if (obj.type === 'system' && obj.run_url) {
runUrl = obj.run_url;
}
} catch (e) {
// Ignore non-JSON lines
}
}

const content = (lastText || raw || '').trim();
// Use agent text if available, otherwise fall back to reasoning summary.
// For non-JSONL output (e.g. text format), use raw output as-is.
let content = '';
if (lastAgentText) {
content = lastAgentText.trim();
} else if (!isJsonl && raw.trim()) {
content = raw.trim();
} else if (lastReasoning) {
content = lastReasoning.trim();
}

if (!content) {
core.info('No agent output to reply with.');
return;
}

if (runUrl) {
content += `\n\n[View full agent run](${runUrl})`;
}

const body = `@${context.payload.comment.user.login}: ${content}`;
const { owner, repo } = context.repo;

Expand Down
32 changes: 28 additions & 4 deletions examples/respond-to-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,27 +189,51 @@ jobs:
script: |
const raw = process.env.AGENT_OUTPUT || '';

// Walk JSONL lines and capture the last agent text message, if any.
let lastText = '';
// Walk JSONL lines and extract structured content.
// Priority: last `agent` text > last `agent_reasoning` text.
// Never fall back to dumping raw JSONL.
let lastAgentText = '';
let lastReasoning = '';
let runUrl = '';
let isJsonl = false;
for (const line of raw.split('\n')) {
const trimmed = line.trim();
if (!trimmed) continue;
try {
const obj = JSON.parse(trimmed);
isJsonl = true;
if (obj.type === 'agent' && typeof obj.text === 'string') {
lastText = obj.text;
lastAgentText = obj.text;
} else if (obj.type === 'agent_reasoning' && typeof obj.text === 'string') {
lastReasoning = obj.text;
} else if (obj.type === 'system' && obj.run_url) {
runUrl = obj.run_url;
}
} catch (e) {
// Ignore non-JSON lines
}
}

const content = (lastText || raw || '').trim();
// Use agent text if available, otherwise fall back to reasoning summary.
// For non-JSONL output (e.g. text format), use raw output as-is.
let content = '';
if (lastAgentText) {
content = lastAgentText.trim();
} else if (!isJsonl && raw.trim()) {
content = raw.trim();
} else if (lastReasoning) {
content = lastReasoning.trim();
}

if (!content) {
core.info('No agent output to reply with.');
return;
}

if (runUrl) {
content += `\n\n[View full agent run](${runUrl})`;
}

const body = `@${context.payload.comment.user.login}: ${content}`;
const { owner, repo } = context.repo;

Expand Down