mirror of
https://github.com/myronblair/jarvis
synced 2026-07-28 08:43:00 -05:00
Compare commits
31 Commits
main
...
f8a095f783
| Author | SHA1 | Date | |
|---|---|---|---|
| f8a095f783 | |||
| e060ff0c63 | |||
| 588cfe3f10 | |||
| 3db329e925 | |||
| c01805316a | |||
| 20b510186a | |||
| 9b5e16660a | |||
| 7020d445b3 | |||
| 80b0dfc583 | |||
| 30e2bc093c | |||
| a29670e93d | |||
| 10350cbcd8 | |||
| 24bc876c1d | |||
| cfb5b2a3f9 | |||
| 0b1a19d9de | |||
| 66a5443f22 | |||
| e5536b077c | |||
| a292411d52 | |||
| 26b501b600 | |||
| 7327104612 | |||
| a13f750846 | |||
| 3c8dd8e206 | |||
| 554488aefa | |||
| e99c3aa171 | |||
| 2528b37ea1 | |||
| 46dabe3c31 | |||
| d6a1fc9456 | |||
| 2f74b98bbc | |||
| ed15ff12dd | |||
| 3f18cec739 | |||
| 8911645c20 |
@@ -281,7 +281,7 @@ def get_uptime() -> dict:
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_services(cfg: dict) -> list:
|
def get_services(cfg: dict) -> list:
|
||||||
watch = cfg.get("watch_services", ["ollama", "homeassistant", "mysql", "nginx", "apache2"])
|
watch = cfg.get("watch_services", [])
|
||||||
statuses = []
|
statuses = []
|
||||||
for svc in watch:
|
for svc in watch:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ foreach ($svcNames as $s) {
|
|||||||
|
|
||||||
// Site health from kb_facts
|
// Site health from kb_facts
|
||||||
$siteLabels = [
|
$siteLabels = [
|
||||||
"jarvis" => "jarvis.orbishosting.com:1972",
|
"jarvis" => "jarvis.orbishosting.com",
|
||||||
"tomsjavajive" => "tomsjavajive.com",
|
"tomsjavajive" => "tomsjavajive.com",
|
||||||
"epictravelexp"=> "epictravelexpeditions.com",
|
"epictravelexp"=> "epictravelexpeditions.com",
|
||||||
"parkersling" => "parkerslingshotrentals.com",
|
"parkersling" => "parkerslingshotrentals.com",
|
||||||
|
|||||||
@@ -21,13 +21,18 @@ function collect_all(): array {
|
|||||||
|
|
||||||
// Returns true if a fact category has been updated within $secs seconds.
|
// Returns true if a fact category has been updated within $secs seconds.
|
||||||
// Prevents expensive external calls when data is still fresh.
|
// Prevents expensive external calls when data is still fresh.
|
||||||
|
// Comparison is done entirely in SQL (via NOW()) rather than PHP's time()/strtotime()
|
||||||
|
// — this file's config.php sets date_default_timezone_set('America/Chicago'), which
|
||||||
|
// makes strtotime() misinterpret MySQL's naive (UTC) datetime strings as being in
|
||||||
|
// Chicago time, throwing every freshness check off by the UTC offset (previously
|
||||||
|
// caused "sites" to always look artificially fresh and never actually refresh).
|
||||||
$fresh = function(string $cat, int $secs): bool {
|
$fresh = function(string $cat, int $secs): bool {
|
||||||
$row = JarvisDB::query(
|
$row = JarvisDB::query(
|
||||||
'SELECT updated_at FROM kb_facts WHERE category=? ORDER BY updated_at DESC LIMIT 1',
|
'SELECT (updated_at > DATE_SUB(NOW(), INTERVAL ? SECOND)) AS is_fresh FROM kb_facts WHERE category=? ORDER BY updated_at DESC LIMIT 1',
|
||||||
[$cat]
|
[$secs, $cat]
|
||||||
);
|
);
|
||||||
if (empty($row[0]['updated_at'])) return false;
|
if (empty($row)) return false;
|
||||||
return (time() - strtotime($row[0]['updated_at'])) < $secs;
|
return (bool) $row[0]['is_fresh'];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,329 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* JARVIS KB Intent Generator
|
||||||
|
* Generates 1,000+ educational KB intents via Groq LLM and imports to kb_intents table.
|
||||||
|
* Also runs a cleanup pass: deduplication, short-response pruning, pattern normalisation.
|
||||||
|
*
|
||||||
|
* CLI / cron: /usr/bin/php8.3 /var/www/jarvis/api/endpoints/kb_intent_generator.php
|
||||||
|
* Schedule: Daily – 3 am
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../config.php';
|
||||||
|
require_once __DIR__ . '/../lib/db.php';
|
||||||
|
|
||||||
|
/* ── helpers ── */
|
||||||
|
function ts(): string { return '[' . date('Y-m-d H:i:s') . ']'; }
|
||||||
|
function log_line(string $msg): void { echo ts() . ' KB Intent Generator: ' . $msg . "\n"; flush(); }
|
||||||
|
|
||||||
|
function groq(string $system, string $user, int $max = 3000, int $retries = 2): ?string {
|
||||||
|
for ($attempt = 0; $attempt <= $retries; $attempt++) {
|
||||||
|
if ($attempt > 0) {
|
||||||
|
log_line(" Retry {$attempt}/{$retries} after rate-limit pause...");
|
||||||
|
sleep(25);
|
||||||
|
}
|
||||||
|
$ch = curl_init('https://api.groq.com/openai/v1/chat/completions');
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_POST => true,
|
||||||
|
CURLOPT_TIMEOUT => 60,
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
'Authorization: Bearer ' . GROQ_API_KEY,
|
||||||
|
'Content-Type: application/json',
|
||||||
|
],
|
||||||
|
CURLOPT_POSTFIELDS => json_encode([
|
||||||
|
'model' => 'llama-3.3-70b-versatile',
|
||||||
|
'max_tokens' => $max,
|
||||||
|
'temperature' => 0.7,
|
||||||
|
'messages' => [
|
||||||
|
['role' => 'system', 'content' => $system],
|
||||||
|
['role' => 'user', 'content' => $user],
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
$raw = curl_exec($ch);
|
||||||
|
$err = curl_error($ch);
|
||||||
|
$info = curl_getinfo($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($err || !$raw) continue;
|
||||||
|
|
||||||
|
// Check for rate limit response (429)
|
||||||
|
if (($info['http_code'] ?? 0) === 429) continue;
|
||||||
|
|
||||||
|
$d = json_decode($raw, true);
|
||||||
|
$content = $d['choices'][0]['message']['content'] ?? null;
|
||||||
|
if ($content !== null) return $content;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── normalize a pattern to valid PHP PCRE ── */
|
||||||
|
function normalize_pattern(string $pat): string {
|
||||||
|
$pat = trim($pat);
|
||||||
|
// If pattern already has PCRE delimiters, leave it alone
|
||||||
|
if (preg_match('/^[\/|~#!@%]/', $pat)) return $pat;
|
||||||
|
// Strip any (?i) inline flag — we'll add /i at the delimiter level
|
||||||
|
$pat = preg_replace('/^\(\?i\)/', '', $pat);
|
||||||
|
// Escape forward slashes inside the pattern
|
||||||
|
$pat = str_replace('/', '\\/', $pat);
|
||||||
|
return '/' . $pat . '/i';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── run guard: skip if ran within last 4 hours ── */
|
||||||
|
/* Set JARVIS_FORCE_RUN=1 (env) or pass --force (argv) to bypass */
|
||||||
|
/* Comparison done in SQL (NOW()) rather than PHP time()/strtotime() — this process's
|
||||||
|
date_default_timezone_set('America/Chicago') makes strtotime() misread MySQL's naive
|
||||||
|
(UTC) timestamps as Chicago time, throwing elapsed-time checks off by the UTC offset. */
|
||||||
|
$recentRun = JarvisDB::single(
|
||||||
|
"SELECT (updated_at > DATE_SUB(NOW(), INTERVAL 14400 SECOND)) AS is_recent FROM kb_facts WHERE category='kb_generator' AND fact_key='last_run'"
|
||||||
|
);
|
||||||
|
$forceRun = !empty(getenv('JARVIS_FORCE_RUN')) || (isset($argv[1]) && $argv[1] === '--force');
|
||||||
|
if (!$forceRun && $recentRun && $recentRun['is_recent']) {
|
||||||
|
log_line('Skipping – ran within last 4 hours. Use --force to override.');
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if ($forceRun) log_line('Force-run flag set — bypassing 4-hour guard.');
|
||||||
|
|
||||||
|
log_line('Starting daily KB intent generation run.');
|
||||||
|
|
||||||
|
/* ── load active topics from database ── */
|
||||||
|
$BATCHES = JarvisDB::query(
|
||||||
|
"SELECT t.topic_id AS id, t.category, t.topic_name AS topic, t.description AS `desc`
|
||||||
|
FROM kb_generator_topics t WHERE t.active=1 ORDER BY t.id ASC"
|
||||||
|
);
|
||||||
|
if (empty($BATCHES)) {
|
||||||
|
log_line('ERROR: No active topics in kb_generator_topics table. Add topics via the JARVIS admin panel.');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
log_line('Loaded ' . count($BATCHES) . ' active topics from database.');
|
||||||
|
|
||||||
|
/* ── ROTATION ENGINE: process BATCH_SIZE topics per run, cycling through all ── */
|
||||||
|
define('BATCH_SIZE', 25);
|
||||||
|
$totalTopics = count($BATCHES);
|
||||||
|
$offsetRow = JarvisDB::single(
|
||||||
|
"SELECT CAST(fact_value AS SIGNED) AS v FROM kb_facts WHERE category='kb_generator' AND fact_key='batch_offset'"
|
||||||
|
);
|
||||||
|
$batchOffset = max(0, (int)($offsetRow['v'] ?? 0));
|
||||||
|
if ($batchOffset >= $totalTopics) $batchOffset = 0;
|
||||||
|
$nextOffset = ($batchOffset + BATCH_SIZE) % $totalTopics;
|
||||||
|
$cycleComplete = ($batchOffset + BATCH_SIZE) >= $totalTopics;
|
||||||
|
$cycleLen = (int)ceil($totalTopics / BATCH_SIZE);
|
||||||
|
|
||||||
|
$runBatches = [];
|
||||||
|
for ($i = 0; $i < BATCH_SIZE; $i++) {
|
||||||
|
$runBatches[] = $BATCHES[($batchOffset + $i) % $totalTopics];
|
||||||
|
}
|
||||||
|
$endIdx = ($batchOffset + BATCH_SIZE - 1) % $totalTopics;
|
||||||
|
log_line("Rotation: topics " . ($batchOffset + 1) . "–" . ($endIdx + 1) . " of {$totalTopics} | cycle = {$cycleLen} runs × 6h = " . ($cycleLen * 6) . "h full cycle.");
|
||||||
|
if ($cycleComplete) log_line(" ↻ Full cycle complete — restarting from topic 1 next run.");
|
||||||
|
|
||||||
|
/* ── system prompt ── */
|
||||||
|
/* RESTORED 2026-07-07: this and safe_insert() below were lost during the 2026-07-05 rotation-engine
|
||||||
|
refactor (moving from a hardcoded $BATCHES array to the kb_generator_topics table). Their absence
|
||||||
|
caused an uncaught TypeError on every run since (undefined $SYSTEM passed to groq()'s non-nullable
|
||||||
|
string param), silently swallowed by config.php's error_reporting(0) — the cron looked like it was
|
||||||
|
running fine but died instantly on batch 1 every single time. Restored from kb_intent_generator.php.bak2,
|
||||||
|
with the intent count adjusted from 40 to 20 to match this version's actual per-topic request below. */
|
||||||
|
$SYSTEM = <<<'SYS'
|
||||||
|
You are an expert educator generating KB (knowledge-base) intents for an AI assistant called JARVIS.
|
||||||
|
Each intent is a question/phrase a student might ask, paired with a clear educational answer.
|
||||||
|
|
||||||
|
Respond ONLY with a valid JSON array (no markdown, no backticks, no commentary).
|
||||||
|
Each element must have exactly these keys:
|
||||||
|
"n" – intent_name: unique snake_case identifier ≤ 60 chars, prefixed with the batch id given
|
||||||
|
"p" – pattern: a PHP PCRE regex (use (?i) for case-insensitive) that matches the question
|
||||||
|
"r" – response: a thorough but concise educational answer (2–5 sentences or a short structured list)
|
||||||
|
"c" – category: the category string provided
|
||||||
|
|
||||||
|
Rules:
|
||||||
|
- Patterns must use \\b word boundaries; escape backslashes for JSON (\\b not \b)
|
||||||
|
- Patterns should NOT start with ^ or end with $ (they are substring matches)
|
||||||
|
- Responses must be factually accurate
|
||||||
|
- Do not duplicate intent names; every "n" must be unique within this batch
|
||||||
|
- Return exactly 20 intents
|
||||||
|
SYS;
|
||||||
|
|
||||||
|
/* ── insert helper ── */
|
||||||
|
$inserted = 0;
|
||||||
|
$skipped = 0;
|
||||||
|
$errors = 0;
|
||||||
|
|
||||||
|
function safe_insert(array $intent, string $batchCategory): void {
|
||||||
|
global $inserted, $skipped, $errors;
|
||||||
|
$name = trim($intent['n'] ?? '');
|
||||||
|
$pattern = trim($intent['p'] ?? '');
|
||||||
|
$response = trim($intent['r'] ?? '');
|
||||||
|
$category = trim($intent['c'] ?? $batchCategory);
|
||||||
|
|
||||||
|
if (!$name || !$pattern || !$response) { $errors++; return; }
|
||||||
|
if (strlen($name) > 64) $name = substr($name, 0, 64);
|
||||||
|
if (strlen($pattern) > 512) $pattern = substr($pattern, 0, 512);
|
||||||
|
if (strlen($response) < 30) { $skipped++; return; } // too short
|
||||||
|
|
||||||
|
try {
|
||||||
|
JarvisDB::execute(
|
||||||
|
'INSERT INTO kb_intents (intent_name, pattern, response_template, fact_category, action_type, priority, active)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
pattern=VALUES(pattern),
|
||||||
|
response_template=VALUES(response_template),
|
||||||
|
fact_category=VALUES(fact_category)',
|
||||||
|
[$name, $pattern, $response, $category, 'response', 5, 1]
|
||||||
|
);
|
||||||
|
$inserted++;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$errors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── main generation loop ── */
|
||||||
|
$totalBatches = count($runBatches);
|
||||||
|
foreach ($runBatches as $idx => $batch) {
|
||||||
|
$num = $idx + 1;
|
||||||
|
log_line("Batch {$num}/{$totalBatches}: {$batch['topic']}");
|
||||||
|
|
||||||
|
$user = "Generate 20 KB intents for the topic: {$batch['topic']}.\n"
|
||||||
|
. "Subtopics to cover: {$batch['desc']}.\n"
|
||||||
|
. "Prefix every intent_name with \"{$batch['id']}_\".\n"
|
||||||
|
. "Category string to use: \"{$batch['category']}\".";
|
||||||
|
|
||||||
|
$raw = groq($SYSTEM, $user, 5000);
|
||||||
|
if ($raw === null) {
|
||||||
|
log_line(" ✗ API call failed after retries – skipping batch.");
|
||||||
|
$errors += 20;
|
||||||
|
sleep(8);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip markdown code fences if model added them
|
||||||
|
$raw = preg_replace('/^```(?:json)?\s*/m', '', $raw);
|
||||||
|
$raw = preg_replace('/^```\s*/m', '', $raw);
|
||||||
|
$raw = trim($raw);
|
||||||
|
|
||||||
|
// Extract JSON array; fall back to partial recovery for truncated responses
|
||||||
|
$items = null;
|
||||||
|
if (preg_match('/\[\s*\{.*\}\s*\]/s', $raw, $m)) {
|
||||||
|
$items = json_decode($m[0], true);
|
||||||
|
if (!is_array($items)) {
|
||||||
|
log_line(" ✗ JSON parse failed – skipping batch.");
|
||||||
|
$errors += 20; sleep(8); continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$start = strpos($raw, '[');
|
||||||
|
if ($start !== false) {
|
||||||
|
$partial = substr($raw, $start);
|
||||||
|
if (preg_match_all('/\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}/s', $partial, $objs) && !empty($objs[0])) {
|
||||||
|
$recovered = '[' . implode(',', $objs[0]) . ']';
|
||||||
|
$items = json_decode($recovered, true);
|
||||||
|
if (is_array($items) && count($items) > 0)
|
||||||
|
log_line(" ⚠ Truncated — recovered " . count($items) . " items.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!is_array($items) || count($items) === 0) {
|
||||||
|
log_line(" ✗ No JSON array found — raw[0:120]: " . substr(str_replace("\n", ' ', $raw), 0, 120));
|
||||||
|
$errors += 20; sleep(8); continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$batchInserted = 0;
|
||||||
|
foreach ($items as $item) {
|
||||||
|
if (!is_array($item)) continue;
|
||||||
|
safe_insert($item, $batch['category']);
|
||||||
|
$batchInserted++;
|
||||||
|
}
|
||||||
|
log_line(" ✓ Parsed {$batchInserted} intents (running total inserted: {$inserted}).");
|
||||||
|
|
||||||
|
// Polite delay between API calls — Groq TPM limit needs ~8s between batches
|
||||||
|
if ($num < $totalBatches) sleep(8);
|
||||||
|
}
|
||||||
|
|
||||||
|
log_line("Generation complete. Inserted/updated: {$inserted} | Short/invalid skipped: {$skipped} | Errors: {$errors}");
|
||||||
|
|
||||||
|
/* ── cleanup phase ── */
|
||||||
|
log_line('Starting cleanup phase...');
|
||||||
|
|
||||||
|
// 1. Remove exact duplicate intent_names (keep the one with the longer response)
|
||||||
|
$dups = JarvisDB::query(
|
||||||
|
'SELECT intent_name, COUNT(*) AS cnt FROM kb_intents GROUP BY intent_name HAVING cnt > 1'
|
||||||
|
);
|
||||||
|
$dupsPruned = 0;
|
||||||
|
foreach ($dups as $dup) {
|
||||||
|
$rows = JarvisDB::query(
|
||||||
|
'SELECT id, LENGTH(response_template) AS rlen FROM kb_intents WHERE intent_name=? ORDER BY rlen DESC',
|
||||||
|
[$dup['intent_name']]
|
||||||
|
);
|
||||||
|
array_shift($rows);
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
JarvisDB::execute('DELETE FROM kb_intents WHERE id=?', [$row['id']]);
|
||||||
|
$dupsPruned++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log_line(" Duplicate intent_names pruned: {$dupsPruned}");
|
||||||
|
|
||||||
|
// 2. Remove intents with very short responses (< 40 chars)
|
||||||
|
$shortPruned = JarvisDB::execute(
|
||||||
|
"DELETE FROM kb_intents WHERE LENGTH(response_template) < 40 AND priority <= 5"
|
||||||
|
);
|
||||||
|
log_line(" Short-response rows pruned: {$shortPruned}");
|
||||||
|
|
||||||
|
// 3. Trim whitespace on all generated intents
|
||||||
|
JarvisDB::execute(
|
||||||
|
"UPDATE kb_intents SET
|
||||||
|
intent_name = TRIM(intent_name),
|
||||||
|
pattern = TRIM(pattern),
|
||||||
|
response_template = TRIM(response_template),
|
||||||
|
fact_category = TRIM(fact_category)
|
||||||
|
WHERE priority = 5"
|
||||||
|
);
|
||||||
|
log_line(' Whitespace trimmed on all generated intents.');
|
||||||
|
|
||||||
|
// 4. Fix and validate PCRE patterns — normalize then deactivate only truly broken ones
|
||||||
|
$all = JarvisDB::query('SELECT id, pattern FROM kb_intents WHERE priority=5');
|
||||||
|
$badPattern = 0;
|
||||||
|
$fixedPattern = 0;
|
||||||
|
foreach ($all as $row) {
|
||||||
|
$pat = normalize_pattern($row['pattern']);
|
||||||
|
if ($pat !== $row['pattern']) {
|
||||||
|
// Update to normalized form
|
||||||
|
JarvisDB::execute('UPDATE kb_intents SET pattern=?, active=1 WHERE id=?', [$pat, $row['id']]);
|
||||||
|
$fixedPattern++;
|
||||||
|
} elseif (@preg_match($pat, '') === false) {
|
||||||
|
JarvisDB::execute('UPDATE kb_intents SET active=0 WHERE id=?', [$row['id']]);
|
||||||
|
$badPattern++;
|
||||||
|
} else {
|
||||||
|
// Valid pattern — make sure it's active
|
||||||
|
JarvisDB::execute('UPDATE kb_intents SET active=1 WHERE id=?', [$row['id']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log_line(" Patterns normalized: {$fixedPattern} | Bad PCRE deactivated: {$badPattern}");
|
||||||
|
|
||||||
|
// 5. Enable ALL remaining inactive intents (including pre-existing ones)
|
||||||
|
$reactivated = JarvisDB::execute('UPDATE kb_intents SET active=1 WHERE active=0 AND priority <= 5');
|
||||||
|
log_line(" Re-activated previously inactive intents: {$reactivated}");
|
||||||
|
|
||||||
|
// 6. Final stats
|
||||||
|
$stats = JarvisDB::single('SELECT COUNT(*) AS total, SUM(active) AS active FROM kb_intents');
|
||||||
|
log_line("Final KB Intents table: {$stats['total']} total, {$stats['active']} active.");
|
||||||
|
|
||||||
|
/* ── record last-run timestamp ── */
|
||||||
|
JarvisDB::execute(
|
||||||
|
"INSERT INTO kb_facts (category, fact_key, fact_value, host)
|
||||||
|
VALUES ('kb_generator', 'last_run', NOW(), 'local')
|
||||||
|
ON DUPLICATE KEY UPDATE fact_value=NOW(), updated_at=NOW()",
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
JarvisDB::execute(
|
||||||
|
"INSERT INTO kb_facts (category, fact_key, fact_value, host)
|
||||||
|
VALUES ('kb_generator', 'batch_offset', ?, 'local')
|
||||||
|
ON DUPLICATE KEY UPDATE fact_value=VALUES(fact_value), updated_at=NOW()",
|
||||||
|
[$nextOffset]
|
||||||
|
);
|
||||||
|
log_line("Next run will start at topic offset {$nextOffset}/{$totalTopics}.");
|
||||||
|
JarvisDB::execute(
|
||||||
|
"INSERT INTO kb_facts (category, fact_key, fact_value, host)
|
||||||
|
VALUES ('kb_generator', 'last_inserted', ?, 'local')
|
||||||
|
ON DUPLICATE KEY UPDATE fact_value=VALUES(fact_value), updated_at=NOW()",
|
||||||
|
[$inserted]
|
||||||
|
);
|
||||||
|
|
||||||
|
log_line('Done.');
|
||||||
@@ -0,0 +1,284 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* JARVIS KB Intent Generator
|
||||||
|
* Generates 1,000+ educational KB intents via Groq LLM and imports to kb_intents table.
|
||||||
|
* Also runs a cleanup pass: deduplication, short-response pruning, pattern normalisation.
|
||||||
|
*
|
||||||
|
* CLI / cron: /usr/bin/php8.3 /var/www/jarvis/api/endpoints/kb_intent_generator.php
|
||||||
|
* Schedule: Weekly – Sunday 3 am
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../config.php';
|
||||||
|
require_once __DIR__ . '/../lib/db.php';
|
||||||
|
|
||||||
|
/* ── helpers ── */
|
||||||
|
function ts(): string { return '[' . date('Y-m-d H:i:s') . ']'; }
|
||||||
|
function log_line(string $msg): void { echo ts() . ' KB Intent Generator: ' . $msg . "\n"; flush(); }
|
||||||
|
function groq(string $system, string $user, int $max = 3000): ?string {
|
||||||
|
$ch = curl_init('https://api.groq.com/openai/v1/chat/completions');
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_POST => true,
|
||||||
|
CURLOPT_TIMEOUT => 60,
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
'Authorization: Bearer ' . GROQ_API_KEY,
|
||||||
|
'Content-Type: application/json',
|
||||||
|
],
|
||||||
|
CURLOPT_POSTFIELDS => json_encode([
|
||||||
|
'model' => 'llama-3.3-70b-versatile',
|
||||||
|
'max_tokens' => $max,
|
||||||
|
'temperature' => 0.7,
|
||||||
|
'messages' => [
|
||||||
|
['role' => 'system', 'content' => $system],
|
||||||
|
['role' => 'user', 'content' => $user],
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
$raw = curl_exec($ch);
|
||||||
|
$err = curl_error($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
if ($err || !$raw) return null;
|
||||||
|
$d = json_decode($raw, true);
|
||||||
|
return $d['choices'][0]['message']['content'] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── daily guard: skip if already ran within last 20 hours ── */
|
||||||
|
$lastRun = JarvisDB::single(
|
||||||
|
"SELECT updated_at FROM kb_facts WHERE category='kb_generator' AND fact_key='last_run'"
|
||||||
|
);
|
||||||
|
if ($lastRun && (time() - strtotime($lastRun['updated_at'])) < 72000) {
|
||||||
|
log_line('Skipping – ran within last 6 days (next run Sunday 3am).');
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
log_line('Starting weekly KB intent generation run.');
|
||||||
|
|
||||||
|
/* ── topic batches (25 topics × ~40 intents = 1,000+) ── */
|
||||||
|
$BATCHES = [
|
||||||
|
['id' => 'math_elem', 'category' => 'math_elementary', 'topic' => 'Elementary school mathematics',
|
||||||
|
'desc' => 'counting, basic arithmetic, place value, simple fractions, 2D/3D shapes, measurement, telling time, money, patterns'],
|
||||||
|
['id' => 'math_mid', 'category' => 'math_middle', 'topic' => 'Middle school mathematics',
|
||||||
|
'desc' => 'ratios, percentages, integers, exponents, pre-algebra equations, coordinate planes, probability, statistics (mean/median/mode), geometry area/volume'],
|
||||||
|
['id' => 'math_high', 'category' => 'math_high', 'topic' => 'High school mathematics',
|
||||||
|
'desc' => 'quadratic equations, polynomials, functions, logarithms, trigonometry (SOH-CAH-TOA, unit circle), sequences, permutations and combinations, matrices'],
|
||||||
|
['id' => 'math_college', 'category' => 'math_college', 'topic' => 'College-level mathematics',
|
||||||
|
'desc' => 'limits and continuity, derivatives, integrals, chain rule, L\'Hopital, differential equations, vectors, eigenvalues, hypothesis testing, normal distribution'],
|
||||||
|
['id' => 'bio_cell', 'category' => 'biology', 'topic' => 'Cell biology and genetics',
|
||||||
|
'desc' => 'organelles, mitosis vs meiosis, DNA structure, protein synthesis (transcription/translation), Mendelian genetics, dominant/recessive, mutations, genetic disorders'],
|
||||||
|
['id' => 'bio_body', 'category' => 'biology', 'topic' => 'Human body systems',
|
||||||
|
'desc' => 'skeletal, muscular, cardiovascular, respiratory, digestive, nervous, endocrine, immune, reproductive, and excretory systems'],
|
||||||
|
['id' => 'bio_ecology', 'category' => 'biology', 'topic' => 'Ecology and evolution',
|
||||||
|
'desc' => 'ecosystems, biomes, food webs, trophic levels, symbiosis (mutualism/commensalism/parasitism), natural selection, adaptation, speciation, biodiversity'],
|
||||||
|
['id' => 'chem_basics', 'category' => 'chemistry', 'topic' => 'Chemistry fundamentals',
|
||||||
|
'desc' => 'atomic structure, periodic table trends, ionic vs covalent bonds, Lewis structures, polarity, molecular geometry (VSEPR), intermolecular forces'],
|
||||||
|
['id' => 'chem_rxns', 'category' => 'chemistry', 'topic' => 'Chemical reactions and thermochemistry',
|
||||||
|
'desc' => 'balancing equations, stoichiometry, limiting reagents, reaction types, enthalpy, entropy, Gibbs free energy, Le Chatelier\'s principle, equilibrium constants'],
|
||||||
|
['id' => 'phys_mech', 'category' => 'physics', 'topic' => 'Physics – mechanics and energy',
|
||||||
|
'desc' => 'kinematics, Newton\'s three laws, friction, momentum, conservation of energy, work and power, circular motion, gravitation, projectile motion'],
|
||||||
|
['id' => 'phys_em', 'category' => 'physics', 'topic' => 'Physics – waves, electricity and magnetism',
|
||||||
|
'desc' => 'wave properties (amplitude, frequency, wavelength), sound, light spectrum, reflection/refraction, Ohm\'s law, series vs parallel circuits, magnetic fields, electromagnetic induction'],
|
||||||
|
['id' => 'earth_sci', 'category' => 'earth_science', 'topic' => 'Earth and environmental science',
|
||||||
|
'desc' => 'rock cycle, plate tectonics, earthquakes, volcanoes, atmosphere layers, weather vs climate, greenhouse effect, water cycle, ocean currents, soil formation'],
|
||||||
|
['id' => 'astronomy', 'category' => 'astronomy', 'topic' => 'Astronomy and space science',
|
||||||
|
'desc' => 'solar system planets, star life cycles, galaxies, Big Bang theory, light-years, telescopes, space exploration milestones, dark matter/energy, black holes'],
|
||||||
|
['id' => 'hist_us', 'category' => 'history_us', 'topic' => 'United States history',
|
||||||
|
'desc' => 'colonial era, American Revolution, Constitution, westward expansion, Civil War, Reconstruction, Gilded Age, WWI, Great Depression, WWII, Civil Rights, Cold War, modern era'],
|
||||||
|
['id' => 'hist_world', 'category' => 'history_world', 'topic' => 'World history',
|
||||||
|
'desc' => 'ancient civilisations (Egypt, Greece, Rome, Mesopotamia, China, India), Medieval period, Renaissance, Reformation, age of exploration, colonialism, Industrial Revolution, WWI, WWII, decolonisation, Cold War'],
|
||||||
|
['id' => 'geo_world', 'category' => 'geography', 'topic' => 'World geography',
|
||||||
|
'desc' => 'continents and oceans, countries and capitals, physical features (mountains, rivers, deserts), climate zones, latitude/longitude, map projections, time zones, population distribution'],
|
||||||
|
['id' => 'civics', 'category' => 'civics', 'topic' => 'Civics and US government',
|
||||||
|
'desc' => 'three branches of government, checks and balances, Bill of Rights, Constitutional amendments, federalism, Electoral College, legislative process, Supreme Court landmark cases, political parties'],
|
||||||
|
['id' => 'econ', 'category' => 'economics', 'topic' => 'Economics',
|
||||||
|
'desc' => 'supply and demand, market equilibrium, elasticity, GDP, inflation, unemployment, fiscal vs monetary policy, comparative advantage, market structures (monopoly, oligopoly, perfect competition), opportunity cost'],
|
||||||
|
['id' => 'lit_writing', 'category' => 'literature', 'topic' => 'Literature and writing',
|
||||||
|
'desc' => 'figurative language (simile, metaphor, personification, irony), plot structure, literary themes, point of view, genre types, essay structure, thesis statements, grammar rules, poetry forms, citing sources'],
|
||||||
|
['id' => 'cs_prog', 'category' => 'computer_science', 'topic' => 'Computer science and programming',
|
||||||
|
'desc' => 'variables, data types, loops, conditionals, functions, OOP concepts, arrays/lists, sorting and searching algorithms, time/space complexity, binary, hexadecimal, recursion, debugging'],
|
||||||
|
['id' => 'cs_systems', 'category' => 'computer_science', 'topic' => 'Computer systems and networking',
|
||||||
|
'desc' => 'CPU/RAM/storage, operating systems, file systems, TCP/IP, DNS, HTTP/HTTPS, databases (SQL vs NoSQL), cybersecurity threats (phishing, SQL injection, XSS, malware), encryption basics, cloud computing'],
|
||||||
|
['id' => 'psych', 'category' => 'psychology', 'topic' => 'Psychology',
|
||||||
|
'desc' => 'classical and operant conditioning, Maslow\'s hierarchy, Piaget\'s stages, Erikson\'s stages, memory types, sleep stages, cognitive biases, Freud\'s theory, social influence, abnormal psychology basics'],
|
||||||
|
['id' => 'phil', 'category' => 'philosophy', 'topic' => 'Philosophy and logic',
|
||||||
|
'desc' => 'Socrates/Plato/Aristotle, ethical theories (utilitarianism, deontology, virtue ethics), epistemology, deductive vs inductive reasoning, logical fallacies, existentialism, free will vs determinism, political philosophy'],
|
||||||
|
['id' => 'health_sci', 'category' => 'health', 'topic' => 'Health and life skills',
|
||||||
|
'desc' => 'nutrition (macronutrients, vitamins, minerals), exercise physiology, mental health (anxiety, depression, stress response), reproductive health, substance abuse, first aid, disease prevention, sleep hygiene'],
|
||||||
|
['id' => 'arts_music', 'category' => 'arts', 'topic' => 'Arts and music',
|
||||||
|
'desc' => 'elements of art (line, shape, color, texture), colour theory, major art movements, famous artists and their works, music notes and scales, rhythm and meter, instrument families, major composers and genres'],
|
||||||
|
];
|
||||||
|
|
||||||
|
/* ── system prompt ── */
|
||||||
|
$SYSTEM = <<<'SYS'
|
||||||
|
You are an expert educator generating KB (knowledge-base) intents for an AI assistant called JARVIS.
|
||||||
|
Each intent is a question/phrase a student might ask, paired with a clear educational answer.
|
||||||
|
|
||||||
|
Respond ONLY with a valid JSON array (no markdown, no backticks, no commentary).
|
||||||
|
Each element must have exactly these keys:
|
||||||
|
"n" – intent_name: unique snake_case identifier ≤ 60 chars, prefixed with the batch id given
|
||||||
|
"p" – pattern: a PHP PCRE regex (use (?i) for case-insensitive) that matches the question
|
||||||
|
"r" – response: a thorough but concise educational answer (2–5 sentences or a short structured list)
|
||||||
|
"c" – category: the category string provided
|
||||||
|
|
||||||
|
Rules:
|
||||||
|
- Patterns must use \\b word boundaries; escape backslashes for JSON (\\b not \b)
|
||||||
|
- Patterns should NOT start with ^ or end with $ (they are substring matches)
|
||||||
|
- Responses must be factually accurate
|
||||||
|
- Do not duplicate intent names; every "n" must be unique within this batch
|
||||||
|
- Return exactly 40 intents
|
||||||
|
SYS;
|
||||||
|
|
||||||
|
/* ── insert helper ── */
|
||||||
|
$inserted = 0;
|
||||||
|
$skipped = 0;
|
||||||
|
$errors = 0;
|
||||||
|
|
||||||
|
function safe_insert(array $intent, string $batchCategory): void {
|
||||||
|
global $inserted, $skipped, $errors;
|
||||||
|
$name = trim($intent['n'] ?? '');
|
||||||
|
$pattern = trim($intent['p'] ?? '');
|
||||||
|
$response = trim($intent['r'] ?? '');
|
||||||
|
$category = trim($intent['c'] ?? $batchCategory);
|
||||||
|
|
||||||
|
if (!$name || !$pattern || !$response) { $errors++; return; }
|
||||||
|
if (strlen($name) > 64) $name = substr($name, 0, 64);
|
||||||
|
if (strlen($pattern) > 512) $pattern = substr($pattern, 0, 512);
|
||||||
|
if (strlen($response) < 30) { $skipped++; return; } // too short
|
||||||
|
|
||||||
|
try {
|
||||||
|
JarvisDB::execute(
|
||||||
|
'INSERT INTO kb_intents (intent_name, pattern, response_template, fact_category, action_type, priority, active)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
pattern=VALUES(pattern),
|
||||||
|
response_template=VALUES(response_template),
|
||||||
|
fact_category=VALUES(fact_category)',
|
||||||
|
[$name, $pattern, $response, $category, 'response', 5, 1]
|
||||||
|
);
|
||||||
|
$inserted++;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$errors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── main generation loop ── */
|
||||||
|
$totalBatches = count($BATCHES);
|
||||||
|
foreach ($BATCHES as $idx => $batch) {
|
||||||
|
$num = $idx + 1;
|
||||||
|
log_line("Batch {$num}/{$totalBatches}: {$batch['topic']}");
|
||||||
|
|
||||||
|
$user = "Generate 40 KB intents for the topic: {$batch['topic']}.\n"
|
||||||
|
. "Subtopics to cover: {$batch['desc']}.\n"
|
||||||
|
. "Prefix every intent_name with \"{$batch['id']}_\".\n"
|
||||||
|
. "Category string to use: \"{$batch['category']}\".";
|
||||||
|
|
||||||
|
$raw = groq($SYSTEM, $user, 3500);
|
||||||
|
if ($raw === null) {
|
||||||
|
log_line(" ✗ API call failed – skipping batch.");
|
||||||
|
$errors += 40;
|
||||||
|
sleep(3);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip markdown code fences if model added them
|
||||||
|
$raw = preg_replace('/^```(?:json)?\s*/m', '', $raw);
|
||||||
|
$raw = preg_replace('/^```\s*/m', '', $raw);
|
||||||
|
$raw = trim($raw);
|
||||||
|
|
||||||
|
// Extract JSON array (even if the model added preamble text)
|
||||||
|
if (!preg_match('/\[\s*\{.*\}\s*\]/s', $raw, $m)) {
|
||||||
|
log_line(" ✗ No JSON array found in response – skipping batch.");
|
||||||
|
$errors += 40;
|
||||||
|
sleep(2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$items = json_decode($m[0], true);
|
||||||
|
if (!is_array($items)) {
|
||||||
|
log_line(" ✗ JSON parse failed – skipping batch.");
|
||||||
|
$errors += 40;
|
||||||
|
sleep(2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$batchInserted = 0;
|
||||||
|
foreach ($items as $item) {
|
||||||
|
if (!is_array($item)) continue;
|
||||||
|
safe_insert($item, $batch['category']);
|
||||||
|
$batchInserted++;
|
||||||
|
}
|
||||||
|
log_line(" ✓ Parsed {$batchInserted} intents (running total inserted: {$inserted}).");
|
||||||
|
|
||||||
|
// Polite delay between API calls to avoid rate limiting
|
||||||
|
if ($num < $totalBatches) sleep(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
log_line("Generation complete. Inserted/updated: {$inserted} | Short/invalid skipped: {$skipped} | Errors: {$errors}");
|
||||||
|
|
||||||
|
/* ── cleanup phase ── */
|
||||||
|
log_line('Starting cleanup phase...');
|
||||||
|
|
||||||
|
// 1. Remove exact duplicate intent_names (keep the one with the longer response)
|
||||||
|
$dups = JarvisDB::query(
|
||||||
|
'SELECT intent_name, COUNT(*) AS cnt FROM kb_intents GROUP BY intent_name HAVING cnt > 1'
|
||||||
|
);
|
||||||
|
$dupsPruned = 0;
|
||||||
|
foreach ($dups as $dup) {
|
||||||
|
$rows = JarvisDB::query(
|
||||||
|
'SELECT id, LENGTH(response_template) AS rlen FROM kb_intents WHERE intent_name=? ORDER BY rlen DESC',
|
||||||
|
[$dup['intent_name']]
|
||||||
|
);
|
||||||
|
// Delete all but the first (longest response)
|
||||||
|
array_shift($rows);
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
JarvisDB::execute('DELETE FROM kb_intents WHERE id=?', [$row['id']]);
|
||||||
|
$dupsPruned++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log_line(" Duplicate intent_names pruned: {$dupsPruned}");
|
||||||
|
|
||||||
|
// 2. Remove intents with very short responses (< 40 chars) — likely garbage
|
||||||
|
$shortPruned = JarvisDB::execute(
|
||||||
|
"DELETE FROM kb_intents WHERE LENGTH(response_template) < 40 AND priority <= 5"
|
||||||
|
);
|
||||||
|
log_line(" Short-response rows pruned: {$shortPruned}");
|
||||||
|
|
||||||
|
// 3. Trim whitespace on all text columns for the auto-generated ones
|
||||||
|
JarvisDB::execute(
|
||||||
|
"UPDATE kb_intents SET
|
||||||
|
intent_name = TRIM(intent_name),
|
||||||
|
pattern = TRIM(pattern),
|
||||||
|
response_template = TRIM(response_template),
|
||||||
|
fact_category = TRIM(fact_category)
|
||||||
|
WHERE priority = 5"
|
||||||
|
);
|
||||||
|
log_line(' Whitespace trimmed on all generated intents.');
|
||||||
|
|
||||||
|
// 4. Deactivate intents whose pattern is invalid PCRE
|
||||||
|
$all = JarvisDB::query('SELECT id, pattern FROM kb_intents WHERE active=1 AND priority=5');
|
||||||
|
$badPattern = 0;
|
||||||
|
foreach ($all as $row) {
|
||||||
|
if (@preg_match($row['pattern'], '') === false) {
|
||||||
|
JarvisDB::execute('UPDATE kb_intents SET active=0 WHERE id=?', [$row['id']]);
|
||||||
|
$badPattern++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log_line(" Bad PCRE patterns deactivated: {$badPattern}");
|
||||||
|
|
||||||
|
// 5. Stats
|
||||||
|
$stats = JarvisDB::single('SELECT COUNT(*) AS total, SUM(active) AS active FROM kb_intents');
|
||||||
|
log_line("Final KB Intents table: {$stats['total']} total, {$stats['active']} active.");
|
||||||
|
|
||||||
|
/* ── record last-run timestamp in kb_facts ── */
|
||||||
|
JarvisDB::execute(
|
||||||
|
"INSERT INTO kb_facts (category, fact_key, fact_value, host)
|
||||||
|
VALUES ('kb_generator', 'last_run', NOW(), 'local')
|
||||||
|
ON DUPLICATE KEY UPDATE fact_value=NOW(), updated_at=NOW()",
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
JarvisDB::execute(
|
||||||
|
"INSERT INTO kb_facts (category, fact_key, fact_value, host)
|
||||||
|
VALUES ('kb_generator', 'last_inserted', ?, 'local')
|
||||||
|
ON DUPLICATE KEY UPDATE fact_value=VALUES(fact_value), updated_at=NOW()",
|
||||||
|
[$inserted]
|
||||||
|
);
|
||||||
|
|
||||||
|
log_line('Done.');
|
||||||
@@ -0,0 +1,270 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* JARVIS KB Intent Generator
|
||||||
|
* Generates 1,000+ educational KB intents via Groq LLM and imports to kb_intents table.
|
||||||
|
* Also runs a cleanup pass: deduplication, short-response pruning, pattern normalisation.
|
||||||
|
*
|
||||||
|
* CLI / cron: /usr/bin/php8.3 /var/www/jarvis/api/endpoints/kb_intent_generator.php
|
||||||
|
* Schedule: Daily – 3 am
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../config.php';
|
||||||
|
require_once __DIR__ . '/../lib/db.php';
|
||||||
|
|
||||||
|
/* ── helpers ── */
|
||||||
|
function ts(): string { return '[' . date('Y-m-d H:i:s') . ']'; }
|
||||||
|
function log_line(string $msg): void { echo ts() . ' KB Intent Generator: ' . $msg . "\n"; flush(); }
|
||||||
|
|
||||||
|
function groq(string $system, string $user, int $max = 3000, int $retries = 2): ?string {
|
||||||
|
for ($attempt = 0; $attempt <= $retries; $attempt++) {
|
||||||
|
if ($attempt > 0) {
|
||||||
|
log_line(" Retry {$attempt}/{$retries} after rate-limit pause...");
|
||||||
|
sleep(25);
|
||||||
|
}
|
||||||
|
$ch = curl_init('https://api.groq.com/openai/v1/chat/completions');
|
||||||
|
curl_setopt_array($ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_POST => true,
|
||||||
|
CURLOPT_TIMEOUT => 60,
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
'Authorization: Bearer ' . GROQ_API_KEY,
|
||||||
|
'Content-Type: application/json',
|
||||||
|
],
|
||||||
|
CURLOPT_POSTFIELDS => json_encode([
|
||||||
|
'model' => 'llama-3.3-70b-versatile',
|
||||||
|
'max_tokens' => $max,
|
||||||
|
'temperature' => 0.7,
|
||||||
|
'messages' => [
|
||||||
|
['role' => 'system', 'content' => $system],
|
||||||
|
['role' => 'user', 'content' => $user],
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
$raw = curl_exec($ch);
|
||||||
|
$err = curl_error($ch);
|
||||||
|
$info = curl_getinfo($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if ($err || !$raw) continue;
|
||||||
|
|
||||||
|
// Check for rate limit response (429)
|
||||||
|
if (($info['http_code'] ?? 0) === 429) continue;
|
||||||
|
|
||||||
|
$d = json_decode($raw, true);
|
||||||
|
$content = $d['choices'][0]['message']['content'] ?? null;
|
||||||
|
if ($content !== null) return $content;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── normalize a pattern to valid PHP PCRE ── */
|
||||||
|
function normalize_pattern(string $pat): string {
|
||||||
|
$pat = trim($pat);
|
||||||
|
// If pattern already has PCRE delimiters, leave it alone
|
||||||
|
if (preg_match('/^[\/|~#!@%]/', $pat)) return $pat;
|
||||||
|
// Strip any (?i) inline flag — we'll add /i at the delimiter level
|
||||||
|
$pat = preg_replace('/^\(\?i\)/', '', $pat);
|
||||||
|
// Escape forward slashes inside the pattern
|
||||||
|
$pat = str_replace('/', '\\/', $pat);
|
||||||
|
return '/' . $pat . '/i';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── run guard: skip if ran within last 4 hours ── */
|
||||||
|
/* Set JARVIS_FORCE_RUN=1 (env) or pass --force (argv) to bypass */
|
||||||
|
/* Comparison done in SQL (NOW()) rather than PHP time()/strtotime() — this process's
|
||||||
|
date_default_timezone_set('America/Chicago') makes strtotime() misread MySQL's naive
|
||||||
|
(UTC) timestamps as Chicago time, throwing elapsed-time checks off by the UTC offset. */
|
||||||
|
$recentRun = JarvisDB::single(
|
||||||
|
"SELECT (updated_at > DATE_SUB(NOW(), INTERVAL 14400 SECOND)) AS is_recent FROM kb_facts WHERE category='kb_generator' AND fact_key='last_run'"
|
||||||
|
);
|
||||||
|
$forceRun = !empty(getenv('JARVIS_FORCE_RUN')) || (isset($argv[1]) && $argv[1] === '--force');
|
||||||
|
if (!$forceRun && $recentRun && $recentRun['is_recent']) {
|
||||||
|
log_line('Skipping – ran within last 4 hours. Use --force to override.');
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if ($forceRun) log_line('Force-run flag set — bypassing 4-hour guard.');
|
||||||
|
|
||||||
|
log_line('Starting daily KB intent generation run.');
|
||||||
|
|
||||||
|
/* ── load active topics from database ── */
|
||||||
|
$BATCHES = JarvisDB::query(
|
||||||
|
"SELECT t.topic_id AS id, t.category, t.topic_name AS topic, t.description AS `desc`
|
||||||
|
FROM kb_generator_topics t WHERE t.active=1 ORDER BY t.id ASC"
|
||||||
|
);
|
||||||
|
if (empty($BATCHES)) {
|
||||||
|
log_line('ERROR: No active topics in kb_generator_topics table. Add topics via the JARVIS admin panel.');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
log_line('Loaded ' . count($BATCHES) . ' active topics from database.');
|
||||||
|
|
||||||
|
/* ── ROTATION ENGINE: process BATCH_SIZE topics per run, cycling through all ── */
|
||||||
|
define('BATCH_SIZE', 25);
|
||||||
|
$totalTopics = count($BATCHES);
|
||||||
|
$offsetRow = JarvisDB::single(
|
||||||
|
"SELECT CAST(fact_value AS SIGNED) AS v FROM kb_facts WHERE category='kb_generator' AND fact_key='batch_offset'"
|
||||||
|
);
|
||||||
|
$batchOffset = max(0, (int)($offsetRow['v'] ?? 0));
|
||||||
|
if ($batchOffset >= $totalTopics) $batchOffset = 0;
|
||||||
|
$nextOffset = ($batchOffset + BATCH_SIZE) % $totalTopics;
|
||||||
|
$cycleComplete = ($batchOffset + BATCH_SIZE) >= $totalTopics;
|
||||||
|
$cycleLen = (int)ceil($totalTopics / BATCH_SIZE);
|
||||||
|
|
||||||
|
$runBatches = [];
|
||||||
|
for ($i = 0; $i < BATCH_SIZE; $i++) {
|
||||||
|
$runBatches[] = $BATCHES[($batchOffset + $i) % $totalTopics];
|
||||||
|
}
|
||||||
|
$endIdx = ($batchOffset + BATCH_SIZE - 1) % $totalTopics;
|
||||||
|
log_line("Rotation: topics " . ($batchOffset + 1) . "–" . ($endIdx + 1) . " of {$totalTopics} | cycle = {$cycleLen} runs × 6h = " . ($cycleLen * 6) . "h full cycle.");
|
||||||
|
if ($cycleComplete) log_line(" ↻ Full cycle complete — restarting from topic 1 next run.");
|
||||||
|
|
||||||
|
/* ── main generation loop ── */
|
||||||
|
$totalBatches = count($runBatches);
|
||||||
|
foreach ($runBatches as $idx => $batch) {
|
||||||
|
$num = $idx + 1;
|
||||||
|
log_line("Batch {$num}/{$totalBatches}: {$batch['topic']}");
|
||||||
|
|
||||||
|
$user = "Generate 20 KB intents for the topic: {$batch['topic']}.\n"
|
||||||
|
. "Subtopics to cover: {$batch['desc']}.\n"
|
||||||
|
. "Prefix every intent_name with \"{$batch['id']}_\".\n"
|
||||||
|
. "Category string to use: \"{$batch['category']}\".";
|
||||||
|
|
||||||
|
$raw = groq($SYSTEM, $user, 5000);
|
||||||
|
if ($raw === null) {
|
||||||
|
log_line(" ✗ API call failed after retries – skipping batch.");
|
||||||
|
$errors += 20;
|
||||||
|
sleep(8);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip markdown code fences if model added them
|
||||||
|
$raw = preg_replace('/^```(?:json)?\s*/m', '', $raw);
|
||||||
|
$raw = preg_replace('/^```\s*/m', '', $raw);
|
||||||
|
$raw = trim($raw);
|
||||||
|
|
||||||
|
// Extract JSON array; fall back to partial recovery for truncated responses
|
||||||
|
$items = null;
|
||||||
|
if (preg_match('/\[\s*\{.*\}\s*\]/s', $raw, $m)) {
|
||||||
|
$items = json_decode($m[0], true);
|
||||||
|
if (!is_array($items)) {
|
||||||
|
log_line(" ✗ JSON parse failed – skipping batch.");
|
||||||
|
$errors += 20; sleep(8); continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$start = strpos($raw, '[');
|
||||||
|
if ($start !== false) {
|
||||||
|
$partial = substr($raw, $start);
|
||||||
|
if (preg_match_all('/\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}/s', $partial, $objs) && !empty($objs[0])) {
|
||||||
|
$recovered = '[' . implode(',', $objs[0]) . ']';
|
||||||
|
$items = json_decode($recovered, true);
|
||||||
|
if (is_array($items) && count($items) > 0)
|
||||||
|
log_line(" ⚠ Truncated — recovered " . count($items) . " items.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!is_array($items) || count($items) === 0) {
|
||||||
|
log_line(" ✗ No JSON array found — raw[0:120]: " . substr(str_replace("\n", ' ', $raw), 0, 120));
|
||||||
|
$errors += 20; sleep(8); continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$batchInserted = 0;
|
||||||
|
foreach ($items as $item) {
|
||||||
|
if (!is_array($item)) continue;
|
||||||
|
safe_insert($item, $batch['category']);
|
||||||
|
$batchInserted++;
|
||||||
|
}
|
||||||
|
log_line(" ✓ Parsed {$batchInserted} intents (running total inserted: {$inserted}).");
|
||||||
|
|
||||||
|
// Polite delay between API calls — Groq TPM limit needs ~8s between batches
|
||||||
|
if ($num < $totalBatches) sleep(8);
|
||||||
|
}
|
||||||
|
|
||||||
|
log_line("Generation complete. Inserted/updated: {$inserted} | Short/invalid skipped: {$skipped} | Errors: {$errors}");
|
||||||
|
|
||||||
|
/* ── cleanup phase ── */
|
||||||
|
log_line('Starting cleanup phase...');
|
||||||
|
|
||||||
|
// 1. Remove exact duplicate intent_names (keep the one with the longer response)
|
||||||
|
$dups = JarvisDB::query(
|
||||||
|
'SELECT intent_name, COUNT(*) AS cnt FROM kb_intents GROUP BY intent_name HAVING cnt > 1'
|
||||||
|
);
|
||||||
|
$dupsPruned = 0;
|
||||||
|
foreach ($dups as $dup) {
|
||||||
|
$rows = JarvisDB::query(
|
||||||
|
'SELECT id, LENGTH(response_template) AS rlen FROM kb_intents WHERE intent_name=? ORDER BY rlen DESC',
|
||||||
|
[$dup['intent_name']]
|
||||||
|
);
|
||||||
|
array_shift($rows);
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
JarvisDB::execute('DELETE FROM kb_intents WHERE id=?', [$row['id']]);
|
||||||
|
$dupsPruned++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log_line(" Duplicate intent_names pruned: {$dupsPruned}");
|
||||||
|
|
||||||
|
// 2. Remove intents with very short responses (< 40 chars)
|
||||||
|
$shortPruned = JarvisDB::execute(
|
||||||
|
"DELETE FROM kb_intents WHERE LENGTH(response_template) < 40 AND priority <= 5"
|
||||||
|
);
|
||||||
|
log_line(" Short-response rows pruned: {$shortPruned}");
|
||||||
|
|
||||||
|
// 3. Trim whitespace on all generated intents
|
||||||
|
JarvisDB::execute(
|
||||||
|
"UPDATE kb_intents SET
|
||||||
|
intent_name = TRIM(intent_name),
|
||||||
|
pattern = TRIM(pattern),
|
||||||
|
response_template = TRIM(response_template),
|
||||||
|
fact_category = TRIM(fact_category)
|
||||||
|
WHERE priority = 5"
|
||||||
|
);
|
||||||
|
log_line(' Whitespace trimmed on all generated intents.');
|
||||||
|
|
||||||
|
// 4. Fix and validate PCRE patterns — normalize then deactivate only truly broken ones
|
||||||
|
$all = JarvisDB::query('SELECT id, pattern FROM kb_intents WHERE priority=5');
|
||||||
|
$badPattern = 0;
|
||||||
|
$fixedPattern = 0;
|
||||||
|
foreach ($all as $row) {
|
||||||
|
$pat = normalize_pattern($row['pattern']);
|
||||||
|
if ($pat !== $row['pattern']) {
|
||||||
|
// Update to normalized form
|
||||||
|
JarvisDB::execute('UPDATE kb_intents SET pattern=?, active=1 WHERE id=?', [$pat, $row['id']]);
|
||||||
|
$fixedPattern++;
|
||||||
|
} elseif (@preg_match($pat, '') === false) {
|
||||||
|
JarvisDB::execute('UPDATE kb_intents SET active=0 WHERE id=?', [$row['id']]);
|
||||||
|
$badPattern++;
|
||||||
|
} else {
|
||||||
|
// Valid pattern — make sure it's active
|
||||||
|
JarvisDB::execute('UPDATE kb_intents SET active=1 WHERE id=?', [$row['id']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log_line(" Patterns normalized: {$fixedPattern} | Bad PCRE deactivated: {$badPattern}");
|
||||||
|
|
||||||
|
// 5. Enable ALL remaining inactive intents (including pre-existing ones)
|
||||||
|
$reactivated = JarvisDB::execute('UPDATE kb_intents SET active=1 WHERE active=0 AND priority <= 5');
|
||||||
|
log_line(" Re-activated previously inactive intents: {$reactivated}");
|
||||||
|
|
||||||
|
// 6. Final stats
|
||||||
|
$stats = JarvisDB::single('SELECT COUNT(*) AS total, SUM(active) AS active FROM kb_intents');
|
||||||
|
log_line("Final KB Intents table: {$stats['total']} total, {$stats['active']} active.");
|
||||||
|
|
||||||
|
/* ── record last-run timestamp ── */
|
||||||
|
JarvisDB::execute(
|
||||||
|
"INSERT INTO kb_facts (category, fact_key, fact_value, host)
|
||||||
|
VALUES ('kb_generator', 'last_run', NOW(), 'local')
|
||||||
|
ON DUPLICATE KEY UPDATE fact_value=NOW(), updated_at=NOW()",
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
JarvisDB::execute(
|
||||||
|
"INSERT INTO kb_facts (category, fact_key, fact_value, host)
|
||||||
|
VALUES ('kb_generator', 'batch_offset', ?, 'local')
|
||||||
|
ON DUPLICATE KEY UPDATE fact_value=VALUES(fact_value), updated_at=NOW()",
|
||||||
|
[$nextOffset]
|
||||||
|
);
|
||||||
|
log_line("Next run will start at topic offset {$nextOffset}/{$totalTopics}.");
|
||||||
|
JarvisDB::execute(
|
||||||
|
"INSERT INTO kb_facts (category, fact_key, fact_value, host)
|
||||||
|
VALUES ('kb_generator', 'last_inserted', ?, 'local')
|
||||||
|
ON DUPLICATE KEY UPDATE fact_value=VALUES(fact_value), updated_at=NOW()",
|
||||||
|
[$inserted]
|
||||||
|
);
|
||||||
|
|
||||||
|
log_line('Done.');
|
||||||
@@ -479,3 +479,58 @@ CREATE TABLE IF NOT EXISTS `guardian_events` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
|
||||||
-- Dump completed on 2026-06-29 23:15:44
|
-- Dump completed on 2026-06-29 23:15:44
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `email_triage` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`msg_id` varchar(255) NOT NULL,
|
||||||
|
`account` varchar(64) NOT NULL DEFAULT 'gmail',
|
||||||
|
`from_name` varchar(255) DEFAULT NULL,
|
||||||
|
`from_email` varchar(255) DEFAULT NULL,
|
||||||
|
`subject` varchar(500) DEFAULT NULL,
|
||||||
|
`date_received` datetime DEFAULT NULL,
|
||||||
|
`category` varchar(32) NOT NULL DEFAULT 'info',
|
||||||
|
`priority` int(11) NOT NULL DEFAULT 3,
|
||||||
|
`summary` text DEFAULT NULL,
|
||||||
|
`draft_reply` text DEFAULT NULL,
|
||||||
|
`action_taken` varchar(32) NOT NULL DEFAULT 'none',
|
||||||
|
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `uq_msg` (`msg_id`),
|
||||||
|
KEY `idx_category` (`category`),
|
||||||
|
KEY `idx_action` (`action_taken`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `email_actions` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`msg_id` varchar(255) DEFAULT NULL,
|
||||||
|
`from_name` varchar(255) DEFAULT NULL,
|
||||||
|
`from_email` varchar(255) DEFAULT NULL,
|
||||||
|
`subject` varchar(500) DEFAULT NULL,
|
||||||
|
`received_at` datetime DEFAULT NULL,
|
||||||
|
`suggested_title` varchar(255) DEFAULT NULL,
|
||||||
|
`suggested_date` date DEFAULT NULL,
|
||||||
|
`task_id` int(11) DEFAULT NULL,
|
||||||
|
`appointment_id` int(11) DEFAULT NULL,
|
||||||
|
`dismissed` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
|
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `idx_dismissed` (`dismissed`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `email_sent` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`account` varchar(64) NOT NULL DEFAULT 'gmail',
|
||||||
|
`to_email` varchar(255) NOT NULL,
|
||||||
|
`to_name` varchar(255) DEFAULT NULL,
|
||||||
|
`subject` varchar(500) DEFAULT NULL,
|
||||||
|
`body` text DEFAULT NULL,
|
||||||
|
`triage_id` int(11) DEFAULT NULL,
|
||||||
|
`status` varchar(32) NOT NULL DEFAULT 'sent',
|
||||||
|
`sent_at` timestamp NULL DEFAULT current_timestamp(),
|
||||||
|
`error` text DEFAULT NULL,
|
||||||
|
`message_id` varchar(255) DEFAULT NULL,
|
||||||
|
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `idx_account` (`account`),
|
||||||
|
KEY `idx_status` (`status`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
|||||||
Executable
+31
@@ -0,0 +1,31 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# JARVIS backup — DB dump as tar.gz, admin-panel compatible
|
||||||
|
BACKUP_DIR="/var/backups/jarvis"
|
||||||
|
LOG="$BACKUP_DIR/backup.log"
|
||||||
|
LOCK="$BACKUP_DIR/backup.lock"
|
||||||
|
DB_NAME="jarvis_db"
|
||||||
|
DB_USER="jarvis_user"
|
||||||
|
DB_PASS="J4rv1s_Pr0t0c0l_2026!"
|
||||||
|
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
|
||||||
|
OUTFILE="$BACKUP_DIR/jarvis_backup_${TIMESTAMP}.tar.gz"
|
||||||
|
TMPDIR=$(mktemp -d)
|
||||||
|
|
||||||
|
mkdir -p "$BACKUP_DIR"
|
||||||
|
touch "$LOCK"
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting backup..." >> "$LOG"
|
||||||
|
|
||||||
|
cleanup() { rm -rf "$TMPDIR"; rm -f "$LOCK"; }
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
if mysqldump -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" > "$TMPDIR/jarvis_db.sql" 2>>"$LOG"; then
|
||||||
|
tar -czf "$OUTFILE" -C "$TMPDIR" jarvis_db.sql
|
||||||
|
SIZE=$(du -sh "$OUTFILE" | cut -f1)
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Backup OK: $(basename "$OUTFILE") ($SIYE)" >> "$LOG"
|
||||||
|
else
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ERROR: mysqldump failed" >> "$LOG"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
find "$BACKUP_DIR" -name "jarvis_backup_*.tar.gz" -mtime +7 -delete
|
||||||
|
COUNT=$(ls "$BACKUP_DIR"/jarvis_backup_*.tar.gz 2>/dev/null | wc -l)
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Done. Files retained: $COUNT" >> "$LOG"
|
||||||
+67
-107
@@ -41,16 +41,17 @@ DB_PORT = 3306
|
|||||||
DB_USER = "jarvis_user"
|
DB_USER = "jarvis_user"
|
||||||
DB_PASS = "J4rv1s_Pr0t0c0l_2026!"
|
DB_PASS = "J4rv1s_Pr0t0c0l_2026!"
|
||||||
DB_NAME = "jarvis_db"
|
DB_NAME = "jarvis_db"
|
||||||
LOG_FILE = "/home/jarvis.orbishosting.com/logs/arc_reactor.log"
|
LOG_FILE = "/var/log/jarvis/arc_reactor.log"
|
||||||
POLL_INTERVAL = 3
|
POLL_INTERVAL = 3
|
||||||
HEARTBEAT_INTERVAL = 30
|
HEARTBEAT_INTERVAL = 30
|
||||||
|
|
||||||
CLAUDE_API_KEY = "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"
|
CLAUDE_API_KEY = "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"
|
||||||
CLAUDE_MODEL = "claude-sonnet-4-6"
|
CLAUDE_MODEL = "claude-sonnet-4-6"
|
||||||
GROQ_API_KEY = "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"
|
GROQ_API_KEY = "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"
|
||||||
GROQ_MODEL = "llama-3.3-70b-versatile"
|
GROQ_MODEL = "llama-3.3-70b-versatile"
|
||||||
OLLAMA_HOST = "http://10.48.200.210:11434"
|
OLLAMA_HOST = "http://10.48.200.210:11434"
|
||||||
OLLAMA_MODEL = "llama3.1:8b"
|
OLLAMA_MODEL = "llama3.1:8b"
|
||||||
|
OLLAMA_VISION_MODEL = os.environ.get("OLLAMA_VISION_MODEL", "") # e.g. "llava" or "moondream" -- empty = disabled
|
||||||
|
|
||||||
GMAIL_USER = "myronblair@gmail.com"
|
GMAIL_USER = "myronblair@gmail.com"
|
||||||
GMAIL_PASS = "demsvdylwweacbcx"
|
GMAIL_PASS = "demsvdylwweacbcx"
|
||||||
@@ -175,15 +176,56 @@ async def _ollama_call(messages: list, system: str = "") -> str:
|
|||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
return data.get("response", "")
|
return data.get("response", "")
|
||||||
|
|
||||||
async def _ollama_vision_call(image_b64: str, prompt: str) -> str:
|
|
||||||
async with aiohttp.ClientSession() as session:
|
# -- VISION CALL ----------------------------------------------------------
|
||||||
async with session.post(
|
async def _vision_call(image_b64: str, prompt: str) -> tuple:
|
||||||
f"{OLLAMA_HOST}/api/generate",
|
"""
|
||||||
json={"model": "llava:7b", "prompt": prompt, "images": [image_b64], "stream": False},
|
Vision provider cascade: Claude -> Ollama vision model -> graceful fallback.
|
||||||
timeout=aiohttp.ClientTimeout(total=120),
|
Returns (analysis: str, provider: str).
|
||||||
) as resp:
|
To enable a local vision model: set OLLAMA_VISION_MODEL env var (e.g. "llava").
|
||||||
data = await resp.json()
|
"""
|
||||||
return data.get("response", "").strip()
|
# 1. Claude (primary)
|
||||||
|
if CLAUDE_API_KEY:
|
||||||
|
try:
|
||||||
|
import anthropic as _anthropic
|
||||||
|
_client = _anthropic.AsyncAnthropic(api_key=CLAUDE_API_KEY)
|
||||||
|
_msg = await _client.messages.create(
|
||||||
|
model="claude-opus-4-8-20251101",
|
||||||
|
max_tokens=2048,
|
||||||
|
messages=[{"role": "user", "content": [
|
||||||
|
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": image_b64}},
|
||||||
|
{"type": "text", "text": prompt},
|
||||||
|
]}],
|
||||||
|
)
|
||||||
|
text = _msg.content[0].text if _msg.content else ""
|
||||||
|
log.info("[VISION] Claude vision OK")
|
||||||
|
return text, "claude"
|
||||||
|
except Exception as e:
|
||||||
|
log.warning(f"[VISION] Claude failed ({e}), trying next provider")
|
||||||
|
|
||||||
|
# 2. Ollama vision model (if configured via OLLAMA_VISION_MODEL env var)
|
||||||
|
if OLLAMA_VISION_MODEL:
|
||||||
|
try:
|
||||||
|
async with aiohttp.ClientSession() as _sess:
|
||||||
|
_payload = {"model": OLLAMA_VISION_MODEL, "prompt": prompt,
|
||||||
|
"images": [image_b64], "stream": False}
|
||||||
|
async with _sess.post(f"{OLLAMA_HOST}/api/generate", json=_payload,
|
||||||
|
timeout=aiohttp.ClientTimeout(total=120)) as _resp:
|
||||||
|
if _resp.status == 200:
|
||||||
|
_data = await _resp.json()
|
||||||
|
text = _data.get("response", "")
|
||||||
|
log.info(f"[VISION] Ollama vision OK ({OLLAMA_VISION_MODEL})")
|
||||||
|
return text, f"ollama/{OLLAMA_VISION_MODEL}"
|
||||||
|
raise RuntimeError(f"Ollama HTTP {_resp.status}")
|
||||||
|
except Exception as e:
|
||||||
|
log.warning(f"[VISION] Ollama vision failed ({e})")
|
||||||
|
|
||||||
|
# 3. No vision provider available
|
||||||
|
msg = ("[Vision unavailable] Claude credits depleted and no local vision model configured. "
|
||||||
|
"To enable: pull a vision model on Ollama (e.g. 'ollama pull llava') then set "
|
||||||
|
"OLLAMA_VISION_MODEL=llava in the jarvis-arc systemd environment.")
|
||||||
|
log.warning("[VISION] All vision providers unavailable")
|
||||||
|
return msg, "none"
|
||||||
|
|
||||||
async def handle_llm(payload: dict) -> dict:
|
async def handle_llm(payload: dict) -> dict:
|
||||||
message = payload.get("message", "")
|
message = payload.get("message", "")
|
||||||
@@ -668,44 +710,19 @@ async def handle_screenshot(payload: dict) -> dict:
|
|||||||
height = result.get("height", 0)
|
height = result.get("height", 0)
|
||||||
file_size = result.get("file_size", 0)
|
file_size = result.get("file_size", 0)
|
||||||
|
|
||||||
# Run vision analysis if we have an image — llava first, Claude fallback
|
# Run Claude vision analysis if we have an image
|
||||||
analysis = ""
|
analysis = ""
|
||||||
provider_used = ""
|
provider_used = ""
|
||||||
if do_analyze and image_b64:
|
if do_analyze and image_b64:
|
||||||
try:
|
analysis, provider_used = await _vision_call(image_b64, analyze_prompt)
|
||||||
analysis = await _ollama_vision_call(image_b64, analyze_prompt)
|
log.info(f"[VISION] Analysis complete via {provider_used} ({len(analysis)} chars)")
|
||||||
provider_used = "ollama:llava"
|
|
||||||
log.info(f"[VISION] llava analysis complete ({len(analysis)} chars)")
|
|
||||||
except Exception as e:
|
|
||||||
log.warning(f"[VISION] llava failed: {e} — falling back to Claude")
|
|
||||||
try:
|
|
||||||
import anthropic
|
|
||||||
client = anthropic.AsyncAnthropic(api_key=CLAUDE_API_KEY)
|
|
||||||
msg = await client.messages.create(
|
|
||||||
model="claude-opus-4-8-20251101",
|
|
||||||
max_tokens=1024,
|
|
||||||
messages=[{
|
|
||||||
"role": "user",
|
|
||||||
"content": [
|
|
||||||
{"type": "image", "source": {"type": "base64",
|
|
||||||
"media_type": "image/png", "data": image_b64}},
|
|
||||||
{"type": "text", "text": analyze_prompt},
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
)
|
|
||||||
analysis = msg.content[0].text if msg.content else ""
|
|
||||||
provider_used = "claude"
|
|
||||||
log.info(f"[VISION] Claude fallback analysis complete ({len(analysis)} chars)")
|
|
||||||
except Exception as e2:
|
|
||||||
log.warning(f"[VISION] Claude fallback also failed: {e2}")
|
|
||||||
analysis = f"Vision analysis unavailable: {e2}"
|
|
||||||
elif do_analyze and not image_b64 and result.get("snapshot_type") == "text":
|
elif do_analyze and not image_b64 and result.get("snapshot_type") == "text":
|
||||||
# Text-only sysinfo snapshot — summarize with Ollama
|
# Text-only sysinfo snapshot — summarize with LLM
|
||||||
try:
|
try:
|
||||||
snap_text = json.dumps(result, indent=2)[:3000]
|
snap_text = json.dumps(result, indent=2)[:3000]
|
||||||
prompt = f"Summarize this server system snapshot for JARVIS. Highlight any concerns:\n\n{snap_text}"
|
prompt = f"Summarize this server system snapshot for JARVIS. Highlight any concerns:\n\n{snap_text}"
|
||||||
analysis = await llm_call([{"role": "user", "content": prompt}], "ollama")
|
analysis = await llm_call([{"role": "user", "content": prompt}], "groq")
|
||||||
provider_used = "ollama"
|
provider_used = "groq"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
analysis = f"Analysis unavailable: {e}"
|
analysis = f"Analysis unavailable: {e}"
|
||||||
|
|
||||||
@@ -758,41 +775,9 @@ async def handle_vision(payload: dict) -> dict:
|
|||||||
if not image_b64:
|
if not image_b64:
|
||||||
raise ValueError("No image data provided")
|
raise ValueError("No image data provided")
|
||||||
|
|
||||||
log.info(f"[VISION] Analysis: screenshot_id={screenshot_id} agent={hostname} provider={provider}")
|
log.info(f"[VISION] Analysis: screenshot_id={screenshot_id} agent={hostname}")
|
||||||
|
|
||||||
analysis = ""
|
analysis, provider_used = await _vision_call(image_b64, prompt)
|
||||||
provider_used = provider
|
|
||||||
|
|
||||||
if provider == "ollama" or provider == "llava":
|
|
||||||
analysis = await _ollama_vision_call(image_b64, prompt)
|
|
||||||
provider_used = "ollama:llava"
|
|
||||||
else:
|
|
||||||
# Default: llava first, Claude fallback
|
|
||||||
try:
|
|
||||||
analysis = await _ollama_vision_call(image_b64, prompt)
|
|
||||||
provider_used = "ollama:llava"
|
|
||||||
log.info(f"[VISION] llava analysis complete ({len(analysis)} chars)")
|
|
||||||
except Exception as e:
|
|
||||||
log.warning(f"[VISION] llava failed: {e} — falling back to Claude")
|
|
||||||
try:
|
|
||||||
import anthropic
|
|
||||||
client = anthropic.AsyncAnthropic(api_key=CLAUDE_API_KEY)
|
|
||||||
msg = await client.messages.create(
|
|
||||||
model="claude-opus-4-8-20251101",
|
|
||||||
max_tokens=2048,
|
|
||||||
messages=[{
|
|
||||||
"role": "user",
|
|
||||||
"content": [
|
|
||||||
{"type": "image", "source": {"type": "base64",
|
|
||||||
"media_type": "image/png", "data": image_b64}},
|
|
||||||
{"type": "text", "text": prompt},
|
|
||||||
],
|
|
||||||
}],
|
|
||||||
)
|
|
||||||
analysis = msg.content[0].text if msg.content else ""
|
|
||||||
provider_used = "claude"
|
|
||||||
except Exception as e2:
|
|
||||||
raise RuntimeError(f"Vision analysis failed (llava: {e}, claude: {e2})")
|
|
||||||
|
|
||||||
# Update stored screenshot if we have an ID
|
# Update stored screenshot if we have an ID
|
||||||
if screenshot_id:
|
if screenshot_id:
|
||||||
@@ -1053,7 +1038,7 @@ async def guardian_loop() -> None:
|
|||||||
"for Myron. Be direct about severity and what action to take. "
|
"for Myron. Be direct about severity and what action to take. "
|
||||||
"No markdown, no headers."
|
"No markdown, no headers."
|
||||||
)
|
)
|
||||||
ai_msg = await llm_call([{"role": "user", "content": ai_prompt}], "ollama")
|
ai_msg = await llm_call([{"role": "user", "content": ai_prompt}], "groq")
|
||||||
# Update the most recent guardian event with AI analysis
|
# Update the most recent guardian event with AI analysis
|
||||||
await db_execute(
|
await db_execute(
|
||||||
"""UPDATE guardian_events SET ai_analysis=%s
|
"""UPDATE guardian_events SET ai_analysis=%s
|
||||||
@@ -1082,7 +1067,7 @@ async def _guardian_inject_chat(message: str) -> None:
|
|||||||
"""Write a proactive JARVIS message into the conversations table so the HUD picks it up."""
|
"""Write a proactive JARVIS message into the conversations table so the HUD picks it up."""
|
||||||
try:
|
try:
|
||||||
await db_execute(
|
await db_execute(
|
||||||
"""INSERT INTO conversations (session_id, role, content, created_at)
|
"""INSERT INTO conversations (session_id, role, message, created_at)
|
||||||
VALUES ('guardian', 'assistant', %s, NOW())""",
|
VALUES ('guardian', 'assistant', %s, NOW())""",
|
||||||
(message,)
|
(message,)
|
||||||
)
|
)
|
||||||
@@ -1096,7 +1081,7 @@ async def handle_sitrep(payload: dict) -> dict:
|
|||||||
payload: { detail: brief|full, provider: groq }
|
payload: { detail: brief|full, provider: groq }
|
||||||
"""
|
"""
|
||||||
detail = payload.get("detail", "full")
|
detail = payload.get("detail", "full")
|
||||||
provider = payload.get("provider", "ollama")
|
provider = payload.get("provider", "groq")
|
||||||
|
|
||||||
log.info(f"[GUARDIAN] SITREP requested (detail={detail})")
|
log.info(f"[GUARDIAN] SITREP requested (detail={detail})")
|
||||||
|
|
||||||
@@ -1837,7 +1822,7 @@ Keep the tone confident and action-oriented. Format with clear sections. Under 4
|
|||||||
|
|
||||||
# Store in conversations so HUD can surface it
|
# Store in conversations so HUD can surface it
|
||||||
await db_execute(
|
await db_execute(
|
||||||
"INSERT INTO conversations (session_id, role, content, created_at) VALUES ('guardian','assistant',%s,NOW())",
|
"INSERT INTO conversations (session_id, role, message, created_at) VALUES ('guardian','assistant',%s,NOW())",
|
||||||
(review_text,)
|
(review_text,)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -2240,31 +2225,6 @@ async def lifespan(app: FastAPI):
|
|||||||
log.info(f"◈ JARVIS Arc Reactor v{VERSION} starting on {HOST}:{PORT}")
|
log.info(f"◈ JARVIS Arc Reactor v{VERSION} starting on {HOST}:{PORT}")
|
||||||
await get_pool()
|
await get_pool()
|
||||||
await db_execute("UPDATE arc_status SET started_at=NOW(), last_heartbeat=NOW(), version=%s WHERE id=1", (VERSION,))
|
await db_execute("UPDATE arc_status SET started_at=NOW(), last_heartbeat=NOW(), version=%s WHERE id=1", (VERSION,))
|
||||||
await db_execute("""CREATE TABLE IF NOT EXISTS guardian_config (
|
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
key_name VARCHAR(64) NOT NULL,
|
|
||||||
value VARCHAR(255) NOT NULL DEFAULT '',
|
|
||||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
UNIQUE KEY uk_key (key_name)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci""")
|
|
||||||
await db_execute("""CREATE TABLE IF NOT EXISTS guardian_events (
|
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
event_type VARCHAR(64) NOT NULL,
|
|
||||||
severity ENUM('info','warning','critical') NOT NULL DEFAULT 'info',
|
|
||||||
agent_id VARCHAR(64) NOT NULL DEFAULT '',
|
|
||||||
hostname VARCHAR(128) NOT NULL DEFAULT '',
|
|
||||||
metric VARCHAR(64) NOT NULL DEFAULT '',
|
|
||||||
value FLOAT NOT NULL DEFAULT 0,
|
|
||||||
threshold FLOAT NOT NULL DEFAULT 0,
|
|
||||||
message TEXT NOT NULL,
|
|
||||||
ai_analysis TEXT NOT NULL DEFAULT '',
|
|
||||||
acknowledged TINYINT(1) NOT NULL DEFAULT 0,
|
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
KEY idx_severity (severity),
|
|
||||||
KEY idx_ack (acknowledged),
|
|
||||||
KEY idx_created (created_at),
|
|
||||||
KEY idx_agent (agent_id)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci""")
|
|
||||||
asyncio.create_task(job_poller())
|
asyncio.create_task(job_poller())
|
||||||
asyncio.create_task(heartbeat_loop())
|
asyncio.create_task(heartbeat_loop())
|
||||||
asyncio.create_task(guardian_loop())
|
asyncio.create_task(guardian_loop())
|
||||||
@@ -2784,13 +2744,13 @@ async def guardian_chat_events(since: str = ""):
|
|||||||
"""Return proactive guardian messages injected into conversations."""
|
"""Return proactive guardian messages injected into conversations."""
|
||||||
if since:
|
if since:
|
||||||
rows = await db_fetchall(
|
rows = await db_fetchall(
|
||||||
"SELECT id, content AS message, created_at FROM conversations "
|
"SELECT id, message, created_at FROM conversations "
|
||||||
"WHERE session_id='guardian' AND created_at > %s ORDER BY created_at ASC",
|
"WHERE session_id='guardian' AND created_at > %s ORDER BY created_at ASC",
|
||||||
(since,)
|
(since,)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
rows = await db_fetchall(
|
rows = await db_fetchall(
|
||||||
"SELECT id, content AS message, created_at FROM conversations "
|
"SELECT id, message, created_at FROM conversations "
|
||||||
"WHERE session_id='guardian' ORDER BY created_at DESC LIMIT 10"
|
"WHERE session_id='guardian' ORDER BY created_at DESC LIMIT 10"
|
||||||
)
|
)
|
||||||
return rows or []
|
return rows or []
|
||||||
|
|||||||
@@ -1,738 +0,0 @@
|
|||||||
# INFRASTRUCTURE REFERENCE — COMPLETE SYSTEM MAP
|
|
||||||
**Last Updated:** 2026-06-18
|
|
||||||
**Owner:** Myron Blair — myronblair@outlook.com
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## TABLE OF CONTENTS
|
|
||||||
1. [Network Overview](#1-network-overview)
|
|
||||||
2. [Cloud Servers](#2-cloud-servers)
|
|
||||||
3. [On-Premise — Proxmox Hypervisors](#3-on-premise--proxmox-hypervisors)
|
|
||||||
4. [On-Premise — Virtual Machines](#4-on-premise--virtual-machines)
|
|
||||||
5. [NAS Storage](#5-nas-storage)
|
|
||||||
6. [Websites (all on DO)](#6-websites--all-on-do)
|
|
||||||
7. [JARVIS AI System](#7-jarvis-ai-system)
|
|
||||||
8. [Phone System (FusionPBX)](#8-phone-system-fusionpbx)
|
|
||||||
9. [Networking & VPN](#9-networking--vpn)
|
|
||||||
10. [Backup Systems](#10-backup-systems)
|
|
||||||
11. [SSH Quick Reference](#11-ssh-quick-reference)
|
|
||||||
12. [Critical Credentials Master List](#12-critical-credentials-master-list)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 1. NETWORK OVERVIEW
|
|
||||||
|
|
||||||
```
|
|
||||||
INTERNET
|
|
||||||
│
|
|
||||||
▼
|
|
||||||
[Cloudflare CDN] ──────────────────────────────────────────────────────────────
|
|
||||||
│ (proxied DNS for public sites)
|
|
||||||
│
|
|
||||||
├─► [DigitalOcean 165.22.1.228] — CyberPanel/OLS — All websites (6 sites)
|
|
||||||
│
|
|
||||||
└─► [FusionPBX 134.209.72.226] — FreeSWITCH PBX (SSH via DO relay)
|
|
||||||
|
|
||||||
HOME NETWORK (FortiGate router at 10.48.200.1)
|
|
||||||
WAN: 97.154.109.245 (dynamic, DDNS: orbisne.fortiddns.com)
|
|
||||||
│
|
|
||||||
├─► PVE1 Proxmox 10.48.200.90 (primary hypervisor)
|
|
||||||
│ ├── VM 101 10.48.200.97 Home Assistant
|
|
||||||
│ ├── VM 112 10.48.200.33 Jellyfin
|
|
||||||
│ ├── VM 113 10.48.200.35 MediaStack (Sonarr/Radarr/qBT/Prowlarr)
|
|
||||||
│ ├── VM 118 10.48.200.18 Homebridge
|
|
||||||
│ ├── VM 120 10.48.200.110 NovaCPX hosting panel
|
|
||||||
│ ├── VM 210 10.48.200.210 Ollama (local LLM) (local LLM)
|
|
||||||
│ └── CT110 10.48.200.19 WireGuard exit container
|
|
||||||
│
|
|
||||||
├─► PVE2 Proxmox 10.48.200.91 (secondary hypervisor)
|
|
||||||
│ └── VM 302 10.48.200.99 NetworkBackup
|
|
||||||
│
|
|
||||||
├─► Synology NAS 10.48.200.249 — Media & backup storage
|
|
||||||
├─► Yealink T48S 10.48.200.2 — Ext 1000 (Myron Blair, Desk)
|
|
||||||
├─► Yealink T48S 10.48.200.43 — Ext 1001 (Tommy Ivy, Desk)
|
|
||||||
├─► Yealink AX86R 10.48.200.65 — Ext 1002 (Myron Blair, WiFi Work)
|
|
||||||
├─► Yealink T57W 10.48.200.3 — External SIP (United Mirror & Glass)
|
|
||||||
├─► Yealink T57W 10.48.200.83 — Ext 1003 (Kitchen)
|
|
||||||
└─► Yealink T57W 10.48.200.85 — Ext 1004 (Master Bedroom)
|
|
||||||
|
|
||||||
FortiGate Port Forwards:
|
|
||||||
orbisne.fortiddns.com:8006 → PVE1:8006 (Proxmox web UI)
|
|
||||||
orbisne.fortiddns.com:8123 → HA:8123 (Home Assistant)
|
|
||||||
orbisne.fortiddns.com:22 → HA VM:22 (SSH — key only, unreliable)
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 2. CLOUD SERVERS
|
|
||||||
|
|
||||||
### 2A. DigitalOcean — Main Server
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **IP** | 165.22.1.228 |
|
|
||||||
| **OS** | Ubuntu 22.04 LTS |
|
|
||||||
| **Panel** | CyberPanel (OpenLiteSpeed) |
|
|
||||||
| **SSH** | `ssh root@165.22.1.228` — password: `Gonewalk1974!@#` |
|
|
||||||
| **Purpose** | All public websites (6 sites) — webhook deploy for websites |
|
|
||||||
|
|
||||||
**Key Paths:**
|
|
||||||
- All sites: `/home/<domain>/public_html/`
|
|
||||||
|
|
||||||
- Deploy log: per-site (website deploys only)
|
|
||||||
- Watchdog log: `/usr/local/lsws/logs/watchdog.log`
|
|
||||||
- Infra repo: `/opt/infra`
|
|
||||||
|
|
||||||
**Services running:**
|
|
||||||
- OpenLiteSpeed web server (`lsws`) — serves all 7 sites
|
|
||||||
- MySQL 8 — all site databases on localhost
|
|
||||||
- Redis — session/cache
|
|
||||||
- PHP 8.5 (`lsphp85`) — runtime for all sites
|
|
||||||
- Cron jobs: website deploy runner (every 1 min), watchdog (every 5 min)
|
|
||||||
|
|
||||||
**CyberPanel Web UI:** `https://165.22.1.228:8090`
|
|
||||||
Login: `myron / Joker1974!!!`
|
|
||||||
|
|
||||||
**phpMyAdmin:** `https://165.22.1.228/phpmyadmin`
|
|
||||||
Login: `myron / Joker1974!!!`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 2B. FusionPBX / FreeSWITCH — PBX Server
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **IP** | 134.209.72.226 |
|
|
||||||
| **OS** | Debian (DigitalOcean droplet) |
|
|
||||||
| **SSH** | Direct via Tailscale: `ssh root@100.74.46.120` — password: `Joker1974!@#` |
|
|
||||||
| **Direct SSH** | Only from: 107.178.2.130 / 97.154.109.245 |
|
|
||||||
| **Purpose** | VoIP phone system — handles all inbound/outbound calls |
|
|
||||||
|
|
||||||
**Web UI:** `https://fusion.orbishosting.com`
|
|
||||||
Login: `admin / fY7XP5swgtpbzrYLhkeVYkA4744`
|
|
||||||
|
|
||||||
**Database:** PostgreSQL
|
|
||||||
User: `fusionpbx` / Password: `pSJaF9mUJqPr4Sj5mwJyRqvCCpc` / Host: 127.0.0.1
|
|
||||||
|
|
||||||
**SIP Trunk:** SignalWire
|
|
||||||
DID: +1 (817) 764-5007
|
|
||||||
Gateway: `signalwire` on external profile (port 5080, UDP)
|
|
||||||
|
|
||||||
**How calls flow:**
|
|
||||||
```
|
|
||||||
Caller → SignalWire SIP → FusionPBX:5080 → IVR (ext 900) → Ring extensions
|
|
||||||
Outbound: Phone → FusionPBX:5080 → SignalWire → PSTN
|
|
||||||
```
|
|
||||||
|
|
||||||
**SSH Relay Command:**
|
|
||||||
```bash
|
|
||||||
sshpass -p 'Gonewalk1974!@#' ssh -o StrictHostKeyChecking=no root@165.22.1.228 \
|
|
||||||
'sshpass -p "Joker1974!@#" ssh -o StrictHostKeyChecking=no root@134.209.72.226 "COMMAND"'
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 3. ON-PREMISE — PROXMOX HYPERVISORS
|
|
||||||
|
|
||||||
### PVE1 — Primary Hypervisor
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **Local IP** | 10.48.200.90 |
|
|
||||||
| **External** | orbisne.fortiddns.com (FortiGate DDNS — auto-updates on WAN IP change) |
|
|
||||||
| **OS** | Proxmox VE 8.x |
|
|
||||||
| **SSH** | `ssh root@orbisne.fortiddns.com` OR `ssh root@10.48.200.90` — password: `Joker1974!!!` |
|
|
||||||
| **Web UI** | `https://orbisne.fortiddns.com:8006` — `root / Joker1974!!!` |
|
|
||||||
| **Purpose** | Runs VMs 101, 112, 113, 118, 120, 210, CT110 |
|
|
||||||
|
|
||||||
**Useful commands:**
|
|
||||||
```bash
|
|
||||||
qm list # list all VMs
|
|
||||||
qm start/stop/restart <VMID> # control VMs
|
|
||||||
qm guest exec <VMID> -- bash -c "cmd" # run command inside VM (requires QEMU agent)
|
|
||||||
```
|
|
||||||
|
|
||||||
**JARVIS API Token:** `root@pam!jarvis=c45b5feb-f9a9-445d-a626-14fbb959f78b`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### PVE2 — Secondary Hypervisor
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **Local IP** | 10.48.200.91 |
|
|
||||||
| **OS** | Proxmox VE 8.x |
|
|
||||||
| **SSH** | `ssh root@10.48.200.91` — password: `Joker1974!!!` |
|
|
||||||
| **Web UI** | `https://10.48.200.91:8006` — `root / Joker1974!!!` |
|
|
||||||
| **Purpose** | Runs VM 302 (NetworkBackup); part of shared Proxmox cluster with PVE1 |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 4. ON-PREMISE — VIRTUAL MACHINES
|
|
||||||
|
|
||||||
### VM 101 — Home Assistant (PVE1)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **IP** | 10.48.200.97 |
|
|
||||||
| **OS** | Ubuntu + Home Assistant OS/Supervised |
|
|
||||||
| **Web UI** | `http://orbisne.fortiddns.com:8123` — `myron / [HA password]` |
|
|
||||||
| **SSH** | Via HA web terminal only (Settings → Add-ons → Advanced SSH & Web Terminal) |
|
|
||||||
| **Purpose** | Smart home automation — 212 entities (lights, switches, scenes, sensors) |
|
|
||||||
| **JARVIS Agent** | ID: `homeassistant_ha` — pushes entity states to JARVIS every 10s |
|
|
||||||
|
|
||||||
**JARVIS ↔ HA Integration:**
|
|
||||||
- HA custom component at `/config/custom_components/jarvis_agent/`
|
|
||||||
- Pushes all entity state changes to JARVIS `/api/agent/ha_state` (debounced 2s)
|
|
||||||
- JARVIS admin toggles → queued in `agent_commands` table → HA executes natively
|
|
||||||
- HA Long-lived Token (Jarvis2): `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIzNmI0N2I1Njk5ZGQ0MTQ2ODMwZWFmYjZiYTQ1MjJkMSIsImlhdCI6MTc4MDIwMzU5NCwiZXhwIjoyMDk1NTYzNTk0fQ.sYRok-jRDlA4lFgWxLQELcEjkJNGQdprk6ZziLwLtXE`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### VM 112 — Jellyfin Media Server (PVE1)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **IP** | 10.48.200.33 |
|
|
||||||
| **OS** | Ubuntu 22.04 LTS |
|
|
||||||
| **SSH** | `ssh root@10.48.200.33` — password: `Joker1974!!!` (enabled 2026-06-14) |
|
|
||||||
| **Web UI** | `http://10.48.200.33:8096` |
|
|
||||||
| **Purpose** | Media streaming server — Movies and TV shows |
|
|
||||||
| **JARVIS Agent** | Not yet installed |
|
|
||||||
|
|
||||||
**Media Libraries:**
|
|
||||||
- Movies: `/mnt/mediastack/movies` — NFS from MediaStack (10.48.200.35:/media/movies)
|
|
||||||
- TV: `/mnt/mediastack/tv` — NFS from MediaStack (10.48.200.35:/media/tv)
|
|
||||||
|
|
||||||
**NFS chain:** Jellyfin → MediaStack → Synology NAS (`/volume1/video/movies` and `/volume1/video/tv`)
|
|
||||||
|
|
||||||
**Admin token:** `7c0ccf78b91d4b5bafa607f585f24f2d`
|
|
||||||
|
|
||||||
**If library scan needed:**
|
|
||||||
```bash
|
|
||||||
curl -X POST "http://10.48.200.33:8096/Library/Refresh" \
|
|
||||||
-H "X-Emby-Token: 7c0ccf78b91d4b5bafa607f585f24f2d"
|
|
||||||
```
|
|
||||||
|
|
||||||
**If NFS stale after MediaStack changes:**
|
|
||||||
```bash
|
|
||||||
umount -l /mnt/mediastack/movies && umount -l /mnt/mediastack/tv
|
|
||||||
mount /mnt/mediastack/movies && mount /mnt/mediastack/tv
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### VM 113 — MediaStack (PVE1)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **IP** | 10.48.200.35 |
|
|
||||||
| **OS** | Ubuntu 24.04 LTS |
|
|
||||||
| **SSH** | Via PVE1: `ssh -i /root/.ssh/id_rsa root@10.48.200.35` (no direct access from DO) |
|
|
||||||
| **Purpose** | Automated media download pipeline + NFS server to Jellyfin |
|
|
||||||
| **JARVIS Agent** | ID: `MediaStack_2c00b1b8` |
|
|
||||||
|
|
||||||
**Services:**
|
|
||||||
| Service | Port | Login | API Key |
|
|
||||||
|---------|------|-------|---------|
|
|
||||||
| qBittorrent | :8080 | `admin / Joker1974!!!` | — |
|
|
||||||
| Sonarr | :8989 | `admin / Joker1974!!!` | `b43e04350a594846b4ee95261c29e9e0` |
|
|
||||||
| Radarr | :7878 | `admin / Joker1974!!!` | `53c4268360444feeae5f98c0cc24e0e3` |
|
|
||||||
| Prowlarr | :9696 | `admin / Joker1974!!!` | `9d0ce6c5660743b5bf1c7951efc62252` |
|
|
||||||
|
|
||||||
**All services run as root** — required by Synology NFS ACL (only root can write).
|
|
||||||
|
|
||||||
**VPN:** NordVPN — `nordlynx` WireGuard interface — exit IP 181.214.226.188 (US Dallas)
|
|
||||||
All download traffic exits via NordVPN. If downloads stall, check: `ip rule show` for rules 32764/32765.
|
|
||||||
|
|
||||||
**Media Flow:**
|
|
||||||
```
|
|
||||||
IPTorrents (Prowlarr) → Sonarr/Radarr search → qBittorrent download
|
|
||||||
→ /mnt/nas/video/downloads (NAS)
|
|
||||||
→ Sonarr/Radarr import → /mnt/nas/video/tv or /mnt/nas/video/movies (NAS)
|
|
||||||
→ NFS → Jellyfin /mnt/mediastack/movies or /mnt/mediastack/tv
|
|
||||||
```
|
|
||||||
|
|
||||||
**Indexer:** IPTorrents via Prowlarr cookie auth
|
|
||||||
Cookie: `uid=2237410; pass=JzLP2niTWxBJAZIU3yvtLbJzD55kdLeB`
|
|
||||||
(Expires — if search fails, log into iptorrents.com, copy uid+pass cookies)
|
|
||||||
|
|
||||||
**If Radarr/Sonarr shows "0 active indexers":**
|
|
||||||
```bash
|
|
||||||
systemctl stop radarr
|
|
||||||
sqlite3 /var/lib/radarr/radarr.db "DELETE FROM IndexerStatus WHERE ProviderId=1;"
|
|
||||||
systemctl start radarr
|
|
||||||
```
|
|
||||||
|
|
||||||
**SSH from DO:**
|
|
||||||
```bash
|
|
||||||
sshpass -p 'Joker1974!!!' ssh -o StrictHostKeyChecking=no root@10.48.200.90 \
|
|
||||||
'ssh -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa root@10.48.200.35 "COMMAND"'
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### VM 118 — Homebridge (PVE1)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **IP** | 10.48.200.18 |
|
|
||||||
| **OS** | Linux |
|
|
||||||
| **SSH** | `ssh myron@10.48.200.18` — password: `Joker1974!` |
|
|
||||||
| **Purpose** | Apple HomeKit bridge — exposes non-HomeKit devices to Apple Home app |
|
|
||||||
| **JARVIS Agent** | ID: `homebridge_b57cbaea` |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### VM 120 — NovaCPX Hosting Panel (PVE1)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **IP** | 10.48.200.110 |
|
|
||||||
| **OS** | Ubuntu 24.04 LTS |
|
|
||||||
| **SSH** | `ssh root@10.48.200.110` — password: `Joker1974!!!` (direct, no PVE hop) |
|
|
||||||
| **Purpose** | Custom web hosting control panel (cPanel alternative), v1.0.27 |
|
|
||||||
| **JARVIS Agent** | ID: `novacpx_e3b07264` |
|
|
||||||
|
|
||||||
**Ports:**
|
|
||||||
| Port | Panel |
|
|
||||||
|------|-------|
|
|
||||||
| :8880 | User panel |
|
|
||||||
| :8881 | Reseller panel |
|
|
||||||
| :8882 | Admin panel |
|
|
||||||
| :8883 | Roundcube webmail |
|
|
||||||
|
|
||||||
**Admin:** `https://10.48.200.110:8882` — `admin / Admin2026!`
|
|
||||||
**phpMyAdmin:** `http://10.48.200.110/phpmyadmin`
|
|
||||||
|
|
||||||
**File Paths:**
|
|
||||||
- Web root: `/srv/novacpx/public/`
|
|
||||||
- DB (SQLite): `/var/lib/novacpx/panel.db`
|
|
||||||
- Config: `/etc/novacpx/config.ini`
|
|
||||||
- Git repo: `/opt/novacpx-src/`
|
|
||||||
- GitHub: `myronblair/novacpx` (auto-deploy on push to `main`)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### VM 210 — Ollama Local LLM (PVE1)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **IP** | 10.48.200.210 |
|
|
||||||
| **OS** | Ubuntu (cloud image) |
|
|
||||||
| **SSH** | `ssh myron@10.48.200.95` — password: `Joker1974!` (then `sudo`) |
|
|
||||||
| **Purpose** | Local AI inference — runs llama3.2 model for JARVIS Tier 1 chat |
|
|
||||||
| **API** | `http://10.48.200.210:11434` (Ollama REST API) |
|
|
||||||
| **JARVIS Agent** | ID: `ollama-ai_ubuntu` |
|
|
||||||
|
|
||||||
**JARVIS uses this as Tier 1 AI** — if Ollama is down, falls back to Groq (cloud).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### VM 302 — NetworkBackup (PVE2)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **IP** | 10.48.200.99 |
|
|
||||||
| **OS** | Ubuntu/Linux |
|
|
||||||
| **SSH** | `ssh myron@10.48.200.99` — password: `Joker1974!` (then `sudo`) |
|
|
||||||
| **Purpose** | Network backup storage / backup operations |
|
|
||||||
| **JARVIS Agent** | ID: `networkbackup_NetworkB` |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### CT110 — WireGuard Exit Container (PVE1)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **IP** | 10.48.200.19 / 10.48.200.67 |
|
|
||||||
| **Purpose** | Legacy WireGuard exit tunnel to DO (10.200.0.4 via wg-exit) — currently NOT used by MediaStack/Jellyfin |
|
|
||||||
| **Note** | MediaStack uses NordVPN directly; Jellyfin uses wg1 peer on MediaStack for NFS only |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 5. NAS STORAGE
|
|
||||||
|
|
||||||
### Synology NAS
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **IP** | 10.48.200.249 |
|
|
||||||
| **Login** | `nas / Joker1974!!!` |
|
|
||||||
| **DSM Web UI** | `http://10.48.200.249:5000` |
|
|
||||||
| **Purpose** | Primary media and download storage |
|
|
||||||
|
|
||||||
**NFS Share:** `/volume1/video` (exported to MediaStack only)
|
|
||||||
|
|
||||||
**Directory structure:**
|
|
||||||
```
|
|
||||||
/volume1/video/
|
|
||||||
movies/ ← Radarr imports here; NFS-exported to Jellyfin via MediaStack
|
|
||||||
tv/ ← Sonarr imports here; NFS-exported to Jellyfin via MediaStack
|
|
||||||
downloads/ ← qBittorrent downloads here (temp)
|
|
||||||
incomplete/ ← in-progress torrents
|
|
||||||
```
|
|
||||||
|
|
||||||
**Important:** Synology NFS ACL only allows root to write. All services on MediaStack run as root.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 6. WEBSITES (ALL ON DO)
|
|
||||||
|
|
||||||
All sites are at `/home/<domain>/public_html/` on DO (165.22.1.228).
|
|
||||||
**Auto-deploy:** Push to `main` on GitHub → webhook → server pulls in ~1 min.
|
|
||||||
**GitHub PAT:** `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` (expires ~2026-08-20)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### jarvis.orbishosting.com — JARVIS AI Dashboard (MOVED TO PVE1 VM 211)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **URL** | http://jarvis.orbishosting.com:1972 |
|
|
||||||
| **Path** | `/var/www/jarvis/ (on JARVIS VM 10.48.200.211)` |
|
|
||||||
| **GitHub** | `myronblair/jarvis` |
|
|
||||||
| **Login** | `myron / Joker1974!!!` |
|
|
||||||
| **Purpose** | Iron Man-style AI home dashboard with voice control, smart home, media, planner |
|
|
||||||
|
|
||||||
See Section 7 for full JARVIS details.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### tomsjavajive.com — Tom's Java Jive
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **URL** | https://tomsjavajive.com |
|
|
||||||
| **Path** | `/home/tomsjavajive.com/public_html/` |
|
|
||||||
| **GitHub** | `myronblair/tomsjavajive` |
|
|
||||||
| **Purpose** | Coffee shop e-commerce — products, orders, loyalty, wallet, reviews |
|
|
||||||
| **Admin URL** | `https://tomsjavajive.com/admin/` |
|
|
||||||
| **Admin Login** | `admin@tomsjavajive.com / Joker1974!!!` OR `myronblair@outlook.com / Joker1974!!!` |
|
|
||||||
| **DB** | `toms_tjj_db / toms_tjj_user / +60wlPc+55e@gFq4` |
|
|
||||||
| **Email** | CyberMail API key: `sk_live_7f9b0f9a29f6de31a0d229d4af75d56b094ad724fc58a57d` |
|
|
||||||
| **Email From** | `noreply@tomsjavajive.com` / `Toms Java Jive` (set in DB settings table) |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### epictravelexpeditions.com — Epic Travel Expeditions
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **URL** | https://epictravelexpeditions.com |
|
|
||||||
| **Path** | `/home/epictravelexpeditions.com/public_html/` |
|
|
||||||
| **GitHub** | `myronblair/epictravelexpeditions` |
|
|
||||||
| **Purpose** | Travel booking / expeditions website |
|
|
||||||
| **DB** | `epic_travel_db` (see `api/config.php`) |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### parkerslingshot.epictravelexpeditions.com — Parker Slingshot (OLD)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **URL** | https://parkerslingshot.epictravelexpeditions.com |
|
|
||||||
| **Path** | `/home/epictravelexpeditions.com/parkerslingshot/` |
|
|
||||||
| **GitHub** | `myronblair/parkerslingshot` |
|
|
||||||
| **Purpose** | Old slingshot rental site (superseded by parkerslingshotrentals.com) |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### parkerslingshotrentals.com — Parker Slingshot Rentals (LIVE)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **URL** | https://www.parkerslingshotrentals.com |
|
|
||||||
| **Path** | `/home/parkerslingshotrentals.com/public_html/` |
|
|
||||||
| **GitHub** | `myronblair/parkerslingshotrentals` |
|
|
||||||
| **Purpose** | Polaris Slingshot rental — bookings, e-signature waiver, admin management |
|
|
||||||
| **Admin** | `/admin/index.php` — `admin / Parker2026!` |
|
|
||||||
| **DB** | `park_slingshot / park_slingshotuser / 4@rxg*8kovxCr7w6` |
|
|
||||||
| **Square** | Production token: `EAAAl3FsAu_2ri8kZE_ENEyi2T_C8HXXm5XQFY6Lbnd8SX6FqYp8J_upUeXNYh7v` |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### orbishosting.com — Orbis Hosting (Landing Page)
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **URL** | https://orbishosting.com |
|
|
||||||
| **Path** | `/home/orbishosting.com/public_html/` |
|
|
||||||
| **GitHub** | `myronblair/orbishosting` |
|
|
||||||
| **Purpose** | Public landing page for Orbis Hosting brand |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### orbis.orbishosting.com — Orbis Hosting Portal
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **URL** | https://orbis.orbishosting.com |
|
|
||||||
| **Path** | `/home/orbis.orbishosting.com/public_html/` |
|
|
||||||
| **GitHub** | `myronblair/orbis-hosting-portal` |
|
|
||||||
| **Purpose** | Customer-facing hosting portal |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### tomtomgames.com — TomTom Games
|
|
||||||
| Field | Value |
|
|
||||||
|-------|-------|
|
|
||||||
| **URL** | https://tomtomgames.com |
|
|
||||||
| **Path** | `/home/tomtomgames.com/public_html/` |
|
|
||||||
| **GitHub** | `myronblair/tomtomgames` |
|
|
||||||
| **Purpose** | Gaming website |
|
|
||||||
| **DB** | `tomtom_games_db` (see config) |
|
|
||||||
| **Email** | CyberMail API key: `sk_live_7f9b...` |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 7. JARVIS AI SYSTEM
|
|
||||||
|
|
||||||
**URL:** http://jarvis.orbishosting.com:1972
|
|
||||||
**Files:** `/var/www/jarvis/` on JARVIS VM (PVE1 VM 211 — 10.48.200.211, 8 cores, 16GB RAM)
|
|
||||||
**DB:** `jarvis_db` — `jarvis_user / J4rv1s_Pr0t0c0l_2026!`
|
|
||||||
**Login:** `myron / Joker1974!!!`
|
|
||||||
**Admin portal:** http://jarvis.orbishosting.com:1972/admin
|
|
||||||
|
|
||||||
### Architecture (end-to-end)
|
|
||||||
|
|
||||||
```
|
|
||||||
Voice (browser mic)
|
|
||||||
→ SpeechRecognition API
|
|
||||||
→ Wake phrase: "wake up JARVIS" / "daddy's home"
|
|
||||||
→ "JARVIS [command]" triggers action
|
|
||||||
→ /api/chat.php (4-tier AI)
|
|
||||||
Tier 0.7: KB intents / planner (tasks, appointments)
|
|
||||||
Tier 1: Knowledge Base (MySQL)
|
|
||||||
Tier 1.5: Ollama (10.48.200.210:11434, llama3.2) — local LLM
|
|
||||||
Tier 2: Groq (cloud, model: compound-beta-mini)
|
|
||||||
Tier 3: Claude API (Anthropic, fallback)
|
|
||||||
→ ElevenLabs TTS → browser speaker
|
|
||||||
```
|
|
||||||
|
|
||||||
### Deploy Pipeline
|
|
||||||
```
|
|
||||||
Code edit → git push → GitHub webhook → /webhook.php (HMAC verified)
|
|
||||||
→ /tmp/jarvis-deploy-queue.txt → /usr/local/bin/jarvis-deploy.sh (cron 1min)
|
|
||||||
→ git pull + PHP syntax check → deploy or auto-revert
|
|
||||||
```
|
|
||||||
Webhook secret: `4c8805f0285214ff0a0602b5880270b935f36a896946c7f1`
|
|
||||||
|
|
||||||
### Agent System
|
|
||||||
Agents installed on all servers — phone home every 10s (heartbeat) / 30s (metrics).
|
|
||||||
Registration key: `f846a9aaf7ce9a61742c63c87c4186052a71d2a580c65518`
|
|
||||||
Install command: `curl -sk http://10.48.200.211/install-agent.sh | bash -s <hostname> <linux|proxmox>`
|
|
||||||
|
|
||||||
### Self-Healing Watchdog
|
|
||||||
`/usr/local/bin/jarvis-watchdog.sh` — runs every 5 min (root cron on DO)
|
|
||||||
Restarts: lsws, mysql, redis if down
|
|
||||||
Restarts offline Proxmox VM agents via `qm guest exec`
|
|
||||||
|
|
||||||
### Cron Jobs (DO server)
|
|
||||||
| Schedule | Script | Purpose |
|
|
||||||
|----------|--------|---------|
|
|
||||||
| Every 1 min | `jarvis-deploy.sh` | Process GitHub deploy queue |
|
|
||||||
| Every 3 min | `facts_collector.php` | Collect agent metrics, KB facts, site health |
|
|
||||||
| Every 5 min | `stats_cache.php` | Weather, news, Proxmox stats refresh |
|
|
||||||
| Every 5 min | `jarvis-watchdog.sh` | Self-healing: restart dead services |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 8. PHONE SYSTEM (FUSIONPBX)
|
|
||||||
|
|
||||||
### Extensions
|
|
||||||
| Ext | Name | Phone | IP | SIP Password |
|
|
||||||
|-----|------|-------|----|-------------|
|
|
||||||
| 1000 | Myron Blair — Desk | Yealink T48S | 10.48.200.2 | `Xk9mPw3nQv7rLs2t` |
|
|
||||||
| 1001 | Tommy Ivy — Desk | Yealink T48S | 10.48.200.43 | `Tv8xNm4pWq6rZs3k` |
|
|
||||||
| 1002 | Myron Blair — WiFi Work | Yealink AX86R | 10.48.200.65 | `yXHaJTwa8rj?$GkrVFQB` |
|
|
||||||
| 1003 | Kitchen | Yealink T57W | 10.48.200.83 | — |
|
|
||||||
| 1004 | Master Bedroom | Yealink T57W | 10.48.200.85 | — |
|
|
||||||
| 1010 | Parker County Slingshot | Virtual (voicemail only) | — | — |
|
|
||||||
| 1011 | Epic Travel Expeditions | Virtual (voicemail only) | — | — |
|
|
||||||
| 1012 | Tom's Java Jive | Virtual (voicemail only) | — | — |
|
|
||||||
| 900 | IVR | — | — | (auto-attendant) |
|
|
||||||
|
|
||||||
**Phone SIP Settings (all phones):**
|
|
||||||
- Server: `134.209.72.226`
|
|
||||||
- Port: `5080`
|
|
||||||
- Transport: UDP
|
|
||||||
|
|
||||||
**Provisioning URL:** `https://fusion.orbishosting.com/app/provision/`
|
|
||||||
(Username: `provision-master`, Password: `Joker1974!!!`)
|
|
||||||
|
|
||||||
### Call Flow
|
|
||||||
```
|
|
||||||
Inbound (+18177645007)
|
|
||||||
→ SignalWire → FusionPBX:5080 (UDP)
|
|
||||||
→ signalwire-inbound dialplan (catch-all ^.*$)
|
|
||||||
→ IVR ext 900 (ivr_menu_16k.wav)
|
|
||||||
→ Routes to extensions 1000/1001/1002/1003/1004
|
|
||||||
|
|
||||||
Outbound
|
|
||||||
→ Phone → FusionPBX:5080
|
|
||||||
→ signalwire gateway → SignalWire → PSTN
|
|
||||||
```
|
|
||||||
|
|
||||||
### FreeSWITCH CLI Commands
|
|
||||||
```bash
|
|
||||||
fs_cli -x "sofia status profile external reg" # check registrations
|
|
||||||
fs_cli -x "sofia xmlstatus gateway" # check SignalWire gateway
|
|
||||||
fs_cli -x "reloadxml" # reload config (safe)
|
|
||||||
fs_cli -x "reloadacl" # reload ACL (safe)
|
|
||||||
# AVOID: sofia profile external restart (drops all phone registrations)
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 9. NETWORKING & VPN
|
|
||||||
|
|
||||||
### FortiGate Firewall
|
|
||||||
- WAN IP: 97.154.109.245 (dynamic)
|
|
||||||
- DDNS: `orbisne.fortiddns.com` (FortiGate auto-updates on IP change)
|
|
||||||
- Blocks: outbound port 53 (DNS) — MediaStack uses PVE1 dnsmasq (10.48.200.90) as resolver → 100.100.100.100
|
|
||||||
|
|
||||||
**Port Forwards:**
|
|
||||||
| External Port | Internal Destination | Purpose |
|
|
||||||
|--------------|---------------------|---------|
|
|
||||||
| :8006 | PVE1:8006 | Proxmox web UI |
|
|
||||||
| :8123 | HA VM:8123 | Home Assistant |
|
|
||||||
| :22 | HA VM:22 | HA SSH (unreliable) |
|
|
||||||
|
|
||||||
### WireGuard — Jellyfin ↔ MediaStack
|
|
||||||
- MediaStack runs WireGuard server on `wg1` (port 51820, subnet 10.200.0.1/24)
|
|
||||||
- Jellyfin peer: 10.200.0.3 (active handshake)
|
|
||||||
- Used for NFS media file access ONLY — not internet VPN
|
|
||||||
|
|
||||||
### NordVPN — MediaStack Internet Traffic
|
|
||||||
- Interface: `nordlynx` on MediaStack
|
|
||||||
- Exit IP: 181.214.226.188 (US Dallas)
|
|
||||||
- Policy routing: table 205 (all traffic via nordlynx), managed by `nordvpn-routing.service`
|
|
||||||
- Required for IPTorrents access (blocks non-VPN IPs)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 10. BACKUP SYSTEMS
|
|
||||||
|
|
||||||
### DO Server Backup
|
|
||||||
- **Repo:** `myronblair/do-server-config`
|
|
||||||
- **Schedule:** Weekly, Sunday 4am
|
|
||||||
- **Launcher:** `/usr/local/bin/do-server-backup` on DO
|
|
||||||
- **Covers:** Scripts, systemd units, WireGuard, OLS vhosts, cron, MySQL credentials
|
|
||||||
- **Restore:** 8-phase wizard in `restore.sh`
|
|
||||||
- **DB backups:** `jarvis-backup.sh` runs daily (separate)
|
|
||||||
|
|
||||||
### Proxmox Config Backup
|
|
||||||
- **Repo:** `myronblair/proxmox-config`
|
|
||||||
- **Schedule:** Weekly, Sunday 3am (both PVE1 and PVE2)
|
|
||||||
- **Launcher:** `/usr/local/bin/proxmox-backup` on each node
|
|
||||||
- **Covers:** VM .conf files, network, cron, systemd, scripts
|
|
||||||
- **VM disks:** Covered by Proxmox Backup Server (PBS)
|
|
||||||
|
|
||||||
### FusionPBX Backup
|
|
||||||
- **Repo:** `myronblair/fusionpbx-config`
|
|
||||||
- **Schedule:** Weekly, Sunday 5am
|
|
||||||
- **Launcher:** `/usr/local/bin/fusionpbx-backup`
|
|
||||||
- **Covers:** PostgreSQL dump (gzip, ~29MB) + FreeSWITCH configs
|
|
||||||
- **Restore:** 10-phase wizard in `restore.sh`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 11. SSH QUICK REFERENCE
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# DO (main web server)
|
|
||||||
sshpass -p 'Gonewalk1974!@#' ssh -o StrictHostKeyChecking=no root@165.22.1.228
|
|
||||||
|
|
||||||
# FusionPBX (must relay via DO)
|
|
||||||
sshpass -p 'Gonewalk1974!@#' ssh root@165.22.1.228 \
|
|
||||||
'sshpass -p "Joker1974!@#" ssh root@134.209.72.226 "CMD"'
|
|
||||||
|
|
||||||
# PVE1 (direct or via DDNS)
|
|
||||||
sshpass -p 'Joker1974!!!' ssh -o StrictHostKeyChecking=no root@orbisne.fortiddns.com
|
|
||||||
sshpass -p 'Joker1974!!!' ssh -o StrictHostKeyChecking=no root@10.48.200.90
|
|
||||||
|
|
||||||
# PVE2
|
|
||||||
sshpass -p 'Joker1974!!!' ssh -o StrictHostKeyChecking=no root@10.48.200.91
|
|
||||||
|
|
||||||
# MediaStack (via PVE1)
|
|
||||||
sshpass -p 'Joker1974!!!' ssh root@10.48.200.90 \
|
|
||||||
'ssh -i /root/.ssh/id_rsa root@10.48.200.35 "CMD"'
|
|
||||||
|
|
||||||
# Jellyfin (direct, password enabled 2026-06-14)
|
|
||||||
sshpass -p 'Joker1974!!!' ssh -o StrictHostKeyChecking=no root@10.48.200.33
|
|
||||||
|
|
||||||
# NovaCPX (direct)
|
|
||||||
sshpass -p 'Joker1974!!!' ssh -o StrictHostKeyChecking=no root@10.48.200.110
|
|
||||||
|
|
||||||
# Ollama / Homebridge / NetworkBackup (myron user, then sudo)
|
|
||||||
sshpass -p 'Joker1974!' ssh myron@10.48.200.95 # Ollama
|
|
||||||
sshpass -p 'Joker1974!' ssh myron@10.48.200.18 # Homebridge
|
|
||||||
sshpass -p 'Joker1974!' ssh myron@10.48.200.99 # NetworkBackup
|
|
||||||
|
|
||||||
# Run command inside VM via Proxmox (requires QEMU agent installed)
|
|
||||||
sshpass -p 'Joker1974!!!' ssh root@10.48.200.90 \
|
|
||||||
'qm guest exec 210 -- bash -c "CMD"'
|
|
||||||
```
|
|
||||||
|
|
||||||
**Password fallback order:** `Joker1974!@#` → `Joker1974!!!` → `Joker1974!`
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 12. CRITICAL CREDENTIALS MASTER LIST
|
|
||||||
|
|
||||||
### SSH / Root Access
|
|
||||||
| System | User | Password | Notes |
|
|
||||||
|--------|------|----------|-------|
|
|
||||||
| DO (165.22.1.228) | root | `Gonewalk1974!@#` | Main web server |
|
|
||||||
| FusionPBX (134.209.72.226) | root | `Joker1974!@#` | Via DO relay |
|
|
||||||
| PVE1 (10.48.200.90) | root | `Joker1974!!!` | Also via DDNS |
|
|
||||||
| PVE2 (10.48.200.91) | root | `Joker1974!!!` | |
|
|
||||||
| MediaStack (10.48.200.35) | root | key only | Via PVE1 (`/root/.ssh/id_rsa`) |
|
|
||||||
| Jellyfin (10.48.200.33) | root | `Joker1974!!!` | Enabled 2026-06-14 |
|
|
||||||
| NovaCPX (10.48.200.110) | root | `Joker1974!!!` | Direct SSH works |
|
|
||||||
| Ollama / Homebridge / Backup VMs | myron | `Joker1974!` | Then sudo |
|
|
||||||
|
|
||||||
### Web Panels & Admin
|
|
||||||
| System | URL | User | Password |
|
|
||||||
|--------|-----|------|----------|
|
|
||||||
| CyberPanel | https://165.22.1.228:8090 | myron | `Joker1974!!!` |
|
|
||||||
| phpMyAdmin (DO) | https://165.22.1.228/phpmyadmin | myron | `Joker1974!!!` |
|
|
||||||
| Proxmox PVE1 | https://orbisne.fortiddns.com:8006 | root | `Joker1974!!!` |
|
|
||||||
| Proxmox PVE2 | https://10.48.200.91:8006 | root | `Joker1974!!!` |
|
|
||||||
| JARVIS | http://jarvis.orbishosting.com:1972 | myron | `Joker1974!!!` |
|
|
||||||
| JARVIS Admin | http://jarvis.orbishosting.com:1972/admin | myron | `Joker1974!!!` |
|
|
||||||
| FusionPBX | https://fusion.orbishosting.com | admin | `fY7XP5swgtpbzrYLhkeVYkA4744` |
|
|
||||||
| Home Assistant | http://orbisne.fortiddns.com:8123 | myron | (HA password) |
|
|
||||||
| NovaCPX Admin | https://10.48.200.110:8882 | admin | `Admin2026!` |
|
|
||||||
| Jellyfin | http://10.48.200.33:8096 | — | token: `7c0ccf78b91d4b5bafa607f585f24f2d` |
|
|
||||||
| qBittorrent | http://10.48.200.35:8080 | admin | `Joker1974!!!` |
|
|
||||||
| Sonarr | http://10.48.200.35:8989 | admin | `Joker1974!!!` |
|
|
||||||
| Radarr | http://10.48.200.35:7878 | admin | `Joker1974!!!` |
|
|
||||||
| Prowlarr | http://10.48.200.35:9696 | admin | `Joker1974!!!` |
|
|
||||||
| Synology NAS | http://10.48.200.249:5000 | nas | `Joker1974!!!` |
|
|
||||||
| Parker Slingshot Admin | https://parkerslingshotrentals.com/admin | admin | `Parker2026!` |
|
|
||||||
| TJJ Admin | https://tomsjavajive.com/admin | `admin@tomsjavajive.com` OR `myronblair@outlook.com` | `Joker1974!!!` |
|
|
||||||
|
|
||||||
### Databases
|
|
||||||
| Site | DB Name | DB User | DB Password |
|
|
||||||
|------|---------|---------|-------------|
|
|
||||||
| JARVIS | `jarvis_db` | `jarvis_user` | `J4rv1s_Pr0t0c0l_2026!` |
|
|
||||||
| Tom's Java Jive | `toms_tjj_db` | `toms_tjj_user` | `+60wlPc+55e@gFq4` |
|
|
||||||
| Parker Slingshot Rentals | `park_slingshot` | `park_slingshotuser` | `4@rxg*8kovxCr7w6` |
|
|
||||||
| Epic Travel | `epic_travel_db` | (see config.php) | (see config.php) |
|
|
||||||
| Epic/Parker Slingshot | `epic_parkersling` | `epic_parkersling` | `Joker1974!!!` |
|
|
||||||
| NovaCPX | SQLite: `/var/lib/novacpx/panel.db` | — | — |
|
|
||||||
| FusionPBX | PostgreSQL | `fusionpbx` | `pSJaF9mUJqPr4Sj5mwJyRqvCCpc` |
|
|
||||||
| MySQL root (DO) | — | root | `b71e5c1a8c7457541b9c1db822de37adfa271926a38b6c20` |
|
|
||||||
|
|
||||||
### API Keys
|
|
||||||
| Service | Key |
|
|
||||||
|---------|-----|
|
|
||||||
| GitHub PAT | `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` (exp ~2026-08-20) |
|
|
||||||
| JARVIS Agent Registration | `f846a9aaf7ce9a61742c63c87c4186052a71d2a580c65518` |
|
|
||||||
| Proxmox API Token | `root@pam!jarvis=c45b5feb-f9a9-445d-a626-14fbb959f78b` |
|
|
||||||
| HA Long-lived Token | `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIzNmI0N2I1Njk5ZGQ0MTQ2ODMwZWFmYjZiYTQ1MjJkMSIsImlhdCI6MTc4MDIwMzU5NCwiZXhwIjoyMDk1NTYzNTk0fQ.sYRok-jRDlA4lFgWxLQELcEjkJNGQdprk6ZziLwLtXE` |
|
|
||||||
| Sonarr API | `b43e04350a594846b4ee95261c29e9e0` |
|
|
||||||
| Radarr API | `53c4268360444feeae5f98c0cc24e0e3` |
|
|
||||||
| Prowlarr API | `9d0ce6c5660743b5bf1c7951efc62252` |
|
|
||||||
| Jellyfin Admin Token | `7c0ccf78b91d4b5bafa607f585f24f2d` |
|
|
||||||
| Square (Parker) Production | `EAAAl3FsAu_2ri8kZE_ENEyi2T_C8HXXm5XQFY6Lbnd8SX6FqYp8J_upUeXNYh7v` |
|
|
||||||
| Square App ID (Parker) | `sq0idp-YSM7BU9IVyOWSzpeP-0nzQ` |
|
|
||||||
| Webhook HMAC Secret | `4c8805f0285214ff0a0602b5880270b935f36a896946c7f1` |
|
|
||||||
|
|
||||||
### SIP / Phone
|
|
||||||
| Extension | Name | SIP Password |
|
|
||||||
|-----------|------|-------------|
|
|
||||||
| 1000 | Myron Blair — Desk (10.48.200.2) | `Xk9mPw3nQv7rLs2t` |
|
|
||||||
| 1001 | Tommy Ivy — Desk (10.48.200.43) | `Tv8xNm4pWq6rZs3k` |
|
|
||||||
| 1002 | Myron Blair — WiFi Work (10.48.200.65) | `yXHaJTwa8rj?$GkrVFQB` |
|
|
||||||
| 1003 | Kitchen (10.48.200.83) | — |
|
|
||||||
| 1004 | Master Bedroom (10.48.200.85) | — |
|
|
||||||
| 1010 | Parker County Slingshot (voicemail only) | — |
|
|
||||||
| 1011 | Epic Travel Expeditions (voicemail only) | — |
|
|
||||||
| 1012 | Tom's Java Jive (voicemail only) | — |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
*This document contains sensitive credentials. Store securely and do not share.*
|
|
||||||
+763
-48
@@ -242,9 +242,7 @@ if ($action) {
|
|||||||
$search = strtolower(trim($_GET['search'] ?? ''));
|
$search = strtolower(trim($_GET['search'] ?? ''));
|
||||||
$skipDomains = ['sensor','binary_sensor','button','update','select','number',
|
$skipDomains = ['sensor','binary_sensor','button','update','select','number',
|
||||||
'device_tracker','event','image','person','zone','tts','conversation',
|
'device_tracker','event','image','person','zone','tts','conversation',
|
||||||
'assist_satellite','input_button','media_player','scene','water_heater',
|
'assist_satellite','input_button'];
|
||||||
'alarm_control_panel','automation','script','calendar','notify',
|
|
||||||
'weather','camera','siren','remote','todo','lawn_mower'];
|
|
||||||
$skipKeywords = ['pre_release','_record','_ftp_','_push_','_hub_ringtone',
|
$skipKeywords = ['pre_release','_record','_ftp_','_push_','_hub_ringtone',
|
||||||
'_siren_on','_email_on','_manual_record','_infrared_',
|
'_siren_on','_email_on','_manual_record','_infrared_',
|
||||||
'do_not_disturb','matter_server','zerotier','mariadb',
|
'do_not_disturb','matter_server','zerotier','mariadb',
|
||||||
@@ -432,7 +430,7 @@ if ($action) {
|
|||||||
|
|
||||||
|
|
||||||
case 'cal_feeds_list':
|
case 'cal_feeds_list':
|
||||||
j(JarvisDB::query("SELECT * FROM calendar_feeds ORDER BY source,name") ?? []);
|
j(JarvisDB::query("SELECT id,name,source,ics_url,username,(password != '' AND password IS NOT NULL) AS has_password,active,created_at FROM calendar_feeds ORDER BY source,name") ?? []);
|
||||||
|
|
||||||
case 'cal_feed_save':
|
case 'cal_feed_save':
|
||||||
$id = (int)($_POST['id'] ?? 0);
|
$id = (int)($_POST['id'] ?? 0);
|
||||||
@@ -489,25 +487,26 @@ if ($action) {
|
|||||||
$arcCounts = [];
|
$arcCounts = [];
|
||||||
foreach ($arcStats as $r) $arcCounts[$r['status']] = (int)$r['cnt'];
|
foreach ($arcStats as $r) $arcCounts[$r['status']] = (int)$r['cnt'];
|
||||||
$cronLast = [];
|
$cronLast = [];
|
||||||
$cronLog = '/home/jarvis.orbishosting.com/logs/cron.log';
|
$cronLog = '/var/log/jarvis/cron.log';
|
||||||
if (file_exists($cronLog)) {
|
if (file_exists($cronLog)) {
|
||||||
$lines = array_filter(explode("\n", shell_exec("grep -a 'facts\\|stats\\|calendar' " . escapeshellarg($cronLog) . " | tail -60")));
|
$lines = array_filter(explode("\n", shell_exec("grep -a 'facts\\|stats\\|calendar\\|intent' " . escapeshellarg($cronLog) . " | tail -60")));
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
if (preg_match('/^\\[(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\].*facts/i', $line, $m)) $cronLast['facts_collector'] = $m[1];
|
if (preg_match('/^\\[?(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\]?.*facts/i', $line, $m)) $cronLast['facts_collector'] = $m[1];
|
||||||
if (preg_match('/^\\[(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\].*stats/i', $line, $m)) $cronLast['stats_cache'] = $m[1];
|
if (preg_match('/^\\[?(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\]?.*stats/i', $line, $m)) $cronLast['stats_cache'] = $m[1];
|
||||||
if (preg_match('/^\\[(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\].*calendar/i', $line, $m)) $cronLast['calendar_sync'] = $m[1];
|
if (preg_match('/^\\[?(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\]?.*calendar/i', $line, $m)) $cronLast['calendar_sync'] = $m[1];
|
||||||
|
if (preg_match('/^\\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\\].*intent/i', $line, $m)) $cronLast['kb_intent_generator'] = $m[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($cronLast['stats_cache'])) {
|
if (empty($cronLast['stats_cache'])) {
|
||||||
$row = JarvisDB::query('SELECT MAX(updated_at) as t FROM api_cache WHERE cache_key IN ("weather","news")');
|
$row = JarvisDB::query('SELECT MAX(updated_at) as t FROM api_cache WHERE cache_key IN ("weather","news")');
|
||||||
if (!empty($row[0]['t'])) $cronLast['stats_cache'] = $row[0]['t'];
|
if (!empty($row[0]['t'])) $cronLast['stats_cache'] = $row[0]['t'];
|
||||||
}
|
}
|
||||||
$deployLog = '/home/jarvis.orbishosting.com/logs/deploy.log';
|
$deployLog = '/var/log/jarvis/deploy.log';
|
||||||
if (file_exists($deployLog)) {
|
if (file_exists($deployLog)) {
|
||||||
$last = shell_exec("grep -a '\\[' " . escapeshellarg($deployLog) . " | tail -1");
|
$last = shell_exec("grep -a '\\[' " . escapeshellarg($deployLog) . " | tail -1");
|
||||||
if (preg_match('/^\\[(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\]/', trim($last), $m)) $cronLast['jarvis_deploy'] = $m[1];
|
if (preg_match('/^\\[(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\]/', trim($last), $m)) $cronLast['jarvis_deploy'] = $m[1];
|
||||||
}
|
}
|
||||||
$wdLog = '/home/jarvis.orbishosting.com/logs/watchdog.log';
|
$wdLog = '/var/log/jarvis/watchdog.log';
|
||||||
if (file_exists($wdLog)) $cronLast['jarvis_watchdog'] = date('Y-m-d H:i:s', filemtime($wdLog));
|
if (file_exists($wdLog)) $cronLast['jarvis_watchdog'] = date('Y-m-d H:i:s', filemtime($wdLog));
|
||||||
$bkLog = '/var/backups/jarvis/backup.log';
|
$bkLog = '/var/backups/jarvis/backup.log';
|
||||||
if (file_exists($bkLog)) {
|
if (file_exists($bkLog)) {
|
||||||
@@ -520,9 +519,9 @@ if ($action) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'worker_action':
|
case 'worker_action':
|
||||||
$wType = $data['worker_type'] ?? '';
|
$wType = $_REQUEST['worker_type'] ?? '';
|
||||||
$wId = $data['worker_id'] ?? '';
|
$wId = $_REQUEST['worker_id'] ?? '';
|
||||||
$wAction = $data['action'] ?? '';
|
$wAction = $_REQUEST['waction'] ?? $_REQUEST['action'] ?? '';
|
||||||
if ($wType === 'agent' && $wAction === 'update') {
|
if ($wType === 'agent' && $wAction === 'update') {
|
||||||
JarvisDB::execute('INSERT INTO agent_commands (agent_id,command_type,command_data,status) VALUES (?,?,?,?)',
|
JarvisDB::execute('INSERT INTO agent_commands (agent_id,command_type,command_data,status) VALUES (?,?,?,?)',
|
||||||
[$wId,'update','{}','pending']);
|
[$wId,'update','{}','pending']);
|
||||||
@@ -535,39 +534,203 @@ if ($action) {
|
|||||||
j(json_decode(curl_exec($ch),true)?:['error'=>'reactor unreachable']);
|
j(json_decode(curl_exec($ch),true)?:['error'=>'reactor unreachable']);
|
||||||
} elseif ($wType === 'cron' && $wAction === 'run') {
|
} elseif ($wType === 'cron' && $wAction === 'run') {
|
||||||
$scripts = [
|
$scripts = [
|
||||||
'facts_collector'=>[true, '/home/jarvis.orbishosting.com/api/endpoints/facts_collector.php'],
|
'facts_collector' =>[true, '/var/www/jarvis/api/endpoints/facts_collector.php'],
|
||||||
'stats_cache' =>[true, '/home/jarvis.orbishosting.com/api/endpoints/stats_cache.php'],
|
'stats_cache' =>[true, '/var/www/jarvis/api/endpoints/stats_cache.php'],
|
||||||
'calendar_sync' =>[true, '/home/jarvis.orbishosting.com/api/endpoints/calendar_sync.php'],
|
'calendar_sync' =>[true, '/var/www/jarvis/api/endpoints/calendar_sync.php'],
|
||||||
|
'kb_intent_generator' =>[true, '/var/www/jarvis/api/endpoints/kb_intent_generator.php'],
|
||||||
'jarvis_deploy' =>[false,'/usr/local/bin/jarvis-deploy.sh'],
|
'jarvis_deploy' =>[false,'/usr/local/bin/jarvis-deploy.sh'],
|
||||||
'jarvis_watchdog'=>[false,'/usr/local/bin/jarvis-watchdog.sh'],
|
'jarvis_watchdog' =>[false,'/usr/local/bin/jarvis-watchdog.sh'],
|
||||||
];
|
];
|
||||||
if (isset($scripts[$wId])) {
|
if (isset($scripts[$wId])) {
|
||||||
[$isPhp,$path] = $scripts[$wId];
|
[$isPhp,$path] = $scripts[$wId];
|
||||||
|
$env = ($wId === 'kb_intent_generator') ? 'JARVIS_FORCE_RUN=1 ' : '';
|
||||||
$cmd = $isPhp
|
$cmd = $isPhp
|
||||||
? '/usr/local/lsws/lsphp85/bin/lsphp '.escapeshellarg($path).' >> /home/jarvis.orbishosting.com/logs/cron.log 2>&1 &'
|
? $env.'/usr/bin/php8.3 '.escapeshellarg($path).' >> /var/log/jarvis/cron.log 2>&1 &'
|
||||||
: escapeshellcmd($path).' >> /home/jarvis.orbishosting.com/logs/deploy.log 2>&1 &';
|
: escapeshellcmd($path).' >> /var/log/jarvis/deploy.log 2>&1 &';
|
||||||
shell_exec($cmd);
|
shell_exec($cmd);
|
||||||
j(['ok'=>true,'msg'=>ucwords(str_replace('_',' ',$wId)).' triggered']);
|
j(['ok'=>true,'msg'=>ucwords(str_replace('_',' ',$wId)).' triggered']);
|
||||||
} else { bad('Unknown cron worker'); }
|
} else { bad('Unknown cron worker'); }
|
||||||
} elseif ($wType === 'daemon' && $wId === 'arc_reactor' && $wAction === 'restart') {
|
} elseif ($wType === 'daemon' && $wId === 'arc_reactor' && $wAction === 'restart') {
|
||||||
shell_exec('bash -c "mkdir -p /home/jarvis.orbishosting.com/logs; systemctl restart jarvis-arc 2>/dev/null || (pkill -f reactor.py 2>/dev/null; sleep 1; cd /opt/jarvis-arc && source venv/bin/activate && nohup python3 reactor.py >> /home/jarvis.orbishosting.com/logs/arc_reactor.log 2>&1 &)"');
|
shell_exec('systemctl restart jarvis-arc 2>&1');
|
||||||
j(['ok'=>true,'msg'=>'Arc Reactor restarting']);
|
j(['ok'=>true,'msg'=>'Arc Reactor restarting via systemd']);
|
||||||
} elseif ($wType === 'daemon' && $wId === 'arc_reactor' && $wAction === 'setup') {
|
} elseif ($wType === 'daemon' && $wId === 'arc_reactor' && $wAction === 'setup') {
|
||||||
$setupLog = '/home/jarvis.orbishosting.com/logs/arc_reactor.log';
|
$log = '/var/log/jarvis/arc-setup.log';
|
||||||
$cmd = 'bash -c "'.
|
$cmd = implode(' && ', [
|
||||||
'mkdir -p /opt/jarvis-arc /home/jarvis.orbishosting.com/logs && '.
|
'mkdir -p /opt/jarvis-arc /var/log/jarvis',
|
||||||
'cp /var/www/jarvis/deploy/reactor.py /opt/jarvis-arc/reactor.py && '.
|
'cp /var/www/jarvis/deploy/reactor.py /opt/jarvis-arc/reactor.py',
|
||||||
'cp /var/www/jarvis/deploy/requirements.txt /opt/jarvis-arc/requirements.txt && '.
|
'cp /var/www/jarvis/deploy/requirements.txt /opt/jarvis-arc/requirements.txt',
|
||||||
'if [ ! -d /opt/jarvis-arc/venv ]; then python3 -m venv /opt/jarvis-arc/venv; fi && '.
|
'[ ! -f /opt/jarvis-arc/venv/bin/activate ] && python3 -m venv /opt/jarvis-arc/venv || true',
|
||||||
'/opt/jarvis-arc/venv/bin/pip install -q -r /opt/jarvis-arc/requirements.txt && '.
|
'/opt/jarvis-arc/venv/bin/pip install -q -r /opt/jarvis-arc/requirements.txt',
|
||||||
'pkill -f reactor.py 2>/dev/null; sleep 1 && '.
|
'cp /var/www/jarvis/deploy/jarvis-arc.service /etc/systemd/system/jarvis-arc.service',
|
||||||
'cd /opt/jarvis-arc && source venv/bin/activate && '.
|
'systemctl daemon-reload',
|
||||||
'nohup python3 reactor.py >> '.$setupLog.' 2>&1 &'.
|
'systemctl enable jarvis-arc',
|
||||||
'" >> '.$setupLog.' 2>&1';
|
'systemctl restart jarvis-arc',
|
||||||
shell_exec($cmd);
|
]);
|
||||||
j(['ok'=>true,'msg'=>'Arc Reactor setup started — check log in ~30s then restart']);
|
shell_exec("($cmd) >> " . escapeshellarg($log) . " 2>&1 &");
|
||||||
|
j(['ok'=>true,'msg'=>'Arc Reactor setup started — check ' . $log]);
|
||||||
|
} elseif ($wType === 'agent' && $wAction === 'update_status') {
|
||||||
|
$ag = JarvisDB::single('SELECT version, status FROM registered_agents WHERE agent_id=?', [$wId]);
|
||||||
|
j(['ok'=>true,'version'=>$ag['version']??null,'status'=>$ag['status']??'unknown']);
|
||||||
} else { bad('Invalid worker action'); }
|
} else { bad('Invalid worker action'); }
|
||||||
break;
|
break;
|
||||||
|
case 'intent_gen_history':
|
||||||
|
$logFile = '/var/log/jarvis/cron.log';
|
||||||
|
$result = ['last_success'=>null,'last_success_count'=>null,'failures'=>[]];
|
||||||
|
if (file_exists($logFile)) {
|
||||||
|
$lines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
|
$cutoff = time() - 7 * 86400;
|
||||||
|
foreach (array_reverse($lines) as $line) {
|
||||||
|
if (stripos($line, 'KB Intent Generator') === false) continue;
|
||||||
|
// parse timestamp
|
||||||
|
preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\]/', $line, $tm);
|
||||||
|
$ts = isset($tm[1]) ? strtotime($tm[1]) : 0;
|
||||||
|
// last success (done/complete)
|
||||||
|
if (!$result['last_success'] && preg_match('/done|complete/i', $line)) {
|
||||||
|
$result['last_success'] = $tm[1] ?? null;
|
||||||
|
preg_match('/inserted[:\s]+(\d+)/i', $line, $cnt);
|
||||||
|
$result['last_success_count'] = isset($cnt[1]) ? (int)$cnt[1] : null;
|
||||||
|
}
|
||||||
|
// failures in last 7 days
|
||||||
|
if ($ts >= $cutoff && preg_match('/error|fail/i', $line)) {
|
||||||
|
$result['failures'][] = $line;
|
||||||
|
if (count($result['failures']) >= 20) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result['failures'] = array_reverse($result['failures']);
|
||||||
|
}
|
||||||
|
j($result);
|
||||||
|
case 'intent_gen_log':
|
||||||
|
$logFile = '/var/log/jarvis/cron.log';
|
||||||
|
$since = max(0, (int)($_GET['since'] ?? 0));
|
||||||
|
if (!file_exists($logFile)) { j(['lines'=>[],'next_line'=>0]); }
|
||||||
|
$allLines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
|
$total = count($allLines);
|
||||||
|
// snapshot=1 just returns the current line count (call BEFORE triggering run)
|
||||||
|
if (!empty($_GET['snapshot'])) { j(['next_line'=>$total]); }
|
||||||
|
// Return only KB Intent Generator lines from position $since onward
|
||||||
|
$out = [];
|
||||||
|
for ($i = $since; $i < $total; $i++) {
|
||||||
|
if (stripos($allLines[$i], 'KB Intent Generator') !== false) {
|
||||||
|
$out[] = $allLines[$i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
j(['lines'=>$out, 'next_line'=>$total]);
|
||||||
|
|
||||||
|
// ── GENERIC WORKER LOG (live-popup support for Facts/Stats/Calendar) ────────
|
||||||
|
case 'worker_log':
|
||||||
|
$wKeywords = [
|
||||||
|
'facts_collector' => '/facts|system:|network:|proxmox:|ha:|do_server:|ollama:|sites:|nmap_scan:/i',
|
||||||
|
'stats_cache' => '/\[cache\]/i',
|
||||||
|
'calendar_sync' => '/calendar/i',
|
||||||
|
];
|
||||||
|
$wid = $_REQUEST['worker_id'] ?? '';
|
||||||
|
if (!isset($wKeywords[$wid])) { bad('Unknown worker'); }
|
||||||
|
$logFile = '/var/log/jarvis/cron.log';
|
||||||
|
$since = max(0, (int)($_GET['since'] ?? 0));
|
||||||
|
if (!file_exists($logFile)) { j(['lines'=>[],'next_line'=>0]); }
|
||||||
|
$allLines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
|
$total = count($allLines);
|
||||||
|
if (!empty($_GET['snapshot'])) { j(['next_line'=>$total]); }
|
||||||
|
$out = [];
|
||||||
|
for ($i = $since; $i < $total; $i++) {
|
||||||
|
if (preg_match($wKeywords[$wid], $allLines[$i])) $out[] = $allLines[$i];
|
||||||
|
}
|
||||||
|
j(['lines'=>$out, 'next_line'=>$total]);
|
||||||
|
|
||||||
|
case 'worker_history':
|
||||||
|
$wKeywords = [
|
||||||
|
'facts_collector' => '/facts|system:|network:|proxmox:|ha:|do_server:|ollama:|sites:|nmap_scan:/i',
|
||||||
|
'stats_cache' => '/\[cache\]/i',
|
||||||
|
'calendar_sync' => '/calendar/i',
|
||||||
|
];
|
||||||
|
$wid = $_REQUEST['worker_id'] ?? '';
|
||||||
|
if (!isset($wKeywords[$wid])) { bad('Unknown worker'); }
|
||||||
|
$logFile = '/var/log/jarvis/cron.log';
|
||||||
|
$result = ['last_success'=>null,'last_success_count'=>null,'failures'=>[]];
|
||||||
|
if (file_exists($logFile)) {
|
||||||
|
$lines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
|
$cutoff = time() - 7 * 86400;
|
||||||
|
foreach (array_reverse($lines) as $line) {
|
||||||
|
if (!preg_match($wKeywords[$wid], $line)) continue;
|
||||||
|
preg_match('/^\[?(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\]?/', $line, $tm);
|
||||||
|
$ts = isset($tm[1]) ? strtotime($tm[1]) : 0;
|
||||||
|
if (!$result['last_success'] && preg_match('/done|complete|collected|synced/i', $line)) {
|
||||||
|
$result['last_success'] = $tm[1] ?? null;
|
||||||
|
}
|
||||||
|
if ($ts >= $cutoff && preg_match('/error|fail/i', $line)) {
|
||||||
|
$result['failures'][] = $line;
|
||||||
|
if (count($result['failures']) >= 20) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result['failures'] = array_reverse($result['failures']);
|
||||||
|
}
|
||||||
|
j($result);
|
||||||
|
|
||||||
|
// ── KB GENERATOR TOPICS ─────────────────────────────────────────────
|
||||||
|
case 'kb_topics':
|
||||||
|
$where = ['1=1']; $params = [];
|
||||||
|
if (!empty($_GET['q'])) {
|
||||||
|
$q2 = '%'.$_GET['q'].'%';
|
||||||
|
$where[] = '(topic_name LIKE ? OR topic_id LIKE ? OR category LIKE ? OR description LIKE ?)';
|
||||||
|
$params = array_merge($params, [$q2,$q2,$q2,$q2]);
|
||||||
|
}
|
||||||
|
if (isset($_GET['cat']) && $_GET['cat'] !== '') { $where[] = 'category=?'; $params[] = $_GET['cat']; }
|
||||||
|
if (isset($_GET['active']) && $_GET['active'] !== '') { $where[] = 'active=?'; $params[] = (int)$_GET['active']; }
|
||||||
|
$topics = JarvisDB::query(
|
||||||
|
'SELECT id,topic_id,category,topic_name,description,active,run_count,last_run_at
|
||||||
|
FROM kb_generator_topics WHERE '.implode(' AND ',$where).' ORDER BY category,topic_name',
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
$catRows = JarvisDB::query('SELECT DISTINCT category FROM kb_generator_topics ORDER BY category');
|
||||||
|
j(['topics'=>$topics, 'categories'=>array_column($catRows,'category')]);
|
||||||
|
|
||||||
|
case 'kb_topic_save':
|
||||||
|
$id = (int)($_POST['id'] ?? 0);
|
||||||
|
$tid = preg_replace('/[^a-z0-9_]/', '_', strtolower(trim($_POST['topic_id'] ?? '')));
|
||||||
|
$cat = trim($_POST['category'] ?? '');
|
||||||
|
$name = trim($_POST['topic_name'] ?? '');
|
||||||
|
$desc = trim($_POST['description'] ?? '');
|
||||||
|
$act = (int)!empty($_POST['active']);
|
||||||
|
if (!$tid || !preg_match('/[a-z0-9]/', $tid) || !$cat || !$name || !$desc)
|
||||||
|
bad('All fields required — topic_id must contain at least one letter or digit');
|
||||||
|
try {
|
||||||
|
if ($id) {
|
||||||
|
JarvisDB::execute(
|
||||||
|
'UPDATE kb_generator_topics SET topic_id=?,category=?,topic_name=?,description=?,active=?,updated_at=NOW() WHERE id=?',
|
||||||
|
[$tid,$cat,$name,$desc,$act,$id]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
JarvisDB::execute(
|
||||||
|
'INSERT INTO kb_generator_topics (topic_id,category,topic_name,description,active) VALUES (?,?,?,?,?)',
|
||||||
|
[$tid,$cat,$name,$desc,$act]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
bad(strpos($e->getMessage(), 'Duplicate entry') !== false
|
||||||
|
? 'topic_id already in use — choose a different slug'
|
||||||
|
: 'Database error');
|
||||||
|
}
|
||||||
|
j(['ok'=>true,'msg'=> $id ? 'Topic updated' : 'Topic created']);
|
||||||
|
|
||||||
|
case 'kb_topic_delete':
|
||||||
|
$id = (int)($_POST['id'] ?? 0); if (!$id) bad('Missing id');
|
||||||
|
JarvisDB::execute('DELETE FROM kb_generator_topics WHERE id=?', [$id]);
|
||||||
|
j(['ok'=>true]);
|
||||||
|
|
||||||
|
case 'kb_topic_toggle':
|
||||||
|
$id = (int)($_POST['id'] ?? 0); if (!$id) bad('Missing id');
|
||||||
|
JarvisDB::execute('UPDATE kb_generator_topics SET active=NOT active, updated_at=NOW() WHERE id=?', [$id]);
|
||||||
|
$row = JarvisDB::single('SELECT active FROM kb_generator_topics WHERE id=?', [$id]);
|
||||||
|
j(['ok'=>true,'active'=>(bool)$row['active']]);
|
||||||
|
|
||||||
|
case 'arc_setup_log':
|
||||||
|
$logFile = '/var/log/jarvis/arc-setup.log';
|
||||||
|
$since = max(0, (int)($_GET['since'] ?? 0));
|
||||||
|
if (!file_exists($logFile)) { j(['lines'=>[],'next_line'=>0]); }
|
||||||
|
$allLines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
|
$total = count($allLines);
|
||||||
|
if (!empty($_GET['snapshot'])) { j(['next_line'=>$total]); }
|
||||||
|
j(['lines'=>array_values(array_slice($allLines, $since)), 'next_line'=>$total]);
|
||||||
case 'arc_status':
|
case 'arc_status':
|
||||||
$ch = curl_init('http://127.0.0.1:7474/status');
|
$ch = curl_init('http://127.0.0.1:7474/status');
|
||||||
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>5, CURLOPT_CONNECTTIMEOUT=>3]);
|
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>5, CURLOPT_CONNECTTIMEOUT=>3]);
|
||||||
@@ -1142,6 +1305,17 @@ if ($action) {
|
|||||||
readfile($path);
|
readfile($path);
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
case 'docs_download':
|
||||||
|
$path = '/var/www/jarvis-private/INFRASTRUCTURE-REFERENCE.md';
|
||||||
|
if (!file_exists($path)) bad('File not found', 404);
|
||||||
|
header('Content-Type: text/markdown');
|
||||||
|
header('Content-Disposition: attachment; filename="INFRASTRUCTURE-REFERENCE.md"');
|
||||||
|
header('Content-Length: ' . filesize($path));
|
||||||
|
header('X-Accel-Buffering: no');
|
||||||
|
ob_end_clean();
|
||||||
|
readfile($path);
|
||||||
|
exit;
|
||||||
|
|
||||||
default: bad('Unknown action');
|
default: bad('Unknown action');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1442,6 +1616,8 @@ select.filter-sel:focus{border-color:var(--cyan)}
|
|||||||
<button class="btn btn-sm btn-green" onclick="intentModal()">+ ADD INTENT</button>
|
<button class="btn btn-sm btn-green" onclick="intentModal()">+ ADD INTENT</button>
|
||||||
<button class="btn btn-sm btn-yellow" onclick="intentTestModal()">TEST PATTERN</button>
|
<button class="btn btn-sm btn-yellow" onclick="intentTestModal()">TEST PATTERN</button>
|
||||||
<button class="btn btn-sm" onclick="loadIntents()">REFRESH</button>
|
<button class="btn btn-sm" onclick="loadIntents()">REFRESH</button>
|
||||||
|
<button class="btn btn-sm" style="border-color:#7f5fff;color:#7f5fff" onclick="openTopicsManager()">⚙ MANAGE TOPICS</button>
|
||||||
|
<button class="btn btn-sm" style="border-color:#00d4ff;color:#00d4ff" onclick="runIntentGenerator()">▶ RUN GENERATOR</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="display:flex;gap:8px;margin-bottom:10px;align-items:center">
|
<div style="display:flex;gap:8px;margin-bottom:10px;align-items:center">
|
||||||
@@ -1529,7 +1705,7 @@ select.filter-sel:focus{border-color:var(--cyan)}
|
|||||||
<div class="card" style="padding:24px;margin:20px 0">
|
<div class="card" style="padding:24px;margin:20px 0">
|
||||||
<div style="font-size:0.7rem;letter-spacing:2px;color:var(--cyan);margin-bottom:8px">INFRASTRUCTURE REFERENCE</div>
|
<div style="font-size:0.7rem;letter-spacing:2px;color:var(--cyan);margin-bottom:8px">INFRASTRUCTURE REFERENCE</div>
|
||||||
<div style="color:var(--text-dim);font-size:0.75rem;margin-bottom:16px">Complete server map, credentials, deployment workflow, service configs, and phone system reference.</div>
|
<div style="color:var(--text-dim);font-size:0.75rem;margin-bottom:16px">Complete server map, credentials, deployment workflow, service configs, and phone system reference.</div>
|
||||||
<a href="downloads/INFRASTRUCTURE-REFERENCE.md" download="INFRASTRUCTURE-REFERENCE.md"
|
<a href="?action=docs_download" download="INFRASTRUCTURE-REFERENCE.md"
|
||||||
style="display:inline-block;padding:8px 20px;background:rgba(0,212,255,0.1);border:1px solid var(--cyan);color:var(--cyan);font-size:0.7rem;letter-spacing:2px;text-decoration:none">
|
style="display:inline-block;padding:8px 20px;background:rgba(0,212,255,0.1);border:1px solid var(--cyan);color:var(--cyan);font-size:0.7rem;letter-spacing:2px;text-decoration:none">
|
||||||
↓ DOWNLOAD INFRASTRUCTURE-REFERENCE.MD
|
↓ DOWNLOAD INFRASTRUCTURE-REFERENCE.MD
|
||||||
</a>
|
</a>
|
||||||
@@ -2056,6 +2232,12 @@ let _alertFilter = 'active';
|
|||||||
let _modalCb = null;
|
let _modalCb = null;
|
||||||
|
|
||||||
function esc(s){ return String(s||'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); }
|
function esc(s){ return String(s||'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"'); }
|
||||||
|
// For values embedded inside a single-quoted JS string literal within an HTML attribute
|
||||||
|
// (e.g. onclick="fn('${escJs(x)}')"). Escaping the quote via esc() alone is NOT enough:
|
||||||
|
// the browser HTML-decodes the attribute before parsing it as JS, so '/" would
|
||||||
|
// just turn back into a literal ' before the JS parser ever sees it. Backslash-escaping
|
||||||
|
// survives that decode step, so JS-escape first, then HTML-escape on top.
|
||||||
|
function escJs(s){ return esc(String(s||'').replace(/\\/g,'\\\\').replace(/'/g,"\\'").replace(/\n/g,'\\n').replace(/\r/g,'\\r')); }
|
||||||
function ts(s){ if(!s) return '—'; const d=new Date(s); return d.toLocaleString('en-US',{month:'short',day:'numeric',hour:'2-digit',minute:'2-digit'}); }
|
function ts(s){ if(!s) return '—'; const d=new Date(s); return d.toLocaleString('en-US',{month:'short',day:'numeric',hour:'2-digit',minute:'2-digit'}); }
|
||||||
function ago(s){ if(!s) return '—'; const sec=Math.floor((Date.now()-new Date(s))/1000); if(sec<60) return sec+'s ago'; if(sec<3600) return Math.floor(sec/60)+'m ago'; return Math.floor(sec/3600)+'h ago'; }
|
function ago(s){ if(!s) return '—'; const sec=Math.floor((Date.now()-new Date(s))/1000); if(sec<60) return sec+'s ago'; if(sec<3600) return Math.floor(sec/60)+'m ago'; return Math.floor(sec/3600)+'h ago'; }
|
||||||
function fmtUp(s){ const d=Math.floor(s/86400),h=Math.floor((s%86400)/3600),m=Math.floor((s%3600)/60); return (d>0?d+'d ':'')+h+'h '+m+'m'; }
|
function fmtUp(s){ const d=Math.floor(s/86400),h=Math.floor((s%86400)/3600),m=Math.floor((s%3600)/60); return (d>0?d+'d ':'')+h+'h '+m+'m'; }
|
||||||
@@ -2174,7 +2356,8 @@ const CRON_DEFS = [
|
|||||||
{id:'jarvis_deploy', label:'Deploy Runner', schedule:'Every 1 min', host:'jarvis-do'},
|
{id:'jarvis_deploy', label:'Deploy Runner', schedule:'Every 1 min', host:'jarvis-do'},
|
||||||
{id:'jarvis_watchdog', label:'Watchdog', schedule:'Every 5 min', host:'jarvis-do'},
|
{id:'jarvis_watchdog', label:'Watchdog', schedule:'Every 5 min', host:'jarvis-do'},
|
||||||
{id:'jarvis_backup', label:'JARVIS Backup', schedule:'Daily 2am', host:'jarvis-do', norun:true},
|
{id:'jarvis_backup', label:'JARVIS Backup', schedule:'Daily 2am', host:'jarvis-do', norun:true},
|
||||||
{id:'do_server_backup',label:'DO Server Backup', schedule:'Weekly Sun 4am', host:'jarvis-do', norun:true},
|
{id:'do_server_backup', label:'DO Server Backup', schedule:'Weekly Sun 4am', host:'jarvis-do', norun:true},
|
||||||
|
{id:'kb_intent_generator', label:'KB Intent Generator', schedule:'Daily 3am', host:'jarvis'},
|
||||||
];
|
];
|
||||||
function wBtn(col) {
|
function wBtn(col) {
|
||||||
const c={cyan:'var(--cyan)',red:'var(--red)',green:'var(--green)',dim:'var(--dim)'}[col]||'var(--dim)';
|
const c={cyan:'var(--cyan)',red:'var(--red)',green:'var(--green)',dim:'var(--dim)'}[col]||'var(--dim)';
|
||||||
@@ -2201,12 +2384,530 @@ function wToast(msg,err=false) {
|
|||||||
t.style.opacity='1';t.textContent=msg;
|
t.style.opacity='1';t.textContent=msg;
|
||||||
setTimeout(()=>{t.style.opacity='0';},3000);
|
setTimeout(()=>{t.style.opacity='0';},3000);
|
||||||
}
|
}
|
||||||
|
async function runIntentGenerator() {
|
||||||
|
const modalHtml = `
|
||||||
|
<div style="font-family:var(--mono);font-size:0.72rem;line-height:1.8">
|
||||||
|
<div id="ig-history" style="background:#0a0f14;border:1px solid var(--border);border-radius:3px;padding:8px 12px;margin-bottom:10px;font-size:0.6rem;color:var(--text-dim)">Loading history...</div>
|
||||||
|
<div id="ig-status" style="color:var(--cyan);margin-bottom:8px;font-size:0.65rem;letter-spacing:1px">LAUNCHING...</div>
|
||||||
|
<div id="ig-log" style="background:#060a0e;border:1px solid var(--border);border-radius:3px;padding:10px 12px;min-height:160px;max-height:320px;overflow-y:auto;white-space:pre-wrap;font-size:0.62rem;line-height:1.7;color:var(--text-dim)">Waiting for first output...</div>
|
||||||
|
<div id="ig-stats" style="margin-top:10px;display:flex;gap:20px;font-size:0.6rem;color:var(--text-dim)"></div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
openModal('▶ KB INTENT GENERATOR', modalHtml, null, null);
|
||||||
|
document.getElementById('modalSave').textContent = 'CLOSE';
|
||||||
|
|
||||||
|
const logEl = document.getElementById('ig-log');
|
||||||
|
const statEl = document.getElementById('ig-status');
|
||||||
|
const statsEl = document.getElementById('ig-stats');
|
||||||
|
const historyEl = document.getElementById('ig-history');
|
||||||
|
|
||||||
|
let _igStop = false;
|
||||||
|
let _igDone = false;
|
||||||
|
let lastLine = 0;
|
||||||
|
let dotted = 0;
|
||||||
|
|
||||||
|
// Close just stops polling — server job keeps running
|
||||||
|
const stopAndClose = () => {
|
||||||
|
_igStop = true;
|
||||||
|
closeModal();
|
||||||
|
if (!_igDone) toast('KB generator running in background', 'ok');
|
||||||
|
};
|
||||||
|
document.getElementById('modalSave').onclick = stopAndClose;
|
||||||
|
document.getElementById('modalClose').onclick = stopAndClose;
|
||||||
|
|
||||||
|
// Load history panel (async, non-blocking)
|
||||||
|
api('intent_gen_history').then(h => {
|
||||||
|
if (!historyEl) return;
|
||||||
|
let html = '';
|
||||||
|
if (h?.last_success) {
|
||||||
|
html += `<span style="color:var(--green)">✓ Last success: ${h.last_success}`;
|
||||||
|
if (h.last_success_count != null) html += ` (+${h.last_success_count} intents)`;
|
||||||
|
html += '</span>';
|
||||||
|
} else {
|
||||||
|
html += '<span style="color:var(--text-dim)">No recorded successes in log</span>';
|
||||||
|
}
|
||||||
|
if (h?.failures?.length) {
|
||||||
|
html += `<br><span style="color:var(--red)">⚠ ${h.failures.length} failure line(s) in last 7 days:</span>`;
|
||||||
|
h.failures.slice(-3).forEach(f => {
|
||||||
|
html += `<div style="color:var(--red);opacity:0.7;margin-left:8px">${f.replace(/</g,'<')}</div>`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
historyEl.innerHTML = html || '<span>No history found</span>';
|
||||||
|
}).catch(() => { if (historyEl) historyEl.textContent = 'History unavailable'; });
|
||||||
|
|
||||||
|
// Snapshot log position BEFORE triggering
|
||||||
|
const snap = await api('intent_gen_log', {snapshot:1});
|
||||||
|
lastLine = snap?.next_line ?? 0;
|
||||||
|
|
||||||
|
// Kick off the generator (JARVIS_FORCE_RUN=1 set server-side — bypasses 20h guard)
|
||||||
|
const kick = await api('worker_action', {worker_type:'cron', worker_id:'kb_intent_generator', waction:'run'});
|
||||||
|
if (!kick || !kick.ok) {
|
||||||
|
statEl.style.color = 'var(--red)';
|
||||||
|
statEl.textContent = 'LAUNCH FAILED: ' + (kick?.error || 'unknown error');
|
||||||
|
document.getElementById('modalSave').textContent = 'CLOSE';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
statEl.textContent = 'RUNNING — polling log every 3s...';
|
||||||
|
|
||||||
|
async function pollLog() {
|
||||||
|
if (_igStop) return;
|
||||||
|
try {
|
||||||
|
const res = await api('intent_gen_log', {since: lastLine});
|
||||||
|
if (res && Array.isArray(res.lines) && res.lines.length) {
|
||||||
|
lastLine = res.next_line;
|
||||||
|
const isFirst = logEl.textContent === 'Waiting for first output...';
|
||||||
|
if (isFirst) logEl.textContent = '';
|
||||||
|
res.lines.forEach(line => {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
const lower = line.toLowerCase();
|
||||||
|
if (lower.includes('error') || lower.includes('fail'))
|
||||||
|
div.style.color = 'var(--red)';
|
||||||
|
else if (lower.includes('skip') || lower.includes('warn'))
|
||||||
|
div.style.color = 'var(--yellow)';
|
||||||
|
else if (lower.includes('insert') || lower.includes('added') || lower.includes('done') || lower.includes('complete') || lower.includes('cleanup') || lower.includes('force-run'))
|
||||||
|
div.style.color = 'var(--green)';
|
||||||
|
else
|
||||||
|
div.style.color = 'var(--text-dim)';
|
||||||
|
div.textContent = line;
|
||||||
|
logEl.appendChild(div);
|
||||||
|
});
|
||||||
|
logEl.scrollTop = logEl.scrollHeight;
|
||||||
|
|
||||||
|
const lastLines = res.lines.join(' ').toLowerCase();
|
||||||
|
if (lastLines.includes('kb intent generator: done') || lastLines.includes('total inserted') || lastLines.includes('cleanup complete')) {
|
||||||
|
_igDone = true;
|
||||||
|
statEl.style.color = 'var(--green)';
|
||||||
|
statEl.textContent = 'COMPLETE';
|
||||||
|
const total = (res.lines.join('\n').match(/inserted[:\s]+(\d+)/i) || [])[1];
|
||||||
|
if (total) statsEl.innerHTML = `<span style="color:var(--green)">+${total} intents added</span>`;
|
||||||
|
document.getElementById('modalSave').textContent = 'CLOSE';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dotted = 0;
|
||||||
|
} else {
|
||||||
|
dotted++;
|
||||||
|
if (dotted < 30) {
|
||||||
|
const waitDiv = document.createElement('div');
|
||||||
|
waitDiv.style.color = 'rgba(0,212,255,0.3)';
|
||||||
|
waitDiv.textContent = '· waiting for output' + '.'.repeat(dotted % 4);
|
||||||
|
const last = logEl.lastChild;
|
||||||
|
if (last && last.textContent && last.textContent.startsWith('· waiting')) {
|
||||||
|
logEl.replaceChild(waitDiv, last);
|
||||||
|
} else {
|
||||||
|
if (logEl.textContent === 'Waiting for first output...') logEl.textContent = '';
|
||||||
|
logEl.appendChild(waitDiv);
|
||||||
|
}
|
||||||
|
logEl.scrollTop = logEl.scrollHeight;
|
||||||
|
} else {
|
||||||
|
statEl.style.color = 'var(--yellow)';
|
||||||
|
statEl.textContent = 'RUNNING IN BACKGROUND (check cron log for results)';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
if (!_igStop) setTimeout(pollLog, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(pollLog, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generic live-log popup for simple cron workers (Facts Collector, Stats Cache, Calendar Sync).
|
||||||
|
// Same pattern as runIntentGenerator() above, parameterized instead of duplicated per worker.
|
||||||
|
async function runWorkerWithLog(workerId, label, doneRegex) {
|
||||||
|
const modalHtml = `
|
||||||
|
<div style="font-family:var(--mono);font-size:0.72rem;line-height:1.8">
|
||||||
|
<div id="wl-history" style="background:#0a0f14;border:1px solid var(--border);border-radius:3px;padding:8px 12px;margin-bottom:10px;font-size:0.6rem;color:var(--text-dim)">Loading history...</div>
|
||||||
|
<div id="wl-status" style="color:var(--cyan);margin-bottom:8px;font-size:0.65rem;letter-spacing:1px">LAUNCHING...</div>
|
||||||
|
<div id="wl-log" style="background:#060a0e;border:1px solid var(--border);border-radius:3px;padding:10px 12px;min-height:160px;max-height:320px;overflow-y:auto;white-space:pre-wrap;font-size:0.62rem;line-height:1.7;color:var(--text-dim)">Waiting for first output...</div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
openModal(`▶ ${label.toUpperCase()}`, modalHtml, null, null);
|
||||||
|
document.getElementById('modalSave').textContent = 'CLOSE';
|
||||||
|
|
||||||
|
const logEl = document.getElementById('wl-log');
|
||||||
|
const statEl = document.getElementById('wl-status');
|
||||||
|
const historyEl = document.getElementById('wl-history');
|
||||||
|
|
||||||
|
let _stop = false, _done = false, lastLine = 0, dotted = 0;
|
||||||
|
|
||||||
|
const stopAndClose = () => {
|
||||||
|
_stop = true;
|
||||||
|
closeModal();
|
||||||
|
if (!_done) wToast(`${label} running in background`);
|
||||||
|
};
|
||||||
|
document.getElementById('modalSave').onclick = stopAndClose;
|
||||||
|
document.getElementById('modalClose').onclick = stopAndClose;
|
||||||
|
|
||||||
|
api('worker_history', {worker_id: workerId}).then(h => {
|
||||||
|
if (!historyEl) return;
|
||||||
|
let html = '';
|
||||||
|
if (h?.last_success) html += `<span style="color:var(--green)">✓ Last success: ${h.last_success}</span>`;
|
||||||
|
else html += '<span style="color:var(--text-dim)">No recorded successes in log</span>';
|
||||||
|
if (h?.failures?.length) {
|
||||||
|
html += `<br><span style="color:var(--red)">⚠ ${h.failures.length} failure line(s) in last 7 days:</span>`;
|
||||||
|
h.failures.slice(-3).forEach(f => {
|
||||||
|
html += `<div style="color:var(--red);opacity:0.7;margin-left:8px">${f.replace(/</g,'<')}</div>`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
historyEl.innerHTML = html || '<span>No history found</span>';
|
||||||
|
}).catch(() => { if (historyEl) historyEl.textContent = 'History unavailable'; });
|
||||||
|
|
||||||
|
const snap = await api('worker_log', {worker_id: workerId, snapshot:1});
|
||||||
|
lastLine = snap?.next_line ?? 0;
|
||||||
|
|
||||||
|
const kick = await api('worker_action', {worker_type:'cron', worker_id: workerId, waction:'run'});
|
||||||
|
if (!kick || !kick.ok) {
|
||||||
|
statEl.style.color = 'var(--red)';
|
||||||
|
statEl.textContent = 'LAUNCH FAILED: ' + (kick?.error || 'unknown error');
|
||||||
|
document.getElementById('modalSave').textContent = 'CLOSE';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
statEl.textContent = 'RUNNING — polling log every 3s...';
|
||||||
|
|
||||||
|
async function pollLog() {
|
||||||
|
if (_stop) return;
|
||||||
|
try {
|
||||||
|
const res = await api('worker_log', {worker_id: workerId, since: lastLine});
|
||||||
|
if (res && Array.isArray(res.lines) && res.lines.length) {
|
||||||
|
lastLine = res.next_line;
|
||||||
|
if (logEl.textContent === 'Waiting for first output...') logEl.textContent = '';
|
||||||
|
res.lines.forEach(line => {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
const lower = line.toLowerCase();
|
||||||
|
if (lower.includes('error') || lower.includes('fail')) div.style.color = 'var(--red)';
|
||||||
|
else if (lower.includes('skip') || lower.includes('warn')) div.style.color = 'var(--yellow)';
|
||||||
|
else if (lower.includes('done') || lower.includes('complete') || lower.includes('ok')) div.style.color = 'var(--green)';
|
||||||
|
else div.style.color = 'var(--text-dim)';
|
||||||
|
div.textContent = line;
|
||||||
|
logEl.appendChild(div);
|
||||||
|
});
|
||||||
|
logEl.scrollTop = logEl.scrollHeight;
|
||||||
|
|
||||||
|
const joined = res.lines.join(' ').toLowerCase();
|
||||||
|
if (doneRegex.test(joined)) {
|
||||||
|
_done = true;
|
||||||
|
statEl.style.color = 'var(--green)';
|
||||||
|
statEl.textContent = 'COMPLETE';
|
||||||
|
document.getElementById('modalSave').textContent = 'CLOSE';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dotted = 0;
|
||||||
|
} else {
|
||||||
|
dotted++;
|
||||||
|
if (dotted < 30) {
|
||||||
|
const waitDiv = document.createElement('div');
|
||||||
|
waitDiv.style.color = 'rgba(0,212,255,0.3)';
|
||||||
|
waitDiv.textContent = '· waiting for output' + '.'.repeat(dotted % 4);
|
||||||
|
const last = logEl.lastChild;
|
||||||
|
if (last && last.textContent && last.textContent.startsWith('· waiting')) {
|
||||||
|
logEl.replaceChild(waitDiv, last);
|
||||||
|
} else {
|
||||||
|
if (logEl.textContent === 'Waiting for first output...') logEl.textContent = '';
|
||||||
|
logEl.appendChild(waitDiv);
|
||||||
|
}
|
||||||
|
logEl.scrollTop = logEl.scrollHeight;
|
||||||
|
} else {
|
||||||
|
statEl.style.color = 'var(--yellow)';
|
||||||
|
statEl.textContent = 'RUNNING IN BACKGROUND (check cron log for results)';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
if (!_stop) setTimeout(pollLog, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(pollLog, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
let _topicsData = [];
|
||||||
|
let _topicsCats = [];
|
||||||
|
|
||||||
|
async function openTopicsManager() {
|
||||||
|
const modalHtml = `
|
||||||
|
<div style="font-family:var(--mono);font-size:0.72rem">
|
||||||
|
<div id="tm-view-list">
|
||||||
|
<div style="display:flex;gap:8px;margin-bottom:8px;align-items:center;flex-wrap:wrap">
|
||||||
|
<input id="tm-search" type="text" placeholder="Search topics…" style="flex:1;min-width:140px;background:var(--bg2);border:1px solid var(--border);color:var(--fg);padding:5px 8px;font-size:0.7rem;border-radius:3px;font-family:inherit" oninput="tmFilter()">
|
||||||
|
<select id="tm-cat-filter" style="background:var(--bg2);border:1px solid var(--border);color:var(--fg);padding:5px 8px;font-size:0.7rem;border-radius:3px;font-family:inherit" onchange="tmFilter()">
|
||||||
|
<option value="">ALL CATEGORIES</option>
|
||||||
|
</select>
|
||||||
|
<select id="tm-active-filter" style="background:var(--bg2);border:1px solid var(--border);color:var(--fg);padding:5px 8px;font-size:0.7rem;border-radius:3px;font-family:inherit" onchange="tmFilter()">
|
||||||
|
<option value="">ALL STATUS</option>
|
||||||
|
<option value="1">ACTIVE</option>
|
||||||
|
<option value="0">DISABLED</option>
|
||||||
|
</select>
|
||||||
|
<button class="btn btn-sm btn-green" onclick="tmEditTopic(null)">+ ADD</button>
|
||||||
|
</div>
|
||||||
|
<div id="tm-stats" style="color:var(--text-dim);font-size:0.6rem;margin-bottom:6px;letter-spacing:0.5px"></div>
|
||||||
|
<div id="tm-list" style="max-height:370px;overflow-y:auto"><div class="loading">LOADING…</div></div>
|
||||||
|
</div>
|
||||||
|
<div id="tm-view-edit" style="display:none">
|
||||||
|
<div style="margin-bottom:12px">
|
||||||
|
<button class="btn btn-sm" onclick="tmShowList()">← BACK</button>
|
||||||
|
<span id="tm-edit-title" style="color:var(--cyan);margin-left:12px;font-size:0.65rem;letter-spacing:1px"></span>
|
||||||
|
</div>
|
||||||
|
<div style="display:grid;gap:8px">
|
||||||
|
<input type="hidden" id="tm-edit-id">
|
||||||
|
<div style="display:grid;grid-template-columns:1fr 1fr;gap:8px">
|
||||||
|
<label style="font-size:0.6rem;color:var(--text-dim)">TOPIC ID (slug)
|
||||||
|
<input id="tm-edit-tid" type="text" placeholder="e.g. math_arith" style="width:100%;margin-top:3px;background:var(--bg2);border:1px solid var(--border);color:var(--fg);padding:5px 8px;font-size:0.7rem;border-radius:3px;font-family:inherit;box-sizing:border-box">
|
||||||
|
</label>
|
||||||
|
<label style="font-size:0.6rem;color:var(--text-dim)">CATEGORY
|
||||||
|
<input id="tm-edit-cat" type="text" placeholder="e.g. mathematics" list="tm-cat-dl" style="width:100%;margin-top:3px;background:var(--bg2);border:1px solid var(--border);color:var(--fg);padding:5px 8px;font-size:0.7rem;border-radius:3px;font-family:inherit;box-sizing:border-box">
|
||||||
|
<datalist id="tm-cat-dl"></datalist>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<label style="font-size:0.6rem;color:var(--text-dim)">TOPIC NAME
|
||||||
|
<input id="tm-edit-name" type="text" placeholder="e.g. Arithmetic and number sense" style="width:100%;margin-top:3px;background:var(--bg2);border:1px solid var(--border);color:var(--fg);padding:5px 8px;font-size:0.7rem;border-radius:3px;font-family:inherit;box-sizing:border-box">
|
||||||
|
</label>
|
||||||
|
<label style="font-size:0.6rem;color:var(--text-dim)">DESCRIPTION (subtopics to cover — comma-separated)
|
||||||
|
<textarea id="tm-edit-desc" rows="5" placeholder="e.g. fractions, decimals, order of operations, prime numbers…" style="width:100%;margin-top:3px;background:var(--bg2);border:1px solid var(--border);color:var(--fg);padding:5px 8px;font-size:0.7rem;border-radius:3px;font-family:inherit;resize:vertical;box-sizing:border-box"></textarea>
|
||||||
|
</label>
|
||||||
|
<label style="font-size:0.6rem;color:var(--text-dim);display:flex;align-items:center;gap:6px;cursor:pointer">
|
||||||
|
<input id="tm-edit-active" type="checkbox" checked style="cursor:pointer"> ACTIVE (included in rotation)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
openModal('⚙ KB TOPIC MANAGER', modalHtml, null, null);
|
||||||
|
const saveBtn = document.getElementById('modalSave');
|
||||||
|
const closeBtn = document.getElementById('modalClose');
|
||||||
|
saveBtn.textContent = 'SAVE TOPIC';
|
||||||
|
saveBtn.style.display = 'none';
|
||||||
|
saveBtn.onclick = tmSaveTopic;
|
||||||
|
closeBtn.onclick = closeModal;
|
||||||
|
|
||||||
|
await tmLoadTopics();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function tmLoadTopics() {
|
||||||
|
const res = await api('kb_topics');
|
||||||
|
_topicsData = res?.topics || [];
|
||||||
|
_topicsCats = res?.categories || [];
|
||||||
|
|
||||||
|
const catSel = document.getElementById('tm-cat-filter');
|
||||||
|
if (catSel) {
|
||||||
|
const cur = catSel.value;
|
||||||
|
while (catSel.options.length > 1) catSel.remove(1);
|
||||||
|
_topicsCats.forEach(c => catSel.add(new Option(c.toUpperCase(), c)));
|
||||||
|
if (cur) catSel.value = cur;
|
||||||
|
}
|
||||||
|
const dl = document.getElementById('tm-cat-dl');
|
||||||
|
if (dl) { dl.innerHTML = ''; _topicsCats.forEach(c => { const o = document.createElement('option'); o.value=c; dl.appendChild(o); }); }
|
||||||
|
|
||||||
|
tmFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
function tmFilter() {
|
||||||
|
const q = (document.getElementById('tm-search')?.value || '').toLowerCase();
|
||||||
|
const cat = document.getElementById('tm-cat-filter')?.value || '';
|
||||||
|
const active = document.getElementById('tm-active-filter')?.value;
|
||||||
|
|
||||||
|
const rows = _topicsData.filter(t => {
|
||||||
|
if (cat && t.category !== cat) return false;
|
||||||
|
if (active !== '' && active !== null && active !== undefined && String(t.active) !== String(active)) return false;
|
||||||
|
if (q && !`${t.topic_name} ${t.topic_id} ${t.category} ${t.description}`.toLowerCase().includes(q)) return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
const total = _topicsData.length;
|
||||||
|
const activeCount = _topicsData.filter(t => t.active == 1).length;
|
||||||
|
const statsEl = document.getElementById('tm-stats');
|
||||||
|
if (statsEl) statsEl.innerHTML =
|
||||||
|
`<span style="color:var(--cyan)">${total} topics</span> | ` +
|
||||||
|
`<span style="color:var(--green)">${activeCount} active</span> | ` +
|
||||||
|
`<span style="color:var(--yellow)">${total-activeCount} disabled</span>` +
|
||||||
|
(rows.length < total ? ` | <span style="color:var(--text-dim)">${rows.length} shown</span>` : '');
|
||||||
|
|
||||||
|
const listEl = document.getElementById('tm-list');
|
||||||
|
if (!listEl) return;
|
||||||
|
if (!rows.length) {
|
||||||
|
listEl.innerHTML = '<div style="color:var(--text-dim);padding:20px;text-align:center">No topics match filter</div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
listEl.innerHTML = `<table style="width:100%;border-collapse:collapse">
|
||||||
|
<thead><tr style="color:var(--cyan);font-size:0.58rem;border-bottom:1px solid var(--border)">
|
||||||
|
<th style="padding:4px 6px;text-align:left;font-weight:normal">TOPIC ID</th>
|
||||||
|
<th style="padding:4px 6px;text-align:left;font-weight:normal">CATEGORY</th>
|
||||||
|
<th style="padding:4px 6px;text-align:left;font-weight:normal">TOPIC NAME</th>
|
||||||
|
<th style="padding:4px 6px;text-align:center;font-weight:normal">ON</th>
|
||||||
|
<th style="padding:4px 6px;text-align:center;font-weight:normal">RUNS</th>
|
||||||
|
<th style="padding:4px 6px;text-align:right;font-weight:normal">ACTIONS</th>
|
||||||
|
</tr></thead>
|
||||||
|
<tbody>${rows.map(t => `
|
||||||
|
<tr style="border-bottom:1px solid rgba(255,255,255,0.03);font-size:0.65rem">
|
||||||
|
<td style="padding:4px 6px;color:var(--text-dim);font-size:0.57rem">${esc(t.topic_id)}</td>
|
||||||
|
<td style="padding:4px 6px"><span style="background:var(--bg2);padding:1px 5px;border-radius:2px;font-size:0.57rem;white-space:nowrap">${esc(t.category)}</span></td>
|
||||||
|
<td style="padding:4px 6px;max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${esc(t.description)}">${esc(t.topic_name)}</td>
|
||||||
|
<td style="padding:4px 6px;text-align:center">
|
||||||
|
<input type="checkbox" ${t.active==1?'checked':''} onchange="tmToggle(${t.id},this)" style="cursor:pointer;accent-color:var(--green)">
|
||||||
|
</td>
|
||||||
|
<td style="padding:4px 6px;text-align:center;color:var(--text-dim);font-size:0.6rem">${t.run_count||0}</td>
|
||||||
|
<td style="padding:4px 6px;text-align:right;white-space:nowrap">
|
||||||
|
<button class="btn btn-sm btn-yellow" style="padding:2px 7px;font-size:0.58rem" onclick="tmEditTopic(${t.id})">EDIT</button>
|
||||||
|
<button class="btn btn-sm btn-red" style="padding:2px 7px;font-size:0.58rem;margin-left:3px" onclick="tmDelete(${t.id})">DEL</button>
|
||||||
|
</td>
|
||||||
|
</tr>`).join('')}
|
||||||
|
</tbody></table>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tmShowList() {
|
||||||
|
document.getElementById('tm-view-list').style.display = '';
|
||||||
|
document.getElementById('tm-view-edit').style.display = 'none';
|
||||||
|
document.getElementById('modalSave').style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
function tmEditTopic(id) {
|
||||||
|
document.getElementById('tm-view-list').style.display = 'none';
|
||||||
|
document.getElementById('tm-view-edit').style.display = '';
|
||||||
|
document.getElementById('modalSave').style.display = '';
|
||||||
|
|
||||||
|
const tidEl = document.getElementById('tm-edit-tid');
|
||||||
|
if (id) {
|
||||||
|
const t = _topicsData.find(x => x.id == id);
|
||||||
|
if (!t) return;
|
||||||
|
document.getElementById('tm-edit-title').textContent = 'EDIT TOPIC: ' + t.topic_id;
|
||||||
|
document.getElementById('tm-edit-id').value = t.id;
|
||||||
|
tidEl.value = t.topic_id;
|
||||||
|
tidEl.readOnly = true;
|
||||||
|
tidEl.style.opacity = '0.6';
|
||||||
|
document.getElementById('tm-edit-cat').value = t.category;
|
||||||
|
document.getElementById('tm-edit-name').value = t.topic_name;
|
||||||
|
document.getElementById('tm-edit-desc').value = t.description;
|
||||||
|
document.getElementById('tm-edit-active').checked = t.active == 1;
|
||||||
|
} else {
|
||||||
|
document.getElementById('tm-edit-title').textContent = 'ADD NEW TOPIC';
|
||||||
|
document.getElementById('tm-edit-id').value = '';
|
||||||
|
tidEl.value = '';
|
||||||
|
tidEl.readOnly = false;
|
||||||
|
tidEl.style.opacity = '1';
|
||||||
|
document.getElementById('tm-edit-cat').value = '';
|
||||||
|
document.getElementById('tm-edit-name').value = '';
|
||||||
|
document.getElementById('tm-edit-desc').value = '';
|
||||||
|
document.getElementById('tm-edit-active').checked = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function tmSaveTopic() {
|
||||||
|
const id = document.getElementById('tm-edit-id').value;
|
||||||
|
const data = {
|
||||||
|
id: id ? parseInt(id) : 0,
|
||||||
|
topic_id: document.getElementById('tm-edit-tid').value.trim(),
|
||||||
|
category: document.getElementById('tm-edit-cat').value.trim(),
|
||||||
|
topic_name: document.getElementById('tm-edit-name').value.trim(),
|
||||||
|
description: document.getElementById('tm-edit-desc').value.trim(),
|
||||||
|
active: document.getElementById('tm-edit-active').checked ? 1 : 0,
|
||||||
|
};
|
||||||
|
if (!data.topic_id || !data.category || !data.topic_name || !data.description) {
|
||||||
|
toast('All fields are required', 'err'); return;
|
||||||
|
}
|
||||||
|
apiPost('kb_topic_save', data, async (res) => {
|
||||||
|
toast(res?.msg || 'Saved', 'ok');
|
||||||
|
tmShowList();
|
||||||
|
await tmLoadTopics();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function tmToggle(id, el) {
|
||||||
|
const prev = !el.checked;
|
||||||
|
const fd = new FormData();
|
||||||
|
fd.append('action', 'kb_topic_toggle');
|
||||||
|
fd.append('id', id);
|
||||||
|
try {
|
||||||
|
const r = await fetch(location.href, {method:'POST', body:fd});
|
||||||
|
const d = await r.json();
|
||||||
|
if (d.error) { toast(d.error, 'err'); el.checked = prev; return; }
|
||||||
|
const t = _topicsData.find(x => x.id == id);
|
||||||
|
if (t) t.active = d.active ? 1 : 0;
|
||||||
|
tmFilter();
|
||||||
|
} catch(e) { toast('Toggle failed', 'err'); el.checked = prev; }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function tmDelete(id) {
|
||||||
|
const t = _topicsData.find(x => x.id == id);
|
||||||
|
const name = t?.topic_name || 'this topic';
|
||||||
|
openModal('CONFIRM DELETE',
|
||||||
|
`<div style="font-family:var(--mono);font-size:0.75rem;line-height:2;padding:4px 0">Delete topic:<br>` +
|
||||||
|
`<span style="color:var(--red)">${esc(name)}</span><br>` +
|
||||||
|
`<span style="color:var(--text-dim);font-size:0.65rem">This cannot be undone.</span></div>`,
|
||||||
|
() => { apiPost('kb_topic_delete', {id}, async () => { toast('Topic deleted', 'ok'); await openTopicsManager(); }); },
|
||||||
|
'DELETE');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async function arcSetup() {
|
||||||
|
const modalHtml = `
|
||||||
|
<div style="font-family:var(--mono);font-size:0.72rem;line-height:1.8">
|
||||||
|
<div id="as-status" style="color:var(--cyan);margin-bottom:8px;font-size:0.65rem;letter-spacing:1px">LAUNCHING...</div>
|
||||||
|
<div id="as-log" style="background:#060a0e;border:1px solid var(--border);border-radius:3px;padding:10px 12px;min-height:160px;max-height:360px;overflow-y:auto;white-space:pre-wrap;font-size:0.62rem;line-height:1.7;color:var(--text-dim)">Waiting for output...</div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
openModal("⚙ ARC REACTOR SETUP", modalHtml, null, null);
|
||||||
|
document.getElementById("modalSave").textContent = "CLOSE";
|
||||||
|
let _stop = false;
|
||||||
|
document.getElementById("modalSave").onclick = () => { _stop = true; closeModal(); loadWorkers(); };
|
||||||
|
document.getElementById("modalClose").onclick = () => { _stop = true; closeModal(); loadWorkers(); };
|
||||||
|
|
||||||
|
const logEl = document.getElementById("as-log");
|
||||||
|
const statEl = document.getElementById("as-status");
|
||||||
|
|
||||||
|
const snap = await api("arc_setup_log", {snapshot:1});
|
||||||
|
let lastLine = snap?.next_line ?? 0;
|
||||||
|
|
||||||
|
const kick = await api("worker", {type:"daemon", id:"arc_reactor", action:"setup"});
|
||||||
|
if (!kick?.ok) {
|
||||||
|
statEl.style.color = "var(--red)";
|
||||||
|
statEl.textContent = "LAUNCH FAILED: " + (kick?.msg || kick?.error || "unknown");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
statEl.textContent = "RUNNING — polling every 2s...";
|
||||||
|
|
||||||
|
async function pollLog() {
|
||||||
|
if (_stop) return;
|
||||||
|
try {
|
||||||
|
const res = await api("arc_setup_log", {since: lastLine});
|
||||||
|
if (res?.lines?.length) {
|
||||||
|
lastLine = res.next_line;
|
||||||
|
if (logEl.textContent === "Waiting for output...") logEl.textContent = "";
|
||||||
|
res.lines.forEach(line => {
|
||||||
|
const d = document.createElement("div");
|
||||||
|
const l = line.toLowerCase();
|
||||||
|
if (l.includes("error") || l.includes("fail")) d.style.color = "var(--red)";
|
||||||
|
else if (l.includes("warn") || l.includes("skip")) d.style.color = "var(--yellow)";
|
||||||
|
else if (l.includes("ok") || l.includes("done") || l.includes("active") ||
|
||||||
|
l.includes("success") || l.includes("restart") || l.includes("enabled")) d.style.color = "var(--green)";
|
||||||
|
else d.style.color = "var(--text-dim)";
|
||||||
|
d.textContent = line;
|
||||||
|
logEl.appendChild(d);
|
||||||
|
});
|
||||||
|
logEl.scrollTop = logEl.scrollHeight;
|
||||||
|
const joined = res.lines.join(" ").toLowerCase();
|
||||||
|
if (joined.includes("systemctl restart") || joined.includes("active") ||
|
||||||
|
joined.includes("done") || joined.includes("failed")) {
|
||||||
|
statEl.style.color = (joined.includes("error") || joined.includes("fail")) ? "var(--red)" : "var(--green)";
|
||||||
|
statEl.textContent = (joined.includes("error") || joined.includes("fail")) ? "SETUP FAILED" : "SETUP COMPLETE";
|
||||||
|
document.getElementById("modalSave").textContent = "CLOSE";
|
||||||
|
loadWorkers(); return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
setTimeout(pollLog, 2000);
|
||||||
|
}
|
||||||
|
setTimeout(pollLog, 1500);
|
||||||
|
}
|
||||||
|
|
||||||
async function workerAction(type,id,action) {
|
async function workerAction(type,id,action) {
|
||||||
if (type === 'agent' && action === 'update') {
|
if (type === 'agent' && action === 'update') {
|
||||||
await agentUpdateFlow(id);
|
await agentUpdateFlow(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const res=await api('worker_action',{worker_type:type,worker_id:id,action});
|
const res=await api('worker_action',{worker_type:type,worker_id:id,waction:action});
|
||||||
if(res&&res.ok){wToast(res.msg||'Done');setTimeout(loadWorkers,2500);}
|
if(res&&res.ok){wToast(res.msg||'Done');setTimeout(loadWorkers,2500);}
|
||||||
else wToast((res&&res.error)||'Action failed',true);
|
else wToast((res&&res.error)||'Action failed',true);
|
||||||
}
|
}
|
||||||
@@ -2231,7 +2932,7 @@ async function agentUpdateFlow(agentId) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Dispatch command
|
// Dispatch command
|
||||||
const res = await api('worker_action', {worker_type:'agent', worker_id:agentId, action:'update'});
|
const res = await api('worker_action', {worker_type:'agent', worker_id:agentId, waction:'update'});
|
||||||
if (!res || !res.ok) {
|
if (!res || !res.ok) {
|
||||||
log('✗ Failed to dispatch: ' + (res?.error||'unknown'), 'var(--red)');
|
log('✗ Failed to dispatch: ' + (res?.error||'unknown'), 'var(--red)');
|
||||||
document.getElementById('modalSave').style.display = '';
|
document.getElementById('modalSave').style.display = '';
|
||||||
@@ -2242,7 +2943,7 @@ async function agentUpdateFlow(agentId) {
|
|||||||
log('✓ Command dispatched — waiting for agent to pick up...', 'var(--cyan)');
|
log('✓ Command dispatched — waiting for agent to pick up...', 'var(--cyan)');
|
||||||
|
|
||||||
// Poll agent_commands for the result (max 90s)
|
// Poll agent_commands for the result (max 90s)
|
||||||
const cmdRes = await api('worker_action', {worker_type:'agent', worker_id:agentId, action:'update_status'}).catch(()=>null);
|
const cmdRes = await api('worker_action', {worker_type:'agent', worker_id:agentId, waction:'update_status'}).catch(()=>null);
|
||||||
// Actually poll via workers_list for version change
|
// Actually poll via workers_list for version change
|
||||||
const deadline = Date.now() + 90000;
|
const deadline = Date.now() + 90000;
|
||||||
let done = false;
|
let done = false;
|
||||||
@@ -2327,8 +3028,22 @@ async function loadWorkers() {
|
|||||||
}
|
}
|
||||||
// Cron Workers
|
// Cron Workers
|
||||||
const cl=d.cron_last||{};
|
const cl=d.cron_last||{};
|
||||||
|
const LIVE_LOG_WORKERS = {
|
||||||
|
facts_collector: /done|collected/,
|
||||||
|
stats_cache: /done/,
|
||||||
|
calendar_sync: /done/,
|
||||||
|
};
|
||||||
document.getElementById('workers-crons').innerHTML=CRON_DEFS.map(c=>{
|
document.getElementById('workers-crons').innerHTML=CRON_DEFS.map(c=>{
|
||||||
const runBtn=!c.norun?`<button onclick="workerAction('cron','${c.id}','run')" style="${wBtn('cyan')}">▶ RUN</button>`:'<span class="ts">—</span>';
|
let runBtn;
|
||||||
|
if (c.norun) {
|
||||||
|
runBtn = '<span class="ts">—</span>';
|
||||||
|
} else if (c.id === 'kb_intent_generator') {
|
||||||
|
runBtn = `<button onclick="runIntentGenerator()" style="${wBtn('cyan')}">▶ RUN</button>`;
|
||||||
|
} else if (LIVE_LOG_WORKERS[c.id]) {
|
||||||
|
runBtn = `<button onclick="runWorkerWithLog('${c.id}','${c.label}',${LIVE_LOG_WORKERS[c.id]})" style="${wBtn('cyan')}">▶ RUN</button>`;
|
||||||
|
} else {
|
||||||
|
runBtn = `<button onclick="workerAction('cron','${c.id}','run')" style="${wBtn('cyan')}">▶ RUN</button>`;
|
||||||
|
}
|
||||||
return `<tr>
|
return `<tr>
|
||||||
<td><strong>${c.label}</strong></td>
|
<td><strong>${c.label}</strong></td>
|
||||||
<td class="ts">${c.schedule}</td>
|
<td class="ts">${c.schedule}</td>
|
||||||
@@ -2346,9 +3061,9 @@ async function loadWorkers() {
|
|||||||
<td class="ts">jarvis-do :7474</td>
|
<td class="ts">jarvis-do :7474</td>
|
||||||
<td>${rdot}${ron?'<span style="color:var(--green)">ONLINE</span>':'<span style="color:var(--red)">OFFLINE</span>'}</td>
|
<td>${rdot}${ron?'<span style="color:var(--green)">ONLINE</span>':'<span style="color:var(--red)">OFFLINE</span>'}</td>
|
||||||
<td class="ts">${rinfo}</td>
|
<td class="ts">${rinfo}</td>
|
||||||
<td style="display:flex;gap:4px">
|
<td style="white-space:nowrap">
|
||||||
<button onclick="workerAction('daemon','arc_reactor','restart')" style="${wBtn('red')}">↻ RESTART</button>
|
<button onclick="workerAction('daemon','arc_reactor','restart')" style="${wBtn('red')}">↻ RESTART</button>
|
||||||
<button onclick="workerAction('daemon','arc_reactor','setup')" style="${wBtn('orange')}">⚙ SETUP</button>
|
<button onclick="arcSetup()" style="${wBtn('cyan')};margin-left:6px">⚙ SETUP</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
}
|
}
|
||||||
@@ -2552,7 +3267,7 @@ function renderNetwork() {
|
|||||||
<td class="ts">${ago(d.last_seen)}</td>
|
<td class="ts">${ago(d.last_seen)}</td>
|
||||||
<td><div class="actions-col">
|
<td><div class="actions-col">
|
||||||
<button class="btn btn-xs" onclick="pingDev('${esc(d.ip)}',this)">PING</button>
|
<button class="btn btn-xs" onclick="pingDev('${esc(d.ip)}',this)">PING</button>
|
||||||
<button class="btn btn-xs btn-yellow" onclick="netModal(${d.id},'${esc(d.ip)}','${esc(d.alias||'')}','${esc(d.device_type||'')}')">NAME</button>
|
<button class="btn btn-xs btn-yellow" onclick="netModal(${d.id},'${escJs(d.ip)}','${escJs(d.alias||'')}','${escJs(d.device_type||'')}')">NAME</button>
|
||||||
<button class="btn btn-xs btn-red" onclick="delNet(${d.id},'${esc(name)}')">DEL</button>
|
<button class="btn btn-xs btn-red" onclick="delNet(${d.id},'${esc(name)}')">DEL</button>
|
||||||
</div></td>`;
|
</div></td>`;
|
||||||
}, null, null);
|
}, null, null);
|
||||||
@@ -2631,7 +3346,7 @@ async function loadAlerts() {
|
|||||||
<td class="ts">${ts(a.created_at)}</td>
|
<td class="ts">${ts(a.created_at)}</td>
|
||||||
<td><div class="actions-col">
|
<td><div class="actions-col">
|
||||||
${!a.resolved?`<button class="btn btn-xs btn-green" onclick="apiPost('alerts_resolve',{id:${a.id}},()=>{toast('Resolved','ok');loadAlerts()})">RESOLVE</button>`:''}
|
${!a.resolved?`<button class="btn btn-xs btn-green" onclick="apiPost('alerts_resolve',{id:${a.id}},()=>{toast('Resolved','ok');loadAlerts()})">RESOLVE</button>`:''}
|
||||||
<button class="btn btn-xs btn-yellow" onclick="alertModal(${a.id},'${esc(a.alert_type)}','${esc(a.title)}','${esc(a.message||'')}','${esc(a.severity)}')">EDIT</button>
|
<button class="btn btn-xs btn-yellow" onclick="alertModal(${a.id},'${escJs(a.alert_type)}','${escJs(a.title)}','${escJs(a.message||'')}','${escJs(a.severity)}')">EDIT</button>
|
||||||
<button class="btn btn-xs btn-red" onclick="apiPost('alerts_delete',{id:${a.id}},()=>{toast('Deleted','ok');loadAlerts()})">DEL</button>
|
<button class="btn btn-xs btn-red" onclick="apiPost('alerts_delete',{id:${a.id}},()=>{toast('Deleted','ok');loadAlerts()})">DEL</button>
|
||||||
</div></td>`, null, null);
|
</div></td>`, null, null);
|
||||||
}
|
}
|
||||||
@@ -2741,7 +3456,7 @@ function renderIntents(intents) {
|
|||||||
<td>${i.active?'<span class="badge badge-green">ON</span>':'<span class="badge badge-dim">OFF</span>'}</td>
|
<td>${i.active?'<span class="badge badge-green">ON</span>':'<span class="badge badge-dim">OFF</span>'}</td>
|
||||||
<td><div class="actions-col">
|
<td><div class="actions-col">
|
||||||
<button class="btn btn-xs" onclick="apiPost('intents_toggle',{id:${i.id}},()=>{toast('Toggled','ok');loadIntents()})">${i.active?'DISABLE':'ENABLE'}</button>
|
<button class="btn btn-xs" onclick="apiPost('intents_toggle',{id:${i.id}},()=>{toast('Toggled','ok');loadIntents()})">${i.active?'DISABLE':'ENABLE'}</button>
|
||||||
<button class="btn btn-xs btn-yellow" onclick='intentModal(${i.id},"${esc(i.intent_name)}","${esc(i.pattern)}",${JSON.stringify(i.response_template||"")},"${esc(i.action_type)}",${i.priority},${i.active})'>EDIT</button>
|
<button class="btn btn-xs btn-yellow" onclick="intentModal(${i.id},'${escJs(i.intent_name)}','${escJs(i.pattern)}','${escJs(i.response_template||'')}','${escJs(i.action_type)}',${i.priority},${i.active})">EDIT</button>
|
||||||
<button class="btn btn-xs btn-red" onclick="apiPost('intents_delete',{id:${i.id}},()=>{toast('Deleted','ok');loadIntents()})">DEL</button>
|
<button class="btn btn-xs btn-red" onclick="apiPost('intents_delete',{id:${i.id}},()=>{toast('Deleted','ok');loadIntents()})">DEL</button>
|
||||||
</div></td>`, null, null);
|
</div></td>`, null, null);
|
||||||
}
|
}
|
||||||
@@ -2973,7 +3688,7 @@ async function loadNews() {
|
|||||||
<div style="font-size:0.75rem">${esc(c.title)}</div>
|
<div style="font-size:0.75rem">${esc(c.title)}</div>
|
||||||
${c.url?`<div style="font-size:0.6rem;color:var(--dim)">${esc(c.url)}</div>`:''}
|
${c.url?`<div style="font-size:0.6rem;color:var(--dim)">${esc(c.url)}</div>`:''}
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-xs btn-yellow" onclick='newsCustomModal(${c.id},"${esc(c.title)}","${esc(c.url||"")}")'>EDIT</button>
|
<button class="btn btn-xs btn-yellow" onclick="newsCustomModal(${c.id},'${escJs(c.title)}','${escJs(c.url||'')}')">EDIT</button>
|
||||||
<button class="btn btn-xs btn-red" onclick="apiPost('news_custom_delete',{id:${c.id}},()=>{toast('Deleted','ok');loadNews()})">DEL</button>
|
<button class="btn btn-xs btn-red" onclick="apiPost('news_custom_delete',{id:${c.id}},()=>{toast('Deleted','ok');loadNews()})">DEL</button>
|
||||||
</div>`).join('');
|
</div>`).join('');
|
||||||
}
|
}
|
||||||
@@ -4358,7 +5073,7 @@ async function loadCalFeeds() {
|
|||||||
<td>${ts(f.last_sync)}</td>
|
<td>${ts(f.last_sync)}</td>
|
||||||
<td>${f.last_count||0}</td>
|
<td>${f.last_count||0}</td>
|
||||||
<td>${f.active?'<span class="badge badge-green">ACTIVE</span>':'<span class="badge badge-red">PAUSED</span>'}</td>
|
<td>${f.active?'<span class="badge badge-green">ACTIVE</span>':'<span class="badge badge-red">PAUSED</span>'}</td>
|
||||||
<td><button class="btn btn-xs" onclick='calFeedModal(${JSON.stringify(f)})'>EDIT</button>
|
<td><button class="btn btn-xs" onclick="calFeedModal(${esc(JSON.stringify(f))})">EDIT</button>
|
||||||
<button class="btn btn-xs btn-red" onclick="calFeedDel(${f.id})">DEL</button></td>
|
<button class="btn btn-xs btn-red" onclick="calFeedDel(${f.id})">DEL</button></td>
|
||||||
</tr>`).join('')}</tbody></table>`;
|
</tr>`).join('')}</tbody></table>`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ else
|
|||||||
"poll_interval": 30,
|
"poll_interval": 30,
|
||||||
"heartbeat_every": 10,
|
"heartbeat_every": 10,
|
||||||
"update_check_hours": 24,
|
"update_check_hours": 24,
|
||||||
"watch_services": ["ollama", "homeassistant", "mysql", "mariadb", "nginx", "apache2", "docker"]
|
"watch_services": []
|
||||||
}
|
}
|
||||||
JSONEOF
|
JSONEOF
|
||||||
chmod 600 "$CONFIG_DIR/config.json"
|
chmod 600 "$CONFIG_DIR/config.json"
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ def get_uptime() -> dict:
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_services(cfg: dict) -> list:
|
def get_services(cfg: dict) -> list:
|
||||||
watch = cfg.get("watch_services", ["ollama", "homeassistant", "mysql", "nginx", "apache2"])
|
watch = cfg.get("watch_services", [])
|
||||||
statuses = []
|
statuses = []
|
||||||
for svc in watch:
|
for svc in watch:
|
||||||
try:
|
try:
|
||||||
|
|||||||
+6
-1
@@ -27,7 +27,12 @@ if (!$_skipSession) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
header('Access-Control-Allow-Origin: *');
|
$_allowedOrigins = ['https://jarvis.orbishosting.com', 'http://jarvis.orbishosting.com'];
|
||||||
|
$_origin = $_SERVER['HTTP_ORIGIN'] ?? '';
|
||||||
|
if (in_array($_origin, $_allowedOrigins, true)) {
|
||||||
|
header('Access-Control-Allow-Origin: ' . $_origin);
|
||||||
|
header('Access-Control-Allow-Credentials: true');
|
||||||
|
}
|
||||||
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
||||||
header('Access-Control-Allow-Headers: Content-Type, X-Session-Token');
|
header('Access-Control-Allow-Headers: Content-Type, X-Session-Token');
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
// ── GLOBALS ──────────────────────────────────────────────────────────
|
// ── GLOBALS ──────────────────────────────────────────────────────────
|
||||||
|
function escHtml(s) {
|
||||||
|
return String(s == null ? '' : s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
|
||||||
|
}
|
||||||
|
// For values embedded inside a single-quoted JS string literal within an HTML attribute
|
||||||
|
// (e.g. onclick="fn('${escJs(x)}')"). escHtml() alone isn't enough there: the browser
|
||||||
|
// HTML-decodes the attribute before parsing it as JS, so an encoded quote would just
|
||||||
|
// turn back into a literal ' before the JS parser ever sees it.
|
||||||
|
function escJs(s) {
|
||||||
|
return escHtml(String(s == null ? '' : s).replace(/\\/g,'\\\\').replace(/'/g,"\\'").replace(/\n/g,'\\n').replace(/\r/g,'\\r'));
|
||||||
|
}
|
||||||
let sessionToken = '';
|
let sessionToken = '';
|
||||||
let sessionUser = '';
|
let sessionUser = '';
|
||||||
let sessionId = 'session_' + Date.now();
|
let sessionId = 'session_' + Date.now();
|
||||||
@@ -596,15 +606,15 @@ function renderNetworkStatus(n) {
|
|||||||
agent_id: d.agent_id, hostname: d.name};
|
agent_id: d.agent_id, hostname: d.name};
|
||||||
const lat = d.latency_ms ? ' · ' + d.latency_ms + 'ms' : '';
|
const lat = d.latency_ms ? ' · ' + d.latency_ms + 'ms' : '';
|
||||||
const badge = d.source === 'agent'
|
const badge = d.source === 'agent'
|
||||||
? `<span style="font-size:0.53rem;color:var(--cyan);letter-spacing:1px;margin-left:4px">${(d.agent_type||'AGENT').toUpperCase()}</span>` : '';
|
? `<span style="font-size:0.53rem;color:var(--cyan);letter-spacing:1px;margin-left:4px">${escHtml((d.agent_type||'AGENT').toUpperCase())}</span>` : '';
|
||||||
const del = d.deletable
|
const del = d.deletable
|
||||||
? `<button onclick="deleteNetworkDevice('${d.ip}',event)" style="background:none;border:none;color:var(--red);cursor:pointer;font-size:0.9rem;padding:0 2px;opacity:0.5;flex-shrink:0" title="Remove">×</button>` : '';
|
? `<button onclick="deleteNetworkDevice('${escJs(d.ip)}',event)" style="background:none;border:none;color:var(--red);cursor:pointer;font-size:0.9rem;padding:0 2px;opacity:0.5;flex-shrink:0" title="Remove">×</button>` : '';
|
||||||
const bl = d.source === 'agent' ? 'border-left:2px solid ' + (alive ? 'var(--green)' : 'var(--red)') + ';' : '';
|
const bl = d.source === 'agent' ? 'border-left:2px solid ' + (alive ? 'var(--green)' : 'var(--red)') + ';' : '';
|
||||||
return `<div class="device-item" data-ctx-key="${ctxKey}" onclick="selectContext('${ctxKey}')" style="${bl}display:flex;align-items:center">
|
return `<div class="device-item" data-ctx-key="${ctxKey}" onclick="selectContext('${escJs(ctxKey)}')" style="${bl}display:flex;align-items:center">
|
||||||
<div class="device-status ${alive?'on':'off'}" style="flex-shrink:0"></div>
|
<div class="device-status ${alive?'on':'off'}" style="flex-shrink:0"></div>
|
||||||
<div class="device-info" style="flex:1;min-width:0">
|
<div class="device-info" style="flex:1;min-width:0">
|
||||||
<div class="device-name" style="display:flex;align-items:center">${d.name||d.ip}${badge}</div>
|
<div class="device-name" style="display:flex;align-items:center">${escHtml(d.name||d.ip)}${badge}</div>
|
||||||
<div class="device-ip">${d.ip||''}${lat}</div>
|
<div class="device-ip">${escHtml(d.ip||'')}${lat}</div>
|
||||||
</div>${del}
|
</div>${del}
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
@@ -684,7 +694,7 @@ async function loadProxmox() {
|
|||||||
type_label:vm.type||'qemu', uptime:vm.uptime||0};
|
type_label:vm.type||'qemu', uptime:vm.uptime||0};
|
||||||
return `<div class="vm-card" data-ctx-key="${ctxKey}" onclick="selectContext('${ctxKey}')" title="Click to ask Jarvis about this VM">
|
return `<div class="vm-card" data-ctx-key="${ctxKey}" onclick="selectContext('${ctxKey}')" title="Click to ask Jarvis about this VM">
|
||||||
<div class="vm-header">
|
<div class="vm-header">
|
||||||
<span class="vm-name">${vm.name}</span>
|
<span class="vm-name">${escHtml(vm.name)}</span>
|
||||||
<span style="color:${statusColor};font-size:0.65rem">● ${(vm.status||'').toUpperCase()}</span>
|
<span style="color:${statusColor};font-size:0.65rem">● ${(vm.status||'').toUpperCase()}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="vm-metrics">
|
<div class="vm-metrics">
|
||||||
@@ -1031,10 +1041,11 @@ async function loadNews() {
|
|||||||
const ctxKey = 'news_' + (cat + '_' + a.title).replace(/[^a-z0-9]/gi,'').slice(0,30);
|
const ctxKey = 'news_' + (cat + '_' + a.title).replace(/[^a-z0-9]/gi,'').slice(0,30);
|
||||||
_panelCtx[ctxKey] = {type:'news', label:a.title,
|
_panelCtx[ctxKey] = {type:'news', label:a.title,
|
||||||
title:a.title, source:a.source, pub:a.pub||'', category:cat};
|
title:a.title, source:a.source, pub:a.pub||'', category:cat};
|
||||||
|
const titleDisplay = a.title.length > 90 ? a.title.slice(0,87)+'…' : a.title;
|
||||||
html += `<div class="news-item" data-ctx-key="${ctxKey}" onclick="selectContext('${ctxKey}')" title="Click to ask Jarvis about this story">
|
html += `<div class="news-item" data-ctx-key="${ctxKey}" onclick="selectContext('${ctxKey}')" title="Click to ask Jarvis about this story">
|
||||||
<div class="news-source">${a.source}</div>
|
<div class="news-source">${escHtml(a.source)}</div>
|
||||||
<div class="news-title">${a.title.length > 90 ? a.title.slice(0,87)+'…' : a.title}</div>
|
<div class="news-title">${escHtml(titleDisplay)}</div>
|
||||||
${a.pub ? '<div class="news-time">' + a.pub + '</div>' : ''}
|
${a.pub ? '<div class="news-time">' + escHtml(a.pub) + '</div>' : ''}
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -401,8 +401,8 @@ function renderAgentsTab(agents, metrics) {
|
|||||||
style="flex-direction:column;align-items:stretch;border-left:3px solid ${alive ? 'var(--green)' : 'var(--red)'}">
|
style="flex-direction:column;align-items:stretch;border-left:3px solid ${alive ? 'var(--green)' : 'var(--red)'}">
|
||||||
<div style="display:flex;align-items:center;gap:8px;margin-bottom:6px">
|
<div style="display:flex;align-items:center;gap:8px;margin-bottom:6px">
|
||||||
<div style="width:8px;height:8px;border-radius:50%;background:${alive ? 'var(--green)' : 'var(--red)'};box-shadow:${alive ? '0 0 6px var(--green)' : 'none'};flex-shrink:0"></div>
|
<div style="width:8px;height:8px;border-radius:50%;background:${alive ? 'var(--green)' : 'var(--red)'};box-shadow:${alive ? '0 0 6px var(--green)' : 'none'};flex-shrink:0"></div>
|
||||||
<span style="font-family:var(--font-mono);font-size:0.72rem;color:var(--text);flex:1">${ag.hostname}</span>
|
<span style="font-family:var(--font-mono);font-size:0.72rem;color:var(--text);flex:1">${escHtml(ag.hostname)}</span>
|
||||||
<span style="font-size:0.58rem;color:var(--text-dim)">${ag.agent_type.toUpperCase()} · ${ag.ip_address}</span>
|
<span style="font-size:0.58rem;color:var(--text-dim)">${escHtml(ag.agent_type.toUpperCase())} · ${escHtml(ag.ip_address)}</span>
|
||||||
<span style="font-size:0.58rem;color:${alive ? 'var(--green)' : 'var(--red)'};">${alive ? 'ONLINE' : 'OFFLINE'}</span>
|
<span style="font-size:0.58rem;color:${alive ? 'var(--green)' : 'var(--red)'};">${alive ? 'ONLINE' : 'OFFLINE'}</span>
|
||||||
</div>
|
</div>
|
||||||
${alive ? `<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px;margin-bottom:4px">
|
${alive ? `<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px;margin-bottom:4px">
|
||||||
@@ -425,8 +425,8 @@ function renderAgentsTab(agents, metrics) {
|
|||||||
${svcs ? `<div style="font-size:0.58rem">${svcs}</div>` : ''}
|
${svcs ? `<div style="font-size:0.58rem">${svcs}</div>` : ''}
|
||||||
</div>
|
</div>
|
||||||
${alive ? `<div style="display:flex;gap:5px;margin-top:6px">
|
${alive ? `<div style="display:flex;gap:5px;margin-top:6px">
|
||||||
<button onclick="event.stopPropagation();agentScreenshot('${ag.hostname}')" style="flex:1;background:rgba(0,212,255,0.06);border:1px solid var(--panel-border);border-radius:3px;padding:3px 6px;color:var(--cyan);font-family:var(--font-display);font-size:0.48rem;letter-spacing:1px;cursor:pointer">◈ SCREENSHOT</button>
|
<button onclick="event.stopPropagation();agentScreenshot('${escJs(ag.hostname)}')" style="flex:1;background:rgba(0,212,255,0.06);border:1px solid var(--panel-border);border-radius:3px;padding:3px 6px;color:var(--cyan);font-family:var(--font-display);font-size:0.48rem;letter-spacing:1px;cursor:pointer">◈ SCREENSHOT</button>
|
||||||
<button onclick="event.stopPropagation();agentSysinfo('${ag.hostname}')" style="flex:1;background:rgba(0,212,255,0.06);border:1px solid var(--panel-border);border-radius:3px;padding:3px 6px;color:var(--text-dim);font-family:var(--font-display);font-size:0.48rem;letter-spacing:1px;cursor:pointer">⚡ SYSINFO</button>
|
<button onclick="event.stopPropagation();agentSysinfo('${escJs(ag.hostname)}')" style="flex:1;background:rgba(0,212,255,0.06);border:1px solid var(--panel-border);border-radius:3px;padding:3px 6px;color:var(--text-dim);font-family:var(--font-display);font-size:0.48rem;letter-spacing:1px;cursor:pointer">⚡ SYSINFO</button>
|
||||||
</div>` : ''}
|
</div>` : ''}
|
||||||
</div>`;
|
</div>`;
|
||||||
}).join('');
|
}).join('');
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ else
|
|||||||
"poll_interval": 30,
|
"poll_interval": 30,
|
||||||
"heartbeat_every": 10,
|
"heartbeat_every": 10,
|
||||||
"update_check_hours": 24,
|
"update_check_hours": 24,
|
||||||
"watch_services": ["ollama", "homeassistant", "mysql", "mariadb", "nginx", "apache2", "docker"]
|
"watch_services": []
|
||||||
}
|
}
|
||||||
JSONEOF
|
JSONEOF
|
||||||
chmod 600 "$CONFIG_DIR/config.json"
|
chmod 600 "$CONFIG_DIR/config.json"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ if (!defined('WEBHOOK_SECRET')) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
define('DEPLOY_QUEUE', '/tmp/jarvis-deploy-queue.txt');
|
define('DEPLOY_QUEUE', '/tmp/jarvis-deploy-queue.txt');
|
||||||
define('DEPLOY_LOG', '/var/www/jarvis/logs/deploy.log');
|
define('DEPLOY_LOG', '/var/log/jarvis/deploy.log');
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
@@ -33,9 +33,10 @@ $repo = $data['repository']['name'] ?? '';
|
|||||||
$ref = $data['ref'] ?? '';
|
$ref = $data['ref'] ?? '';
|
||||||
$pusher = $data['pusher']['name'] ?? 'unknown';
|
$pusher = $data['pusher']['name'] ?? 'unknown';
|
||||||
|
|
||||||
// Only deploy on pushes to main
|
// Only deploy on pushes to the repo's actual default branch (master, not main —
|
||||||
if ($ref !== 'refs/heads/main') {
|
// this was checking 'main' for a while even though the jarvis repo has always used 'master')
|
||||||
echo json_encode(['ok' => true, 'skipped' => "ref $ref is not main"]);
|
if ($ref !== 'refs/heads/master') {
|
||||||
|
echo json_encode(['ok' => true, 'skipped' => "ref $ref is not master"]);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user