1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
|
import { useState, useEffect, useCallback, useRef } from "react";
import { useAuth } from "../contexts/AuthContext";
import { useNavigate } from "react-router";
import { Masthead } from "../components/Masthead";
import {
listDaemons,
restartDaemon,
triggerDaemonReauth,
getDaemonReauthStatus,
type Daemon,
type DaemonListResponse,
} from "../lib/api";
// =============================================================================
// Section Header Component
// =============================================================================
function SectionHeader({ children }: { children: React.ReactNode }) {
return (
<h2 className="text-[11px] font-mono uppercase tracking-wide text-[#8899aa] mb-3 pb-2 border-b border-[rgba(117,170,252,0.15)]">
{children}
</h2>
);
}
// =============================================================================
// Alert Component
// =============================================================================
function ErrorAlert({ children }: { children: React.ReactNode }) {
return (
<div className="border border-red-700/50 bg-red-900/20 text-red-400 px-3 py-2 mb-4 font-mono text-xs">
{children}
</div>
);
}
// =============================================================================
// Reauth Modal Component
// =============================================================================
type ReauthState =
| { phase: "initiating" }
| { phase: "url_ready"; loginUrl: string; requestId: string }
| { phase: "waiting_for_auth"; loginUrl: string; requestId: string }
| { phase: "success" }
| { phase: "error"; message: string };
function ReauthModal({
daemon,
onClose,
}: {
daemon: Daemon;
onClose: () => void;
}) {
const [state, setState] = useState<ReauthState>({ phase: "initiating" });
const pollingRef = useRef<ReturnType<typeof setInterval> | null>(null);
// Cleanup polling on unmount
useEffect(() => {
return () => {
if (pollingRef.current) {
clearInterval(pollingRef.current);
}
};
}, []);
// Start polling for status updates (URL ready, then completion)
const startPolling = useCallback(
(requestId: string) => {
if (pollingRef.current) {
clearInterval(pollingRef.current);
}
pollingRef.current = setInterval(async () => {
try {
const status = await getDaemonReauthStatus(daemon.id, requestId);
if (status.status === "completed") {
setState({ phase: "success" });
if (pollingRef.current) {
clearInterval(pollingRef.current);
pollingRef.current = null;
}
} else if (status.status === "url_ready" && status.loginUrl) {
setState((prev) => {
// Only update if we haven't already shown the URL
if (prev.phase === "initiating") {
return {
phase: "url_ready",
loginUrl: status.loginUrl!,
requestId,
};
}
return prev;
});
// Keep polling for completion - don't stop here
} else if (status.status === "failed") {
setState({
phase: "error",
message: status.error || "Reauth failed",
});
if (pollingRef.current) {
clearInterval(pollingRef.current);
pollingRef.current = null;
}
}
} catch {
// Polling errors are non-fatal, keep trying
}
}, 2000);
},
[daemon.id],
);
// Trigger reauth on mount
useEffect(() => {
let cancelled = false;
const trigger = async () => {
try {
const res = await triggerDaemonReauth(daemon.id);
if (cancelled) return;
startPolling(res.requestId);
} catch (err) {
if (cancelled) return;
setState({
phase: "error",
message:
err instanceof Error ? err.message : "Failed to trigger reauth",
});
}
};
trigger();
return () => {
cancelled = true;
};
}, [daemon.id, startPolling]);
// When URL is shown, transition to waiting_for_auth after user clicks the link
const handleOpenedLink = useCallback(() => {
setState((prev) => {
if (prev.phase === "url_ready") {
return {
phase: "waiting_for_auth",
loginUrl: prev.loginUrl,
requestId: prev.requestId,
};
}
return prev;
});
}, []);
const handleRetry = useCallback(() => {
setState({ phase: "initiating" });
const trigger = async () => {
try {
const res = await triggerDaemonReauth(daemon.id);
startPolling(res.requestId);
} catch (err) {
setState({
phase: "error",
message:
err instanceof Error
? err.message
: "Failed to trigger reauth",
});
}
};
trigger();
}, [daemon.id, startPolling]);
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60">
<div className="bg-[#0d1b2d] border border-[rgba(117,170,252,0.35)] p-6 max-w-md w-full mx-4 shadow-2xl">
{/* Header */}
<div className="flex items-center justify-between mb-4">
<h3 className="text-xs font-mono uppercase tracking-wide text-[#9bc3ff]">
Reauthorize Daemon
</h3>
<button
onClick={onClose}
className="text-[#7788aa] hover:text-[#9bc3ff] text-sm font-mono"
>
✕
</button>
</div>
<p className="text-[10px] font-mono text-[#7788aa] mb-4">
{daemon.hostname || "Unknown Host"}
</p>
{/* Initiating */}
{state.phase === "initiating" && (
<div className="flex items-center gap-2 py-4">
<div className="w-3 h-3 border border-[#75aafc] border-t-transparent rounded-full animate-spin" />
<span className="text-[10px] font-mono text-[#7788aa]">
Initiating reauthorization...
</span>
</div>
)}
{/* URL Ready - user needs to click the link */}
{state.phase === "url_ready" && (
<div className="space-y-3">
<p className="text-[10px] font-mono text-[#7788aa]">
Click the button below to open the OAuth login page. Authentication will complete automatically.
</p>
<a
href={state.loginUrl}
target="_blank"
rel="noopener noreferrer"
onClick={handleOpenedLink}
className="block text-center bg-amber-500 hover:bg-amber-400 text-black font-mono text-xs font-medium px-4 py-2 transition-colors"
>
Login to Claude
</a>
<div className="flex items-center gap-2 pt-1">
<div className="w-2 h-2 bg-amber-500/50 rounded-full animate-pulse" />
<span className="text-[10px] font-mono text-[#7788aa]">
Waiting for authentication to complete...
</span>
</div>
</div>
)}
{/* Waiting for auth - user has clicked the link, waiting for token */}
{state.phase === "waiting_for_auth" && (
<div className="space-y-3">
<div className="flex items-center gap-2 py-2">
<div className="w-3 h-3 border border-amber-400 border-t-transparent rounded-full animate-spin" />
<span className="text-[10px] font-mono text-[#7788aa]">
Waiting for authentication to complete...
</span>
</div>
<p className="text-[10px] font-mono text-[#556677]">
Complete the login in your browser. The token will be saved automatically.
</p>
<a
href={state.loginUrl}
target="_blank"
rel="noopener noreferrer"
className="inline-block text-[10px] font-mono text-amber-500/70 hover:text-amber-400 underline"
>
Open login page again
</a>
</div>
)}
{/* Success */}
{state.phase === "success" && (
<div className="py-4">
<div className="flex items-center gap-2 text-green-400 mb-2">
<span className="text-sm">✓</span>
<span className="text-xs font-mono font-medium">
Authentication successful
</span>
</div>
<p className="text-[10px] font-mono text-[#7788aa] mb-3">
The daemon's OAuth token has been refreshed. Tasks can now run normally.
</p>
<button
onClick={onClose}
className="text-[10px] font-mono text-[#75aafc] hover:text-[#9bc3ff]"
>
Close
</button>
</div>
)}
{/* Error */}
{state.phase === "error" && (
<div className="py-4">
<div className="border border-red-700/50 bg-red-900/20 text-red-400 px-3 py-2 mb-3 font-mono text-xs">
{state.message}
</div>
<div className="flex gap-2">
<button
onClick={handleRetry}
className="text-[10px] font-mono text-amber-400 hover:text-amber-300 px-2 py-1 border border-amber-700/50 bg-amber-900/20"
>
Retry
</button>
<button
onClick={onClose}
className="text-[10px] font-mono text-[#7788aa] hover:text-[#9bc3ff] px-2 py-1"
>
Close
</button>
</div>
</div>
)}
</div>
</div>
);
}
// =============================================================================
// Daemons Page
// =============================================================================
export default function DaemonsPage() {
const { isAuthenticated, isAuthConfigured } = useAuth();
const navigate = useNavigate();
// Daemon state
const [daemons, setDaemons] = useState<Daemon[]>([]);
const [daemonsLoading, setDaemonsLoading] = useState(true);
const [daemonsError, setDaemonsError] = useState<string | null>(null);
const [restartingDaemonId, setRestartingDaemonId] = useState<string | null>(null);
const [restartConfirmDaemonId, setRestartConfirmDaemonId] = useState<string | null>(null);
const [reauthDaemon, setReauthDaemon] = useState<Daemon | null>(null);
// Redirect if not authenticated
useEffect(() => {
if (isAuthConfigured && !isAuthenticated) {
navigate("/login");
}
}, [isAuthConfigured, isAuthenticated, navigate]);
const loadDaemons = async () => {
try {
setDaemonsError(null);
const response: DaemonListResponse = await listDaemons();
setDaemons(response.daemons);
} catch (err) {
setDaemonsError(err instanceof Error ? err.message : "Failed to load daemons");
} finally {
setDaemonsLoading(false);
}
};
const handleRestartDaemon = async (id: string) => {
try {
setRestartingDaemonId(id);
setDaemonsError(null);
await restartDaemon(id);
// Daemon will restart, so refresh the list after a short delay
setTimeout(() => {
loadDaemons();
}, 2000);
} catch (err) {
setDaemonsError(err instanceof Error ? err.message : "Failed to restart daemon");
} finally {
setRestartingDaemonId(null);
setRestartConfirmDaemonId(null);
}
};
// Static platform data for download links
const downloadPlatforms = [
{ key: "linux-x86_64", label: "Linux (Intel/AMD)", filename: "makima-vX.X.X-linux-x86_64.tar.gz" },
{ key: "linux-arm64", label: "Linux (ARM64)", filename: "makima-vX.X.X-linux-arm64.tar.gz" },
{ key: "macos-x86_64", label: "macOS (Intel)", filename: "makima-vX.X.X-macos-x86_64.tar.gz" },
{ key: "macos-arm64", label: "macOS (Apple Silicon)", filename: "makima-vX.X.X-macos-arm64.tar.gz" },
];
// Initial load
useEffect(() => {
loadDaemons();
}, []);
// Auto-refresh daemons every 30 seconds
useEffect(() => {
const interval = setInterval(() => {
loadDaemons();
}, 30000);
return () => clearInterval(interval);
}, []);
return (
<div className="relative z-10 min-h-screen flex flex-col bg-[#0a1628]">
<Masthead showNav />
<main className="flex-1 max-w-4xl mx-auto p-6 w-full">
{/* Page Header */}
<div className="mb-8">
<h1 className="text-sm font-mono uppercase tracking-wide text-[#9bc3ff]">Daemons</h1>
<p className="text-[#7788aa] font-mono text-[10px] mt-2">
Daemons are worker processes that connect to Makima and execute tasks on your machines.
</p>
<div className="h-px bg-[rgba(117,170,252,0.35)] mt-2" />
</div>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
{/* Left Column */}
<div className="space-y-6">
{/* Download Section */}
<section className="border border-[rgba(117,170,252,0.25)] bg-[#0d1b2d] p-4">
<SectionHeader>Download Daemon</SectionHeader>
<p className="text-[#7788aa] font-mono text-[10px] mb-4">
Download the pre-compiled daemon binary for your platform. The daemon connects to the Makima server and executes tasks.
</p>
<div className="grid grid-cols-2 gap-2 mb-4">
{downloadPlatforms.map((p) => (
<a
key={p.key}
href="https://github.com/soryu-co/makima/releases/latest"
target="_blank"
rel="noopener noreferrer"
className="flex flex-col items-center justify-center gap-1 p-3 border border-[rgba(117,170,252,0.25)] bg-[#0a1525] font-mono text-xs text-[#9bc3ff] transition-colors hover:bg-[#0d1f3a] cursor-pointer"
>
<span className="text-[10px] uppercase tracking-wide">
{p.label}
</span>
<span className="text-[10px] text-[#556677]">
{p.filename}
</span>
</a>
))}
</div>
<div className="border-t border-[rgba(117,170,252,0.15)] pt-3">
<p className="text-[10px] font-mono uppercase tracking-wide text-[#8899aa] mb-2">
Quick Install
</p>
<code className="block bg-black/50 px-3 py-2 text-[11px] font-mono text-green-400 break-all">
curl -fsSL https://raw.githubusercontent.com/soryu-co/makima/master/install.sh | bash
</code>
</div>
</section>
{/* Daemon Setup */}
<section className="border border-[rgba(117,170,252,0.25)] bg-[#0d1b2d] p-4">
<SectionHeader>Daemon Setup</SectionHeader>
<p className="text-[#7788aa] font-mono text-[10px] mb-3">
Set your API key as an environment variable:
</p>
<code className="block bg-black/50 px-3 py-2 text-[11px] font-mono text-green-400 mb-3">
export MAKIMA_API_KEY="your-key"
</code>
<p className="text-[#7788aa] font-mono text-[10px]">
Then run: <code className="text-green-400">makima-daemon</code>
</p>
</section>
{/* Kubernetes Section */}
<section className="border border-[rgba(117,170,252,0.25)] bg-[#0d1b2d] p-4">
<SectionHeader>Run in Kubernetes</SectionHeader>
<p className="text-[#7788aa] font-mono text-[10px] mb-3">
Deploy daemons as containers in Kubernetes for scalable task execution.
</p>
<p className="text-[10px] font-mono uppercase tracking-wide text-[#8899aa] mb-2">
Pull Container Image
</p>
<code className="block bg-black/50 px-3 py-2 text-[11px] font-mono text-green-400 mb-4 break-all">
docker pull ghcr.io/soryu-co/makima-daemon:latest
</code>
<p className="text-[10px] font-mono uppercase tracking-wide text-[#8899aa] mb-2">
Environment Variables
</p>
<div className="bg-black/50 px-3 py-2 text-[11px] font-mono text-green-400 space-y-1 mb-3">
<div>MAKIMA_API_KEY=<span className="text-[#7788aa]">"your-key"</span></div>
<div>MAKIMA_SERVER_URL=<span className="text-[#7788aa]">"https://your-server"</span></div>
<div>GITHUB_TOKEN=<span className="text-[#7788aa]">"ghp_..." </span><span className="text-[#556677]"># optional, for repo access</span></div>
</div>
<p className="text-[#556677] font-mono text-[10px]">
Kubernetes manifests available at{" "}
<a
href="https://github.com/soryu-co/makima"
target="_blank"
rel="noopener noreferrer"
className="text-[#75aafc] hover:underline"
>
github.com/soryu-co/makima
</a>
</p>
</section>
</div>
{/* Right Column */}
<div className="space-y-6">
{/* Connected Daemons */}
<section className="border border-[rgba(117,170,252,0.25)] bg-[#0d1b2d] p-4">
<div className="flex items-center justify-between mb-3 pb-2 border-b border-[rgba(117,170,252,0.15)]">
<div className="flex items-center gap-2">
<h2 className="text-[11px] font-mono uppercase tracking-wide text-[#8899aa]">
Connected Daemons
</h2>
{daemons.length > 0 && (
<span className="text-[10px] font-mono text-[#556677]">
({daemons.filter(d => d.status === "connected").length} connected / {daemons.length} total)
</span>
)}
</div>
<button
onClick={loadDaemons}
disabled={daemonsLoading}
className="text-[10px] font-mono text-[#75aafc] hover:text-[#9bc3ff] disabled:opacity-50"
title="Refresh"
>
{daemonsLoading ? "..." : "\u21BB"}
</button>
</div>
{daemonsError && <ErrorAlert>{daemonsError}</ErrorAlert>}
{daemonsLoading && daemons.length === 0 ? (
<p className="text-[#7788aa] font-mono text-xs">Loading...</p>
) : daemons.length === 0 ? (
<div className="text-center py-4">
<p className="text-[#7788aa] font-mono text-xs mb-2">No daemons connected</p>
<p className="text-[#556677] font-mono text-[10px]">
Start a daemon to enable task execution
</p>
</div>
) : (
<div className="space-y-2">
{daemons.map((daemon) => (
<div
key={daemon.id}
className="border border-[rgba(117,170,252,0.15)] bg-[#0a1525] p-3"
>
<div className="flex items-center justify-between mb-2">
<span className="font-mono text-xs text-[#9bc3ff]">
{daemon.hostname || "Unknown Host"}
</span>
<div className="flex items-center gap-2">
<span
className={`text-[10px] font-mono uppercase px-2 py-0.5 border ${
daemon.status === "connected"
? "text-green-400 border-green-700/50 bg-green-900/20"
: daemon.status === "unhealthy"
? "text-yellow-400 border-yellow-700/50 bg-yellow-900/20"
: "text-[#8899aa] border-[rgba(117,170,252,0.25)]"
}`}
>
{daemon.status}
</span>
</div>
</div>
<div className="font-mono text-[10px] text-[#7788aa] space-y-1">
<div className="flex justify-between">
<span>Tasks</span>
<span className="text-[#9bc3ff]">
{daemon.currentTaskCount} / {daemon.maxConcurrentTasks}
</span>
</div>
<div className="flex justify-between">
<span>Connected</span>
<span className="text-[#75aafc]">
{new Date(daemon.connectedAt).toLocaleString()}
</span>
</div>
{daemon.machineId && (
<div className="flex justify-between">
<span>Machine</span>
<span className="text-[#556677] truncate ml-2" title={daemon.machineId}>
{daemon.machineId.substring(0, 16)}...
</span>
</div>
)}
</div>
{/* Actions Section */}
{daemon.status === "connected" && (
<div className="mt-3 pt-2 border-t border-[rgba(117,170,252,0.1)]">
{restartConfirmDaemonId === daemon.id ? (
<div className="flex items-center justify-between gap-2">
<span className="text-[10px] font-mono text-yellow-400">
Restart daemon? Running tasks will be interrupted.
</span>
<div className="flex gap-2">
<button
onClick={() => setRestartConfirmDaemonId(null)}
className="text-[10px] font-mono text-[#7788aa] hover:text-[#9bc3ff] px-2 py-1"
disabled={restartingDaemonId === daemon.id}
>
Cancel
</button>
<button
onClick={() => handleRestartDaemon(daemon.id)}
disabled={restartingDaemonId === daemon.id}
className="text-[10px] font-mono text-red-400 hover:text-red-300 px-2 py-1 border border-red-700/50 bg-red-900/20 disabled:opacity-50"
>
{restartingDaemonId === daemon.id ? "Restarting..." : "Confirm"}
</button>
</div>
</div>
) : (
<div className="flex items-center gap-3">
<button
onClick={() => setReauthDaemon(daemon)}
className="text-[10px] font-mono text-amber-400 hover:text-amber-300"
>
🔑 Reauthorize
</button>
<button
onClick={() => setRestartConfirmDaemonId(daemon.id)}
className="text-[10px] font-mono text-[#75aafc] hover:text-[#9bc3ff]"
>
⟳ Restart Daemon
</button>
</div>
)}
</div>
)}
</div>
))}
</div>
)}
</section>
</div>
</div>
</main>
{/* Reauth Modal */}
{reauthDaemon && (
<ReauthModal
daemon={reauthDaemon}
onClose={() => setReauthDaemon(null)}
/>
)}
</div>
);
}
|