File size: 50,451 Bytes
1f21206 | 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 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 | import { useEffect, useMemo, useRef, useState } from 'react'
import { skillsApi } from '../../api/skills'
import { mcpApi } from '../../api/mcp'
import {
sessionsApi,
type SessionContextSnapshot,
type SessionInspectionResponse,
type SessionUsageSnapshot,
} from '../../api/sessions'
import { useTranslation, type TranslationKey } from '../../i18n'
import { useUIStore } from '../../stores/uiStore'
import { SETTINGS_TAB_ID, useTabStore } from '../../stores/tabStore'
import { useMcpStore } from '../../stores/mcpStore'
import { useSkillStore } from '../../stores/skillStore'
import type { McpServerRecord } from '../../types/mcp'
import type { SkillMeta } from '../../types/skill'
import type { SlashCommandOption } from './composerUtils'
export type LocalSlashCommandName = 'mcp' | 'skills' | 'help' | 'status' | 'cost' | 'context'
type Props = {
command: LocalSlashCommandName
sessionId?: string
cwd?: string
commands?: SlashCommandOption[]
onClose: () => void
}
type SessionInspectorTab = 'status' | 'usage' | 'context'
type Translate = ReturnType<typeof useTranslation>
function toneForStatus(status: McpServerRecord['status']) {
switch (status) {
case 'connected':
return 'bg-[var(--color-inspector-success-bg)] text-[var(--color-inspector-success)] border-[var(--color-inspector-border)]'
case 'needs-auth':
return 'bg-[var(--color-surface-container-low)] text-[var(--color-warning)] border-[var(--color-border)]'
case 'failed':
return 'bg-[var(--color-inspector-danger-bg)] text-[var(--color-inspector-danger)] border-[var(--color-inspector-border)]'
case 'disabled':
return 'bg-[var(--color-surface-hover)] text-[var(--color-text-secondary)] border-[var(--color-border)]'
default:
return ''
}
}
function scopeLabel(scope: string, t: ReturnType<typeof useTranslation>) {
switch (scope) {
case 'user':
return t('settings.mcp.scope.user')
case 'local':
return t('settings.mcp.scope.local')
case 'project':
return t('settings.mcp.scope.project')
default:
return scope
}
}
function projectBadge(path?: string, t?: ReturnType<typeof useTranslation>) {
if (!path || !t) return null
const label = path.replace(/\/$/, '').split('/').pop() || path
return t('slash.mcp.projectBadge', { name: label })
}
function PanelShell({
title,
subtitle,
children,
onClose,
}: {
title: string
subtitle: string
children: React.ReactNode
onClose: () => void
}) {
return (
<div className="absolute bottom-full left-0 right-0 z-50 mb-3 overflow-hidden rounded-2xl border border-[var(--color-border)] bg-[var(--color-surface-container-lowest)] shadow-[var(--shadow-dropdown)]">
<div className="flex items-start justify-between gap-4 border-b border-[var(--color-border)] px-5 py-4">
<div>
<h3 className="text-lg font-semibold text-[var(--color-text-primary)]">{title}</h3>
<p className="mt-1 text-sm text-[var(--color-text-tertiary)]">{subtitle}</p>
</div>
<button
type="button"
onClick={onClose}
className="flex h-9 w-9 items-center justify-center rounded-full text-[var(--color-text-secondary)] transition-colors hover:bg-[var(--color-surface-hover)] hover:text-[var(--color-text-primary)]"
>
<span className="material-symbols-outlined text-[18px]">close</span>
</button>
</div>
<div className="max-h-[min(620px,72vh)] overflow-y-auto px-5 py-4">{children}</div>
</div>
)
}
function LoadingState({ label }: { label: string }) {
return (
<div className="flex items-center justify-center py-12 text-sm text-[var(--color-text-tertiary)]">
<div className="mr-3 h-5 w-5 animate-spin rounded-full border-2 border-[var(--color-brand)] border-t-transparent" />
{label}
</div>
)
}
function EmptyState({ title, body }: { title: string; body: string }) {
return (
<div className="rounded-2xl border border-dashed border-[var(--color-border)] bg-[var(--color-surface)] px-5 py-10 text-center">
<div className="text-sm font-semibold text-[var(--color-text-primary)]">{title}</div>
<div className="mt-2 text-xs leading-6 text-[var(--color-text-tertiary)]">{body}</div>
</div>
)
}
function ErrorState({ message }: { message: string }) {
return (
<div className="rounded-2xl border border-[var(--color-inspector-border)] bg-[var(--color-inspector-panel)] px-5 py-4 text-sm text-[var(--color-inspector-danger)]">
{message}
</div>
)
}
function formatNumber(value: number | undefined) {
return new Intl.NumberFormat().format(value ?? 0)
}
function formatDuration(seconds: number | undefined) {
const total = Math.max(0, Math.round(seconds ?? 0))
if (total < 60) return `${total}s`
const minutes = Math.floor(total / 60)
const remaining = total % 60
return remaining ? `${minutes}m ${remaining}s` : `${minutes}m`
}
function formatPercent(value: number | undefined) {
const percent = Math.max(0, Math.min(100, value ?? 0))
return `${percent.toFixed(percent >= 10 || Number.isInteger(percent) ? 0 : 1)}%`
}
function sessionInspectorInitialTab(command: LocalSlashCommandName): SessionInspectorTab {
if (command === 'cost') return 'usage'
if (command === 'context') return 'context'
return 'status'
}
function isRecord(value: unknown): value is Record<string, unknown> {
return Boolean(value && typeof value === 'object')
}
function isSessionInspectionResponse(value: unknown): value is SessionInspectionResponse {
if (!isRecord(value)) return false
if (typeof value.active !== 'boolean') return false
if (!isRecord(value.status)) return false
return (
typeof value.status.sessionId === 'string' &&
typeof value.status.workDir === 'string' &&
typeof value.status.permissionMode === 'string'
)
}
function assertSessionInspectionResponse(value: unknown, t: Translate): SessionInspectionResponse {
if (isSessionInspectionResponse(value)) return value
throw new Error(t('slash.inspector.error.unavailable'))
}
function InspectorSectionTitle({ children, action }: { children: React.ReactNode; action?: React.ReactNode }) {
return (
<div className="mb-3 flex items-center justify-between gap-4">
<div className="font-mono text-[12px] font-semibold uppercase tracking-[0.24em] text-[var(--color-inspector-heading)]">{children}</div>
{action}
</div>
)
}
function MetricCard({ label, value, detail }: { label: string; value: React.ReactNode; detail?: React.ReactNode }) {
return (
<div className="min-h-[82px] rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-panel)] px-4 py-4 font-mono">
<div className="text-[12px] uppercase tracking-[0.2em] text-[var(--color-inspector-heading)]">{label}</div>
<div className="mt-3 whitespace-pre-line text-[15px] leading-6 text-[var(--color-inspector-text)]">{value}</div>
{detail && <div className="mt-1 text-[13px] leading-5 text-[var(--color-inspector-muted)]">{detail}</div>}
</div>
)
}
function InspectorNotice({ children }: { children: React.ReactNode }) {
return (
<div className="flex items-center gap-3 rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-surface)] px-4 py-3 text-[14px] text-[var(--color-inspector-heading)]">
<span className="material-symbols-outlined text-[18px] text-[var(--color-inspector-muted)]">info</span>
<span>{children}</span>
</div>
)
}
function KeyValueRows({ rows }: { rows: Array<[string, React.ReactNode]> }) {
return (
<div className="overflow-hidden rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-surface)] font-mono">
{rows.map(([label, value]) => (
<div key={label} className="grid grid-cols-[220px_minmax(0,1fr)] border-t border-[var(--color-inspector-border)] first:border-t-0">
<div className="border-r border-[var(--color-inspector-border)] bg-[var(--color-inspector-panel)] px-4 py-3 text-[12px] font-semibold uppercase tracking-[0.24em] text-[var(--color-inspector-heading)]">
{label}
</div>
<div className="min-w-0 break-words px-4 py-3 text-[14px] text-[var(--color-inspector-text)]">{value}</div>
</div>
))}
</div>
)
}
function UsageTab({
usage,
context,
error,
t,
}: {
usage?: SessionUsageSnapshot
context?: SessionContextSnapshot
error?: string
t: Translate
}) {
if (error && !usage) return <ErrorState message={error} />
if (!usage) {
return <EmptyState title={t('slash.inspector.usage.emptyTitle')} body={t('slash.inspector.usage.emptyBody')} />
}
const usageHasTokens = (
usage.totalInputTokens +
usage.totalOutputTokens +
usage.totalCacheReadInputTokens +
usage.totalCacheCreationInputTokens
) > 0
const apiUsage = context?.apiUsage
const useContextUsageFallback = !usageHasTokens && !!apiUsage
const totalInputTokens = useContextUsageFallback ? apiUsage.input_tokens : usage.totalInputTokens
const totalOutputTokens = useContextUsageFallback ? apiUsage.output_tokens : usage.totalOutputTokens
const totalCacheReadInputTokens = useContextUsageFallback ? apiUsage.cache_read_input_tokens : usage.totalCacheReadInputTokens
const totalCacheCreationInputTokens = useContextUsageFallback ? apiUsage.cache_creation_input_tokens : usage.totalCacheCreationInputTokens
const models = Array.isArray(usage.models) && usage.models.length > 0
? usage.models
: useContextUsageFallback
? [{
model: context?.model ?? 'current-model',
displayName: context?.model ?? t('slash.inspector.status.activeModel'),
inputTokens: totalInputTokens,
outputTokens: totalOutputTokens,
cacheReadInputTokens: totalCacheReadInputTokens,
cacheCreationInputTokens: totalCacheCreationInputTokens,
webSearchRequests: 0,
costUSD: 0,
costDisplay: 'n/a',
contextWindow: context?.rawMaxTokens ?? 0,
maxOutputTokens: 0,
}]
: []
const sourceLabel = useContextUsageFallback
? t('slash.inspector.usage.source.contextSnapshot')
: usage.source === 'transcript'
? t('slash.inspector.usage.source.transcript')
: t('slash.inspector.usage.source.currentProcess')
return (
<div className="space-y-7">
{useContextUsageFallback && (
<InspectorNotice>
{t('slash.inspector.usage.contextSnapshotNotice')}
</InspectorNotice>
)}
{usage.source === 'transcript' && (
<div className="rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-surface)] px-4 py-3 text-sm text-[var(--color-inspector-muted-strong)]">
{t('slash.inspector.usage.transcriptNotice')}
</div>
)}
{usage.hasUnknownModelCost && (
<div className="rounded-xl border border-[var(--color-inspector-border)] bg-[var(--color-inspector-panel)] px-4 py-3 text-sm text-[var(--color-warning)]">
{t('slash.inspector.usage.unknownCost')}
</div>
)}
<div className="grid grid-cols-2 gap-4 lg:grid-cols-4">
<MetricCard label={t('slash.inspector.usage.totalCost')} value={useContextUsageFallback ? 'n/a' : usage.costDisplay} />
<MetricCard label={t('slash.inspector.usage.source')} value={sourceLabel} />
<MetricCard label={t('slash.inspector.usage.apiDuration')} value={usage.source === 'transcript' || useContextUsageFallback ? '0ms' : formatDuration(usage.totalAPIDuration)} />
<MetricCard label={usage.source === 'transcript' ? t('slash.inspector.usage.usageSpan') : t('slash.inspector.usage.wallDuration')} value={useContextUsageFallback ? '0ms' : formatDuration(usage.totalDuration)} />
<MetricCard
label={t('slash.inspector.usage.codeChanges')}
value={`${formatNumber(usage.totalLinesAdded)}/${formatNumber(usage.totalLinesRemoved)}`}
/>
<MetricCard label={t('slash.inspector.usage.input')} value={formatNumber(totalInputTokens)} />
<MetricCard label={t('slash.inspector.usage.output')} value={formatNumber(totalOutputTokens)} />
<MetricCard label={t('slash.inspector.usage.cacheReadWrite')} value={`${formatNumber(totalCacheReadInputTokens)} / ${formatNumber(totalCacheCreationInputTokens)}`} />
<MetricCard label={t('slash.inspector.usage.webSearch')} value={formatNumber(usage.totalWebSearchRequests)} />
</div>
<section>
<div className="mb-3 text-[22px] font-semibold text-[var(--color-inspector-text)]">{t('slash.inspector.usage.byModel')}</div>
{models.length === 0 ? (
<EmptyState title={t('slash.inspector.usage.noModelTitle')} body={t('slash.inspector.usage.noModelBody')} />
) : (
<div className="overflow-hidden rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-surface)] font-mono">
{models.map((model) => (
<div key={model.model} className="border-t border-[var(--color-inspector-border)] first:border-t-0">
<div className="grid grid-cols-[minmax(0,1fr)_120px] items-center gap-4 border-b border-[var(--color-inspector-border)] px-4 py-3">
<div className="min-w-0">
<div className="truncate text-[13px] font-semibold text-[var(--color-inspector-text)]">{model.displayName || model.model}</div>
{(model.contextWindow > 0 || context?.rawMaxTokens) && (
<div className="mt-1 truncate text-[11px] text-[var(--color-inspector-muted)]">
{t('slash.inspector.status.contextWindow')}: {formatNumber(model.contextWindow || context?.rawMaxTokens)}
</div>
)}
</div>
<div className="text-right text-[12px] font-semibold uppercase tracking-[0.18em] text-[var(--color-inspector-heading)]">{t('slash.inspector.usage.tokens')}</div>
</div>
<div className="grid grid-cols-[160px_minmax(0,1fr)_120px] items-center gap-4 border-b border-[var(--color-inspector-border)] px-4 py-3 last:border-b-0">
<div className="text-[12px] uppercase tracking-[0.18em] text-[var(--color-inspector-heading)]">{t('slash.inspector.usage.input')}</div>
<div className="h-1 overflow-hidden rounded-full bg-[var(--color-inspector-chip)]">
<div className="h-full rounded-full bg-[var(--color-inspector-accent)]" style={{ width: '95%' }} />
</div>
<div className="text-right text-[13px] text-[var(--color-inspector-text)]">{formatNumber(model.inputTokens)}</div>
</div>
<div className="grid grid-cols-[160px_minmax(0,1fr)_120px] items-center gap-4 px-4 py-3">
<div className="text-[12px] uppercase tracking-[0.18em] text-[var(--color-inspector-heading)]">{t('slash.inspector.usage.output')}</div>
<div className="h-1 overflow-hidden rounded-full bg-[var(--color-inspector-chip)]">
<div className="h-full rounded-full bg-[var(--color-inspector-accent-secondary)]" style={{ width: `${Math.max(4, Math.min(100, (model.outputTokens / Math.max(1, model.inputTokens)) * 100))}%` }} />
</div>
<div className="text-right text-[13px] text-[var(--color-inspector-text)]">{formatNumber(model.outputTokens)}</div>
</div>
</div>
))}
</div>
)}
</section>
</div>
)
}
type ContextCategory = SessionContextSnapshot['categories'][number]
type ContextMemoryFile = SessionContextSnapshot['memoryFiles'][number]
function isCapacityCategory(category: ContextCategory) {
const name = category.name.toLowerCase()
return category.isDeferred || name.includes('free') || name.includes('autocompact')
}
function ContextStackedBar({ categories, rawMaxTokens }: { categories: ContextCategory[]; rawMaxTokens: number }) {
const activeCategories = categories.filter((category) => !isCapacityCategory(category) && category.tokens > 0)
if (activeCategories.length === 0) return null
return (
<div className="overflow-hidden rounded-full bg-[var(--color-inspector-chip)]">
<div className="flex h-2.5 w-full">
{activeCategories.map((category) => (
<div
key={category.name}
title={`${category.name}: ${formatNumber(category.tokens)} tokens`}
style={{
width: `${Math.max(0.5, (category.tokens / rawMaxTokens) * 100)}%`,
backgroundColor: category.color,
}}
/>
))}
</div>
</div>
)
}
function CategoryBreakdown({ categories, rawMaxTokens, t }: { categories: ContextCategory[]; rawMaxTokens: number; t: Translate }) {
const visibleCategories = categories.filter((category) => category.tokens > 0)
if (visibleCategories.length === 0) {
return <EmptyState title={t('slash.inspector.context.noCategoriesTitle')} body={t('slash.inspector.context.noCategoriesBody')} />
}
return (
<div className="rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-panel)] px-5 py-5 font-mono">
<InspectorSectionTitle>{t('slash.inspector.context.categoryTitle')}</InspectorSectionTitle>
<div className="grid gap-x-10 gap-y-5 sm:grid-cols-2">
{visibleCategories.map((category) => {
const percent = rawMaxTokens > 0 ? (category.tokens / rawMaxTokens) * 100 : 0
const muted = isCapacityCategory(category)
return (
<div
key={category.name}
className="min-w-0"
>
<div className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-3">
<div className="flex min-w-0 items-center gap-2">
<span className={`min-w-0 truncate text-[14px] font-semibold ${muted ? 'text-[var(--color-inspector-muted-strong)]' : 'text-[var(--color-inspector-text)]'}`}>
{category.name}
</span>
</div>
<div className="shrink-0 text-right leading-tight">
<div className="text-sm text-[var(--color-inspector-text)]">{formatNumber(category.tokens)}</div>
<div className="mt-0.5 text-[12px] text-[var(--color-inspector-muted)]">{formatPercent(percent)}</div>
</div>
</div>
<div className="mt-2 h-1 overflow-hidden rounded-full bg-[var(--color-inspector-chip)]">
<div
className={muted ? 'h-full rounded-full opacity-65' : 'h-full rounded-full'}
style={{
width: `${Math.min(100, Math.max(0.5, percent))}%`,
backgroundColor: muted ? 'var(--color-inspector-capacity)' : 'var(--color-inspector-accent)',
}}
/>
</div>
</div>
)
})}
</div>
</div>
)
}
function memoryContextFileLabel(path: string) {
const normalized = path.replace(/\\/g, '/')
return normalized.split('/').pop() || normalized
}
function MemoryFilesBreakdown({ files, t }: { files: ContextMemoryFile[]; t: Translate }) {
const setPendingSettingsTab = useUIStore((state) => state.setPendingSettingsTab)
const setPendingMemoryPath = useUIStore((state) => state.setPendingMemoryPath)
const openSettings = (path?: string) => {
if (path) setPendingMemoryPath(path)
setPendingSettingsTab('memory')
useTabStore.getState().openTab(SETTINGS_TAB_ID, 'Settings', 'settings')
}
if (files.length === 0) {
return (
<div className="rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-panel)] px-5 py-5">
<div className="flex items-center justify-between gap-3">
<InspectorSectionTitle>{t('slash.inspector.context.memoryFiles')}</InspectorSectionTitle>
<button
type="button"
onClick={() => openSettings()}
className="rounded-sm border border-[var(--color-inspector-border)] bg-[var(--color-inspector-chip)] px-2.5 py-1 text-xs font-semibold text-[var(--color-inspector-muted-strong)] hover:text-[var(--color-inspector-text)]"
>
{t('slash.inspector.context.openMemory')}
</button>
</div>
<div className="mt-4 text-sm text-[var(--color-inspector-muted)]">{t('slash.inspector.context.noMemoryFiles')}</div>
</div>
)
}
return (
<div className="rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-panel)] px-5 py-5">
<div className="flex items-center justify-between gap-3">
<InspectorSectionTitle>{t('slash.inspector.context.memoryFiles')}</InspectorSectionTitle>
<button
type="button"
onClick={() => openSettings(files[0]?.path)}
className="rounded-sm border border-[var(--color-inspector-border)] bg-[var(--color-inspector-chip)] px-2.5 py-1 text-xs font-semibold text-[var(--color-inspector-muted-strong)] hover:text-[var(--color-inspector-text)]"
>
{t('slash.inspector.context.openMemory')}
</button>
</div>
<div className="mt-4 grid gap-2">
{files.map((file) => (
<div
key={`${file.type}:${file.path}`}
className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-3 rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-surface)] px-3 py-2"
>
<div className="min-w-0">
<div className="truncate font-mono text-sm font-semibold text-[var(--color-inspector-text)]" title={file.path}>
{memoryContextFileLabel(file.path)}
</div>
<div className="mt-0.5 truncate font-mono text-[11px] text-[var(--color-inspector-muted)]" title={file.path}>
{file.path}
</div>
</div>
<div className="shrink-0 text-right font-mono">
<div className="text-xs font-semibold uppercase tracking-[0.12em] text-[var(--color-inspector-muted-strong)]">{file.type}</div>
<div className="mt-0.5 text-[11px] text-[var(--color-inspector-muted)]">{formatNumber(file.tokens)} tokens</div>
</div>
</div>
))}
</div>
</div>
)
}
function ContextStatPill({ label, value, detail }: { label: string; value: string; detail?: string }) {
return (
<div className="min-w-0 font-mono">
<div className="truncate text-[12px] font-semibold uppercase tracking-[0.22em] text-[var(--color-inspector-muted)]">{label}</div>
<div className="mt-2 truncate text-[16px] font-semibold text-[var(--color-inspector-text)]">{value}</div>
{detail && <div className="mt-1 truncate text-[13px] text-[var(--color-inspector-muted)]">{detail}</div>}
</div>
)
}
function statusDisplayLabel(status: string, t: Translate) {
const normalized = status.toLowerCase()
if (normalized === 'connected') return t('slash.inspector.status.connected')
if (normalized === 'failed') return t('slash.inspector.status.failed')
return status
}
function InspectorStatusBadge({ status, t }: { status: string; t: Translate }) {
const normalized = status.toLowerCase()
const isConnected = normalized === 'connected'
const isFailed = normalized === 'failed'
const badgeClass = isConnected
? 'bg-[var(--color-inspector-success-bg)] text-[var(--color-inspector-success)]'
: isFailed
? 'bg-[var(--color-inspector-danger-bg)] text-[var(--color-inspector-danger)]'
: 'bg-[var(--color-inspector-chip)] text-[var(--color-inspector-muted-strong)]'
const dotClass = isConnected ? 'bg-[var(--color-inspector-success)]' : isFailed ? 'bg-[var(--color-inspector-danger)]' : 'bg-[var(--color-inspector-muted)]'
return (
<span className={`inline-flex items-center gap-1.5 rounded-sm px-2.5 py-1 font-mono text-[10px] font-semibold uppercase tracking-[0.08em] ${badgeClass}`}>
<span className={`h-1.5 w-1.5 rounded-full ${dotClass}`} />
{statusDisplayLabel(status, t)}
</span>
)
}
function McpServerIcon({ status }: { status: string }) {
const isFailed = status === 'failed'
const icon = isFailed ? 'power_off' : 'dns'
return (
<span className={`material-symbols-outlined text-[20px] ${isFailed ? 'text-[var(--color-inspector-danger)]' : 'text-[var(--color-inspector-success)]'}`}>
{icon}
</span>
)
}
function ContextOverview({ context, categories, t }: { context: SessionContextSnapshot; categories: ContextCategory[]; t: Translate }) {
const usedPercent = Math.min(100, Math.max(0, context.percentage))
const freeTokens = Math.max(0, context.rawMaxTokens - context.totalTokens)
const freePercent = context.rawMaxTokens > 0 ? (freeTokens / context.rawMaxTokens) * 100 : 0
return (
<div className="rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-panel)] px-5 py-6">
<div className="mb-8 flex items-start justify-between gap-4">
<InspectorSectionTitle>{t('slash.inspector.context.windowUsage')}</InspectorSectionTitle>
<span className="rounded-sm border border-[var(--color-inspector-border)] bg-[var(--color-inspector-chip)] px-2 py-1 font-mono text-xs text-[var(--color-inspector-muted-strong)]">{context.model}</span>
</div>
<div className="font-mono text-[24px] font-semibold text-[var(--color-inspector-text)]">
{formatNumber(context.totalTokens)}
<span className="mx-1.5 text-[var(--color-inspector-text)]">/</span>
<span>{formatNumber(context.rawMaxTokens)}</span>
<span className="ml-3 align-middle text-sm font-normal text-[var(--color-inspector-accent-secondary)]">[{formatPercent(usedPercent)} {t('slash.inspector.context.used')}]</span>
</div>
<div className="mt-7">
<ContextStackedBar categories={categories} rawMaxTokens={context.rawMaxTokens} />
</div>
<div className="mt-8 grid grid-cols-2 gap-3 lg:grid-cols-4">
<div className="rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-surface)] px-4 py-3">
<ContextStatPill label={t('slash.inspector.context.free')} value={formatNumber(freeTokens)} detail={formatPercent(freePercent)} />
</div>
<div className="rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-surface)] px-4 py-3">
<ContextStatPill label={t('slash.inspector.context.messages')} value={formatNumber(context.messageBreakdown?.assistantMessageTokens ?? 0)} detail={t('slash.inspector.context.assistant')} />
</div>
<div className="rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-surface)] px-4 py-3">
<ContextStatPill label={t('slash.inspector.context.toolResults')} value={formatNumber(context.messageBreakdown?.toolResultTokens ?? 0)} />
</div>
<div className="rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-surface)] px-4 py-3">
<ContextStatPill label={t('slash.inspector.context.context')} value={formatPercent(usedPercent)} />
</div>
</div>
</div>
)
}
function ContextTab({
context,
error,
loading,
t,
}: {
context?: SessionContextSnapshot
error?: string
loading?: boolean
t: Translate
}) {
if (error && !context) return <ErrorState message={error} />
if (loading && !context) return <LoadingState label={t('slash.inspector.context.loading')} />
if (!context) {
return <EmptyState title={t('slash.inspector.context.emptyTitle')} body={t('slash.inspector.context.emptyBody')} />
}
const categories = Array.isArray(context.categories) ? context.categories : []
return (
<div className="space-y-6">
<ContextOverview context={context} categories={categories} t={t} />
<MemoryFilesBreakdown files={Array.isArray(context.memoryFiles) ? context.memoryFiles : []} t={t} />
<CategoryBreakdown categories={categories} rawMaxTokens={context.rawMaxTokens} t={t} />
</div>
)
}
function StatusTab({
data,
commands,
t,
}: {
data: SessionInspectionResponse
commands?: SlashCommandOption[]
t: Translate
}) {
const mcpServers = Array.isArray(data.status.mcpServers) ? data.status.mcpServers : []
const tools = Array.isArray(data.status.tools) ? data.status.tools : []
const context = data.context ?? data.contextEstimate
const model = data.status.model ?? context?.model ?? data.usage?.models?.[0]?.displayName ?? data.usage?.models?.[0]?.model ?? t('slash.inspector.status.unknown')
const contextWindow = context?.rawMaxTokens ?? data.usage?.models?.find((entry) => entry.contextWindow > 0)?.contextWindow
const slashCommandCount = (data.status.slashCommandCount ?? 0) > 0
? data.status.slashCommandCount
: commands?.length ?? 0
const connectedMcp = mcpServers.filter((server) => server.status === 'connected').length
const failedMcp = mcpServers.filter((server) => server.status === 'failed').length
return (
<div className="space-y-8">
<div className="grid grid-cols-2 gap-4 lg:grid-cols-4">
<MetricCard
label={t('slash.inspector.status.cliStatus')}
value={(
<span className="inline-flex items-center gap-2">
<span className={`h-2 w-2 rounded-full ${data.active ? 'bg-[var(--color-inspector-success)]' : 'bg-[var(--color-inspector-danger)]'}`} />
{data.active ? t('slash.inspector.status.running') : t('slash.inspector.status.notRunning')}
</span>
)}
/>
<MetricCard
label={t('slash.inspector.status.activeModel')}
value={model}
detail={contextWindow ? `${t('slash.inspector.status.contextWindow')}: ${formatNumber(contextWindow)}` : undefined}
/>
<MetricCard
label={t('slash.inspector.status.mcpConnections')}
value={(
<span>
<span className="text-[var(--color-inspector-success)]">{formatNumber(connectedMcp)}</span>
<span className="mx-5 text-[var(--color-inspector-text)]">/</span>
<span className="text-[var(--color-inspector-danger)]">{formatNumber(failedMcp)}</span>
</span>
)}
detail={(
<span>
<span className="text-[var(--color-inspector-success)]">{t('slash.inspector.status.connected')}</span>
<span className="mx-5 text-[var(--color-inspector-text)]" />
<span className="text-[var(--color-inspector-danger)]">{t('slash.inspector.status.failed')}</span>
</span>
)}
/>
<MetricCard label={t('slash.inspector.status.registeredTools')} value={`${formatNumber(tools.length)} / ${formatNumber(slashCommandCount)} ${t('slash.inspector.status.commands')}`} />
</div>
<section>
<InspectorSectionTitle>{t('slash.inspector.status.sessionMetadata')}</InspectorSectionTitle>
<KeyValueRows
rows={[
[t('slash.inspector.status.version'), data.status.version ?? t('slash.inspector.status.unknown')],
[t('slash.inspector.status.sessionId'), <span className="font-mono text-[13px]">{data.status.sessionId}</span>],
[t('slash.inspector.status.workingDirectory'), <span className="font-mono text-[13px]">{data.status.cwd ?? data.status.workDir}</span>],
[t('slash.inspector.status.permissionMode'), <span className="rounded-sm bg-[var(--color-inspector-chip)] px-1.5 py-1">{data.status.permissionMode}</span>],
[t('slash.inspector.status.authToken'), data.status.apiKeySource ?? t('slash.inspector.status.unknown')],
[t('slash.inspector.status.outputStyle'), data.status.outputStyle ?? t('slash.inspector.status.default')],
]}
/>
</section>
{mcpServers.length > 0 && (
<section>
<InspectorSectionTitle
action={<button type="button" className="font-mono text-[12px] tracking-[0.18em] text-[var(--color-inspector-accent)] hover:text-[var(--color-inspector-accent-hover)]">↻ {t('slash.inspector.status.refresh')}</button>}
>
{t('slash.inspector.status.mcpServers')}
</InspectorSectionTitle>
<div className="grid gap-3 lg:grid-cols-2">
{mcpServers.map((server) => (
<div
key={`${server.name}:${server.status}`}
className="flex min-h-[48px] items-center justify-between gap-4 rounded-md border border-[var(--color-inspector-border)] bg-[var(--color-inspector-panel)] px-4 py-3 font-mono"
>
<div className="flex min-w-0 items-center gap-3">
<McpServerIcon status={server.status} />
<span className="min-w-0 truncate text-[14px] text-[var(--color-inspector-text)]">{server.name}</span>
</div>
<InspectorStatusBadge status={server.status} t={t} />
</div>
))}
</div>
</section>
)}
</div>
)
}
function SessionInspectorShell({
selectedTab,
tabs,
onSelectTab,
onClose,
children,
t,
}: {
selectedTab: SessionInspectorTab
tabs: Array<{ id: SessionInspectorTab; label: string }>
onSelectTab: (tab: SessionInspectorTab) => void
onClose: () => void
children: React.ReactNode
t: Translate
}) {
return (
<div
className="absolute bottom-full left-0 right-0 z-50 mb-4 overflow-hidden rounded-[10px] border border-[var(--color-inspector-border)] bg-[var(--color-inspector-surface)] text-[var(--color-inspector-text)] shadow-[var(--shadow-inspector)]"
>
<div className="grid min-h-[64px] grid-cols-[1fr_auto_1fr] items-center border-b border-[var(--color-inspector-border)] bg-[var(--color-inspector-surface)] px-6">
<div className="font-mono text-[16px] font-semibold uppercase text-[var(--color-inspector-accent)]">{t('slash.inspector.title')}</div>
<div className="flex items-center gap-8">
{tabs.map((tab) => (
<button
key={tab.id}
type="button"
onClick={() => onSelectTab(tab.id)}
className={`relative h-10 px-0 font-sans text-sm transition-colors ${
selectedTab === tab.id ? 'text-[var(--color-inspector-accent)]' : 'text-[var(--color-inspector-muted-strong)] hover:text-[var(--color-inspector-accent)]'
}`}
>
{tab.label}
{selectedTab === tab.id && <span className="absolute bottom-1 left-0 right-0 h-[2px] bg-[var(--color-inspector-accent)]" />}
</button>
))}
</div>
<div className="flex justify-end">
<button
type="button"
onClick={onClose}
aria-label={t('slash.inspector.close')}
className="flex h-10 w-10 items-center justify-center text-[var(--color-inspector-accent)] transition-colors hover:text-[var(--color-inspector-accent-hover)]"
>
<span className="material-symbols-outlined text-[24px]">close</span>
</button>
</div>
</div>
<div className="max-h-[min(540px,58vh)] overflow-y-auto bg-[var(--color-inspector-surface)] px-6 py-6">{children}</div>
</div>
)
}
function SessionInspectorPanel({
command,
sessionId,
commands,
onClose,
}: {
command: LocalSlashCommandName
sessionId?: string
commands?: SlashCommandOption[]
onClose: () => void
}) {
const t = useTranslation()
const [selectedTab, setSelectedTab] = useState<SessionInspectorTab>(() => sessionInspectorInitialTab(command))
const [data, setData] = useState<SessionInspectionResponse | null>(null)
const [error, setError] = useState<string | null>(null)
const [contextLoading, setContextLoading] = useState(false)
const [contextError, setContextError] = useState<string | null>(null)
const contextRequestSessionRef = useRef<string | null>(null)
useEffect(() => {
if (command !== 'status' && command !== 'cost' && command !== 'context') return
setSelectedTab(sessionInspectorInitialTab(command))
}, [command])
useEffect(() => {
if (!sessionId) {
setError(t('slash.inspector.error.noActiveSession'))
return
}
let cancelled = false
setData(null)
setError(null)
setContextLoading(false)
setContextError(null)
contextRequestSessionRef.current = null
sessionsApi.getInspection(sessionId, { includeContext: false })
.then((response) => {
if (!cancelled) setData(assertSessionInspectionResponse(response, t))
})
.catch((err) => {
if (!cancelled) setError(err instanceof Error ? err.message : String(err))
})
return () => {
cancelled = true
}
}, [sessionId, t])
useEffect(() => {
if (!sessionId || selectedTab !== 'context' || data === null || data.context) return
if (contextRequestSessionRef.current === sessionId) return
contextRequestSessionRef.current = sessionId
let cancelled = false
setContextLoading(true)
setContextError(null)
sessionsApi.getInspection(sessionId, { includeContext: true, contextOnly: true, timeout: 45_000 })
.then((response) => {
if (cancelled) return
const inspected = assertSessionInspectionResponse(response, t)
setData((current) => current
? {
...current,
context: inspected.context,
errors: {
...(current.errors ?? {}),
...(inspected.errors ?? {}),
},
}
: inspected)
setContextError(inspected.errors?.context ?? null)
})
.catch((err) => {
if (!cancelled) setContextError(err instanceof Error ? err.message : String(err))
})
.finally(() => {
if (!cancelled) setContextLoading(false)
})
return () => {
cancelled = true
}
}, [data, selectedTab, sessionId, t])
const tabs: Array<{ id: SessionInspectorTab; label: string }> = [
{ id: 'status', label: t('slash.inspector.tab.status') },
{ id: 'usage', label: t('slash.inspector.tab.usage') },
{ id: 'context', label: t('slash.inspector.tab.context') },
]
return (
<SessionInspectorShell selectedTab={selectedTab} tabs={tabs} onSelectTab={setSelectedTab} onClose={onClose} t={t}>
{error ? (
<ErrorState message={error} />
) : data === null ? (
<LoadingState label={t('slash.inspector.loading')} />
) : selectedTab === 'usage' ? (
<UsageTab usage={data.usage} context={data.context ?? data.contextEstimate} error={data.errors?.usage} t={t} />
) : selectedTab === 'context' ? (
<ContextTab
context={data.context ?? data.contextEstimate}
error={contextError ?? data.errors?.context}
loading={contextLoading && !data.contextEstimate}
t={t}
/>
) : (
<StatusTab data={data} commands={commands} t={t} />
)}
</SessionInspectorShell>
)
}
function McpPanel({ cwd, onClose }: { cwd?: string; onClose: () => void }) {
const t = useTranslation()
const setPendingSettingsTab = useUIStore((s) => s.setPendingSettingsTab)
const selectServer = useMcpStore((s) => s.selectServer)
const [servers, setServers] = useState<McpServerRecord[] | null>(null)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
let cancelled = false
mcpApi.list(cwd)
.then(async (response) => {
if (cancelled) return
const visibleServers = response.servers.filter((server) => server.scope === 'user' || server.scope === 'local' || server.scope === 'project')
setServers(visibleServers)
const statusResults = await Promise.allSettled(
visibleServers.map((server) => mcpApi.status(server.name, cwd)),
)
if (cancelled) return
const liveServers = new Map<string, McpServerRecord>()
for (const result of statusResults) {
if (result.status === 'fulfilled') {
liveServers.set(result.value.server.name, result.value.server)
}
}
if (liveServers.size > 0) {
setServers((current) =>
current?.map((server) => liveServers.get(server.name) ?? server) ?? current,
)
}
})
.catch((err) => {
if (cancelled) return
setError(err instanceof Error ? err.message : String(err))
})
return () => {
cancelled = true
}
}, [cwd])
const grouped = useMemo(() => {
const groups = new Map<string, McpServerRecord[]>()
for (const server of servers ?? []) {
const key = server.scope
const existing = groups.get(key) ?? []
existing.push(server)
groups.set(key, existing)
}
return groups
}, [servers])
return (
<PanelShell
title={t('slash.mcp.title')}
subtitle={cwd ? t('slash.mcp.subtitleWithProject', { path: cwd }) : t('slash.mcp.subtitle')}
onClose={onClose}
>
{error ? (
<ErrorState message={error} />
) : servers === null ? (
<LoadingState label={t('common.loading')} />
) : servers.length === 0 ? (
<EmptyState title={t('slash.mcp.emptyTitle')} body={t('slash.mcp.emptyBody')} />
) : (
<div className="space-y-5">
{['user', 'local', 'project'].filter((scope) => grouped.has(scope)).map((scope) => (
<section key={scope}>
<div className="mb-2 flex items-center justify-between">
<div className="text-sm font-semibold text-[var(--color-text-primary)]">{scopeLabel(scope, t)}</div>
<div className="text-xs text-[var(--color-text-tertiary)]">{grouped.get(scope)?.length ?? 0}</div>
</div>
<div className="overflow-hidden rounded-2xl border border-[var(--color-border)] bg-[var(--color-surface)]">
{grouped.get(scope)?.map((server) => (
<button
type="button"
key={`${server.scope}:${server.projectPath ?? 'global'}:${server.name}`}
onClick={() => {
selectServer(server)
setPendingSettingsTab('mcp')
useTabStore.getState().openTab(SETTINGS_TAB_ID, 'Settings', 'settings')
onClose()
}}
className="block w-full border-t border-[var(--color-border)] px-4 py-4 text-left first:border-t-0 hover:bg-[var(--color-surface-hover)]"
>
<div className="flex items-center gap-3">
<div className="text-sm font-semibold text-[var(--color-text-primary)]">{server.name}</div>
<span className={`inline-flex items-center rounded-full border px-2 py-1 text-[11px] font-semibold ${toneForStatus(server.status)}`}>
{server.statusLabel}
</span>
</div>
<div className="mt-2 flex flex-wrap items-center gap-2 text-xs text-[var(--color-text-tertiary)]">
<span className="rounded-full bg-[var(--color-surface-hover)] px-2 py-1">{server.transport}</span>
{server.projectPath && (
<span className="rounded-full bg-[var(--color-surface-hover)] px-2 py-1" title={server.projectPath}>
{projectBadge(server.projectPath, t)}
</span>
)}
<span className="truncate">{server.summary}</span>
</div>
</button>
))}
</div>
</section>
))}
</div>
)}
</PanelShell>
)
}
function SkillsPanel({ cwd, onClose }: { cwd?: string; onClose: () => void }) {
const t = useTranslation()
const setPendingSettingsTab = useUIStore((s) => s.setPendingSettingsTab)
const fetchSkillDetail = useSkillStore((s) => s.fetchSkillDetail)
const [skills, setSkills] = useState<SkillMeta[] | null>(null)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
let cancelled = false
skillsApi.list(cwd)
.then((response) => {
if (cancelled) return
setSkills(response.skills.filter((skill) => skill.userInvocable))
})
.catch((err) => {
if (cancelled) return
setError(err instanceof Error ? err.message : String(err))
})
return () => {
cancelled = true
}
}, [cwd])
return (
<PanelShell
title={t('slash.skills.title')}
subtitle={cwd ? t('slash.skills.subtitleWithProject', { path: cwd }) : t('slash.skills.subtitle')}
onClose={onClose}
>
{error ? (
<ErrorState message={error} />
) : skills === null ? (
<LoadingState label={t('common.loading')} />
) : skills.length === 0 ? (
<EmptyState title={t('slash.skills.emptyTitle')} body={t('slash.skills.emptyBody')} />
) : (
<div className="overflow-hidden rounded-2xl border border-[var(--color-border)] bg-[var(--color-surface)]">
{skills.map((skill) => (
<button
type="button"
key={`${skill.source}:${skill.name}`}
onClick={async () => {
await fetchSkillDetail(skill.source, skill.name, cwd, 'skills')
setPendingSettingsTab('skills')
useTabStore.getState().openTab(SETTINGS_TAB_ID, 'Settings', 'settings')
onClose()
}}
className="block w-full border-t border-[var(--color-border)] px-4 py-4 text-left first:border-t-0 hover:bg-[var(--color-surface-hover)]"
>
<div className="flex items-center gap-3">
<div className="text-sm font-semibold text-[var(--color-text-primary)]">/{skill.name}</div>
<span className="rounded-full bg-[var(--color-surface-hover)] px-2 py-1 text-[11px] text-[var(--color-text-secondary)]">
{skill.source}
</span>
</div>
<div className="mt-2 text-xs leading-6 text-[var(--color-text-tertiary)]">{skill.description}</div>
</button>
))}
</div>
)}
</PanelShell>
)
}
const COMMAND_GROUPS = [
{
titleKey: 'slash.help.group.context',
names: ['clear', 'compact', 'context', 'cost'],
},
{
titleKey: 'slash.help.group.project',
names: ['init', 'review', 'commit', 'pr'],
},
{
titleKey: 'slash.help.group.desktop',
names: ['mcp', 'skills', 'plugin', 'help'],
},
] satisfies Array<{ titleKey: TranslationKey; names: string[] }>
function HelpPanel({
commands,
onClose,
}: {
commands?: SlashCommandOption[]
onClose: () => void
}) {
const t = useTranslation()
const commandMap = useMemo(() => {
const map = new Map<string, SlashCommandOption>()
for (const command of commands ?? []) {
map.set(command.name, command)
}
return map
}, [commands])
const groupedNames = new Set(COMMAND_GROUPS.flatMap((group) => group.names))
const otherCommands = (commands ?? [])
.filter((command) => !groupedNames.has(command.name))
.slice(0, 12)
const hiddenOtherCommandCount = Math.max(
0,
(commands ?? []).filter((command) => !groupedNames.has(command.name)).length - otherCommands.length,
)
const renderCommand = (command: SlashCommandOption) => (
<div key={command.name} className="flex min-w-0 items-start gap-3 border-t border-[var(--color-border)] px-4 py-3 first:border-t-0">
<div className="flex min-w-[120px] max-w-[45%] shrink-0 flex-wrap items-baseline gap-x-1.5 font-mono">
<span className="text-sm font-semibold text-[var(--color-text-primary)]">/{command.name}</span>
{command.argumentHint ? (
<span className="text-[11px] leading-5 text-[var(--color-text-tertiary)]">{command.argumentHint}</span>
) : null}
</div>
<div className="min-w-0 flex-1 text-xs leading-5 text-[var(--color-text-tertiary)]">{command.description}</div>
</div>
)
return (
<PanelShell
title={t('slash.help.title')}
subtitle={t('slash.help.subtitle')}
onClose={onClose}
>
<div className="space-y-4">
{COMMAND_GROUPS.map((group) => {
const entries = group.names
.map((name) => commandMap.get(name))
.filter((command): command is SlashCommandOption => Boolean(command))
if (entries.length === 0) return null
return (
<section key={group.titleKey}>
<div className="mb-2 text-sm font-semibold text-[var(--color-text-primary)]">{t(group.titleKey)}</div>
<div className="overflow-hidden rounded-2xl border border-[var(--color-border)] bg-[var(--color-surface)]">
{entries.map(renderCommand)}
</div>
</section>
)
})}
{otherCommands.length > 0 && (
<section>
<div className="mb-2 text-sm font-semibold text-[var(--color-text-primary)]">{t('slash.help.group.more')}</div>
<div className="overflow-hidden rounded-2xl border border-[var(--color-border)] bg-[var(--color-surface)]">
{otherCommands.map(renderCommand)}
</div>
{hiddenOtherCommandCount > 0 && (
<p className="mt-2 text-xs leading-5 text-[var(--color-text-tertiary)]">
{t('slash.help.moreAvailable', { count: hiddenOtherCommandCount })}
</p>
)}
</section>
)}
</div>
</PanelShell>
)
}
export function LocalSlashCommandPanel({ command, sessionId, cwd, commands, onClose }: Props) {
if (command === 'mcp') return <McpPanel cwd={cwd} onClose={onClose} />
if (command === 'skills') return <SkillsPanel cwd={cwd} onClose={onClose} />
if (command === 'status' || command === 'cost' || command === 'context') {
return <SessionInspectorPanel command={command} sessionId={sessionId} commands={commands} onClose={onClose} />
}
return <HelpPanel commands={commands} onClose={onClose} />
}
|