( ctx context.Context, spec *taskpkg.StartTaskSession, )
| 123 | } |
| 124 | |
| 125 | func (b *taskSessionBridge) StartTaskSession( |
| 126 | ctx context.Context, |
| 127 | spec *taskpkg.StartTaskSession, |
| 128 | ) (*taskpkg.SessionRef, error) { |
| 129 | if ctx == nil { |
| 130 | return nil, errors.New("daemon: start task session context is required") |
| 131 | } |
| 132 | if spec == nil { |
| 133 | return nil, errors.New("daemon: start task session spec is required") |
| 134 | } |
| 135 | |
| 136 | opts := session.CreateOpts{ |
| 137 | AgentName: taskSessionAgentName(spec.Task), |
| 138 | Provider: "", |
| 139 | Name: taskSessionName(spec), |
| 140 | Channel: taskRunSessionChannel(spec.Run), |
| 141 | Type: session.SessionTypeSystem, |
| 142 | } |
| 143 | applyTaskSessionWorkerProfile(&opts, spec.ExecutionProfile) |
| 144 | applyTaskSessionSandboxProfile(&opts, spec.ExecutionProfile) |
| 145 | applyTaskSessionRuntimeProfile(&opts, spec.ExecutionProfile) |
| 146 | switch spec.Task.Scope.Normalize() { |
| 147 | case taskpkg.ScopeWorkspace: |
| 148 | opts.Workspace = strings.TrimSpace(spec.Task.WorkspaceID) |
| 149 | case taskpkg.ScopeGlobal: |
| 150 | if b.globalWorkspacePath == "" { |
| 151 | return nil, errors.New("daemon: task session bridge global workspace path is required") |
| 152 | } |
| 153 | opts.WorkspacePath = b.globalWorkspacePath |
| 154 | default: |
| 155 | return nil, fmt.Errorf( |
| 156 | "%w: unsupported task scope %q for task session start", |
| 157 | taskpkg.ErrValidation, |
| 158 | spec.Task.Scope, |
| 159 | ) |
| 160 | } |
| 161 | if b.contextOverlay != nil { |
| 162 | overlay, err := b.contextOverlay.TaskRunPromptOverlay(ctx, spec.Task, spec.Run, spec.ExecutionProfile) |
| 163 | if err != nil { |
| 164 | return nil, fmt.Errorf("daemon: render task session context overlay: %w", err) |
| 165 | } |
| 166 | opts.PromptOverlay = joinPromptOverlays(opts.PromptOverlay, overlay) |
| 167 | } |
| 168 | |
| 169 | created, err := b.sessions.Create(ctx, opts) |
| 170 | if err != nil { |
| 171 | return nil, err |
| 172 | } |
| 173 | if created == nil { |
| 174 | return nil, fmt.Errorf("%w: task session bridge create returned nil session", taskpkg.ErrValidation) |
| 175 | } |
| 176 | info := created.Info() |
| 177 | if info == nil { |
| 178 | return nil, fmt.Errorf("%w: task session bridge create returned nil session info", taskpkg.ErrValidation) |
| 179 | } |
| 180 | return &taskpkg.SessionRef{ |
| 181 | SessionID: strings.TrimSpace(info.ID), |
| 182 | WorkspaceID: strings.TrimSpace(info.WorkspaceID), |
nothing calls this directly
no test coverage detected