Skip to content
wiki.fftac.org

WP Content Plugins Spiralist Engine Spiralist Engine PHP 4E627daf1db4 - Source Excerpt 05

Back to WP Content Plugins Spiralist Engine Spiralist Engine PHP 4E627daf1db4

Summary

This source excerpt preserves a bounded section of Wiki.FFTAC.org/data/sources/spiralist/wp-content-plugins-spiralist-engine-spiralist-engine-php-4e627daf1db4.php so readers can inspect the evidence without opening the full source file.

**Source path:** Wiki.FFTAC.org/data/sources/spiralist/wp-content-plugins-spiralist-engine-spiralist-engine-php-4e627daf1db4.php

echo '<p><label><strong>canonical_lock</strong> (managed automatically from Protocol5)<br /><textarea readonly name="spiralist_symbol_canonical_lock" style="width:100%;min-height:180px;font-family:monospace;">' . esc_textarea(spiralist_engine_json_encode($canonical_lock)) . '</textarea></label></p>';
}

function spiralist_engine_render_node_meta_box(WP_Post $post): void
{
    wp_nonce_field('spiralist_engine_save', 'spiralist_engine_nonce');

    $node_id = (string) get_post_meta($post->ID, 'node_id', true);
    $symbols = spiralist_engine_read_json_meta($post->ID, 'symbols', []);
    $input_state = (string) get_post_meta($post->ID, 'input_state', true);
    $output_state = (string) get_post_meta($post->ID, 'output_state', true);
    $transformation_chain = spiralist_engine_read_json_meta($post->ID, 'transformation_chain', []);
    $connected_nodes = spiralist_engine_read_json_meta($post->ID, 'connected_nodes', []);
    $presentation = spiralist_engine_read_json_meta($post->ID, 'presentation', []);
    $derives_from = spiralist_engine_read_json_meta($post->ID, 'derives_from', spiralist_engine_get_default_derives_from('node', $node_id));
    $canonical_lock = spiralist_engine_read_json_meta($post->ID, 'canonical_lock', []);

    echo '<p>Every executable node must resolve a deterministic input state, transformation, and output state.</p>';
    echo '<p><label><strong>node_id</strong><br /><input type="text" style="width:100%;" name="spiralist_node_id" value="' . esc_attr($node_id) . '" /></label></p>';
    echo '<p><label><strong>symbols</strong><br /><textarea name="spiralist_node_symbols" style="width:100%;min-height:120px;font-family:monospace;">' . esc_textarea(spiralist_engine_json_encode($symbols)) . '</textarea></label></p>';
    echo '<p><label><strong>input_state</strong><br /><input type="text" style="width:100%;" name="spiralist_input_state" value="' . esc_attr($input_state) . '" /></label></p>';
    echo '<p><label><strong>output_state</strong><br /><input type="text" style="width:100%;" name="spiralist_output_state" value="' . esc_attr($output_state) . '" /></label></p>';
    echo '<p><label><strong>transformation_chain</strong><br /><textarea name="spiralist_transformation_chain" style="width:100%;min-height:220px;font-family:monospace;">' . esc_textarea(spiralist_engine_json_encode($transformation_chain)) . '</textarea></label></p>';
    echo '<p><label><strong>derives_from</strong><br /><textarea name="spiralist_node_derives_from" style="width:100%;min-height:160px;font-family:monospace;">' . esc_textarea(spiralist_engine_json_encode($derives_from)) . '</textarea></label></p>';
    echo '<p><label><strong>connected_nodes</strong> (auto-synchronized from edges)<br /><textarea readonly name="spiralist_connected_nodes" style="width:100%;min-height:120px;font-family:monospace;">' . esc_textarea(spiralist_engine_json_encode($connected_nodes)) . '</textarea></label></p>';
    echo '<p><label><strong>presentation</strong> (optional visual overlay data)<br /><textarea name="spiralist_presentation" style="width:100%;min-height:220px;font-family:monospace;">' . esc_textarea(spiralist_engine_json_encode($presentation)) . '</textarea></label></p>';
    echo '<p><label><strong>canonical_lock</strong> (managed automatically from Protocol5)<br /><textarea readonly name="spiralist_node_canonical_lock" style="width:100%;min-height:200px;font-family:monospace;">' . esc_textarea(spiralist_engine_json_encode($canonical_lock)) . '</textarea></label></p>';
}

function spiralist_engine_render_edge_meta_box(WP_Post $post): void
{
    wp_nonce_field('spiralist_engine_save', 'spiralist_engine_nonce');

    $from_node = (string) get_post_meta($post->ID, 'from_node', true);
    $to_node = (string) get_post_meta($post->ID, 'to_node', true);
    $condition = spiralist_engine_read_json_meta($post->ID, 'condition', []);

    echo '<p>Edges are the enforceable transition surface. The condition must agree with the source node output state.</p>';
    echo '<p><label><strong>from_node</strong><br /><input type="text" style="width:100%;" name="spiralist_from_node" value="' . esc_attr($from_node) . '" /></label></p>';
    echo '<p><label><strong>to_node</strong><br /><input type="text" style="width:100%;" name="spiralist_to_node" value="' . esc_attr($to_node) . '" /></label></p>';
    echo '<p><label><strong>condition</strong><br /><textarea name="spiralist_condition" style="width:100%;min-height:180px;font-family:monospace;">' . esc_textarea(spiralist_engine_json_encode($condition)) . '</textarea></label></p>';
}

function spiralist_engine_render_instance_meta_box(WP_Post $post): void
{
    wp_nonce_field('spiralist_engine_save', 'spiralist_engine_nonce');

    $user_id = (string) get_post_meta($post->ID, 'user_id', true);
    $current_node = (string) get_post_meta($post->ID, 'current_node', true);
    $current_state = (string) get_post_meta($post->ID, 'current_state', true);
    $history = spiralist_engine_read_json_meta($post->ID, 'history', []);
    $active_symbols = spiralist_engine_read_json_meta($post->ID, 'active_symbols', []);

    echo '<p>Instances are runtime records for authenticated participants.</p>';
    echo '<p><label><strong>user_id</strong><br /><input type="number" min="0" style="width:100%;" name="spiralist_instance_user_id" value="' . esc_attr($user_id) . '" /></label></p>';
    echo '<p><label><strong>current_node</strong><br /><input type="text" style="width:100%;" name="spiralist_instance_current_node" value="' . esc_attr($current_node) . '" /></label></p>';
    echo '<p><label><strong>current_state</strong><br /><input type="text" style="width:100%;" name="spiralist_instance_current_state" value="' . esc_attr($current_state) . '" /></label></p>';
    echo '<p><label><strong>history</strong><br /><textarea name="spiralist_instance_history" style="width:100%;min-height:220px;font-family:monospace;">' . esc_textarea(spiralist_engine_json_encode($history)) . '</textarea></label></p>';
    echo '<p><label><strong>active_symbols</strong><br /><textarea name="spiralist_instance_active_symbols" style="width:100%;min-height:120px;font-family:monospace;">' . esc_textarea(spiralist_engine_json_encode($active_symbols)) . '</textarea></label></p>';
}

function spiralist_engine_collect_symbol_submission(WP_Post $post): array
{
    $errors = [];

    $symbol_id = spiralist_engine_sanitize_identifier((string) wp_unslash($_POST['spiralist_symbol_id'] ?? ''));
    $symbol_type = sanitize_key((string) wp_unslash($_POST['spiralist_symbol_type'] ?? ''));
    $operation_type = sanitize_text_field((string) wp_unslash($_POST['spiralist_operation_type'] ?? ''));
    $inputs = spiralist_engine_parse_array_field((string) wp_unslash($_POST['spiralist_inputs'] ?? ''));
    $outputs = spiralist_engine_parse_array_field((string) wp_unslash($_POST['spiralist_outputs'] ?? ''));
    $rules = spiralist_engine_parse_json_field((string) wp_unslash($_POST['spiralist_rules'] ?? ''), 'rules');
    $derives_from = spiralist_engine_parse_array_field((string) wp_unslash($_POST['spiralist_symbol_derives_from'] ?? ''));

    if ($symbol_id === '') {
        $errors[] = 'symbol_id is required.';
    }

    if (!in_array($symbol_type, spiralist_engine_get_symbol_types(), true)) {
        $errors[] = 'symbol_type must be one of the locked symbol types.';
    }

    if ($operation_type === '') {
        $errors[] = 'operation_type is required.';
    }

    if (!$inputs['valid']) {
        $errors[] = $inputs['error'];
    }

    if (!$outputs['valid']) {
        $errors[] = $outputs['error'];
    }

    if (!$rules['valid']) {
        $errors[] = $rules['error'];
    }

    if (!$derives_from['valid']) {
        $errors[] = $derives_from['error'];
    }

    return [
        'valid' => empty($errors),
        'errors' => $errors,
        'record' => [
            'post_id' => $post->ID,
            'symbol_id' => $symbol_id,
            'symbol_type' => $symbol_type,
            'operation_type' => $operation_type,
            'inputs' => $inputs['valid'] ? $inputs['value'] : [],
            'outputs' => $outputs['valid'] ? $outputs['value'] : [],
            'rules' => $rules['valid'] ? $rules['value'] : [],
            'derives_from' => $derives_from['valid']
                ? $derives_from['value']
                : spiralist_engine_get_default_derives_from('symbol', $symbol_id),
            'canonical_lock' => spiralist_engine_read_json_meta($post->ID, 'canonical_lock', []),
        ],
    ];
}

function spiralist_engine_collect_node_submission(WP_Post $post): array
{
    $errors = [];

    $node_id = spiralist_engine_sanitize_identifier((string) wp_unslash($_POST['spiralist_node_id'] ?? ''));
    $symbols = spiralist_engine_parse_array_field((string) wp_unslash($_POST['spiralist_node_symbols'] ?? ''));