Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
110079d99d | ||
|
|
34a126a6d7 | ||
|
|
31462f64d8 | ||
|
|
de0a488985 |
No files matched your search
+1
-1
@@ -25,7 +25,6 @@ Docs: https://docs.clawd.bot
|
|||||||
- UI: add copy-as-markdown with error feedback and drop legacy list view. (#1345) — thanks @bradleypriest.
|
- UI: add copy-as-markdown with error feedback and drop legacy list view. (#1345) — thanks @bradleypriest.
|
||||||
- TUI: add input history (up/down) for submitted messages. (#1348) — thanks @vignesh07.
|
- TUI: add input history (up/down) for submitted messages. (#1348) — thanks @vignesh07.
|
||||||
### Fixes
|
### Fixes
|
||||||
- iOS: explain Talk mode is unavailable on the simulator to avoid Speech live-audio crashes. (#1358) — thanks @vignesh07.
|
|
||||||
- Discovery: shorten Bonjour DNS-SD service type to `_clawdbot-gw._tcp` and update discovery clients/docs.
|
- Discovery: shorten Bonjour DNS-SD service type to `_clawdbot-gw._tcp` and update discovery clients/docs.
|
||||||
- Agents: preserve subagent announce thread/topic routing + queued replies across channels. (#1241) — thanks @gnarco.
|
- Agents: preserve subagent announce thread/topic routing + queued replies across channels. (#1241) — thanks @gnarco.
|
||||||
- Agents: avoid treating timeout errors with "aborted" messages as user aborts, so model fallback still runs.
|
- Agents: avoid treating timeout errors with "aborted" messages as user aborts, so model fallback still runs.
|
||||||
@@ -35,6 +34,7 @@ Docs: https://docs.clawd.bot
|
|||||||
- CLI: keep `clawdbot logs` output resilient to broken pipes while preserving progress output.
|
- CLI: keep `clawdbot logs` output resilient to broken pipes while preserving progress output.
|
||||||
- Model catalog: avoid caching import failures, log transient discovery errors, and keep partial results. (#1332) — thanks @dougvk.
|
- Model catalog: avoid caching import failures, log transient discovery errors, and keep partial results. (#1332) — thanks @dougvk.
|
||||||
- Doctor: clarify plugin auto-enable hint text in the startup banner.
|
- Doctor: clarify plugin auto-enable hint text in the startup banner.
|
||||||
|
- Gateway: allow mobile node client ids for iOS + Android handshake validation. (#1354) — thanks @vignesh07.
|
||||||
- Gateway: clarify unauthorized handshake responses with token/password mismatch guidance.
|
- Gateway: clarify unauthorized handshake responses with token/password mismatch guidance.
|
||||||
- Gateway: clarify connect/validation errors for gateway params. (#1347) — thanks @vignesh07.
|
- Gateway: clarify connect/validation errors for gateway params. (#1347) — thanks @vignesh07.
|
||||||
- Gateway: preserve restart wake routing + thread replies across restarts. (#1337) — thanks @John-Rood.
|
- Gateway: preserve restart wake routing + thread replies across restarts. (#1337) — thanks @John-Rood.
|
||||||
|
|||||||
@@ -529,7 +529,7 @@ class NodeRuntime(context: Context) {
|
|||||||
caps = buildCapabilities(),
|
caps = buildCapabilities(),
|
||||||
commands = buildInvokeCommands(),
|
commands = buildInvokeCommands(),
|
||||||
permissions = emptyMap(),
|
permissions = emptyMap(),
|
||||||
client = buildClientInfo(clientId = "node-host", clientMode = "node"),
|
client = buildClientInfo(clientId = "clawdbot-android", clientMode = "node"),
|
||||||
userAgent = buildUserAgent(),
|
userAgent = buildUserAgent(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,13 +132,6 @@ final class TalkModeManager: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func startRecognition() throws {
|
private func startRecognition() throws {
|
||||||
#if targetEnvironment(simulator)
|
|
||||||
// Apple Speech live-audio recognition is not supported on Simulator.
|
|
||||||
throw NSError(domain: "TalkMode", code: 2, userInfo: [
|
|
||||||
NSLocalizedDescriptionKey: "Talk mode is not supported on the iOS simulator (Speech live audio requires a device).",
|
|
||||||
])
|
|
||||||
#endif
|
|
||||||
|
|
||||||
self.stopRecognition()
|
self.stopRecognition()
|
||||||
self.speechRecognizer = SFSpeechRecognizer()
|
self.speechRecognizer = SFSpeechRecognizer()
|
||||||
guard let recognizer = self.speechRecognizer else {
|
guard let recognizer = self.speechRecognizer else {
|
||||||
@@ -153,11 +146,6 @@ final class TalkModeManager: NSObject {
|
|||||||
|
|
||||||
let input = self.audioEngine.inputNode
|
let input = self.audioEngine.inputNode
|
||||||
let format = input.outputFormat(forBus: 0)
|
let format = input.outputFormat(forBus: 0)
|
||||||
guard format.sampleRate > 0, format.channelCount > 0 else {
|
|
||||||
throw NSError(domain: "TalkMode", code: 3, userInfo: [
|
|
||||||
NSLocalizedDescriptionKey: "Invalid audio input format",
|
|
||||||
])
|
|
||||||
}
|
|
||||||
input.removeTap(onBus: 0)
|
input.removeTap(onBus: 0)
|
||||||
let tapBlock = Self.makeAudioTapAppendCallback(request: request)
|
let tapBlock = Self.makeAudioTapAppendCallback(request: request)
|
||||||
input.installTap(onBus: 0, bufferSize: 2048, format: format, block: tapBlock)
|
input.installTap(onBus: 0, bufferSize: 2048, format: format, block: tapBlock)
|
||||||
|
|||||||
@@ -87,15 +87,7 @@ final class ControlChannel {
|
|||||||
|
|
||||||
func configure() async {
|
func configure() async {
|
||||||
self.logger.info("control channel configure mode=local")
|
self.logger.info("control channel configure mode=local")
|
||||||
self.state = .connecting
|
await self.refreshEndpoint(reason: "configure")
|
||||||
do {
|
|
||||||
try await GatewayConnection.shared.refresh()
|
|
||||||
self.state = .connected
|
|
||||||
PresenceReporter.shared.sendImmediate(reason: "connect")
|
|
||||||
} catch {
|
|
||||||
let message = self.friendlyGatewayMessage(error)
|
|
||||||
self.state = .degraded(message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func configure(mode: Mode = .local) async throws {
|
func configure(mode: Mode = .local) async throws {
|
||||||
@@ -111,7 +103,7 @@ final class ControlChannel {
|
|||||||
"target=\(target, privacy: .public) identitySet=\(idSet, privacy: .public)")
|
"target=\(target, privacy: .public) identitySet=\(idSet, privacy: .public)")
|
||||||
self.state = .connecting
|
self.state = .connecting
|
||||||
_ = try await GatewayEndpointStore.shared.ensureRemoteControlTunnel()
|
_ = try await GatewayEndpointStore.shared.ensureRemoteControlTunnel()
|
||||||
await self.configure()
|
await self.refreshEndpoint(reason: "configure")
|
||||||
} catch {
|
} catch {
|
||||||
self.state = .degraded(error.localizedDescription)
|
self.state = .degraded(error.localizedDescription)
|
||||||
throw error
|
throw error
|
||||||
@@ -119,6 +111,19 @@ final class ControlChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refreshEndpoint(reason: String) async {
|
||||||
|
self.logger.info("control channel refresh endpoint reason=\(reason, privacy: .public)")
|
||||||
|
self.state = .connecting
|
||||||
|
do {
|
||||||
|
try await self.establishGatewayConnection()
|
||||||
|
self.state = .connected
|
||||||
|
PresenceReporter.shared.sendImmediate(reason: "connect")
|
||||||
|
} catch {
|
||||||
|
let message = self.friendlyGatewayMessage(error)
|
||||||
|
self.state = .degraded(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func disconnect() async {
|
func disconnect() async {
|
||||||
await GatewayConnection.shared.shutdown()
|
await GatewayConnection.shared.shutdown()
|
||||||
self.state = .disconnected
|
self.state = .disconnected
|
||||||
@@ -275,18 +280,28 @@ final class ControlChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
await self.refreshEndpoint(reason: "recovery:\(reasonText)")
|
||||||
try await GatewayConnection.shared.refresh()
|
if case .connected = self.state {
|
||||||
self.logger.info("control channel recovery finished")
|
self.logger.info("control channel recovery finished")
|
||||||
} catch {
|
} else if case let .degraded(message) = self.state {
|
||||||
self.logger.error(
|
self.logger.error("control channel recovery failed \(message, privacy: .public)")
|
||||||
"control channel recovery failed \(error.localizedDescription, privacy: .public)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.recoveryTask = nil
|
self.recoveryTask = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func establishGatewayConnection(timeoutMs: Int = 5000) async throws {
|
||||||
|
try await GatewayConnection.shared.refresh()
|
||||||
|
let ok = try await GatewayConnection.shared.healthOK(timeoutMs: timeoutMs)
|
||||||
|
if ok == false {
|
||||||
|
throw NSError(
|
||||||
|
domain: "Gateway",
|
||||||
|
code: 0,
|
||||||
|
userInfo: [NSLocalizedDescriptionKey: "gateway health not ok"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func sendSystemEvent(_ text: String, params: [String: AnyHashable] = [:]) async throws {
|
func sendSystemEvent(_ text: String, params: [String: AnyHashable] = [:]) async throws {
|
||||||
var merged = params
|
var merged = params
|
||||||
merged["text"] = AnyHashable(text)
|
merged["text"] = AnyHashable(text)
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import Foundation
|
||||||
|
import Observation
|
||||||
|
import OSLog
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
@Observable
|
||||||
|
final class GatewayConnectivityCoordinator {
|
||||||
|
static let shared = GatewayConnectivityCoordinator()
|
||||||
|
|
||||||
|
private let logger = Logger(subsystem: "com.clawdbot", category: "gateway.connectivity")
|
||||||
|
private var endpointTask: Task<Void, Never>?
|
||||||
|
private var lastResolvedURL: URL?
|
||||||
|
|
||||||
|
private(set) var endpointState: GatewayEndpointState?
|
||||||
|
private(set) var resolvedURL: URL?
|
||||||
|
private(set) var resolvedMode: AppState.ConnectionMode?
|
||||||
|
private(set) var resolvedHostLabel: String?
|
||||||
|
|
||||||
|
private init() {
|
||||||
|
self.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
func start() {
|
||||||
|
guard self.endpointTask == nil else { return }
|
||||||
|
self.endpointTask = Task { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
let stream = await GatewayEndpointStore.shared.subscribe()
|
||||||
|
for await state in stream {
|
||||||
|
await MainActor.run { self.handleEndpointState(state) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var localEndpointHostLabel: String? {
|
||||||
|
guard self.resolvedMode == .local, let url = self.resolvedURL else { return nil }
|
||||||
|
return Self.hostLabel(for: url)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleEndpointState(_ state: GatewayEndpointState) {
|
||||||
|
self.endpointState = state
|
||||||
|
switch state {
|
||||||
|
case let .ready(mode, url, _, _):
|
||||||
|
self.resolvedMode = mode
|
||||||
|
self.resolvedURL = url
|
||||||
|
self.resolvedHostLabel = Self.hostLabel(for: url)
|
||||||
|
let urlChanged = self.lastResolvedURL?.absoluteString != url.absoluteString
|
||||||
|
if urlChanged {
|
||||||
|
self.lastResolvedURL = url
|
||||||
|
Task { await ControlChannel.shared.refreshEndpoint(reason: "endpoint changed") }
|
||||||
|
}
|
||||||
|
case let .connecting(mode, _):
|
||||||
|
self.resolvedMode = mode
|
||||||
|
case let .unavailable(mode, _):
|
||||||
|
self.resolvedMode = mode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func hostLabel(for url: URL) -> String {
|
||||||
|
let host = url.host ?? url.absoluteString
|
||||||
|
if let port = url.port { return "\(host):\(port)" }
|
||||||
|
return host
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -68,6 +68,7 @@ actor GatewayEndpointStore {
|
|||||||
env: ProcessInfo.processInfo.environment)
|
env: ProcessInfo.processInfo.environment)
|
||||||
let customBindHost = GatewayEndpointStore.resolveGatewayCustomBindHost(root: root)
|
let customBindHost = GatewayEndpointStore.resolveGatewayCustomBindHost(root: root)
|
||||||
let tailscaleIP = await MainActor.run { TailscaleService.shared.tailscaleIP }
|
let tailscaleIP = await MainActor.run { TailscaleService.shared.tailscaleIP }
|
||||||
|
?? TailscaleService.fallbackTailnetIPv4()
|
||||||
return GatewayEndpointStore.resolveLocalGatewayHost(
|
return GatewayEndpointStore.resolveLocalGatewayHost(
|
||||||
bindMode: bind,
|
bindMode: bind,
|
||||||
customBindHost: customBindHost,
|
customBindHost: customBindHost,
|
||||||
@@ -487,6 +488,7 @@ actor GatewayEndpointStore {
|
|||||||
guard currentHost == "127.0.0.1" || currentHost == "localhost" else { return nil }
|
guard currentHost == "127.0.0.1" || currentHost == "localhost" else { return nil }
|
||||||
|
|
||||||
let tailscaleIP = await MainActor.run { TailscaleService.shared.tailscaleIP }
|
let tailscaleIP = await MainActor.run { TailscaleService.shared.tailscaleIP }
|
||||||
|
?? TailscaleService.fallbackTailnetIPv4()
|
||||||
guard let tailscaleIP, !tailscaleIP.isEmpty else { return nil }
|
guard let tailscaleIP, !tailscaleIP.isEmpty else { return nil }
|
||||||
|
|
||||||
let scheme = GatewayEndpointStore.resolveGatewayScheme(
|
let scheme = GatewayEndpointStore.resolveGatewayScheme(
|
||||||
|
|||||||
@@ -235,8 +235,8 @@ final class HealthStore {
|
|||||||
let lower = error.lowercased()
|
let lower = error.lowercased()
|
||||||
if lower.contains("connection refused") {
|
if lower.contains("connection refused") {
|
||||||
let port = GatewayEnvironment.gatewayPort()
|
let port = GatewayEnvironment.gatewayPort()
|
||||||
return "The gateway control port (127.0.0.1:\(port)) isn’t listening — " +
|
let host = GatewayConnectivityCoordinator.shared.localEndpointHostLabel ?? "127.0.0.1:\(port)"
|
||||||
"restart Clawdbot to bring it back."
|
return "The gateway control port (\(host)) isn’t listening — restart Clawdbot to bring it back."
|
||||||
}
|
}
|
||||||
if lower.contains("timeout") {
|
if lower.contains("timeout") {
|
||||||
return "Timed out waiting for the control server; the gateway may be crashed or still starting."
|
return "Timed out waiting for the control server; the gateway may be crashed or still starting."
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ struct ClawdbotApp: App {
|
|||||||
private let gatewayManager = GatewayProcessManager.shared
|
private let gatewayManager = GatewayProcessManager.shared
|
||||||
private let controlChannel = ControlChannel.shared
|
private let controlChannel = ControlChannel.shared
|
||||||
private let activityStore = WorkActivityStore.shared
|
private let activityStore = WorkActivityStore.shared
|
||||||
|
private let connectivityCoordinator = GatewayConnectivityCoordinator.shared
|
||||||
@State private var statusItem: NSStatusItem?
|
@State private var statusItem: NSStatusItem?
|
||||||
@State private var isMenuPresented = false
|
@State private var isMenuPresented = false
|
||||||
@State private var isPanelVisible = false
|
@State private var isPanelVisible = false
|
||||||
|
|||||||
@@ -469,7 +469,7 @@ extension MenuSessionsInjector {
|
|||||||
}
|
}
|
||||||
case .local:
|
case .local:
|
||||||
platform = "local"
|
platform = "local"
|
||||||
host = "127.0.0.1:\(port)"
|
host = GatewayConnectivityCoordinator.shared.localEndpointHostLabel ?? "127.0.0.1:\(port)"
|
||||||
case .unconfigured:
|
case .unconfigured:
|
||||||
platform = nil
|
platform = nil
|
||||||
host = nil
|
host = nil
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ final class TailscaleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkTailscaleStatus() async {
|
func checkTailscaleStatus() async {
|
||||||
|
let previousIP = self.tailscaleIP
|
||||||
self.isInstalled = self.checkAppInstallation()
|
self.isInstalled = self.checkAppInstallation()
|
||||||
if !self.isInstalled {
|
if !self.isInstalled {
|
||||||
self.isRunning = false
|
self.isRunning = false
|
||||||
@@ -147,6 +148,10 @@ final class TailscaleService {
|
|||||||
self.statusError = nil
|
self.statusError = nil
|
||||||
self.logger.info("Tailscale interface IP detected (fallback) ip=\(fallback, privacy: .public)")
|
self.logger.info("Tailscale interface IP detected (fallback) ip=\(fallback, privacy: .public)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if previousIP != self.tailscaleIP {
|
||||||
|
await GatewayEndpointStore.shared.refresh()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func openTailscaleApp() {
|
func openTailscaleApp() {
|
||||||
@@ -214,4 +219,8 @@ final class TailscaleService {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nonisolated static func fallbackTailnetIPv4() -> String? {
|
||||||
|
Self.detectTailnetIPv4()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -30,13 +30,6 @@ function buildRows(entries: Array<{ id: string; name?: string | undefined }>) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatEntry(entry: { id: string; name?: string; handle?: string }) {
|
|
||||||
const name = entry.name?.trim() ?? "";
|
|
||||||
const handle = entry.handle?.trim() ?? "";
|
|
||||||
const label = name || handle;
|
|
||||||
return label ? `${entry.id} - ${label}` : entry.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function registerDirectoryCli(program: Command) {
|
export function registerDirectoryCli(program: Command) {
|
||||||
const directory = program
|
const directory = program
|
||||||
.command("directory")
|
.command("directory")
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
import { defaultRuntime } from "../runtime.js";
|
|
||||||
|
|
||||||
const { buildProgram } = await import("./program.js");
|
const { buildProgram } = await import("./program.js");
|
||||||
|
|
||||||
describe("dns cli", () => {
|
describe("dns cli", () => {
|
||||||
it("prints setup info (no apply)", async () => {
|
it("prints setup info (no apply)", async () => {
|
||||||
const log = vi.spyOn(defaultRuntime, "log").mockImplementation(() => {});
|
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||||
const program = buildProgram();
|
const program = buildProgram();
|
||||||
await program.parseAsync(["dns", "setup"], { from: "user" });
|
await program.parseAsync(["dns", "setup"], { from: "user" });
|
||||||
const output = log.mock.calls.map((args) => args.join(" ")).join("\n");
|
expect(log).toHaveBeenCalledWith(expect.stringContaining("Domain:"));
|
||||||
expect(output).toContain("clawdbot.internal");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -46,13 +46,10 @@ function formatNodeVersions(node: {
|
|||||||
|
|
||||||
function parseSinceMs(raw: unknown, label: string): number | undefined {
|
function parseSinceMs(raw: unknown, label: string): number | undefined {
|
||||||
if (raw === undefined || raw === null) return undefined;
|
if (raw === undefined || raw === null) return undefined;
|
||||||
let value = "";
|
const value =
|
||||||
if (typeof raw === "string") {
|
typeof raw === "string" ? raw.trim() : typeof raw === "number" ? String(raw).trim() : null;
|
||||||
value = raw.trim();
|
if (value === null) {
|
||||||
} else if (typeof raw === "number") {
|
defaultRuntime.error(`${label}: invalid duration value`);
|
||||||
value = `${raw}`;
|
|
||||||
} else {
|
|
||||||
defaultRuntime.error(`${label}: expected a duration string`);
|
|
||||||
defaultRuntime.exit(1);
|
defaultRuntime.exit(1);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { Command } from "commander";
|
import { Command } from "commander";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
import { defaultRuntime } from "../runtime.js";
|
|
||||||
|
|
||||||
const listChannelPairingRequests = vi.fn();
|
const listChannelPairingRequests = vi.fn();
|
||||||
const approveChannelPairingCode = vi.fn();
|
const approveChannelPairingCode = vi.fn();
|
||||||
const notifyPairingApproved = vi.fn();
|
const notifyPairingApproved = vi.fn();
|
||||||
@@ -66,16 +64,14 @@ describe("pairing cli", () => {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const log = vi.spyOn(defaultRuntime, "log").mockImplementation(() => {});
|
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
program.name("test");
|
program.name("test");
|
||||||
registerPairingCli(program);
|
registerPairingCli(program);
|
||||||
await program.parseAsync(["pairing", "list", "--channel", "telegram"], {
|
await program.parseAsync(["pairing", "list", "--channel", "telegram"], {
|
||||||
from: "user",
|
from: "user",
|
||||||
});
|
});
|
||||||
const output = log.mock.calls.map((args) => args.join(" ")).join("\n");
|
expect(log).toHaveBeenCalledWith(expect.stringContaining("telegramUserId=123"));
|
||||||
expect(output).toContain("telegramUserId");
|
|
||||||
expect(output).toContain("123");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("accepts channel as positional for list", async () => {
|
it("accepts channel as positional for list", async () => {
|
||||||
@@ -128,16 +124,14 @@ describe("pairing cli", () => {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const log = vi.spyOn(defaultRuntime, "log").mockImplementation(() => {});
|
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
program.name("test");
|
program.name("test");
|
||||||
registerPairingCli(program);
|
registerPairingCli(program);
|
||||||
await program.parseAsync(["pairing", "list", "--channel", "discord"], {
|
await program.parseAsync(["pairing", "list", "--channel", "discord"], {
|
||||||
from: "user",
|
from: "user",
|
||||||
});
|
});
|
||||||
const output = log.mock.calls.map((args) => args.join(" ")).join("\n");
|
expect(log).toHaveBeenCalledWith(expect.stringContaining("discordUserId=999"));
|
||||||
expect(output).toContain("discordUserId");
|
|
||||||
expect(output).toContain("999");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("accepts channel as positional for approve (npm-run compatible)", async () => {
|
it("accepts channel as positional for approve (npm-run compatible)", async () => {
|
||||||
@@ -152,7 +146,7 @@ describe("pairing cli", () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const log = vi.spyOn(defaultRuntime, "log").mockImplementation(() => {});
|
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
program.name("test");
|
program.name("test");
|
||||||
registerPairingCli(program);
|
registerPairingCli(program);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ type CommandOptions = Record<string, unknown>;
|
|||||||
|
|
||||||
// --- Helpers ---
|
// --- Helpers ---
|
||||||
|
|
||||||
const SANDBOX_EXAMPLES: Record<string, [string, string][]> = {
|
const SANDBOX_EXAMPLES = {
|
||||||
main: [
|
main: [
|
||||||
["clawdbot sandbox list", "List all sandbox containers."],
|
["clawdbot sandbox list", "List all sandbox containers."],
|
||||||
["clawdbot sandbox list --browser", "List only browser containers."],
|
["clawdbot sandbox list --browser", "List only browser containers."],
|
||||||
@@ -40,7 +40,7 @@ const SANDBOX_EXAMPLES: Record<string, [string, string][]> = {
|
|||||||
["clawdbot sandbox explain --agent work", "Explain an agent sandbox."],
|
["clawdbot sandbox explain --agent work", "Explain an agent sandbox."],
|
||||||
["clawdbot sandbox explain --json", "JSON output."],
|
["clawdbot sandbox explain --json", "JSON output."],
|
||||||
],
|
],
|
||||||
};
|
} as const;
|
||||||
|
|
||||||
function createRunner(
|
function createRunner(
|
||||||
commandFn: (opts: CommandOptions, runtime: typeof defaultRuntime) => Promise<void>,
|
commandFn: (opts: CommandOptions, runtime: typeof defaultRuntime) => Promise<void>,
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ export const GATEWAY_CLIENT_IDS = {
|
|||||||
CLI: "cli",
|
CLI: "cli",
|
||||||
GATEWAY_CLIENT: "gateway-client",
|
GATEWAY_CLIENT: "gateway-client",
|
||||||
MACOS_APP: "clawdbot-macos",
|
MACOS_APP: "clawdbot-macos",
|
||||||
|
IOS_APP: "clawdbot-ios",
|
||||||
|
ANDROID_APP: "clawdbot-android",
|
||||||
NODE_HOST: "node-host",
|
NODE_HOST: "node-host",
|
||||||
TEST: "test",
|
TEST: "test",
|
||||||
FINGERPRINT: "fingerprint",
|
FINGERPRINT: "fingerprint",
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import { test } from "vitest";
|
||||||
|
import WebSocket from "ws";
|
||||||
|
|
||||||
|
import { PROTOCOL_VERSION } from "./protocol/index.js";
|
||||||
|
import { getFreePort, onceMessage, startGatewayServer } from "./test-helpers.server.js";
|
||||||
|
|
||||||
|
function connectReq(
|
||||||
|
ws: WebSocket,
|
||||||
|
params: { clientId: string; platform: string; token?: string; password?: string },
|
||||||
|
): Promise<{ ok: boolean; error?: { message?: string } }> {
|
||||||
|
const id = `c-${Math.random().toString(16).slice(2)}`;
|
||||||
|
ws.send(
|
||||||
|
JSON.stringify({
|
||||||
|
type: "req",
|
||||||
|
id,
|
||||||
|
method: "connect",
|
||||||
|
params: {
|
||||||
|
minProtocol: PROTOCOL_VERSION,
|
||||||
|
maxProtocol: PROTOCOL_VERSION,
|
||||||
|
client: {
|
||||||
|
id: params.clientId,
|
||||||
|
version: "dev",
|
||||||
|
platform: params.platform,
|
||||||
|
mode: "node",
|
||||||
|
},
|
||||||
|
auth: {
|
||||||
|
token: params.token,
|
||||||
|
password: params.password,
|
||||||
|
},
|
||||||
|
role: "node",
|
||||||
|
scopes: [],
|
||||||
|
caps: ["canvas"],
|
||||||
|
commands: ["system.notify"],
|
||||||
|
permissions: {},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return onceMessage(
|
||||||
|
ws,
|
||||||
|
(o) => (o as { type?: string }).type === "res" && (o as { id?: string }).id === id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
test("accepts clawdbot-ios as a valid gateway client id", async () => {
|
||||||
|
const port = await getFreePort();
|
||||||
|
const server = await startGatewayServer(port);
|
||||||
|
const ws = new WebSocket(`ws://127.0.0.1:${port}`);
|
||||||
|
await new Promise<void>((resolve) => ws.once("open", resolve));
|
||||||
|
|
||||||
|
const res = await connectReq(ws, { clientId: "clawdbot-ios", platform: "ios" });
|
||||||
|
// We don't care if auth fails here; we only care that schema validation accepts the client id.
|
||||||
|
// A schema rejection would close the socket before sending a response.
|
||||||
|
if (!res.ok) {
|
||||||
|
// allow unauthorized error when gateway requires auth
|
||||||
|
// but reject schema validation errors
|
||||||
|
const message = String(res.error?.message ?? "");
|
||||||
|
if (message.includes("invalid connect params")) {
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ws.close();
|
||||||
|
await server.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("accepts clawdbot-android as a valid gateway client id", async () => {
|
||||||
|
const port = await getFreePort();
|
||||||
|
const server = await startGatewayServer(port);
|
||||||
|
const ws = new WebSocket(`ws://127.0.0.1:${port}`);
|
||||||
|
await new Promise<void>((resolve) => ws.once("open", resolve));
|
||||||
|
|
||||||
|
const res = await connectReq(ws, { clientId: "clawdbot-android", platform: "android" });
|
||||||
|
// We don't care if auth fails here; we only care that schema validation accepts the client id.
|
||||||
|
// A schema rejection would close the socket before sending a response.
|
||||||
|
if (!res.ok) {
|
||||||
|
// allow unauthorized error when gateway requires auth
|
||||||
|
// but reject schema validation errors
|
||||||
|
const message = String(res.error?.message ?? "");
|
||||||
|
if (message.includes("invalid connect params")) {
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ws.close();
|
||||||
|
await server.close();
|
||||||
|
});
|
||||||
@@ -187,7 +187,7 @@ export function onceMessage<T = unknown>(
|
|||||||
// Full-suite runs can saturate the event loop (581+ files). Keep this high
|
// Full-suite runs can saturate the event loop (581+ files). Keep this high
|
||||||
// enough to avoid flaky RPC timeouts, but still fail fast when a response
|
// enough to avoid flaky RPC timeouts, but still fail fast when a response
|
||||||
// never arrives.
|
// never arrives.
|
||||||
timeoutMs = 15_000,
|
timeoutMs = 10_000,
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
return new Promise<T>((resolve, reject) => {
|
return new Promise<T>((resolve, reject) => {
|
||||||
const timer = setTimeout(() => reject(new Error("timeout")), timeoutMs);
|
const timer = setTimeout(() => reject(new Error("timeout")), timeoutMs);
|
||||||
|
|||||||
Reference in new issue
Block a user