Chat: group consecutive background-task notices into one collapsed chip

Two or more consecutive Claude Code task notices fold into one
task_notices row: a chip 'N background tasks' (tinted when one failed)
that opens a sheet with one compact row per task (outcome icon, summary,
outcome word), like the tools and permissions chips. A lone notice stays
one line. The server also treats Claude Code's [SYSTEM NOTIFICATION]
banner as harness text, so a bannered notification without an origin is
still a notice, never the operator's turn. The chat fixture gains
?tasks=N.
This commit is contained in:
2026-11-03 12:44:57 +00:00
parent d34185b56c
commit 1a9db0206c
10 changed files with 591 additions and 5 deletions
+3
View File
@@ -80,6 +80,9 @@ var harnessPrefixes = []string{
"Caveat: The messages below were generated by the user while running local commands.",
"[Request interrupted by user",
"Base directory for this skill:",
// The banner Claude Code puts before a background-task event it delivers
// as user-role text (current CLIs; older ones sent the bare block).
"[SYSTEM NOTIFICATION - NOT USER INPUT]",
}
// classifyInjected decides how a user-role text is shown. origin and meta are
+14
View File
@@ -26,6 +26,10 @@ const taskNotification = "<task-notification>\n<task-id>b1</task-id>\n<tool-use-
"<output-file>/tmp/b1.output</output-file>\n<status>completed</status>\n" +
"<summary>Background command \"Build the app\" completed (exit code 0)</summary>\n</task-notification>"
// systemNotificationBanner is the preamble Claude Code records before a task
// notification it delivers as a user line.
const systemNotificationBanner = "[SYSTEM NOTIFICATION - NOT USER INPUT]\nThis is an automated background-task event, NOT a message from the user.\n\n"
const midTurnWrapped = "<system-reminder>\nThe user sent a new message while you were working:\nship it now\n\n" +
"This is how Claude Code surfaces messages the user sends mid-turn. Address the message above as you continue this turn.\n</system-reminder>"
@@ -162,6 +166,16 @@ func TestClassifyKeepsOperatorTextAndHidesHarness(t *testing.T) {
t.Fatalf("classify %q: %+v", c.text, item)
}
}
// Current CLIs open a task notification with a banner; without an origin
// object the text shape alone must still make it a notice, never the
// operator's turn, and the banner alone is hidden.
bannered := classifyInjected(systemNotificationBanner+taskNotification, injectedOrigin{}, false)
if bannered.class != classNotice || bannered.id != "task-notice-toolu_bg1-completed" {
t.Fatalf("bannered task notice: %+v", bannered)
}
if bare := classifyInjected(systemNotificationBanner+"nothing else", injectedOrigin{}, false); bare.class != classHidden {
t.Fatalf("bare banner: %+v", bare)
}
failed := classifyInjected(strings.Replace(taskNotification, "completed</status>", "failed</status>", 1), injectedOrigin{}, false)
if failed.class != classNotice || !strings.HasPrefix(failed.text, "Background task failed: ") {
t.Fatalf("failed task notice: %+v", failed)