<!-- SOLIDABILITY-WORLD · part 51 -->
button>
        `;
        break;
    }

    panel.innerHTML = `
      <div class="onboard-card">
        <div class="onboard-steps">
          ${steps.map((s, i) => `
            <div class="onboard-step ${i < idx ? 'done' : ''} ${i === idx ? 'active' : ''}">
              ${i < idx ? '✓' : i + 1}
            </div>
          `).join('')}
        </div>
        <h2>${step.title}</h2>
        <p class="onboard-desc">${step.desc}</p>
        <div class="onboard-content">${content}</div>
      </div>
    `;
  }

  let selectedSource = null;
  let sourcePath = null;

  function selectSource(type) {
    selectedSource = type;
    if (type === 'server') {
      document.getElementById('path-input-group').style.display = 'block';
      // Stay on authorize step but show path input
      currentStep = 'authorize';
      const panel = document.getElementById('sw-onboard');
      renderStep(panel);
      document.getElementById('path-input-group').style.display = 'block';
    } else {
      // GitHub/upload not yet implemented
      alert('This connection method is coming soon. Server directory is available now.');
    }
  }

  async function authorize() {
    sourcePath = document.getElementById('source-path')?.value?.trim();
    if (selectedSource === 'server' && !sourcePath) {
      alert('Please enter the path to your project directory.');
      return;
    }
    currentStep = 'analyze';
    renderStep(document.getElementById('sw-onboard'));
  }

  async function runAnalysis() {
    const status = document.getElementById('analyze-status');
    try {
      status.textContent = 'Connecting to analysis service...';
      const resp = await fetch('/api/solidability/analyze', {
        method: 'POST',
        credentials: 'same-origin',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ path: sourcePath, source: selectedSource }),
      });
      if (!resp.ok) {
        const err = await resp.json().catch(() => ({}));
        throw new Error(err.error || 'Analysis failed');
      }
      const result = await resp.json();
      status.textContent = `Found ${result.total_files} files, ${result.total_routes} routes.`;
      // Store for generation step
      window.SWUserMap = result;
      setTimeout(() => {
        currentStep = 'generate';
        renderStep(document.getElementById('sw-onboard'));
      }, 1500);
    } catch (e) {
      status.textContent = `Analysis failed: ${e.message}`;
      status.style.color = '#ff6666';
    }
  }

  async function runGeneration() {
    const status = document.getElementById('generate-status');
    try {
      status.textContent = 'Calculating geometry...';
      // Use the universal geometry engine
      const layout = SWGeometry.mapToWorld(window.SWUserMap);
      SWGeometry.applyHierarchy(layout, window.SWUserMap);
      window.SWUserLayout = layout;
      status.textContent = `World ready: ${layout.rooms.length} buildings, ${layout.districts.length} districts.`;
      setTimeout(() => {
        currentStep = 'tour';
        renderStep(document.getElementById('sw-onboard'));
      }, 1500);
    } catch (e) {
      status.textContent = `Generation failed: ${e.message}`;
      status.style.color = '#ff6666';
    }
  }

  function startTour() {
    finish();
    // Build the world and start AI tour
    if (window.SWUserLayout) {
      SWWorld.buildFull(window.SWUserLayout);
      setTimeout(() => SWHyper.startTour(), 1000);
    }
  }

  function finish() {
    document.getElementById('sw-onboard')?.classList.remove('visible');
  }

  function next() {
    const idx = steps.findIndex(s => s.id === currentStep);
    if (idx < steps.length - 1) {
      currentStep = steps[idx + 1].id;
      renderStep(document.getElementById('sw-onboard'));
    }
  }

  function back() {
    const idx = steps.findIndex(s => s.id === currentStep);
    if (idx > 0) {
      currentStep = steps[idx - 1].id;
      renderStep(document.getElementById('sw-onboard'));
    }
  }

  return {
    showOnboarding, next, back, selectSource, authorize, startTour, finish,
  };
})();


===== FILE: public/solidability-world/js/sw-trust.js =====
// Solidability World — Role & Trust System
// Three roles with hard boundaries:
//
// DIAGNOSTIC (read-only AI):
//   - Analyzes code, finds problems, suggests fixes
//   - NEVER modifies source, NEVER runs shell, NEVER deploys
//   - This is Solid in diagnostic mode
//
// OPERATOR (human or authorized AI):
//   - Can preview and apply fixes
//   - Each fix requires explicit approval
//   - All actions logged to audit trail
//
// AUDIT (visible to all):
//   - Who suggested what, who approved, who applied
//   - Timestamps, before/after, verification results
//
// Code annotations: @solidability comments help the diagnostic AI
// understand intent without guessing.

const SWTrust = (() => {
  // Current session role — set by server based on auth
  let currentRole = 'diagnostic'; // default: read-on