fix: remove silent ls -l injection, keep emoji for explicit ls -l
Remove ensureLsLong which silently injected -l into all ls commands, changing output format unexpectedly. Now ls runs as-is; emoji type indicators only apply when user explicitly uses ls -l. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7cedf9bd0e
commit
027a1b3ee7
1 changed files with 8 additions and 20 deletions
|
|
@ -1369,15 +1369,9 @@ func (al *AgentLoop) executeCmdMode(ctx context.Context, agent *AgentInstance, c
|
||||||
workDir = agent.Workspace
|
workDir = agent.Workspace
|
||||||
}
|
}
|
||||||
|
|
||||||
// For ls commands, ensure -l flag so we can parse file types
|
|
||||||
execCmd := content
|
|
||||||
if isLsCommand(content) {
|
|
||||||
execCmd = ensureLsLong(content)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute via ExecTool
|
// Execute via ExecTool
|
||||||
result := agent.Tools.ExecuteWithContext(ctx, "exec", map[string]any{
|
result := agent.Tools.ExecuteWithContext(ctx, "exec", map[string]any{
|
||||||
"command": execCmd,
|
"command": content,
|
||||||
"working_dir": workDir,
|
"working_dir": workDir,
|
||||||
}, channel, chatID, nil)
|
}, channel, chatID, nil)
|
||||||
|
|
||||||
|
|
@ -1387,8 +1381,8 @@ func (al *AgentLoop) executeCmdMode(ctx context.Context, agent *AgentInstance, c
|
||||||
output = "(no output)"
|
output = "(no output)"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Colorize ls output with emoji type indicators
|
// Colorize ls output with emoji type indicators (only when user explicitly used ls -l)
|
||||||
if isLsCommand(content) {
|
if isLsCommand(content) && hasLongFlag(content) {
|
||||||
output = formatLsOutput(output)
|
output = formatLsOutput(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1716,20 +1710,14 @@ func isLsCommand(cmd string) bool {
|
||||||
return cmd == "ls" || strings.HasPrefix(cmd, "ls ")
|
return cmd == "ls" || strings.HasPrefix(cmd, "ls ")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensureLsLong injects -l into an ls command if not already present,
|
// hasLongFlag checks if an ls command already includes the -l flag.
|
||||||
// so the output always contains permission strings for type detection.
|
func hasLongFlag(cmd string) bool {
|
||||||
func ensureLsLong(cmd string) string {
|
for _, p := range strings.Fields(cmd)[1:] {
|
||||||
parts := strings.Fields(cmd)
|
|
||||||
for _, p := range parts[1:] {
|
|
||||||
if strings.HasPrefix(p, "-") && !strings.HasPrefix(p, "--") && strings.ContainsRune(p, 'l') {
|
if strings.HasPrefix(p, "-") && !strings.HasPrefix(p, "--") && strings.ContainsRune(p, 'l') {
|
||||||
return cmd // already has -l
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// "ls" → "ls -l", "ls -a /tmp" → "ls -l -a /tmp"
|
return false
|
||||||
if len(parts) == 1 {
|
|
||||||
return "ls -l"
|
|
||||||
}
|
|
||||||
return "ls -l " + strings.Join(parts[1:], " ")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// formatLsOutput adds emoji type indicators to ls -l style output lines.
|
// formatLsOutput adds emoji type indicators to ls -l style output lines.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue