Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/shared/src/analytics-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ export type ChannelsSurface =
| "sidebar"
| "command_menu"
| "new_task"
| "task_input"
| "channel_home"
| "channel_history"
| "channel_artifacts"
Expand Down
7 changes: 5 additions & 2 deletions packages/ui/src/features/canvas/hooks/useTaskChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ export function normalizeChannelName(name: string): string {
* folder "channels" stay on the desktop file system for CONTEXT.md and
* artifacts). Listing also lazily provisions the requester's #me channel.
*/
export function useTaskChannels(): {
export function useTaskChannels(options?: { enabled?: boolean }): {
channels: TaskChannel[];
personalChannel: TaskChannel | undefined;
isLoading: boolean;
} {
const query = useAuthenticatedQuery<TaskChannel[]>(
TASK_CHANNELS_QUERY_KEY,
(client) => client.getTaskChannels(),
{ refetchInterval: TASK_CHANNELS_POLL_INTERVAL_MS },
{
enabled: options?.enabled ?? true,
refetchInterval: TASK_CHANNELS_POLL_INTERVAL_MS,
},
);
const channels = useMemo(() => query.data ?? [], [query.data]);
const personalChannel = useMemo(
Expand Down
32 changes: 31 additions & 1 deletion packages/ui/src/features/task-detail/hooks/useTaskCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import { useHostTRPC, useHostTRPCClient } from "@posthog/host-router/react";
import {
type Adapter,
ANALYTICS_EVENTS,
PROJECT_BLUEBIRD_FLAG,
type TaskCreationInput,
type WorkspaceMode,
} from "@posthog/shared";
import type { ExecutionMode, Task } from "@posthog/shared/domain-types";
import { useTaskChannels } from "@posthog/ui/features/canvas/hooks/useTaskChannels";
import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";
import { useTaskInputPrefillStore } from "@posthog/ui/features/task-detail/stores/taskInputPrefillStore";
import { navigateToTaskPending } from "@posthog/ui/router/navigationBridge";
import { openTask, openTaskInput } from "@posthog/ui/router/useOpenTask";
Expand Down Expand Up @@ -201,6 +204,17 @@ export function useTaskCreation({
// Used to name the task occupying a branch's worktree when reuse is blocked.
const { data: tasks } = useTasks();

// Tasks created without a channel default into the user's private #me
// backend channel so they still surface in the Channels space instead of
// staying unfiled. The personal channel is per-user and provisioned lazily
// server-side on first list, so this can't collide across teammates. If it
// hasn't loaded yet the task is created unfiled, as before.
const bluebirdEnabled = useFeatureFlag(
PROJECT_BLUEBIRD_FLAG,
import.meta.env.DEV,
);
const { personalChannel } = useTaskChannels({ enabled: bluebirdEnabled });

const hasRequiredPath = allowNoRepo
? true
: workspaceMode === "cloud"
Expand Down Expand Up @@ -307,6 +321,11 @@ export function useTaskCreation({
}

const settings = useSettingsStore.getState();
const defaultedChannelId =
bluebirdEnabled && !channelId && !channelName
? personalChannel?.id
: undefined;

const input = prepareTaskInput(serializedContent, filePaths, {
// In channels chat-box mode no repo is attached up front, even if a
// directory/repo is lingering in the persisted picker state.
Expand All @@ -329,7 +348,7 @@ export function useTaskCreation({
additionalDirectories,
channelContext,
channelName,
channelId,
channelId: channelId ?? defaultedChannelId,
customInstructions: getEffectiveCustomInstructions(settings),
autoPublishCloudRuns: settings.autoPublishCloudRuns,
rtkEnabledCloud: settings.rtkEnabledCloud,
Expand Down Expand Up @@ -376,6 +395,15 @@ export function useTaskCreation({
if (!pendingTaskKey && !contentOverride) {
editor.clear();
}
if (defaultedChannelId) {
track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
action_type: "file_task",
surface: "task_input",
channel_id: defaultedChannelId,
task_id: output.task.id,
success: true,
});
}
onTaskCreatedEffect?.(output.task);
if (onTaskCreated) {
onTaskCreated(output.task);
Expand Down Expand Up @@ -493,6 +521,8 @@ export function useTaskCreation({
channelName,
channelId,
allowNoRepo,
bluebirdEnabled,
personalChannel?.id,
clearTaskInputReportAssociation,
invalidateTasks,
onTaskCreated,
Expand Down
Loading