Skip to content

Commit 203e308

Browse files
committed
fix(scheduled-tasks): seed task contexts instead of clobbering auto-mentions
Cursor (Medium): the mount-only `setContexts(task.contexts)` replaced the editor's context list AFTER the chipify pass had already registered the prompt's integration `@`-mentions and `/`-skills, so a task with any stored resource context lost its integration/skill chip overlay. Thread an `initialContexts` option through `usePromptEditor` (into the context manager's existing `initialContexts` seed) and seed the task's stored contexts there. The mount chipify pass then MERGES integration and skill contexts on top of the seed (deduped), so the overlay renders the full set — resources from the seed, integrations/skills from the text.
1 parent 94a2bb1 commit 203e308

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/use-prompt-editor.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ export interface UsePromptEditorProps {
104104
workspaceId: string
105105
/** Initial text. Chipified (`@`-mentions / `/`-skills converted) on mount. */
106106
initialValue?: string
107+
/**
108+
* Contexts to seed the editor with — restored resource mentions (files,
109+
* tables, knowledge) that cannot be recovered from the prompt text alone.
110+
* Seed these rather than calling `setContexts` after mount: the mount
111+
* chipify pass MERGES integration `@`-mentions and `/`-skills on top, so a
112+
* post-mount `setContexts` would clobber those auto-registered contexts.
113+
*/
114+
initialContexts?: ChatContext[]
107115
/**
108116
* Notified when a context is added through an interactive path — a mention
109117
* pick, a resource drop, or a skill pick. Paste re-registration is
@@ -142,6 +150,7 @@ export type PromptEditorInstance = ReturnType<typeof usePromptEditor>
142150
export function usePromptEditor({
143151
workspaceId,
144152
initialValue = '',
153+
initialContexts,
145154
onContextAdd,
146155
onPasteFiles,
147156
}: UsePromptEditorProps) {
@@ -170,7 +179,7 @@ export function usePromptEditor({
170179
const slashRangeRef = useRef<{ start: number; end: number } | null>(null)
171180
const [slashQuery, setSlashQuery] = useState<string | null>(null)
172181

173-
const contextManagement = useContextManagement({ message: value })
182+
const contextManagement = useContextManagement({ message: value, initialContexts })
174183
const contextManagementRef = useRef(contextManagement)
175184
contextManagementRef.current = contextManagement
176185

apps/sim/app/workspace/[workspaceId]/scheduled-tasks/components/task-details-modal/task-details-modal.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use client'
22

3-
import { useEffect } from 'react'
43
import { format } from 'date-fns'
54
import { useParams } from 'next/navigation'
65
import {
@@ -70,19 +69,19 @@ export function TaskDetailsModal({ task, onClose }: TaskDetailsModalProps) {
7069
*/
7170
function TaskDetailsContent({ task, onClose }: { task: ScheduledTask; onClose: () => void }) {
7271
const { workspaceId } = useParams<{ workspaceId: string }>()
73-
const editor = usePromptEditor({ workspaceId, initialValue: task.prompt })
74-
const setContexts = editor.setContexts
75-
7672
/**
77-
* Re-registers the task's stored `@`-mentions once on open so resource chips
78-
* (files, tables, knowledge) render. Integration `@`-mentions and `/`-skills
79-
* chipify from the seeded text alone, so they render even without stored
80-
* contexts. Runs once per open since the content remounts each time it opens.
73+
* Seed the stored resource mentions (files, tables, knowledge) as the editor's
74+
* initial contexts — these can't be recovered from the prompt text alone. The
75+
* mount chipify pass then merges integration `@`-mentions and `/`-skills on top
76+
* (they DO chipify from text), so the overlay renders the full set. Seeding is
77+
* deliberate over a post-mount `setContexts`, which would clobber the
78+
* auto-registered integration/skill contexts.
8179
*/
82-
useEffect(() => {
83-
if (task.contexts && task.contexts.length > 0) setContexts(task.contexts)
84-
// eslint-disable-next-line react-hooks/exhaustive-deps -- mount-only re-register
85-
}, [])
80+
const editor = usePromptEditor({
81+
workspaceId,
82+
initialValue: task.prompt,
83+
initialContexts: task.contexts,
84+
})
8685

8786
return (
8887
<>

0 commit comments

Comments
 (0)