Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .agents/skills/make-feature/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
name: make-feature
description: Creates a SwiftUI feature foundation with ObservableViewModel and FactoryKit. Use when creating a feature or its actor, provider, use cases, state, view model, and view.
---

# Make a feature

Create one feature that builds in the target app and connects a view action to observable state.

## Locate the reference and target

1. Read the target repository's `AGENTS.md` and package or Xcode configuration.
2. Find the ObservableViewModel checkout, three directories above this skill directory when using the repository copy.
3. Read that checkout's `README.md` and `Demo/ObservableViewModelDemo/MyFeature` Swift files.
4. Identify the target app, feature name, destination, initial state, and first action from the request and existing code.
5. If a required choice remains unclear, ask the user before you create files that depend on it.

Use the target app's module and naming conventions.
If the app already has a provider or use case for the requested behavior, use it.
Default to an in-memory value when the user requests only a foundation.

## Create the foundation

Use this file map unless the app already has an equivalent structure:

```text
<Feature>/
<Feature>Actor.swift
Domain/
<Feature>Provider.swift
Get<Value>UseCase.swift
Set<Value>UseCase.swift
Container.swift
Presentation/
<Feature>ViewModel.swift
<Feature>.swift
```

1. Declare `<Feature>Actor` as a global actor with a shared instance for domain work.
2. Define a sendable provider protocol with a value stream and an actor-isolated mutation method.
3. Implement the provider with storage on `<Feature>Actor` and a stream that supports task cancellation.
4. Define get and set use case protocols and implementations that access the provider through FactoryKit.
5. Register the provider and use cases on `Container`. Share the provider instance between reads and writes.
6. Define `<Feature>State: ViewState` with sendable fields and default values for a no-argument initializer.
7. Add `Equatable` when the view compares or animates the state.
8. Declare the view model with `@ViewModelActor`, `@Observable`, and `@ObservableViewModel` dependency key paths.
9. Declare `@MainActor var state: <Feature>State` without an initial value or an explicit view model initializer.
10. Bind the value stream in `observe()`, with child tasks in `withDiscardingTaskGroup` for multiple streams.
11. Add an async action with a view-owned task, or a nonisolated action that starts actor-isolated work.
12. Create the SwiftUI view with a private `@State` view model and `.observe(on: viewModel)`.
13. Connect the requested action and state display in the view.
14. Add the files to the app target.
15. If the request includes an app entry point, connect navigation.

## Concurrency and dependencies

- Keep domain storage on `<Feature>Actor`, view model behavior on its global actor, and view state on `MainActor`.
- Make use case protocols `Sendable`. With default main-actor isolation, mark actor-independent use case protocols and implementations `nonisolated`.
- Preserve `Sendable` when you erase an async sequence type, such as `any AsyncSequence<String, Never> & Sendable`.
- Use `await setState` for state changes from the view model actor.
- Use the closure form for a state change that depends on the previous state.
- Register dependency replacements before creating a view model. The macro resolves dependencies during initialization.
- Use `FactoryKit` directly in targets that import it, with a direct package product dependency.
- For a custom container, resolve its dependencies explicitly instead of passing them to the macro.
- Use `Observations` only when the target supports it. The demo requires iOS 26 or macOS 26.
- For older targets, use a cancellation-aware `AsyncStream` with a separate continuation for each subscriber.
- Handle throwing streams in `observe()` and expose the requested error state.
- Keep long-lived observation in the task that `.observe(on:)` manages.

## Verify and report

1. Build the target app with its configured Swift language mode and deployment target.
2. Check the first action, the state update, and observation cancellation with a focused test or app run.
For concurrent Swift tests, follow `Tests/ObservableViewModelTests/ConcurrentObservationTests.swift` in the library checkout.
Use FactoryTesting’s `.container` trait for isolated dependencies.
Assert state with `ObservationsShim` and bounded `fulfillment` calls.
3. For library changes in this checkout, run `swift test`.
4. Report the files you created, the connected behavior, and the checks that passed.
5. If a build or runtime check was unavailable, state the limit and the remaining check.

Example request: “Create an Animals feature with an in-memory animal stream and an action that selects another animal.”
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.build/
.swiftpm/
.DS_Store
DerivedData/
xcuserdata/
*.xcuserstate
30 changes: 30 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Repository guide

Read [README.md](README.md) for setup and public usage.

## Create a feature

When you create a feature with ObservableViewModel, read [.agents/skills/make-feature/SKILL.md](.agents/skills/make-feature/SKILL.md).
Use [Demo/ObservableViewModelDemo/MyFeature](Demo/ObservableViewModelDemo/MyFeature) as the working reference.
Create app features in the requested app target, outside the library's `Sources` directory.

## Change the library

- Keep runtime APIs in `Sources/ObservableViewModel` and macro expansion in `Sources/ObservableViewModelMacros`.
- Preserve the explicit actor, `@Observable`, and state declarations that the macro requires.
- Keep view state on `MainActor` and feature behavior on its declared global actor.
- When behavior changes, add or update a test in `Tests/ObservableViewModelTests`.
- When the public pattern changes, update the README, demo, and feature skill together.

## Verify changes

Run `swift test` from the repository root for library or macro changes.
For demo changes, build the Xcode project with the command in [README.md](README.md#development).
Use `-destination 'generic/platform=iOS Simulator'` to check its iOS build.
Report the checks you ran and any checks you could not complete.

## Write documentation

Use short, active sentences and consistent names.
Check examples against the package's Swift language mode and deployment targets.
State higher OS requirements for APIs such as `Observations`.
Loading
Loading