winzik/tools/notify.php

31 lines
1.3 KiB
PHP

<?php
// bin/jumphp notify / notify:login / notify:stats / notify:history / notify:mcp (tools/notify-commands.sh): the owner's push notification
// tools (docs/notifications.md). Runs in the desktop runtime image; the token folder ~/.jumphp/notify is mounted at JUMPHP_NOTIFY_HOME.
// The classes are those of the extension jumphp/notification (extensions/notification/src) and the engine's Task: no composer needed.
spl_autoload_register(static function (string $class): void {
$root = dirname(__DIR__);
foreach (['JumphpExtensions\\Notification\\' => $root . '/extensions/notification/src/', 'JumPHP\\' => $root . '/engine/src/'] as $prefix => $dir) {
if (str_starts_with($class, $prefix)) {
$file = $dir . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php';
if (is_file($file)) {
require $file;
}
return;
}
}
});
use JumphpExtensions\Notification\Tools\McpServer;
use JumphpExtensions\Notification\Tools\NotifyCli;
use JumphpExtensions\Notification\Tools\TokenStore;
$args = array_slice($argv, 1);
if (($args[0] ?? '') === 'mcp') {
// stdout is the MCP channel: errors go to stderr only
ini_set('display_errors', 'stderr');
(new McpServer(new TokenStore()))->serve(STDIN, STDOUT);
exit(0);
}
exit((new NotifyCli(new TokenStore()))->run($args));