@steerable/agent-shell-web 0.12.8 → 0.14.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerable/agent-shell-web",
3
- "version": "0.12.8",
3
+ "version": "0.14.0",
4
4
  "type": "module",
5
5
  "description": "Steerable framework — product-neutral renderer SPA source for @steerable/agent-shell (React + Vite). Consumed by product web entry points via the `@/` alias (anchored at this package's src/) and the createProductViteConfig factory. Published as a source package (src/), plus the compiled vite.base config factory (vite.base.js + .d.ts) for Node-side config loading.",
6
6
  "license": "Apache-2.0",
@@ -45,8 +45,8 @@
45
45
  "react-router-dom": "^6.30.0",
46
46
  "rehype-raw": "^7.0.0",
47
47
  "remark-gfm": "^4.0.1",
48
- "@steerable/agent-protocol": "0.12.8",
49
- "@steerable/agent-ui": "0.12.8"
48
+ "@steerable/agent-protocol": "0.14.0",
49
+ "@steerable/agent-ui": "0.14.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@tailwindcss/vite": "^4.3.0",
@@ -59,7 +59,7 @@
59
59
  "typescript": "^5.8.3",
60
60
  "vite": "^5.4.21",
61
61
  "vitest": "^3.2.4",
62
- "@steerable/pack-sdk": "0.12.8"
62
+ "@steerable/pack-sdk": "0.14.0"
63
63
  },
64
64
  "scripts": {
65
65
  "gen": "echo agent-shell-web",
@@ -430,6 +430,8 @@ interface AgentSidebarProps {
430
430
  onToggleRightPanel?: (kind: string) => void;
431
431
  /** 收起侧边栏(AgentLayout 换成窄 rail,展开按钮在 rail 上)。 */
432
432
  onCollapse: () => void;
433
+ /** Custom ApplicationManifest navigation visibility rules (bypassed under ?safe=1). */
434
+ hiddenNavItems?: readonly ('skills' | 'mcp' | 'agents' | 'terminal')[];
433
435
  }
434
436
 
435
437
  export function AgentSidebar({
@@ -437,6 +439,7 @@ export function AgentSidebar({
437
439
  rightPanel: _rightPanel,
438
440
  onToggleRightPanel: _onToggleRightPanel,
439
441
  onCollapse,
442
+ hiddenNavItems = [],
440
443
  }: AgentSidebarProps) {
441
444
  const navigate = useNavigate();
442
445
  const location = useLocation();
@@ -449,11 +452,13 @@ export function AgentSidebar({
449
452
  () => new URLSearchParams(location.search).get("section"),
450
453
  [location.search],
451
454
  );
455
+ const hiddenSet = useMemo(() => new Set(hiddenNavItems), [hiddenNavItems]);
452
456
  const pluginsAvailable =
453
- settingsChrome("agents") ||
454
- settingsChrome("skills") ||
455
- settingsChrome("mcp") ||
456
- settingsChrome("web-search");
457
+ (!hiddenSet.has("agents") && settingsChrome("agents")) ||
458
+ (!hiddenSet.has("skills") && settingsChrome("skills")) ||
459
+ (!hiddenSet.has("mcp") && settingsChrome("mcp")) ||
460
+ (!(hiddenSet.has("agents") && hiddenSet.has("skills") && hiddenSet.has("mcp")) &&
461
+ settingsChrome("web-search"));
457
462
  const onPluginsSettings =
458
463
  pluginsAvailable &&
459
464
  onSettingsPage &&
@@ -0,0 +1,64 @@
1
+ import { useState } from 'react';
2
+ import { useNavigate } from 'react-router-dom';
3
+ import { LuShieldAlert } from 'react-icons/lu';
4
+ import { t } from '@/i18n';
5
+ import { resetToDefaultApplication, stripSafeQueryParam } from '@/lib/safe-mode';
6
+
7
+ export interface SafeRecoveryBannerProps {
8
+ onResetComplete?: () => void;
9
+ }
10
+
11
+ export function SafeRecoveryBanner({ onResetComplete }: SafeRecoveryBannerProps) {
12
+ const navigate = useNavigate();
13
+ const [resetting, setResetting] = useState(false);
14
+
15
+ const handleReset = async () => {
16
+ setResetting(true);
17
+ try {
18
+ await resetToDefaultApplication();
19
+ onResetComplete?.();
20
+ if (typeof window !== 'undefined') {
21
+ const cleaned = stripSafeQueryParam(window.location.href);
22
+ window.history.replaceState(null, '', cleaned);
23
+ }
24
+ navigate('/agent');
25
+ } finally {
26
+ setResetting(false);
27
+ }
28
+ };
29
+
30
+ return (
31
+ <div
32
+ role="region"
33
+ aria-label={t('Safe recovery mode')}
34
+ data-testid="safe-recovery-banner"
35
+ className="flex items-center justify-between gap-3 border-b border-amber-500/30 bg-amber-500/10 px-3.5 py-2 text-xs text-agent-foreground"
36
+ >
37
+ <div className="flex min-w-0 items-center gap-2">
38
+ <LuShieldAlert className="h-4 w-4 flex-shrink-0 text-amber-600 dark:text-amber-400" aria-hidden="true" />
39
+ <span className="truncate font-medium">
40
+ {t('Safe recovery mode · custom application shell bypassed')}
41
+ </span>
42
+ </div>
43
+ <div className="flex flex-shrink-0 items-center gap-2">
44
+ <button
45
+ type="button"
46
+ onClick={() => navigate('/settings')}
47
+ data-testid="safe-recovery-settings"
48
+ className="rounded-md px-2 py-1 text-xs font-medium text-agent-muted-foreground transition-colors hover:bg-agent-foreground/10 hover:text-agent-foreground"
49
+ >
50
+ {t('Settings')}
51
+ </button>
52
+ <button
53
+ type="button"
54
+ disabled={resetting}
55
+ onClick={() => void handleReset()}
56
+ data-testid="safe-recovery-reset"
57
+ className="rounded-md bg-agent-foreground px-2.5 py-1 text-xs font-medium text-agent-canvas transition-opacity hover:opacity-90 disabled:opacity-50"
58
+ >
59
+ {t('Reset to default application')}
60
+ </button>
61
+ </div>
62
+ </div>
63
+ );
64
+ }
@@ -1,4 +1,5 @@
1
- import { LuShieldAlert, LuTriangleAlert } from 'react-icons/lu';
1
+ import { useEffect, useRef } from 'react';
2
+ import { LuFlag, LuShieldAlert, LuTriangleAlert } from 'react-icons/lu';
2
3
  import {
3
4
  type ApprovalDecisionKind,
4
5
  type ApprovalPromptRequest,
@@ -6,17 +7,11 @@ import {
6
7
  import { t } from '@/i18n';
7
8
 
8
9
  /**
9
- * ApprovalPromptMenu — W4-1 审批代数的输入区 UI。
10
+ * ApprovalPromptMenu — W4-1 & Phase 9 `outward` approval UI.
10
11
  *
11
- * 由 ApprovalPromptProvider 提供当前请求,在普通输入框的位置让用户对
12
- * 工具调用做 7 变体决策(允许/拒绝 × 一次性/会话/持久 + 中止)。
13
- *
14
- * 持久化语义(与框架 ApprovalExecutor 对齐):
15
- * - 一次性:只作用于本次调用,不缓存。
16
- * - 会话:按 category(默认=工具名)缓存在本 chat 的会话级 cache。
17
- * - 持久:写入 ~/.steerable/approvals.json,跨会话生效。
18
- *
19
- * 请求队列及刷新恢复由 Provider 管理。
12
+ * Supports the 7-variant approval algebra for standard/egress/sandbox prompts,
13
+ * and enforces single-invocation confirmation for `checkpoint === 'outward'`
14
+ * (hiding session/always options and placing initial keyboard focus on Reject).
20
15
  */
21
16
 
22
17
  const MODE_LABEL: Record<string, string> = {
@@ -27,8 +22,6 @@ const MODE_LABEL: Record<string, string> = {
27
22
  };
28
23
 
29
24
  function summarizeArguments(args: Record<string, unknown>): string {
30
- // 'url' 必须在前列:批准一次 web_fetch 就是批准一次出网请求,
31
- // 用户必须看清目标地址(W5-2)。
32
25
  for (const key of ['url', 'command', 'cmd', 'path', 'file', 'target', 'query', 'content']) {
33
26
  const v = args[key];
34
27
  if (typeof v === 'string' && v.length > 0) {
@@ -111,17 +104,30 @@ export function ApprovalPromptMenu({
111
104
  pendingCount: number;
112
105
  onDecide: (kind: ApprovalDecisionKind) => void;
113
106
  }) {
107
+ const isOutward = current.checkpoint === 'outward';
108
+ const outwardRejectRef = useRef<HTMLButtonElement | null>(null);
109
+
110
+ useEffect(() => {
111
+ if (!isOutward) return;
112
+ outwardRejectRef.current?.focus();
113
+ const onWindowKeyDown = (e: KeyboardEvent) => {
114
+ if (e.key === 'Escape') {
115
+ e.preventDefault();
116
+ onDecide('deny_once');
117
+ }
118
+ };
119
+ window.addEventListener('keydown', onWindowKeyDown);
120
+ return () => window.removeEventListener('keydown', onWindowKeyDown);
121
+ }, [isOutward, current.requestId, onDecide]);
122
+
114
123
  const destructive = current.mode === 'destructive';
115
- // 网络出口拓宽(W-egress-ask):sidecar 的 web 工具被 egress 代理 403
116
- // 后发起。白名单是代理进程级的(会话寿命),所以「始终」变体对网络
117
- // 出口没有意义——只给一次性/会话两档,且默认焦点在拒绝(安全默认:
118
- // 用户能认出 api.github.com,认不出 cdn.jsdelivr.net.evil.com)。
119
124
  const isEgress = current.category === 'network_egress';
120
125
  const isSandboxEscalation = current.category === 'sandbox_escalation';
121
126
  const isBrowser = current.category === 'browser';
122
127
  const sandboxOff = current.sandboxEnforced === false;
123
128
  const outsideWorkspace =
124
129
  current.outsideWorkspace === true &&
130
+ !isOutward &&
125
131
  !isEgress &&
126
132
  !isSandboxEscalation &&
127
133
  !isBrowser &&
@@ -136,132 +142,188 @@ export function ApprovalPromptMenu({
136
142
  <div
137
143
  className="overflow-hidden rounded-agent-lg border border-agent-border bg-agent-canvas text-xs text-agent-foreground shadow-xl"
138
144
  data-testid="approval-composer"
145
+ onKeyDown={(e) => {
146
+ if (isOutward && e.key === 'Escape') {
147
+ e.preventDefault();
148
+ onDecide('deny_once');
149
+ }
150
+ }}
139
151
  >
140
- <div className="flex items-center gap-2 border-b border-agent-border px-3 py-2">
141
- {destructive ? (
142
- <LuTriangleAlert className="h-4 w-4 shrink-0 text-agent-destructive" />
143
- ) : (
144
- <LuShieldAlert className="h-4 w-4 shrink-0 text-amber-500" />
145
- )}
146
- <div className="min-w-0 flex-1">
147
- <div className="text-xs font-medium text-agent-foreground">
148
- {isEgress ? (
149
- <>
150
- {t('Agent requests internet access')}
151
- <span className="mx-1 font-mono">
152
- {egressHost}
153
- {egressPort !== null ? `:${egressPort}` : ''}
152
+ <div
153
+ className={`flex items-center gap-2 border-b px-3 py-2 ${
154
+ isOutward
155
+ ? 'border-rose-500/30 bg-rose-500/10'
156
+ : 'border-agent-border'
157
+ }`}
158
+ >
159
+ {isOutward ? (
160
+ <LuFlag className="h-4 w-4 shrink-0 text-agent-destructive" aria-hidden="true" />
161
+ ) : destructive ? (
162
+ <LuTriangleAlert className="h-4 w-4 shrink-0 text-agent-destructive" />
163
+ ) : (
164
+ <LuShieldAlert className="h-4 w-4 shrink-0 text-amber-500" />
165
+ )}
166
+ <div className="min-w-0 flex-1">
167
+ <div className="text-xs font-medium text-agent-foreground">
168
+ {isOutward ? (
169
+ <span data-testid="approval-outward-badge">
170
+ {t('Outward submission · manual confirmation required every time')}
171
+ <span className="mx-1 font-mono">{current.toolName}</span>
172
+ </span>
173
+ ) : isEgress ? (
174
+ <>
175
+ {t('Agent requests internet access')}
176
+ <span className="mx-1 font-mono">
177
+ {egressHost}
178
+ {egressPort !== null ? `:${egressPort}` : ''}
179
+ </span>
180
+ {current.categoryLabel ? (
181
+ <span className="text-agent-muted-foreground">
182
+ {t('({category})', { category: categoryName(current.categoryLabel) })}
183
+ </span>
184
+ ) : null}
185
+ </>
186
+ ) : isSandboxEscalation ? (
187
+ <>
188
+ {t('Agent requests to run a command outside the workspace')}
189
+ {current.categoryLabel ? (
190
+ <span className="ml-1 text-agent-muted-foreground">
191
+ {t('({category})', { category: categoryName(current.categoryLabel) })}
154
192
  </span>
155
- {current.categoryLabel ? (
156
- <span className="text-agent-muted-foreground">
157
- {t('({category})', { category: categoryName(current.categoryLabel) })}
158
- </span>
159
- ) : null}
160
- </>
161
- ) : isSandboxEscalation ? (
162
- <>
163
- {t('Agent requests to run a command outside the workspace')}
164
- {current.categoryLabel ? (
165
- <span className="ml-1 text-agent-muted-foreground">
166
- {t('({category})', { category: categoryName(current.categoryLabel) })}
167
- </span>
168
- ) : null}
169
- </>
170
- ) : isBrowser && current.toolName === 'browser_navigate' ? (
171
- <>
172
- {t('Agent requests to open a page')}
173
- <span className="mx-1 font-mono">{current.toolName}</span>
174
- {current.categoryLabel ? (
175
- <span className="text-agent-muted-foreground">
176
- {t('({category})', { category: categoryName(current.categoryLabel) })}
177
- </span>
178
- ) : null}
179
- </>
180
- ) : (
181
- <>
182
- {t('Agent requests to run')}
183
- <span className="mx-1 font-mono">{current.toolName}</span>
193
+ ) : null}
194
+ </>
195
+ ) : isBrowser && current.toolName === 'browser_navigate' ? (
196
+ <>
197
+ {t('Agent requests to open a page')}
198
+ <span className="mx-1 font-mono">{current.toolName}</span>
199
+ {current.categoryLabel ? (
184
200
  <span className="text-agent-muted-foreground">
185
- {current.categoryLabel
186
- ? t('({category})', { category: categoryName(current.categoryLabel) })
187
- : t('({mode} action)', {
188
- mode: MODE_LABEL[current.mode] ? t(MODE_LABEL[current.mode]) : current.mode,
189
- })}
201
+ {t('({category})', { category: categoryName(current.categoryLabel) })}
190
202
  </span>
191
- </>
192
- )}
193
- </div>
194
- {pendingCount > 0 && (
195
- <div className="mt-0.5 text-[11px] text-agent-muted-foreground">
196
- {t('{count} more awaiting approval', { count: pendingCount })}
197
- </div>
203
+ ) : null}
204
+ </>
205
+ ) : (
206
+ <>
207
+ {t('Agent requests to run')}
208
+ <span className="mx-1 font-mono">{current.toolName}</span>
209
+ <span className="text-agent-muted-foreground">
210
+ {current.categoryLabel
211
+ ? t('({category})', { category: categoryName(current.categoryLabel) })
212
+ : t('({mode} action)', {
213
+ mode: MODE_LABEL[current.mode] ? t(MODE_LABEL[current.mode]) : current.mode,
214
+ })}
215
+ </span>
216
+ </>
198
217
  )}
199
218
  </div>
219
+ {pendingCount > 0 && (
220
+ <div className="mt-0.5 text-[11px] text-agent-muted-foreground">
221
+ {t('{count} more awaiting approval', { count: pendingCount })}
222
+ </div>
223
+ )}
200
224
  </div>
225
+ </div>
201
226
 
202
- <div className="max-h-48 overflow-auto px-3 py-2">
203
- <pre className="whitespace-pre-wrap break-all rounded-agent-md bg-agent-muted/50 px-3 py-2 font-mono text-xs text-agent-foreground">
204
- {summarizeArguments(current.arguments)}
205
- </pre>
206
- {isEgress ? (
207
- <p className="mt-2 text-[11px] leading-relaxed text-agent-muted-foreground">
208
- {t(
209
- 'This domain is not on the egress allowlist. Check the full spelling before allowing it (lookalike domains often use similar spellings, such as cdn.jsdelivr.net.evil.com). Allowing it applies only to this chat. To allow it permanently, add the domain to the egress allowlist in Settings.',
210
- )}
211
- </p>
212
- ) : isSandboxEscalation ? (
213
- <p className="mt-2 text-[11px] leading-relaxed text-agent-muted-foreground">
214
- {t(
215
- 'The workspace sandbox blocked this command. Allowing it retries only this command, without limiting where it can write.',
216
- )}
217
- </p>
218
- ) : isBrowser ? (
219
- <p className="mt-2 text-[11px] leading-relaxed text-agent-muted-foreground">
220
- {t(
221
- 'Opening pages, clicking, filling, and pressing keys act on that site and can send information off this computer. Scrolling, reading, and screenshots do not need approval.',
222
- )}
223
- </p>
224
- ) : outsideWorkspace ? (
225
- <p className="mt-2 text-[11px] leading-relaxed text-agent-muted-foreground">
226
- {current.outsideWorkspaceKind === 'workspace'
227
- ? cwd
228
- ? t(
229
- 'The command runs in the sandbox. Working directory {cwd} is outside this chat workspace, so writes there are blocked.',
230
- { cwd },
231
- )
232
- : t(
233
- 'The command runs in the sandbox. Its working directory is outside this chat workspace, so writes there are blocked.',
234
- )
235
- : cwd
236
- ? t(
237
- 'The command runs in the sandbox. Working directory {cwd} is outside the project, so writes there are blocked. Add that directory as a project source folder when a write is required.',
238
- { cwd },
239
- )
240
- : t(
241
- 'The command runs in the sandbox. Its working directory is outside the project, so writes there are blocked. Add that directory as a project source folder when a write is required.',
242
- )}
243
- </p>
244
- ) : (
245
- <>
246
- {current.category !== current.toolName && (
247
- <p className="mt-2 text-[11px] text-agent-muted-foreground">
248
- {t(
249
- 'Saved category: {category} (a chat or always decision applies to every call in this category)',
250
- { category: current.category },
251
- )}
252
- </p>
253
- )}
254
- {!sandboxOff && (
255
- <p className="mt-2 text-[11px] leading-relaxed text-agent-muted-foreground">
256
- {t(
257
- 'Runs in the workspace sandbox. Writes outside it are blocked. To write outside, switch the sandbox to "Full access" and try again.',
227
+ <div className="max-h-48 overflow-auto px-3 py-2">
228
+ <pre className="whitespace-pre-wrap break-all rounded-agent-md bg-agent-muted/50 px-3 py-2 font-mono text-xs text-agent-foreground">
229
+ {summarizeArguments(current.arguments)}
230
+ </pre>
231
+ {isOutward ? (
232
+ <p className="mt-2 text-[11px] leading-relaxed text-agent-muted-foreground">
233
+ {t(
234
+ 'This action submits data to an external system or modifies authoritative records. Session and permanent auto-allow grants are disabled.',
235
+ )}
236
+ </p>
237
+ ) : isEgress ? (
238
+ <p className="mt-2 text-[11px] leading-relaxed text-agent-muted-foreground">
239
+ {t(
240
+ 'This domain is not on the egress allowlist. Check the full spelling before allowing it (lookalike domains often use similar spellings, such as cdn.jsdelivr.net.evil.com). Allowing it applies only to this chat. To allow it permanently, add the domain to the egress allowlist in Settings.',
241
+ )}
242
+ </p>
243
+ ) : isSandboxEscalation ? (
244
+ <p className="mt-2 text-[11px] leading-relaxed text-agent-muted-foreground">
245
+ {t(
246
+ 'The workspace sandbox blocked this command. Allowing it retries only this command, without limiting where it can write.',
247
+ )}
248
+ </p>
249
+ ) : isBrowser ? (
250
+ <p className="mt-2 text-[11px] leading-relaxed text-agent-muted-foreground">
251
+ {t(
252
+ 'Opening pages, clicking, filling, and pressing keys act on that site and can send information off this computer. Scrolling, reading, and screenshots do not need approval.',
253
+ )}
254
+ </p>
255
+ ) : outsideWorkspace ? (
256
+ <p className="mt-2 text-[11px] leading-relaxed text-agent-muted-foreground">
257
+ {current.outsideWorkspaceKind === 'workspace'
258
+ ? cwd
259
+ ? t(
260
+ 'The command runs in the sandbox. Working directory {cwd} is outside this chat workspace, so writes there are blocked.',
261
+ { cwd },
262
+ )
263
+ : t(
264
+ 'The command runs in the sandbox. Its working directory is outside this chat workspace, so writes there are blocked.',
265
+ )
266
+ : cwd
267
+ ? t(
268
+ 'The command runs in the sandbox. Working directory {cwd} is outside the project, so writes there are blocked. Add that directory as a project source folder when a write is required.',
269
+ { cwd },
270
+ )
271
+ : t(
272
+ 'The command runs in the sandbox. Its working directory is outside the project, so writes there are blocked. Add that directory as a project source folder when a write is required.',
258
273
  )}
259
- </p>
260
- )}
261
- </>
262
- )}
263
- </div>
274
+ </p>
275
+ ) : (
276
+ <>
277
+ {current.category !== current.toolName && (
278
+ <p className="mt-2 text-[11px] text-agent-muted-foreground">
279
+ {t(
280
+ 'Saved category: {category} (a chat or always decision applies to every call in this category)',
281
+ { category: current.category },
282
+ )}
283
+ </p>
284
+ )}
285
+ {!sandboxOff && (
286
+ <p className="mt-2 text-[11px] leading-relaxed text-agent-muted-foreground">
287
+ {t(
288
+ 'Runs in the workspace sandbox. Writes outside it are blocked. To write outside, switch the sandbox to "Full access" and try again.',
289
+ )}
290
+ </p>
291
+ )}
292
+ </>
293
+ )}
294
+ </div>
264
295
 
296
+ {isOutward ? (
297
+ <div className="flex flex-wrap items-center justify-between gap-2 border-t border-agent-border px-3 py-2">
298
+ <div className="flex flex-wrap items-center gap-2">
299
+ <button
300
+ ref={outwardRejectRef}
301
+ type="button"
302
+ data-testid="approval-deny_once"
303
+ onClick={() => onDecide('deny_once')}
304
+ className="rounded-agent-md border border-agent-border px-3 py-1.5 text-xs font-medium text-agent-foreground transition hover:bg-agent-muted"
305
+ >
306
+ {t('Reject this submission')}
307
+ </button>
308
+ <button
309
+ type="button"
310
+ data-testid="approval-abort"
311
+ onClick={() => onDecide('abort')}
312
+ className="rounded-agent-md bg-agent-destructive px-3 py-1.5 text-xs font-medium text-white transition hover:opacity-90"
313
+ >
314
+ {t('Abort this turn')}
315
+ </button>
316
+ </div>
317
+ <button
318
+ type="button"
319
+ data-testid="approval-allow_once"
320
+ onClick={() => onDecide('allow_once')}
321
+ className="rounded-agent-md bg-agent-foreground px-3 py-1.5 text-xs font-medium text-agent-canvas transition hover:opacity-90"
322
+ >
323
+ {t('Approve this submission')}
324
+ </button>
325
+ </div>
326
+ ) : (
265
327
  <div className="space-y-2 border-t border-agent-border px-3 py-2">
266
328
  <DecisionRow
267
329
  buttons={
@@ -295,6 +357,7 @@ export function ApprovalPromptMenu({
295
357
  : t('"This chat" applies only to this chat. "Always" is saved on this computer and applies to every chat.')}
296
358
  </p>
297
359
  </div>
360
+ )}
298
361
  </div>
299
362
  );
300
363
  }
@@ -20,6 +20,7 @@ import type { ChildInfo } from './OrchestrationChildrenCard';
20
20
  import { collectTurnParticipants, extractMentionedAgentIds } from './executed-actions-model';
21
21
  import type { InspectTaskInput } from './executed-actions-model';
22
22
  import { StreamingStatus } from './StreamingStatus';
23
+ import { classifyErrorMessage } from '@steerable/agent-protocol';
23
24
  import { TurnFailureCard, type TurnFailureCardProps } from './TurnFailureCard';
24
25
  import { readFailureDetail, type TurnFailureDetail } from './turn-failure';
25
26
  import type { RetryState } from './RetryStatus';
@@ -286,34 +287,48 @@ function readTurnStatus(message: ChatMessage): 'failed' | 'cancelled' | 'complet
286
287
  }
287
288
 
288
289
  function readTurnFailure(message: ChatMessage, content: string): TurnFailure | null {
289
- if (content.startsWith(STREAM_ERROR_PREFIX)) {
290
- // Live path: the framework stamped the reason into the content before the
291
- // turn was persisted, so nothing structured is available yet.
292
- return { reason: content.slice(STREAM_ERROR_PREFIX.length), contentIsError: true };
293
- }
290
+ const isStreamErrorContent = content.startsWith(STREAM_ERROR_PREFIX);
294
291
  const raw = (message as { messageMetadata?: unknown }).messageMetadata;
295
- if (typeof raw !== 'string' || !raw) return null;
296
- try {
297
- const meta = JSON.parse(raw) as {
298
- completionStatus?: unknown;
299
- completionReason?: unknown;
300
- failure?: unknown;
301
- traceId?: unknown;
302
- };
303
- if (
304
- meta?.completionStatus === 'failed' &&
305
- typeof meta.completionReason === 'string' &&
306
- meta.completionReason
307
- ) {
308
- return {
309
- reason: meta.completionReason,
310
- contentIsError: false,
311
- detail: readFailureDetail(meta.failure),
312
- traceId: typeof meta.traceId === 'string' && meta.traceId ? meta.traceId : undefined,
292
+ if (typeof raw === 'string' && raw) {
293
+ try {
294
+ const meta = JSON.parse(raw) as {
295
+ completionStatus?: unknown;
296
+ completionReason?: unknown;
297
+ failure?: unknown;
298
+ failureInfo?: unknown;
299
+ traceId?: unknown;
313
300
  };
301
+ if (
302
+ meta?.completionStatus === 'failed' &&
303
+ typeof meta.completionReason === 'string' &&
304
+ meta.completionReason
305
+ ) {
306
+ const parsedDetail =
307
+ readFailureDetail(meta.failure) ?? readFailureDetail(meta.failureInfo);
308
+ const fallbackKind = classifyErrorMessage(meta.completionReason);
309
+ return {
310
+ reason: meta.completionReason,
311
+ contentIsError: isStreamErrorContent,
312
+ detail:
313
+ parsedDetail ??
314
+ (fallbackKind !== 'unknown' ? { kind: fallbackKind } : undefined),
315
+ traceId: typeof meta.traceId === 'string' && meta.traceId ? meta.traceId : undefined,
316
+ };
317
+ }
318
+ } catch {
319
+ // 元数据损坏按无失败处理——落回下方的流式前缀兜底或空消息展示。
314
320
  }
315
- } catch {
316
- // 元数据损坏按无失败处理——落回原有的空消息展示。
321
+ }
322
+ if (isStreamErrorContent) {
323
+ // Live path before message_id arrives: the framework stamped the reason
324
+ // into the content before the turn was persisted.
325
+ const rawReason = content.slice(STREAM_ERROR_PREFIX.length);
326
+ const fallbackKind = classifyErrorMessage(rawReason);
327
+ return {
328
+ reason: rawReason,
329
+ contentIsError: true,
330
+ detail: fallbackKind !== 'unknown' ? { kind: fallbackKind } : undefined,
331
+ };
317
332
  }
318
333
  return null;
319
334
  }
@@ -1165,7 +1165,21 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
1165
1165
  useEffect(() => {
1166
1166
  if (slashQuery) {
1167
1167
  const query = slashQuery.query;
1168
- const skillMatches: SlashSuggestion[] = skills
1168
+ const builtinCommandSkills: SkillItem[] = [
1169
+ {
1170
+ name: 'compact',
1171
+ displayName: 'Compact context',
1172
+ description: t('Summarize earlier messages to free up context window space'),
1173
+ isBuiltin: true,
1174
+ },
1175
+ ];
1176
+ const allSkills = [
1177
+ ...builtinCommandSkills.filter(
1178
+ (b) => !skills.some((s) => s.name.toLowerCase() === b.name),
1179
+ ),
1180
+ ...skills,
1181
+ ];
1182
+ const skillMatches: SlashSuggestion[] = allSkills
1169
1183
  .filter(
1170
1184
  (s) =>
1171
1185
  s.name.toLowerCase().includes(query) ||