Skip to content

Commit 8f06ddb

Browse files
authored
Merge pull request #958 from dgageot/remove-dead-code-1337
Remove dead code
2 parents d58c20d + 3f5d48f commit 8f06ddb

14 files changed

Lines changed: 57 additions & 242 deletions

File tree

cmd/root/new.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ func (f *newFlags) runNewCommand(cmd *cobra.Command, args []string) error {
6969

7070
sess := session.New(opts...)
7171

72-
return runTUI(ctx, "", rt, sess, firstMessage)
72+
return runTUI(ctx, rt, sess, firstMessage)
7373
}
7474

75-
func runTUI(ctx context.Context, agentFilename string, rt runtime.Runtime, sess *session.Session, firstMessage *string) error {
76-
a := app.New(ctx, agentFilename, rt, sess, firstMessage)
75+
func runTUI(ctx context.Context, rt runtime.Runtime, sess *session.Session, firstMessage *string) error {
76+
a := app.New(ctx, rt, sess, firstMessage)
7777
m := tui.New(ctx, a)
7878

7979
progOpts := []tea.ProgramOption{

cmd/root/run.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []s
114114
}
115115

116116
if !tui {
117-
return f.handleExecMode(ctx, out, agentFileName, rt, sess, args)
117+
return f.handleExecMode(ctx, out, rt, sess, args)
118118
}
119119

120-
return handleRunMode(ctx, agentFileName, rt, sess, args)
120+
return handleRunMode(ctx, rt, sess, args)
121121
}
122122

123123
func (f *runExecFlags) loadAgentFrom(ctx context.Context, source teamloader.AgentSource) (*team.Team, error) {
@@ -187,7 +187,7 @@ func (f *runExecFlags) createLocalRuntimeAndSession(t *team.Team) (runtime.Runti
187187
return localRt, sess, nil
188188
}
189189

190-
func (f *runExecFlags) handleExecMode(ctx context.Context, out *cli.Printer, agentFilename string, rt runtime.Runtime, sess *session.Session, args []string) error {
190+
func (f *runExecFlags) handleExecMode(ctx context.Context, out *cli.Printer, rt runtime.Runtime, sess *session.Session, args []string) error {
191191
execArgs := []string{"exec"}
192192
if len(args) == 2 {
193193
execArgs = append(execArgs, args[1])
@@ -198,7 +198,7 @@ func (f *runExecFlags) handleExecMode(ctx context.Context, out *cli.Printer, age
198198
err := cli.Run(ctx, out, cli.Config{
199199
AppName: AppName,
200200
AttachmentPath: f.attachmentPath,
201-
}, agentFilename, rt, sess, execArgs)
201+
}, rt, sess, execArgs)
202202
if cliErr, ok := err.(cli.RuntimeError); ok {
203203
return RuntimeError{Err: cliErr.Err}
204204
}
@@ -222,11 +222,11 @@ func readInitialMessage(args []string) (*string, error) {
222222
return &args[1], nil
223223
}
224224

225-
func handleRunMode(ctx context.Context, agentFilename string, rt runtime.Runtime, sess *session.Session, args []string) error {
225+
func handleRunMode(ctx context.Context, rt runtime.Runtime, sess *session.Session, args []string) error {
226226
firstMessage, err := readInitialMessage(args)
227227
if err != nil {
228228
return err
229229
}
230230

231-
return runTUI(ctx, agentFilename, rt, sess, firstMessage)
231+
return runTUI(ctx, rt, sess, firstMessage)
232232
}

pkg/acp/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (a *Agent) Prompt(ctx context.Context, params acp.PromptRequest) (acp.Promp
181181
}
182182

183183
if userContent != "" {
184-
acpSess.sess.AddMessage(session.UserMessage(a.agentFilename, userContent))
184+
acpSess.sess.AddMessage(session.UserMessage(userContent))
185185
}
186186

187187
// Run the agent and stream updates

pkg/api/pagination_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ func createTestMessages(count int) []session.Message {
2020
role = chat.MessageRoleAssistant
2121
}
2222
messages[i] = session.Message{
23-
AgentFilename: "test.yaml",
24-
AgentName: "test",
23+
AgentName: "test",
2524
Message: chat.Message{
2625
Role: role,
2726
Content: "Message " + strconv.Itoa(i),

pkg/api/types.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,13 @@ type DeleteAgentResponse struct {
115115

116116
// SessionsResponse represents a session in the sessions list
117117
type SessionsResponse struct {
118-
ID string `json:"id"`
119-
Title string `json:"title"`
120-
CreatedAt string `json:"created_at"`
121-
NumMessages int `json:"num_messages"`
122-
InputTokens int `json:"input_tokens"`
123-
OutputTokens int `json:"output_tokens"`
124-
GetMostRecentAgentFilename string `json:"most_recent_agent_filename"`
125-
WorkingDir string `json:"working_dir,omitempty"`
118+
ID string `json:"id"`
119+
Title string `json:"title"`
120+
CreatedAt string `json:"created_at"`
121+
NumMessages int `json:"num_messages"`
122+
InputTokens int `json:"input_tokens"`
123+
OutputTokens int `json:"output_tokens"`
124+
WorkingDir string `json:"working_dir,omitempty"`
126125
}
127126

128127
// SessionResponse represents a detailed session

pkg/app/app.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
)
1717

1818
type App struct {
19-
agentFilename string
2019
runtime runtime.Runtime
2120
session *session.Session
2221
firstMessage *string
@@ -25,9 +24,8 @@ type App struct {
2524
cancel context.CancelFunc
2625
}
2726

28-
func New(ctx context.Context, agentFilename string, rt runtime.Runtime, sess *session.Session, firstMessage *string) *App {
27+
func New(ctx context.Context, rt runtime.Runtime, sess *session.Session, firstMessage *string) *App {
2928
app := &App{
30-
agentFilename: agentFilename,
3129
runtime: rt,
3230
session: sess,
3331
firstMessage: firstMessage,
@@ -129,7 +127,7 @@ func (a *App) EmitStartupInfo(ctx context.Context, events chan runtime.Event) {
129127
func (a *App) Run(ctx context.Context, cancel context.CancelFunc, message string) {
130128
a.cancel = cancel
131129
go func() {
132-
a.session.AddMessage(session.UserMessage(a.agentFilename, message))
130+
a.session.AddMessage(session.UserMessage(message))
133131
for event := range a.runtime.RunStream(ctx, a.session) {
134132
if ctx.Err() != nil {
135133
return

pkg/cli/runner.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Config struct {
3838
}
3939

4040
// Run executes an agent in non-TUI mode, handling user input and runtime events
41-
func Run(ctx context.Context, out *Printer, cfg Config, agentFilename string, rt runtime.Runtime, sess *session.Session, args []string) error {
41+
func Run(ctx context.Context, out *Printer, cfg Config, rt runtime.Runtime, sess *session.Session, args []string) error {
4242
// Create a cancellable context for this agentic loop and wire Ctrl+C to cancel it
4343
ctx, cancel := context.WithCancel(ctx)
4444
defer cancel()
@@ -79,7 +79,7 @@ func Run(ctx context.Context, out *Printer, cfg Config, agentFilename string, rt
7979
finalAttachPath = cfg.AttachmentPath
8080
}
8181

82-
sess.AddMessage(createUserMessageWithAttachment(agentFilename, messageText, finalAttachPath))
82+
sess.AddMessage(createUserMessageWithAttachment(messageText, finalAttachPath))
8383

8484
firstLoop := true
8585
lastAgent := rt.CurrentAgentName()
@@ -390,16 +390,16 @@ func parseAttachCommand(userInput string) (messageText, attachPath string) {
390390
}
391391

392392
// createUserMessageWithAttachment creates a user message with optional image attachment
393-
func createUserMessageWithAttachment(agentFilename, userContent, attachmentPath string) *session.Message {
393+
func createUserMessageWithAttachment(userContent, attachmentPath string) *session.Message {
394394
if attachmentPath == "" {
395-
return session.UserMessage(agentFilename, userContent)
395+
return session.UserMessage(userContent)
396396
}
397397

398398
// Convert file to data URL
399399
dataURL, err := fileToDataURL(attachmentPath)
400400
if err != nil {
401401
slog.Warn("Failed to attach file", "path", attachmentPath, "error", err)
402-
return session.UserMessage(agentFilename, userContent)
402+
return session.UserMessage(userContent)
403403
}
404404

405405
// Ensure we have some text content when attaching a file
@@ -423,7 +423,7 @@ func createUserMessageWithAttachment(agentFilename, userContent, attachmentPath
423423
},
424424
}
425425

426-
return session.UserMessage(agentFilename, "", multiContent...)
426+
return session.UserMessage("", multiContent...)
427427
}
428428

429429
// fileToDataURL converts a file to a data URL

pkg/runtime/runtime.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ func (r *LocalRuntime) handleTaskTransfer(ctx context.Context, sess *session.Ses
13351335

13361336
s := session.New(
13371337
session.WithSystemMessage(memberAgentTask),
1338-
session.WithImplicitUserMessage("", "Follow the default instructions"),
1338+
session.WithImplicitUserMessage("Follow the default instructions"),
13391339
session.WithMaxIterations(child.MaxIterations()),
13401340
session.WithTitle("Transferred task"),
13411341
session.WithToolsApproved(sess.ToolsApproved),
@@ -1489,7 +1489,7 @@ func (r *LocalRuntime) Summarize(ctx context.Context, sess *session.Session, eve
14891489
)
14901490

14911491
summarySession := session.New(session.WithSystemMessage(systemPrompt))
1492-
summarySession.AddMessage(session.UserMessage("", userPrompt))
1492+
summarySession.AddMessage(session.UserMessage(userPrompt))
14931493
summarySession.Title = "Generating summary..."
14941494

14951495
summaryRuntime, err := New(newTeam, WithSessionCompaction(false))

pkg/server/server.go

Lines changed: 9 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,13 @@ type Server struct {
4040
ociTeamKey string
4141
agentsDir string
4242
agentsPath string // For local files: specific file path to reload (instead of scanning agentsDir)
43-
rootFS *os.Root
4443
}
4544

4645
type Opt func(*Server) error
4746

4847
func WithAgentsDir(dir string) Opt {
4948
return func(s *Server) error {
50-
rootFs, err := os.OpenRoot(dir)
51-
if err != nil {
52-
return fmt.Errorf("failed to open root filesystem at %s: %w", dir, err)
53-
}
54-
5549
s.agentsDir = dir
56-
s.rootFS = rootFs
5750
return nil
5851
}
5952
}
@@ -106,17 +99,11 @@ func New(sessionStore session.Store, runConfig *config.RuntimeConfig, teams map[
10699

107100
// List all available agents
108101
group.GET("/agents", s.getAgents)
109-
// Get an agent by id
110-
group.GET("/agents/:id", s.getAgentConfig)
111-
// Get an agent's raw YAML configuration by id
112-
group.GET("/agents/:id/yaml", s.getAgentConfigYAML)
113102

114103
// SESSIONS
115104

116105
// List all sessions
117106
group.GET("/sessions", s.getSessions)
118-
// Get sessions by agent filename
119-
group.GET("/sessions/agent/:id", s.getSessionsByAgent)
120107
// Get a session by id
121108
group.GET("/sessions/:id", s.getSession)
122109
// Resume a session by id
@@ -154,7 +141,7 @@ func (s *Server) Serve(ctx context.Context, ln net.Listener) error {
154141
// hasAgentsDir returns true if the server has a local agents directory.
155142
// Returns false for OCI reference-based servers, which load from memory.
156143
func (s *Server) hasAgentsDir() bool {
157-
return s.agentsDir != "" && s.rootFS != nil
144+
return s.agentsDir != ""
158145
}
159146

160147
// getTeam retrieves a team by key with read lock
@@ -191,38 +178,6 @@ func (s *Server) getOCIRef(key string) (string, bool) {
191178

192179
// API handlers
193180

194-
func (s *Server) getAgentConfig(c echo.Context) error {
195-
agentID := c.Param("id")
196-
p := addYamlExt(agentID)
197-
198-
data, err := s.rootFS.ReadFile(p)
199-
if err != nil {
200-
return fmt.Errorf("reading config file %s: %w", p, err)
201-
}
202-
203-
cfg, err := config.Load(c.Request().Context(), teamloader.NewBytesSource(data))
204-
if err != nil {
205-
slog.Error("Failed to load config", "error", err)
206-
return echo.NewHTTPError(http.StatusNotFound, "agent not found")
207-
}
208-
209-
return c.JSON(http.StatusOK, cfg)
210-
}
211-
212-
func (s *Server) getAgentConfigYAML(c echo.Context) error {
213-
agentID := c.Param("id")
214-
p := addYamlExt(agentID)
215-
216-
// Read the YAML file
217-
yamlContent, err := s.rootFS.ReadFile(p)
218-
if err != nil {
219-
slog.Error("Failed to read agent YAML file", "path", p, "error", err)
220-
return echo.NewHTTPError(http.StatusInternalServerError, "failed to read agent file")
221-
}
222-
223-
return c.String(http.StatusOK, string(yamlContent))
224-
}
225-
226181
func (s *Server) getAgents(c echo.Context) error {
227182
// Refresh agents from disk to get the latest configurations
228183
// Only refresh for local files/dirs (hasAgentsDir == true)
@@ -346,41 +301,13 @@ func (s *Server) getSessions(c echo.Context) error {
346301
responses := make([]api.SessionsResponse, len(sessions))
347302
for i, sess := range sessions {
348303
responses[i] = api.SessionsResponse{
349-
ID: sess.ID,
350-
Title: sess.Title,
351-
CreatedAt: sess.CreatedAt.Format(time.RFC3339),
352-
NumMessages: len(sess.GetAllMessages()),
353-
InputTokens: sess.InputTokens,
354-
OutputTokens: sess.OutputTokens,
355-
GetMostRecentAgentFilename: sess.GetMostRecentAgentFilename(),
356-
WorkingDir: sess.WorkingDir,
357-
}
358-
}
359-
return c.JSON(http.StatusOK, responses)
360-
}
361-
362-
func (s *Server) getSessionsByAgent(c echo.Context) error {
363-
agentFilename := c.Param("id")
364-
if agentFilename == "" {
365-
return echo.NewHTTPError(http.StatusBadRequest, "id parameter is required")
366-
}
367-
368-
sessions, err := s.sessionStore.GetSessionsByAgent(c.Request().Context(), agentFilename)
369-
if err != nil {
370-
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("failed to get sessions for agent: %v", err))
371-
}
372-
373-
responses := make([]api.SessionsResponse, len(sessions))
374-
for i, sess := range sessions {
375-
responses[i] = api.SessionsResponse{
376-
ID: sess.ID,
377-
Title: sess.Title,
378-
CreatedAt: sess.CreatedAt.Format(time.RFC3339),
379-
NumMessages: len(sess.GetAllMessages()),
380-
InputTokens: sess.InputTokens,
381-
OutputTokens: sess.OutputTokens,
382-
GetMostRecentAgentFilename: sess.GetMostRecentAgentFilename(),
383-
WorkingDir: sess.WorkingDir,
304+
ID: sess.ID,
305+
Title: sess.Title,
306+
CreatedAt: sess.CreatedAt.Format(time.RFC3339),
307+
NumMessages: len(sess.GetAllMessages()),
308+
InputTokens: sess.InputTokens,
309+
OutputTokens: sess.OutputTokens,
310+
WorkingDir: sess.WorkingDir,
384311
}
385312
}
386313
return c.JSON(http.StatusOK, responses)
@@ -540,7 +467,7 @@ func (s *Server) runAgent(c echo.Context) error {
540467
}
541468

542469
for _, msg := range messages {
543-
sess.AddMessage(session.UserMessage(agentFilename, msg.Content, msg.MultiContent...))
470+
sess.AddMessage(session.UserMessage(msg.Content, msg.MultiContent...))
544471
}
545472

546473
if err := s.sessionStore.UpdateSession(c.Request().Context(), sess); err != nil {
@@ -655,13 +582,6 @@ func (s *Server) loadTeamForSession(ctx context.Context, agentFilename string, s
655582
return t, nil
656583
}
657584

658-
func addYamlExt(filename string) string {
659-
if strings.HasSuffix(filename, ".yaml") || strings.HasSuffix(filename, ".yml") {
660-
return filename
661-
}
662-
return filename + ".yaml"
663-
}
664-
665585
func (s *Server) elicitation(c echo.Context) error {
666586
sessionID := c.Param("id")
667587
var req api.ResumeElicitationRequest

0 commit comments

Comments
 (0)