( message: string, conversationContext?: string, latestUserMessage?: string )
| 144 | * - title: Human-readable description (e.g., "Fix plan mode over SSH") |
| 145 | */ |
| 146 | export function buildWorkspaceIdentityPrompt( |
| 147 | message: string, |
| 148 | conversationContext?: string, |
| 149 | latestUserMessage?: string |
| 150 | ): string { |
| 151 | const promptSections: string[] = [`Primary user objective: "${message}"`]; |
| 152 | |
| 153 | const trimmedConversationContext = conversationContext?.trim(); |
| 154 | if (trimmedConversationContext && trimmedConversationContext.length > 0) { |
| 155 | promptSections.push( |
| 156 | `Conversation turns (chronological sample):\n${trimmedConversationContext.slice(0, 6_000)}` |
| 157 | ); |
| 158 | |
| 159 | const normalizedLatestUserMessage = latestUserMessage?.replace(/\s+/g, " ").trim(); |
| 160 | if (normalizedLatestUserMessage) { |
| 161 | promptSections.push( |
| 162 | `Most recent user message (extra context; do not prefer it over earlier turns): "${normalizedLatestUserMessage.slice(0, 1_000)}"` |
| 163 | ); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Prompt wording is tuned for short UI titles that stay accurate over the whole chat, |
| 168 | // rather than over-indexing on whichever message happened most recently. |
| 169 | return [ |
| 170 | "Generate a workspace name and title for this development task:\n\n", |
| 171 | `${promptSections.join("\n\n")}\n\n`, |
| 172 | "Requirements:\n", |
| 173 | '- name: The area of the codebase being worked on (1-2 words, max 15 chars, git-safe: lowercase, hyphens only). Random bytes will be appended for uniqueness, so focus on the area not the specific task. Examples: "sidebar", "auth", "config", "api"\n', |
| 174 | '- title: 2-5 words, verb-noun format, describing the primary deliverable (what will be different when the work is done). Examples: "Fix plan mode", "Add user authentication", "Refactor sidebar layout"\n', |
| 175 | '- title quality: Be specific about the feature/system being changed. Prefer concrete nouns; avoid vague words ("stuff", "things"), self-referential meta phrases ("this chat", "this conversation", "regenerate title"), and temporal words ("latest", "recent", "today", "now").\n', |
| 176 | "- title scope: Choose the title that best represents the overall scope and goal across the entire conversation. Weigh all turns equally — do not favor the most recent message over earlier ones.\n", |
| 177 | "- title style: Sentence case, no punctuation, no quotes.\n", |
| 178 | ].join(""); |
| 179 | } |
| 180 | |
| 181 | export async function generateWorkspaceIdentity( |
| 182 | message: string, |
no test coverage detected