mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-06 04:14:15 +00:00
Norma adds Monitor, TaskOutput, TaskStop and TaskList to each session unless DisableBackgroundTasks is set, and only the connection test and the goal decomposer set it. Monitor starts a shell command in the panel process, outside the sandbox Bash goes through, so with ARTEX_SANDBOX=required a worker, planner, chat or main-agent model could run commands in the panel container. All agent sessions are now built by newSession, which sets DisableBackgroundTasks while the sandbox is required and turns a nil tool list into an empty one (Norma reads nil as "install my default file and shell tools"). With the sandbox off the tools stay: local Bash needs the same task manager for background runs, the pause kill switch and the interactive shell. The tool catalogue resolver no longer returns nil when the tools table cannot be read. Tests drive each production session (chat, Auto chat, goal decomposition, planner, main agent, worker, captureRun) under the required sandbox mode and fail when a background-task tool is offered to the model, check that no file calls agentcore.NewSession directly, and check the resolver's catalogue failure path.
54 lines
2.1 KiB
Go
54 lines
2.1 KiB
Go
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
|
|
}
|