@steerable/agent-shell-web 0.14.4 → 0.14.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { useEffect, useMemo, useRef, useState } from 'react';
1
+ import { useEffect, useId, useMemo, useRef, useState } from 'react';
2
2
  import {
3
3
  LuCircle,
4
4
  LuCircleCheck,
@@ -6,9 +6,7 @@ import {
6
6
  LuChevronDown,
7
7
  LuListChecks,
8
8
  LuLoaderCircle,
9
- LuX,
10
9
  } from 'react-icons/lu';
11
- import { useExclusiveExpand } from './composer-status-stack';
12
10
  import { t } from '@/i18n';
13
11
  import {
14
12
  summarizeTodos,
@@ -63,7 +61,7 @@ export function TodoItems({
63
61
  }) {
64
62
  return (
65
63
  <ol
66
- className={`m-0 list-none ${compact ? 'max-h-48 space-y-1 overflow-y-auto px-2.5 py-1.5' : 'space-y-1 px-2.5 py-1.5'}`}
64
+ className={`m-0 list-none ${compact ? 'max-h-52 space-y-1.5 overflow-y-auto px-3 py-2' : 'space-y-1 px-2.5 py-1.5'}`}
67
65
  >
68
66
  {todos.map((todo) => {
69
67
  const done = todo.status === 'completed';
@@ -94,11 +92,28 @@ export function TodoItems({
94
92
  );
95
93
  }
96
94
 
97
- export function SessionTodoList({ todos }: { todos: SessionTodo[] }) {
95
+ export interface TurnTodoStripProps {
96
+ todos: SessionTodo[];
97
+ /** When false, renders standalone rounded corners (e.g. isolated tests). Defaults to true. */
98
+ attachedTop?: boolean;
99
+ }
100
+
101
+ /**
102
+ * Compact 28px single-line progress strip attached directly beneath the turn's
103
+ * sticky user prompt card. Always defaults to collapsed so streaming output is
104
+ * never occluded; clicking opens a downward step list dismissed via Escape or
105
+ * outside pointerdown in any status.
106
+ */
107
+ export function TurnTodoStrip({
108
+ todos,
109
+ attachedTop = true,
110
+ }: TurnTodoStripProps) {
98
111
  const containerRef = useRef<HTMLDivElement>(null);
112
+ const panelId = useId();
113
+ const [expanded, setExpanded] = useState(false);
114
+
99
115
  const current = useMemo(() => currentTodoStep(todos), [todos]);
100
116
  const progressLabel = useMemo(() => todoProgressCopy(todos), [todos]);
101
-
102
117
  const hasActive = useMemo(
103
118
  () => todos.some((todo) => todo.status === 'in_progress'),
104
119
  [todos],
@@ -108,83 +123,72 @@ export function SessionTodoList({ todos }: { todos: SessionTodo[] }) {
108
123
  return summary.total > 0 && summary.completed === summary.total;
109
124
  }, [todos]);
110
125
 
111
- // 执行中默认展开,全部完成默认折叠;允许用户手动点击收起或展开。
112
- // 与编排胶囊同列时,展开浮层互斥。
113
- const [userToggled, setUserToggled] = useState<boolean | null>(null);
114
- const desired = userToggled ?? hasActive;
115
- const { expanded, requestOpen } = useExclusiveExpand('todos', desired);
116
-
117
- // 当任务全部执行完毕时,自动收起为紧凑胶囊
118
- useEffect(() => {
119
- if (isAllCompleted) {
120
- setUserToggled(false);
121
- }
122
- }, [isAllCompleted]);
123
-
124
- // 当新出现执行中的任务时,恢复默认展开
125
126
  useEffect(() => {
126
- if (hasActive) {
127
- setUserToggled(null);
128
- }
129
- }, [hasActive]);
130
-
131
- // 任务全部完成后,如果展开了浮层,点击外部区域时自动收起
132
- useEffect(() => {
133
- if (!expanded || !isAllCompleted) return;
127
+ if (!expanded) return;
134
128
  const handlePointerDown = (event: PointerEvent) => {
135
129
  if (
136
130
  containerRef.current &&
137
131
  !containerRef.current.contains(event.target as Node)
138
132
  ) {
139
- setUserToggled(false);
133
+ setExpanded(false);
134
+ }
135
+ };
136
+ const handleKeyDown = (event: KeyboardEvent) => {
137
+ if (event.key === 'Escape') {
138
+ event.preventDefault();
139
+ event.stopPropagation();
140
+ setExpanded(false);
140
141
  }
141
142
  };
142
143
  document.addEventListener('pointerdown', handlePointerDown);
143
- return () => document.removeEventListener('pointerdown', handlePointerDown);
144
- }, [expanded, isAllCompleted]);
144
+ document.addEventListener('keydown', handleKeyDown);
145
+ return () => {
146
+ document.removeEventListener('pointerdown', handlePointerDown);
147
+ document.removeEventListener('keydown', handleKeyDown);
148
+ };
149
+ }, [expanded]);
150
+
151
+ const shapeClass = attachedTop
152
+ ? 'rounded-b-agent-lg border border-t-0 border-agent-border/80'
153
+ : 'rounded-agent-lg border border-agent-border/80';
154
+
155
+ const toneClass = isAllCompleted
156
+ ? 'bg-emerald-500/[0.06] text-emerald-700 dark:text-emerald-300 hover:bg-emerald-500/[0.10]'
157
+ : hasActive
158
+ ? 'bg-blue-500/[0.06] text-blue-700 dark:text-blue-300 hover:bg-blue-500/[0.11]'
159
+ : 'bg-agent-canvas/90 text-agent-muted-foreground hover:bg-agent-muted/60 hover:text-agent-foreground';
145
160
 
146
161
  return (
147
162
  <div
148
163
  ref={containerRef}
149
- className="relative inline-flex items-center"
164
+ className="relative w-full"
150
165
  data-testid="session-todo-list"
151
166
  >
152
167
  <button
153
168
  type="button"
154
- onClick={() => {
155
- if (expanded) setUserToggled(false);
156
- else {
157
- setUserToggled(true);
158
- requestOpen();
159
- }
160
- }}
161
- className={[
162
- 'flex h-6 max-w-[240px] sm:max-w-[320px] items-center gap-1.5 rounded-full px-2 text-left text-[11px] transition-all duration-200 select-none shadow-2xs',
163
- isAllCompleted
164
- ? 'border border-emerald-500/25 bg-emerald-500/[0.04] text-emerald-700 dark:text-emerald-300 hover:bg-emerald-500/[0.08]'
165
- : hasActive
166
- ? 'border border-blue-500/30 bg-blue-500/[0.06] text-blue-700 dark:text-blue-300 hover:bg-blue-500/10'
167
- : 'border border-agent-border/80 bg-agent-canvas text-agent-muted-foreground hover:bg-agent-foreground/5 hover:text-agent-foreground',
168
- ].join(' ')}
169
+ onClick={() => setExpanded((prev) => !prev)}
169
170
  aria-expanded={expanded}
171
+ aria-controls={expanded ? panelId : undefined}
172
+ title={expanded ? t('Hide task steps') : t('Show task steps')}
173
+ className={`flex h-7 w-full cursor-pointer items-center gap-2 px-3 text-left text-[11px] select-none transition-colors ${shapeClass} ${toneClass}`}
170
174
  >
171
175
  {isAllCompleted ? (
172
176
  <LuCircleCheck className="h-3.5 w-3.5 shrink-0 text-emerald-600 dark:text-emerald-400" />
173
177
  ) : hasActive ? (
174
178
  <LuLoaderCircle className="h-3.5 w-3.5 shrink-0 animate-spin text-blue-600 dark:text-blue-400" />
175
- ) : current ? (
176
- <StatusIcon status={current.status} />
177
179
  ) : (
178
- <LuListChecks className="h-3.5 w-3.5 shrink-0 text-agent-foreground" />
180
+ <LuListChecks className="h-3.5 w-3.5 shrink-0 text-agent-muted-foreground" />
179
181
  )}
180
182
  <span className="min-w-0 flex-1 truncate font-medium">
181
- {isAllCompleted ? t('Task list') : (current?.content ?? t('Task list'))}
183
+ {isAllCompleted
184
+ ? t('All tasks completed')
185
+ : (current?.content ?? t('Task list'))}
182
186
  </span>
183
187
  {progressLabel ? (
184
188
  <span
185
- className={`shrink-0 rounded-full px-1.5 py-0.2 text-[10px] font-medium ${
189
+ className={`shrink-0 rounded-full px-1.5 py-0.5 font-mono text-[10px] font-medium tabular-nums leading-none ${
186
190
  isAllCompleted
187
- ? 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400'
191
+ ? 'bg-emerald-500/12 text-emerald-700 dark:text-emerald-300'
188
192
  : hasActive
189
193
  ? 'bg-blue-500/15 text-blue-700 dark:text-blue-300'
190
194
  : 'bg-agent-muted text-agent-muted-foreground'
@@ -203,25 +207,11 @@ export function SessionTodoList({ todos }: { todos: SessionTodo[] }) {
203
207
 
204
208
  {expanded && (
205
209
  <div
206
- className="absolute bottom-full right-0 mb-1.5 w-72 sm:w-80 overflow-hidden rounded-agent-lg border border-agent-border bg-agent-canvas/98 backdrop-blur-md shadow-xl z-40 animate-in fade-in slide-in-from-bottom-1 duration-150"
210
+ id={panelId}
211
+ role="region"
212
+ aria-label={t('Task list')}
213
+ className="absolute left-0 right-0 top-full z-30 mt-1 overflow-hidden rounded-agent-lg border border-agent-border bg-agent-canvas/98 shadow-lg backdrop-blur-md animate-in fade-in slide-in-from-top-1 duration-150"
207
214
  >
208
- <div className="flex items-center justify-between border-b border-agent-border/60 bg-agent-muted/30 px-2.5 py-1.5">
209
- <div className="flex items-center gap-1.5 text-[11px] font-medium text-agent-foreground">
210
- <LuListChecks className="h-3.5 w-3.5 text-agent-foreground" />
211
- <span>{t('Task list')}</span>
212
- </div>
213
- <div className="flex items-center gap-1.5">
214
- <button
215
- type="button"
216
- onClick={() => setUserToggled(false)}
217
- className="flex h-5 w-5 items-center justify-center rounded text-agent-muted-foreground transition-colors hover:bg-agent-foreground/10 hover:text-agent-foreground"
218
- title={t('Collapse list')}
219
- aria-label={t('Collapse list')}
220
- >
221
- <LuX className="h-3 w-3" />
222
- </button>
223
- </div>
224
- </div>
225
215
  <TodoItems todos={todos} compact />
226
216
  </div>
227
217
  )}
@@ -229,5 +219,6 @@ export function SessionTodoList({ todos }: { todos: SessionTodo[] }) {
229
219
  );
230
220
  }
231
221
 
232
- export default SessionTodoList;
222
+ export const SessionTodoList = TurnTodoStrip;
233
223
 
224
+ export default TurnTodoStrip;