Crimes are handled in the story goal _CRIME_CrimeTriggers in combination with the character scripts CRIME_HumanReactions.charScript and CRIME_AnimalReactions.charScript.
Crimes are created by calling either CrimeRegisterCrime() or CrimeRegisterCrimeWithPosition(). For stealing specifically, this is done by calling CrimeRegisterCrime() with "Steal" or "EmptyPocketNoticed" as crime type.
The reactions to crimes are data-driven, but unfortunately there is no integrated editor for the data yet. It is done via Public/Shared/Stats/Generated/Data/Crimes.txt. We have quite a bit of documentation about the crime system on the internal wiki, but it still needs to be converted/transferred to docs.larian.com
Here's a summary I wrote about it a while ago on the internal chat, which explains the basic way it works:
1) you perform a "hostile" action (attack, kill, steal, pickpocked, use owned item, move owned item). This is the crime type: Assault, Murder, Theft, ... (names custom-defined by script/data; nothing is hard-coded regarding this)
2) the action is against someone that is (generally) not hostile to you (i.e., not in combat with you). This is the victim.
3) It is Osiris scripting that decides which actions under which circumstances are crimes, and then it just calls RegisterCrime() reporting the crime type (as a string), the perpetrator, the victim, evidence if any, optionally a specific position. E.g. (simplified) CharacterKilledByCharacter() -> register Murder crime
4) Others may see you perform this action (CanSee). Those are witnesses that may react to the crime. They are collected by code.
5) Others may hear you perform this action (distance check). They may start investigations. They are collected by code.
6) Some actions create leave behind evidence, such as murder (the body) or stealing (the missing item). If an NPC later on sees the crime scene, they may start an investigation at that point
Who can react to a crime?
* This is tag-based with priorities (defined in data, looked up using the crime type string that was specified when script registered the crime). MAGISTER and GUARD characters will generally get priority over anyone else. If no-one with a listed tag is found, no one will react (except for the victim itself).
* Different reactions can be specified depending on whether someone is a victim or a witness. E.g. attacking a BADASSCIVILIAN will immediately lead to combat, but attacking someone else with a BADASSCIVILIAN nearby, will make him try to arrest the perpetrator.
* Code will select who reacts to a crime (usually a witness or the victim), although script can transfer the investigation/reaction to another character (e.g. if the reaction of the victim is to call for help)How will they react?
* again tag-based. Some will flee (e.g. animals), while others may attack or arrest you.
* if they discovered a crime scene after the fact, or only heard the crime, they will start "investigating" to find the culprit. This boils down to interrogating all players they encounter in the neighbourhood. They will magically (and correctly) know whether you're guilty or not. Depending on tags and victim/non-victim status, they will then possibly allow you to bribe them, attack you, send you to prison, warn you, ...
* if they saw you performing the crime, they will directly go to one of the above behaviours without interrogating anyone (but it can be a different one compared to the one after an investigation)