public function bootstrapUserCode()
    {
        // Clean previously registered events
        $this->tasks->clearRegisteredEvents();
        $this->bootstrapPlugins();

        // Get the registered events
        $hooks = (array) $this->config->getContextually('hooks');
        $tasks = isset($hooks['tasks']) ? (array) $hooks['tasks'] : [];
        $roles = isset($hooks['roles']) ? (array) $hooks['roles'] : [];
        $events = isset($hooks['events']) ? (array) $hooks['events'] : [];

        // Bind tasks and commands
        foreach ($tasks as $name => $task) {
            try {
                $this->tasks->task($name, $task);
            } catch (TaskCompositionException $exception) {
                $this->tasks->command($name, $task);
            }
        }

        // Bind events
        $this->events->onTag('hooks', function () use ($events) {
            foreach ($events as $event => $tasks) {
                foreach ($tasks as $task => $listeners) {
                    $this->tasks->addTaskListeners($task, $event, $listeners, 0);
                }
            }
        });

        // Assign roles
        $this->roles->assignTasksRoles($roles);
    }