MCPcopy Create free account
hub / github.com/compozy/agh / newSessionResumeCommand

Function newSessionResumeCommand

internal/cli/session.go:278–331  ·  view source on GitHub ↗
(deps commandDeps)

Source from the content-addressed store, hash-verified

276}
277
278func newSessionResumeCommand(deps commandDeps) *cobra.Command {
279 var (
280 latest bool
281 workspaceFilter string
282 )
283 cmd := &cobra.Command{
284 Use: "resume [id]",
285 Short: "Attach to a resumable session",
286 Example: ` # Attach to a resumable session by ID
287 agh session resume sess_1234
288
289 # Attach to the latest eligible session in a workspace
290 agh session resume --latest --workspace checkout-api`,
291 Args: sessionResumeArgs,
292 RunE: func(cmd *cobra.Command, args []string) error {
293 client, err := clientFromDeps(deps)
294 if err != nil {
295 return err
296 }
297 if latest && len(args) > 0 {
298 return errors.New("cli: --latest cannot be combined with a session id")
299 }
300 if !latest && len(args) == 0 {
301 return errors.New("session_resume_ambiguous: pass a session id or --latest")
302 }
303 sessionID := ""
304 if latest {
305 candidates, err := client.ListSessions(cmd.Context(), SessionListQuery{
306 Workspace: workspaceFilter,
307 Resumable: true,
308 Sort: "last_activity",
309 Limit: 1,
310 })
311 if err != nil {
312 return err
313 }
314 if len(candidates) == 0 {
315 return writeCommandOutput(cmd, sessionResumeEmptyBundle())
316 }
317 sessionID = candidates[0].ID
318 } else {
319 sessionID = args[0]
320 }
321 info, err := client.ResumeSession(cmd.Context(), sessionID)
322 if err != nil {
323 return err
324 }
325 return writeCommandOutput(cmd, sessionBundle(info, deps.now))
326 },
327 }
328 cmd.Flags().BoolVar(&latest, "latest", false, "Attach to the latest eligible session")
329 cmd.Flags().StringVar(&workspaceFilter, workspaceSkillSource, "", "Filter --latest by workspace name or ID")
330 return cmd
331}
332
333func sessionResumeArgs(_ *cobra.Command, args []string) error {
334 if len(args) > 1 {

Callers 1

newSessionCommandFunction · 0.85

Calls 6

clientFromDepsFunction · 0.85
writeCommandOutputFunction · 0.85
sessionResumeEmptyBundleFunction · 0.85
sessionBundleFunction · 0.85
ListSessionsMethod · 0.65
ResumeSessionMethod · 0.65

Tested by

no test coverage detected