Skip to content

Commit c98e695

Browse files
committed
fix: report Windows node command success
1 parent d0c5550 commit c98e695

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

‎src/OpenClaw.Shared/Capabilities/SystemCapability.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ private async Task<NodeInvokeResponse> HandleRunAsync(NodeInvokeRequest request)
472472
stderr = result.Stderr,
473473
exitCode = result.ExitCode,
474474
timedOut = result.TimedOut,
475+
success = result.ExitCode == 0 && !result.TimedOut,
475476
durationMs = result.DurationMs
476477
});
477478
}

‎src/OpenClaw.Shared/Mcp/McpToolBridge.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private object HandleToolsList()
187187
["system.notify"] =
188188
"Show a Windows toast notification on the node. Args: title (string, default 'OpenClaw'), body (string), subtitle (string), sound (bool, default true). Returns { sent: true }.",
189189
["system.run"] =
190-
"Execute a shell command on the Windows node host. Args: command (string or string[] argv, required), args (string[]), shell (string), cwd (string), timeoutMs (int, default 30000), env (object). Subject to the local exec approval policy. Returns { stdout, stderr, exitCode, timedOut, durationMs }.",
190+
"Execute a shell command on the Windows node host. Args: command (string or string[] argv, required), args (string[]), shell (string), cwd (string), timeoutMs (int, default 30000), env (object). Subject to the local exec approval policy. Returns { stdout, stderr, exitCode, timedOut, success, durationMs }.",
191191
["system.run.prepare"] =
192192
"Pre-flight a system.run invocation: returns the parsed execution plan (argv, cwd, rawCommand, agentId, sessionKey) without running anything. The gateway uses this to build its approval context before the actual run.",
193193
["system.which"] =

‎tests/OpenClaw.Shared.Tests/CapabilityTests.cs‎

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,29 @@ public async Task Run_AcceptsCommandAsArray()
110110
Assert.True(res.Ok);
111111
Assert.Equal("echo", runner.LastRequest!.Command);
112112
Assert.Equal(new[] { "hello", "world" }, runner.LastRequest.Args);
113+
var payload = JsonSerializer.SerializeToElement(res.Payload);
114+
Assert.True(payload.GetProperty("success").GetBoolean());
115+
}
116+
117+
[Fact]
118+
public async Task Run_ReportsUnsuccessfulExit()
119+
{
120+
var cap = new SystemCapability(NullLogger.Instance);
121+
cap.SetCommandRunner(new FakeCommandRunner
122+
{
123+
Result = new CommandResult { ExitCode = 1, TimedOut = false }
124+
});
125+
126+
var res = await cap.ExecuteAsync(new NodeInvokeRequest
127+
{
128+
Id = "r1-failed",
129+
Command = "system.run",
130+
Args = Parse("""{"command":["cmd.exe","/d","/s","/c","exit 1"]}""")
131+
});
132+
133+
Assert.True(res.Ok);
134+
var payload = JsonSerializer.SerializeToElement(res.Payload);
135+
Assert.False(payload.GetProperty("success").GetBoolean());
113136
}
114137

115138
[Fact]
@@ -927,6 +950,14 @@ private class FakeCommandRunner : ICommandRunner
927950
public CommandRequest? LastRequest { get; private set; }
928951
public string? LastResolvedShell { get; private set; }
929952
public string? ForcedEffectiveShell { get; set; }
953+
public CommandResult Result { get; set; } = new()
954+
{
955+
Stdout = "ok",
956+
Stderr = "",
957+
ExitCode = 0,
958+
TimedOut = false,
959+
DurationMs = 1
960+
};
930961

931962
public string ResolveEffectiveShell(string? requestedShell)
932963
{
@@ -949,14 +980,7 @@ public string ResolveEffectiveShell(string? requestedShell)
949980
public Task<CommandResult> RunAsync(CommandRequest request, CancellationToken ct = default)
950981
{
951982
LastRequest = request;
952-
return Task.FromResult(new CommandResult
953-
{
954-
Stdout = "ok",
955-
Stderr = "",
956-
ExitCode = 0,
957-
TimedOut = false,
958-
DurationMs = 1
959-
});
983+
return Task.FromResult(Result);
960984
}
961985
}
962986

0 commit comments

Comments
 (0)