mirror of
https://github.com/myronblair/jarvis
synced 2026-06-30 17:50:23 -05:00
Phase 3: Comms Protocol + Field Protocol
- chat.php: Add Tier 0.9a (gmail_triage), Tier 0.9b (remote_exec) detection; refactor arc submit into arcSubmitJob() helper; natural-language triggers for email triage (check my email, triage inbox) and remote exec (restart X on Y, run X on Y, get logs from X on Y) - arc.php: Add triage and triage_action endpoints (read/update email_triage table) - index.html: Add COMMS tab with triage card UI (filter bar, category badges, draft reply viewer, copy/dismiss actions); loadComms() with 8s polling; onArcJobStarted() routes gmail_triage jobs to COMMS tab - admin/index.php: Add GMAIL TRIAGE section under COMMUNICATIONS nav; triage_list/ triage_action/triage_run PHP actions; loadTriage() JS with full table + draft modal; triageRunNow() submits gmail_triage job to Arc Reactor
This commit is contained in:
+95
-19
@@ -1063,10 +1063,102 @@ if (!$reply && preg_match('/\b(news|headlines|latest|what.?s happening|current e
|
||||
}
|
||||
}
|
||||
|
||||
// ── Tier 0.9: Intel Protocol — research & tool_loop detection ────────────
|
||||
// ── Tier 0.9: Intel Protocol — research, tool_loop, gmail_triage, remote_exec ─
|
||||
$arcJobId = null;
|
||||
|
||||
// Detect "research X", "look up X", "deep dive X", "investigate X", "find out about X"
|
||||
// Helper: submit job to Arc Reactor
|
||||
function arcSubmitJob(string $type, array $payload, string $sessionId): ?array {
|
||||
$ch = curl_init('http://127.0.0.1:7474/job');
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode([
|
||||
'type' => $type,
|
||||
'payload' => $payload,
|
||||
'priority' => 7,
|
||||
'created_by' => 'chat:' . $sessionId,
|
||||
]),
|
||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||
CURLOPT_TIMEOUT => 5,
|
||||
CURLOPT_CONNECTTIMEOUT => 3,
|
||||
]);
|
||||
$res = json_decode(curl_exec($ch), true);
|
||||
curl_close($ch);
|
||||
return $res;
|
||||
}
|
||||
|
||||
// ── Tier 0.9a: Comms Protocol — gmail_triage detection ────────────────────
|
||||
if (!$reply) {
|
||||
$triagePatterns = [
|
||||
'/^(?:jarvis[,\s]+)?(?:check|triage|sort)\s+(?:my\s+)?(?:email|inbox|gmail|mail)/i',
|
||||
'/^(?:jarvis[,\s]+)?what(?:\'s|\s+is)\s+(?:urgent|important)\s+(?:in\s+my\s+)?(?:email|inbox|mail)/i',
|
||||
'/^(?:jarvis[,\s]+)?(?:any\s+)?(?:urgent|important)\s+(?:email|emails|messages)/i',
|
||||
'/^(?:jarvis[,\s]+)?email\s+(?:briefing|brief|report|summary)/i',
|
||||
];
|
||||
foreach ($triagePatterns as $pat) {
|
||||
if (preg_match($pat, $message)) {
|
||||
$account = preg_match('/icloud/i', $message) ? 'icloud' : 'gmail';
|
||||
$maxEmails = 20;
|
||||
if (preg_match('/\b(\d+)\s+emails?\b/i', $message, $em)) $maxEmails = min((int)$em[1], 40);
|
||||
$arcRes = arcSubmitJob('gmail_triage', [
|
||||
'account' => $account,
|
||||
'max_emails' => $maxEmails,
|
||||
'provider' => 'claude',
|
||||
], $sessionId);
|
||||
if (isset($arcRes['job_id'])) {
|
||||
$arcJobId = $arcRes['job_id'];
|
||||
$acctLabel = strtoupper($account);
|
||||
$reply = "◈ COMMS PROTOCOL ACTIVATED — Triaging your {$acctLabel} inbox (Job #{$arcJobId}). I'm fetching emails and running priority analysis now, {$userAddr}. Switch to the COMMS tab to see results.";
|
||||
$source = 'arc:gmail_triage';
|
||||
} else {
|
||||
$reply = "Comms Protocol is offline, {$userAddr}. Arc Reactor may be unavailable.";
|
||||
$source = 'arc:offline';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Tier 0.9b: Field Protocol — remote_exec detection ────────────────────
|
||||
if (!$reply) {
|
||||
$remotePatterns = [
|
||||
'/^(?:jarvis[,\s]+)?restart\s+(.+?)\s+on\s+(.+)/i' => ['restart_service', 1, 2],
|
||||
'/^(?:jarvis[,\s]+)?(?:run|execute|exec)\s+(.+?)\s+on\s+(.+)/i' => ['shell', 1, 2],
|
||||
'/^(?:jarvis[,\s]+)?get\s+logs?\s+(?:from\s+|for\s+)?(.+?)\s+on\s+(.+)/i' => ['get_logs', 1, 2],
|
||||
'/^(?:jarvis[,\s]+)?(?:ping|check)\s+agent\s+(.+)/i' => ['ping', 1, null],
|
||||
'/^(?:jarvis[,\s]+)?what(?:\'s|\s+is)\s+(?:running|the\s+status)\s+on\s+(.+)/i' => ['ping', 1, null],
|
||||
];
|
||||
foreach ($remotePatterns as $pat => $cfg) {
|
||||
if (preg_match($pat, $message, $m)) {
|
||||
[$cmdType, $cmdIdx, $agentIdx] = $cfg;
|
||||
$cmdArg = $agentIdx ? trim($m[$cmdIdx]) : '';
|
||||
$agentArg = $agentIdx ? trim($m[$agentIdx]) : trim($m[$cmdIdx]);
|
||||
$cmdData = match($cmdType) {
|
||||
'restart_service' => ['service' => $cmdArg],
|
||||
'shell' => ['command' => $cmdArg],
|
||||
'get_logs' => ['service' => $cmdArg, 'lines' => 50],
|
||||
default => [],
|
||||
};
|
||||
$arcRes = arcSubmitJob('remote_exec', [
|
||||
'agent' => $agentArg,
|
||||
'command_type' => $cmdType,
|
||||
'command_data' => $cmdData,
|
||||
'timeout' => 35,
|
||||
], $sessionId);
|
||||
if (isset($arcRes['job_id'])) {
|
||||
$arcJobId = $arcRes['job_id'];
|
||||
$reply = "◈ FIELD PROTOCOL ACTIVATED — Dispatching **{$cmdType}** to agent **{$agentArg}** (Job #{$arcJobId}). I'll relay the result when the field station responds, {$userAddr}.";
|
||||
$source = 'arc:remote_exec';
|
||||
} else {
|
||||
$reply = "Field Protocol is offline, {$userAddr}. Arc Reactor may be unavailable.";
|
||||
$source = 'arc:offline';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Tier 0.9c: Intel Protocol — research & tool_loop detection ────────────
|
||||
$intelPatterns = [
|
||||
'/^(?:jarvis[,\s]+)?(?:research|investigate|deep[- ]dive|deep dive)\s+(.+)/i' => 'research',
|
||||
'/^(?:jarvis[,\s]+)?(?:look\s+(?:up|into)|find\s+out\s+(?:about)?)\s+(.+)/i' => 'research',
|
||||
@@ -1088,23 +1180,7 @@ if (!$reply) {
|
||||
? ['query' => $queryOrTask, 'depth' => $depth, 'provider' => 'claude']
|
||||
: ['task' => $queryOrTask, 'max_iterations' => 12, 'provider' => 'claude'];
|
||||
|
||||
// Submit to Arc Reactor
|
||||
$arcCh = curl_init('http://127.0.0.1:7474/job');
|
||||
curl_setopt_array($arcCh, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => json_encode([
|
||||
'type' => $jobType,
|
||||
'payload' => $jobPayload,
|
||||
'priority' => 7,
|
||||
'created_by' => 'chat:' . $sessionId,
|
||||
]),
|
||||
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
||||
CURLOPT_TIMEOUT => 5,
|
||||
CURLOPT_CONNECTTIMEOUT => 3,
|
||||
]);
|
||||
$arcRes = json_decode(curl_exec($arcCh), true);
|
||||
curl_close($arcCh);
|
||||
$arcRes = arcSubmitJob($jobType, $jobPayload, $sessionId);
|
||||
|
||||
if (isset($arcRes['job_id'])) {
|
||||
$arcJobId = $arcRes['job_id'];
|
||||
|
||||
Reference in New Issue
Block a user