feat(cli): add agent send command and wire through XPC
This commit is contained in:
@@ -67,6 +67,22 @@ final class ClawdisXPCService: NSObject, ClawdisXPCProtocol {
|
|||||||
guard authorized else { return Response(ok: false, message: "screen recording permission missing") }
|
guard authorized else { return Response(ok: false, message: "screen recording permission missing") }
|
||||||
}
|
}
|
||||||
return await ShellRunner.run(command: command, cwd: cwd, env: env, timeout: timeoutSec)
|
return await ShellRunner.run(command: command, cwd: cwd, env: env, timeout: timeoutSec)
|
||||||
|
|
||||||
|
case let .agent(message, thinking, session):
|
||||||
|
let trimmed = message.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
guard !trimmed.isEmpty else { return Response(ok: false, message: "message empty") }
|
||||||
|
|
||||||
|
let sent = await MainActor.run {
|
||||||
|
WebChatManager.shared.sendMessage(
|
||||||
|
trimmed,
|
||||||
|
thinking: thinking ?? "default",
|
||||||
|
sessionKey: session ?? "main")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sent {
|
||||||
|
return Response(ok: true, message: "sent")
|
||||||
|
}
|
||||||
|
return Response(ok: false, message: "failed to enqueue message")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,6 +133,28 @@ struct ClawdisCLI {
|
|||||||
case "status":
|
case "status":
|
||||||
return .status
|
return .status
|
||||||
|
|
||||||
|
case "agent":
|
||||||
|
var message: String?
|
||||||
|
var thinking: String?
|
||||||
|
var session: String?
|
||||||
|
|
||||||
|
while !args.isEmpty {
|
||||||
|
let arg = args.removeFirst()
|
||||||
|
switch arg {
|
||||||
|
case "--message": message = args.popFirst()
|
||||||
|
case "--thinking": thinking = args.popFirst()
|
||||||
|
case "--session": session = args.popFirst()
|
||||||
|
default:
|
||||||
|
// Support bare message as last argument
|
||||||
|
if message == nil {
|
||||||
|
message = arg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let message else { throw CLIError.help }
|
||||||
|
return .agent(message: message, thinking: thinking, session: session)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw CLIError.help
|
throw CLIError.help
|
||||||
}
|
}
|
||||||
@@ -152,6 +174,7 @@ struct ClawdisCLI {
|
|||||||
clawdis-mac screenshot [--display-id <u32>] [--window-id <u32>]
|
clawdis-mac screenshot [--display-id <u32>] [--window-id <u32>]
|
||||||
clawdis-mac run [--cwd <path>] [--env KEY=VAL] [--timeout <sec>] [--needs-screen-recording] <command ...>
|
clawdis-mac run [--cwd <path>] [--env KEY=VAL] [--timeout <sec>] [--needs-screen-recording] <command ...>
|
||||||
clawdis-mac status
|
clawdis-mac status
|
||||||
|
clawdis-mac agent --message <text> [--thinking <low|default|high>] [--session <key>]
|
||||||
clawdis-mac --help
|
clawdis-mac --help
|
||||||
|
|
||||||
Returns JSON to stdout:
|
Returns JSON to stdout:
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public enum Request: Sendable {
|
|||||||
timeoutSec: Double?,
|
timeoutSec: Double?,
|
||||||
needsScreenRecording: Bool)
|
needsScreenRecording: Bool)
|
||||||
case status
|
case status
|
||||||
|
case agent(message: String, thinking: String?, session: String?)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Responses
|
// MARK: - Responses
|
||||||
@@ -51,6 +52,7 @@ extension Request: Codable {
|
|||||||
case caps, interactive
|
case caps, interactive
|
||||||
case displayID, windowID, format
|
case displayID, windowID, format
|
||||||
case command, cwd, env, timeoutSec, needsScreenRecording
|
case command, cwd, env, timeoutSec, needsScreenRecording
|
||||||
|
case message, thinking, session
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum Kind: String, Codable {
|
private enum Kind: String, Codable {
|
||||||
@@ -59,6 +61,7 @@ extension Request: Codable {
|
|||||||
case screenshot
|
case screenshot
|
||||||
case runShell
|
case runShell
|
||||||
case status
|
case status
|
||||||
|
case agent
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public func encode(to encoder: Encoder) throws {
|
||||||
@@ -91,6 +94,12 @@ extension Request: Codable {
|
|||||||
|
|
||||||
case .status:
|
case .status:
|
||||||
try container.encode(Kind.status, forKey: .type)
|
try container.encode(Kind.status, forKey: .type)
|
||||||
|
|
||||||
|
case let .agent(message, thinking, session):
|
||||||
|
try container.encode(Kind.agent, forKey: .type)
|
||||||
|
try container.encode(message, forKey: .message)
|
||||||
|
try container.encodeIfPresent(thinking, forKey: .thinking)
|
||||||
|
try container.encodeIfPresent(session, forKey: .session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,6 +134,12 @@ extension Request: Codable {
|
|||||||
|
|
||||||
case .status:
|
case .status:
|
||||||
self = .status
|
self = .status
|
||||||
|
|
||||||
|
case .agent:
|
||||||
|
let message = try container.decode(String.self, forKey: .message)
|
||||||
|
let thinking = try container.decodeIfPresent(String.self, forKey: .thinking)
|
||||||
|
let session = try container.decodeIfPresent(String.self, forKey: .session)
|
||||||
|
self = .agent(message: message, thinking: thinking, session: session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user