(opts: {
blurb: string;
seedPlan?: string;
getAppState: () => AppState;
setAppState: (f: (prev: AppState) => AppState) => void;
signal: AbortSignal;
onSessionReady?: (msg: string) => void;
})
| 292 | return buildLaunchMessage(disconnectedBridge); |
| 293 | } |
| 294 | async function launchDetached(opts: { |
| 295 | blurb: string; |
| 296 | seedPlan?: string; |
| 297 | getAppState: () => AppState; |
| 298 | setAppState: (f: (prev: AppState) => AppState) => void; |
| 299 | signal: AbortSignal; |
| 300 | onSessionReady?: (msg: string) => void; |
| 301 | }): Promise<void> { |
| 302 | const { |
| 303 | blurb, |
| 304 | seedPlan, |
| 305 | getAppState, |
| 306 | setAppState, |
| 307 | signal, |
| 308 | onSessionReady |
| 309 | } = opts; |
| 310 | // Hoisted so the catch block can archive the remote session if an error |
| 311 | // occurs after teleportToRemote succeeds (avoids 30min orphan). |
| 312 | let sessionId: string | undefined; |
| 313 | try { |
| 314 | const model = getUltraplanModel(); |
| 315 | const eligibility = await checkRemoteAgentEligibility(); |
| 316 | if (!eligibility.eligible) { |
| 317 | logEvent('tengu_ultraplan_create_failed', { |
| 318 | reason: 'precondition' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 319 | precondition_errors: eligibility.errors.map(e => e.type).join(',') as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS |
| 320 | }); |
| 321 | const reasons = eligibility.errors.map(formatPreconditionError).join('\n'); |
| 322 | enqueuePendingNotification({ |
| 323 | value: `ultraplan: cannot launch remote session —\n${reasons}`, |
| 324 | mode: 'task-notification' |
| 325 | }); |
| 326 | return; |
| 327 | } |
| 328 | const prompt = buildUltraplanPrompt(blurb, seedPlan); |
| 329 | let bundleFailMsg: string | undefined; |
| 330 | const session = await teleportToRemote({ |
| 331 | initialMessage: prompt, |
| 332 | description: blurb || 'Refine local plan', |
| 333 | model, |
| 334 | permissionMode: 'plan', |
| 335 | ultraplan: true, |
| 336 | signal, |
| 337 | useDefaultEnvironment: true, |
| 338 | onBundleFail: msg => { |
| 339 | bundleFailMsg = msg; |
| 340 | } |
| 341 | }); |
| 342 | if (!session) { |
| 343 | logEvent('tengu_ultraplan_create_failed', { |
| 344 | reason: (bundleFailMsg ? 'bundle_fail' : 'teleport_null') as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS |
| 345 | }); |
| 346 | enqueuePendingNotification({ |
| 347 | value: `ultraplan: session creation failed${bundleFailMsg ? ` — ${bundleFailMsg}` : ''}. See --debug for details.`, |
| 348 | mode: 'task-notification' |
| 349 | }); |
| 350 | return; |
| 351 | } |
no test coverage detected