agent-flutter 0.1.20 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-flutter",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "Portable Flutter skill/rule pack initializer for multiple AI IDEs.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -697,8 +697,7 @@ Use local instructions from \`.cursor\`.
697
697
  Priority:
698
698
  1. \`.cursor/rules/shared/ui.md\`
699
699
  2. \`.cursor/rules/shared/integration-api.md\`
700
- 3. \`.cursor/rules/shared/document-workflow-function.md\`
701
- 4. \`.cursor/rules/shared/unit-test.md\` and \`.cursor/rules/shared/widget-test.md\`
700
+ 3. \`.cursor/rules/shared/unit-test.md\` and \`.cursor/rules/shared/widget-test.md\`
702
701
 
703
702
  When a task matches a skill, load the corresponding \`SKILL.md\` under:
704
703
  \`.cursor/skills/<skill>/SKILL.md\`
@@ -1,3 +1,153 @@
1
1
  ---
2
2
  alwaysApply: false
3
3
  ---
4
+ # API Integration Rules & Workflow
5
+
6
+ ## 1. Goal
7
+ Standardize how to integrate backend APIs into this project using the current architecture:
8
+ - Transport: `lib/src/api/api.dart`
9
+ - Endpoint mapping: `lib/src/api/api_url.dart`
10
+ - Flavor config: `lib/src/utils/app_api_config.dart`
11
+ - Persistence/token: `lib/src/utils/app_shared.dart`
12
+ - State/UI: `lib/src/ui/**` with `Bloc + PageState`
13
+
14
+ The rule is designed to prevent common violations: hardcoded URLs, mixed model layers, missing flavor handling, and inconsistent error behavior.
15
+
16
+ ## 1.1 Skill References (Required)
17
+ When executing this rule, apply these skills together:
18
+ - Architecture: [flutter-standard-lib-src-architecture](../skills/flutter-standard-lib-src-architecture/SKILL.md)
19
+ - Dependency flow: [flutter-standard-lib-src-architecture-dependency-rules](../skills/flutter-standard-lib-src-architecture-dependency-rules/SKILL.md)
20
+ - State management: [flutter-bloc-state-management](../skills/flutter-bloc-state-management/SKILL.md)
21
+ - DI: [flutter-dependency-injection-injectable](../skills/flutter-dependency-injection-injectable/SKILL.md)
22
+ - Error handling: [flutter-error-handling](../skills/flutter-error-handling/SKILL.md)
23
+ - Localization: [getx-localization-standard](../skills/getx-localization-standard/SKILL.md)
24
+ - Model reuse: [dart-model-reuse](../skills/dart-model-reuse/SKILL.md)
25
+
26
+ ## 2. Definition of Ready (P1 - Required Before Coding)
27
+ API integration must not start until all items are clear:
28
+ - Feature scope (function flow) is explicit.
29
+ - API contract is explicit: method, path, request body/query, response schema, error schema.
30
+ - Database-side behavior is understood from backend contract (field semantics, nullable rules, pagination/sort semantics).
31
+ - Target flavor is explicit for testing (`staging` or `prod`).
32
+
33
+ If any item is missing, stop implementation and request contract clarification first.
34
+
35
+ ## 3. Project Conventions (Current Repo)
36
+
37
+ ### A. Endpoint Source of Truth
38
+ - Base URL must come from `AppApiConfig.baseApiUrl`.
39
+ - Endpoint paths must be defined in `api_url.dart` interfaces (`IAuthApiUrl`, future groups).
40
+ - Do not hardcode endpoint strings inside bloc/page/widget.
41
+
42
+ ### B. Transport Layer
43
+ - Reuse `Api.request()` in `lib/src/api/api.dart`.
44
+ - Use `useIDToken: true` by default for authenticated APIs.
45
+ - Use `useIDToken: false` only for anonymous APIs (login/register/...).
46
+ - Do not duplicate Dio setup in feature code.
47
+
48
+ ### C. Model Layer Separation
49
+ - Request models: `lib/src/core/model/request/`
50
+ - Response models: `lib/src/core/model/response/`
51
+ - UI/domain-only models: `lib/src/core/model/`
52
+ - Never pass raw `Map<String, dynamic>` across UI layers for non-trivial APIs.
53
+ - Reuse-first: check existing models before creating new ones.
54
+
55
+ ### D. Repository Boundary
56
+ - All remote calls must be wrapped by repository classes in `lib/src/core/repository/`.
57
+ - Bloc/Controller must call repository methods, not `Api.request()` directly.
58
+ - Repository owns request/response mapping and token persistence side effects when needed.
59
+ - New repository methods should prefer `Result<T, E>` style returns for predictable error flow.
60
+
61
+ ### E. State/Error Handling
62
+ - Use `PageState` (`initial/loading/failure/success`) for request lifecycle.
63
+ - User-facing messages must be localized via `LocaleKey.*.tr` (no hardcoded text in bloc).
64
+ - Network/server errors should be normalized in repository before bubbling to UI state.
65
+ - Token invalid flow should be handled consistently with existing dialog flow (`showDialogErrorToken`).
66
+ - Do not throw raw exceptions into UI layer for new integrations; map to typed error/result first.
67
+
68
+ ## 4. Standard Workflow for New API Integration
69
+
70
+ ### Step 1: Confirm Contract + Flavor
71
+ - Confirm endpoint contract and sample payloads.
72
+ - Confirm test flavor command:
73
+ - `fvm flutter run --flavor staging --dart-define=FLAVOR=staging`
74
+ - `fvm flutter run --flavor prod --dart-define=FLAVOR=prod`
75
+
76
+ ### Step 2: Add Endpoint Mapping
77
+ - Extend `api_url.dart` by feature group interface.
78
+ - Keep path builders centralized (no duplicated string fragments).
79
+ - Follow structure constraints from [flutter-standard-lib-src-architecture](../skills/flutter-standard-lib-src-architecture/SKILL.md).
80
+
81
+ ### Step 3: Create Models
82
+ - Add request/response models in correct folders.
83
+ - Prefer typed fields and safe nullability.
84
+ - Add parser methods (`fromJson/toJson`) consistently.
85
+ - Apply reuse/evolution checklist from [dart-model-reuse](../skills/dart-model-reuse/SKILL.md).
86
+
87
+ ### Step 4: Implement Repository Method
88
+ - Repository extends/reuses `Api`.
89
+ - Use endpoint from `apiUrl.<group>`.
90
+ - Map response to typed model.
91
+ - Handle auth token persistence/refresh responsibilities in repository only.
92
+ - Follow mapping strategy from [flutter-error-handling](../skills/flutter-error-handling/SKILL.md).
93
+
94
+ ### Step 5: Wire DI
95
+ - Register repository through binding/module with `Get` injection.
96
+ - UI layer resolves repository through bloc/controller, not directly in widgets.
97
+ - Follow module boundaries from [flutter-dependency-injection-injectable](../skills/flutter-dependency-injection-injectable/SKILL.md).
98
+
99
+ ### Step 6: Integrate into Bloc
100
+ - Add event(s): trigger API use case.
101
+ - Emit `PageState.loading` before call.
102
+ - On success: emit `PageState.success` with typed data.
103
+ - On failure: emit `PageState.failure` with localized error key/message.
104
+ - Keep event/state modeling aligned with [flutter-bloc-state-management](../skills/flutter-bloc-state-management/SKILL.md).
105
+
106
+ ### Step 7: UI Consumption
107
+ - UI reads bloc state and renders loading/error/success.
108
+ - No API parsing logic in widget tree.
109
+ - All strings shown from API errors must pass localization policy in [getx-localization-standard](../skills/getx-localization-standard/SKILL.md).
110
+
111
+ ## 5. Minimal Reference Pattern
112
+
113
+ ```dart
114
+ class FeatureRepository extends Api {
115
+ final IFeatureApiUrl _url;
116
+ FeatureRepository(this._url);
117
+
118
+ Future<FeatureResponse> fetchFeature(FeatureRequest req) async {
119
+ final res = await request<Map<String, dynamic>>(
120
+ _url.fetchFeature,
121
+ Method.post,
122
+ body: req.toJson(),
123
+ useIDToken: true,
124
+ );
125
+ return FeatureResponse.fromJson(res.data ?? <String, dynamic>{});
126
+ }
127
+ }
128
+ ```
129
+
130
+ ## 6. Anti-Patterns (Do Not)
131
+ - Do not call `Dio()` directly inside bloc/controller.
132
+ - Do not put endpoint string literals in UI layer.
133
+ - Do not mix request/response classes in one generic model file.
134
+ - Do not hardcode user-facing error strings.
135
+ - Do not bypass flavor config by using fixed base URL.
136
+
137
+ ## 7. Verification Checklist Before PR
138
+ - [ ] Endpoint added in `api_url.dart` and consumed from repository only.
139
+ - [ ] Request/response models are separated and typed.
140
+ - [ ] Bloc uses `PageState` lifecycle correctly.
141
+ - [ ] All displayed text/error is localized via `LocaleKey`.
142
+ - [ ] Flavor run verified at least on staging command.
143
+ - [ ] `fvm flutter analyze` passes.
144
+ - [ ] Existing behavior (auth/token/toast/dialog flow) is not regressed.
145
+
146
+ ## 8. Prompt Template for AI
147
+ Use this when asking AI to implement integration:
148
+
149
+ > Integrate API for `<feature>` using project rule `integration-api.md`.
150
+ > Contract: `<method/path/request/response/errors>`.
151
+ > Use `api_url.dart` + repository layer + typed models + bloc `PageState`.
152
+ > No hardcoded endpoint/message. Localize all user text.
153
+ > Validate with `analyze` and staging flavor run command.
@@ -1,98 +0,0 @@
1
- ---
2
- alwaysApply: false
3
- ---
4
- # AI Documentation Workflow (Function)
5
-
6
- ## **Goal**
7
- To automatically generate and maintain detailed functional documentation in `spec/function-workflow.md`. This documentation bridges the gap between the high-level UI flow (from `ui-workflow.md`) and the technical implementation, focusing on **API integrations, Data Transformations, and State Management logic**.
8
-
9
- ## **Trigger**
10
- This workflow is triggered when:
11
- 1. The `spec/ui-workflow.md` has been updated (Prerequisite).
12
- 2. Backend integration (API) is implemented for a feature.
13
- 3. Complex business logic is added (e.g., data validation, caching, error handling).
14
- 4. The user requests: "Update function workflow for [feature]".
15
-
16
- ## **Workflow Steps**
17
-
18
- ### **Step 1: Analyze the Implementation**
19
- - **Input**: The feature folder (`lib/src/ui/<feature>`) and `spec/ui-workflow.md`.
20
- - **Action**: Deep dive into the following files:
21
- - `bloc/*_bloc.dart`: Identify Events, States, and Side Effects.
22
- - `repository/*_repository.dart`: Identify API endpoints, Request/Response models.
23
- - `model/*`: Analyze data structures.
24
- - `core/managers/*`: Check for global state usage (e.g., Auth, Permission).
25
-
26
- ### **Step 2: Format the Documentation**
27
- - **Output File**: `spec/function-workflow.md`
28
- - **Format**: Append (or Update) a section for EACH feature using the following template:
29
-
30
- ```markdown
31
- ## [Feature Name] (e.g., Login)
32
- **Ref UI**: [Link to UI Spec Section]
33
-
34
- ### **1. Data Model**
35
- **Request**: `LoginRequest`
36
- - `email` (String): Required, valid email format.
37
- - `password` (String): Required, min 6 chars.
38
-
39
- **Response**: `LoginResponse`
40
- - `token` (String): JWT Token.
41
- - `user` (UserDto): User profile info.
42
-
43
- ### **2. State Management (BLoC)**
44
- **Events**:
45
- - `LoginEvent(email, password)`: Triggers the login process.
46
- - `LoginReset()`: Resets state to initial.
47
-
48
- **States**:
49
- - `LoginInitial`: Form inputs enabled.
50
- - `LoginLoading`: Inputs disabled, loading spinner active.
51
- - `LoginSuccess(user)`: Navigation trigger.
52
- - `LoginFailure(error)`: Error message display.
53
-
54
- ### **3. Functional Logic**
55
- 1. **Validation**:
56
- - Check `email` via Regex.
57
- - Check `password.length >= 6`.
58
- - *If invalid*: Emit `LoginFailure(ValidationError)`.
59
-
60
- 2. **API Call**:
61
- - Call `AuthRepository.login(request)`.
62
- - **Endpoint**: `POST /api/v1/auth/login`
63
- - **Headers**: `Content-Type: application/json`
64
-
65
- 3. **Error Handling**:
66
- - **401 Unauthorized**: "Incorrect credentials".
67
- - **500 Server Error**: "System error, try again".
68
- - **Network Error**: "Check connection".
69
-
70
- 4. **Post-Process**:
71
- - Save `token` to `SecureStorage`.
72
- - Update `UserManager.currentUser`.
73
- - Emit `LoginSuccess`.
74
-
75
- ### **4. Dependencies & Services**
76
- - `AuthRepository`: API communication.
77
- - `SecureStorage`: Token persistence.
78
- - `UserManager`: Global user state.
79
-
80
- ### **5. Technical Debt / Optimization**
81
- - [ ] Add rate limiting on login attempts.
82
- - [ ] Cache last used email for convenience.
83
- ```
84
-
85
- ### **Step 3: Verification**
86
- - **Consistency Check**: Ensure the "Functional Logic" aligns with the "User Flow" in `spec/ui-workflow.md`.
87
- - **API Check**: Verify that the documented Endpoint and Request/Response models match the actual code in `Repository` and `Retrofit` clients.
88
- - **Edge Cases**: Ensure error handling (Network, Validation, Server) is documented.
89
-
90
- ---
91
-
92
- ## **Prompt for AI**
93
-
94
- ### **Case 1: Single Feature**
95
- > "Analyze `lib/src/ui/<feature>` and update `spec/function-workflow.md` based on the UI spec."
96
-
97
- ### **Case 2: Sync with UI Spec**
98
- > "Read `spec/ui-workflow.md` and generate the corresponding functional specs in `spec/function-workflow.md`."
@@ -1,51 +0,0 @@
1
- ---
2
- alwaysApply: false
3
- ---
4
- # New Template Project (Script-first)
5
-
6
- Use the bootstrap script instead of generating the full workflow text.
7
-
8
- ## Script path
9
- - Trae: `.trae/scripts/bootstrap_flutter_template.sh`
10
- - Codex: `.codex/scripts/bootstrap_flutter_template.sh`
11
- - Cursor: `.cursor/scripts/bootstrap_flutter_template.sh`
12
- - Windsurf: `.windsurf/scripts/bootstrap_flutter_template.sh`
13
- - Cline: `.clinerules/scripts/bootstrap_flutter_template.sh`
14
- - GitHub: `.github/scripts/bootstrap_flutter_template.sh`
15
-
16
- ## Run
17
- Interactive mode:
18
- ```bash
19
- bash .codex/scripts/bootstrap_flutter_template.sh
20
- ```
21
-
22
- Non-interactive mode:
23
- ```bash
24
- bash .codex/scripts/bootstrap_flutter_template.sh \
25
- --name link_home_mobile \
26
- --org com.company \
27
- --flutter-version stable \
28
- --dir ~/workspace \
29
- --force \
30
- --non-interactive
31
- ```
32
-
33
- ## Inputs
34
- - `--name`: project folder name (required in non-interactive mode).
35
- - `--org`: reverse-domain org id (default: `com.example`).
36
- - `--flutter-version`: Flutter version for FVM (default: `stable`).
37
- - `--dir`: parent folder to create project in (default: current directory).
38
- - `--force`: allow overwrite in an existing non-empty directory.
39
-
40
- ## What the script does
41
- 1. Ensures FVM exists (auto-installs with `dart pub global activate fvm` if needed).
42
- 2. Creates Flutter project with FVM and selected version.
43
- 3. Adds core dependencies and dev dependencies.
44
- 4. Creates architecture folders and starter files (`main`, DI, locale, routing, home feature).
45
- 5. Creates `.env`, `.env.staging`, `.env.prod` and updates `.gitignore`.
46
-
47
- ## Validation
48
- ```bash
49
- cd <project_name>
50
- fvm flutter run
51
- ```