Skip to content

feat: AI Agent system with service automation#2

Merged
SonnyTaylor merged 72 commits intomasterfrom
feature/agentic-ai-repair
Mar 18, 2026
Merged

feat: AI Agent system with service automation#2
SonnyTaylor merged 72 commits intomasterfrom
feature/agentic-ai-repair

Conversation

@SonnyTaylor
Copy link
Owner

Summary

Adds the ServiceAgent — an agentic AI assistant built into RustService for computer repair technicians. This is a major feature branch with 35k+ lines of new code.

Agent System

  • Multi-provider AI chat (OpenAI, Anthropic, Google, xAI, Mistral, Groq, DeepSeek, OpenRouter, Ollama)
  • 30+ tools: command execution, file management, web search, service automation
  • Human-in-the-loop approval with 3 modes: Safe (always approve), Whitelist, YOLO
  • Persistent conversations stored in SQLite
  • MCP server for remote LLM control via HTTP with bearer token auth

Service Automation

  • Agent can discover, configure, and run diagnostic service queues
  • Live supervision: receives updates as each service completes
  • Post-run analysis: reviews findings, writes summaries, generates PDF reports
  • Pause/resume/cancel support during runs

New Services

  • Battery Report, Energy Report, Driver Audit, Installed Software
  • Network Config, Startup Optimizer, Restore Point, USB Stability

Bug Fixes (in this branch)

  • Tool call status reverting from "complete" to "running" — React state race condition
  • Agent limited to ~20 tool calls — now supports up to 50 auto-continue turns
  • HITL approval silently failing when auto-execute tools run in same turn

Code Quality

  • Split monolithic AgentPage.tsx (1911 → 1306 lines, -32%) into hooks
  • Split monolithic agent.rs (2672 lines) into 7 focused modules
  • Extracted shared utilities, eliminated duplicated HITL execution code
  • Fixed CI: migrated from pnpm to bun

Other Changes

  • USB Shield logo and updated app metadata
  • 5 new themes (Forge, Cobalt, Circuit, Oxide, Neon Workshop)
  • Performance: blocking IPC commands moved to spawn_blocking
  • UI improvements across service queue, findings display

Test plan

  • CI passes (frontend + rust checks)
  • TypeScript compiles clean (bunx tsc --noEmit)
  • Rust compiles clean (cargo check)
  • Manual: run bun tauri dev, exercise Agent tab with API key
  • Manual: test tool approval flow (approve/reject commands)
  • Manual: test service run supervision via Agent
  • Manual: verify conversation persistence (create, load, switch)

🤖 Generated with Claude Code

SonnyTaylor and others added 30 commits December 17, 2025 11:15
…t, and web search capabilities

- Added comprehensive documentation for the agent system architecture and key files.
- Updated Tauri command parameters to use snake_case for compatibility.
- Introduced command approval modes and memory types for enhanced functionality.
- Implemented tools for memory management and web search integration.
…e chat message handling for streaming responses
…dling

- Added InlineCommandApproval component for user command approvals in chat.
- Integrated command execution and approval logic into the agent's workflow.
- Updated agent-tools to define client-side HITL tools for user interaction.
- Enhanced agent chat service to support multi-step tool execution with user approval.
- Improved error handling and user feedback for tool execution results.
- Refactored AgentPage to manage pending tool calls and display approval requests.
…ontent formatting

- Integrated ReactMarkdown for rendering markdown content in ChatMessage.
- Updated CodeBlock component to handle code snippets with copy functionality.
- Improved tool call handling in AgentPage to support YOLO mode for automatic tool execution.
- Added logic to collect and display results from YOLO mode tool calls.
…rations and behavior management

- Introduced AgentRightSidebar for managing agent tools and settings.
- Added BehaviorSettings component for defining agent behavior and personality.
- Implemented CommandHistory for tracking executed commands with status indicators.
- Enhanced AgentActivityItem to support new activity types including file operations (move, copy, list).
- Integrated marked library for improved markdown rendering in chat messages.
- Updated agent memory management to include behavior type and support for embedding generation.
- Refactored agent tools to include new file operation commands and instrument management.
…rt features

- Introduced a new memory system that distinguishes between global and machine-specific memories for improved context management.
- Added features for auto-saving successful solutions and extracting key facts from conversations.
- Enhanced memory management UI with bulk operations, statistics, and filtering capabilities.
- Updated agent settings to include options for auto-extracting facts, context compression, and memory retention.
- Improved documentation to reflect new memory functionalities and architecture.
- Replaced the tabbed interface in AgentRightSidebar with a streamlined layout focusing solely on the InstrumentList.
- Removed BehaviorSettings, KnowledgeBase, and MemoryBrowser components to declutter the agent's functionality.
- Updated the sidebar's header to better reflect its purpose and enhance user experience.
- Adjusted related styles and imports to align with the new structure.
- Introduced Model Context Protocol (MCP) server to enable external AI systems to control the machine remotely.
- Added configuration options for enabling the server, setting API keys, and defining the server port in agent settings.
- Implemented key files and tools for command execution, file management, and system information retrieval.
- Enhanced documentation to cover MCP server architecture, usage, security considerations, and testing procedures.
- Updated the settings UI to manage MCP server configurations and provide user-friendly access to API keys and port settings.
…anagement

- Added JSON-RPC 2.0 support to the MCP server for remote LLM control, enabling structured communication.
- Introduced new tools for executing commands, reading/writing files, and listing system information.
- Enhanced the server's capabilities with methods for listing available tools and executing custom scripts.
- Updated documentation to reflect new features, including JSON-RPC methods and tool descriptions.
- Improved error handling and response formatting for better client-server interaction.
Rust Backend:
- Remove duplicate Instrument struct from types/agent.rs
- Clean MCP mod.rs exports (remove unused re-exports)
- Suppress dead_code warnings on JsonRpcRequest and RustServiceTools::new()
- Fix unused variable warnings in smartctl.rs and bluescreen.rs
- Register 11 missing memory commands in lib.rs invoke_handler
  (save_memory, search_memories, search_memories_vector, get_all_memories,
   delete_memory, update_memory, bulk_delete_memories, clear_all_memories,
   get_memory_stats, get_recent_memories, increment_memory_access, get_machine_id)

Frontend Theme (all agent components):
- Replace all hardcoded zinc-* colors with theme tokens across:
  MemoizedMarkdown, ChatMessage, FileReference, AgentActivityItem,
  TerminalOutputBlock
- Use foreground/muted-foreground/muted/border/primary/destructive tokens
- Fix prose-invert to dark:prose-invert for proper light mode rendering

Agent Tools:
- Add save_to_memory and recall_memory tools to agent-tools.ts
- Clean AgentToolName type: remove 10 unimplemented ghost entries,
  keep only 12 actually implemented tools

ChatMessage UX:
- Add Bot avatar with secondary-colored circle for assistant messages
- Add 'Agent' label with timestamp matching user message layout
- Proper flex layout with avatar + content column

AgentPage UX:
- Replace minimal empty state with rich welcome screen
- Add sparkle icon, descriptive text, 4 suggested prompt buttons
- Remove unnecessary AgentSettings type cast (now properly typed)

AgentRightSidebar:
- Convert from single Instruments panel to tabbed interface
- Add Instruments, Behaviors, and Memory tabs
- New MemoryStatsPanel shows memory counts by type
- Responsive tab labels (icons-only on smaller widths)

Settings Type Safety:
- Add 'agent' to SettingKey union type with AgentSettings value mapping
- Remove all 'as any' casts from SettingsPage.tsx agent settings updates
…n loading, rename to ServiceAgent

- Remove all memory features: delete agent-memory.ts, MemoryBrowser.tsx, BehaviorSettings.tsx, KnowledgeBase.tsx
- Remove memory types, embedding types, and memory settings from agent.ts (~250 lines removed)
- Remove 12 memory command registrations from lib.rs
- Rewrite agent-tools.ts: no memory tools, add get_system_info tool, improved PowerShell descriptions
- Rewrite system prompt: comprehensive ServiceAgent identity, environment context, PowerShell quick reference, formatting guidelines
- Fix message grouping: runAgentLoop reuses existing assistant message across tool call chains (one message per turn)
- Fix conversation loading: reconstruct activities from tool-call parts, pair with tool results, merge consecutive assistant messages
- Rename 'Agent Zero' to 'ServiceAgent' throughout UI
- Redesign AgentRightSidebar: replace Memory/Behaviors tabs with clean Instruments + AgentInfoPanel layout
- Add remark-gfm for markdown table rendering in MemoizedMarkdown
- Clean agent-activity.ts: replace memory_save/memory_recall with get_system_info
- Clean AgentActivityItem.tsx: replace Brain icon with Cpu for system info
- Add @ai-sdk/mcp for connecting to external MCP servers (SSE/HTTP)
- New MCP manager (mcp-manager.ts) with connection lifecycle management
- MCP server config UI in Settings → AI Agent → MCP Connections
- MCP connection status display in agent sidebar
- Tool names prefixed with mcp_{serverId}_ to avoid collisions
- Rewrite system prompt to enforce sequential tool execution
- Reduce max steps from 15 to 10
- Add prominent stop button in chat input area
- Add MCPServerConfig types (TypeScript + Rust)
- Fix isError nullish coalescing warning
- Fix stale closure in saveConversation that prevented assistant messages from being persisted (used ref instead of stale state snapshot)
- Fix history reconstruction to preserve text-tool interleaving order instead of concatenating all text before all tool calls
- Fix broken Math.floor(index/2) timestamp mapping in saveConversation that produced wrong timestamps due to tool messages in history
- Extract duplicated HITL tool execution logic from autoExecuteHITLTool and handleActivityApprove into shared executeHITLTool function
- Fix getEnabledTools to spread from agentTools so new tools are not silently dropped
- Fix runInstrumentTool shell injection: sanitize args parameter and switch from legacy queue_agent_command to execute_agent_command
- Track actual streaming message ID instead of blindly marking last assistant message as streaming (fixes spurious cursor after HITL)
- Make suggestion buttons send messages directly instead of only populating the input field
- Add copy-to-clipboard button on assistant messages (hover to reveal)
- Add MCP tool activity type for external MCP server tool calls
- Remove dead code: CommandApproval.tsx, InlineCommandApproval.tsx, CommandHistory.tsx, and unused parallel type systems from agent.ts

Co-authored-by: Cursor <cursoragent@cursor.com>
SonnyTaylor and others added 29 commits February 28, 2026 11:27
…, and service UI overhaul

Fix concurrent runAgentLoop crashes by routing service events through a
coalescing queue that serializes loop execution. Add a heartbeat watchdog
that detects stalled streams (30s timeout) with a "Force Restart" UI.

Implement multi-HITL resolution so multiple pending tool approvals are
tracked and the loop only resumes after all are resolved.

Add 8 dedicated service activity types replacing generic fallbacks, redesign
ServiceRunMonitor with a scrollable service list and rich completion summary,
and align all activity component colors to CSS variable theme classes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…n in production

React production builds unmount the entire component tree on uncaught
rendering errors, causing a white screen with no recovery. This adds:

- React ErrorBoundary component with recovery UI at app and per-tab level
- Global window.onerror and unhandledrejection handlers for non-render errors
- Defensive guards in ChatMessage (Array.isArray, safe timestamp parsing)
- Try-catch wrappers in AgentPage service event handlers with null checks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update the Claude theme to use official Anthropic brand colors:
- Orange accent (#d97757) as primary
- Blue secondary (#6a9bcc)
- Green tertiary (#788c5d)
- Dark background (#141413) and light (#faf9f5)
- Mid gray (#b0aea5) for secondary elements
- Light gray (#e8e6dc) for subtle backgrounds

Updated both light and dark modes for consistency and added
color palette to chart variables for cohesive visual design.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Import Poppins (headings) and Lora (body) from Google Fonts and apply
them scoped to .theme-claude so only that theme uses the brand typography.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Replace guessed colors with values sourced directly from claude.ai's
live CSS (bg-bg-100/200/300, text-text-100/200, accent-main-100 tokens):

Light: bg #faf9f5 / cards #f5f4ed / deep #f0eee6, text #141413 / #73726c
Dark:  bg #262624 / cards #1f1e1d / deep #141413, text #faf9f5 / #c2c0b6
Accent: light #c6613f, dark #d97757

The previous dark mode used #141413 as the main background which is
claude.ai's deepest tertiary layer — making it look stark and wrong.
The real dark bg is the warm charcoal #262624.

Simplified font rules to cascade correctly from body/heading selectors.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Lora is Anthropic's document/presentation font, not the UI font.
Claude.ai uses anthropicSans → Segoe UI → system-ui (clean sans-serif).

Drop Lora from Google Fonts import, keep Poppins for headings only.
Body now uses Segoe UI / system-ui stack matching claude.ai's feel.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
The replace_all missed the dark mode block since it lacked the comment.
Font variables now only declared once in .theme-claude and inherit into
.theme-claude.dark correctly.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Remove unused imports FileGenerationRequest and FileUploadRequest
- Replace deprecated base64::decode/encode with Engine::decode/encode
- Prefix unused `size` parameter with underscore
- Move Google Fonts @import before Tailwind to fix PostCSS ordering error

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rator

- Touch/Stylus tab: canvas drawing area with multi-touch support, pointer
  type detection (mouse/touch/pen), pressure display for stylus, per-pointer
  color coding, active/max simultaneous point counters
- Display tab: added SMPTE color bars, crosshatch, dot matrix, horizontal
  and vertical stripes patterns; refactored to shared getPatternStyle()
  helper eliminating duplicated style logic
- Audio tab: tone generator expanded with waveform selector (sine/square/
  sawtooth/triangle), L/R channel pan control, volume slider, frequency
  sweep (100Hz→2000Hz over 3s); audio graph upgraded to include GainNode
  and StereoPannerNode for live parameter updates

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d layout

Add BIOS, system product, RAM slot details, and CPU cache info via PowerShell
WMI queries. Reorganize page into sectioned layout with hero card, better
spacing, and new Memory Modules/BIOS cards. Fix printable component to match
actual type definitions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…health

disk_health.rs had its own find_smartctl() that only checked flat paths,
missing smartctl in subdirectories of data/programs. Now uses
get_program_exe_path() (same as smartctl service and Programs page) which
checks settings overrides and recursively searches the programs folder.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
messagesRef was updated via useEffect (async), but read synchronously
in recursive runAgentLoop calls. YOLO-mode tool executions would set
status to 'success', but the stale ref caused the recursive loop to
overwrite parts back to 'running'. Fixed by synchronously updating
messagesRef inside the setMessages state updater.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Embed a Windows application manifest via tauri_build that sets
requestedExecutionLevel to requireAdministrator, so the app prompts
for UAC elevation on launch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Dev builds use the default manifest so the dev server can run without
UAC elevation from a normal terminal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Merged battery-info (real-time battery crate) and battery-report (powercfg
/batteryreport) into a single comprehensive service. The consolidated
battery-report now includes real-time charge status, state, and time
estimates alongside the detailed capacity history and degradation analysis.

Updated all presets and service knowledge to remove duplicates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove redundant summary stats card (header already shows count + time)
- Tighten queue item padding, icon sizes, and gap spacing
- Reduce footer height and button sizes
- Shrink spacing between queue items from 12px to 6px

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ice page

Add a Skip button to the "Enter service details" dialog so users can
start a service run without filling in technician/customer info.

Also includes extracted service page components (PresetsView, RunnerView,
ResultsView, etc.) and floating service status updates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Enumerates all Windows startup items (registry, startup folders, scheduled
tasks), sends them to the user's configured LLM for intelligent classification
(essential/useful/unnecessary), and optionally disables unnecessary items to
improve boot time. Falls back to heuristic pattern matching when no AI
provider is configured.

- Refactor startup.rs to expose sync helpers as pub(crate)
- Add reqwest blocking feature for sync LLM API calls
- Support all 10 AI providers (OpenAI, Anthropic, Google, xAI, etc.)
- Register in complete preset (report-only) and custom preset
- Add renderer with AI badge, classification filters, and search
- Update service-knowledge.ts to recommend for startup/boot symptoms

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Compact the card headers (px-4 py-2, text-sm) and content areas (pt-3)
across all service renderers and the report view for a tighter layout.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove pnpm-lock.yaml, add bun.lock
- Update all docs (CLAUDE.md, README.md, AGENTS.md) to use bun/bunx commands
- Add CLAUDE.md for Claude Code guidance

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reduce excessive padding (p-6/p-8 → p-4) across all page scroll areas
to maximize usable space. Redesign service queue: clicking anywhere on
a row toggles enable/disable, add smooth framer-motion animations for
item transitions, and show action buttons only on hover.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Wrap get_system_info, get_disk_health, get_restore_points,
create_restore_point, and get_required_programs_status in
tokio::task::spawn_blocking so PowerShell WMI queries, smartctl
calls, and recursive dir scans don't freeze the UI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add 5 new custom themes with light/dark variants. Set Forge as the
default theme. Rename the original shadcn theme to "Shadcn" and move
it to the end of the theme list.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add USB Shield logo (SVG + all icon sizes for Windows/macOS/mobile).
Show logo in titlebar. Fix productName to "RustService" for taskbar.
Update Cargo.toml description and author. Fix build commands to use
bun instead of pnpm.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…e findings UI

- Add ServiceCardWrapper component with category-based gradient headers,
  standardized icon/badge/duration display across all 23 service renderers
- Add dependencies field to ServiceDefinition (Rust + TypeScript) with
  ordering enforcement in both sequential and parallel runners
- SFC now declares dependency on DISM for correct execution order
- Add System Restore Point service that creates restore points before
  maintenance, enabled by default in General and Complete presets
- Reduce findings view outer padding and remove redundant wrapper divs
- Show dependency info and violation warnings in queue item UI

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…bugs

Fix three bugs in the agent system and refactor monolithic code:

**Bug fixes:**
- Tool call status reverting from "complete" to "running" at end of
  messages — caused by React batched state race when runAgentLoop
  recurses; now passes parts directly via LoopOptions
- Agent limited to ~20 tool calls per message — replaced boolean
  allowAutoContinue with turnsRemaining counter (default 50)
- HITL approve/reject silently failing when auto-execute tools run in
  same turn — now searches for last assistant message instead of
  assuming it's the last history entry
- Deduplicated ~150 lines of identical HITL execution switch statements
  into shared executeHITLTool() function

**Frontend refactoring (AgentPage 1911→1306 lines, -32%):**
- Extract validateToolCall, mapToolToActivityType, extractActivityDetails
  to src/lib/agent-activity-utils.ts
- Extract conversation management to src/hooks/useConversations.ts
- Extract service supervision to src/hooks/useServiceSupervision.ts
- Update LoopOptions type in agent-loop-queue.ts

**Backend refactoring (agent.rs 2672 lines → 7 focused modules):**
- agent/mod.rs — shared state, DB helpers, re-exports
- agent/commands.rs — command execution & approval
- agent/memory.rs — memory CRUD + vector search
- agent/files.rs — file ops, instruments, programs, grep, glob
- agent/attachments.rs — file attachment system
- agent/conversations.rs — conversation persistence
- agent/search.rs — web search (Tavily, SearXNG)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix CI workflow: migrate from pnpm to bun, remove clippy -D warnings
  (pre-existing warnings across codebase, not from agent changes)
- Update README: fix logo path (icon.png → logo.svg), add Agent system
  to features, update services list, add agent to data directory
- Update agent-system.md: fix Key Files table to reflect module split,
  remove stale references to CommandApproval/MemoryBrowser/KnowledgeBase/
  BehaviorSettings components that no longer exist, update tool lists
  to match actual implementation
- Update CLAUDE.md: note agent/ directory module structure

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@SonnyTaylor SonnyTaylor merged commit 7e12935 into master Mar 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant