adds claude-generated commit messages and a recent commits panel to the git view - adds log tailing in the explorer, branch merging and a clean up button

This commit is contained in:
2026-11-04 10:07:52 +01:00
parent 600d4874d2
commit cc6651c08a
49 changed files with 1944 additions and 180 deletions
@@ -20,6 +20,16 @@ public struct ExecutableLocator: Sendable {
return ExecutableLocator(directories: dirs.filter { seen.insert($0).inserted })
}
/// `standard` plus the folders the Claude CLI installs itself into, which a GUI app's PATH never holds.
public static var agent: ExecutableLocator {
let home = FileManager.default.homeDirectoryForCurrentUser.path
var locator = standard
for dir in ["\(home)/.local/bin", "\(home)/.claude/local"] where !locator.directories.contains(dir) {
locator.directories.append(dir)
}
return locator
}
/// The first executable file called `name`, or nil. A name with a slash is checked as given.
public func locate(_ name: String) -> URL? {
let fm = FileManager.default
@@ -25,12 +25,21 @@ public protocol ProcessRunning: Sendable {
/// Runs `executable` (a name looked up on the search path, or a path) and collects its output.
/// A non-zero exit is a normal result, not an error; `environment: nil` inherits ours.
func run(_ executable: String, arguments: [String], in directory: URL?, environment: [String: String]?) async throws -> ProcessResult
/// Like `run`, with `input` written to the child's stdin, which is then closed.
func run(_ executable: String, arguments: [String], in directory: URL?, environment: [String: String]?,
input: String) async throws -> ProcessResult
/// Like `run`, but hands each output line to `onLine` as it arrives (`isError` for stderr).
func stream(_ executable: String, arguments: [String], in directory: URL?, environment: [String: String]?,
onLine: @escaping @Sendable (_ line: String, _ isError: Bool) -> Void) async throws -> ProcessResult
}
extension ProcessRunning {
/// Refuses, so a runner that cannot feed stdin never runs a child that would wait on it.
public func run(_ executable: String, arguments: [String], in directory: URL?, environment: [String: String]?,
input: String) async throws -> ProcessResult {
throw ProcessRunnerError.launchFailed("stdin is not supported by \(type(of: self))")
}
/// Runs to completion, then emits the stdout lines and after them the stderr lines.
public func stream(_ executable: String, arguments: [String], in directory: URL?, environment: [String: String]?,
onLine: @escaping @Sendable (_ line: String, _ isError: Bool) -> Void) async throws -> ProcessResult {
@@ -53,18 +62,23 @@ public struct ProcessRunner: ProcessRunning {
}
public func run(_ executable: String, arguments: [String], in directory: URL?, environment: [String: String]?) async throws -> ProcessResult {
try await launch(executable, arguments: arguments, in: directory, environment: environment, onLine: nil)
try await launch(executable, arguments: arguments, in: directory, environment: environment, input: nil, onLine: nil)
}
public func run(_ executable: String, arguments: [String], in directory: URL?, environment: [String: String]?,
input: String) async throws -> ProcessResult {
try await launch(executable, arguments: arguments, in: directory, environment: environment, input: Data(input.utf8), onLine: nil)
}
public func stream(_ executable: String, arguments: [String], in directory: URL?, environment: [String: String]?,
onLine: @escaping @Sendable (_ line: String, _ isError: Bool) -> Void) async throws -> ProcessResult {
try await launch(executable, arguments: arguments, in: directory, environment: environment, onLine: onLine)
try await launch(executable, arguments: arguments, in: directory, environment: environment, input: nil, onLine: onLine)
}
private func launch(_ executable: String, arguments: [String], in directory: URL?, environment: [String: String]?,
onLine: (@Sendable (String, Bool) -> Void)?) async throws -> ProcessResult {
input: Data?, onLine: (@Sendable (String, Bool) -> Void)?) async throws -> ProcessResult {
guard let url = locator.locate(executable) else { throw ProcessRunnerError.executableNotFound(executable) }
let job = Job(url: url, arguments: arguments, directory: directory, environment: environment, onLine: onLine)
let job = Job(url: url, arguments: arguments, directory: directory, environment: environment, input: input, onLine: onLine)
return try await withTaskCancellationHandler {
try await withCheckedThrowingContinuation { continuation in
job.start(continuation)
@@ -118,12 +132,14 @@ private final class Job: @unchecked Sendable {
private var cancelled = false
private var continuation: CheckedContinuation<ProcessResult, Error>?
private let onLine: (@Sendable (String, Bool) -> Void)?
private let input: Data?
/// Keeps `onLine` to one call at a time, though both pipes feed it.
private let emitLock = NSLock()
init(url: URL, arguments: [String], directory: URL?, environment: [String: String]?,
init(url: URL, arguments: [String], directory: URL?, environment: [String: String]?, input: Data?,
onLine: (@Sendable (String, Bool) -> Void)?) {
self.onLine = onLine
self.input = input
process.executableURL = url
process.arguments = arguments
if let directory { process.currentDirectoryURL = directory }
@@ -136,6 +152,8 @@ private final class Job: @unchecked Sendable {
let err = Pipe()
process.standardOutput = out
process.standardError = err
let stdin = input.map { _ in Pipe() }
if let stdin { process.standardInput = stdin }
let group = DispatchGroup()
var outData = Data()
@@ -159,6 +177,10 @@ private final class Job: @unchecked Sendable {
self.continuation = continuation
lock.unlock()
if let stdin, let input {
DispatchQueue.global().async { Self.write(input, to: stdin.fileHandleForWriting) }
}
group.enter()
DispatchQueue.global().async { [self] in
outData = drain(out.fileHandleForReading, isError: false)
@@ -178,6 +200,14 @@ private final class Job: @unchecked Sendable {
}
}
/// Writes on its own thread, since a child that stops reading would block it. A child that exits
/// early makes the write fail instead of raising SIGPIPE, which would end the app.
private static func write(_ data: Data, to handle: FileHandle) {
_ = fcntl(handle.fileDescriptor, F_SETNOSIGPIPE, 1)
try? handle.write(contentsOf: data)
try? handle.close()
}
/// Resumes the caller once; whichever of finish and cancel comes second is dropped.
private func resume(with result: Result<ProcessResult, Error>) {
lock.lock()