ytahdn 1f34c18f2f
feat(web-shell,webui,sdk): context-usage API + daemon-react-sdk refactor + dialog UX (#4573)
* feat(web-shell,webui,sdk,cli): context-usage API + dialog UX improvements

- Add GET /session/:id/context-usage endpoint (SDK types, acp-bridge,
  cli route, acpAgent handler with tests)
- Refactor webui daemon providers into session/ and workspace/ modules
  with daemon-react-sdk subpath export
- Web-shell dialog UX: replace left back icon with right-side ESC close
  button, fix keyboard scope so dialogs properly capture keys when input
  is focused, blur editor when dialog opens
- Remove /stats subcommands and model dialog custom model (c key) feature
- Remove slash completion auto-submit behavior (align with CLI)


* fix(web-shell,webui,cli): address PR #4573 review issues + parallel agents display

Security fixes:
- Mermaid securityLevel reverted to 'strict', strip foreignObject/style from SVG sanitizer
- Shift+Tab no longer silently sets yolo mode (only approves current request)
- clientLifecycle uses sessionStorage for per-tab client ID isolation

Bug fixes:
- cancel() finally block guards setPromptStatus with session-ID check
- lastRecapBlockCountRef resets on session switch
- collectContextData wrapped in try/catch with field stripping
- useDaemonResource: request sequence counter prevents stale response overwrite
- ResumeDialog: shows error state when session list fails to load
- detachDaemonClient: adds keepalive:true for tab-close reliability
- server.test.ts: adds session_context_usage to EXPECTED_STAGE1_FEATURES

Performance:
- useSyncExternalStore selector hoisted via useCallback

Feature:
- Parallel agents merged display (ParallelAgentsGroup component)

Tests:
- clientLifecycle.test.ts (9 tests): sessionStorage, keepalive, detach behavior
- useDaemonResource.test.tsx (5 tests): stale response race condition coverage
- Markdown.test.ts: updated foreignObject/style assertions to expect stripping


* fix(web-shell): improve ask user question flow

Fix AskUserQuestion answer submission and rendering by forwarding answers through acp-bridge permission metadata while keeping arbitrary response fields filtered.

Improve the web-shell AskUserQuestion dialog: keep the submit tab in order, preserve custom input values, align cursor position with existing selections when switching tabs, and show selected/custom answers with a consistent underline state.

Show ask_user_question tool results without truncating the answer payload.

* fix(web-shell,webui,cli): address PR #4573 critical and suggestion review issues

Critical fixes:
- releaseSession: close session before detaching client to avoid orphaned sessions
- ParallelAgentsGroup: forward pendingApproval/onConfirm props so approvals render inside grouped agents
- fmtCategoryRow: guard against zero contextWindowSize division

Suggestion fixes:
- MemoryDialog: await reloadMemory() before showing success message
- useInputHistory: keep storageKeyRef in sync with prop changes
- App: reset lastRecapBlockCountRef on session switch to prevent auto-recap from silently failing
- App: log auto-recap errors instead of silently swallowing them
- acpAgent: log collectContextData failures instead of silent catch


* feat(web-shell): add daemon followup suggestions

* fix(web-shell): validate context-usage payload and restore question-text answer keys

- parseContextUsageMessage: add runtime check for usage.totalTokens before casting, prevent white-screen on malformed daemon payload
- AskUserQuestion buildResult: use q.question as answer key instead of numeric index, matching downstream consumers that match answers by question text


* fix(web-shell,webui): address remaining PR #4573 review issues

- sanitizeSvg: keep <style> (sanitize @import/external url()) and <foreignObject>
  so mermaid diagrams render with correct theming and visible text labels
- mermaid: skip redundant mermaid.initialize() when theme unchanged
- newSession: abort in-flight prompts before resetting store
- ParallelAgentsGroup: i18n for hardcoded English strings
- vite.config: restore rollupTypes: true for NodeNext compatibility
- AskUserQuestion: restore q.question as answer key


* fix(web-shell,webui): fix mermaid error rendering, add detach logging, deduplicate session switch, and add tests

- Add suppressErrorRendering to mermaid.initialize() to prevent error SVGs from being injected into the DOM on render failure
- Replace silent catch on detachDaemonClient with console.warn for debuggability
- Extract startSessionSwitch() helper to deduplicate loadSession/resumeSession
- Update sanitizeSvg tests to match current behavior (foreignObject/style preserved)
- Add groupParallelAgents unit tests covering grouping, splitting, and edge cases


* fix(webui): resolve rebase conflicts with upstream daemon_mode_b_main

- Fix useDaemonFollowupSuggestion import path after DaemonSessionProvider move to session/
- Merge daemon/index.ts exports (keep followup suggestion + add SDK type re-exports)
- Restore lastEventId/setLastEventId in test MockSession interface
- Remove non-existent DaemonWorkspaceSkillDetail re-export


* fix(acp-bridge): validate answer value types in permission response metadata

Reject non-string values in the answers payload to prevent malformed
data from being forwarded through the permission mediator to the agent.

* fix(web-shell,webui): fix shell command output display, loading state, and detach timeout

- transcriptToMessages: create standalone tool_group for shell output
  when previous message is not a tool_group (fixes silent drop of ! command output)
- actions: register sendShellCommand in activePromptsRef and manage
  promptStatus lifecycle (fixes stuck loading after shell command)
- actions: wrap detachDaemonClient with withActionTimeout in releaseSession
  to prevent indefinite hang when daemon is unresponsive
- ToolGroup: auto-expand bash/shell/execute_command tool output by default
- Add shell output tests for transcriptToMessages

* fix(webui): fix state_resync_required handling and catchingUp flag

- Differentiate state_resync_required by reason: epoch_reset resets store
  and replays on same stream; ring_evicted preserves awaitingResync and
  continues on same stream; other reasons keep original break+reconnect
- Clear awaitingResync on replay_complete so post-replay events flow
- Set catchingUp when activeSession.lastEventId is present, not only on
  same-session reconnect (fixes resume catchingUp indicator)

* fix(web-shell,webui): add getTasks action and fix broken reference after rebase

- Add getTasks() to DaemonSessionActions interface and implement in actions.ts
- Fix App.tsx: actions.getTasks → sessionActions.getTasks (variable renamed
  during refactor but this callsite was missed during rebase merge)

* fix(webui): fix releaseSession to use closeSession instead of detach

releaseSession was incorrectly calling detachDaemonClient with the
current client's ID, which only decremented attachCount without
actually closing the target session. Replace with
session.client.closeSession() (DELETE /session/:id) to properly
terminate the session. Also fix sendShellCommand to use a distinct
shellKey to avoid colliding with prompt AbortControllers.

* feat(webui): add non-blocking prompt settlement and passive turn event handling

- Add settleActivePromptFromTurnEvent to resolve/reject active prompts
  from turn_complete/turn_error SSE events in the Provider event loop
- Add isPromptLifecycleTurnEvent filter to prevent turn events from being
  dispatched to the transcript store as unrecognized debug events
- Add waitForAcceptedPromptCompletion in actions.ts to bridge the gap
  between 202-accepted prompts and their eventual turn completion
- Extend ActivePrompt type with promptId, resolve/reject callbacks, and
  pendingResult/pendingError for deferred settlement
- Add passive observer handling for turn_complete/turn_error so non-sender
  tabs correctly end the streaming state
- Add tests for non-blocking prompt acceptance and early turn completion

---------

Co-authored-by: ytahdn <ytahdn@gmail.com>
2026-05-28 17:59:54 +08:00

156 lines
3.2 KiB
CSS

.app {
--font-mono:
'SF Mono', 'Fira Code', 'JetBrains Mono', 'Cascadia Code', monospace;
--font-sans:
-apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
--radius: 6px;
position: relative;
display: flex;
flex-direction: column;
height: 100%;
padding: 12px 24px;
background: var(--app-bg);
color: var(--text-primary);
font-family: var(--font-mono);
font-size: 14px;
line-height: 1.6;
overflow: hidden;
}
.app,
.app * {
box-sizing: border-box;
}
.themeDark {
--app-bg: #111;
--bg-primary: #0d0d0d;
--bg-secondary: #161616;
--bg-tertiary: #1e1e1e;
--bg-surface: #1a1a1a;
--border-color: #2a2a2a;
--text-primary: #e4e4e4;
--text-secondary: #a0a0a0;
--text-dimmed: #666;
--accent-color: #4a9eff;
--accent-hover: #3a8eef;
--success-color: #48bb78;
--warning-color: #ecc94b;
--error-color: #fc8181;
--user-color: #48bb78;
--assist-color: #b794f4;
--welcome-logo-gradient: linear-gradient(
90deg,
#4796e4 0%,
#847ace 52%,
#c3677f 100%
);
--editor-bg: #0a0a0a;
--msg-body-color: #e3bcfe;
--thinking-pre-color: #9d9ec6;
--subtle-bg: rgba(255, 255, 255, 0.04);
--subtle-bg-strong: rgba(255, 255, 255, 0.06);
--info-bg: rgba(74, 158, 255, 0.08);
--info-border: rgba(74, 158, 255, 0.2);
--success-bg: rgba(72, 187, 120, 0.12);
--warning-bg: rgba(236, 201, 75, 0.08);
--warning-border: rgba(236, 201, 75, 0.2);
--error-bg: rgba(252, 129, 129, 0.08);
--error-border: rgba(252, 129, 129, 0.2);
}
.themeLight {
--app-bg: #FFF;
--bg-primary: #ffffff;
--bg-secondary: #f7f7f2;
--bg-tertiary: #efeee8;
--bg-surface: #f5f4ed;
--border-color: #d8d6cc;
--text-primary: #22231f;
--text-secondary: #5f6259;
--text-dimmed: #8b8d84;
--accent-color: #0b66c3;
--accent-hover: #0756a6;
--success-color: #1f7a3a;
--warning-color: #9a6a00;
--error-color: #c0362c;
--user-color: #0a7a3d;
--assist-color: #7b4ab8;
--welcome-logo-gradient: linear-gradient(
90deg,
#0b66c3 0%,
#7357b8 52%,
#bd4f67 100%
);
--editor-bg: #f7f7f2;
--msg-body-color: #0b6f3a;
--thinking-pre-color: #74788f;
--subtle-bg: rgba(32, 31, 25, 0.05);
--subtle-bg-strong: rgba(32, 31, 25, 0.08);
--info-bg: rgba(11, 102, 195, 0.08);
--info-border: rgba(11, 102, 195, 0.22);
--success-bg: rgba(31, 122, 58, 0.11);
--warning-bg: rgba(154, 106, 0, 0.1);
--warning-border: rgba(154, 106, 0, 0.24);
--error-bg: rgba(192, 54, 44, 0.1);
--error-border: rgba(192, 54, 44, 0.24);
}
.dialogOverlay {
position: absolute;
inset: 0;
z-index: 10;
display: flex;
flex-direction: column;
background: var(--app-bg);
}
.content {
flex: 0 1 auto;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
}
.contentHasMessages {
flex: 0 1 auto;
}
.footer {
margin: 0 -12px;
flex-shrink: 0;
}
.bottomPanels {
display: flex;
flex-direction: column;
gap: 4px;
padding-bottom: 4px;
}
.composer {
flex-shrink: 0;
padding: 0;
}
.queuedPrompts {
display: flex;
flex-direction: column;
gap: 2px;
padding: 0 12px 6px 36px;
color: var(--text-dimmed);
font-size: 12px;
line-height: 1.4;
}
.queuedPrompt {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.queuedHint {
font-style: italic;
}