feat: session lifecycle wrapper with manifest capture and session logging
Refactor new/resume/open to use session.Run() which wraps child process launch with pre/post manifest capture and append-only session logging to logs/sessions.log. Bump version to 0.2.0. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+18
-14
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warrenronsiek/ctask/internal/config"
|
||||
"github.com/warrenronsiek/ctask/internal/session"
|
||||
"github.com/warrenronsiek/ctask/internal/shell"
|
||||
"github.com/warrenronsiek/ctask/internal/workspace"
|
||||
)
|
||||
@@ -26,20 +27,25 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
resumeCmd.Flags().BoolVar(&resumeContainer, "container", false, "Resume in container mode (v0.2)")
|
||||
resumeCmd.Flags().BoolVar(&resumeContainer, "container", false, "Resume in container mode (deferred)")
|
||||
resumeCmd.Flags().BoolVar(&resumeShell, "shell", false, "Open shell instead of agent")
|
||||
resumeCmd.Flags().StringVarP(&resumeAgent, "agent", "a", "", "Override agent command")
|
||||
rootCmd.AddCommand(resumeCmd)
|
||||
}
|
||||
|
||||
func runResume(cmd *cobra.Command, args []string) error {
|
||||
if resumeContainer {
|
||||
return doResume(args[0], resumeContainer, resumeShell, resumeAgent)
|
||||
}
|
||||
|
||||
// doResume is the shared resume logic used by both resume and last commands.
|
||||
func doResume(query string, container, useShell bool, agentOverride string) error {
|
||||
if container {
|
||||
fmt.Println(shell.ContainerNotice())
|
||||
return nil
|
||||
}
|
||||
|
||||
root := config.ResolveRoot()
|
||||
ws := resolveOne(root, args[0], false)
|
||||
ws := resolveOne(root, query, false)
|
||||
|
||||
// Update updated_at
|
||||
now := time.Now().UTC().Truncate(time.Second)
|
||||
@@ -49,21 +55,19 @@ func runResume(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("updating metadata: %w", err)
|
||||
}
|
||||
|
||||
agent := resumeAgent
|
||||
agent := agentOverride
|
||||
if agent == "" {
|
||||
agent = ws.Meta.Agent
|
||||
}
|
||||
|
||||
envVars := config.EnvVars(ws.Meta.Slug, ws.Meta.Mode, root, ws.Path, ws.Meta.Category)
|
||||
|
||||
if resumeShell {
|
||||
return shell.ExecShell(ws.Path, envVars, ws.Meta.Slug, ws.Meta.Mode)
|
||||
}
|
||||
|
||||
// Agent mode
|
||||
for _, line := range shell.BannerLines(ws.Meta.Mode, ws.Meta.Slug, ws.Path) {
|
||||
fmt.Println(line)
|
||||
}
|
||||
|
||||
return shell.ExecAgent(agent, ws.Path, envVars)
|
||||
return session.Run(session.LaunchOpts{
|
||||
WsDir: ws.Path,
|
||||
EnvVars: envVars,
|
||||
Agent: agent,
|
||||
Mode: ws.Meta.Mode,
|
||||
Slug: ws.Meta.Slug,
|
||||
Shell: useShell,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user