blob: 560044a104690cebf057592348a64d80882f844d [file] [log] [blame]
Philip Zeyliger16fa8b42025-05-02 04:28:16 +00001import { State, AgentMessage } from "../types";
Sean McCulloughb29f8912025-04-20 15:39:11 -07002import { LitElement, css, html } from "lit";
Philip Zeyligere66db3e2025-04-27 15:40:39 +00003import { customElement, property, state } from "lit/decorators.js";
Josh Bleecher Snydera0801ad2025-04-25 19:34:53 +00004import { formatNumber } from "../utils";
Sean McCullough86b56862025-04-18 13:04:03 -07005
6@customElement("sketch-container-status")
7export class SketchContainerStatus extends LitElement {
8 // Header bar: Container status details
9
10 @property()
11 state: State;
12
Philip Zeyligere66db3e2025-04-27 15:40:39 +000013 @state()
14 showDetails: boolean = false;
15
Philip Zeyliger16fa8b42025-05-02 04:28:16 +000016 @state()
17 lastCommit: { hash: string; pushedBranch?: string } | null = null;
18
19 @state()
20 lastCommitCopied: boolean = false;
21
Sean McCullough86b56862025-04-18 13:04:03 -070022 // See https://lit.dev/docs/components/styles/ for how lit-element handles CSS.
23 // Note that these styles only apply to the scope of this web component's
24 // shadow DOM node, so they won't leak out or collide with CSS declared in
25 // other components or the containing web page (...unless you want it to do that).
26 static styles = css`
Philip Zeyliger16fa8b42025-05-02 04:28:16 +000027 /* Last commit display styling */
28 .last-commit {
29 display: flex;
30 flex-direction: column;
31 padding: 3px 8px;
32 cursor: pointer;
33 position: relative;
34 margin: 4px 0;
35 transition: color 0.2s ease;
36 }
37
38 .last-commit:hover {
39 color: #0366d6;
40 }
41
Philip Zeyliger9bca61e2025-05-22 12:40:06 -070042 /* Pulse animation for new commits */
43 @keyframes pulse {
44 0% {
45 transform: scale(1);
46 opacity: 1;
47 }
48 50% {
49 transform: scale(1.05);
50 opacity: 0.8;
51 }
52 100% {
53 transform: scale(1);
54 opacity: 1;
55 }
56 }
57
58 .pulse {
59 animation: pulse 1.5s ease-in-out;
60 background-color: rgba(38, 132, 255, 0.1);
61 border-radius: 3px;
62 }
63
Philip Zeyliger16fa8b42025-05-02 04:28:16 +000064 .last-commit-title {
65 color: #666;
66 font-family: system-ui, sans-serif;
67 font-size: 11px;
68 font-weight: 500;
69 line-height: 1.2;
70 }
71
72 .last-commit-hash {
73 font-family: monospace;
74 font-size: 12px;
75 white-space: nowrap;
76 overflow: hidden;
77 text-overflow: ellipsis;
78 }
79
80 /* Styles for the last commit in main grid */
81 .last-commit-column {
82 justify-content: flex-start;
83 }
84
85 .info-label {
86 color: #666;
87 font-family: system-ui, sans-serif;
88 font-size: 11px;
89 font-weight: 500;
90 }
91
92 .last-commit-main {
93 cursor: pointer;
94 position: relative;
95 padding-top: 0;
96 }
97
98 .last-commit-main:hover {
99 color: #0366d6;
100 }
101
102 .main-grid-commit {
103 font-family: monospace;
104 font-size: 12px;
105 white-space: nowrap;
106 overflow: hidden;
107 text-overflow: ellipsis;
108 }
109
110 .commit-hash-indicator {
111 color: #666;
112 }
113
114 .commit-branch-indicator {
115 color: #28a745;
116 }
117
118 .no-commit-indicator {
119 color: #999;
120 font-style: italic;
121 font-size: 12px;
122 }
123
Philip Zeyliger9bca61e2025-05-22 12:40:06 -0700124 .copied-indicator {
125 position: absolute;
126 top: 0;
127 left: 0;
128 background: rgba(0, 0, 0, 0.7);
129 color: white;
130 padding: 2px 6px;
131 border-radius: 3px;
132 font-size: 11px;
133 pointer-events: none;
134 z-index: 10;
135 }
136
137 .copy-icon {
138 margin-left: 4px;
139 opacity: 0.7;
140 }
141
142 .copy-icon svg {
143 vertical-align: middle;
144 }
145
146 .last-commit-main:hover .copy-icon {
147 opacity: 1;
148 }
149
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000150 .info-container {
151 display: flex;
152 align-items: center;
153 position: relative;
Sean McCullough86b56862025-04-18 13:04:03 -0700154 }
155
156 .info-grid {
157 display: flex;
158 flex-wrap: wrap;
159 gap: 8px;
160 background: #f9f9f9;
161 border-radius: 4px;
162 padding: 4px 10px;
163 box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
164 flex: 1;
165 }
166
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000167 .info-expanded {
168 position: absolute;
169 top: 100%;
170 right: 0;
171 z-index: 10;
Philip Zeyligerc72fff52025-04-29 20:17:54 +0000172 min-width: 400px;
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000173 background: white;
174 border-radius: 8px;
175 padding: 10px 15px;
176 box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
177 margin-top: 5px;
178 display: none;
179 }
180
181 .info-expanded.active {
182 display: block;
183 }
184
Sean McCullough86b56862025-04-18 13:04:03 -0700185 .info-item {
186 display: flex;
187 align-items: center;
188 white-space: nowrap;
189 margin-right: 10px;
190 font-size: 13px;
191 }
192
193 .info-label {
194 font-size: 11px;
195 color: #555;
196 margin-right: 3px;
197 font-weight: 500;
198 }
199
200 .info-value {
201 font-size: 11px;
202 font-weight: 600;
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000203 word-break: break-all;
Sean McCullough86b56862025-04-18 13:04:03 -0700204 }
205
Philip Zeyligerd1402952025-04-23 03:54:37 +0000206 [title] {
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000207 cursor: default;
Philip Zeyligerd1402952025-04-23 03:54:37 +0000208 }
209
Sean McCullough86b56862025-04-18 13:04:03 -0700210 .info-item a {
211 --tw-text-opacity: 1;
212 color: rgb(37 99 235 / var(--tw-text-opacity, 1));
213 text-decoration: inherit;
214 }
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000215
216 .info-toggle {
217 margin-left: 8px;
218 width: 24px;
219 height: 24px;
220 border-radius: 50%;
221 display: flex;
222 align-items: center;
223 justify-content: center;
224 background: #f0f0f0;
225 border: 1px solid #ddd;
226 cursor: pointer;
227 font-weight: bold;
228 font-style: italic;
229 color: #555;
230 transition: all 0.2s ease;
231 }
232
233 .info-toggle:hover {
234 background: #e0e0e0;
235 }
236
237 .info-toggle.active {
238 background: #4a90e2;
239 color: white;
240 border-color: #3a80d2;
241 }
242
243 .main-info-grid {
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000244 display: grid;
Josh Bleecher Snyder44f847a2025-06-05 14:33:50 -0700245 grid-template-columns: 1fr 1fr;
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000246 gap: 10px;
247 width: 100%;
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000248 }
249
250 .info-column {
251 display: flex;
252 flex-direction: column;
253 gap: 2px;
254 }
255
256 .detailed-info-grid {
257 display: grid;
258 grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
259 gap: 8px;
260 margin-top: 10px;
261 }
Philip Zeyligerc72fff52025-04-29 20:17:54 +0000262
263 .ssh-section {
264 margin-top: 10px;
265 padding-top: 10px;
266 border-top: 1px solid #eee;
267 }
268
269 .ssh-command {
270 display: flex;
271 align-items: center;
272 margin-bottom: 8px;
273 gap: 10px;
274 }
275
276 .ssh-command-text {
277 font-family: monospace;
278 font-size: 12px;
279 background: #f5f5f5;
280 padding: 4px 8px;
281 border-radius: 4px;
282 border: 1px solid #e0e0e0;
283 flex-grow: 1;
284 }
285
286 .copy-button {
287 background: #f0f0f0;
288 border: 1px solid #ddd;
289 border-radius: 4px;
290 padding: 3px 6px;
291 font-size: 11px;
292 cursor: pointer;
293 transition: all 0.2s;
294 }
295
296 .copy-button:hover {
297 background: #e0e0e0;
298 }
299
300 .ssh-warning {
301 background: #fff3e0;
302 border-left: 3px solid #ff9800;
303 padding: 8px 12px;
304 margin-top: 8px;
305 font-size: 12px;
306 color: #e65100;
307 }
308
309 .vscode-link {
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000310 color: white;
311 text-decoration: none;
312 background-color: #0066b8;
313 padding: 4px 8px;
314 border-radius: 4px;
315 display: flex;
316 align-items: center;
317 gap: 6px;
318 font-size: 12px;
319 transition: all 0.2s ease;
320 }
321
322 .vscode-link:hover {
323 background-color: #005091;
324 }
325
326 .vscode-icon {
327 width: 16px;
328 height: 16px;
329 }
330
331 .github-link {
Philip Zeyligerc72fff52025-04-29 20:17:54 +0000332 color: #2962ff;
333 text-decoration: none;
334 }
335
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000336 .github-link:hover {
Philip Zeyligerc72fff52025-04-29 20:17:54 +0000337 text-decoration: underline;
338 }
philip.zeyliger6d3de482025-06-10 19:38:14 -0700339
340 .commit-info-container {
341 display: flex;
342 align-items: center;
343 gap: 6px;
344 }
345
346 .commit-info-container .copy-icon {
347 opacity: 0.7;
348 display: flex;
349 align-items: center;
350 }
351
352 .commit-info-container .copy-icon svg {
353 vertical-align: middle;
354 }
355
356 .commit-info-container:hover .copy-icon {
357 opacity: 1;
358 }
359
360 .octocat-link {
361 color: #586069;
362 text-decoration: none;
363 display: flex;
364 align-items: center;
365 transition: color 0.2s ease;
366 }
367
368 .octocat-link:hover {
369 color: #0366d6;
370 }
371
372 .octocat-icon {
373 width: 16px;
374 height: 16px;
375 }
Sean McCullough86b56862025-04-18 13:04:03 -0700376 `;
377
378 constructor() {
379 super();
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000380 this._toggleInfoDetails = this._toggleInfoDetails.bind(this);
381
382 // Close the info panel when clicking outside of it
383 document.addEventListener("click", (event) => {
384 if (this.showDetails && !this.contains(event.target as Node)) {
385 this.showDetails = false;
386 this.requestUpdate();
387 }
388 });
389 }
390
391 /**
392 * Toggle the display of detailed information
393 */
394 private _toggleInfoDetails(event: Event) {
395 event.stopPropagation();
396 this.showDetails = !this.showDetails;
397 this.requestUpdate();
Sean McCullough86b56862025-04-18 13:04:03 -0700398 }
399
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000400 /**
401 * Update the last commit information based on messages
402 */
403 public updateLastCommitInfo(newMessages: AgentMessage[]): void {
404 if (!newMessages || newMessages.length === 0) return;
405
406 // Process messages in chronological order (latest last)
407 for (const message of newMessages) {
408 if (
409 message.type === "commit" &&
410 message.commits &&
411 message.commits.length > 0
412 ) {
413 // Get the first commit from the list
414 const commit = message.commits[0];
415 if (commit) {
Philip Zeyliger9bca61e2025-05-22 12:40:06 -0700416 // Check if the commit hash has changed
417 const hasChanged =
418 !this.lastCommit || this.lastCommit.hash !== commit.hash;
419
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000420 this.lastCommit = {
421 hash: commit.hash,
422 pushedBranch: commit.pushed_branch,
423 };
424 this.lastCommitCopied = false;
Philip Zeyliger9bca61e2025-05-22 12:40:06 -0700425
426 // Add pulse animation if the commit changed
427 if (hasChanged) {
428 // Find the last commit element
429 setTimeout(() => {
430 const lastCommitEl =
431 this.shadowRoot?.querySelector(".last-commit-main");
432 if (lastCommitEl) {
433 // Add the pulse class
434 lastCommitEl.classList.add("pulse");
435
436 // Remove the pulse class after animation completes
437 setTimeout(() => {
438 lastCommitEl.classList.remove("pulse");
439 }, 1500);
440 }
441 }, 0);
442 }
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000443 }
444 }
445 }
446 }
447
448 /**
449 * Copy commit info to clipboard when clicked
450 */
451 private copyCommitInfo(event: MouseEvent): void {
452 event.preventDefault();
453 event.stopPropagation();
454
455 if (!this.lastCommit) return;
456
457 const textToCopy =
458 this.lastCommit.pushedBranch || this.lastCommit.hash.substring(0, 8);
459
460 navigator.clipboard
461 .writeText(textToCopy)
462 .then(() => {
463 this.lastCommitCopied = true;
Philip Zeyliger9bca61e2025-05-22 12:40:06 -0700464 // Reset the copied state after 1.5 seconds
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000465 setTimeout(() => {
466 this.lastCommitCopied = false;
Philip Zeyliger9bca61e2025-05-22 12:40:06 -0700467 }, 1500);
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000468 })
469 .catch((err) => {
470 console.error("Failed to copy commit info:", err);
471 });
472 }
473
Philip Zeyligerd1402952025-04-23 03:54:37 +0000474 formatHostname() {
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000475 // Only display outside hostname
Philip Zeyliger18532b22025-04-23 21:11:46 +0000476 const outsideHostname = this.state?.outside_hostname;
Philip Zeyligerd1402952025-04-23 03:54:37 +0000477
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000478 if (!outsideHostname) {
Philip Zeyligerd1402952025-04-23 03:54:37 +0000479 return this.state?.hostname;
480 }
481
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000482 return outsideHostname;
Philip Zeyligerd1402952025-04-23 03:54:37 +0000483 }
484
485 formatWorkingDir() {
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000486 // Only display outside working directory
Philip Zeyliger18532b22025-04-23 21:11:46 +0000487 const outsideWorkingDir = this.state?.outside_working_dir;
Philip Zeyligerd1402952025-04-23 03:54:37 +0000488
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000489 if (!outsideWorkingDir) {
Philip Zeyligerd1402952025-04-23 03:54:37 +0000490 return this.state?.working_dir;
491 }
492
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000493 return outsideWorkingDir;
Philip Zeyligerd1402952025-04-23 03:54:37 +0000494 }
495
496 getHostnameTooltip() {
Philip Zeyliger18532b22025-04-23 21:11:46 +0000497 const outsideHostname = this.state?.outside_hostname;
498 const insideHostname = this.state?.inside_hostname;
Philip Zeyligerd1402952025-04-23 03:54:37 +0000499
500 if (
Philip Zeyliger18532b22025-04-23 21:11:46 +0000501 !outsideHostname ||
502 !insideHostname ||
503 outsideHostname === insideHostname
Philip Zeyligerd1402952025-04-23 03:54:37 +0000504 ) {
505 return "";
506 }
507
Philip Zeyliger18532b22025-04-23 21:11:46 +0000508 return `Outside: ${outsideHostname}, Inside: ${insideHostname}`;
509 }
510
511 getWorkingDirTooltip() {
512 const outsideWorkingDir = this.state?.outside_working_dir;
513 const insideWorkingDir = this.state?.inside_working_dir;
514
515 if (
516 !outsideWorkingDir ||
517 !insideWorkingDir ||
518 outsideWorkingDir === insideWorkingDir
519 ) {
520 return "";
521 }
522
523 return `Outside: ${outsideWorkingDir}, Inside: ${insideWorkingDir}`;
Philip Zeyligerd1402952025-04-23 03:54:37 +0000524 }
525
Sean McCullough86b56862025-04-18 13:04:03 -0700526 // See https://lit.dev/docs/components/lifecycle/
527 connectedCallback() {
528 super.connectedCallback();
529 // register event listeners
530 }
531
532 // See https://lit.dev/docs/components/lifecycle/
533 disconnectedCallback() {
534 super.disconnectedCallback();
535 // unregister event listeners
536 }
537
Philip Zeyligerc72fff52025-04-29 20:17:54 +0000538 copyToClipboard(text: string) {
539 navigator.clipboard
540 .writeText(text)
541 .then(() => {
542 // Could add a temporary success indicator here
543 })
544 .catch((err) => {
545 console.error("Could not copy text: ", err);
546 });
547 }
548
549 getSSHHostname() {
550 return `sketch-${this.state?.session_id}`;
551 }
552
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000553 // Format GitHub repository URL to org/repo format
554 formatGitHubRepo(url) {
555 if (!url) return null;
556
557 // Common GitHub URL patterns
558 const patterns = [
559 // HTTPS URLs
560 /https:\/\/github\.com\/([^/]+)\/([^/\s.]+)(?:\.git)?/,
561 // SSH URLs
562 /git@github\.com:([^/]+)\/([^/\s.]+)(?:\.git)?/,
563 // Git protocol
564 /git:\/\/github\.com\/([^/]+)\/([^/\s.]+)(?:\.git)?/,
565 ];
566
567 for (const pattern of patterns) {
568 const match = url.match(pattern);
569 if (match) {
570 return {
571 formatted: `${match[1]}/${match[2]}`,
572 url: `https://github.com/${match[1]}/${match[2]}`,
philip.zeyliger6d3de482025-06-10 19:38:14 -0700573 owner: match[1],
574 repo: match[2],
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000575 };
576 }
577 }
578
579 return null;
580 }
581
philip.zeyliger6d3de482025-06-10 19:38:14 -0700582 // Generate GitHub branch URL if linking is enabled
583 getGitHubBranchLink(branchName) {
584 if (!this.state?.link_to_github || !branchName) {
585 return null;
586 }
587
588 const github = this.formatGitHubRepo(this.state?.git_origin);
589 if (!github) {
590 return null;
591 }
592
593 return `https://github.com/${github.owner}/${github.repo}/tree/${branchName}`;
594 }
595
Philip Zeyligerc72fff52025-04-29 20:17:54 +0000596 renderSSHSection() {
597 // Only show SSH section if we're in a Docker container and have session ID
598 if (!this.state?.session_id) {
599 return html``;
600 }
601
602 const sshHost = this.getSSHHostname();
603 const sshCommand = `ssh ${sshHost}`;
604 const vscodeCommand = `code --remote ssh-remote+root@${sshHost} /app -n`;
605 const vscodeURL = `vscode://vscode-remote/ssh-remote+root@${sshHost}/app?windowId=_blank`;
606
607 if (!this.state?.ssh_available) {
608 return html`
609 <div class="ssh-section">
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000610 <h3>Connect to Container</h3>
Philip Zeyligerc72fff52025-04-29 20:17:54 +0000611 <div class="ssh-warning">
612 SSH connections are not available:
613 ${this.state?.ssh_error || "SSH configuration is missing"}
614 </div>
615 </div>
616 `;
617 }
618
619 return html`
620 <div class="ssh-section">
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000621 <h3>Connect to Container</h3>
Philip Zeyligerc72fff52025-04-29 20:17:54 +0000622 <div class="ssh-command">
623 <div class="ssh-command-text">${sshCommand}</div>
624 <button
625 class="copy-button"
626 @click=${() => this.copyToClipboard(sshCommand)}
627 >
628 Copy
629 </button>
630 </div>
631 <div class="ssh-command">
632 <div class="ssh-command-text">${vscodeCommand}</div>
633 <button
634 class="copy-button"
635 @click=${() => this.copyToClipboard(vscodeCommand)}
636 >
637 Copy
638 </button>
639 </div>
640 <div class="ssh-command">
Philip Zeyligerbce3a132025-04-30 22:03:39 +0000641 <a href="${vscodeURL}" class="vscode-link" title="${vscodeURL}">
642 <svg
643 class="vscode-icon"
644 xmlns="http://www.w3.org/2000/svg"
645 viewBox="0 0 24 24"
646 fill="none"
647 stroke="white"
648 stroke-width="2"
649 stroke-linecap="round"
650 stroke-linejoin="round"
651 >
652 <path
653 d="M16.5 9.4 7.55 4.24a.35.35 0 0 0-.41.01l-1.23.93a.35.35 0 0 0-.14.29v13.04c0 .12.07.23.17.29l1.24.93c.13.1.31.09.43-.01L16.5 14.6l-6.39 4.82c-.16.12-.38.12-.55.01l-1.33-1.01a.35.35 0 0 1-.14-.28V5.88c0-.12.07-.23.18-.29l1.23-.93c.14-.1.32-.1.46 0l6.54 4.92-6.54 4.92c-.14.1-.32.1-.46 0l-1.23-.93a.35.35 0 0 1-.18-.29V5.88c0-.12.07-.23.17-.29l1.33-1.01c.16-.12.39-.11.55.01l6.39 4.81z"
654 />
655 </svg>
656 <span>Open in VSCode</span>
657 </a>
Philip Zeyligerc72fff52025-04-29 20:17:54 +0000658 </div>
659 </div>
660 `;
661 }
662
Sean McCullough86b56862025-04-18 13:04:03 -0700663 render() {
664 return html`
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000665 <div class="info-container">
Josh Bleecher Snyder44f847a2025-06-05 14:33:50 -0700666 <!-- Main visible info in two columns - github/hostname/dir and last commit -->
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000667 <div class="main-info-grid">
Josh Bleecher Snyder44f847a2025-06-05 14:33:50 -0700668 <!-- First column: GitHub repo (or hostname) and working dir -->
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000669 <div class="info-column">
670 <div class="info-item">
Josh Bleecher Snyder44f847a2025-06-05 14:33:50 -0700671 ${(() => {
672 const github = this.formatGitHubRepo(this.state?.git_origin);
673 if (github) {
674 return html`
675 <a
676 href="${github.url}"
677 target="_blank"
678 rel="noopener noreferrer"
679 class="github-link"
680 title="${this.state?.git_origin}"
681 >
682 ${github.formatted}
683 </a>
684 `;
685 } else {
686 return html`
687 <span
688 id="hostname"
689 class="info-value"
690 title="${this.getHostnameTooltip()}"
691 >
692 ${this.formatHostname()}
693 </span>
694 `;
695 }
696 })()}
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000697 </div>
698 <div class="info-item">
699 <span
700 id="workingDir"
701 class="info-value"
702 title="${this.getWorkingDirTooltip()}"
703 >
704 ${this.formatWorkingDir()}
705 </span>
706 </div>
707 </div>
708
Josh Bleecher Snyder44f847a2025-06-05 14:33:50 -0700709 <!-- Second column: Last Commit -->
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000710 <div class="info-column last-commit-column">
711 <div class="info-item">
712 <span class="info-label">Last Commit</span>
713 </div>
714 <div
715 class="info-item last-commit-main"
716 @click=${(e: MouseEvent) => this.copyCommitInfo(e)}
717 title="Click to copy"
718 >
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000719 ${this.lastCommit
720 ? this.lastCommit.pushedBranch
philip.zeyliger6d3de482025-06-10 19:38:14 -0700721 ? (() => {
722 const githubLink = this.getGitHubBranchLink(
723 this.lastCommit.pushedBranch,
724 );
725 return html`
726 <div class="commit-info-container">
727 <span
728 class="commit-branch-indicator main-grid-commit"
729 title="Click to copy: ${this.lastCommit
730 .pushedBranch}"
731 @click=${(e) => this.copyCommitInfo(e)}
732 >${this.lastCommit.pushedBranch}</span
733 >
734 <span class="copy-icon">
735 ${this.lastCommitCopied
736 ? html`<svg
737 xmlns="http://www.w3.org/2000/svg"
738 width="16"
739 height="16"
740 viewBox="0 0 24 24"
741 fill="none"
742 stroke="currentColor"
743 stroke-width="2"
744 stroke-linecap="round"
745 stroke-linejoin="round"
746 >
747 <path d="M20 6L9 17l-5-5"></path>
748 </svg>`
749 : html`<svg
750 xmlns="http://www.w3.org/2000/svg"
751 width="16"
752 height="16"
753 viewBox="0 0 24 24"
754 fill="none"
755 stroke="currentColor"
756 stroke-width="2"
757 stroke-linecap="round"
758 stroke-linejoin="round"
759 >
760 <rect
761 x="9"
762 y="9"
763 width="13"
764 height="13"
765 rx="2"
766 ry="2"
767 ></rect>
768 <path
769 d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"
770 ></path>
771 </svg>`}
772 </span>
773 ${githubLink
774 ? html`<a
775 href="${githubLink}"
776 target="_blank"
777 rel="noopener noreferrer"
778 class="octocat-link"
779 title="Open ${this.lastCommit
780 .pushedBranch} on GitHub"
781 @click=${(e) => e.stopPropagation()}
782 >
783 <svg
784 class="octocat-icon"
785 viewBox="0 0 16 16"
786 width="16"
787 height="16"
788 >
789 <path
790 fill="currentColor"
791 d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"
792 />
793 </svg>
794 </a>`
795 : ""}
796 </div>
797 `;
798 })()
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000799 : html`<span class="commit-hash-indicator main-grid-commit"
800 >${this.lastCommit.hash.substring(0, 8)}</span
801 >`
802 : html`<span class="no-commit-indicator">N/A</span>`}
803 </div>
804 </div>
Sean McCullough86b56862025-04-18 13:04:03 -0700805 </div>
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000806
807 <!-- Info toggle button -->
808 <button
809 class="info-toggle ${this.showDetails ? "active" : ""}"
810 @click=${this._toggleInfoDetails}
811 title="Show/hide details"
812 >
813 i
814 </button>
815
816 <!-- Expanded info panel -->
817 <div class="info-expanded ${this.showDetails ? "active" : ""}">
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000818 <!-- Last Commit section moved to main grid -->
819
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000820 <div class="detailed-info-grid">
821 <div class="info-item">
822 <span class="info-label">Commit:</span>
823 <span id="initialCommit" class="info-value"
824 >${this.state?.initial_commit?.substring(0, 8)}</span
825 >
826 </div>
827 <div class="info-item">
828 <span class="info-label">Msgs:</span>
829 <span id="messageCount" class="info-value"
830 >${this.state?.message_count}</span
831 >
832 </div>
833 <div class="info-item">
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000834 <span class="info-label">Session ID:</span>
835 <span id="sessionId" class="info-value"
836 >${this.state?.session_id || "N/A"}</span
837 >
838 </div>
Josh Bleecher Snyder44f847a2025-06-05 14:33:50 -0700839 <div class="info-item">
840 <span class="info-label">Hostname:</span>
841 <span
842 id="hostnameDetail"
843 class="info-value"
844 title="${this.getHostnameTooltip()}"
845 >
846 ${this.formatHostname()}
847 </span>
848 </div>
Philip Zeyliger72318392025-05-14 02:56:07 +0000849 ${this.state?.agent_state
850 ? html`
851 <div class="info-item">
852 <span class="info-label">Agent State:</span>
853 <span id="agentState" class="info-value"
854 >${this.state?.agent_state}</span
855 >
856 </div>
857 `
858 : ""}
Philip Zeyliger16fa8b42025-05-02 04:28:16 +0000859 <div class="info-item">
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000860 <span class="info-label">Input tokens:</span>
861 <span id="inputTokens" class="info-value"
862 >${formatNumber(
863 (this.state?.total_usage?.input_tokens || 0) +
864 (this.state?.total_usage?.cache_read_input_tokens || 0) +
865 (this.state?.total_usage?.cache_creation_input_tokens || 0),
866 )}</span
867 >
868 </div>
869 <div class="info-item">
870 <span class="info-label">Output tokens:</span>
871 <span id="outputTokens" class="info-value"
872 >${formatNumber(this.state?.total_usage?.output_tokens)}</span
873 >
874 </div>
Josh Bleecher Snyder44f847a2025-06-05 14:33:50 -0700875 ${(this.state?.total_usage?.total_cost_usd || 0) > 0
876 ? html`
877 <div class="info-item">
878 <span class="info-label">Total cost:</span>
879 <span id="totalCost" class="info-value cost"
880 >$${(this.state?.total_usage?.total_cost_usd).toFixed(
881 2,
882 )}</span
883 >
884 </div>
885 `
886 : ""}
Philip Zeyligere66db3e2025-04-27 15:40:39 +0000887 <div
888 class="info-item"
889 style="grid-column: 1 / -1; margin-top: 5px; border-top: 1px solid #eee; padding-top: 5px;"
890 >
891 <a href="logs">Logs</a> (<a href="download">Download</a>)
892 </div>
893 </div>
Philip Zeyligerc72fff52025-04-29 20:17:54 +0000894
895 <!-- SSH Connection Information -->
896 ${this.renderSSHSection()}
Sean McCullough86b56862025-04-18 13:04:03 -0700897 </div>
898 </div>
899 `;
900 }
901}
902
903declare global {
904 interface HTMLElementTagNameMap {
905 "sketch-container-status": SketchContainerStatus;
906 }
907}