-
Notifications
You must be signed in to change notification settings - Fork 1
release: v0.1.52 — live in-flight run progress #112
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
60df8e5
feat: live in-flight run progress notification (A1) (#111)
adebnar 85818f0
chore: bump version to 0.1.52 (live in-flight run progress)
adebnar 521a9ee
merge: bring main into dev before promotion
adebnar b98e014
Fix review findings on run-progress notification
adebnar 55480bf
fix: name notification intent components explicitly for static analysis
adebnar 72d56ae
fix: spell PendingIntent flags out at each creation site
adebnar 0158632
fix: build notification intents with direct calls, not apply blocks
adebnar 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
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/hermes/client/data/progress/RunProgress.kt
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,69 @@ | ||
| package com.hermes.client.data.progress | ||
|
|
||
| import com.hermes.client.data.network.ServerEvent | ||
| import com.hermes.client.data.network.bool | ||
| import com.hermes.client.data.network.str | ||
| import com.hermes.client.data.network.todoCounts | ||
|
|
||
| /** | ||
| * State of the agent run currently in flight, derived purely from gateway WebSocket events. | ||
| * | ||
| * Deliberately NOT part of ChatUiState: that is scoped to an open chat screen and dies when the | ||
| * app is backgrounded, which is exactly when this state must survive to drive a notification. | ||
| */ | ||
| data class RunProgress( | ||
| val running: Boolean = false, | ||
| val sessionId: String? = null, | ||
| val profile: String? = null, | ||
| val tool: String? = null, | ||
| val done: Int = 0, | ||
| val total: Int = 0, | ||
| ) { | ||
| /** A determinate bar is only possible once the `todo` tool has reported a non-empty list. */ | ||
| val determinate: Boolean get() = total > 0 | ||
| } | ||
|
|
||
| /** | ||
| * Folds one gateway event into run state. Pure — no Android, no IO. | ||
| * | ||
| * `activeProfile` is latched into the run at the moment it starts (or restarts) so the | ||
| * tenant travels with the run itself rather than being re-read from a mutable source at | ||
| * notification-post time — a profile switch mid-run must never re-tag an in-flight run's | ||
| * notification with a different tenant while its route still points at the original session. | ||
| * | ||
| * `session.info.running` is the authoritative backstop: `message.complete` alone misses | ||
| * interrupted and compacted turns, which would otherwise strand a permanent "running" state. | ||
| * Tool events are ignored while idle so a late/stray `tool.*` cannot resurrect a finished run. | ||
| */ | ||
| fun RunProgress.reduce(event: ServerEvent, activeProfile: String?): RunProgress = when (event.type) { | ||
| "message.start" -> RunProgress(running = true, sessionId = event.sessionId, profile = activeProfile) | ||
|
|
||
| "tool.start" -> if (!running) this else copy(tool = event.str("name")?.ifBlank { null }) | ||
|
|
||
| "tool.complete" -> when { | ||
| !running -> this | ||
| event.str("name") == "todo" -> { | ||
| val (d, t) = event.todoCounts() | ||
| copy(tool = null, done = d, total = t) | ||
| } | ||
| else -> copy(tool = null) | ||
| } | ||
|
|
||
| "message.complete", "error" -> RunProgress() | ||
|
|
||
| // Authoritative busy/idle signal. A missing `running` field leaves state untouched. | ||
| "session.info" -> when (event.bool("running")) { | ||
| false -> RunProgress() | ||
| true -> when { | ||
| !running -> RunProgress(running = true, sessionId = event.sessionId, profile = activeProfile) | ||
| // A differing (non-null) sessionId means a different run started — start fresh | ||
| // rather than silently keeping the stale run's counts/sessionId. | ||
| event.sessionId != null && event.sessionId != sessionId -> | ||
| RunProgress(running = true, sessionId = event.sessionId, profile = activeProfile) | ||
| else -> this | ||
| } | ||
| null -> this | ||
| } | ||
|
|
||
| else -> this | ||
| } |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.