<!-- SOLIDABILITY-WORLD · part 45 -->
estination.key);
      if (!stillExists) {
        hyper.narrate(`Destination no longer exists in the world. Returning to manual control.`);
        hyper.stopAI();
        paused = false;
        pausedState = null;
        return;
      }
      // Resume AI to destination
      hyper.resumeAI(pausedState.destination);
    } else if (pausedState.aiDriving) {
      hyper.resumeAI(null);
    } else {
      hyper.setMode(pausedState.mode);
    }

    logAction('resume');
    paused = false;
    pausedState = null;
    currentInspection = null;
  }

  // REDIRECT: choose new destination, resume AI
  function redirect() {
    hideUI();
    // Focus the command input for new destination
    const input = document.getElementById('hc-input');
    if (input) {
      input.placeholder = 'Where to? (e.g. "drive me to lib")';
      input.focus();
    }
    logAction('redirect');
    // Keep paused until new command given
    SWHyper.narrate(`Paused. Tell me where to go next.`);
  }

  // MANUAL: take over completely
  function manual() {
    hideUI();
    SWGlass.hide();
    SWHyper.stopAI();
    SWHyper.setMode('WALK');
    logAction('manual');
    paused = false;
    pausedState = null;
    currentInspection = null;
  }

  // END: stop everything, clear state
  function end() {
    hideUI();
    SWGlass.hide();
    SWHyper.stopAI();
    SWHyper.setMode('WALK');
    logAction('end');
    paused = false;
    pausedState = null;
    currentInspection = null;
  }

  function logAction(action) {
    if (currentInspection) {
      currentInspection.action = action;
      currentInspection.resolvedAt = new Date().toISOString();
    }
  }

  // Searchable history
  function showHistory() {
    let hist = document.getElementById('intervention-history');
    if (!hist) {
      hist = document.createElement('div');
      hist.id = 'intervention-history';
      document.getElementById('app').appendChild(hist);
    }
    hist.innerHTML = `
      <div class="history-card">
        <div class="history-header">
          <h3>📋 Inspection History</h3>
          <span class="code-close" onclick="document.getElementById('intervention-history').classList.remove('visible')">✕</span>
        </div>
        <input type="text" id="history-search" placeholder="Search inspections..."
               oninput="SWIntervene.filterHistory(this.value)" />
        <div class="history-list" id="history-list">
          ${renderHistoryList('')}
        </div>
      </div>
    `;
    hist.classList.add('visible');
  }

  function renderHistoryList(query) {
    const q = query.toLowerCase();
    const filtered = inspectionLog.filter(i =>
      !q || i.room.toLowerCase().includes(q) ||
      i.file.toLowerCase().includes(q) ||
      i.district.toLowerCase().includes(q)
    ).reverse();

    if (!filtered.length) return '<p class="note">No inspections yet.</p>';
    return filtered.map(i => `
      <div class="history-item" onclick="SWIntervene.revisit('${i.id}')">
        <div class="hist-room">${escapeHtml(i.room)}</div>
        <div class="hist-meta">${escapeHtml(i.district)} · ${i.mode} · ${i.action}</div>
        <div class="hist-time">${new Date(i.timestamp).toLocaleString()}</div>
      </div>
    `).join('');
  }

  function filterHistory(query) {
    document.getElementById('history-list').innerHTML = renderHistoryList(query);
  }

  // Revisit a previous inspection
  function revisit(id) {
    const insp = inspectionLog.find(i => i.id === id);
    if (!insp) return;
    document.getElementById('intervention-history').classList.remove('visible');
    const layout = SWWorld.getLayout();
    const room = layout.rooms.find(r => r.key === insp.roomKey);
    if (room) {
      SWHyper.narrate(`Revisiting <b>${escapeHtml(insp.room)}</b> from ${new Date(insp.timestamp).toLocaleString()}.`);
      SWHyper.aiDriveTo(room, `Returning to a previous inspection.`);
    }
  }

  function isPaused() { return paused; }
  function getLog() { return [...inspectionLog]; }

  function escapeHtml(s) {
    if (!s) return '';
    return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;')
                   .replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  }

  return {
    intervene, resume, redirect, manual, end,
    showHistory, filterHistory, revisit,
    isPaused, getLog,
  };
})();


===== FILE: public/solidability-world/js/sw-investigator.js =====
// Solidability World — AI Investigator V2
// Autonomous diagnostic investigation with task completion, evidence separation,
// investigation memory, and smart prioritization.
// Extends V1 per GPT-6 directive 2026-10-08.

const SWInvestigator = (() => {
  let investigating = false;
  let paused = false;
  let currentCase = null;
  let investigationQueue = [];
  let investigationMemory = {}; // findingId -> {outcome, timestamp, revision}

  // Load memory from localStorage
  try {
    investigationMemory = JSON.parse(localStorage.getItem('sw-investigation-memory') || '{}');
  