Nearly four years before school shooter Nikolas Cruz gunned down 17 students and educators at a Parkland high school, he confided in a therapist that he saw himself in a dream drenched in human blood.

A May 3, 2014, notation in a Broward County schools psychiatric file said Cruz "reported [a dream] last week of him killing people and covered in blood. He smiled and told the therapist that sometimes he says things for shock value."

After Cruz's disclosure to his therapist at the alternative Cross Creek School, administrators developed a "safety plan" to ensure the welfare of Cruz and others while the teen was on summer vacation. The plan included provisions for removing "all sharp objects from the home," and encouraging the youth to "verbalize what the problem is."

THE BUZZ: Gov. Rick Scott signs gun, school security legislation over NRA opposition

If talking about "the problem" was seen as a solution to Cruz's volatile behavior — and, in the short term, it may have been — it did not last. Portions of his psychiatric file, obtained by the Miami Herald on Friday, show a young man whose mental health exhibited frequent and extreme swings. His attitude would brighten for weeks at a time, then descend again into paranoia and anger.

That pent-up rage exploded on Valentine's Day when Cruz took an Uber to his former high school in Parkland and walked onto campus carrying a bag with a semiautomatic rifle and magazines of ammunition. He went on a six-minute rampage, shooting into locked classrooms and through windows and walls and blasting people in the hallways. He killed 17 people, 14 of them students.

Then, wearing an old Marjory Stoneman Douglas High School Junior ROTC polo shirt, he fled the building along with panic-stricken students and escaped the school before police entered. He was caught while walking on the street.

Cruz was formally charged this week with 17 counts of premeditated murder and 17 counts of attempted murder. He has already confessed to police and this week withdrew a not-guilty plea. The legal move underlines that his attorneys at the Broward County Public Defender's Office hope to negotiate for a plea of guilt in exchange for a life sentence. Cruz, who was ordered held without bond Friday on the additional attempted murder counts, now faces the death penalty.

The shooting in Parkland has set off a renewed gun-control movement, and led students at the school to call for a nationwide protest on March 24 to call for stronger gun measures. In Florida, Gov. Rick Scott signed new legislation Friday restricting some access to rifles and allowing police to strip people with mental illness of the ability to own a gun. Nationally, members of Congress have filed gun legislation.

The rage and obsession with violence documented by Cruz's therapists during nearly two years of interactions when he was 15 to 17 years old continued through his school career: Again and again, authorities were warned about the teen's explosive tendencies and lack of impulse control. Again and again, authorities ignored the warnings.

In addition to the troubling behavior Cruz exhibited at the schools he attended — including an incident in which the teen reportedly brought a backpack with bullets to class — law enforcement officers were also alerted that Cruz might be dangerous.

The FBI failed to act on two tips about Cruz, one of which involved Cruz posting online that he planned to become a "professional school shooter." The Broward Sheriff's Office was also warned about the teen, and had received a report that he "planned to shoot up the school."

Cruz alternated between periods of good behavior and periods of paranoia during which he acted out at school and at home, making fun of his peers, cursing at school staff and making threats, according to notes from his period at Cross Creek. The records obtained by the Herald documented weekly therapy sessions between February 2014 and December of 2015.

In one session, Cruz acknowledged to his therapist that he visited YouTube to "research wars, military material and terrorists topics." He said he wore military clothing. His mother, Lynda Cruz, who is now deceased, told the teen's therapist that his obsession with the military resulted from his "excessive gaming."

School administrators spoke with Lynda Cruz in the months that followed about their mutual concerns about Cruz's desire to own a gun and take shooting lessons. The therapist, a Sept. 23, 2014, notation said, "shared concerns with parent about his obsession with guns/military and his poor anger control." The note also cited concerns over the possibility that Cruz would "deploy aggressive behaviors at home."

At the time, Lynda Cruz was considering buying the teen a pellet gun for his birthday. A different therapist who appears to have visited the family at their home suggested the mom develop a "plan" in which the youth would be allowed to buy a gun if he was able to "earn it" with good behavior. There was "a plan in place at home in order to control his use of the pellet gun."

Cruz's school therapist, however, expressed reservations. "Parent was advised against getting him a gun (pellet) or classes for his birthday," the September notation said. "Parent advised to restrict access to any weapon."

The therapy files also underscore Cruz's strong desire to be sent to a regular high school. He frequently discussed transferring with his therapist, but also expressed anxiety about getting mainstreamed.

In some sessions, the therapist described Cruz as "receptive," or noted that he'd had "positive" behavior at school. The therapist role-played with Cruz to teach him how to interact with his peers and avoid conflict. But following other sessions, the therapist noted troubling behavior at school and at home.

In one April 2014 session, the therapist discussed Cruz's "aggressive behavior at home due to his not getting his way." Cruz responded by saying that he saw the therapist as a threat. The therapist noted that Cruz was "very paranoid."

The following month, Cruz cursed at school staff and made comments to his teacher that made the school "fear that he may act out and harm others," the therapist noted. Cruz told the therapist he liked to make his teacher feel uncomfortable. A meeting was scheduled to discuss a treatment plan "to keep client and others safe," the therapist noted.

Around this time, the therapist explained to Cruz that he wasn't ready to attend a regular high school.

Cruz also fantasized about a "perfect summer" that revolved around guns and shooting, according to a short paper he wrote.

Under the heading "What my perfect summer would be," Cruz wrote about "buying some type of gun and shooting at targets that I set up with large amounts of ammo just for fun for hours," stopping only when he got bored or ran out of ammunition. Cruz said he also wanted to get a job and make money "so I can get things that I want for myself [instead] of come to this time wasting school that support stuped [sic] selfish children that I don't care about and gets in the way of my chances of leaving this place."

Cruz also wrote about his loneliness. "I will never be happy with my life I have no money or [sic] freinds," he wrote. He complained about his "annoying mother who won't leave me alone."

In preparation for a summer 2014 recess, Cruz's school therapist and psychiatrist jointly wrote a letter to another one of the teen's psychiatrists articulating a host of serious concerns. "At home, he continues to be aggressive and destructive with minimal provocation," the letter said. "For instance, he destroyed his television after losing a video game that he was playing. Nikolas has a hatchet that he uses to chop up a dead tree in his backyard. Mom has not been able to locate that hatchet as of lately.

"When upset he punches holes in the walls and has used sharp tools to cut up the upholstery on the furniture and carve holes in the walls of the bathroom," the letter added.

By the following April, though, after Cruz had shown "tremendous progress" in his behavior, Cross Creek began efforts to move him to a traditional school.

Psychiatric notes from that period describe a significantly less erratic youth. His mother reported that he was making friends and had exhibited no signs of inappropriate behavior "in the community. She is happy that he has been doing better," an April 28, 2015, notation said.

Cruz had been able to "control" his behavior, both in school and at home, the April 28, 2015, notation said. He was noticeably less aggressive. Teachers did not report having to place him in "time outs."

"Parent has requested student to be mainstreamed," the report added.

In discussions about Cruz's desire to attend a "regular" school, psychiatric progress notes said he was encouraged to continue mental health medication, therapy and social work case-management at home, and was discouraged from becoming a cadet: "Interested in ROTC?" the report said. "Not advised," it added.

Cruz had started attending Stoneman Douglas part time by October of 2015. Later that fall, the therapist noted that Cruz was going to be mainstreamed full time beginning in January. At the last documented session, in December of 2015, Cruz told his therapist he felt he would do very well at his new school.

Herald staff writer David Smily contributed to this report.