Um. Wow.

OK, let me see if I've got this straight.

1. Brain Ghost Dirk lives in Jake's subconscious and is arbitrarily knowledgeable about all sorts of stuff because "pages have lots of untapped potential".
2. Jake dreams, transporting Brain Ghost Dirk to a dreambubble in the process.
3. This version of Dirk gets left behind in the dreambubble when Jake wakes up. Somehow. (You'd think that he could just be part of the dreamscape, which is formed from stuff from the dreamers' minds, but then why can only Terezi see him?)
4. Dream Dirk falls asleep, sending his mind to the dreambubble where he joins up with Brain Ghost Dirk. Again, somehow. Probably Heart powers.

...and that's how Dirk knew to do all of that?

Because if that's not it, I'm lost on how the hell Dirk knew to do all of that.