mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 16:29:04 +00:00
Approvals: Details shows the whole command the agent asks to run, not its first 600 characters (#5856)
"Run N steps on your computer?" put the card's preview under Details, a summary
cut at 600 characters, so a long chain of commands could not be read before
Approve. Details now shows the call's own full command (approvalDetail in
lib/approvals.ts: shell calls; every other action keeps its preview), in a box
that scrolls past 40% of the window height and takes the keyboard focus (tab,
arrow keys). The approved call is unchanged. No new text.
Test: tests/approval-detail.test.mjs (ten long steps with quotes and newlines
byte for byte through presentTool; other actions; the card and its CSS): 3 fail on
9e4ef7ee8, pass here; ui-do 38/38; tsc clean.
This commit is contained in:
1 parent
9e4ef7ee88
commit
70667dd72a
4 files changed
+47
-3
No files matched your search
@@ -4,7 +4,7 @@ import { tr } from '../lib/i18n';
|
||||
import { Btn, Icon } from './ui';
|
||||
import { askQuestion, askSub, askIcon } from '../lib/ask';
|
||||
import { resolveTool, useStore } from '../lib/store';
|
||||
import { pendingApprovals } from '../lib/approvals';
|
||||
import { approvalDetail, pendingApprovals } from '../lib/approvals';
|
||||
import { QuestionCard } from './QuestionCard';
|
||||
import type { AgentAsk } from '../lib/agent-ask';
|
||||
import type { ToolCall } from '../lib/types';
|
||||
@@ -31,7 +31,7 @@ export function ApprovalCard({ messageId, tool: t }: {
|
||||
<div className="askcard__top"><span className="askcard__icon"><Icon name={askIcon(t.ask)} size={18}/></span>
|
||||
<div className="askcard__text"><p className="askcard__q">{askQuestion(t.ask)}</p>{askSub(t.ask) ? <p className="askcard__why" title={askSub(t.ask)}>{askSub(t.ask)}</p> : null}</div>
|
||||
<div className="askcard__acts"><Btn size="sm" onClick={() => resolveTool(messageId, t.id, false)}>{tr("Deny")}</Btn><Btn variant="primary" size="sm" onClick={() => resolveTool(messageId, t.id, true)}>{tr("Approve")}</Btn></div></div>
|
||||
<details className="askcard__details"><summary><Icon name="chevron" size={11}/>{tr("Details")}</summary><pre>{t.preview}</pre></details>
|
||||
<details className="askcard__details"><summary><Icon name="chevron" size={11}/>{tr("Details")}</summary><pre tabIndex={0}>{approvalDetail(t)}</pre></details>
|
||||
</section>;
|
||||
return <section className="toolcard toolcard--compact" data-state={t.state} aria-label={t.name}>
|
||||
<details className="toolcard__disclosure">
|
||||
|
||||
@@ -9,3 +9,13 @@ export function pendingApprovals(session: { messages: { id: string; tools?: Tool
|
||||
out.push({ messageId: m.id, tool });
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the approval card's Details shows: every byte the agent asks to run (#5856). The card's preview is a short summary (cut at 600
|
||||
* characters, whitespace as given); for a command the full command comes from the call's own arguments, so ten long steps can all be
|
||||
* read before Approve. Anything else keeps the preview.
|
||||
*/
|
||||
export function approvalDetail(t: Pick<ToolCall, 'scope' | 'args' | 'preview'>): string {
|
||||
const command = t.scope === 'shell' ? t.args?.command : undefined;
|
||||
return typeof command === 'string' && command.length > 0 ? command : t.preview;
|
||||
}
|
||||
@@ -7080,7 +7080,7 @@ textarea {
|
||||
.askcard__details summary { list-style: none; cursor: pointer; padding: 6px 14px; font-size: var(--st-fs-xs); font-weight: 500; color: var(--st-ink-muted); display: flex; align-items: center; gap: 6px; }
|
||||
.askcard__details summary::-webkit-details-marker { display: none; }
|
||||
.askcard__details[open] summary svg { transform: rotate(180deg); }
|
||||
.askcard__details pre { margin: 0 14px 10px; padding: 8px 10px; background: var(--st-code-bg); color: var(--st-code-ink); border-radius: var(--st-r-sm); font: 12px/1.5 var(--st-font-mono); white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
.askcard__details pre { margin: 0 14px 10px; padding: 8px 10px; background: var(--st-code-bg); color: var(--st-code-ink); border-radius: var(--st-r-sm); font: 12px/1.5 var(--st-font-mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 40vh; overflow: auto; } /* the whole command, scrolled when long (#5856); focusable for the keyboard */
|
||||
@media (max-width: 560px) { .askcard__top { flex-wrap: wrap; } .askcard__acts { margin-left: 32px; } }
|
||||
|
||||
/* ---- an opened task ---- */
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// #5856: "Run 10 steps on your computer?" showed only the start of what would run: Details held the card's preview, cut at 600 characters.
|
||||
// Details now shows the call's own full command, every byte, in a box that scrolls and takes the keyboard focus.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { build } from 'esbuild';
|
||||
import { presentTool } from '../server/agent/events.mjs';
|
||||
|
||||
const built = await build({ entryPoints: [fileURLToPath(new URL('../src/lib/approvals.ts', import.meta.url))], bundle: true, write: false, platform: 'node', format: 'esm' });
|
||||
const { approvalDetail } = await import(`data:text/javascript;base64,${Buffer.from(built.outputFiles[0].text).toString('base64')}`);
|
||||
|
||||
test('ten long steps, quotes and newlines: Details shows every byte the agent asks to run', () => {
|
||||
const steps = Array.from({ length: 10 }, (_, i) => `Copy-Item -Path "C:\\Projects\\very long folder name ${i}\\with 'quotes' and spaces\\file${i}.txt" -Destination "D:\\Backup\\${i}"`);
|
||||
const command = steps.join(' ; \n') + '\n';
|
||||
const card = presentTool({ callId: 'c1', name: 'pwsh', args: { command, description: 'copy files' } });
|
||||
assert.equal(card.scope, 'shell');
|
||||
assert.ok(card.preview.length < command.length, 'the card\'s own summary stays short');
|
||||
assert.equal(approvalDetail(card), command, 'Details: the exact command');
|
||||
for (const s of steps) assert.ok(approvalDetail(card).includes(s));
|
||||
});
|
||||
|
||||
test('other actions keep their preview', () => {
|
||||
assert.equal(approvalDetail({ scope: 'write', args: { file_path: 'a.txt', content: 'x'.repeat(2000) }, preview: 'a.txt' }), 'a.txt');
|
||||
assert.equal(approvalDetail({ scope: 'shell', args: {}, preview: 'p' }), 'p', 'no command: the preview');
|
||||
assert.equal(approvalDetail({ scope: 'connected', args: { command: 'not a shell' }, preview: 'tool' }), 'tool');
|
||||
});
|
||||
|
||||
test('the card shows it in a box that scrolls and takes the keyboard focus', () => {
|
||||
const card = readFileSync(fileURLToPath(new URL('../src/components/ApprovalCard.tsx', import.meta.url)), 'utf8');
|
||||
assert.match(card, /<summary><Icon name="chevron" size=\{11\}\/>\{tr\("Details"\)\}<\/summary><pre tabIndex=\{0\}>\{approvalDetail\(t\)\}<\/pre>/);
|
||||
const css = readFileSync(fileURLToPath(new URL('../src/styles/app.css', import.meta.url)), 'utf8');
|
||||
assert.match(css, /\.askcard__details pre \{[^}]*white-space: pre-wrap;[^}]*max-height: 40vh; overflow: auto; \}/);
|
||||
});
|
||||
Reference in new issue
Block a user