-
-
Notifications
You must be signed in to change notification settings - Fork 359
feat: display background task count in status bar #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { isObject } from '@hapi/protocol' | ||
| import { unwrapRoleWrappedRecordEnvelope } from '@hapi/protocol/messages' | ||
|
|
||
| /** | ||
| * Extract background task start/completion signals from a message. | ||
| * | ||
| * Uses role-aware parsing to avoid false positives: | ||
| * - Started: agent-role output with tool_result containing | ||
| * "Command running in background with ID:" | ||
| * - Completed: agent-role output wrapping a user-type message (system-injected) | ||
| * starting with "<task-notification>" | ||
| * | ||
| * Both signals arrive as { role: 'agent', content: { type: 'output', data: {...} } } | ||
| * because the CLI wraps all messages in agent envelopes. | ||
| */ | ||
| export function extractBackgroundTaskDelta(messageContent: unknown): { started: number; completed: number } | null { | ||
| const record = unwrapRoleWrappedRecordEnvelope(messageContent) | ||
| if (!record || record.role !== 'agent') return null | ||
| if (!isObject(record.content) || record.content.type !== 'output') return null | ||
|
|
||
| const data = isObject(record.content.data) ? record.content.data : null | ||
| if (!data) return null | ||
|
|
||
| const started = countTaskStarts(record.content) | ||
| const completed = data.type === 'user' ? countTaskCompletions(data) : 0 | ||
|
|
||
| if (started === 0 && completed === 0) return null | ||
| return { started, completed } | ||
| } | ||
|
|
||
| /** | ||
| * Count background task starts from tool_result blocks. | ||
| */ | ||
| function countTaskStarts(content: Record<string, unknown>): number { | ||
| const data = isObject(content.data) ? content.data : null | ||
| if (!data) return 0 | ||
|
|
||
| // Direct tool_result | ||
| if (data.type === 'tool_result') { | ||
| return isBackgroundStartResult(data) ? 1 : 0 | ||
| } | ||
|
|
||
| // Assistant message with content array containing tool_result blocks | ||
| if (data.type === 'assistant') { | ||
| const message = isObject(data.message) ? data.message : null | ||
| const modelContent = message?.content | ||
| if (!Array.isArray(modelContent)) return 0 | ||
|
|
||
| let count = 0 | ||
| for (const block of modelContent) { | ||
| if (isObject(block) && block.type === 'tool_result' && isBackgroundStartResult(block)) { | ||
| count++ | ||
| } | ||
| } | ||
| return count | ||
| } | ||
|
|
||
| return 0 | ||
| } | ||
|
|
||
| function isBackgroundStartResult(block: Record<string, unknown>): boolean { | ||
| const text = typeof block.content === 'string' | ||
| ? block.content | ||
| : Array.isArray(block.content) | ||
| ? block.content.map((c: unknown) => isObject(c) && typeof c.text === 'string' ? c.text : '').join('') | ||
| : '' | ||
| return text.includes('Command running in background with ID:') | ||
| } | ||
|
|
||
| /** | ||
| * Count task completions from system-injected user messages. | ||
| * | ||
| * These arrive as: { type: 'user', message: { content: '<task-notification>...' } } | ||
| * inside the agent output envelope. | ||
| */ | ||
| function countTaskCompletions(data: Record<string, unknown>): number { | ||
| // { type: 'user', message: { content: '<task-notification>...' } } | ||
| if (isObject(data.message)) { | ||
| const msg = data.message as Record<string, unknown> | ||
| if (typeof msg.content === 'string' && msg.content.trimStart().startsWith('<task-notification>')) { | ||
| return 1 | ||
| } | ||
| } | ||
|
|
||
| // { type: 'user', uuid: '...', content: '<task-notification>...' } | ||
| if (typeof data.content === 'string' && data.content.trimStart().startsWith('<task-notification>')) { | ||
| return 1 | ||
| } | ||
|
|
||
| return 0 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MINOR] This new status text is hardcoded in English, while the rest of the connection-state labels already go through
useTranslation(). Inzh-CN, users will now see an English-only status as soon as a background task is running.Suggested fix:
Add the matching
misc.backgroundTasksRunningentry inweb/src/lib/locales/en.tsandweb/src/lib/locales/zh-CN.ts.