MCPcopy Index your code
hub / github.com/docker/docker-agent / dispatchWorktreeCreate

Method dispatchWorktreeCreate

cmd/root/run.go:685–724  ·  view source on GitHub ↗

dispatchWorktreeCreate fires the worktree_create hooks of the agent the run targets, just after the worktree is created and before the session exists. Unlike every other event, this is dispatched from the CLI rather than the run loop: the worktree (and the working directory the runtime, session, too

(ctx context.Context, out *cli.Printer, t *team.Team, wt *worktree.Worktree)

Source from the content-addressed store, hash-verified

683// Hooks run inside the new worktree so setup commands (copy .env, install
684// deps) operate on the fresh checkout. A blocking verdict aborts the run.
685func (f *runExecFlags) dispatchWorktreeCreate(ctx context.Context, out *cli.Printer, t *team.Team, wt *worktree.Worktree) error {
686 agt, err := t.AgentOrDefault(f.agentName)
687 if err != nil {
688 return err
689 }
690 hooksCfg := agt.Hooks()
691 if hooksCfg == nil {
692 return nil
693 }
694
695 executor := hooks.NewExecutor(hooksCfg, wt.Dir, os.Environ())
696 if !executor.Has(hooks.EventWorktreeCreate) {
697 return nil
698 }
699
700 result, err := executor.Dispatch(ctx, hooks.EventWorktreeCreate, &hooks.Input{
701 AgentName: agt.Name(),
702 Cwd: wt.Dir,
703 WorktreePath: wt.Dir,
704 WorktreeBranch: wt.Branch,
705 WorktreeSourceDir: wt.SourceDir,
706 })
707 if err != nil {
708 return fmt.Errorf("running worktree_create hooks: %w", err)
709 }
710 if result.SystemMessage != "" {
711 out.Println(result.SystemMessage)
712 }
713 if result.AdditionalContext != "" {
714 out.Println(result.AdditionalContext)
715 }
716 if !result.Allowed {
717 msg := result.Message
718 if msg == "" {
719 msg = "a worktree_create hook blocked the run"
720 }
721 return fmt.Errorf("worktree_create hook aborted the run: %s", msg)
722 }
723 return nil
724}
725
726func (f *runExecFlags) loadAgentFrom(ctx context.Context, req runtime.LoadTeamRequest) (*teamloader.LoadResult, error) {
727 opts := append(loaderdefaults.Opts(), teamloader.WithModelOverrides(req.ModelOverrides))

Callers 1

runOrExecMethod · 0.95

Calls 7

HasMethod · 0.95
DispatchMethod · 0.95
NewExecutorFunction · 0.92
AgentOrDefaultMethod · 0.80
HooksMethod · 0.80
PrintlnMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected