Skip to content

buidangminh23/design-pro-max / skills/apple/.vendor/swiftui-expert-skill

swiftui-expert-skill

Verified

Use when writing, reviewing, or refactoring SwiftUI code for iOS or macOS, including state and `@Observable` data flow, view composition, resizable layouts, safe areas, display scale, performance, lists, environment, localization, animation, Liquid Glass, and API migration. Also use for iPhone Duo, foldable, or large-display layouts (`NavigationSplitView` on large displays, iPhone tab sidebar, two-column reflow, foldable grids, `ArrangementView`, `ReservedRegion`), hinge effects, vertical bars, `@State` initialization or synthesized-property diagnostics, `@ContentBuilder` ambiguity, `reorderable` drag/drop, custom `AsyncImage` `URLSession`, swipe actions outside List, item-bound `alert`/`confirmationDialog`, `ToolbarOverflowMenu`, `AnimatableValues`, Document APIs (`Document`/`DocumentReader`), and Instruments `.trace` capture or analysis.

FileKindSize
LICENSEother1.1 KB
SKILL.mdskill md11.4 KB
UPSTREAM.jsonconfig12.1 KB
references/accessibility-patterns.mdmarkdown5.9 KB
references/animation-advanced.mdmarkdown11.2 KB
references/animation-basics.mdmarkdown6.7 KB
references/animation-transitions.mdmarkdown7.9 KB
references/charts-accessibility.mdmarkdown6.1 KB
references/charts.mdmarkdown16.8 KB
references/document-apps.mdmarkdown11.1 KB
references/environment-patterns.mdmarkdown7.1 KB
references/focus-patterns.mdmarkdown8.7 KB
references/image-optimization.mdmarkdown10.4 KB
references/iphone-duo.mdmarkdown7.4 KB
references/latest-apis.mdmarkdown24.8 KB
references/layout-best-practices.mdmarkdown20.6 KB
references/liquid-glass.mdmarkdown12.4 KB
references/list-patterns.mdmarkdown20.5 KB
references/localization.mdmarkdown9.7 KB
references/macos-scenes.mdmarkdown9.5 KB
references/macos-views.mdmarkdown10.8 KB
references/macos-window-styling.mdmarkdown8.6 KB
references/modifier-patterns.mdmarkdown2.5 KB
references/performance-patterns.mdmarkdown11.7 KB
references/previews.mdmarkdown8.1 KB
references/scroll-patterns.mdmarkdown10.6 KB
references/sheet-navigation-patterns.mdmarkdown15.0 KB
references/soft-deprecation.mdmarkdown2.9 KB
references/state-management.mdmarkdown21.5 KB
references/styled-text-editing.mdmarkdown8.7 KB
references/text-patterns.mdmarkdown1.6 KB
references/toolbar-patterns.mdmarkdown9.9 KB
references/trace-analysis.mdmarkdown14.1 KB
references/trace-recording.mdmarkdown5.8 KB
references/view-structure.mdmarkdown28.3 KB
references/webkit-integration.mdmarkdown9.5 KB
scripts/analyze_trace.pyscript9.9 KB
scripts/instruments_parser/__init__.pyscript69 B
scripts/instruments_parser/causes.pyscript5.9 KB
scripts/instruments_parser/correlate.pyscript6.2 KB
scripts/instruments_parser/events.pyscript10.6 KB
scripts/instruments_parser/hangs.pyscript3.4 KB
scripts/instruments_parser/hitches.pyscript4.5 KB
scripts/instruments_parser/summary.pyscript9.1 KB
scripts/instruments_parser/swiftui.pyscript6.6 KB
scripts/instruments_parser/time_profiler.pyscript4.3 KB
scripts/instruments_parser/xctrace.pyscript3.5 KB
scripts/instruments_parser/xml_utils.pyscript7.4 KB
scripts/record_trace.pyscript10.6 KB

scripts/instruments_parser/hangs.py

View on GitHub
"""Hangs lane parser (schema `potential-hangs`).

The schema lacks inline backtraces — stacks come from Time Profiler samples
that overlap each hang's window. Correlation is done later in correlate.py.
"""
from __future__ import annotations

from pathlib import Path
from typing import Any

from . import xctrace, xml_utils

PREFERRED_SCHEMAS = ("potential-hangs",)
FALLBACK_SCHEMAS = ("main-thread-hang", "hang", "hangs")


def analyze(
    trace_path: Path,
    toc_schemas: frozenset[str],
    top_n: int = 10,
    window: tuple[int, int] | None = None,
    run: int = 1,
) -> dict[str, Any]:
    schema = _pick_schema(toc_schemas)
    if schema is None:
        return {
            "lane": "hangs",
            "available": False,
            "notes": ["Hangs data not present in trace."],
        }

    xml_bytes = xctrace.export_schema(trace_path, schema, run=run)
    stream = xml_utils.RowStream(xml_bytes)

    hangs: list[dict] = []
    for row in stream:
        start_el = row.get("start")
        dur_el = row.get("duration")
        type_el = row.get("hang-type")
        thread_el = row.get("thread")
        if start_el is None or dur_el is None:
            continue
        start_ns = xml_utils.int_text(stream.resolve(start_el))
        duration_ns = xml_utils.int_text(stream.resolve(dur_el))
        if start_ns is None or duration_ns is None:
            continue
        if not xml_utils.event_overlaps_window(start_ns, start_ns + duration_ns, window):
            continue
        hang_type = xml_utils.str_text(stream.resolve(type_el)) if type_el is not None else None
        thread = xml_utils.extract_thread(thread_el, stream) if thread_el is not None else None

        hangs.append({
            "start_ns": start_ns,
            "duration_ns": duration_ns,
            "end_ns": start_ns + duration_ns,
            "duration_ms": round(duration_ns / 1_000_000, 2),
            "start_ms": round(start_ns / 1_000_000, 2),
            "hang_type": hang_type or "Hang",
            "thread": thread,
        })

    hangs.sort(key=lambda h: h["duration_ns"], reverse=True)

    total_ms = sum(h["duration_ms"] for h in hangs)
    worst = hangs[0] if hangs else None

    # Severity buckets per Apple docs (Microhang: 250ms–500ms, Hang: ≥500ms).
    # We bucket by raw duration so the agent can reason about it.
    buckets = {"lt_250ms": 0, "250ms_1s": 0, "gt_1s": 0}
    for h in hangs:
        if h["duration_ms"] < 250:
            buckets["lt_250ms"] += 1
        elif h["duration_ms"] < 1000:
            buckets["250ms_1s"] += 1
        else:
            buckets["gt_1s"] += 1

    top_offenders = [
        {
            "start_ms": h["start_ms"],
            "duration_ms": h["duration_ms"],
            "hang_type": h["hang_type"],
            "thread": (h["thread"] or {}).get("name", ""),
        }
        for h in hangs[:top_n]
    ]

    return {
        "lane": "hangs",
        "available": True,
        "schema_used": schema,
        "metrics": {
            "count": len(hangs),
            "total_duration_ms": round(total_ms, 2),
            "worst_duration_ms": worst["duration_ms"] if worst else 0,
            "severity_buckets": buckets,
        },
        "top_offenders": top_offenders,
        "notes": [],
        "_events": hangs,  # retained for correlation
    }


def _pick_schema(available: frozenset[str]) -> str | None:
    for s in PREFERRED_SCHEMAS + FALLBACK_SCHEMAS:
        if s in available:
            return s
    return None
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall