MCPcopy
hub / github.com/docker/docker-agent / createSessionSpawner

Method createSessionSpawner

cmd/root/run.go:1038–1097  ·  view source on GitHub ↗

createSessionSpawner creates a function that can spawn new sessions with different working directories.

(agentSource config.Source, sessStore session.Store)

Source from the content-addressed store, hash-verified

1036
1037// createSessionSpawner creates a function that can spawn new sessions with different working directories.
1038func (f *runExecFlags) createSessionSpawner(agentSource config.Source, sessStore session.Store) tui.SessionSpawner {
1039 return func(spawnCtx context.Context, workingDir string) (*app.App, *session.Session, func(), error) {
1040 // Create a copy of the runtime config with the new working directory
1041 runConfigCopy := f.runConfig.Clone()
1042 runConfigCopy.WorkingDir = workingDir
1043
1044 // Load team with the new working directory, honouring every flag the
1045 // initial load already honours (model overrides AND prompt files).
1046 loadReq := f.loadTeamRequest(agentSource)
1047 loadReq.RunConfig = runConfigCopy
1048 loadResult, err := f.loadAgentFrom(spawnCtx, loadReq)
1049 if err != nil {
1050 return nil, nil, nil, err
1051 }
1052
1053 t := loadResult.Team
1054 agt, err := t.AgentOrDefault(f.agentName)
1055 if err != nil {
1056 return nil, nil, nil, err
1057 }
1058
1059 // Merge global permissions into the team's checker
1060 if f.globalPermissions != nil && !f.globalPermissions.IsEmpty() {
1061 t.SetPermissions(permissions.Merge(t.Permissions(), f.globalPermissions))
1062 }
1063
1064 rtOpts, ctrl, err := f.snapshotRuntimeOpts()
1065 if err != nil {
1066 return nil, nil, nil, err
1067 }
1068 runtimeOpts := append(f.runtimeOpts(loadResult, runConfigCopy, sessStore, agt.Name()), rtOpts...)
1069 localRt, err := runtime.New(spawnCtx, t, runtimeOpts...)
1070 if err != nil {
1071 return nil, nil, nil, err
1072 }
1073
1074 // Create a new session
1075 spawnReq := f.createSessionRequest(workingDir)
1076 spawnReq.AgentName = agt.Name()
1077 newSess := session.New(f.buildSessionOpts(agt, spawnReq)...)
1078
1079 // Create cleanup function
1080 cleanup := func() {
1081 stopToolSets(spawnCtx, t)
1082 }
1083
1084 // Create the app
1085 var appOpts []app.Opt
1086 if gen := localRt.TitleGenerator(spawnCtx); gen != nil {
1087 appOpts = append(appOpts, app.WithTitleGenerator(gen))
1088 }
1089 if ctrl != nil {
1090 appOpts = append(appOpts, app.WithSnapshotController(ctrl))
1091 }
1092
1093 a := app.New(spawnCtx, localRt, newSess, appOpts...)
1094
1095 return a, newSess, cleanup, nil

Callers 1

SpawnerMethod · 0.80

Calls 15

loadTeamRequestMethod · 0.95
loadAgentFromMethod · 0.95
snapshotRuntimeOptsMethod · 0.95
runtimeOptsMethod · 0.95
createSessionRequestMethod · 0.95
buildSessionOptsMethod · 0.95
MergeFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
WithTitleGeneratorFunction · 0.92
WithSnapshotControllerFunction · 0.92
NewFunction · 0.92

Tested by

no test coverage detected