Skip to content

feat(gastown): parse H1 headers from agent output as automatic status updates#1374

Open
jrf0110 wants to merge 1 commit intoconvoy/parse-agent-status-from-h1-headers-repla/52d188d7/headfrom
convoy/parse-agent-status-from-h1-headers-repla/52d188d7/gt/maple/f0ad7dff
Open

feat(gastown): parse H1 headers from agent output as automatic status updates#1374
jrf0110 wants to merge 1 commit intoconvoy/parse-agent-status-from-h1-headers-repla/52d188d7/headfrom
convoy/parse-agent-status-from-h1-headers-repla/52d188d7/gt/maple/f0ad7dff

Conversation

@jrf0110
Copy link
Contributor

@jrf0110 jrf0110 commented Mar 21, 2026

Summary

Parse markdown H1 headers from message.part.updated / message_part.updated events in broadcastEvent() and post them to the agent status API. This provides dashboard visibility into what agents are doing without requiring explicit gt_status tool calls — agents just write naturally with H1 headers at phase transitions.

Key implementation details:

  • Uses last H1 match when multiple exist in a single text part (most current status)
  • Deduplicates via module-level lastStatusForAgent Map to avoid redundant API calls
  • Truncates status text to 120 characters
  • Cleans up lastStatusForAgent entries at all agent exit paths: exitAgent(), stream error handler, stopAgent(), and stopAll()
  • Auth follows the same container-token/session-token pattern as event persistence

Refs: #1307

Verification

  • Typecheck passes (reported by author)
  • Lint passes (reported by author)
  • Format passes (reported by author)
  • Code review: correctness, security, cleanup paths all verified

Visual Changes

N/A

Reviewer Notes

  • The auth token resolution + header construction (lines 173-186) duplicates the pattern from the event persistence block above (lines 117-131). This is a minor code smell but acceptable given the localized scope. A future cleanup could extract a shared helper.
  • The agents.get(agentId) call at line 173 (agentMeta) is redundant since agent was already fetched at line 114 and is still in scope. Not a bug, but a minor inefficiency.
  • The H1 regex (?:^|\n)# (.+) could theoretically match code comments (e.g., Python #) in code blocks, but false positives would just produce a slightly wrong status update — low severity and self-correcting.
  • No new tests added; the container's process-manager.ts has no existing test infrastructure to extend.

… updates

Parse markdown H1 headers from message.part.updated events in
broadcastEvent() and post them to the agent status API. This provides
dashboard visibility into agent activity without requiring agents to
call gt_status explicitly.

- Uses last H1 match (most current) when multiple exist in one text part
- Deduplicates via lastStatusForAgent Map to avoid redundant API calls
- Truncates status to 120 characters
- Cleans up lastStatusForAgent on agent exit/stop/failure/shutdown

Refs: #1307
typeof part.text === 'string'
) {
// Use last H1 match — most current status when agent writes multiple headers
const matches = [...part.text.matchAll(/(?:^|\n)# (.+)/g)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: This will publish partial H1 fragments while the heading is still streaming

message.part.updated is emitted for each text delta, and part.text is the accumulated content so far. As soon as the model has produced something like # A, this regex starts matching, and lastStatusForAgent will not dedupe the follow-up # An, # Ana, etc. updates because each fragment is different. That can turn one heading into dozens of /status writes and bead events before the line is complete. Please wait until the H1 line is finished (for example, require a terminating newline or emit on a completion event) before posting the status.

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 21, 2026

Code Review Summary

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
cloudflare-gastown/container/src/process-manager.ts 166 message.part.updated streams token-by-token, so the H1 regex can emit partial headings and spam /status writes before the line is complete.
Other Observations (not in diff)

None.

Files Reviewed (1 files)
  • cloudflare-gastown/container/src/process-manager.ts - 1 issue

Reviewed by gpt-5.4-20260305 · 395,364 tokens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant