chore: clean artifacts and fix device roles

This commit is contained in:
Peter Steinberger
2026-01-19 09:23:40 +00:00
parent 35e7c62e78
commit 9292ec9880
4 changed files with 38 additions and 2 deletions

3
.gitignore vendored
View File

@@ -35,6 +35,8 @@ vendor/
apps/ios/Clawdbot.xcodeproj/
apps/ios/Clawdbot.xcodeproj/**
apps/macos/.build/**
**/*.bun-build
apps/ios/*.xcfilelist
# Vendor build artifacts
vendor/a2ui/renderers/lit/dist/
@@ -48,6 +50,7 @@ apps/ios/fastlane/screenshots/
apps/ios/fastlane/test_output/
apps/ios/fastlane/logs/
apps/ios/fastlane/.env
apps/ios/fastlane/report.xml
# fastlane build artifacts (local)
apps/ios/*.ipa

View File

@@ -24,6 +24,7 @@ export const DevicePairRequestedEventSchema = Type.Object(
clientId: Type.Optional(NonEmptyString),
clientMode: Type.Optional(NonEmptyString),
role: Type.Optional(NonEmptyString),
roles: Type.Optional(Type.Array(NonEmptyString)),
scopes: Type.Optional(Type.Array(NonEmptyString)),
remoteIp: Type.Optional(NonEmptyString),
silent: Type.Optional(Type.Boolean()),

View File

@@ -30,6 +30,12 @@ import {
} from "./nodes.helpers.js";
import type { GatewayRequestHandlers } from "./types.js";
function isNodeEntry(entry: { role?: string; roles?: string[] }) {
if (entry.role === "node") return true;
if (Array.isArray(entry.roles) && entry.roles.includes("node")) return true;
return false;
}
export const nodeHandlers: GatewayRequestHandlers = {
"node.pair.request": async ({ params, respond, context }) => {
if (!validateNodePairRequestParams(params)) {
@@ -207,7 +213,7 @@ export const nodeHandlers: GatewayRequestHandlers = {
const list = await listDevicePairing();
const pairedById = new Map(
list.paired
.filter((entry) => entry.role === "node")
.filter((entry) => isNodeEntry(entry))
.map((entry) => [
entry.deviceId,
{
@@ -284,7 +290,7 @@ export const nodeHandlers: GatewayRequestHandlers = {
}
await respondUnavailableOnThrow(respond, async () => {
const list = await listDevicePairing();
const paired = list.paired.find((n) => n.deviceId === id && n.role === "node");
const paired = list.paired.find((n) => n.deviceId === id && isNodeEntry(n));
const connected = context.nodeRegistry.listConnected();
const live = connected.find((n) => n.nodeId === id);

View File

@@ -12,6 +12,7 @@ export type DevicePairingPendingRequest = {
clientId?: string;
clientMode?: string;
role?: string;
roles?: string[];
scopes?: string[];
remoteIp?: string;
silent?: boolean;
@@ -27,6 +28,7 @@ export type PairedDevice = {
clientId?: string;
clientMode?: string;
role?: string;
roles?: string[];
scopes?: string[];
remoteIp?: string;
createdAtMs: number;
@@ -134,6 +136,24 @@ function normalizeDeviceId(deviceId: string) {
return deviceId.trim();
}
function mergeRoles(...items: Array<string | string[] | undefined>): string[] | undefined {
const roles = new Set<string>();
for (const item of items) {
if (!item) continue;
if (Array.isArray(item)) {
for (const role of item) {
const trimmed = role.trim();
if (trimmed) roles.add(trimmed);
}
} else {
const trimmed = item.trim();
if (trimmed) roles.add(trimmed);
}
}
if (roles.size === 0) return undefined;
return [...roles];
}
export async function listDevicePairing(baseDir?: string): Promise<DevicePairingList> {
const state = await loadState(baseDir);
const pending = Object.values(state.pendingById).sort((a, b) => b.ts - a.ts);
@@ -179,6 +199,7 @@ export async function requestDevicePairing(
clientId: req.clientId,
clientMode: req.clientMode,
role: req.role,
roles: req.role ? [req.role] : undefined,
scopes: req.scopes,
remoteIp: req.remoteIp,
silent: req.silent,
@@ -201,6 +222,7 @@ export async function approveDevicePairing(
if (!pending) return null;
const now = Date.now();
const existing = state.pairedByDeviceId[pending.deviceId];
const roles = mergeRoles(existing?.roles, existing?.role, pending.roles, pending.role);
const device: PairedDevice = {
deviceId: pending.deviceId,
publicKey: pending.publicKey,
@@ -209,6 +231,7 @@ export async function approveDevicePairing(
clientId: pending.clientId,
clientMode: pending.clientMode,
role: pending.role,
roles,
scopes: pending.scopes,
remoteIp: pending.remoteIp,
createdAtMs: existing?.createdAtMs ?? now,
@@ -244,12 +267,15 @@ export async function updatePairedDeviceMetadata(
const state = await loadState(baseDir);
const existing = state.pairedByDeviceId[normalizeDeviceId(deviceId)];
if (!existing) return;
const roles = mergeRoles(existing.roles, existing.role, patch.role);
state.pairedByDeviceId[deviceId] = {
...existing,
...patch,
deviceId: existing.deviceId,
createdAtMs: existing.createdAtMs,
approvedAtMs: existing.approvedAtMs,
role: patch.role ?? existing.role,
roles,
};
await persistState(state, baseDir);
});