* Generates a title and branch name for a coding session using Claude Haiku * @param description The description/prompt for the session * @returns Promise The generated title and branch name
(description: string, signal: AbortSignal)
| 100 | * @returns Promise<TitleAndBranch> The generated title and branch name |
| 101 | */ |
| 102 | async function generateTitleAndBranch(description: string, signal: AbortSignal): Promise<TitleAndBranch> { |
| 103 | const fallbackTitle = truncateToWidth(description, 75); |
| 104 | const fallbackBranch = 'claude/task'; |
| 105 | try { |
| 106 | const userPrompt = SESSION_TITLE_AND_BRANCH_PROMPT.replace('{description}', description); |
| 107 | const response = await queryHaiku({ |
| 108 | systemPrompt: asSystemPrompt([]), |
| 109 | userPrompt, |
| 110 | outputFormat: { |
| 111 | type: 'json_schema', |
| 112 | schema: { |
| 113 | type: 'object', |
| 114 | properties: { |
| 115 | title: { |
| 116 | type: 'string' |
| 117 | }, |
| 118 | branch: { |
| 119 | type: 'string' |
| 120 | } |
| 121 | }, |
| 122 | required: ['title', 'branch'], |
| 123 | additionalProperties: false |
| 124 | } |
| 125 | }, |
| 126 | signal, |
| 127 | options: { |
| 128 | querySource: 'teleport_generate_title', |
| 129 | agents: [], |
| 130 | isNonInteractiveSession: false, |
| 131 | hasAppendSystemPrompt: false, |
| 132 | mcpTools: [] |
| 133 | } |
| 134 | }); |
| 135 | |
| 136 | // Extract text from the response |
| 137 | const firstBlock = response.message.content[0]; |
| 138 | if (firstBlock?.type !== 'text') { |
| 139 | return { |
| 140 | title: fallbackTitle, |
| 141 | branchName: fallbackBranch |
| 142 | }; |
| 143 | } |
| 144 | const parsed = safeParseJSON(firstBlock.text.trim()); |
| 145 | const parseResult = z.object({ |
| 146 | title: z.string(), |
| 147 | branch: z.string() |
| 148 | }).safeParse(parsed); |
| 149 | if (parseResult.success) { |
| 150 | return { |
| 151 | title: parseResult.data.title || fallbackTitle, |
| 152 | branchName: parseResult.data.branch || fallbackBranch |
| 153 | }; |
| 154 | } |
| 155 | return { |
| 156 | title: fallbackTitle, |
| 157 | branchName: fallbackBranch |
| 158 | }; |
| 159 | } catch (error) { |
no test coverage detected