SIMON Master Console Rebuild
True command center for SIMON + WEB360
This rebuild gives you a cleaner production spine: interactive tree, live viewer, guarded editor, dynamic graphics, architecture map, and note storage. It is designed to sit beside your existing
console.php
and become the stronger replacement path.
Dashboard
Tree
Viewer
System Map
File Registry
Notes
Files
15,360
Folders
427
Scanned Size
3.85 GB
PHP Files
948
Editable Text Files
12,616
File viewer
guarded to /htdocs
/si/_core/memory.php
<?php declare(strict_types=1); require_once __DIR__ . '/common.php'; function si_memory_dir(): string { $dir = si_core_private_root() . '/memory'; if (!is_dir($dir)) @mkdir($dir, 0700, true); return $dir; } function si_memory_id(string $contact): string { $contact = strtolower(trim($contact)); return hash('sha256', $contact !== '' ? $contact : 'anonymous'); } function si_memory_remember(string $channel, string $contact, string $role, string $text, array $meta = []): void { $text = trim($text); if ($text === '') return; $record = [ 'time' => gmdate('c'), 'channel' => $channel, 'contact' => $contact, 'role' => $role, 'text' => function_exists('mb_substr') ? mb_substr($text, 0, 4000) : substr($text, 0, 4000), 'meta' => $meta, ]; $file = si_memory_dir() . '/' . si_memory_id($contact) . '.ndjson'; @file_put_contents($file, json_encode($record, JSON_UNESCAPED_SLASHES) . PHP_EOL, FILE_APPEND | LOCK_EX); $index = si_memory_dir() . '/contacts.ndjson'; @file_put_contents($index, json_encode([ 'time' => $record['time'], 'id' => si_memory_id($contact), 'contact' => $contact, 'channel' => $channel, 'preview' => substr($text, 0, 180), ], JSON_UNESCAPED_SLASHES) . PHP_EOL, FILE_APPEND | LOCK_EX); } function si_memory_recent(string $contact, int $limit = 12): array { $file = si_memory_dir() . '/' . si_memory_id($contact) . '.ndjson'; if (!is_readable($file)) return []; $lines = array_slice(file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [], -max(1, min($limit, 50))); $rows = []; foreach ($lines as $line) { $row = json_decode($line, true); if (is_array($row)) $rows[] = $row; } return $rows; } function si_memory_name(string $contact): string { foreach (array_reverse(si_memory_recent($contact, 30)) as $row) { $text = (string) ($row['text'] ?? ''); if (preg_match('/\b(?:my name is|this is|i am|i\'m)\s+([a-z][a-z\-\']{1,30})\b/i', $text, $m)) return ucfirst(strtolower($m[1])); } return ''; } function si_memory_context(string $contact, int $limit = 10): string { $rows = si_memory_recent($contact, $limit); $parts = []; foreach ($rows as $row) $parts[] = strtoupper((string) ($row['role'] ?? 'unknown')) . ': ' . (string) ($row['text'] ?? ''); return implode("\n", $parts); } function si_memory_contact_count(): int { $files = glob(si_memory_dir() . '/*.ndjson') ?: []; return max(0, count(array_filter($files, function($f){ return basename($f) !== 'contacts.ndjson'; }))); }
Save file
Quick jump
open a path
Open