@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,35 +1,16 @@
1
1
  import { useEffect, useRef, useState } from 'react';
2
- import { LuChevronDown, LuFolderLock, LuLockOpen } from 'react-icons/lu';
2
+ import { LuChevronDown, LuShieldAlert, LuShieldCheck } from 'react-icons/lu';
3
3
  import type { ExecPolicy } from '@/lib/exec-policy';
4
4
  import { t } from '@/i18n';
5
5
 
6
6
  /**
7
- * ExecPolicyPicker — 输入框上的命令沙箱切换(类 Codex 底部权限档)。
7
+ * ExecPolicyPicker — WorkBuddy-style sandbox permission pill + Switch card.
8
8
  *
9
- * 切档立刻记住。排队的下一轮按当时的档开流;插进当前回合的消息会改
10
- * 这一回合后面的命令沙箱。已经在跑的那条命令保持它开始时的档。
11
- * 工作区 = Seatbelt/bwrap 只允许写项目家目录、源文件夹(含各自子目录)或本对话工作区;完整权限
12
- * = 不下发命令沙箱,本机路径(如 Downloads)不再被 Operation not permitted 拦住。
9
+ * Default (`workspace`) confines writes and shell commands to the current
10
+ * workspace/project folders and prompts before stepping outside; toggling
11
+ * `Allow full access` (`full`) turns off the command sandbox for this session.
13
12
  */
14
13
 
15
- const OPTIONS: Array<{
16
- id: ExecPolicy;
17
- label: string;
18
- description: string;
19
- }> = [
20
- {
21
- id: 'workspace',
22
- label: 'Workspace',
23
- description: 'Can only write to the current workspace. Paths outside it are blocked.',
24
- },
25
- {
26
- id: 'full',
27
- label: 'Full access',
28
- description:
29
- 'Turns off the command sandbox so any path on this computer can be written. Tool approvals still apply.',
30
- },
31
- ];
32
-
33
14
  export function ExecPolicyPicker({
34
15
  policy,
35
16
  disabled,
@@ -41,81 +22,105 @@ export function ExecPolicyPicker({
41
22
  }) {
42
23
  const [open, setOpen] = useState(false);
43
24
  const rootRef = useRef<HTMLDivElement>(null);
44
- const current = OPTIONS.find((option) => option.id === policy) ?? OPTIONS[0];
45
25
  const isFull = policy === 'full';
46
26
 
47
27
  useEffect(() => {
48
28
  if (!open) return;
49
- const onPointerDown = (event: MouseEvent) => {
29
+ const onPointerDown = (event: PointerEvent | MouseEvent) => {
50
30
  if (rootRef.current && !rootRef.current.contains(event.target as Node)) {
51
31
  setOpen(false);
52
32
  }
53
33
  };
54
- document.addEventListener('mousedown', onPointerDown);
55
- return () => document.removeEventListener('mousedown', onPointerDown);
34
+ const onKeyDown = (event: KeyboardEvent) => {
35
+ if (event.key === 'Escape') {
36
+ event.stopPropagation();
37
+ setOpen(false);
38
+ }
39
+ };
40
+ document.addEventListener('pointerdown', onPointerDown);
41
+ document.addEventListener('keydown', onKeyDown);
42
+ return () => {
43
+ document.removeEventListener('pointerdown', onPointerDown);
44
+ document.removeEventListener('keydown', onKeyDown);
45
+ };
56
46
  }, [open]);
57
47
 
48
+ const descriptionText = isFull
49
+ ? t(
50
+ 'Full access is enabled. The command sandbox is off so any path on this computer can be accessed.',
51
+ )
52
+ : t(
53
+ 'Running with default permissions. Operations stay within the safety sandbox and ask before going outside.',
54
+ );
55
+
58
56
  return (
59
57
  <div ref={rootRef} className="relative">
60
58
  <button
61
59
  type="button"
62
60
  disabled={disabled}
63
- aria-haspopup="listbox"
61
+ aria-haspopup="dialog"
64
62
  aria-expanded={open}
65
63
  aria-label={t('Command sandbox')}
66
64
  data-testid="exec-policy-picker"
67
- title={t(current.description)}
65
+ title={descriptionText}
68
66
  onClick={() => setOpen((next) => !next)}
69
67
  className={[
70
- 'inline-flex h-6 max-w-[140px] items-center gap-1 rounded-full border px-2 text-[12px] leading-[1.45] transition-colors disabled:cursor-not-allowed disabled:opacity-70',
68
+ 'inline-flex h-6 max-w-[150px] items-center gap-1 rounded-full border px-2 text-[12px] leading-[1.45] transition-colors disabled:cursor-not-allowed disabled:opacity-70',
71
69
  isFull
72
- ? 'border-amber-400/50 bg-amber-400/10 text-amber-700 dark:text-amber-400'
70
+ ? 'border-amber-400/55 bg-amber-400/12 font-medium text-amber-700 dark:text-amber-300'
73
71
  : 'border-transparent bg-transparent text-agent-muted-foreground hover:bg-agent-foreground/5 hover:text-agent-foreground',
74
72
  ].join(' ')}
75
73
  >
76
74
  {isFull ? (
77
- <LuLockOpen className="h-3 w-3 shrink-0" />
75
+ <LuShieldAlert className="h-3.5 w-3.5 shrink-0" />
78
76
  ) : (
79
- <LuFolderLock className="h-3 w-3 shrink-0" />
77
+ <LuShieldCheck className="h-3.5 w-3.5 shrink-0" />
80
78
  )}
81
- <span className="truncate">{t(current.label)}</span>
82
- <LuChevronDown className="h-3 w-3 shrink-0 text-agent-muted-foreground" />
79
+ <span className="truncate">
80
+ {isFull ? t('Full access') : t('Default permissions')}
81
+ </span>
82
+ <LuChevronDown
83
+ className={`h-3 w-3 shrink-0 text-current opacity-75 transition-transform ${
84
+ open ? 'rotate-180' : ''
85
+ }`}
86
+ />
83
87
  </button>
88
+
84
89
  {open && (
85
90
  <div
86
- role="listbox"
91
+ role="dialog"
87
92
  aria-label={t('Command sandbox')}
88
- className="absolute bottom-full left-0 z-30 mb-1 w-64 overflow-hidden rounded-agent-md border border-agent-border bg-agent-canvas py-1 shadow-sm"
93
+ className="absolute bottom-full left-0 z-40 mb-1.5 w-64 rounded-agent-lg border border-agent-border bg-agent-canvas p-3 shadow-lg"
89
94
  >
90
- {OPTIONS.map((option) => {
91
- const selected = option.id === policy;
92
- return (
93
- <button
94
- key={option.id}
95
- type="button"
96
- role="option"
97
- aria-selected={selected}
98
- data-testid={`exec-policy-${option.id}`}
99
- onClick={() => {
100
- onChange(option.id);
101
- setOpen(false);
102
- }}
103
- className={[
104
- 'flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left transition-colors',
105
- selected
106
- ? 'bg-agent-foreground/10'
107
- : 'hover:bg-agent-foreground/5',
108
- ].join(' ')}
109
- >
110
- <span className="text-[12px] font-medium leading-[1.45] text-agent-foreground">
111
- {t(option.label)}
112
- </span>
113
- <span className="text-[11px] leading-snug text-agent-muted-foreground">
114
- {t(option.description)}
115
- </span>
116
- </button>
117
- );
118
- })}
95
+ <p className="m-0 text-[11px] leading-relaxed text-agent-muted-foreground">
96
+ {descriptionText}
97
+ </p>
98
+ <div className="my-2.5 border-t border-agent-border/60" />
99
+ <button
100
+ type="button"
101
+ role="switch"
102
+ aria-checked={isFull}
103
+ data-testid="exec-policy-full"
104
+ onClick={() => {
105
+ onChange(isFull ? 'workspace' : 'full');
106
+ setOpen(false);
107
+ }}
108
+ className="flex w-full cursor-pointer items-center justify-between gap-2 rounded-agent-sm py-0.5 text-left text-[12px] font-medium text-agent-foreground transition-opacity hover:opacity-90"
109
+ >
110
+ <span>{t('Allow full access')}</span>
111
+ <span
112
+ aria-hidden="true"
113
+ className={`inline-flex h-5 w-9 shrink-0 items-center rounded-full p-0.5 transition-colors ${
114
+ isFull ? 'bg-amber-500' : 'bg-agent-muted-foreground/30'
115
+ }`}
116
+ >
117
+ <span
118
+ className={`h-4 w-4 rounded-full bg-white shadow-xs transition-transform ${
119
+ isFull ? 'translate-x-4' : 'translate-x-0'
120
+ }`}
121
+ />
122
+ </span>
123
+ </button>
119
124
  </div>
120
125
  )}
121
126
  </div>
@@ -24,8 +24,6 @@ import type { TurnFailureCardProps } from './TurnFailureCard';
24
24
  import type { LlmSpeedSnapshot } from './process-status';
25
25
  import { ComposerStatusStack } from './composer-status-stack';
26
26
  import { t } from '@/i18n';
27
- import { SessionTodoList } from './SessionTodoList';
28
- import { resolveLatestSessionTodos, shouldShowComposerTodos } from './todo-list-model';
29
27
  import { SessionOrchestrationFlow } from './SessionOrchestrationFlow';
30
28
  import { resolveLatestSessionOrchestrationFlow } from './orchestration-flow-model';
31
29
  import {
@@ -370,24 +368,6 @@ export function LocalChatPanel({
370
368
  selectedAgentId,
371
369
  ]);
372
370
 
373
- const sessionTodos = useMemo(
374
- () =>
375
- resolveLatestSessionTodos({
376
- messages,
377
- executedActionsByMessageId,
378
- currentTurnActions,
379
- timelineByMessageId,
380
- currentTurnTimeline,
381
- }),
382
- [
383
- messages,
384
- executedActionsByMessageId,
385
- currentTurnActions,
386
- timelineByMessageId,
387
- currentTurnTimeline,
388
- ],
389
- );
390
-
391
371
  const sessionOrchestrationFlow = useMemo(
392
372
  () =>
393
373
  resolveLatestSessionOrchestrationFlow({
@@ -485,22 +465,17 @@ export function LocalChatPanel({
485
465
  selectedAgentId={selectedAgentId}
486
466
  onSelectAgent={onSelectAgent}
487
467
  onOpenSettings={onOpenSettings}
488
- toolbarExtras={inputToolbarExtras}
468
+ layoutVariant={showEmptyHero ? 'hero' : 'chat'}
469
+ toolbarTrailing={inputToolbarExtras}
489
470
  leadingChrome={inputLeadingChrome}
490
471
  trailingChrome={
491
- sessionOrchestrationFlow ||
492
- shouldShowComposerTodos(sessionTodos, isStreaming) ? (
472
+ sessionOrchestrationFlow ? (
493
473
  <ComposerStatusStack>
494
- {sessionOrchestrationFlow ? (
495
- <SessionOrchestrationFlow
496
- flow={sessionOrchestrationFlow}
497
- chatId={chatId}
498
- onInspectTask={onInspectTask}
499
- />
500
- ) : null}
501
- {shouldShowComposerTodos(sessionTodos, isStreaming) ? (
502
- <SessionTodoList todos={sessionTodos} />
503
- ) : null}
474
+ <SessionOrchestrationFlow
475
+ flow={sessionOrchestrationFlow}
476
+ chatId={chatId}
477
+ onInspectTask={onInspectTask}
478
+ />
504
479
  </ComposerStatusStack>
505
480
  ) : undefined
506
481
  }
@@ -28,6 +28,8 @@ import { inferDurationMs, readPersistedDurationMs } from './elapsed';
28
28
  import type { LlmSpeedSnapshot } from './process-status';
29
29
  import type { RetryState } from './RetryStatus';
30
30
  import type { TurnFailureCardProps } from './TurnFailureCard';
31
+ import { TurnTodoStrip } from './SessionTodoList';
32
+ import { resolveTurnTodos, shouldShowTurnTodoStrip } from './todo-list-model';
31
33
 
32
34
  /**
33
35
  * MessageList — scrolling viewport that renders user/assistant message
@@ -327,39 +329,80 @@ export function MessageList({
327
329
  }, [checkAtBottom]);
328
330
 
329
331
  // 右侧预览跟着这一屏在看的回合。停在底部时用最近一份能打开的产物。
332
+ // 区分「历史会话水合」与「本会话活跃流式回合新产出的主交付物」:仅后者带 autoReveal: true 自动开栏。
333
+ const previewHistoryByChatRef = useRef<
334
+ Map<string, { hadLiveStream: boolean; seenPaths: Set<string> }>
335
+ >(new Map());
336
+ if (chatId) {
337
+ let entry = previewHistoryByChatRef.current.get(chatId);
338
+ if (!entry) {
339
+ entry = { hadLiveStream: false, seenPaths: new Set() };
340
+ previewHistoryByChatRef.current.set(chatId, entry);
341
+ }
342
+ if (isStreaming) {
343
+ entry.hadLiveStream = true;
344
+ }
345
+ }
346
+
330
347
  useEffect(() => {
331
348
  if (!chatId) return;
332
- const publish = () => {
349
+ let entry = previewHistoryByChatRef.current.get(chatId);
350
+ if (!entry) {
351
+ entry = { hadLiveStream: isStreaming, seenPaths: new Set() };
352
+ previewHistoryByChatRef.current.set(chatId, entry);
353
+ }
354
+ if (isStreaming) {
355
+ entry.hadLiveStream = true;
356
+ }
357
+
358
+ const ordered = visibleMessages
359
+ .filter((message) => message.role === 'assistant')
360
+ .map((message) => ({
361
+ id: message.id,
362
+ files: message.id === lastAssistantId
363
+ ? (turnFilesByMessageId?.[message.id] ?? currentTurnFiles)
364
+ : turnFilesByMessageId?.[message.id],
365
+ }));
366
+
367
+ // 首次未经历流式的静态水合:把既有产物全部记入基准集合,避免打开旧会话时突然弹开右侧栏。
368
+ if (!entry.hadLiveStream) {
369
+ for (const item of ordered) {
370
+ for (const file of item.files ?? []) {
371
+ if (file.path) entry.seenPaths.add(file.path);
372
+ }
373
+ }
374
+ }
375
+
376
+ const publish = (allowAutoReveal: boolean) => {
333
377
  const el = containerRef.current;
334
378
  if (!el) return;
335
379
  const atBottom =
336
380
  el.scrollHeight - el.scrollTop - el.clientHeight < NEAR_BOTTOM_THRESHOLD_PX;
337
- const ordered = visibleMessages
338
- .filter((message) => message.role === 'assistant')
339
- .map((message) => ({
340
- id: message.id,
341
- files: message.id === lastAssistantId
342
- ? (turnFilesByMessageId?.[message.id] ?? currentTurnFiles)
343
- : turnFilesByMessageId?.[message.id],
344
- }));
345
381
  const selected = followedPreviewPath(ordered, {
346
382
  atBottom,
347
383
  focusedId: atBottom ? null : assistantIdInView(el),
348
384
  });
349
385
  if (!selected) return;
386
+ const isNewLiveDeliverable =
387
+ allowAutoReveal &&
388
+ Boolean(entry?.hadLiveStream) &&
389
+ !entry!.seenPaths.has(selected.path);
390
+ entry?.seenPaths.add(selected.path);
350
391
  publishConversationPreview({
351
392
  chatId,
352
393
  messageId: selected.messageId,
353
394
  path: selected.path,
395
+ ...(isNewLiveDeliverable ? { autoReveal: true } : {}),
354
396
  });
355
397
  };
356
- publish();
398
+ publish(true);
399
+ const onScroll = () => publish(false);
357
400
  const el = containerRef.current;
358
- el?.addEventListener('scroll', publish, { passive: true });
401
+ el?.addEventListener('scroll', onScroll, { passive: true });
359
402
  return () => {
360
- el?.removeEventListener('scroll', publish);
403
+ el?.removeEventListener('scroll', onScroll);
361
404
  };
362
- }, [chatId, currentTurnFiles, lastAssistantId, messages, turnFilesByMessageId]);
405
+ }, [chatId, currentTurnFiles, isStreaming, lastAssistantId, messages, turnFilesByMessageId]);
363
406
 
364
407
  // Snap to bottom on first paint, regardless of whether the user "was" at
365
408
  // the bottom — there's no "before" on mount.
@@ -471,15 +514,44 @@ export function MessageList({
471
514
  emptyState ?? null
472
515
  ) : (
473
516
  <div className="mx-auto w-full max-w-3xl space-y-4">
474
- {conversationTurns.map((turn) => (
517
+ {conversationTurns.map((turn, turnIndex) => {
518
+ const isLatestTurn = turnIndex === conversationTurns.length - 1;
519
+ const hasVisibleUserGroup = Boolean(
520
+ turn.userGroup &&
521
+ !turn.userGroup.messages.every((message) => internalTrigger(message) !== null),
522
+ );
523
+ const isSingleCompactionDivider = Boolean(
524
+ turn.userGroup &&
525
+ turn.userGroup.messages.length === 1 &&
526
+ turn.userGroup.messages[0].content.startsWith(COMPACTED_SUMMARY_PREFIX),
527
+ );
528
+ const turnTodos =
529
+ hasVisibleUserGroup && !isSingleCompactionDivider
530
+ ? resolveTurnTodos({
531
+ assistantMessageIds: turn.assistants.map((item) => item.message.id),
532
+ isLatestTurn,
533
+ executedActionsByMessageId,
534
+ timelineByMessageId,
535
+ currentTurnActions,
536
+ currentTurnTimeline,
537
+ })
538
+ : null;
539
+ const showTurnTodoStrip =
540
+ hasVisibleUserGroup &&
541
+ !isSingleCompactionDivider &&
542
+ shouldShowTurnTodoStrip(turnTodos, {
543
+ isLatestTurn,
544
+ isTurnStreaming: isLatestTurn && isStreaming,
545
+ });
546
+
547
+ return (
475
548
  <div
476
549
  key={turn.key}
477
550
  className="conversation-turn relative space-y-4"
478
551
  data-conversation-turn={turn.key}
479
552
  >
480
- {turn.userGroup &&
481
- !turn.userGroup.messages.every((message) => internalTrigger(message) !== null) ? (
482
- <div className="sticky top-0 z-10 -mx-3 px-3 py-1 bg-agent-canvas/95 backdrop-blur-xs">
553
+ {hasVisibleUserGroup && turn.userGroup ? (
554
+ <div className="sticky top-0 z-20 -mx-3 px-3 py-1 bg-agent-canvas/95 backdrop-blur-xs">
483
555
  {turn.userGroup.messages.length === 1 ? (
484
556
  internalTrigger(turn.userGroup.messages[0]) ? (
485
557
  null
@@ -494,6 +566,7 @@ export function MessageList({
494
566
  message={turn.userGroup.messages[0]}
495
567
  agents={agents}
496
568
  chats={chats}
569
+ attachedBottom={showTurnTodoStrip}
497
570
  onEdit={
498
571
  turn.userGroup.messages[0].id === lastUserId && onEditUserMessage
499
572
  ? (nextText) => onEditUserMessage(turn.userGroup!.messages[0].id, nextText)
@@ -508,7 +581,13 @@ export function MessageList({
508
581
  data-message-role="user-group"
509
582
  >
510
583
  <div className="flex justify-start">
511
- <div className="mx-auto w-full max-w-[var(--chat-input-box-width)] overflow-hidden rounded-agent-lg border border-agent-border/80 bg-agent-muted/70 shadow-sm">
584
+ <div
585
+ className={`mx-auto w-full max-w-[var(--chat-input-box-width)] overflow-hidden ${
586
+ showTurnTodoStrip
587
+ ? 'rounded-t-agent-lg rounded-b-none'
588
+ : 'rounded-agent-lg'
589
+ } border border-agent-border/80 bg-agent-muted/70 shadow-sm`}
590
+ >
512
591
  {turn.userGroup.messages.map((msg, idx) => (
513
592
  internalTrigger(msg) ? (
514
593
  null
@@ -536,6 +615,11 @@ export function MessageList({
536
615
  </div>
537
616
  </div>
538
617
  )}
618
+ {showTurnTodoStrip && turnTodos ? (
619
+ <div className="mx-auto w-full max-w-[var(--chat-input-box-width)]">
620
+ <TurnTodoStrip todos={turnTodos} attachedTop />
621
+ </div>
622
+ ) : null}
539
623
  </div>
540
624
  ) : null}
541
625
 
@@ -651,6 +735,11 @@ export function MessageList({
651
735
  onInspectTask={onInspectTask}
652
736
  onContinueChild={onContinueChild}
653
737
  onStopChild={onStopChild}
738
+ hideInlineNextSteps={
739
+ isStreamingTail ||
740
+ (message.id === lastAssistantId &&
741
+ Boolean(suggestedReplies && suggestedReplies.length > 0 && onSelectSuggestion))
742
+ }
654
743
  />
655
744
  {!isStreaming &&
656
745
  message.id === lastAssistantId &&
@@ -666,7 +755,8 @@ export function MessageList({
666
755
  );
667
756
  })}
668
757
  </div>
669
- ))}
758
+ );
759
+ })}
670
760
  {/* W7-1: 中断提示卡在消息列尾部、与最后一条用户消息同列——
671
761
  视觉上隶属于被截断的那一轮,而非全局横幅。流式期间不显示
672
762
  (进行中的流不是中断)。 */}
@@ -150,7 +150,7 @@ export function ModelPicker({
150
150
  {modelMenuOpen && (
151
151
  <div
152
152
  role="menu"
153
- className="absolute bottom-full left-0 z-50 mb-1 max-h-72 w-80 overflow-y-auto rounded-agent-md border border-agent-border bg-agent-canvas p-1 shadow-lg"
153
+ className="absolute bottom-full right-0 z-50 mb-1 max-h-72 w-80 max-w-[calc(100vw-2rem)] overflow-y-auto rounded-agent-md border border-agent-border bg-agent-canvas p-1 shadow-lg"
154
154
  >
155
155
  <div className="flex items-center justify-between gap-2 px-2 py-1">
156
156
  <span className="text-[10px] font-semibold uppercase tracking-wider text-agent-muted-foreground">
@@ -275,7 +275,7 @@ export function ModelPicker({
275
275
  {effortMenuOpen && (
276
276
  <div
277
277
  role="menu"
278
- className="absolute bottom-full left-0 z-50 mb-1 w-36 overflow-y-auto rounded-agent-md border border-agent-border bg-agent-canvas p-1 shadow-lg"
278
+ className="absolute bottom-full right-0 z-50 mb-1 w-36 overflow-y-auto rounded-agent-md border border-agent-border bg-agent-canvas p-1 shadow-lg"
279
279
  >
280
280
  <button
281
281
  type="button"