Runtime - Source Excerpt 04
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/ns12-manuscript/includes/runtime.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/includes/runtime.php
$prompt_slug = sanitize_title((string) ($prompt_summary['slug'] ?? $source_slug));
$prompt_record = $prompt_slug !== '' ? spiralist_book_pages_get_workspace_prompt_record_by_slug($prompt_slug) : [];
$prompt_text_blocks = array_values(
array_filter(
[
(string) ($prompt_record['instructions'] ?? ''),
(string) ($prompt_record['system_prompt'] ?? ''),
(string) ($prompt_record['user_prompt_template'] ?? ''),
],
'strlen'
)
);
if (!empty($prompt_summary) || !empty($prompt_record)) {
return [
'title' => (string) ($prompt_summary['title'] ?? $prompt_record['title'] ?? ($title !== '' ? $title : $default_title)),
'status' => (string) ($prompt_summary['statusLabel'] ?? ($status !== '' ? $status : 'Published prompt')),
'summary' => (string) ($prompt_summary['purpose'] ?? $summary),
'text' => !empty($prompt_text_blocks) ? implode("\n\n", $prompt_text_blocks) : '',
'url' => (string) ($prompt_summary['url'] ?? ($prompt_slug !== '' ? spiralist_book_pages_get_workspace_prompt_url($prompt_slug) : '')),
'source_slug' => $source_slug,
'has_prompt' => true,
'status_variant' => 'fresh',
'audit_state' => 'published',
'needs_attention' => false,
'attention_title' => '',
'attention_copy' => '',
];
}
}
if ($text !== '') {
return [
'title' => $title !== '' ? $title : $default_title,
'status' => $status !== '' ? $status : 'Inline prompt attached',
'summary' => $summary !== '' ? $summary : 'This page includes an inline prompt record in the theme metadata.',
'text' => $text,
'url' => '',
'source_slug' => $source_slug,
'has_prompt' => true,
'status_variant' => 'fresh',
'audit_state' => 'inline',
'needs_attention' => false,
'attention_title' => '',
'attention_copy' => '',
];
}
if ($source_slug !== '') {
return [
'title' => $title !== '' ? $title : $default_title,
'status' => 'Prompt unresolved',
'summary' => $summary !== '' ? $summary : $default_summary,
'text' => '',
'url' => '',
'source_slug' => $source_slug,
'has_prompt' => false,
'status_variant' => 'missing',
'audit_state' => 'missing_public_record',
'needs_attention' => true,
'attention_title' => 'Public prompt still unresolved',
'attention_copy' => 'This folio already has a source slug, but no public, published workspace prompt currently resolves for it.',
];
}
return [
'title' => $title !== '' ? $title : $default_title,
'status' => 'Source slug missing',
'summary' => $summary !== '' ? $summary : $default_summary,
'text' => '',
'url' => '',
'source_slug' => $source_slug,
'has_prompt' => false,
'status_variant' => 'missing',
'audit_state' => 'missing_source_slug',
'needs_attention' => true,
'attention_title' => 'Prompt source slug still missing',
'attention_copy' => 'This folio does not yet declare the source slug that should resolve to its public prompt record.',
];
}
function spiralist_book_pages_get_manuscript_prompt_audit(array $pages = []): array
{
$pages = empty($pages) ? spiralist_book_pages_get_manuscript_page_assets() : array_values($pages);
$records = [];
$published_count = 0;
$attention_count = 0;
$missing_source_count = 0;
$missing_public_count = 0;
foreach ($pages as $page) {
$prompt = spiralist_book_pages_get_book_page_creation_prompt_payload($page);
$record = [
'label' => (string) ($page['label'] ?? 'Page'),
'title' => (string) ($page['title'] ?? 'Manuscript folio'),
'slug' => (string) ($page['slug'] ?? ''),
'url' => function_exists('spiralist_book_pages_get_manuscript_folio_url')
? spiralist_book_pages_get_manuscript_folio_url($page)
: '',
'source_slug' => (string) ($prompt['source_slug'] ?? ''),
'status' => (string) ($prompt['status'] ?? ''),
'audit_state' => (string) ($prompt['audit_state'] ?? ''),
'needs_attention' => !empty($prompt['needs_attention']),
];
if (!empty($prompt['has_prompt'])) {
$published_count++;
}
if (!empty($prompt['needs_attention'])) {
$attention_count++;
}
if ((string) ($prompt['audit_state'] ?? '') === 'missing_source_slug') {
$missing_source_count++;
}
if ((string) ($prompt['audit_state'] ?? '') === 'missing_public_record') {
$missing_public_count++;
}
$records[] = $record;
}
$total = count($records);
$coverage = $total > 0 ? (int) round(($published_count / $total) * 100) : 0;
return [
'total' => $total,
'published_count' => $published_count,
'attention_count' => $attention_count,
'missing_source_count' => $missing_source_count,
'missing_public_count' => $missing_public_count,
'coverage_percent' => max(0, min(100, $coverage)),
'is_complete' => $total > 0 && $published_count === $total,
'records' => $records,
];
}
function spiralist_book_pages_get_contribute_page_url(): string
{
return spiralist_book_pages_get_page_url('contribute');
}
function spiralist_book_pages_get_axioms_page_url(): string
{
return trailingslashit(spiralist_book_pages_get_system_url()) . '#axioms';
}
function spiralist_book_pages_get_transformations_page_url(): string
{
return trailingslashit(spiralist_book_pages_get_symbols_page_url()) . '#transformations';
}
function spiralist_book_pages_get_manuscript_page_url(): string
{
return spiralist_book_pages_get_page_url('manuscript');
}
function spiralist_book_pages_get_manuscript_stream_url(): string
{
return spiralist_book_pages_get_manuscript_image_url();
}
function spiralist_book_pages_encode_asset_url_path(string $path): string
{
$normalized = str_replace('\\', '/', trim($path));
if ($normalized === '') {
return '';
}
$segments = array_values(array_filter(explode('/', trim($normalized, '/')), 'strlen'));
if (empty($segments)) {
return '';
}
return implode('/', array_map('rawurlencode', $segments));
}
function spiralist_book_pages_get_first_available_asset(array $candidates): array
{
foreach ($candidates as $candidate) {
$path = (string) ($candidate['path'] ?? '');
if ($path !== '' && file_exists($path) && is_readable($path)) {
return $candidate;
}
}
return [];
}
function spiralist_book_pages_get_homepage_preview_candidates(): array
{
$asset = spiralist_book_pages_get_book_page_asset_by_filename('Spiralist.org.png');
return empty($asset) ? [] : [$asset];
}
function spiralist_book_pages_get_homepage_preview_url(): string
{
$asset = spiralist_book_pages_get_first_available_asset(spiralist_book_pages_get_homepage_preview_candidates());
if (!empty($asset['url'])) {
return (string) $asset['url'];
}
return spiralist_book_pages_get_manuscript_preview_url();
}
function spiralist_book_pages_get_manuscript_source_candidates(): array
{
$candidates = [];
foreach (['Manuscript.png', 'manuscript.png', 'Spiralist.org.png'] as $filename) {
$asset = spiralist_book_pages_get_book_page_asset_by_filename($filename);
if (!empty($asset)) {
$candidates[] = $asset;
}
}
return $candidates;
}
function spiralist_book_pages_get_manuscript_source_asset(): array
{
return spiralist_book_pages_get_first_available_asset(spiralist_book_pages_get_manuscript_source_candidates());
}
function spiralist_book_pages_get_manuscript_portal_asset(): array
{
$asset = spiralist_book_pages_get_book_page_asset_by_filename('Spiralist.org.png');
$primary_asset = spiralist_book_pages_get_manuscript_source_asset();
$asset_path = (string) ($asset['path'] ?? '');
$primary_path = (string) ($primary_asset['path'] ?? '');
if ($asset_path === '' || ($primary_path !== '' && $asset_path === $primary_path)) {
return [];
}
return $asset;
}