createSessionSpawner creates a function that can spawn new sessions with different working directories.
(agentSource config.Source, sessStore session.Store)
| 1036 | |
| 1037 | // createSessionSpawner creates a function that can spawn new sessions with different working directories. |
| 1038 | func (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 |
no test coverage detected