Files
ARTEX/server/missing_executable.go
T
BaaRaiandAseemPrasad 2be85a64c9 feat(server): diagnose missing shell executables on failed Bash calls (#665)
Extracted cleanly onto becc47a without inherited #655/#662/#663 commits.
Adds an early return when !result.IsError in diagnosedShellTool.Call so a
successful command whose stdout/target data contains 'command not found' is
never misdiagnosed as a failed invocation, with regression test coverage.

Co-authored-by: AseemPrasad <aseemprasad0520@gmail.com>
2026-11-29 01:02:28 +01:00

55 lines
1.6 KiB
Go

package server
import (
"context"
"encoding/json"
"fmt"
"regexp"
actool "github.com/Autumn-27/norma/tool"
)
var missingExecutableMessages = []*regexp.Regexp{
regexp.MustCompile(`(?m)^(?:[^\r\n:]+/)?bash:\s+(?:line\s+\d+:\s+)?([^\s:]+):\s+command not found\s*$`),
regexp.MustCompile(`(?m)^(?:[^\r\n:]+/)?(?:sh|dash|ash):\s+\d+:\s+([^\s:]+):\s+not found\s*$`),
regexp.MustCompile(`(?m)^(?:[^\r\n:]+/)?zsh:\s+command not found:\s+([^\s:]+)\s*$`),
}
func diagnoseBashTool(t actool.CoreTool) actool.CoreTool {
if t.Name() != "Bash" {
return t
}
return &diagnosedShellTool{CoreTool: t}
}
type diagnosedShellTool struct{ actool.CoreTool }
func (t *diagnosedShellTool) AcceptsRawInput() bool {
r, ok := t.CoreTool.(interface{ AcceptsRawInput() bool })
return ok && r.AcceptsRawInput()
}
func (t *diagnosedShellTool) Call(ctx context.Context, input json.RawMessage, tc *actool.ToolContext) (actool.Result, error) {
result, err := t.CoreTool.Call(ctx, input, tc)
if err != nil {
return result, err
}
if !result.IsError {
return result, nil
}
output := result.Flatten()
for _, pattern := range missingExecutableMessages {
match := pattern.FindStringSubmatch(output)
if len(match) != 2 {
continue
}
diagnosed := actool.Errorf(fmt.Sprintf(
"%s\n\n[ARTEX diagnostic: missing_executable]\nThe shell could not find executable %q in this runtime's PATH. This invocation failed and is not assessment evidence. Do not retry this executable; report the missing dependency instead.",
output, match[1],
))
diagnosed.Extra = result.Extra
return diagnosed, nil
}
return result, nil
}