Skip to content

[Repo Assist] refactor: extract TryParseArgv helper in SystemCapability, fix operator precedence #75

Closed

Description

@github-actions

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Two focused code-quality improvements to SystemCapability.cs:

1. Extract TryParseArgv helper

HandleRunPrepare and HandleRunAsync both contained near-identical ~20-line blocks for parsing the "command" field from JSON args (accepts either a string array or a plain string). This logic is now consolidated in a single private TryParseArgv method:

private static bool TryParseArgv(JsonElement args, out string[] argv)

Both callers are simplified and the parsing contract is documented in one place.

2. Fix operator-precedence clarity in HandleExecApprovalsSet

The enabled boolean check was written as:

// Before — && binds tighter than ||, reads ambiguously
TryGetProperty("enabled", out var enEl) && enEl.ValueKind == JsonValueKind.True || enEl.ValueKind == JsonValueKind.False

The runtime behaviour happened to be correct in all cases (a failed TryGetProperty leaves enEl with ValueKind == Undefined, not False), but the expression is misleading to readers. Added parentheses to make the intent explicit:

// After — intent is clear
TryGetProperty("enabled", out var enEl) && (enEl.ValueKind == JsonValueKind.True || enEl.ValueKind == JsonValueKind.False)

Test Status

  • OpenClaw.Shared.Tests: 503 passed, 18 skipped ✅ (Linux runner)
    • Includes all SystemCapabilityTests and ExecApprovalPolicyTests

Generated by Repo Assist · ◷

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@cbb46ab386962aa371045839fc9998ee4e97ca64

Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch repo-assist/improve-system-capability-argv-20260320-ba985f156baa4975.

Click here to create the pull request

To fix the permissions issue, go to Settings → Actions → General and enable Allow GitHub Actions to create and approve pull requests.

Show patch preview (210 of 210 lines)
From 331b49a33fda7ced0576f4e99ca2c8db8ee4d44f Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Fri, 20 Mar 2026 01:00:05 +0000
Subject: [PATCH] refactor: extract TryParseArgv helper in SystemCapability,
 fix operator precedence

Two related improvements to SystemCapability:

1. Extract TryParseArgv helper: HandleRunPrepare and HandleRunAsync both
   contained near-identical JSON argv-array parsing logic (~20 lines each).
   Extract into a private static TryParseArgv method. Both callers are
   simplified and the parsing contract is documented in one place.

2. Fix operator precedence in HandleExecApprovalsSet: the 'enabled' bool
   check was written as:
     TryGetProperty(...) && kind == True || kind == False
   which C# parses as:
     (TryGetProperty(...) && kind == True) || (kind == False)
   rather than the intended:
     TryGetProperty(...) && (kind == True || kind == False)
   Behaviour happened to be correct in all cases (default JsonElement has
   ValueKind == Undefined, not False), but the unparenthesised form is
   misleading. Added parentheses to make intent explicit.

503 tests pass, 18 skipped (integration/Windows-only).

Co-authored-by: Copilot <[email protected]>
---
 .../Capabilities/SystemCapability.cs          | 133 +++++++++---------
 1 file changed, 63 insertions(+), 70 deletions(-)

diff --git a/src/OpenClaw.Shared/Capabilities/SystemCapability.cs b/src/OpenClaw.Shared/Capabilities/SystemCapability.cs
index 986f3fb..4c89ae7 100644
--- a/src/OpenClaw.Shared/Capabilities/SystemCapability.cs
+++ b/src/OpenClaw.Shared/Capabilities/SystemCapability.cs
@@ -161,46 +161,60 @@ public class SystemCapability : NodeCapabilityBase
     }
     
     private static string FormatExecCommand(string[] argv) => ShellQuoting.FormatExecCommand(argv);
-    
+
     /// <summary>
-    /// Pre-flight for system.run: echoes back the execution plan without running anything.
-    /// The gat
... (truncated)

Activity

  1. shanselman commented on Mar 22, 2026

    @shanselman
    Collaborator

    Closing duplicate tracking issue — Repo Assist can now create PRs directly with Actions permissions enabled. Work continues in the associated branches.

  2. locked as resolved and limited conversation to collaborators on May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions