Files
html/api/opus5-skills-dispatcher.php

49 lines
1.6 KiB
PHP

<?php
// V89 Skills dispatcher API - calls v76-scripts/skill-*.sh
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$action = $_GET['action'] ?? 'list';
$skill = $_GET['skill'] ?? '';
$SCRIPTS_DIR = '/var/www/html/api/v76-scripts';
if ($action === 'list') {
$files = glob("$SCRIPTS_DIR/skill-*.sh");
$list = [];
foreach ($files as $f) {
$n = str_replace(['skill-', '.sh'], '', basename($f));
// Read description from header
$head = file_get_contents($f, false, null, 0, 400);
preg_match('/# Description: (.+)/', $head, $m);
$list[] = ['name' => $n, 'description' => $m[1] ?? '', 'size' => filesize($f)];
}
echo json_encode(['ok' => true, 'total' => count($list), 'skills' => $list], JSON_PRETTY_PRINT);
exit;
}
if ($action === 'run') {
if (!$skill || !preg_match('/^[a-z0-9\-]+$/', $skill)) {
echo json_encode(['error' => 'invalid skill name (alphanum+dash only)']);
exit;
}
$path = "$SCRIPTS_DIR/skill-$skill.sh";
if (!file_exists($path)) {
http_response_code(404);
echo json_encode(['error' => 'skill not found', 'skill' => $skill]);
exit;
}
$t0 = microtime(true);
$output = shell_exec("bash " . escapeshellarg($path) . " 2>&1");
$ms = round((microtime(true) - $t0) * 1000);
echo json_encode([
'ok' => true,
'skill' => $skill,
'output' => $output,
'ms' => $ms
], JSON_UNESCAPED_SLASHES);
exit;
}
echo json_encode(['error' => 'unknown action', 'actions' => ['list', 'run']]);