Is there a general rule for determining the direction of tension force?
Tension is an internal force in a body, such as a rope, that resists any attempt to pull the rope apart. Simply, tension arises due to intermolecular interactions, and if it did not exist, ropes would fall apart the moment you pull on them.
Now, it is necessary to distinguish between internal and external forces for a body. External forces are forces that act on the body due to other bodies, such as friction and gravity. When you look at the body as a whole, it is easy to see the effect of the force on the body. External forces allow the bulk of the body to accelerate, provided no other external forces cancel them out (equilibrium). For example: a body acted upon by the Earth's gravity:
Internal forces of a body are different. Internal forces exist inside a body, and the effects of internal forces cannot directly interact with anything external to the body. In other words, internal forces are forces that one part of a body causes onto another part of the same body (see later). Hence it is not as clear to see the "direction" of such forces. Internal forces do not lead to bulk acceleration, but instead cause body deformation (e.g. stretching a spring, or bending a ruler). Here is a diagram showing the internal forces acting on a block:
Well, you can't see anything obvious on the outside, but that not because internal force don't exist. It's because if you were to take all of the internal forces present in a body, they would sum to zero. This is a result of Newton's 3rd Law. Instead, a better way to visualise internal forces in a body is to make an imaginary cut through the body and see how the forces act on the cut face. This is better demonstrated below in the diagram, where a rope is being pulled apart:
By considering an imaginary cut, you look at the two halves and enforce equilibrium (if the whole rope obeys equilibrium, so must any arbitrary sub-length of rope). By doing so, you find out that in order to satisfy equilibrium, one half must exert a force on the other, and vice versa by Newton's 3rd Law. These particular forces are internal since they're forces caused by one part of the rope acting on another part of the same rope. These internal forces act at the interfaces of the imaginary cut, and, in this case, are known as the tension. To be more precise, it is the tension at the location on the rope where the imaginary cut is made. Note that you can determine the tension's direction if you look at one half of the rope, but since the tensions occur in pair, there is no obvious direction of tension at that point of the rope for the whole rope.
Looking at your example, let's make a few cuts to see the tension forces in the rope:
Only the forces acting on/in the rope, on the box or on the hanging mass are included in the diagram above.
In short, internal forces like tension at a particular point in a rope doesn't really have a clear cut direction, as they occur in pairs.
The tension on a string between two objects (note: your top diagram shows t̲h̲r̲e̲e̲ objects) is analogous to the force between two objects elastically colliding. The force exerted by the one end of the string is opposite and equal to the force exerted by the other end of the string; both forces must be parallel to the string and pointed towards its center.
However, do not confuse the string tension with a force. Even though it will have the same magnitude as the force on either end of the string, and is oriented along the length of the string, tension does NOT have a direction. You can't say "The tension is headed to the left" and be making any sense.
We treat the string/rope like another object. This object exerts forces on other objects such as the hanging mass (in your picture). However, a string, by its very nature, can never "push" another object, it can only "pull" another object. That "pull" is a force which we give the name tension.
Thus, tension will point away from the mass in the direction of the string. In the case of the hanging mass, the string pulls it up, so the string exerts an upward force on the mass, and the tension will be upwards. In the case of the mass on the table, the string pulls it to the right, so the tension will be to the right.
So, for example, suppose you have a rope attached to a mass on a friction-less table, and you pull the rope to the right with a constant force of 1 Newton. The rope will then pull on the mass with a force of 1 Newton to the right, and the mass will start to accelerate to the right. Here, the tension, (i.e. the force with which the rope pulls on the mass) is to the right with a magnitude of 1 Newton. So, you created tension by pulling on the rope; a tension of 1 Newton.
I don't quite understand why you keep referring to the normal force. A normal force is a force perpendicular to a plane of mass; the mass we refer to here we consider to be an ideal case of a point mass, so there is no normal force. Also, the rope can be pulled in any direction, not just the direction perpendicular to the plane of the mass.
Tension is created whenever a rope exerts a force (pull) on another object. Notice that there was no friction in the example above. You don't need friction to have tension; this experiment could have been done in space.