Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f51cab9
feat(kilo-app): add stream-chat-react-native dependency
iscekic Mar 27, 2026
6fc58ca
feat(kilo-app): add useStreamChatCredentials hook
iscekic Mar 27, 2026
3fa5040
feat(kilo-app): add KiloClawChat component with Stream Chat integration
iscekic Mar 27, 2026
c7eb84d
feat(kilo-app): wire up chat screen with KiloClawChat component
iscekic Mar 27, 2026
a43076a
style(kilo-app): fix lint and formatting in chat files
iscekic Mar 27, 2026
666c14b
fix(kilo-app): add null guard for bot membership lookup
iscekic Mar 27, 2026
0f6f01b
revert: remove unnecessary null guard on bot membership lookup
iscekic Mar 27, 2026
21cc160
Merge branch 'main' into feature/kiloclaw-mobile-chat
iscekic Mar 27, 2026
fccb79b
chore(kilo-app): update AGENTS.md and app.config.js
iscekic Mar 27, 2026
9ef4187
fix(kilo-app): ignore netinfo peer dep in knip config
iscekic Mar 27, 2026
c841048
Merge remote-tracking branch 'origin/main' into feature/kiloclaw-mobi…
iscekic Mar 30, 2026
6dfb83b
style(kilo-app): format app.config.js
iscekic Mar 30, 2026
6c31de3
fix(kilo-app): add ascAppId for iOS App Store submission
iscekic Mar 30, 2026
13b8576
fix(kilo-app): enable noUncheckedIndexedAccess and fix type errors
iscekic Mar 30, 2026
83f8163
fix(kilo-app): fix connect/disconnect race and clear connectError on …
iscekic Mar 30, 2026
86867e3
fix(kilo-app): restore disconnectUser in cleanup to tear down WS on u…
iscekic Mar 30, 2026
0dec16c
chore(kilo-app): install stream-chat-react-native optional peer deps
iscekic Mar 30, 2026
d88d9ca
fix(kilo-app): pass empty config to react-native-share plugin
iscekic Mar 30, 2026
f90719d
chore(kilo-app): upgrade Expo SDK packages and exclude from minimumRe…
iscekic Mar 30, 2026
c87c135
fix(kilo-app): remove @stream-io/flat-list-mvcp (jcenter incompatible)
iscekic Mar 30, 2026
77ff30a
fix(kilo-app): pin lightningcss to 1.31.1 to fix CSS bundling error
iscekic Mar 30, 2026
113a244
fix: override lightningcss to 1.31.1 to fix react-native-css bundling
iscekic Mar 30, 2026
59a9963
fix(kilo-app): upgrade react-native-css to 3.0.6 to fix lightningcss …
iscekic Mar 30, 2026
237b674
fix: pin lightningcss to 1.30.1 to fix NativeWind CSS deserialization…
iscekic Mar 30, 2026
22d4cc3
chore(kilo-app): upgrade non-Expo-managed deps to latest
iscekic Mar 30, 2026
22d9d89
chore(kilo-app): upgrade @sentry/react-native from v7 to v8
iscekic Mar 30, 2026
ebc1c47
chore(kilo-app): suppress stream-chat console noise with LogBox
iscekic Mar 30, 2026
e752384
fix(kilo-app): upgrade @gorhom/bottom-sheet to fix getBoundingClientR…
iscekic Mar 30, 2026
cde24c7
revert(kilo-app): downgrade @sentry/react-native back to v7 for Expo …
iscekic Mar 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kilo-app/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## What This Is

Kilo App is an Expo (React Native) mobile application using Expo Router for file-based routing. It lives as a subpackage (`kilo-app/`) in the `cloud` monorepo. **This app targets iOS and Android only — never web.** Do not add `Platform.select({ web: ... })` patterns or web-specific code.
Kilo App is an Expo (React Native) mobile application using Expo Router for file-based routing. It lives as a subpackage (`kilo-app/`) in the `cloud` monorepo. **This app targets iOS and Android only — never web.** Do not add `Platform.select({ web: ... })` patterns or web-specific code. **We use dev builds, not Expo Go.**

## Tech Stack

Expand Down
2 changes: 1 addition & 1 deletion kilo-app/app.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('expo/config').ExpoConfig} */
const config = {
name: 'Kilo',
name: 'KiloClaw',
owner: 'kilocode',
slug: 'kilo-app',
version: '1.0.0',
Expand Down
3 changes: 3 additions & 0 deletions kilo-app/eas.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"production": {
"android": {
"track": "internal"
},
"ios": {
"ascAppId": "6761193135"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion kilo-app/knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"expo-system-ui",
"postcss",
"eslint-plugin-sonarjs",
"@sentry/cli"
"@sentry/cli",
"@react-native-community/netinfo"
],
"ignoreBinaries": ["oxfmt", "oxlint"],
"ignore": ["src/components/ui/**"],
Expand Down
3 changes: 3 additions & 0 deletions kilo-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"dependencies": {
"@kilocode/trpc": "workspace:*",
"@react-native-community/netinfo": "11.5.2",
"@rn-primitives/portal": "^1.3.0",
"@rn-primitives/slot": "^1.2.0",
"@sentry/react-native": "~7.11.0",
Expand Down Expand Up @@ -56,6 +57,8 @@
"react-native-svg": "15.15.3",
"react-native-worklets": "0.7.2",
"sonner-native": "^0.23.1",
"stream-chat": "^9.38.0",
"stream-chat-react-native": "^8.13.7",
"tailwind-merge": "^3.5.0",
"tailwindcss": "^4.2.1"
},
Expand Down
16 changes: 5 additions & 11 deletions kilo-app/src/app/(app)/(tabs)/(1_kiloclaw)/[instance-id]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import { useLocalSearchParams } from 'expo-router';
import { MessageSquare } from 'lucide-react-native';
import { View } from 'react-native';

import { EmptyState } from '@/components/empty-state';
import { ScreenHeader } from '@/components/screen-header';
import { KiloClawChat } from '@/components/kiloclaw/chat';
import { useKiloClawStatus } from '@/lib/hooks/use-kiloclaw';

export default function ChatScreen() {
const { 'instance-id': instanceId } = useLocalSearchParams<{ 'instance-id': string }>();
const { data: status } = useKiloClawStatus();
const isRunning = status?.status === 'running';

return (
<View className="flex-1 bg-background">
<ScreenHeader title="Chat" />
<View className="flex-1 items-center justify-center px-6">
<EmptyState
icon={MessageSquare}
title="Chat coming soon"
description={`Instance: ${instanceId}`}
/>
</View>
<KiloClawChat instanceId={instanceId} enabled={isRunning} />
</View>
);
}
267 changes: 267 additions & 0 deletions kilo-app/src/components/kiloclaw/chat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
import { useCallback, useEffect, useState } from 'react';
import { ActivityIndicator, Pressable, View } from 'react-native';
import { useQueryClient } from '@tanstack/react-query';
import { type Href, useRouter } from 'expo-router';
import { Settings } from 'lucide-react-native';
import { type Event, type Channel as StreamChannel, StreamChat } from 'stream-chat';
import {
Channel,
Chat,
MessageInput,
MessageList,
OverlayProvider,
} from 'stream-chat-react-native';

import { ScreenHeader } from '@/components/screen-header';
import { Text } from '@/components/ui/text';
import { useStreamChatCredentials } from '@/lib/hooks/use-kiloclaw';
import { useThemeColors } from '@/lib/hooks/use-theme-colors';
import { useTRPC } from '@/lib/trpc';

type KiloClawChatProps = {
instanceId: string;
enabled: boolean;
};

export function KiloClawChat({ instanceId, enabled }: Readonly<KiloClawChatProps>) {
const { data: creds, isLoading, error } = useStreamChatCredentials(enabled);

if (!enabled) {
return (
<ChatShell instanceId={instanceId}>
<ChatPlaceholder message="Chat is available when the machine is running." />
</ChatShell>
);
}

if (isLoading) {
return (
<ChatShell instanceId={instanceId}>
<View className="flex-1 items-center justify-center">
<ActivityIndicator />
</View>
</ChatShell>
);
}

if (error) {
return (
<ChatShell instanceId={instanceId}>
<ChatPlaceholder message="Failed to load chat. Please try again." />
</ChatShell>
);
}

if (!creds) {
return (
<ChatShell instanceId={instanceId}>
<ChatPlaceholder message="Chat requires an upgrade. Use 'Upgrade to Latest' on the dashboard." />
</ChatShell>
);
}

return (
<StreamChatUI
instanceId={instanceId}
apiKey={creds.apiKey}
userId={creds.userId}
channelId={creds.channelId}
/>
);
}

// ─── Internal components ────────────────────────────────────────────────────

function ChatShell({ instanceId, children }: { instanceId: string; children: React.ReactNode }) {
return (
<View className="flex-1 bg-background">
<ChatHeader instanceId={instanceId} />
{children}
</View>
);
}

function ChatHeader({ instanceId, botOnline }: { instanceId: string; botOnline?: boolean }) {
const router = useRouter();
const colors = useThemeColors();

const settingsButton = (
<Pressable
onPress={() => {
router.push(`/(app)/(tabs)/(1_kiloclaw)/${instanceId}/dashboard` as Href);
}}
hitSlop={12}
accessibilityLabel="Settings"
className="active:opacity-70"
>
<Settings size={20} color={colors.foreground} />
</Pressable>
);

return (
<ScreenHeader
title="Chat"
headerRight={
<View className="flex-row items-center gap-3">
{botOnline !== undefined && <BotStatusIndicator online={botOnline} />}
{settingsButton}
</View>
}
/>
);
}

function BotStatusIndicator({ online }: { online: boolean }) {
return (
<View className="flex-row items-center gap-1.5">
<View className={`h-2 w-2 rounded-full ${online ? 'bg-emerald-400' : 'bg-neutral-500'}`} />
<Text className="text-xs text-muted-foreground">{online ? 'Online' : 'Offline'}</Text>
</View>
);
}

function StreamChatUI({
instanceId,
apiKey,
userId,
channelId,
}: {
instanceId: string;
apiKey: string;
userId: string;
channelId: string;
}) {
const trpc = useTRPC();
const queryClient = useQueryClient();

// Stable token provider — stream-chat calls this when the current token expires.
const tokenProvider = useCallback(async () => {
const creds = await queryClient.fetchQuery(
trpc.kiloclaw.getStreamChatCredentials.queryOptions(undefined, {
staleTime: 0,
})
);
if (!creds?.userToken) {
throw new Error('Failed to fetch Stream Chat credentials');
}
return creds.userToken;
}, [queryClient, trpc]);

const [client, setClient] = useState<StreamChat | null>(null);
const [channel, setChannel] = useState<StreamChannel | null>(null);
const [connectError, setConnectError] = useState<string | null>(null);

useEffect(() => {
const chatClient = StreamChat.getInstance(apiKey);

let cancelled = false;
setConnectError(null);

const connect = async () => {
try {
// Await disconnect to prevent tokenManager.reset() from racing with the new connection
if (chatClient.userID) {
await chatClient.disconnectUser();
}
if (cancelled) {
return;
}
await chatClient.connectUser({ id: userId }, tokenProvider);
const ch = chatClient.channel('messaging', channelId);
await ch.watch({ presence: true });
// cancelled may change across awaits above
if (!cancelled) {

Check failure on line 173 in kilo-app/src/components/kiloclaw/chat.tsx

View workflow job for this annotation

GitHub Actions / lint

typescript-eslint(no-unnecessary-condition)

Unnecessary conditional, value is always truthy.

Check failure on line 173 in kilo-app/src/components/kiloclaw/chat.tsx

View workflow job for this annotation

GitHub Actions / lint

typescript-eslint(no-unnecessary-condition)

Unnecessary conditional, value is always truthy.
// eslint-disable-line typescript-eslint/no-unnecessary-condition
setClient(chatClient);
setChannel(ch);
}
} catch (error) {
if (!cancelled) {
setConnectError(error instanceof Error ? error.message : 'Failed to connect to chat.');
}
}
};

void connect();

return () => {
cancelled = true;
setClient(null);
setChannel(null);
};
}, [apiKey, userId, channelId, tokenProvider]);

// Bot presence tracking
const sandboxId = channelId.replace(/^default-/, '');
const botUserId = `bot-${sandboxId}`;
const botOnline = useBotOnlineStatus(client, channel, botUserId);

if (connectError) {
return (
<ChatShell instanceId={instanceId}>
<ChatPlaceholder message={connectError} />
</ChatShell>
);
}

if (!client || !channel) {
return (
<ChatShell instanceId={instanceId}>
<View className="flex-1 items-center justify-center">
<ActivityIndicator />
</View>
</ChatShell>
);
}

return (
<View className="flex-1 bg-background">
<ChatHeader instanceId={instanceId} botOnline={botOnline} />
<OverlayProvider>
<Chat client={client}>
<Channel channel={channel}>
<MessageList />
<MessageInput />
</Channel>
</Chat>
</OverlayProvider>
</View>
);
}

function useBotOnlineStatus(
client: StreamChat | null,
channel: StreamChannel | null,
botUserId: string
): boolean {
const [online, setOnline] = useState(false);

useEffect(() => {
const handlePresenceChange = (event: Event) => {
if (event.user?.id === botUserId) {
setOnline(Boolean(event.user.online));
}
};

if (client && channel) {
// Check initial state
const member = channel.state.members[botUserId];
setOnline(Boolean(member?.user?.online));
client.on('user.presence.changed', handlePresenceChange);
}

return () => {
client?.off('user.presence.changed', handlePresenceChange);
};
}, [client, channel, botUserId]);

return online;
}

function ChatPlaceholder({ message }: { message: string }) {
return (
<View className="flex-1 items-center justify-center px-6">
<Text className="text-sm text-muted-foreground text-center">{message}</Text>
</View>
);
}
2 changes: 1 addition & 1 deletion kilo-app/src/components/profile-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function CreditsCard() {
<Skeleton className="mt-1 h-3 w-48 rounded" />
) : (
expiringTotal > 0 &&
Boolean(earliestExpiry) && (
earliestExpiry != null && (
<Text className="mt-1 text-xs text-muted-foreground">
${expiringTotal.toFixed(2)} in bonus credits expiring{' '}
{parseTimestamp(earliestExpiry).toLocaleDateString(undefined, {
Expand Down
10 changes: 10 additions & 0 deletions kilo-app/src/lib/hooks/use-kiloclaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ export function useKiloClawSecretCatalog() {
);
}

export function useStreamChatCredentials(enabled: boolean) {
const trpc = useTRPC();
return useQuery(
trpc.kiloclaw.getStreamChatCredentials.queryOptions(undefined, {
enabled,
staleTime: 5 * 60_000,
})
);
}

// ── Mutations ────────────────────────────────────────────────────────

const onMutationError = (error: { message: string }) => {
Expand Down
1 change: 1 addition & 0 deletions kilo-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"paths": {
"@/*": ["./src/*"],
"@/assets/*": ["./assets/*"]
Expand Down
Loading
Loading