From b263433a6b264743bd79e1cafff949ee2a7d5c2c Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Feb 2026 22:44:28 +0000 Subject: [PATCH] Add writing description input to AI sidebar for participant intent context Adds a textarea at the top of the AIPanel where participants can describe what they're trying to write (e.g., "telling him we need to move the panel we'd scheduled for tomorrow"). This description is sent to the API and injected into all AI condition prompts as a "Writer's Intent" section, giving the model better context for generating suggestions. The description is also included in study event logs. https://claude.ai/code/session_01BeEBSzBFysATTNMFbRtPWq --- experiment/app/api/writing-support/route.ts | 6 ++++++ experiment/components/AIPanel.tsx | 21 +++++++++++++++++++-- experiment/types/index.ts | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/experiment/app/api/writing-support/route.ts b/experiment/app/api/writing-support/route.ts index b1a3557c..39f3bcc4 100644 --- a/experiment/app/api/writing-support/route.ts +++ b/experiment/app/api/writing-support/route.ts @@ -69,6 +69,7 @@ export async function POST(req: Request) { const { beforeCursor, selectedText, afterCursor } = body.editorState; const context = (body.context as keyof typeof prompts) || 'proposal_advice'; + const writingDescription = body.writingDescription; const promptTemplate = prompts[context]; try { @@ -77,6 +78,11 @@ export async function POST(req: Request) { const afterCursorTrim = afterCursor.slice(0, 100); let fullPrompt = promptTemplate; + + if (writingDescription) { + fullPrompt += `\n\n# Writer's Intent\n\nThe writer has described what they are trying to write: "${writingDescription}"`; + } + fullPrompt += `\n\n# Writer's Document So Far\n\n\n${documentText}\n\n`; if (selectedText === '') { diff --git a/experiment/components/AIPanel.tsx b/experiment/components/AIPanel.tsx index c2fb8d7b..b358942e 100644 --- a/experiment/components/AIPanel.tsx +++ b/experiment/components/AIPanel.tsx @@ -87,6 +87,7 @@ export default function AIPanel({ const [isLoading, setIsLoading] = useState(false); const [savedItems, setSavedItems] = useState([]); const [errorMsg, setErrorMsg] = useState(''); + const [writingDescription, setWritingDescription] = useState(''); const docContextRef = useRef(null); const studyParams = useAtomValue(studyParamsAtom); const studyCondition = useAtomValue(studyConditionAtom); @@ -161,6 +162,7 @@ export default function AIPanel({ event: `aiRequest:${modeToUse}`, extra_data: { isAutoRefresh, + writingDescription: writingDescription.trim() || undefined, // Don't log document content right now; we'll log it with the response }, }); @@ -174,6 +176,7 @@ export default function AIPanel({ body: JSON.stringify({ editorState, context: modeToUse, + ...(writingDescription.trim() && { writingDescription: writingDescription.trim() }), }), signal: AbortSignal.timeout(API_TIMEOUT_MS), }); @@ -207,7 +210,7 @@ export default function AIPanel({ await log({ username: studyParams.username, event: `aiResponse:${modeToUse}`, - extra_data: { isAutoRefresh, generation, editorState }, + extra_data: { isAutoRefresh, generation, editorState, writingDescription: writingDescription.trim() || undefined }, }); } } @@ -230,7 +233,7 @@ export default function AIPanel({ setIsLoading(false); } }, - [writingAreaRef, save, mode, isStudyMode, studyParams] + [writingAreaRef, save, mode, isStudyMode, studyParams, writingDescription] ); // Auto-refresh logic for study mode @@ -289,6 +292,20 @@ export default function AIPanel({

AI Writing Assistant

+
+ +