Commit Graph

26 Commits

Author SHA1 Message Date
Scott Hanselman
a1a114a319 refactor: extract WebSocketClientBase from Gateway/Node clients (#63)
Extract ~200 lines of duplicated WebSocket lifecycle code into a shared
abstract base class. Both OpenClawGatewayClient and WindowsNodeClient
now inherit from WebSocketClientBase.

Shared in base class:
- Connection lifecycle: ConnectAsync, ListenForMessagesAsync, ReconnectWithBackoffAsync
- SendRawAsync (thread-safe with TOCTOU protection)
- Dispose (defensive pattern, skip CTS dispose)
- Fields: WebSocket, URL, token, credentials, CTS, backoff array
- StatusChanged event with RaiseStatusChanged helper
- Constructor: URL normalization, credential extraction, validation

Subclass hooks (template method pattern):
- ProcessMessageAsync (abstract) - Gateway wraps sync, Node uses async
- ReceiveBufferSize (abstract) - Gateway 16KB, Node 64KB
- ClientRole (abstract) - for log messages
- OnConnectedAsync, OnDisconnected, OnError, OnDisposing (virtual)

Safety improvements (Node's safer patterns adopted everywhere):
- ObjectDisposedException catch in listen loop
- Post-delay CTS check in reconnect
- Try-catch around reconnect guard
- Constructor argument validation

20 new tests via TestWebSocketClient test double.
596 total tests pass (503 shared + 93 tray).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-17 22:22:11 -07:00
Scott Hanselman
27b1de3600
fix: security hardening from triple-model review (#62)
7 fixes from Opus/Codex/Gemini triple-model review with cross-validation:

Consensus (2+ models agreed):
- ExecApprovalPolicy bypass: full argv evaluated, not just argv[0]
- Thread safety: lock pattern for _sessions/_nodes dictionaries
- SendRawAsync/Dispose races: defensive patterns from WindowsNodeClient

Cross-validated (different model confirmed):
- Canvas jsonlPath restricted to temp directory (arbitrary file read)
- ChannelHealth 'active' status shows [ON] not [OFF]
- OnSettingsSaved mirrors startup if/else (no dual connections)
- TryEnqueue checked in OnCanvasEval/OnCanvasSnapshot (prevents hang)

5 new security tests. All 576 tests pass.
2026-03-17 21:55:52 -07:00
Scott Hanselman
3634f3d112 test: fix false-positive session sorting test and tautological menu assertion
- GetSessionList_SortsMainSessionFirst now populates 3 sessions via
  ParseSessions and verifies the main session is sorted first, instead
  of only asserting an empty list.
- Added ParseSessionsPayload helper to expose the private parser.
- TaskbarAtBottom_TypicalScenario assertion changed from the tautological
  'y + MenuHeight <= 1040 || y >= 0' to the strict 'y + MenuHeight <= 1040'.

571/571 tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-17 19:21:35 -07:00
Scott Hanselman
4549b62af5
[Repo Assist] fix: refresh channel list when channels are added/removed on gateway
Fixes two bugs that together caused issue #55:

1. Remove the healthList.Count > 0 guard so ChannelHealthUpdated fires even when all channels are removed.
2. Dispatch StatusDetailWindow.UpdateStatus when the window is already open.

3 new unit tests added. 478/478 shared tests pass.

Closes #55

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-17 10:49:23 -07:00
Scott Hanselman
bc140e9cca
feat: add WinUI test project with extracted helpers (#45)
Extract testable pure logic from WinUI tray app into shared helpers:
- MenuDisplayHelper: status icons, text truncation, provider formatting
- DeepLinkParser: URI parsing for openclaw:// deep links
- MenuPositioner: tray popup positioning calculations

Create tests/OpenClaw.Tray.Tests with comprehensive coverage for
all extracted helpers plus settings serialization round-trips.

Closes #43
2026-03-16 21:40:55 -07:00
Scott Hanselman
8c1bd38f3f refactor: extract ShellQuoting helper, add comprehensive tests
Extract duplicated metacharacter quoting logic from LocalCommandRunner
and SystemCapability into a shared ShellQuoting static class, following
the established GatewayUrlHelper pattern.

- ShellQuoting.NeedsQuoting: single source of truth for metachar detection
- ShellQuoting.QuoteForShell: shell-aware quoting (cmd vs PowerShell)
- ShellQuoting.FormatExecCommand: display formatting for gateway
- IsShellMetachar: idiomatic switch expression instead of duplicated
  multi-case switch blocks
- 43 new unit tests covering all metacharacters, escaping edge cases,
  null handling, and both shell modes

Co-authored-by: danedane <1402819+danedane@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-16 18:26:06 -07:00
copilot-swe-agent[bot]
39cb73158b Fix system.run hanging indefinitely for CLI tools using local IPC
Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
2026-03-16 18:24:15 -07:00
Copilot
689e35b8fd
Fix channel status icon showing red for 'ready'/'active' channels in Status dialog (#27)
* Initial plan

* Fix StatusIcon colour in Status dialog for 'ready' and 'active' channel statuses

Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>

* Centralize channel healthy-status check into ChannelHealth.IsHealthyStatus

Extract a shared static method ChannelHealth.IsHealthyStatus() in
OpenClaw.Shared to replace duplicated inline status checks across
the codebase. This ensures 'active' and 'ready' are consistently
recognized as healthy in all locations:

- StatusDetailWindow.xaml.cs (was missing active/ready - the original bug)
- App.xaml.cs flyout menu (was missing active/ready)
- App.xaml.cs channel toggle (was missing active/ready)
- TrayApplication.cs channel toggle (was missing active/ready)

Add comprehensive test coverage for the new helper method.

* Add intermediate status tier to Status dialog (yellow for idle/pending/connecting)

Address review feedback from @DanAtkinson: the Status dialog was
treating everything non-healthy as red, but intermediate statuses
like stopped, idle, paused, configured, pending, connecting, and
reconnecting should show yellow — matching the tray popup behavior.

- Add ChannelHealth.IsIntermediateStatus() shared helper
- Update StatusDetailWindow to use 3-tier coloring (green/yellow/red)
- Add test coverage for IsIntermediateStatus

* Fix flyout missing intermediate statuses; add mutual-exclusion tests

The WinUI flyout channel icon switch still had hardcoded
connecting/reconnecting instead of using IsIntermediateStatus(),
causing stopped/idle/paused/etc to show red instead of yellow.

Add mutual-exclusion test ensuring no status is ever classified
as both healthy and intermediate.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
Co-authored-by: Scott Hanselman <scott@hanselman.com>
2026-02-25 16:25:58 -08:00
Scott Hanselman
43c7d9e17e Merge pull request #25 from shanselman/copilot/analyze-test-coverage
Some checks failed
Build and Test / test (push) Has been cancelled
Build and Test / build (win-arm64) (push) Has been cancelled
Build and Test / build (win-x64) (push) Has been cancelled
Build and Test / build-msix (ARM64, win-arm64) (push) Has been cancelled
Build and Test / build-msix (x64, win-x64) (push) Has been cancelled
Build and Test / build-extension (arm64) (push) Has been cancelled
Build and Test / build-extension (x64) (push) Has been cancelled
Build and Test / release (push) Has been cancelled
Add comprehensive OpenClaw.Shared unit tests and retain PR23 credential-hardening expectations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-23 22:45:04 -08:00
Scott Hanselman
63b9268c20 Merge pull request #23 from minikolic/feat/add-support-for-embedded-credentials
Harden gateway credential handling, sanitize display URLs, and expand credential edge-case tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-23 22:43:38 -08:00
copilot-swe-agent[bot]
2e0eca41eb Add 77 new unit tests to improve coverage of GatewayUrlHelper, Models, Capabilities, and ExecApprovalPolicy
Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
2026-02-24 06:16:44 +00:00
Scott Hanselman
ab61f0f3b1 fix(winui): harden preview threading and reconnect capability recovery
Some checks failed
Build and Test / test (push) Has been cancelled
Build and Test / build (win-arm64) (push) Has been cancelled
Build and Test / build (win-x64) (push) Has been cancelled
Build and Test / build-msix (ARM64, win-arm64) (push) Has been cancelled
Build and Test / build-msix (x64, win-x64) (push) Has been cancelled
Build and Test / build-extension (arm64) (push) Has been cancelled
Build and Test / build-extension (x64) (push) Has been cancelled
Build and Test / release (push) Has been cancelled
- synchronize App session preview cache reads/writes/removal with a dedicated lock to avoid cross-thread Dictionary access races between gateway events and tray menu rendering

- reset unsupported-method capability flags on successful gateway reconnect so usage.status, usage.cost, sessions.preview, and node.list can recover after transient or older-gateway errors

- add focused OpenClawGatewayClient regression test covering unsupported-flag reset behavior

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-16 23:29:58 -08:00
Scott Hanselman
3025daaa71 feat(winui): add activity stream and richer node observability
- add shared models and gateway client handling for session, usage, and node.list telemetry

- add ActivityStreamService plus ActivityStreamWindow flyout with filtering, clear, and dashboard jump actions

- wire WinUI tray actions/status surfaces for activity, node/session/usage updates, and one-time discoverability tip

- document exec-policy troubleshooting in README, including Windows policy path and powershell.exe argv[0] matching

- expand shared tests for model parsing and gateway client behavior

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-16 23:02:57 -08:00
Scott Hanselman
c5e5a291e9 Fix issue #18 README allowCommands docs
Some checks failed
Build and Test / test (push) Has been cancelled
Build and Test / build (win-arm64) (push) Has been cancelled
Build and Test / build (win-x64) (push) Has been cancelled
Build and Test / build-msix (ARM64, win-arm64) (push) Has been cancelled
Build and Test / build-msix (x64, win-x64) (push) Has been cancelled
Build and Test / build-extension (arm64) (push) Has been cancelled
Build and Test / build-extension (x64) (push) Has been cancelled
Build and Test / release (push) Has been cancelled
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-16 21:22:08 -08:00
Scott Hanselman
f78d2ed27e Fix issue #19 gateway URL normalization
- Add shared GatewayUrlHelper for ws/wss/http/https validation and normalization\n- Use helper in OpenClawGatewayClient and WindowsNodeClient\n- Reuse helper in WinForms/WinUI settings validation and NodeService A2UI URL derivation\n- Add gateway URL normalization tests for helper, gateway client, and node client

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-16 20:40:17 -08:00
Scott Hanselman
ad1409ca68 Fix update dialog black square, add Debug log level, reduce log noise
- Rewrite UpdateDialog as proper WindowEx (fixes black square and XamlRoot crash)
- Size and center DownloadProgressDialog
- Add Debug level to IOpenClawLogger interface and all implementations
- Downgrade raw JSON, response payloads, channel health, and debug spew from Info to Debug
- Debug messages still visible in dbgview.exe via System.Diagnostics.Debug
- Delete 10 stale remote branches
2026-02-07 18:24:19 -08:00
Scott Hanselman
ca681c7e55 feat: implement system.which capability - resolve executable names via PATH with PATHEXT support on Windows 2026-02-07 17:56:57 -08:00
Scott Hanselman
199f855729
feat: enhanced notification categorization pipeline (#12) (#15)
Replace keyword-only classification with a layered pipeline:
structured metadata (intent/channel) > user rules > keyword fallback.

- Add Channel, Agent, Intent, Tags fields to OpenClawNotification
- Extract NotificationCategorizer class with layered pipeline
- Add NotifyChatResponses toggle to suppress chat toasts
- Add UserNotificationRule model for custom regex/keyword rules
- Map error notifications to urgent setting
- Add 30+ unit tests for categorizer pipeline
- Document categorization system in docs/
2026-02-07 17:24:11 -08:00
Scott Hanselman
45921b07e6 fix: accept system.run command as argv array per OpenClaw spec
Per the official OpenClaw spec (nodes-tool.ts), the 'command' param
for system.run is an argv array (e.g. ["echo","Hello"]), not a string.
Our handler was rejecting array format, causing the first invoke
attempts from the agent to fail with 'Missing command parameter'.

Changes:
- Accept command as array (primary, per spec) or string (fallback)
- Support 'timeoutMs' param name (spec) alongside legacy 'timeout'
- Preserve backward compat for string command + separate args array
- Add 6 new tests for array/string/single-element/error/timeout cases

All 180 tests pass.
2026-02-07 16:49:46 -08:00
Scott Hanselman
4003e58d8f feat: system.run + exec approval policy
Implement system.run command execution with swappable ICommandRunner
interface and glob-pattern-based exec approval policy for security.

ICommandRunner abstraction:
- ICommandRunner interface with CommandRequest/CommandResult models
- LocalCommandRunner: Process.Start with pwsh/cmd/powershell support
- Supports shell selection, cwd, timeout, env vars, args
- Designed for future DockerCommandRunner/WslCommandRunner swap-in

Exec approval policy:
- ExecApprovalPolicy engine with glob-pattern matching (*, ?)
- First-match-wins rule evaluation with Allow/Deny/Ask actions
- JSON persistence to exec-policy.json in data directory
- Default policy: allows read-only commands (echo, Get-*, hostname),
  denies destructive ops (rm, shutdown, Format-*, registry)
- system.execApprovals.get: retrieve current policy rules
- system.execApprovals.set: update policy remotely

Node integration:
- SystemCapability checks approval policy before executing commands
- Denied commands return error with policy rule explanation
- NodeService wires LocalCommandRunner + ExecApprovalPolicy

Tests (191 total, all passing):
- 30 exec approval tests: policy evaluation, persistence, patterns,
  SystemCapability integration, default rules validation
- system.run unit + integration tests
- Fixed: NodeCapabilityBase arg helpers guard default(JsonElement)

Docs updated:
- README: exec approvals commands, usage examples, gateway config
- Architecture doc: capability matrix, roadmap checkboxes updated
2026-02-07 14:16:15 -08:00
Scott Hanselman
6740cae85c test: add node capability and device identity tests
Add 56 new tests covering all 4 capabilities (system, canvas, screen, camera),

NodeCapabilityBase arg parsing, DeviceIdentity keypair/signing (integration),

and fix default JsonElement crash in arg helpers.

Unit tests (135): always run in CI and locally

Integration tests (9): opt-in via OPENCLAW_RUN_INTEGRATION=1

Total: 144 tests, 0 failures
2026-02-06 16:08:38 -08:00
Scott Hanselman
5e347155af test: add opt-in integration test attributes 2026-02-03 21:35:00 -08:00
copilot-swe-agent[bot]
c3c7f4a7aa Rename all Moltbot references to OpenClaw
- Renamed all project directories and files
- Updated all namespaces and class names
- Updated deep link scheme from moltbot:// to openclaw://
- Updated AppData directories to OpenClawTray
- Updated README with OpenClaw references and added history note
- Updated all configuration and build files
- Kept mascot name "Molty" unchanged

Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
2026-01-30 10:16:18 -08:00
Scott Hanselman
a353355fd2 Upgrade to .NET 10 and add GitHub Actions CI
- Upgrade all projects from .NET 9 to .NET 10
- Add .github/workflows/ci.yml with:
  - Test job: runs 88 unit tests
  - Build job: builds Tray for win-x64 and win-arm64
  - Build-extension job: builds Command Palette extension
  - Release job: creates GitHub release on version tags
- All tests passing on .NET 10
2026-01-28 18:51:25 -08:00
copilot-swe-agent[bot]
01e81bce89 Fix .NET version inconsistencies and improve test documentation
Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
2026-01-29 02:04:35 +00:00
copilot-swe-agent[bot]
d8e6938c36 Add comprehensive unit tests for Moltbot.Shared library
Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
2026-01-29 02:00:34 +00:00