| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 1 | import { State, AgentMessage } from "../types"; |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 2 | import { LitElement, css, html } from "lit"; |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 3 | import { customElement, property, state } from "lit/decorators.js"; |
| Josh Bleecher Snyder | a0801ad | 2025-04-25 19:34:53 +0000 | [diff] [blame] | 4 | import { formatNumber } from "../utils"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 5 | |
| 6 | @customElement("sketch-container-status") |
| 7 | export class SketchContainerStatus extends LitElement { |
| 8 | // Header bar: Container status details |
| 9 | |
| 10 | @property() |
| 11 | state: State; |
| 12 | |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 13 | @state() |
| 14 | showDetails: boolean = false; |
| 15 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 16 | @state() |
| 17 | lastCommit: { hash: string; pushedBranch?: string } | null = null; |
| 18 | |
| 19 | @state() |
| 20 | lastCommitCopied: boolean = false; |
| 21 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 22 | // 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 Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 27 | /* 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 Zeyliger | 9bca61e | 2025-05-22 12:40:06 -0700 | [diff] [blame] | 42 | /* 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 Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 64 | .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 Zeyliger | 9bca61e | 2025-05-22 12:40:06 -0700 | [diff] [blame] | 124 | .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 Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 150 | .info-container { |
| 151 | display: flex; |
| 152 | align-items: center; |
| 153 | position: relative; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 154 | } |
| 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 Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 167 | .info-expanded { |
| 168 | position: absolute; |
| 169 | top: 100%; |
| 170 | right: 0; |
| 171 | z-index: 10; |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 172 | min-width: 400px; |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 173 | 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 McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 185 | .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 Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 203 | word-break: break-all; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| Philip Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 206 | [title] { |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 207 | cursor: default; |
| Philip Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 210 | .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 Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 215 | |
| 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 Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 244 | display: grid; |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 245 | grid-template-columns: 1fr 1fr; |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 246 | gap: 10px; |
| 247 | width: 100%; |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 248 | } |
| 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 Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 262 | |
| 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 Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 310 | 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 Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 332 | color: #2962ff; |
| 333 | text-decoration: none; |
| 334 | } |
| 335 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 336 | .github-link:hover { |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 337 | text-decoration: underline; |
| 338 | } |
| philip.zeyliger | 6d3de48 | 2025-06-10 19:38:14 -0700 | [diff] [blame] | 339 | |
| 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 McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 376 | `; |
| 377 | |
| 378 | constructor() { |
| 379 | super(); |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 380 | 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 McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 400 | /** |
| 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 Zeyliger | 9bca61e | 2025-05-22 12:40:06 -0700 | [diff] [blame] | 416 | // Check if the commit hash has changed |
| 417 | const hasChanged = |
| 418 | !this.lastCommit || this.lastCommit.hash !== commit.hash; |
| 419 | |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 420 | this.lastCommit = { |
| 421 | hash: commit.hash, |
| 422 | pushedBranch: commit.pushed_branch, |
| 423 | }; |
| 424 | this.lastCommitCopied = false; |
| Philip Zeyliger | 9bca61e | 2025-05-22 12:40:06 -0700 | [diff] [blame] | 425 | |
| 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 Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 443 | } |
| 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 Zeyliger | 9bca61e | 2025-05-22 12:40:06 -0700 | [diff] [blame] | 464 | // Reset the copied state after 1.5 seconds |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 465 | setTimeout(() => { |
| 466 | this.lastCommitCopied = false; |
| Philip Zeyliger | 9bca61e | 2025-05-22 12:40:06 -0700 | [diff] [blame] | 467 | }, 1500); |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 468 | }) |
| 469 | .catch((err) => { |
| 470 | console.error("Failed to copy commit info:", err); |
| 471 | }); |
| 472 | } |
| 473 | |
| Philip Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 474 | formatHostname() { |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 475 | // Only display outside hostname |
| Philip Zeyliger | 18532b2 | 2025-04-23 21:11:46 +0000 | [diff] [blame] | 476 | const outsideHostname = this.state?.outside_hostname; |
| Philip Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 477 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 478 | if (!outsideHostname) { |
| Philip Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 479 | return this.state?.hostname; |
| 480 | } |
| 481 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 482 | return outsideHostname; |
| Philip Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | formatWorkingDir() { |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 486 | // Only display outside working directory |
| Philip Zeyliger | 18532b2 | 2025-04-23 21:11:46 +0000 | [diff] [blame] | 487 | const outsideWorkingDir = this.state?.outside_working_dir; |
| Philip Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 488 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 489 | if (!outsideWorkingDir) { |
| Philip Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 490 | return this.state?.working_dir; |
| 491 | } |
| 492 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 493 | return outsideWorkingDir; |
| Philip Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | getHostnameTooltip() { |
| Philip Zeyliger | 18532b2 | 2025-04-23 21:11:46 +0000 | [diff] [blame] | 497 | const outsideHostname = this.state?.outside_hostname; |
| 498 | const insideHostname = this.state?.inside_hostname; |
| Philip Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 499 | |
| 500 | if ( |
| Philip Zeyliger | 18532b2 | 2025-04-23 21:11:46 +0000 | [diff] [blame] | 501 | !outsideHostname || |
| 502 | !insideHostname || |
| 503 | outsideHostname === insideHostname |
| Philip Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 504 | ) { |
| 505 | return ""; |
| 506 | } |
| 507 | |
| Philip Zeyliger | 18532b2 | 2025-04-23 21:11:46 +0000 | [diff] [blame] | 508 | 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 Zeyliger | d140295 | 2025-04-23 03:54:37 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 526 | // 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 Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 538 | 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() { |
| philip.zeyliger | 8773e68 | 2025-06-11 21:36:21 -0700 | [diff] [blame^] | 550 | // Use the ssh_connection_string from the state if available, otherwise fall back to generating it |
| 551 | return ( |
| 552 | this.state?.ssh_connection_string || `sketch-${this.state?.session_id}` |
| 553 | ); |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 556 | // Format GitHub repository URL to org/repo format |
| 557 | formatGitHubRepo(url) { |
| 558 | if (!url) return null; |
| 559 | |
| 560 | // Common GitHub URL patterns |
| 561 | const patterns = [ |
| 562 | // HTTPS URLs |
| 563 | /https:\/\/github\.com\/([^/]+)\/([^/\s.]+)(?:\.git)?/, |
| 564 | // SSH URLs |
| 565 | /git@github\.com:([^/]+)\/([^/\s.]+)(?:\.git)?/, |
| 566 | // Git protocol |
| 567 | /git:\/\/github\.com\/([^/]+)\/([^/\s.]+)(?:\.git)?/, |
| 568 | ]; |
| 569 | |
| 570 | for (const pattern of patterns) { |
| 571 | const match = url.match(pattern); |
| 572 | if (match) { |
| 573 | return { |
| 574 | formatted: `${match[1]}/${match[2]}`, |
| 575 | url: `https://github.com/${match[1]}/${match[2]}`, |
| philip.zeyliger | 6d3de48 | 2025-06-10 19:38:14 -0700 | [diff] [blame] | 576 | owner: match[1], |
| 577 | repo: match[2], |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 578 | }; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | return null; |
| 583 | } |
| 584 | |
| philip.zeyliger | 6d3de48 | 2025-06-10 19:38:14 -0700 | [diff] [blame] | 585 | // Generate GitHub branch URL if linking is enabled |
| 586 | getGitHubBranchLink(branchName) { |
| 587 | if (!this.state?.link_to_github || !branchName) { |
| 588 | return null; |
| 589 | } |
| 590 | |
| 591 | const github = this.formatGitHubRepo(this.state?.git_origin); |
| 592 | if (!github) { |
| 593 | return null; |
| 594 | } |
| 595 | |
| 596 | return `https://github.com/${github.owner}/${github.repo}/tree/${branchName}`; |
| 597 | } |
| 598 | |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 599 | renderSSHSection() { |
| 600 | // Only show SSH section if we're in a Docker container and have session ID |
| 601 | if (!this.state?.session_id) { |
| 602 | return html``; |
| 603 | } |
| 604 | |
| 605 | const sshHost = this.getSSHHostname(); |
| 606 | const sshCommand = `ssh ${sshHost}`; |
| 607 | const vscodeCommand = `code --remote ssh-remote+root@${sshHost} /app -n`; |
| 608 | const vscodeURL = `vscode://vscode-remote/ssh-remote+root@${sshHost}/app?windowId=_blank`; |
| 609 | |
| 610 | if (!this.state?.ssh_available) { |
| 611 | return html` |
| 612 | <div class="ssh-section"> |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 613 | <h3>Connect to Container</h3> |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 614 | <div class="ssh-warning"> |
| 615 | SSH connections are not available: |
| 616 | ${this.state?.ssh_error || "SSH configuration is missing"} |
| 617 | </div> |
| 618 | </div> |
| 619 | `; |
| 620 | } |
| 621 | |
| 622 | return html` |
| 623 | <div class="ssh-section"> |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 624 | <h3>Connect to Container</h3> |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 625 | <div class="ssh-command"> |
| 626 | <div class="ssh-command-text">${sshCommand}</div> |
| 627 | <button |
| 628 | class="copy-button" |
| 629 | @click=${() => this.copyToClipboard(sshCommand)} |
| 630 | > |
| 631 | Copy |
| 632 | </button> |
| 633 | </div> |
| 634 | <div class="ssh-command"> |
| 635 | <div class="ssh-command-text">${vscodeCommand}</div> |
| 636 | <button |
| 637 | class="copy-button" |
| 638 | @click=${() => this.copyToClipboard(vscodeCommand)} |
| 639 | > |
| 640 | Copy |
| 641 | </button> |
| 642 | </div> |
| 643 | <div class="ssh-command"> |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 644 | <a href="${vscodeURL}" class="vscode-link" title="${vscodeURL}"> |
| 645 | <svg |
| 646 | class="vscode-icon" |
| 647 | xmlns="http://www.w3.org/2000/svg" |
| 648 | viewBox="0 0 24 24" |
| 649 | fill="none" |
| 650 | stroke="white" |
| 651 | stroke-width="2" |
| 652 | stroke-linecap="round" |
| 653 | stroke-linejoin="round" |
| 654 | > |
| 655 | <path |
| 656 | 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" |
| 657 | /> |
| 658 | </svg> |
| 659 | <span>Open in VSCode</span> |
| 660 | </a> |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 661 | </div> |
| 662 | </div> |
| 663 | `; |
| 664 | } |
| 665 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 666 | render() { |
| 667 | return html` |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 668 | <div class="info-container"> |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 669 | <!-- Main visible info in two columns - github/hostname/dir and last commit --> |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 670 | <div class="main-info-grid"> |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 671 | <!-- First column: GitHub repo (or hostname) and working dir --> |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 672 | <div class="info-column"> |
| 673 | <div class="info-item"> |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 674 | ${(() => { |
| 675 | const github = this.formatGitHubRepo(this.state?.git_origin); |
| 676 | if (github) { |
| 677 | return html` |
| 678 | <a |
| 679 | href="${github.url}" |
| 680 | target="_blank" |
| 681 | rel="noopener noreferrer" |
| 682 | class="github-link" |
| 683 | title="${this.state?.git_origin}" |
| 684 | > |
| 685 | ${github.formatted} |
| 686 | </a> |
| 687 | `; |
| 688 | } else { |
| 689 | return html` |
| 690 | <span |
| 691 | id="hostname" |
| 692 | class="info-value" |
| 693 | title="${this.getHostnameTooltip()}" |
| 694 | > |
| 695 | ${this.formatHostname()} |
| 696 | </span> |
| 697 | `; |
| 698 | } |
| 699 | })()} |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 700 | </div> |
| 701 | <div class="info-item"> |
| 702 | <span |
| 703 | id="workingDir" |
| 704 | class="info-value" |
| 705 | title="${this.getWorkingDirTooltip()}" |
| 706 | > |
| 707 | ${this.formatWorkingDir()} |
| 708 | </span> |
| 709 | </div> |
| 710 | </div> |
| 711 | |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 712 | <!-- Second column: Last Commit --> |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 713 | <div class="info-column last-commit-column"> |
| 714 | <div class="info-item"> |
| 715 | <span class="info-label">Last Commit</span> |
| 716 | </div> |
| 717 | <div |
| 718 | class="info-item last-commit-main" |
| 719 | @click=${(e: MouseEvent) => this.copyCommitInfo(e)} |
| 720 | title="Click to copy" |
| 721 | > |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 722 | ${this.lastCommit |
| 723 | ? this.lastCommit.pushedBranch |
| philip.zeyliger | 6d3de48 | 2025-06-10 19:38:14 -0700 | [diff] [blame] | 724 | ? (() => { |
| 725 | const githubLink = this.getGitHubBranchLink( |
| 726 | this.lastCommit.pushedBranch, |
| 727 | ); |
| 728 | return html` |
| 729 | <div class="commit-info-container"> |
| 730 | <span |
| 731 | class="commit-branch-indicator main-grid-commit" |
| 732 | title="Click to copy: ${this.lastCommit |
| 733 | .pushedBranch}" |
| 734 | @click=${(e) => this.copyCommitInfo(e)} |
| 735 | >${this.lastCommit.pushedBranch}</span |
| 736 | > |
| 737 | <span class="copy-icon"> |
| 738 | ${this.lastCommitCopied |
| 739 | ? html`<svg |
| 740 | xmlns="http://www.w3.org/2000/svg" |
| 741 | width="16" |
| 742 | height="16" |
| 743 | viewBox="0 0 24 24" |
| 744 | fill="none" |
| 745 | stroke="currentColor" |
| 746 | stroke-width="2" |
| 747 | stroke-linecap="round" |
| 748 | stroke-linejoin="round" |
| 749 | > |
| 750 | <path d="M20 6L9 17l-5-5"></path> |
| 751 | </svg>` |
| 752 | : html`<svg |
| 753 | xmlns="http://www.w3.org/2000/svg" |
| 754 | width="16" |
| 755 | height="16" |
| 756 | viewBox="0 0 24 24" |
| 757 | fill="none" |
| 758 | stroke="currentColor" |
| 759 | stroke-width="2" |
| 760 | stroke-linecap="round" |
| 761 | stroke-linejoin="round" |
| 762 | > |
| 763 | <rect |
| 764 | x="9" |
| 765 | y="9" |
| 766 | width="13" |
| 767 | height="13" |
| 768 | rx="2" |
| 769 | ry="2" |
| 770 | ></rect> |
| 771 | <path |
| 772 | d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" |
| 773 | ></path> |
| 774 | </svg>`} |
| 775 | </span> |
| 776 | ${githubLink |
| 777 | ? html`<a |
| 778 | href="${githubLink}" |
| 779 | target="_blank" |
| 780 | rel="noopener noreferrer" |
| 781 | class="octocat-link" |
| 782 | title="Open ${this.lastCommit |
| 783 | .pushedBranch} on GitHub" |
| 784 | @click=${(e) => e.stopPropagation()} |
| 785 | > |
| 786 | <svg |
| 787 | class="octocat-icon" |
| 788 | viewBox="0 0 16 16" |
| 789 | width="16" |
| 790 | height="16" |
| 791 | > |
| 792 | <path |
| 793 | fill="currentColor" |
| 794 | 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" |
| 795 | /> |
| 796 | </svg> |
| 797 | </a>` |
| 798 | : ""} |
| 799 | </div> |
| 800 | `; |
| 801 | })() |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 802 | : html`<span class="commit-hash-indicator main-grid-commit" |
| 803 | >${this.lastCommit.hash.substring(0, 8)}</span |
| 804 | >` |
| 805 | : html`<span class="no-commit-indicator">N/A</span>`} |
| 806 | </div> |
| 807 | </div> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 808 | </div> |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 809 | |
| 810 | <!-- Info toggle button --> |
| 811 | <button |
| 812 | class="info-toggle ${this.showDetails ? "active" : ""}" |
| 813 | @click=${this._toggleInfoDetails} |
| 814 | title="Show/hide details" |
| 815 | > |
| 816 | i |
| 817 | </button> |
| 818 | |
| 819 | <!-- Expanded info panel --> |
| 820 | <div class="info-expanded ${this.showDetails ? "active" : ""}"> |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 821 | <!-- Last Commit section moved to main grid --> |
| 822 | |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 823 | <div class="detailed-info-grid"> |
| 824 | <div class="info-item"> |
| 825 | <span class="info-label">Commit:</span> |
| 826 | <span id="initialCommit" class="info-value" |
| 827 | >${this.state?.initial_commit?.substring(0, 8)}</span |
| 828 | > |
| 829 | </div> |
| 830 | <div class="info-item"> |
| 831 | <span class="info-label">Msgs:</span> |
| 832 | <span id="messageCount" class="info-value" |
| 833 | >${this.state?.message_count}</span |
| 834 | > |
| 835 | </div> |
| 836 | <div class="info-item"> |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 837 | <span class="info-label">Session ID:</span> |
| 838 | <span id="sessionId" class="info-value" |
| 839 | >${this.state?.session_id || "N/A"}</span |
| 840 | > |
| 841 | </div> |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 842 | <div class="info-item"> |
| 843 | <span class="info-label">Hostname:</span> |
| 844 | <span |
| 845 | id="hostnameDetail" |
| 846 | class="info-value" |
| 847 | title="${this.getHostnameTooltip()}" |
| 848 | > |
| 849 | ${this.formatHostname()} |
| 850 | </span> |
| 851 | </div> |
| Philip Zeyliger | 7231839 | 2025-05-14 02:56:07 +0000 | [diff] [blame] | 852 | ${this.state?.agent_state |
| 853 | ? html` |
| 854 | <div class="info-item"> |
| 855 | <span class="info-label">Agent State:</span> |
| 856 | <span id="agentState" class="info-value" |
| 857 | >${this.state?.agent_state}</span |
| 858 | > |
| 859 | </div> |
| 860 | ` |
| 861 | : ""} |
| Philip Zeyliger | 16fa8b4 | 2025-05-02 04:28:16 +0000 | [diff] [blame] | 862 | <div class="info-item"> |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 863 | <span class="info-label">Input tokens:</span> |
| 864 | <span id="inputTokens" class="info-value" |
| 865 | >${formatNumber( |
| 866 | (this.state?.total_usage?.input_tokens || 0) + |
| 867 | (this.state?.total_usage?.cache_read_input_tokens || 0) + |
| 868 | (this.state?.total_usage?.cache_creation_input_tokens || 0), |
| 869 | )}</span |
| 870 | > |
| 871 | </div> |
| 872 | <div class="info-item"> |
| 873 | <span class="info-label">Output tokens:</span> |
| 874 | <span id="outputTokens" class="info-value" |
| 875 | >${formatNumber(this.state?.total_usage?.output_tokens)}</span |
| 876 | > |
| 877 | </div> |
| Josh Bleecher Snyder | 44f847a | 2025-06-05 14:33:50 -0700 | [diff] [blame] | 878 | ${(this.state?.total_usage?.total_cost_usd || 0) > 0 |
| 879 | ? html` |
| 880 | <div class="info-item"> |
| 881 | <span class="info-label">Total cost:</span> |
| 882 | <span id="totalCost" class="info-value cost" |
| 883 | >$${(this.state?.total_usage?.total_cost_usd).toFixed( |
| 884 | 2, |
| 885 | )}</span |
| 886 | > |
| 887 | </div> |
| 888 | ` |
| 889 | : ""} |
| Philip Zeyliger | e66db3e | 2025-04-27 15:40:39 +0000 | [diff] [blame] | 890 | <div |
| 891 | class="info-item" |
| 892 | style="grid-column: 1 / -1; margin-top: 5px; border-top: 1px solid #eee; padding-top: 5px;" |
| 893 | > |
| 894 | <a href="logs">Logs</a> (<a href="download">Download</a>) |
| 895 | </div> |
| 896 | </div> |
| Philip Zeyliger | c72fff5 | 2025-04-29 20:17:54 +0000 | [diff] [blame] | 897 | |
| 898 | <!-- SSH Connection Information --> |
| 899 | ${this.renderSSHSection()} |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 900 | </div> |
| 901 | </div> |
| 902 | `; |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | declare global { |
| 907 | interface HTMLElementTagNameMap { |
| 908 | "sketch-container-status": SketchContainerStatus; |
| 909 | } |
| 910 | } |