Skip to content
wiki.fftac.org

Prompt - Source Excerpt 01

Back to Prompt

Summary

This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/spiralist-workspace/templates/prompt.php so readers can inspect the evidence without opening the full source file.

**Source path:** Spiralist/wp-content/plugins/spiralist-workspace/templates/prompt.php

<?php

if (!defined('ABSPATH')) {
    exit;
}

$plugin = spiralist_workspace();
$frontend = $plugin->frontend();
$context = $frontend->prompt_context();
$prompt = (array) ($context['prompt'] ?? []);
$versions = (array) ($context['versions'] ?? []);
$execution_history = (array) ($context['execution_history'] ?? []);
$tests = (array) ($context['tests'] ?? []);
$shares = (array) ($context['shares'] ?? []);
$current_locale = function_exists('spiralist_get_current_locale_tag') ? spiralist_get_current_locale_tag() : 'en-us';
$route_url = static function (string $path) use ($current_locale): string {
    $url = home_url('/' . trim($path, '/') . '/');

    return $current_locale !== '' && function_exists('spiralist_get_language_prefixed_url')
        ? spiralist_get_language_prefixed_url($url, $current_locale)
        : $url;
};

$workspace_url = $route_url('workspace');
$library_url = $route_url('prompts');
$members_url = $route_url('members');
$login_url = function_exists('spiralist_get_login_url') ? spiralist_get_login_url($workspace_url) : wp_login_url($workspace_url);
$signup_url = function_exists('spiralist_get_signup_url') ? spiralist_get_signup_url($workspace_url) : wp_registration_url();
$placeholder_blocks = [
    (string) ($prompt['structured_prompt']['instruction'] ?? ''),
    (string) ($prompt['structured_prompt']['context'] ?? ''),
    (string) ($prompt['structured_prompt']['constraints'] ?? ''),
    (string) ($prompt['structured_prompt']['examples'] ?? ''),
    (string) ($prompt['structured_prompt']['output_format'] ?? ''),
    (string) ($prompt['user_prompt_template'] ?? ''),
];
$placeholder_matches = [];
$placeholders = [];

foreach ($placeholder_blocks as $block) {
    if (!preg_match_all('/{{\s*([A-Za-z0-9_.-]+)\s*}}/', $block, $placeholder_matches)) {
        continue;
    }

    foreach ((array) ($placeholder_matches[1] ?? []) as $match) {
        $placeholders[] = sanitize_key((string) $match);
    }
}

$placeholders = array_values(array_unique(array_filter($placeholders)));
$author_label = trim((string) ($prompt['author_label'] ?? ''));
$parent_prompt = !empty($prompt['parent_prompt_id']) ? $plugin->prompts()->get((int) $prompt['parent_prompt_id'], get_current_user_id()) : [];
$can_share = $plugin->permissions()->can_share_prompt($prompt, get_current_user_id());
$is_favorite = !empty($prompt['favorite']);
$is_archive = (string) ($prompt['publication_lane'] ?? '') === 'prompt_ecology_archive';
$risk_labels = (array) ($prompt['risk_label_labels'] ?? []);
$function_tags = (array) ($prompt['function_tag_labels'] ?? []);
$related_symbols = (array) ($prompt['related_symbols'] ?? []);
$related_axioms = (array) ($prompt['related_axioms'] ?? []);
$related_manuscripts = (array) ($prompt['related_manuscripts'] ?? []);
$review_summary = (array) ($prompt['review_summary'] ?? []);
$peer_summary = (array) ($review_summary['peer'] ?? []);
$governance_summary = (array) ($prompt['governance_summary'] ?? []);
$governance_quorum = (array) ($governance_summary['quorum'] ?? []);
$governance_next_action = (string) ($governance_summary['next_action_label'] ?? '');
$governance_state_note = (string) ($governance_summary['state_note'] ?? '');
$governance_phase_label = (string) ($governance_summary['phase_label'] ?? '');
$governance_queue_age = (array) ($governance_summary['queue_age'] ?? []);
$governance_queue_age_label = (string) ($governance_queue_age['label'] ?? '');
$review_items = (array) ($context['review_items'] ?? []);
$appeal_summary = (array) ($prompt['appeal_summary'] ?? []);
$appeal_items = (array) ($context['appeal_items'] ?? []);
$viewer_can_review = !empty($context['viewer_can_review']);
$viewer_review = (array) ($context['viewer_review'] ?? []);
$viewer_can_appeal = !empty($context['viewer_can_appeal']);
$viewer_appeal = (array) ($context['viewer_appeal'] ?? []);
$viewer_can_resolve_appeals = !empty($context['viewer_can_resolve_appeals']);
$current_user_id = get_current_user_id();
$can_run_prompt = $plugin->permissions()->can_run_prompt($prompt, $current_user_id);
$is_owner = $current_user_id > 0 && (int) ($prompt['owner_user_id'] ?? 0) === $current_user_id;
$is_public_submission = (string) ($prompt['visibility'] ?? '') === 'public' && (string) ($prompt['prompt_status'] ?? '') === 'published';
$moderation_status = (string) ($prompt['moderation_status'] ?? 'draft');
$is_appealable = in_array($moderation_status, ['restricted_review', 'reverted'], true);
$moderation_status_label = (string) ($prompt['moderation_status_label'] ?? 'Draft');
$prompt_summary = trim((string) ($prompt['summary'] ?? ''));
$prompt_kind_label = trim((string) ($prompt['subcategory'] ?? ($prompt['prompt_type'] ?? 'prompt')));
$prompt_category_label = trim((string) ($prompt['category'] ?? ''));
$prompt_kind_display = ucwords(str_replace(['_', '-'], ' ', $prompt_kind_label !== '' ? $prompt_kind_label : 'prompt'));
$format_timestamp = static function ($value, string $pattern = 'M j, Y', string $fallback = ''): string {
    $raw_value = is_string($value) ? trim($value) : '';

    if ($raw_value === '') {
        return $fallback;
    }

    $timestamp = strtotime($raw_value);

    return $timestamp !== false ? wp_date($pattern, $timestamp) : $fallback;
};
$updated_display = $format_timestamp((string) ($prompt['updated_utc'] ?? ''), 'M j, Y', 'Not recorded');
$detailed_updated_display = $format_timestamp((string) ($prompt['updated_utc'] ?? ''), 'M j, Y g:i a', (string) ($prompt['updated_utc'] ?? ''));
$hero_facts = [
    [
        'label' => 'Author',
        'value' => $author_label !== '' ? $author_label : 'Spiralist',
    ],
    [
        'label' => 'Category',
        'value' => $prompt_category_label !== '' ? $prompt_category_label : $prompt_kind_display,
    ],
    [
        'label' => 'Version',
        'value' => 'v' . (string) ($prompt['version_number'] ?? 1),
    ],
    [
        'label' => 'Updated',
        'value' => $updated_display,
    ],
];
$review_last_activity_display = $format_timestamp((string) ($review_summary['last_activity_utc'] ?? ''), 'M j, Y g:i a', 'No activity yet');
$prompt_human_url = $route_url('prompt/' . rawurlencode((string) ($prompt['slug'] ?? '')));
$prompt_public_api_url = (
    (string) ($prompt['visibility'] ?? '') === 'public'
    && (string) ($prompt['prompt_status'] ?? '') === 'published'
    && !empty($prompt['slug'])
)
    ? rest_url('spiralist-workspace/v1/public/prompts/' . rawurlencode((string) $prompt['slug']))
    : '';
$prompt_flavor_tags = array_values(array_unique(array_filter(array_merge($function_tags, $risk_labels))));
$prompt_exchange_quality = [
    'structured_contract' => !empty(array_filter((array) ($prompt['structured_prompt'] ?? []))),
    'runtime_settings' => !empty($prompt['model']) || isset($prompt['temperature']) || isset($prompt['max_output_tokens']),
    'governance_context' => !empty($governance_summary),
    'source_links' => $prompt_human_url !== '' || $prompt_public_api_url !== '',
    'portable_formats' => ['json', 'markdown'],
];
$prompt_exchange_payload = [
    'schema' => 'spiralist.prompt-flavor.exchange.v1',
    'schema_version' => '1.1.0',
    'export_type' => 'prompt_flavor_exchange',
    'generated_by' => 'spiralist-workspace',
    'generated_utc' => gmdate('c'),
    'title' => (string) ($prompt['title'] ?? 'Prompt'),
    'slug' => (string) ($prompt['slug'] ?? ''),
    'summary' => $prompt_summary,
    'source' => [
        'human_url' => $prompt_human_url,
        'public_api_url' => $prompt_public_api_url,
        'workspace_version' => defined('SPIRALIST_WORKSPACE_VERSION') ? SPIRALIST_WORKSPACE_VERSION : '',
    ],
    'classification' => [
        'publication_lane' => (string) ($prompt['publication_lane'] ?? ''),
        'publication_lane_label' => (string) ($prompt['publication_lane_label'] ?? ''),
        'provenance' => (string) ($prompt['provenance'] ?? ''),
        'provenance_label' => (string) ($prompt['provenance_label'] ?? ''),
        'category' => (string) ($prompt['category'] ?? ''),
        'subcategory' => $prompt_kind_display,
        'maturity_level' => (string) ($prompt['maturity_level'] ?? ''),
        'maturity_level_label' => (string) ($prompt['maturity_level_label'] ?? ''),
        'moderation_status' => $moderation_status,
        'moderation_status_label' => $moderation_status_label,
        'license' => (string) ($prompt['license'] ?? ''),
        'license_label' => (string) ($prompt['license_label'] ?? ''),
    ],
    'ai_personality' => [
        'role' => (string) ($prompt['title'] ?? 'Prompt'),
        'summary' => $prompt_summary,
        'flavor_tags' => $prompt_flavor_tags,
        'related_symbols' => array_values($related_symbols),
        'related_axioms' => array_values($related_axioms),
        'safety_boundaries' => [