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 }