package agent import ( "fmt" "strings" "github.com/Autumn-27/norma/agentcore" actool "github.com/Autumn-27/norma/tool" ) // newSession builds every Norma session ARTEX runs. Norma's background-task // tools (Monitor, TaskOutput, TaskStop, TaskList) start commands in the panel // process, outside the sandbox that Bash goes through, so no session gets them // while the sandbox is required. With the sandbox off, a session that has no // shell tool still must not gain one through Monitor: orchestration agents get // no background tools at all. A session that does have Bash or the interactive // shell keeps the task manager when the sandbox is off: Bash backgrounds long // commands, the pause kill switch ends a command's whole process group, and the // interactive shell keeps its PTY sessions on the same manager. // A nil tool list makes Norma install its own unconfined file and shell tools, // so nil becomes an empty list. func newSession(opts agentcore.Options) *agentcore.Session { if opts.Tools == nil { opts.Tools = []actool.CoreTool{} } if SandboxRequired() || !hasShellTool(opts.Tools) { opts.DisableBackgroundTasks = true } return agentcore.NewSession(opts) } // hasShellTool reports whether the session offers Bash or the interactive shell // (shell_open and its companions), the session tools that need the task manager. func hasShellTool(tools []actool.CoreTool) bool { for _, tool := range tools { if name := tool.Name(); name == "Bash" || strings.HasPrefix(name, "shell_") { return true } } return false } // resumeSession reloads the persisted conversation of session id into s. Norma's // transcript.Store.Load treats a missing file as a fresh session (no records, no // error); any other failure, such as a corrupt line or an unreadable path, is // returned so the caller stops before the first model or tool call instead of // appending a new conversation to the damaged file. func resumeSession(s *agentcore.Session, id string) error { if err := s.Resume(id); err != nil { return fmt.Errorf("restore Norma session %q: %w", id, err) } return nil }