Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
3ed7b94
refactor(db): rename channel_badge_counts to badge_counts (general pu…
iscekic Apr 29, 2026
e8d062c
feat(db): migration to rename badge_counts and reset rows
iscekic Apr 29, 2026
20b9b3b
feat(notifications): add badge-bucket key builders
iscekic Apr 29, 2026
1bb97c6
chore(notifications): add EVENT_SERVICE binding, drop STREAM_CHAT_API…
iscekic Apr 29, 2026
d87c0fb
chore(notifications): add vitest scaffold
iscekic Apr 29, 2026
2a621db
feat(notifications): rewrite NotificationChannelDO around dispatchPush
iscekic Apr 29, 2026
26fccf5
chore(notifications): drop orphan badgeBucketForInstance helper
iscekic Apr 29, 2026
7fad879
feat(notifications): add sendPushForConversation WorkerEntrypoint RPC
iscekic Apr 29, 2026
f6e1848
chore(notifications): delete Stream webhook route
iscekic Apr 29, 2026
3c7c82e
chore(notifications): type EVENT_SERVICE RPC and enable cloudflare:te…
iscekic Apr 29, 2026
227b90e
feat(event-service): add kiloclaw event-context helpers; migrate kilo…
iscekic Apr 29, 2026
87f0fab
feat(kilo-chat): add fetchSandboxLabel helper
iscekic Apr 29, 2026
822d327
chore(kilo-chat): add NOTIFICATIONS service binding
iscekic Apr 29, 2026
372f0a0
feat(kilo-chat): publish push on message.created via NOTIFICATIONS RPC
iscekic Apr 29, 2026
52fe8a6
chore(notifications): drop orphan stream-chat dep, refresh worker typ…
iscekic Apr 29, 2026
4e95291
fix(notifications): named entrypoint export, retry-safe badge, alarm-…
iscekic Apr 29, 2026
4faf0dd
fix(notifications): close two cleanup-alarm leaks
iscekic Apr 29, 2026
8d7b9d7
refactor(event-service): compose presence contexts from kiloclaw helpers
iscekic Apr 29, 2026
893b7f1
feat(web): add kiloChat.getToken tRPC procedure
iscekic Apr 29, 2026
a35c98c
refactor(web): use kiloclaw-context helpers for event subscriptions
iscekic Apr 29, 2026
a43585d
feat(web): lift EventServiceClient to global provider
iscekic Apr 29, 2026
e98f370
feat(web): add usePresenceSubscription primitive
iscekic Apr 29, 2026
6bfbf95
refactor(web): collapse kilo-chat event subscriptions into usePresenc…
iscekic Apr 29, 2026
832e2b7
feat(web): subscribe to /presence/web while tab is visible
iscekic Apr 29, 2026
99b52d5
feat(web): subscribe to /presence/kiloclaw/{sandboxId} on instance views
iscekic Apr 29, 2026
bdb99c6
refactor(web): extract useDocumentVisible primitive
iscekic Apr 29, 2026
405b185
feat(web): subscribe to conversation presence while tab visible
iscekic Apr 29, 2026
4429bdf
style(web): reflow useDocumentVisible useState init to one line
iscekic Apr 29, 2026
eca983e
refactor(web): tighten presence hook + kilo-chat router contract
iscekic Apr 29, 2026
7edca1a
fix(event-service): refcount subscribe/unsubscribe by context
iscekic Apr 29, 2026
67e0fe3
chore(mobile): add EXPO_PUBLIC_KILO_CHAT_URL and EXPO_PUBLIC_EVENT_SE…
iscekic Apr 29, 2026
7b2d7fa
chore(mobile): add kilo-chat workspace deps
iscekic Apr 29, 2026
0735765
feat(mobile): add kilo-chat token getter with caching
iscekic Apr 29, 2026
4294250
feat(mobile): add useCurrentUserId from JWT sub
iscekic Apr 29, 2026
4081c29
feat(mobile): add KiloChatProvider
iscekic Apr 29, 2026
57448bd
feat(mobile): add useKiloChatClient and useEventServiceClient hooks
iscekic Apr 29, 2026
257f381
fix(mobile): fix lint errors in kilo-chat token getter
iscekic Apr 29, 2026
5844aaf
fix(mobile): fix lint errors in useCurrentUserId hook
iscekic Apr 29, 2026
825d1ac
fix(mobile): fix lint errors in useKiloChatClient hook
iscekic Apr 29, 2026
fe060dd
feat(mobile): mount KiloChatProvider in (app) layout
iscekic Apr 29, 2026
029c69a
fix(kilo-chat): assert non-null in base64urlEncode loop
iscekic Apr 29, 2026
f1eb38c
fix(mobile): share kilo-chat token cache + handle fetch errors
iscekic Apr 29, 2026
ecf29a1
fix(mobile): tie kilo-chat token cache to auth token, decode kiloUserId
iscekic Apr 30, 2026
d73befb
fix(mobile): read auth token at call time, not at hook render
iscekic Apr 30, 2026
b89c4d9
feat(mobile): add usePresenceSubscription primitive
iscekic Apr 30, 2026
87a74ed
feat(mobile): subscribe to /presence/app while app is active
iscekic Apr 30, 2026
7e20f1c
feat(mobile): add useInstancePresence hook
iscekic Apr 30, 2026
6d4e6c2
feat(mobile): add useConversationPresence hook
iscekic Apr 30, 2026
4898f43
fix(mobile): fix lint errors in presence hooks
iscekic Apr 30, 2026
1a6b241
feat(mobile): add useEventSubscription primitive
iscekic Apr 30, 2026
f0563e8
feat(mobile): add useInstanceEventSubscription
iscekic Apr 30, 2026
b939c3f
fix(mobile): apply curly/switch-case-braces lint rules to event hooks
iscekic Apr 30, 2026
d40b216
feat(kilo-chat-hooks): create shared package; extract useConversations
iscekic Apr 30, 2026
c829254
feat(kilo-chat-hooks): extract useMessages — base query + optimistic …
iscekic Apr 30, 2026
aa560af
feat(kilo-chat-hooks): useMessages adds edit/delete/react mutations
iscekic Apr 30, 2026
1dd065a
feat(kilo-chat-hooks): extract useMessageCacheUpdater into shared pac…
iscekic Apr 30, 2026
ad591d9
feat(mobile): wire shared kilo-chat-hooks + platform adapters
iscekic Apr 30, 2026
66713ba
fix(kilo-chat-hooks): centralize query keys; tighten event-subscripti…
iscekic Apr 30, 2026
ffeb4b6
fix(mobile): subscribe to conversation.* events on instance context
iscekic Apr 30, 2026
c259c95
chore(mobile): add @shopify/flash-list dependency
iscekic Apr 30, 2026
41bb565
chore(mobile): add EXPO_PUBLIC_KILO_CHAT_URL and EXPO_PUBLIC_EVENT_SE…
iscekic Apr 30, 2026
5fd8c69
feat(mobile): add EmptyConversationList
iscekic Apr 30, 2026
a4c1b99
feat(mobile): add ConversationHeader
iscekic Apr 30, 2026
e3b7d04
feat(mobile): add TypingIndicator placeholder
iscekic Apr 30, 2026
0f910d6
feat(mobile): add MessageInput
iscekic Apr 30, 2026
682e87b
feat(mobile): add MessageBubble
iscekic Apr 30, 2026
a0f8c84
feat(mobile): add MessageList
iscekic Apr 30, 2026
497613a
feat(mobile): add ConversationScreen
iscekic Apr 30, 2026
0d78ce7
feat(mobile): add ConversationListScreen
iscekic Apr 30, 2026
1bf1b34
fix(mobile): address review feedback on kilo-chat components
iscekic Apr 30, 2026
ce577c4
feat(mobile): add chat sandbox stack layout
iscekic Apr 30, 2026
a25a8df
feat(mobile): add conversation list route
iscekic Apr 30, 2026
4ed5cb8
feat(mobile): add conversation message route
iscekic Apr 30, 2026
381ad05
feat(mobile): wire chat deep links and active-conversation suppression
iscekic Apr 30, 2026
d4e68cc
fix(mobile): clear correct badge bucket on legacy chat foreground push
iscekic Apr 30, 2026
3fe7cd8
Merge remote-tracking branch 'origin/feat/kilo-chat-migration-pr1' in…
iscekic Apr 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
20 changes: 20 additions & 0 deletions apps/mobile/src/app/(app)/chat/[sandbox-id]/[conversation-id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useLocalSearchParams } from 'expo-router';

import { ConversationScreen } from '@/components/kilo-chat/conversation-screen';
import { useConversationDetail } from '@/components/kilo-chat/hooks/use-conversations';
import { useKiloChatClient } from '@/components/kilo-chat/hooks/use-kilo-chat-client';

export default function ChatConversationRoute() {
const params = useLocalSearchParams<{ 'sandbox-id': string; 'conversation-id': string }>();
const sandboxId = params['sandbox-id'];
const conversationId = params['conversation-id'];
const client = useKiloChatClient();
const { data } = useConversationDetail(client, conversationId);
return (
<ConversationScreen
sandboxId={sandboxId}
conversationId={conversationId}
conversationTitle={data?.title ?? 'Untitled'}
/>
);
}
5 changes: 5 additions & 0 deletions apps/mobile/src/app/(app)/chat/[sandbox-id]/_layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Stack } from 'expo-router';

export default function ChatSandboxLayout() {
return <Stack screenOptions={{ headerShown: false }} />;
}
11 changes: 11 additions & 0 deletions apps/mobile/src/app/(app)/chat/[sandbox-id]/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useLocalSearchParams } from 'expo-router';

import { ConversationListScreen } from '@/components/kilo-chat/conversation-list-screen';
import { useAllKiloClawInstances } from '@/lib/hooks/use-instance-context';

export default function ChatSandboxIndex() {
const { 'sandbox-id': sandboxId } = useLocalSearchParams<{ 'sandbox-id': string }>();
const { data: instances } = useAllKiloClawInstances();
const sandboxLabel = instances?.find(i => i.sandboxId === sandboxId)?.name ?? 'Chat';
return <ConversationListScreen sandboxId={sandboxId} sandboxLabel={sandboxLabel} />;
}
6 changes: 5 additions & 1 deletion apps/mobile/src/components/kilo-chat/conversation-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useKiloChatClient } from './hooks/use-kilo-chat-client';
import { useMarkRead } from './hooks/use-mark-read';
import { useMessages, useSendMessage } from './hooks/use-messages';
import { useCurrentUserId } from './hooks/use-current-user-id';
import { setActiveChatLocation } from '@/lib/notifications';

type Props = { sandboxId: string; conversationId: string; conversationTitle: string };

Expand Down Expand Up @@ -46,7 +47,10 @@ export function ConversationScreen({ sandboxId, conversationId, conversationTitl
useFocusEffect(
useCallback(() => {
markRead(sandboxId, conversationId);
// Active-conversation suppression wiring added in PR 5d (Task 50).
setActiveChatLocation({ sandboxId, conversationId });
return () => {
setActiveChatLocation(null);
};
}, [sandboxId, conversationId, markRead])
);

Expand Down
16 changes: 7 additions & 9 deletions apps/mobile/src/components/kiloclaw/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { type Channel as StreamChannel, StreamChat } from 'stream-chat';
import { Channel, Chat, MessageInput, MessageList, OverlayProvider } from 'stream-chat-expo';
import { toast } from 'sonner-native';

import { badgeBucketForConversation } from '@kilocode/notifications';

import { KiloClawMessageAvatar } from '@/components/kiloclaw/chat-avatar';
import { ChatPlaceholder } from '@/components/kiloclaw/chat-placeholder';
import { ChatHeader, ChatShell } from '@/components/kiloclaw/chat-shell';
Expand All @@ -19,11 +21,7 @@ import { badgeBucketForInstance } from '@/lib/badge-buckets';
import { useAppLifecycle } from '@/lib/hooks/use-app-lifecycle';
import { useStreamChatCredentials } from '@/lib/hooks/use-kiloclaw-queries';
import { setLastActiveInstance } from '@/lib/last-active-instance';
import {
getNotificationSandboxId,
parseNotificationData,
setActiveChatInstance,
} from '@/lib/notifications';
import { parseNotificationData } from '@/lib/notifications';
import { useTRPC } from '@/lib/trpc';

type KiloClawChatProps = {
Expand Down Expand Up @@ -78,7 +76,6 @@ export function KiloClawChat({
useCallback(() => {
const badgeBucket = badgeBucketForInstance(instanceId);
isFocusedRef.current = true;
setActiveChatInstance(instanceId);
setLastActiveInstance(instanceId);
markChatRead({ badgeBucket });

Expand All @@ -87,14 +84,15 @@ export function KiloClawChat({
// it immediately so the badge never drifts above 0 while the user is reading.
const subscription = Notifications.addNotificationReceivedListener(notification => {
const data = parseNotificationData(notification.request.content.data);
if (data && getNotificationSandboxId(data) === instanceId) {
markChatRead({ badgeBucket });
if (data?.type === 'chat.message' && data.sandboxId === instanceId) {
markChatRead({
badgeBucket: badgeBucketForConversation(data.sandboxId, data.conversationId),
});
}
});

return () => {
isFocusedRef.current = false;
setActiveChatInstance(null);
subscription.remove();
};
}, [instanceId, markChatRead])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function useUnreadCountsInvalidation() {

const received = Notifications.addNotificationReceivedListener(notification => {
const data = parseNotificationData(notification.request.content.data);
if (data?.type === 'chat') {
if (data?.type === 'chat.message') {
invalidate();
}
});
Expand Down
49 changes: 18 additions & 31 deletions apps/mobile/src/lib/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import expoConstants from 'expo-constants';
import * as Notifications from 'expo-notifications';
import { type Href, router } from 'expo-router';
import { Platform } from 'react-native';
import { z } from 'zod';

import { pushDataSchema } from '@kilocode/notifications';

function getProjectId(): string {
const eas = expoConstants.expoConfig?.extra?.eas as { projectId?: string } | undefined;
Expand All @@ -13,44 +14,27 @@ function getProjectId(): string {
return projectId;
}

// Tracks which chat instance screen is currently focused.
// Tracks which conversation screen is currently focused.
// Read by the foreground notification handler to suppress notifications
// when the user is already viewing that chat.
// when the user is already viewing that conversation.
// A module-level variable (not React state) because the notification handler
// is registered once and must always read the latest value without stale closures.
let activeChatInstanceId: string | null = null;
let activeChatLocation: { sandboxId: string; conversationId: string } | null = null;

export function setActiveChatInstance(instanceId: string | null) {
activeChatInstanceId = instanceId;
export function setActiveChatLocation(
location: { sandboxId: string; conversationId: string } | null
) {
activeChatLocation = location;
}

const notificationDataSchema = z.discriminatedUnion('type', [
z.object({
type: z.literal('chat'),
instanceId: z.string().min(1),
}),
z.object({
type: z.literal('chat.message'),
sandboxId: z.string().min(1),
conversationId: z.string().min(1),
messageId: z.string().min(1),
}),
]);

type NotificationData = z.infer<typeof notificationDataSchema>;

// Runtime-validates that an arbitrary notification `data` payload matches the
// shape we care about. Push producers can evolve independently of the app, so
// always parse before reading fields from the OS-provided notification content.
export function parseNotificationData(data: unknown): NotificationData | null {
const parsed = notificationDataSchema.safeParse(data);
export function parseNotificationData(data: unknown) {
const parsed = pushDataSchema.safeParse(data);
return parsed.success ? parsed.data : null;
}

export function getNotificationSandboxId(data: NotificationData): string {
return data.type === 'chat' ? data.instanceId : data.sandboxId;
}

const shown = {
shouldShowAlert: true,
shouldPlaySound: true,
Expand All @@ -73,8 +57,11 @@ export function setupNotificationHandler() {
handleNotification: async notification => {
const data = parseNotificationData(notification.request.content.data);

// Suppress only if the user is already viewing this exact chat
if (data && getNotificationSandboxId(data) === activeChatInstanceId) {
if (
data?.type === 'chat.message' &&
activeChatLocation?.sandboxId === data.sandboxId &&
activeChatLocation.conversationId === data.conversationId
) {
return suppressed;
}

Expand All @@ -98,7 +85,7 @@ export function setupNotificationResponseHandler() {
const data = parseNotificationData(response.notification.request.content.data);

if (data) {
const path = `/(app)/chat/${getNotificationSandboxId(data)}`;
const path = `/(app)/chat/${data.sandboxId}/${data.conversationId}`;
// If the router is ready (has segments), navigate immediately.
// Otherwise store as pending for consumption after auth completes.
try {
Expand All @@ -120,7 +107,7 @@ export function checkInitialNotification(): void {
}
const data = parseNotificationData(response.notification.request.content.data);
if (data) {
pendingNotificationLink = `/(app)/chat/${getNotificationSandboxId(data)}`;
pendingNotificationLink = `/(app)/chat/${data.sandboxId}/${data.conversationId}`;
}
}

Expand Down
2 changes: 0 additions & 2 deletions packages/notifications/src/badge-buckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@
* don't collide as more surfaces start emitting badge updates.
*/

export const badgeBucketForInstance = (sandboxId: string) => `kiloclaw:${sandboxId}` as const;

export const badgeBucketForConversation = (sandboxId: string, conversationId: string) =>
`kiloclaw:${sandboxId}:${conversationId}` as const;