Scheduler: inline cron beside name, dynamic description from script headers

Cron input now sits right of the script label in the same row.
Below each row: one-line description pulled live from the script header
(PURPOSE block or first meaningful comment line) — updates whenever
scripts are edited, no plugin changes needed.
This commit is contained in:
Gmer4Lfe
2026-05-23 18:11:12 -04:00
parent fc01268c12
commit 065b29fcc8
3 changed files with 56 additions and 9 deletions
@@ -59,6 +59,36 @@ function vv_cron_rebuild(array $schedule): bool {
return file_put_contents(CRON_FILE, implode("\n", $lines)) !== false;
}
// Extract a one-line description from a bash script header.
// Supports two patterns:
// 1. # PURPOSE (or # DESCRIPTION) block — returns first non-separator line after it
// 2. First meaningful comment line after the banner
function vv_script_description(string $path): string {
if (!file_exists($path)) return '';
$lines = array_slice(file($path) ?: [], 0, 50);
$purposeNext = false;
$first = '';
foreach ($lines as $raw) {
$raw = rtrim($raw);
if (str_starts_with($raw, '#!')) continue; // shebang
if (!str_starts_with($raw, '#')) continue; // non-comment
$inner = ltrim(substr($raw, 1)); // strip leading #
if (preg_match('/^[\s=\-─━\*]+$/', $inner) || $inner === '') { // separator / blank
if ($purposeNext) continue;
continue;
}
if (preg_match('/^\s*(PURPOSE|DESCRIPTION|Description)\s*$/i', $inner)) {
$purposeNext = true;
continue;
}
if ($purposeNext) {
return mb_substr(trim($inner), 0, 200);
}
if (!$first) $first = mb_substr(trim($inner), 0, 200);
}
return $first;
}
// Walk the scripts repo and return the job tree:
// orchestrators as top-level, individual scripts as children
function vv_job_tree(): array {
@@ -76,6 +106,7 @@ function vv_job_tree(): array {
$orchs[] = [
'id' => $id,
'label' => basename($path, '.sh'),
'desc' => vv_script_description($path),
'type' => 'orchestrator',
'enabled' => (bool)($entry['enabled'] ?? false),
'cron' => $entry['cron'] ?? '',
@@ -120,6 +151,7 @@ function vv_script_children(string $orchPath, array $schedule): array {
$children[] = [
'id' => $rel,
'label' => basename($rel, '.sh'),
'desc' => vv_script_description("$scriptsDir/$rel"),
'type' => 'script',
'enabled' => (bool)($entry['enabled'] ?? false),
'cron' => $entry['cron'] ?? '',