macOS: fix web chat agent PATH and surface stderr
This commit is contained in:
@@ -225,18 +225,25 @@ final class WebChatWindowController: NSWindowController, WKScriptMessageHandler,
|
|||||||
process.currentDirectoryURL = URL(fileURLWithPath: CommandResolver.projectRootPath())
|
process.currentDirectoryURL = URL(fileURLWithPath: CommandResolver.projectRootPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var env = ProcessInfo.processInfo.environment
|
||||||
|
env["PATH"] = CommandResolver.preferredPaths().joined(separator: ":")
|
||||||
|
process.environment = env
|
||||||
|
|
||||||
let pipe = Pipe()
|
let pipe = Pipe()
|
||||||
|
let errPipe = Pipe()
|
||||||
process.standardOutput = pipe
|
process.standardOutput = pipe
|
||||||
process.standardError = Pipe()
|
process.standardError = errPipe
|
||||||
|
|
||||||
try process.run()
|
try process.run()
|
||||||
process.waitUntilExit()
|
process.waitUntilExit()
|
||||||
let out = pipe.fileHandleForReading.readDataToEndOfFile()
|
let out = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||||
|
let err = errPipe.fileHandleForReading.readDataToEndOfFile()
|
||||||
guard process.terminationStatus == 0 else {
|
guard process.terminationStatus == 0 else {
|
||||||
|
let combined = String(data: out.isEmpty ? err : out, encoding: .utf8)
|
||||||
throw NSError(
|
throw NSError(
|
||||||
domain: "ClawdisAgent",
|
domain: "ClawdisAgent",
|
||||||
code: Int(process.terminationStatus),
|
code: Int(process.terminationStatus),
|
||||||
userInfo: [NSLocalizedDescriptionKey: String(data: out, encoding: .utf8) ?? "unknown error"])
|
userInfo: [NSLocalizedDescriptionKey: combined?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "unknown error"])
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}.value
|
}.value
|
||||||
|
|||||||
Reference in New Issue
Block a user