fs: move cwd to ctl command, remove cwd file
/cwd returns current directory, /cwd X changes it (with stat check). One fewer file in the agent namespace.
This commit is contained in:
parent
2561e01574
commit
94088ccc94
|
|
@ -33,7 +33,7 @@ ROOT_ENTRIES="session bypass agents backends models help ctl eventwait complete
|
||||||
SESSION_FILES="env paused connected ctl name id bypass"
|
SESSION_FILES="env paused connected ctl name id bypass"
|
||||||
|
|
||||||
# Agent-level files (exist under session/{name}/agent/{name}/)
|
# Agent-level files (exist under session/{name}/agent/{name}/)
|
||||||
AGENT_FILES="prompt fifo chat chat.raw statewait log plan cfg ctl cwd stats systemprompt tools name id proc"
|
AGENT_FILES="prompt fifo chat chat.raw statewait log plan cfg ctl stats systemprompt tools name id proc"
|
||||||
|
|
||||||
is_root_path() {
|
is_root_path() {
|
||||||
local path="$1"
|
local path="$1"
|
||||||
|
|
|
||||||
|
|
@ -731,30 +731,17 @@ func requestAgentCtl(ctx HandlerCtx, data []byte) ([]byte, error) {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return []byte(ctx.Agent.Cwd() + "\n"), nil
|
return []byte(ctx.Agent.Cwd() + "\n"), nil
|
||||||
}
|
}
|
||||||
ctx.Agent.SetCWD(paths.ExpandHome(strings.Join(args, " ")))
|
dir := paths.ExpandHome(strings.Join(args, " "))
|
||||||
return []byte(strings.Join(args, " ") + "\n"), nil
|
if _, err := os.Stat(dir); err != nil {
|
||||||
|
return nil, fmt.Errorf("cwd: %w", err)
|
||||||
|
}
|
||||||
|
ctx.Agent.SetCWD(dir)
|
||||||
|
return []byte(dir + "\n"), nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown ctl command: %s", cmd)
|
return nil, fmt.Errorf("unknown ctl command: %s", cmd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readAgentCwd(ctx HandlerCtx) ([]byte, error) {
|
|
||||||
return []byte(ctx.Agent.Cwd() + "\n"), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeAgentCwd(ctx HandlerCtx, data []byte) error {
|
|
||||||
input := strings.TrimSpace(string(data))
|
|
||||||
if input == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
input = paths.ExpandHome(input)
|
|
||||||
if _, err := os.Stat(input); err != nil {
|
|
||||||
return fmt.Errorf("cwd: %w", err)
|
|
||||||
}
|
|
||||||
ctx.Agent.SetCWD(input)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func readAgentStats(ctx HandlerCtx) ([]byte, error) {
|
func readAgentStats(ctx HandlerCtx) ([]byte, error) {
|
||||||
s := "usage=" + ctx.Agent.UsageStr() + "\n" +
|
s := "usage=" + ctx.Agent.UsageStr() + "\n" +
|
||||||
"cost=" + ctx.Agent.CostStr() + "\n" +
|
"cost=" + ctx.Agent.CostStr() + "\n" +
|
||||||
|
|
|
||||||
|
|
@ -269,12 +269,6 @@ FileNode("generate", 0666,
|
||||||
Request(requestAgentCtl),
|
Request(requestAgentCtl),
|
||||||
),
|
),
|
||||||
|
|
||||||
FileNode("cwd", 0666,
|
|
||||||
Doc("Agent working directory. Read: current path. Write: change directory."),
|
|
||||||
Read(readAgentCwd),
|
|
||||||
Write(writeAgentCwd),
|
|
||||||
),
|
|
||||||
|
|
||||||
FileNode("stats", 0444,
|
FileNode("stats", 0444,
|
||||||
Doc("Agent statistics. Key=value lines: usage=, cost=, ctxsz=."),
|
Doc("Agent statistics. Key=value lines: usage=, cost=, ctxsz=."),
|
||||||
Read(readAgentStats),
|
Read(readAgentStats),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue