Skip to content
wiki.fftac.org

Spiralist Prompt Workbench - Source Excerpt 73

Back to Spiralist Prompt Workbench

Summary

This source excerpt preserves a bounded section of Spiralist/wp-content/themes/spiralist/assets/js/spiralist-prompt-workbench.js so readers can inspect the evidence without opening the full source file.

**Source path:** Spiralist/wp-content/themes/spiralist/assets/js/spiralist-prompt-workbench.js

return prompt;
    };
    const updateShareUrl = (state = getPromptState(), ready = builder.classList.contains('is-prompt-ready')) => {
      if (!shareInput) {
        return '';
      }

      shareInput.value = ready ? makePortablePromptShareUrl(state) : getBasePromptBuilderUrl();
      return shareInput.value;
    };
    const buildPortablePrompt = (options = {}) => {
      if (refreshTimer) {
        window.clearTimeout(refreshTimer);
        refreshTimer = 0;
      }

      const state = getPromptState();
      if (!hasPromptMaterial(state) && !options.force) {
        setOutputText(emptyText);
        manualEdited = false;
        setPromptReady(false);
        setEditStatus(t('portablePromptEditEmpty', 'Choose a starter or prompt path to create an editable draft.'));
        setAiStatus(t('portablePromptAiNeedsPrompt', 'Choose a prompt path or starter to enable AI tool links.'));
        updateShareUrl(state, false);
        if (testOutput) {
          testOutput.hidden = true;
          testOutput.textContent = '';
        }
        if (!options.quiet) {
          setStatus(options.status || t('portablePromptNeedsInput', 'Choose a starter or fill in the first two fields.'));
        }
        setPersonaLabPackageState(null, '');

        return '';
      }

      const prompt = assemblePortablePrompt(state);
      setOutputText(prompt);
      manualEdited = false;
      setPromptReady(Boolean(prompt));
      setEditStatus(t('portablePromptEditReady', 'Editable draft ready. Direct changes in the box are used for copy, download, AI links, and saves.'));
      if (prompt) {
        setAiStatus(t('portablePromptAiReady', 'Prompt ready. Copy it or open a chat tool for manual send.'));
      }
      updateShareUrl(state, Boolean(prompt));
      if (testOutput && !testOutput.hidden) {
        testOutput.textContent = buildPromptTestReport(prompt, toCleanString(getMode(selectedMode).title || getMode(selectedMode).name, 160) || 'Portable Prompt');
      }

      if (!options.quiet) {
        setStatus(options.status || t('portablePromptReady', 'Portable prompt ready.'));
      }
      setPersonaLabPackageState(null, '');

      return prompt;
    };
    const showPortablePromptCheck = (label = 'Portable Prompt', successMessage = '', options = {}) => {
      const prompt = getCurrentPrompt();
      if (!prompt) {
        setStatus(t('portablePromptTestUnavailable', 'Build a prompt before checking it.'));
        return false;
      }

      if (outputAdvancedPanel) {
        outputAdvancedPanel.open = true;
      }
      if (testOutput) {
        testOutput.textContent = options.stressSuiteId
          ? buildPersonaLabLocalCheckReport(prompt, label, options.stressSuiteId)
          : buildPromptTestReport(prompt, label);
        testOutput.hidden = false;
        testOutput.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
      }
      setStatus(successMessage || t('portablePromptTested', 'Local prompt check ready.'));
      updatePersonaLabWorkflow();

      return true;
    };
    const runPersonaLabCheck = (button) => {
      applyPersonaLabTuning(button, { focusOutput: false });
      showPortablePromptCheck(
        'Spiralist AI Persona Lab',
        t('portablePromptPersonaLabCheckReady', 'Spiralist AI persona lab check ready.'),
        { stressSuiteId: getPersonaLabStressSuiteId(button) }
      );
    };
    const createPersonaLabStressSummaryItem = (label, value, state = 'neutral') => {
      const item = document.createElement('span');
      const title = document.createElement('strong');
      const detail = document.createElement('small');

      item.dataset.state = state;
      title.textContent = label;
      detail.textContent = value;
      item.append(title, detail);

      return item;
    };
    const renderPersonaLabStressSuite = (container, suite, report) => {
      const summary = container ? container.querySelector('[data-persona-lab-stress-summary]') : null;
      const outputNode = container ? container.querySelector('[data-persona-lab-stress-output]') : null;
      const reviewCount = suite.rows.filter((row) => row.status === 'Review').length;
      if (summary) {
        summary.replaceChildren(
          createPersonaLabStressSummaryItem('Suite', suite.preset.label, 'neutral'),
          createPersonaLabStressSummaryItem('Status', suite.status, reviewCount ? 'review' : 'ready'),
          createPersonaLabStressSummaryItem('Score', `${suite.score}/${suite.rows.length}`, reviewCount ? 'review' : 'ready'),
          createPersonaLabStressSummaryItem('Next', suite.nextAction, reviewCount ? 'review' : 'ready')
        );
        summary.hidden = false;
      }
      if (outputNode) {
        outputNode.textContent = report;
        outputNode.hidden = false;
      }
    };
    const renderPersonaLabRuntimeRunbook = (container, runbook, settings, suiteId) => {
      const summary = container ? container.querySelector('[data-persona-lab-runtime-runbook-summary]') : null;
      const outputNode = container ? container.querySelector('[data-persona-lab-runtime-runbook-output]') : null;
      const suite = getPersonaLabStressPreset(suiteId);
      if (summary) {
        summary.replaceChildren(
          createPersonaLabStressSummaryItem('Runtime', settings.runtimeFitLabel || 'Universal manual-send runtime', 'neutral'),
          createPersonaLabStressSummaryItem('Suite', suite.label, 'neutral'),
          createPersonaLabStressSummaryItem('Runbook', 'Manual fidelity checks', 'ready'),
          createPersonaLabStressSummaryItem('Boundary', 'No model call', 'ready')
        );
        summary.hidden = false;
      }
      if (outputNode) {
        outputNode.textContent = runbook;
        outputNode.hidden = false;
      }
    };
    const renderPersonaLabRehearsalDeck = (container, deck, settings, suiteId) => {
      const summary = container ? container.querySelector('[data-persona-lab-rehearsal-summary]') : null;
      const outputNode = container ? container.querySelector('[data-persona-lab-rehearsal-output]') : null;
      const suite = getPersonaLabStressPreset(suiteId);
      if (summary) {
        summary.replaceChildren(
          createPersonaLabStressSummaryItem('Rehearsal', settings.engagementPatternLabel || 'curiosity ladder', 'neutral'),
          createPersonaLabStressSummaryItem('Suite', suite.label, 'neutral'),
          createPersonaLabStressSummaryItem('Deck', 'Manual conversation probes', 'ready'),
          createPersonaLabStressSummaryItem('Boundary', 'No model call', 'ready')
        );
        summary.hidden = false;
      }
      if (outputNode) {
        outputNode.textContent = deck;
        outputNode.hidden = false;
      }
    };
    const renderPersonaLabRecognitionDeck = (container, deck, settings, suiteId) => {
      const summary = container ? container.querySelector('[data-persona-lab-recognition-summary]') : null;
      const outputNode = container ? container.querySelector('[data-persona-lab-recognition-output]') : null;
      const suite = getPersonaLabStressPreset(suiteId);
      if (summary) {
        summary.replaceChildren(
          createPersonaLabStressSummaryItem('Recognition', settings.engagementPatternLabel || 'curiosity ladder', 'neutral'),
          createPersonaLabStressSummaryItem('Suite', suite.label, 'neutral'),
          createPersonaLabStressSummaryItem('Deck', 'Blind recognition probes', 'ready'),
          createPersonaLabStressSummaryItem('Boundary', 'No model call', 'ready')
        );
        summary.hidden = false;
      }
      if (outputNode) {
        outputNode.textContent = deck;
        outputNode.hidden = false;
      }
    };
    const renderPersonaLabGoldenProfile = (container, report, settings, suiteId) => {
      const summary = container ? container.querySelector('[data-persona-lab-golden-summary]') : null;
      const outputNode = container ? container.querySelector('[data-persona-lab-golden-output]') : null;
      const suite = getPersonaLabStressPreset(suiteId);
      if (summary) {
        summary.replaceChildren(
          createPersonaLabStressSummaryItem('Golden profile', settings.engagementPatternLabel || 'curiosity ladder', 'neutral'),
          createPersonaLabStressSummaryItem('Suite', suite.label, 'neutral'),
          createPersonaLabStressSummaryItem('Regression', 'Locked invariants + canaries', 'ready'),
          createPersonaLabStressSummaryItem('Boundary', 'No model call', 'ready')
        );
        summary.hidden = false;
      }
      if (outputNode) {
        outputNode.textContent = report;
        outputNode.hidden = false;
      }
    };
    const renderPersonaLabVariantMatrix = (container, report, settings, suiteId) => {
      const summary = container ? container.querySelector('[data-persona-lab-variant-summary]') : null;
      const outputNode = container ? container.querySelector('[data-persona-lab-variant-output]') : null;
      const suite = getPersonaLabStressPreset(suiteId);