RunSkillFork dispatches a fork-mode skill in an isolated sub-session of the current parent. The parent gains a SubSession item once the runtime opens the child; the sub-session's first user message is the expanded SKILL.md body. Companion of SkillCommandFork.
(ctx context.Context, cancel context.CancelFunc, skillName, task string, _ []messages.Attachment)
| 345 | // opens the child; the sub-session's first user message is the expanded |
| 346 | // SKILL.md body. Companion of SkillCommandFork. |
| 347 | func (a *App) RunSkillFork(ctx context.Context, cancel context.CancelFunc, skillName, task string, _ []messages.Attachment) { |
| 348 | a.cancel = cancel |
| 349 | |
| 350 | // Mirrors App.Run's drain loop: forward events to the App bus and |
| 351 | // always let StreamStoppedEvent through, even after ctx cancellation, |
| 352 | // so the supervisor marks the session idle. |
| 353 | go func() { |
| 354 | events := make(chan runtime.Event, defaultRuntimeEventBuffer) |
| 355 | go func() { |
| 356 | defer close(events) |
| 357 | result, err := a.runtime.RunSkillFork(ctx, a.session, skillstool.RunSkillArgs{ |
| 358 | Name: skillName, |
| 359 | Task: task, |
| 360 | }, runtime.NewChannelSink(events)) |
| 361 | switch { |
| 362 | case errors.Is(err, runtime.ErrUnsupported): |
| 363 | slog.WarnContext(ctx, "Runtime does not support fork-mode skills; skill not executed", "skill", skillName) |
| 364 | a.sendEvent(ctx, runtime.Error(fmt.Sprintf("Skill %q cannot run: this runtime does not support fork-mode skills.", skillName))) |
| 365 | case err != nil: |
| 366 | slog.ErrorContext(ctx, "Failed to run fork-mode skill", "skill", skillName, "error", err) |
| 367 | a.sendEvent(ctx, runtime.Error(fmt.Sprintf("Skill %q failed: %v", skillName, err))) |
| 368 | case result != nil && result.IsError: |
| 369 | a.sendEvent(ctx, runtime.Error(result.Output)) |
| 370 | } |
| 371 | }() |
| 372 | |
| 373 | for event := range events { |
| 374 | if ctx.Err() != nil { |
| 375 | if _, ok := event.(*runtime.StreamStoppedEvent); ok { |
| 376 | // ctx is cancelled; detach cancellation but keep its trace |
| 377 | // context so the stop event still reaches subscribers. |
| 378 | a.sendEvent(context.WithoutCancel(ctx), event) |
| 379 | } |
| 380 | continue |
| 381 | } |
| 382 | a.sendEvent(ctx, event) |
| 383 | } |
| 384 | }() |
| 385 | } |
| 386 | |
| 387 | // defaultRuntimeEventBuffer matches Summarize and Runtime.RunStream; |
| 388 | // wide enough that a fork-skill sub-session won't block the producer. |
nothing calls this directly
no test coverage detected