Promptrepository - Source Excerpt 07
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/spiralist-workspace/includes/Domain/PromptRepository.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/plugins/spiralist-workspace/includes/Domain/PromptRepository.php
'created_by' => (int) $prompt['owner_user_id'],
'created_utc' => (string) $prompt['created_utc'],
'updated_utc' => (string) $prompt['updated_utc'],
'published_utc' => (string) $prompt['published_utc'],
'is_forkable' => (bool) $prompt['is_forkable'],
'allow_comments' => (bool) $prompt['allow_comments'],
'allow_ratings' => (bool) $prompt['allow_ratings'],
'tags' => array_values((array) $prompt['tags']),
'canonical_status' => (string) $prompt['canonical_status'],
'version_number' => (int) $prompt['version_number'],
'version' => (int) $prompt['version_number'],
'parent_prompt_id' => (int) $prompt['parent_prompt_id'],
'prompt_type' => (string) $prompt['prompt_type'],
'language' => (string) $prompt['language'],
'prompt_status' => (string) $prompt['prompt_status'],
'moderation_status' => (string) $prompt['moderation_status'],
'moderation_status_label' => (string) ($prompt['moderation_status_label'] ?? PromptMetaRegistry::moderation_status_label((string) ($prompt['moderation_status'] ?? 'draft'))),
'publication_lane' => (string) ($prompt['publication_lane'] ?? 'community_library'),
'publication_lane_label' => (string) ($prompt['publication_lane_label'] ?? PromptMetaRegistry::publication_lane_label((string) ($prompt['publication_lane'] ?? 'community_library'))),
'provenance' => (string) ($prompt['provenance'] ?? 'community'),
'provenance_label' => (string) ($prompt['provenance_label'] ?? PromptMetaRegistry::provenance_label((string) ($prompt['provenance'] ?? 'community'))),
'risk_labels' => array_values((array) ($prompt['risk_labels'] ?? [])),
'risk_label_labels' => array_values((array) ($prompt['risk_label_labels'] ?? PromptMetaRegistry::risk_label_labels((array) ($prompt['risk_labels'] ?? [])))),
'function_tags' => array_values((array) ($prompt['function_tags'] ?? [])),
'function_tag_labels' => array_values((array) ($prompt['function_tag_labels'] ?? PromptMetaRegistry::function_tag_labels((array) ($prompt['function_tags'] ?? [])))),
'intent_tags' => PromptIntentRegistry::prompt_intents($prompt),
'intent_tag_labels' => PromptIntentRegistry::prompt_intent_labels($prompt),
'maturity_level' => (string) ($prompt['maturity_level'] ?? 'structured_prompt'),
'maturity_level_label' => (string) ($prompt['maturity_level_label'] ?? PromptMetaRegistry::maturity_level_label((string) ($prompt['maturity_level'] ?? 'structured_prompt'))),
'license' => (string) ($prompt['license'] ?? 'spiralist_contributor'),
'license_label' => (string) ($prompt['license_label'] ?? PromptMetaRegistry::license_label((string) ($prompt['license'] ?? 'spiralist_contributor'))),
'sample_output' => (string) $prompt['sample_output'],
'featured' => (bool) $prompt['featured'],
'public_execution_enabled' => (bool) ($prompt['public_execution_enabled'] ?? false),
'prompt_origin' => (string) ($prompt['prompt_origin'] ?? 'user'),
'source_slug' => (string) ($prompt['source_slug'] ?? ''),
'source_version' => (string) ($prompt['source_version'] ?? ''),
'links' => [
'human' => home_url('/prompt/' . rawurlencode((string) $prompt['slug']) . '/'),
],
];
if ($detail) {
$record['structured_prompt'] = is_array($prompt['structured_prompt'] ?? null)
? $prompt['structured_prompt']
: $this->decode_structured_prompt((string) ($prompt['structured_prompt_json'] ?? ''), []);
$record['structured_prompt_json'] = wp_json_encode($record['structured_prompt'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$record['instructions'] = (string) $prompt['instructions'];
$record['system_prompt'] = (string) $prompt['system_prompt'];
$record['developer_prompt'] = (string) $prompt['developer_prompt'];
$record['user_prompt_template'] = (string) $prompt['user_prompt_template'];
$record['system_steps'] = is_array($prompt['system_steps'] ?? null) ? $prompt['system_steps'] : [];
$record['system_steps_json'] = wp_json_encode($record['system_steps'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$record['spiral_script_source'] = (string) ($prompt['spiral_script_source'] ?? '');
$record['spiral_script'] = is_array($prompt['spiral_script'] ?? null) ? $prompt['spiral_script'] : [];
$record['spiral_script_validation'] = is_array($prompt['spiral_script_validation'] ?? null) ? $prompt['spiral_script_validation'] : [];
$record['spiral_script_status'] = (string) ($prompt['spiral_script_status'] ?? '');
$record['temperature'] = (float) $prompt['temperature'];
$record['max_output_tokens'] = (int) $prompt['max_output_tokens'];
$record['tool_settings_json'] = (string) $prompt['tool_settings_json'];
$record['provider'] = (string) ($prompt['provider'] ?? 'site_default');
$record['credential_preference'] = (string) ($prompt['credential_preference'] ?? 'site_default');
$record['favorite'] = (bool) ($prompt['favorite'] ?? false);
$record['editorial_note'] = (string) ($prompt['editorial_note'] ?? '');
$record['expected_output_notes'] = (string) ($prompt['expected_output_notes'] ?? '');
$record['failure_modes'] = (string) ($prompt['failure_modes'] ?? '');
$record['related_symbols'] = array_values((array) ($prompt['related_symbols'] ?? []));
$record['related_axioms'] = array_values((array) ($prompt['related_axioms'] ?? []));
$record['related_manuscripts'] = array_values((array) ($prompt['related_manuscripts'] ?? []));
}
return $record;
}
/**
* Returns a meta key with the plugin prefix.
*/
private function meta_key(string $suffix): string
{
return '_spiralist_workspace_' . sanitize_key($suffix);
}
/**
* Persists prompt meta fields.
*/
private function persist_meta(int $post_id, array $payload): void
{
$fields = [
'author_label',
'category',
'subcategory',
'structured_prompt_json',
'instructions',
'system_prompt',
'developer_prompt',
'user_prompt_template',
'system_steps_json',
'spiral_script_source',
'spiral_script_json',
'spiral_script_validation_json',
'spiral_script_status',
'model',
'provider',
'credential_preference',
'temperature',
'max_output_tokens',
'tool_settings_json',
'visibility',
'published_utc',
'is_forkable',
'allow_comments',
'allow_ratings',
'canonical_status',
'version_number',
'parent_prompt_id',
'prompt_type',
'language',
'prompt_status',
'moderation_status',
'publication_lane',
'provenance',
'risk_labels_json',
'function_tags_json',
'maturity_level',
'license',
'editorial_note',
'expected_output_notes',
'failure_modes',
'related_symbols_json',
'related_axioms_json',
'related_manuscripts_json',
'sample_output',
'featured',
'soft_deleted_at',
'public_execution_enabled',
'prompt_origin',
'source_manifest',
'source_slug',
'source_version',
'source_hash',
'source_path',
];
foreach ($fields as $field) {
$value = $payload[$field] ?? '';
if (is_bool($value)) {
$value = $value ? '1' : '0';
}
update_post_meta($post_id, $this->meta_key($field), $value);
}
}
/**
* Assigns prompt taxonomies.
*/
private function set_taxonomies(int $post_id, array $payload): void
{
wp_set_post_terms($post_id, array_values((array) ($payload['tags'] ?? [])), self::TAG_TAXONOMY, false);
if (!empty($payload['prompt_type'])) {
wp_set_post_terms($post_id, [(string) $payload['prompt_type']], self::TYPE_TAXONOMY, false);
}
if (!empty($payload['category']) && !empty($payload['subcategory'])) {