( onDone: LocalJSXCommandOnDone, context: LocalJSXCommandContext, args: string, )
| 220 | } |
| 221 | |
| 222 | export async function call( |
| 223 | onDone: LocalJSXCommandOnDone, |
| 224 | context: LocalJSXCommandContext, |
| 225 | args: string, |
| 226 | ): Promise<React.ReactNode> { |
| 227 | const customTitle = args?.trim() || undefined |
| 228 | |
| 229 | const originalSessionId = getSessionId() |
| 230 | |
| 231 | try { |
| 232 | const { |
| 233 | sessionId, |
| 234 | title, |
| 235 | forkPath, |
| 236 | serializedMessages, |
| 237 | contentReplacementRecords, |
| 238 | } = await createFork(customTitle) |
| 239 | |
| 240 | // Build LogOption for resume |
| 241 | const now = new Date() |
| 242 | const firstPrompt = deriveFirstPrompt( |
| 243 | serializedMessages.find(m => m.type === 'user'), |
| 244 | ) |
| 245 | |
| 246 | // Save custom title - use provided title or firstPrompt as default |
| 247 | // This ensures /status and /resume show the same session name |
| 248 | // Always add " (Branch)" suffix to make it clear this is a branched session |
| 249 | // Handle collisions by adding a number suffix (e.g., " (Branch 2)", " (Branch 3)") |
| 250 | const baseName = title ?? firstPrompt |
| 251 | const effectiveTitle = await getUniqueForkName(baseName) |
| 252 | await saveCustomTitle(sessionId, effectiveTitle, forkPath) |
| 253 | |
| 254 | logEvent('tengu_conversation_forked', { |
| 255 | message_count: serializedMessages.length, |
| 256 | has_custom_title: !!title, |
| 257 | }) |
| 258 | |
| 259 | const forkLog: LogOption = { |
| 260 | date: now.toISOString().split('T')[0]!, |
| 261 | messages: serializedMessages, |
| 262 | fullPath: forkPath, |
| 263 | value: now.getTime(), |
| 264 | created: now, |
| 265 | modified: now, |
| 266 | firstPrompt, |
| 267 | messageCount: serializedMessages.length, |
| 268 | isSidechain: false, |
| 269 | sessionId, |
| 270 | customTitle: effectiveTitle, |
| 271 | contentReplacements: contentReplacementRecords, |
| 272 | } |
| 273 | |
| 274 | // Resume into the fork |
| 275 | const titleInfo = title ? ` "${title}"` : '' |
| 276 | const resumeHint = `\nTo resume the original: claude -r ${originalSessionId}` |
| 277 | const successMessage = `Branched conversation${titleInfo}. You are now in the branch.${resumeHint}` |
| 278 | |
| 279 | if (context.resume) { |
nothing calls this directly
no test coverage detected