Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Improve Assistant tool activity rows

rcourtmane44b11f4d0df
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index be392a02e5..f44585fdfc 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -366,11 +366,12 @@ runtime cost control, and shared AI transport surfaces.
`packages/opencode/src/cli/cmd/tui/routes/session/index.tsx`, hides generic
output unless `showGenericToolOutput` is enabled, and bounds output-heavy
blocks with `packages/opencode/src/cli/cmd/tui/util/collapse-tool-output.ts`.
- Pulse adapts that by keeping the completed tool action/command visible in the
- transcript, showing a compact plain-text output preview when it is safe and
- useful, and keeping structured JSON, unavailable output, and the full raw
- payload behind Details. This preserves evidence for inspection without
- letting large command output dominate the Assistant answer flow.
+ Pulse adapts that by keeping the completed tool action visible in the
+ transcript, keeping successful raw output behind Details, and surfacing only
+ short failed plain-text output as a preview when it is actionable. Structured
+ JSON, unavailable output, successful command output, and the full raw payload
+ stay behind Details. This preserves evidence for inspection without letting
+ command output compete with the Assistant answer flow.
Tool-row summaries are part of that same source-anchored contract, not
assistant prose cleanup: when provider or backend transport supplies a
function-style call such as `pulse_read(...)` or a friendly string backed by
@@ -564,10 +565,14 @@ runtime cost control, and shared AI transport surfaces.
turns: anchored `session`/prepare events from the normal entry path followed
by mock `workflow_state`, `tool_start`, `tool_progress`, `tool_end`,
response `workflow_state`, content chunks, and terminal `done`. It must also
- persist a real assistant message with model route `pulse:mock-assistant` and
- a successful `pulse_query` tool call so session restore, transcript tooling,
- and stream-contract tests exercise the same backend-to-browser shape as a
- live provider/tool turn. Mock mode is also an effective runtime-config
+ persist a real assistant message with model route `pulse:mock-assistant`,
+ a successful `pulse_query` tool call, and a successful `pulse_read` tool call
+ whose progress event includes provider-style raw input such as
+ `pulse_read(...)`. That fixture keeps session restore, transcript tooling,
+ stream-contract tests, and live browser checks exercising the same
+ backend-to-browser shape as a real provider/tool turn, including the raw
+ function-call syntax Pulse must summarize instead of rendering. Mock mode is
+ also an effective runtime-config
overlay: `internal/api/ai_handler.go` startup, restart, config sync, and
tenant service initialization must treat Assistant as enabled in memory when
mock mode is active, without saving or mutating the persisted `AIConfig`, so
@@ -594,10 +599,12 @@ runtime cost control, and shared AI transport surfaces.
`packages/opencode/src/cli/cmd/tui/feature-plugins/system/session-v2.tsx`.
Pulse's compact tool rows must follow that operator-language model: the row
should summarize the actual governed action (`search "prowlarr"`, `list
- active alerts`, `topology summary`, `$ ls /dev | wc -l on current resource`)
- instead of exposing only internal action names such as `QUERY search`,
- `exec`, or raw JSON; raw input and full output stay available behind
- Details. The referenced OpenCode source at commit
+ active alerts`, `topology summary`, `Inspect devices on current resource`,
+ or exact governed write commands where the command itself is the operator
+ decision) instead of exposing only internal action names such as `QUERY
+ search`, `exec`, provider function calls, or raw JSON; raw input and full
+ output stay available behind Details. The referenced OpenCode source at
+ commit
`9ed17da55ab1f7360cc0e01075f763e27fa899e9` also renders pending tool rows
through `InlineTool` pending text in
`packages/opencode/src/cli/cmd/tui/feature-plugins/system/session-v2.tsx`
@@ -612,10 +619,11 @@ runtime cost control, and shared AI transport surfaces.
generic tool output inside the tool block and uses `collapseToolOutput` in
`packages/opencode/src/cli/cmd/tui/feature-plugins/system/session-v2.tsx`
(`GenericTool`, lines 526-559; `Bash`, lines 701-731) to keep long output bounded.
- Pulse's completed tool rows must adapt that by
- showing a compact plain-text output preview when it is safe and useful,
- while keeping structured JSON, unavailable output, and the full raw payload
- behind Details. The browser implementation owner is
+ Pulse's completed tool rows must adapt that by keeping successful output
+ behind Details and only previewing failed plain-text output when the preview
+ is short enough to be actionable. Structured JSON, unavailable output,
+ successful command output, and the full raw payload stay behind Details. The
+ browser implementation owner is
`frontend-modern/src/components/AI/Chat/ToolExecutionBlock.tsx`; completed
`tool_end` events preserve streamed `raw_input` for the same readable command
summary used while the tool is pending.
diff --git a/frontend-modern/src/components/AI/Chat/ToolExecutionBlock.tsx b/frontend-modern/src/components/AI/Chat/ToolExecutionBlock.tsx
index 144e70ac00..ac973eec11 100644
--- a/frontend-modern/src/components/AI/Chat/ToolExecutionBlock.tsx
+++ b/frontend-modern/src/components/AI/Chat/ToolExecutionBlock.tsx
@@ -18,18 +18,18 @@ interface ToolExecutionBlockProps {
tool: ToolExecution;
}
+interface ToolInputSummaryProps {
+ summary: string;
+}
+
const hasReadableToolOutput = (output: string) => {
const trimmed = output.trim();
return trimmed.length > 0 && !trimmed.toLowerCase().includes('not available');
};
-const ansiControlCodePattern = new RegExp(
- String.raw`\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])`,
- 'g',
-);
+const ansiControlCodePattern = new RegExp(String.raw`\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])`, 'g');
-const stripAnsiControlCodes = (value: string) =>
- value.replace(ansiControlCodePattern, '');
+const stripAnsiControlCodes = (value: string) => value.replace(ansiControlCodePattern, '');
const looksLikeStructuredOutput = (value: string) => {
const trimmed = value.trim();
@@ -58,7 +58,9 @@ const trimPreviewLine = (line: string, maxLength: number) => {
return `${trimmed.slice(0, maxLength).trimEnd()}...`;
};
-const formatOutputPreview = (output: string) => {
+const formatOutputPreview = (output: string, success: boolean) => {
+ if (success) return '';
+
const normalized = stripAnsiControlCodes(output).replace(/\r\n/g, '\n').trim();
if (!hasReadableToolOutput(normalized)) return '';
if (looksLikeStructuredOutput(normalized)) return '';
@@ -78,6 +80,31 @@ const formatOutputPreview = (output: string) => {
return linesTruncated || charsTruncated ? `${fullPreview}\n...` : fullPreview;
};
+const ToolInputSummary: Component<ToolInputSummaryProps> = (props) => {
+ const isShellSummary = createMemo(() => props.summary.trim().startsWith('$ '));
+ const className = createMemo(
+ () =>
+ `mt-1 block whitespace-pre-wrap break-words leading-5 text-base-content ${
+ isShellSummary() ? 'font-mono text-[11px]' : 'text-[12px] font-medium'
+ }`,
+ );
+
+ return (
+ <Show
+ when={isShellSummary()}
+ fallback={
+ <span data-testid="tool-input-summary" class={className()}>
+ {props.summary}
+ </span>
+ }
+ >
+ <code data-testid="tool-input-summary" class={className()}>
+ {props.summary}
+ </code>
+ </Show>
+ );
+};
+
/**
* ToolExecutionBlock - Displays completed tool executions in a compact terminal-like style.
*/
@@ -90,7 +117,7 @@ export const ToolExecutionBlock: Component<ToolExecutionBlockProps> = (props) =>
const inputSummary = createMemo(() =>
parseToolInputSummary(inputText(), props.tool.name, props.tool.rawInput),
);
- const outputPreview = createMemo(() => formatOutputPreview(outputText()));
+ const outputPreview = createMemo(() => formatOutputPreview(outputText(), props.tool.success));
const hasInput = createMemo(() => inputText().trim().length > 0);
const hasOutput = createMemo(() => hasReadableToolOutput(outputText()));
const hasDetails = createMemo(() => hasInput() || hasOutput());
@@ -144,9 +171,7 @@ export const ToolExecutionBlock: Component<ToolExecutionBlockProps> = (props) =>
</button>
</Show>
</div>
- <code class="mt-1 block whitespace-pre-wrap break-words font-mono text-[11px] leading-5 text-base-content">
- {inputSummary()}
- </code>
+ <ToolInputSummary summary={inputSummary()} />
</div>
</div>
@@ -250,9 +275,7 @@ export const PendingToolBlock: Component<PendingToolBlockProps> = (props) => {
<span class="shrink-0 text-[10px] text-muted">{elapsedLabel()}</span>
</Show>
</div>
- <code class="mt-1 block whitespace-pre-wrap break-words font-mono text-[11px] leading-5 text-base-content">
- {inputSummary()}
- </code>
+ <ToolInputSummary summary={inputSummary()} />
</div>
</div>
<Show when={progressText()}>
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/ToolExecutionBlock.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/ToolExecutionBlock.test.tsx
index e2b89efa0c..f98542fedf 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/ToolExecutionBlock.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/ToolExecutionBlock.test.tsx
@@ -180,7 +180,7 @@ describe('ToolExecutionBlock', () => {
expect(screen.getByText('list active alerts')).toBeInTheDocument();
});
- it('renders Pulse read exec input as the actual command', () => {
+ it('renders Pulse read exec input as a readable activity', () => {
render(() => (
<ToolExecutionBlock
tool={makeTool({
@@ -191,7 +191,7 @@ describe('ToolExecutionBlock', () => {
/>
));
- expect(screen.getByText('$ ls /dev | wc -l on current resource')).toBeInTheDocument();
+ expect(screen.getByText('Inspect devices on current resource')).toBeInTheDocument();
expect(screen.queryByText(/"target_host"/)).not.toBeInTheDocument();
});
@@ -206,14 +206,16 @@ describe('ToolExecutionBlock', () => {
/>
));
- const summary = screen.getByText('$ ls /dev | wc -l on current resource').closest('code');
+ const summary = screen
+ .getByText('Inspect devices on current resource')
+ .closest('[data-testid="tool-input-summary"]');
expect(summary).toBeInTheDocument();
expect(summary?.className).toContain('whitespace-pre-wrap');
expect(summary?.className).toContain('break-words');
expect(summary?.className).not.toContain('truncate');
});
- it('renders provider-style Pulse read function input as the actual command', () => {
+ it('renders provider-style Pulse read function input as a readable activity', () => {
render(() => (
<ToolExecutionBlock
tool={makeTool({
@@ -224,7 +226,7 @@ describe('ToolExecutionBlock', () => {
/>
));
- expect(screen.getByText('$ ls /dev | wc -l on current resource')).toBeInTheDocument();
+ expect(screen.getByText('Inspect devices on current resource')).toBeInTheDocument();
expect(screen.queryByText(/pulse_read\(/)).not.toBeInTheDocument();
});
@@ -274,10 +276,12 @@ describe('ToolExecutionBlock', () => {
// --- Output display ---
- it('previews plain-text output while keeping full details available', () => {
+ it('keeps successful plain-text output in details instead of previewing it', () => {
render(() => <ToolExecutionBlock tool={makeTool({ output: 'hello world' })} />);
- expect(screen.getByLabelText('Tool output preview')).toHaveTextContent('hello world');
+ expect(screen.queryByLabelText('Tool output preview')).not.toBeInTheDocument();
expect(screen.getByText('Details')).toBeInTheDocument();
+ fireEvent.click(screen.getByText('Details'));
+ expect(screen.getByText('hello world')).toBeInTheDocument();
});
it('does not preview structured JSON output by default', () => {
@@ -295,7 +299,7 @@ describe('ToolExecutionBlock', () => {
expect(screen.getByText('Details')).toBeInTheDocument();
});
- it('bounds long plain-text output previews without losing full details', () => {
+ it('keeps successful long plain-text output behind details', () => {
const { container } = render(() => (
<ToolExecutionBlock
tool={makeTool({
@@ -305,13 +309,21 @@ describe('ToolExecutionBlock', () => {
));
const text = container.textContent || '';
- expect(screen.getByLabelText('Tool output preview').textContent).toBe(
- ['line 1', 'line 2', 'line 3', 'line 4', '...'].join('\n'),
- );
+ expect(screen.queryByLabelText('Tool output preview')).not.toBeInTheDocument();
+ expect(text).not.toContain('line 1');
expect(text).not.toContain('line 5');
expect(screen.getByText('Details')).toBeInTheDocument();
});
+ it('previews failed plain-text output while keeping full details available', () => {
+ render(() => (
+ <ToolExecutionBlock tool={makeTool({ success: false, output: 'permission denied' })} />
+ ));
+
+ expect(screen.getByLabelText('Tool output preview')).toHaveTextContent('permission denied');
+ expect(screen.getByText('Details')).toBeInTheDocument();
+ });
+
it('uses raw streamed input to summarize sparse completed Pulse read tools', () => {
render(() => (
<ToolExecutionBlock
@@ -325,8 +337,8 @@ describe('ToolExecutionBlock', () => {
/>
));
- expect(screen.getByText('$ ls /dev | wc -l on current resource')).toBeInTheDocument();
- expect(screen.getByLabelText('Tool output preview')).toHaveTextContent('42');
+ expect(screen.getByText('Inspect devices on current resource')).toBeInTheDocument();
+ expect(screen.queryByLabelText('Tool output preview')).not.toBeInTheDocument();
});
it('hides output that is only whitespace', () => {
@@ -532,7 +544,7 @@ describe('PendingToolBlock', () => {
expect(screen.queryByText(/"type"/)).not.toBeInTheDocument();
});
- it('renders pending Pulse read exec input as the command being prepared', () => {
+ it('renders pending Pulse read exec input as readable activity', () => {
render(() => (
<PendingToolBlock
tool={makePending({
@@ -543,7 +555,7 @@ describe('PendingToolBlock', () => {
/>
));
- expect(screen.getByText('$ lsblk -o NAME,SIZE on current resource')).toBeInTheDocument();
+ expect(screen.getByText('Inspect devices on current resource')).toBeInTheDocument();
expect(screen.queryByText(/"command"/)).not.toBeInTheDocument();
});
@@ -558,14 +570,16 @@ describe('PendingToolBlock', () => {
/>
));
- const summary = screen.getByText('$ lsblk -o NAME,SIZE on current resource').closest('code');
+ const summary = screen
+ .getByText('Inspect devices on current resource')
+ .closest('[data-testid="tool-input-summary"]');
expect(summary).toBeInTheDocument();
expect(summary?.className).toContain('whitespace-pre-wrap');
expect(summary?.className).toContain('break-words');
expect(summary?.className).not.toContain('truncate');
});
- it('renders pending provider-style Pulse read function input as the command being prepared', () => {
+ it('renders pending provider-style Pulse read function input as readable activity', () => {
render(() => (
<PendingToolBlock
tool={makePending({
@@ -575,7 +589,7 @@ describe('PendingToolBlock', () => {
/>
));
- expect(screen.getByText('$ lsblk -o NAME,SIZE on current resource')).toBeInTheDocument();
+ expect(screen.getByText('Inspect devices on current resource')).toBeInTheDocument();
expect(screen.queryByText(/pulse_read\(/)).not.toBeInTheDocument();
});
@@ -591,11 +605,11 @@ describe('PendingToolBlock', () => {
/>
));
- expect(screen.getByText('$ ls /dev | wc -l on current resource')).toBeInTheDocument();
+ expect(screen.getByText('Inspect devices on current resource')).toBeInTheDocument();
expect(screen.queryByText(/"target_host"/)).not.toBeInTheDocument();
});
- it('shows the currently streamed command fragment before the tool input is valid JSON', () => {
+ it('turns streamed command fragments into readable activity before valid JSON arrives', () => {
render(() => (
<PendingToolBlock
tool={makePending({
@@ -606,7 +620,7 @@ describe('PendingToolBlock', () => {
/>
));
- expect(screen.getByText('$ ls /dev |')).toBeInTheDocument();
+ expect(screen.getByText('Inspect devices')).toBeInTheDocument();
});
it('uses structured raw input over pending backend command display strings', () => {
@@ -625,7 +639,9 @@ describe('PendingToolBlock', () => {
});
it('renders a command-specific pending label before governed command arguments arrive', () => {
- render(() => <PendingToolBlock tool={makePending({ name: 'pulse_run_command', input: '{}' })} />);
+ render(() => (
+ <PendingToolBlock tool={makePending({ name: 'pulse_run_command', input: '{}' })} />
+ ));
expect(screen.getByText('Writing command...')).toBeInTheDocument();
expect(screen.getByText('writing')).toBeInTheDocument();
diff --git a/frontend-modern/src/components/AI/Chat/toolPresentation.ts b/frontend-modern/src/components/AI/Chat/toolPresentation.ts
index 3417b1cc93..79a63db688 100644
--- a/frontend-modern/src/components/AI/Chat/toolPresentation.ts
+++ b/frontend-modern/src/components/AI/Chat/toolPresentation.ts
@@ -108,6 +108,65 @@ const targetSuffix = (record: Record<string, unknown>) => {
return ` on ${formatIdentifierLabel(target, { maxLength: 18 })}`;
};
+const normalizedShellCommand = (command: string) => command.replace(/\s+/g, ' ').trim();
+
+const shellCommandIntentLabel = (command: string) => {
+ const normalized = normalizedShellCommand(command).toLowerCase();
+ if (!normalized) return '';
+
+ if (/lsblk|udevadm|lspci|lsusb|\/dev|nvme\s+list|blkid/.test(normalized)) {
+ return 'Inspect devices';
+ }
+ if (/smartctl|nvme\s+smart-log|storcli|megacli/.test(normalized)) {
+ return 'Check disk health';
+ }
+ if (/\bdf\b|findmnt|mount\s|ls\s+\/mnt|ls\s+\/media/.test(normalized)) {
+ return 'Inspect filesystems';
+ }
+ if (/\bzpool\b|\bzfs\b/.test(normalized)) {
+ return 'Inspect ZFS storage';
+ }
+ if (
+ /journalctl|docker\s+logs|kubectl\s+logs|tail\s+-f\s+\/var\/log|\/var\/log/.test(normalized)
+ ) {
+ return 'Read logs';
+ }
+ if (/systemctl\s+(status|is-active|show)|service\s+\S+\s+status/.test(normalized)) {
+ return 'Check service status';
+ }
+ if (/docker\s+(ps|inspect|stats)|podman\s+(ps|inspect|stats)/.test(normalized)) {
+ return 'Inspect containers';
+ }
+ if (/kubectl\s+(get|describe|top)|helm\s+(list|status)/.test(normalized)) {
+ return 'Inspect Kubernetes resources';
+ }
+ if (/\b(qm|pct)\s+(list|status|config|pending)|pvesh\s+get|pvesm\s+status/.test(normalized)) {
+ return 'Inspect Proxmox resources';
+ }
+ if (/\b(ip|ss|netstat|ping|traceroute|curl|wget|dig|nslookup)\b/.test(normalized)) {
+ return 'Check network state';
+ }
+ return '';
+};
+
+const isComplexShellCommand = (command: string) =>
+ command.length > 48 || /[;&|`<>]/.test(command) || /\$\(|\${/.test(command);
+
+const formatCommandActivitySummary = (record: Record<string, unknown>, mode: 'read' | 'write') => {
+ const command = normalizedShellCommand(stringField(record, ['command', 'cmd']));
+ if (!command) return '';
+
+ const target = targetSuffix(record);
+ const intent = shellCommandIntentLabel(command);
+ if (mode === 'read' && intent) {
+ return `${intent}${target}`;
+ }
+ if (mode === 'read' && isComplexShellCommand(command)) {
+ return `Read with shell command${target}`;
+ }
+ return `$ ${inlineValue(command, 64)}${target}`;
+};
+
const parseFunctionStyleToolInput = (input: string) => {
const match = /^([a-zA-Z_][a-zA-Z0-9_]*)\s*\(([\s\S]*)\)\s*$/.exec(input.trim());
if (!match) return null;
@@ -222,7 +281,8 @@ const formatPartialRawInputSummary = (rawInput: string | undefined, toolName?: s
const tool = normalizedToolName(toolName);
if ((tool === 'read' || tool === 'run_command' || tool === 'control') && command) {
- return `$ ${inlineValue(command, 64)}${targetSuffix(record)}`;
+ const mode = tool === 'run_command' || tool === 'control' ? 'write' : 'read';
+ return formatCommandActivitySummary(record, mode);
}
if (tool === 'read') {
if (action === 'file' && path) return `read ${inlineValue(path, 36)}${targetSuffix(record)}`;
@@ -240,12 +300,6 @@ const formatPartialRawInputSummary = (rawInput: string | undefined, toolName?: s
return 'receiving input';
};
-const formatCommandSummary = (record: Record<string, unknown>) => {
- const command = stringField(record, ['command', 'cmd']);
- if (!command) return '';
- return `$ ${inlineValue(command, 64)}${targetSuffix(record)}`;
-};
-
const formatPulseReadInputSummary = (record: Record<string, unknown>) => {
const action = stringField(record, ['action', 'type']).toLowerCase();
const path = inlineValue(stringField(record, ['path', 'file', 'file_path', 'filePath']), 36);
@@ -257,7 +311,9 @@ const formatPulseReadInputSummary = (record: Record<string, unknown>) => {
const source = stringField(record, ['source']).toLowerCase();
if (action === 'exec') {
- return formatCommandSummary(record) || `run read-only command${targetSuffix(record)}`;
+ return (
+ formatCommandActivitySummary(record, 'read') || `run read-only command${targetSuffix(record)}`
+ );
}
if (action === 'file') {
return path ? `read ${path}${targetSuffix(record)}` : `read file${targetSuffix(record)}`;
@@ -278,7 +334,8 @@ const formatPulseReadInputSummary = (record: Record<string, unknown>) => {
: `read logs${targetSuffix(record)}`;
}
return (
- formatCommandSummary(record) || (action ? formatIdentifierLabel(action, { maxLength: 28 }) : '')
+ formatCommandActivitySummary(record, 'read') ||
+ (action ? formatIdentifierLabel(action, { maxLength: 28 }) : '')
);
};
@@ -344,7 +401,7 @@ const formatStructuredInputSummary = (
return formatPulseReadInputSummary(record) || 'read resource';
}
if (tool === 'run_command' || tool === 'control') {
- return formatCommandSummary(record) || 'run command';
+ return formatCommandActivitySummary(record, 'write') || 'run command';
}
if (tool === 'query') {
return formatQueryInputSummary(record);
diff --git a/internal/ai/chat/mock_stream.go b/internal/ai/chat/mock_stream.go
index a64d5f06e2..96ebab912c 100644
--- a/internal/ai/chat/mock_stream.go
+++ b/internal/ai/chat/mock_stream.go
@@ -13,9 +13,13 @@ import (
)
const (
- mockAssistantModelRoute = "pulse:mock-assistant"
- mockAssistantToolID = "mock-pulse-query"
- mockAssistantToolName = "pulse_query"
+ mockAssistantModelRoute = "pulse:mock-assistant"
+ mockAssistantQueryToolID = "mock-pulse-query"
+ mockAssistantQueryToolName = "pulse_query"
+ mockAssistantReadToolID = "mock-pulse-read"
+ mockAssistantReadToolName = "pulse_read"
+ mockAssistantToolID = mockAssistantQueryToolID
+ mockAssistantToolName = mockAssistantQueryToolName
)
var mockAssistantStreamPace = 220 * time.Millisecond
@@ -42,12 +46,12 @@ func streamMockAssistantTurnIfEnabled(ctx context.Context, sessions *SessionStor
streamCallback = func(StreamEvent) {}
}
- toolInput := map[string]interface{}{
+ queryInput := map[string]interface{}{
"action": "topology",
"summary_only": true,
"source": "mock_assistant_fixture",
}
- toolOutputBytes, _ := json.Marshal(map[string]interface{}{
+ queryOutputBytes, _ := json.Marshal(map[string]interface{}{
"source": "mock_assistant_fixture",
"summary": map[string]interface{}{
"nodes": 3,
@@ -55,29 +59,52 @@ func streamMockAssistantTurnIfEnabled(ctx context.Context, sessions *SessionStor
"active_findings": 2,
},
})
- toolOutput := string(toolOutputBytes)
+ queryOutput := string(queryOutputBytes)
+ readInput := map[string]interface{}{
+ "action": "exec",
+ "target_host": "current_resource",
+ "command": "ls /dev | wc -l && echo '---' && lsblk -d -o NAME,TYPE,SIZE",
+ }
+ readRawInput := `pulse_read(target_host="current_resource",command="ls/dev|wc-l&&echo'---'&&lsblk-d-oNAME,TYPE,SIZE2>/dev/null||echo'lsblknotavailable'")`
+ readOutput := "devices=42\nblock_devices=8"
emitWorkflowState(streamCallback, "mock_context", "Preparing mock Assistant fixture.", "mock", "")
if !pauseMockAssistantStream(ctx) {
return true
}
- emitToolStartEvent(streamCallback, mockAssistantToolID, mockAssistantToolName, toolInput)
+ emitToolStartEvent(streamCallback, mockAssistantQueryToolID, mockAssistantQueryToolName, queryInput)
+ if !pauseMockAssistantStream(ctx) {
+ return true
+ }
+ emitToolProgressEvent(streamCallback, mockAssistantQueryToolID, mockAssistantQueryToolName, queryInput, "running", "Reading synthetic Pulse inventory.")
+ if !pauseMockAssistantStream(ctx) {
+ return true
+ }
+ emitToolProgressEvent(streamCallback, mockAssistantQueryToolID, mockAssistantQueryToolName, queryInput, "running", "Summarizing mock inventory result.")
if !pauseMockAssistantStream(ctx) {
return true
}
- emitToolProgressEvent(streamCallback, mockAssistantToolID, mockAssistantToolName, toolInput, "running", "Reading synthetic Pulse inventory.")
+ emitToolEndEvent(streamCallback, mockAssistantQueryToolID, mockAssistantQueryToolName, queryInput, queryOutput, true)
if !pauseMockAssistantStream(ctx) {
return true
}
- emitToolProgressEvent(streamCallback, mockAssistantToolID, mockAssistantToolName, toolInput, "running", "Summarizing mock inventory result.")
+ emitToolStartEvent(streamCallback, mockAssistantReadToolID, mockAssistantReadToolName, readInput)
if !pauseMockAssistantStream(ctx) {
return true
}
- emitToolEndEvent(streamCallback, mockAssistantToolID, mockAssistantToolName, toolInput, toolOutput, true)
+ emitToolProgressEventWithRawInput(streamCallback, mockAssistantReadToolID, mockAssistantReadToolName, readInput, readRawInput, "running", "Reading mock device inventory.")
if !pauseMockAssistantStream(ctx) {
return true
}
- emitWorkflowState(streamCallback, "mock_response", "Composing mock Assistant response.", "mock", mockAssistantToolName)
+ emitToolProgressEvent(streamCallback, mockAssistantReadToolID, mockAssistantReadToolName, readInput, "running", "Summarizing mock device count.")
+ if !pauseMockAssistantStream(ctx) {
+ return true
+ }
+ emitToolEndEvent(streamCallback, mockAssistantReadToolID, mockAssistantReadToolName, readInput, readOutput, true)
+ if !pauseMockAssistantStream(ctx) {
+ return true
+ }
+ emitWorkflowState(streamCallback, "mock_response", "Composing mock Assistant response.", "mock", mockAssistantReadToolName)
chunks := mockAssistantResponseChunks(prompt)
answer := strings.Join(chunks, "")
@@ -90,10 +117,16 @@ func streamMockAssistantTurnIfEnabled(ctx context.Context, sessions *SessionStor
Model: mockAssistantModelRoute,
Timestamp: time.Now(),
ToolCalls: []ToolCall{{
- ID: mockAssistantToolID,
- Name: mockAssistantToolName,
- Input: toolInput,
- Output: toolOutput,
+ ID: mockAssistantQueryToolID,
+ Name: mockAssistantQueryToolName,
+ Input: queryInput,
+ Output: queryOutput,
+ Success: &success,
+ }, {
+ ID: mockAssistantReadToolID,
+ Name: mockAssistantReadToolName,
+ Input: readInput,
+ Output: readOutput,
Success: &success,
}},
}); err != nil {
@@ -121,7 +154,8 @@ func mockAssistantResponseChunks(prompt string) []string {
}
return []string{
firstChunk,
- "I read a synthetic Pulse inventory snapshot with pulse_query and found 3 nodes, 8 workloads, and 2 active findings. ",
+ "I read a synthetic Pulse inventory snapshot with pulse_query, then inspected mock device inventory with pulse_read. ",
+ "The fixture found 3 nodes, 8 workloads, 42 device entries, and 2 active findings. ",
"This deterministic stream exercises status, tool, content, and done updates without waiting on a live model provider.",
}
}
diff --git a/internal/ai/chat/service_execute_additional_test.go b/internal/ai/chat/service_execute_additional_test.go
index 17c18cb550..776a4bea8c 100644
--- a/internal/ai/chat/service_execute_additional_test.go
+++ b/internal/ai/chat/service_execute_additional_test.go
@@ -469,10 +469,15 @@ func TestServiceExecuteStreamMockModeStreamsToolFixtureWithoutProviderCall(t *te
"tool_progress",
"tool_progress",
"tool_end",
+ "tool_start",
+ "tool_progress",
+ "tool_progress",
+ "tool_end",
"workflow_state",
"content",
"content",
"content",
+ "content",
"done",
}
if !reflect.DeepEqual(eventTypes, wantTypes) {
@@ -483,7 +488,7 @@ func TestServiceExecuteStreamMockModeStreamsToolFixtureWithoutProviderCall(t *te
if err := json.Unmarshal(events[3].Data, &toolStart); err != nil {
t.Fatalf("unmarshal tool_start: %v", err)
}
- if toolStart.ID != mockAssistantToolID || toolStart.Name != mockAssistantToolName {
+ if toolStart.ID != mockAssistantQueryToolID || toolStart.Name != mockAssistantQueryToolName {
t.Fatalf("tool_start = %#v, want mock pulse_query", toolStart)
}
@@ -491,7 +496,7 @@ func TestServiceExecuteStreamMockModeStreamsToolFixtureWithoutProviderCall(t *te
if err := json.Unmarshal(events[4].Data, &toolProgress); err != nil {
t.Fatalf("unmarshal tool_progress: %v", err)
}
- if toolProgress.ID != mockAssistantToolID || toolProgress.Phase != "running" {
+ if toolProgress.ID != mockAssistantQueryToolID || toolProgress.Phase != "running" {
t.Fatalf("tool_progress = %#v, want running mock tool", toolProgress)
}
@@ -499,10 +504,34 @@ func TestServiceExecuteStreamMockModeStreamsToolFixtureWithoutProviderCall(t *te
if err := json.Unmarshal(events[6].Data, &toolEnd); err != nil {
t.Fatalf("unmarshal tool_end: %v", err)
}
- if toolEnd.ID != mockAssistantToolID || toolEnd.Name != mockAssistantToolName || !toolEnd.Success {
+ if toolEnd.ID != mockAssistantQueryToolID || toolEnd.Name != mockAssistantQueryToolName || !toolEnd.Success {
t.Fatalf("tool_end = %#v, want successful mock pulse_query", toolEnd)
}
+ var readToolStart ToolStartData
+ if err := json.Unmarshal(events[7].Data, &readToolStart); err != nil {
+ t.Fatalf("unmarshal read tool_start: %v", err)
+ }
+ if readToolStart.ID != mockAssistantReadToolID || readToolStart.Name != mockAssistantReadToolName {
+ t.Fatalf("read tool_start = %#v, want mock pulse_read", readToolStart)
+ }
+
+ var readToolProgress ToolProgressData
+ if err := json.Unmarshal(events[8].Data, &readToolProgress); err != nil {
+ t.Fatalf("unmarshal read tool_progress: %v", err)
+ }
+ if readToolProgress.ID != mockAssistantReadToolID || !strings.Contains(readToolProgress.RawInput, "pulse_read(") {
+ t.Fatalf("read tool_progress = %#v, want raw provider-style pulse_read input", readToolProgress)
+ }
+
+ var readToolEnd ToolEndData
+ if err := json.Unmarshal(events[10].Data, &readToolEnd); err != nil {
+ t.Fatalf("unmarshal read tool_end: %v", err)
+ }
+ if readToolEnd.ID != mockAssistantReadToolID || readToolEnd.Name != mockAssistantReadToolName || !readToolEnd.Success {
+ t.Fatalf("read tool_end = %#v, want successful mock pulse_read", readToolEnd)
+ }
+
var done DoneData
if err := json.Unmarshal(events[len(events)-1].Data, &done); err != nil {
t.Fatalf("unmarshal done: %v", err)
@@ -522,15 +551,21 @@ func TestServiceExecuteStreamMockModeStreamsToolFixtureWithoutProviderCall(t *te
if assistantMessage.Role != "assistant" || assistantMessage.Model != mockAssistantModelRoute {
t.Fatalf("assistant message = %#v, want persisted mock assistant", assistantMessage)
}
- if len(assistantMessage.ToolCalls) != 1 {
- t.Fatalf("assistant tool calls = %d, want 1", len(assistantMessage.ToolCalls))
+ if len(assistantMessage.ToolCalls) != 2 {
+ t.Fatalf("assistant tool calls = %d, want 2", len(assistantMessage.ToolCalls))
}
- if assistantMessage.ToolCalls[0].Name != mockAssistantToolName {
+ if assistantMessage.ToolCalls[0].Name != mockAssistantQueryToolName {
t.Fatalf("assistant tool call = %#v, want mock pulse_query", assistantMessage.ToolCalls[0])
}
if assistantMessage.ToolCalls[0].Success == nil || !*assistantMessage.ToolCalls[0].Success {
t.Fatalf("assistant tool call success = %#v, want true", assistantMessage.ToolCalls[0].Success)
}
+ if assistantMessage.ToolCalls[1].Name != mockAssistantReadToolName {
+ t.Fatalf("assistant tool call = %#v, want mock pulse_read", assistantMessage.ToolCalls[1])
+ }
+ if assistantMessage.ToolCalls[1].Success == nil || !*assistantMessage.ToolCalls[1].Success {
+ t.Fatalf("assistant tool call success = %#v, want true", assistantMessage.ToolCalls[1].Success)
+ }
}
func TestService_ExecuteStream_EmitsProviderStartupBeforeProviderCall(t *testing.T) {
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 8484908cc2..c2270e28ff 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -10854,6 +10854,9 @@ func TestContract_AssistantMockModeRuntimeUsesEffectiveConfig(t *testing.T) {
"pauseMockAssistantStream(ctx)",
"Reading synthetic Pulse inventory.",
"Summarizing mock inventory result.",
+ "Reading mock device inventory.",
+ "Summarizing mock device count.",
+ "mockAssistantReadToolName",
"Composing mock Assistant response.",
} {
if !strings.Contains(mockStreamText, required) {