agent-rules Documentation

repository·main·Indexed 26 days ago

https://github.com/steipete/agent-rules

Legacy AI agent rules and instructions from mid-2025. Includes best practices for developing, testing, and releasing Model Context Protocol (MCP) tools, including Pino logging configuration, native binary requirements, and release preparation via npm. Also contains guidelines for modern Swift development, SwiftUI state management, and using the Swift Argument Parser for CLI tools.

Tokens
164.2K
Snippets
393
Records
1K
Agent score
90%

What's inside agent-rules

  1. Overview of UIKit Framework

    main

    UIKit is a framework used to construct and manage graphical, event-driven user interfaces for iOS, iPadOS, and tvOS apps. It provides the window and view architecture, event-handling infrastructure for Multi-Touch and other inputs, and the main run loop for managing interactions between the user, the system, and the app.

    Key capabilities include:

    • Animations, drawing, and printing.
    • Text management and display.
    • Search and app extensions.
    • Resource management and device information.
    • Accessibility customization and localization.
    • Seamless integration with SwiftUI (allowing UIKit views/view controllers to be used inside SwiftUI and vice versa).
  2. Manage app UI instances with Scenes

    main

    UIKit uses UIWindowScene objects to manage multiple instances of an app's UI simultaneously. A scene contains the windows and view controllers for one instance of the UI. Each scene has a corresponding UIWindowSceneDelegate to coordinate interactions. Scenes run concurrently and share the same memory and app process space.

    Key components:

    • UIScene: Represents one instance of the app's user interface.
    • UIWindowScene: A scene that manages one or more windows.
    • UIWindowSceneDelegate: Manages app-specific tasks occurring within a window scene.
    • UISceneDelegate: Core methods for responding to life-cycle events within a scene.
    • UIApplicationSceneManifest: Provides information about the app's scene-based life-cycle support.
    • UISceneConfiguration: Contains information about objects and storyboards used to create a particular scene.
  3. Understand UIStackView and Auto Layout

    main

    A UIStackView manages the layout of its arrangedSubviews along a specific axis (horizontal or vertical). It uses Auto Layout to position and size these views dynamically based on the stack view's axis, distribution, alignment, and spacing properties.

    Key behaviors:

    • Axis Alignment: In horizontal stacks, the first view's leading edge is pinned to the stack's leading edge, and the last view's trailing edge is pinned to the stack's trailing edge. In vertical stacks, top and bottom edges are pinned.
    • Intrinsic Content Size: For most distributions and alignments, the stack view uses each arranged view's intrinsicContentSize to calculate dimensions.
    • Fitting Size:
      • Along the axis: Sum of all arranged view sizes + spacing.
      • Perpendicular to the axis: Size of the largest arranged view.
    • Margins: If isLayoutMarginsRelativeArrangement is true, the stack view pins content to layout margins instead of edges.
  4. Use UIScrollView for scrolling and zooming

    main

    A UIScrollView allows users to scroll and zoom through content. It clips content to its frame and tracks finger movements to adjust the content offset.

    Key Features

    • Scrolling: Adjusts the origin over the content view. It automatically handles bouncing when scrolling exceeds bounds.
    • Zooming: Supports pinch-in/out gestures. To enable zooming, you must implement viewForZooming(in:) and scrollViewDidEndZooming(_:with:atScale:) in a UIScrollViewDelegate and ensure maximumZoomScale is different from minimumZoomScale.
    • State Preservation: If you set a restorationIdentifier, the scroll view attempts to preserve zoomScale, contentInset, and contentOffset between app launches.
  5. Understand Swift 6 Concurrency Migration Errors

    main
    Enabling complete concurrency checking in Swift 6 can surface latent issues even in existing Swift 5 code. These issues may manifest as a large number of warnings or errors. Most errors stem from a small set of root causes related to data isolation guarantees and common patterns that conflict with Swift's concurrency system.
  6. Manage App Life Cycle and Environment

    main

    UIKit provides tools to manage app life cycle events, UI scenes, and environmental traits:

    • App Control: Use UIApplication as the centralized point of control and UIApplicationDelegate to manage shared behaviors and life cycle events.
    • Device Information: Use UIDevice to represent the current device.
    • Environment Adaptivity: UIKit uses UITraitCollection to reflect device settings, interface settings (like Dark Mode), and user preferences.
    • Trait Tracking: Implement UITraitEnvironment to receive notifications when the environment changes. Use UITraitChangeObservable to react to trait environment changes.
  7. SwiftData Core Concepts Overview

    main

    SwiftData provides a native persistence framework for Swift. Key components include:

    • Model Definition: Using @Model, @Attribute, @Relationship, and @Transient to define data structures.
    • Model Life Cycle: Managed via ModelContainer (schema and storage configuration) and ModelContext (fetching, inserting, deleting, and saving).
    • Model Fetching: Using @Query in views or FetchDescriptor to filter and sort data.
    • Storage & History: Support for local storage, iCloud syncing, and tracking changes via HistoryDescriptor and HistoryChange.
  8. Use Views and Controls for UI construction

    main

    Build your user interface using a hierarchy of views and controls:

    • UIView: The root class for all views. Supports containment (superviews/subviews), custom drawing (Core Graphics), drag and drop, focus changes, and animations.
    • UIControl: A subclass of UIView that adds behaviors specific to interactive elements like buttons and switches.
  9. Understand Swift 6 Concurrency and Data Isolation

    main

    Swift 6 introduces a concurrency system that guarantees data-race-free code at compile time through data isolation. Data isolation ensures mutually exclusive access to mutable state by assigning declarations to specific isolation domains.

    There are three primary isolation domains:

    1. Non-isolated: The default state for functions and variables with no explicit isolation.
    2. Isolated to an actor value: State protected by a specific actor instance.
    3. Isolated to a global actor: State protected by a statically assigned global actor (e.g., @MainActor).
  10. Understand the UIKit Model-View-Controller (MVC) architecture

    main

    UIKit apps follow the Model-View-Controller (MVC) design pattern to separate concerns:

    • Model: Manages app data and business logic. Use UIDocument for disk-based files and Foundation/Swift types (strings, numbers, arrays) for data structures.
    • View: Provides the visual representation of data. The UIView class is primarily responsible for displaying content onscreen.
    • Controller: Acts as a bridge between Model and View. UIViewController objects and the UIApplication object (which manages the app's life cycle and main event loop) coordinate data exchange.
  11. Provide a purpose string for protected resources

    main

    When your app accesses protected resources (like location, camera, or Bluetooth), iOS prompts the user for permission. You must provide a purpose string (or usage description) in your app's Info.plist file to explain why the access is needed. If this string is missing, the app may crash or fail to access the resource.

    For apps supporting multiple languages, you should also localize these strings in InfoPlist.strings files for each supported locale.

    Requirements for purpose strings:

    • Must not be blank or consist only of whitespace.
    • Must be shorter than 4,000 bytes.
    • Must be the correct type (typically a string).
    • Must be accurate, meaningful, and specific about the usage.