interaqt 0.7.3 → 0.8.0

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.
@@ -3,6 +3,9 @@
3
3
  "allow": [
4
4
  "Bash(npm run check)",
5
5
  "Bash(npm run test)",
6
+ "Read(STATUS.json)",
7
+ "Write(STATUS.json)",
8
+ "Edit(STATUS.json)",
6
9
  "Read(docs/**)",
7
10
  "Write(docs/**)",
8
11
  "Edit(docs/**)",
@@ -38,7 +41,39 @@
38
41
  "Bash(npm run reset)",
39
42
  "Bash(git restore backend/index.ts docs/computation-implementation-plan.json tests/basic.test.ts)",
40
43
  "Bash(npm run setup)",
41
- "Bash(mv backend/index.template.ts backend/index.ts)"
44
+ "Bash(mv backend/index.template.ts backend/index.ts)",
45
+ "Bash(npm run build)",
46
+ "Bash(npm run dev:frontend)",
47
+ "Bash(npm run dev)",
48
+ "Bash(pkill:*)",
49
+ "Bash(npx tsc:*)",
50
+ "Bash(npx vitest run:*)",
51
+ "Bash(npm run generate-frontend-api)",
52
+ "Bash(lsof:*)",
53
+ "Bash(curl:*)",
54
+ "Bash(test:*)",
55
+ "Bash(rg:*)",
56
+ "Bash(bash:*)",
57
+ "Bash(npm run type-check)",
58
+ "Bash(echo:*)",
59
+ "Bash(find:*)",
60
+ "Bash(grep:*)",
61
+ "Bash(sed:*)",
62
+ "Bash(awk:*)",
63
+ "Bash(tr:*)",
64
+ "Bash(cut:*)",
65
+ "Bash(sort:*)",
66
+ "Bash(uniq:*)",
67
+ "Bash(wc:*)",
68
+ "Bash(node:*)",
69
+ "WebSearch",
70
+ "WebFetch",
71
+ "Bash(if [ -z \"$VOLC_ACCESS_KEY_ID\" ])",
72
+ "Bash(then echo \"VOLC_ACCESS_KEY_ID is empty or not set\")",
73
+ "Bash(else echo \"VOLC_ACCESS_KEY_ID is set\")",
74
+ "Bash(fi:*)",
75
+ "Bash(if [ -z \"$VOLC_SECRET_ACCESS_KEY\" ])",
76
+ "Bash(then echo \"VOLC_SECRET_ACCESS_KEY is empty or not set\")"
42
77
  ],
43
78
  "deny": [],
44
79
  "ask": []
package/agent/CLAUDE.md CHANGED
@@ -9,44 +9,123 @@ You are a honest software expert with the following capabilities:
9
9
 
10
10
  This guide provides a comprehensive step-by-step process for generating backend projects based on the interaqt framework.
11
11
 
12
- ## CRITICAL: Progress Tracking with STATUS.json
13
- **Before starting ANY work, create `docs/STATUS.json` to track your progress:**
12
+ ## CRITICAL: Module Selection and Progress Tracking
13
+
14
+ **🔴 STEP 0: Determine Current Working Module**
15
+
16
+ Before starting any work, you MUST determine which module you're working on:
17
+
18
+ 1. **Check if user specified module in their prompt:**
19
+ - If YES: Write the module name to `.currentmodule` file (create if doesn't exist, overwrite entire content if exists)
20
+ - If NO: Continue to step 2
21
+
22
+ 2. **Check if `.currentmodule` file exists:**
23
+ - If YES: Read the module name from `.currentmodule`
24
+ - If NO: **STOP and ask user which module to work on**, then write the module name to `.currentmodule`
25
+
26
+ 3. **Set the module name for this session:** Use this module name for all subsequent operations
27
+
28
+ **🔴 IMPORTANT: Module-Based Progress Tracking**
29
+
30
+ Each module has its own progress tracking file:
31
+ - **File location**: `docs/{module}.status.json` (where `{module}` is the current module name from `.currentmodule`)
32
+ - **Before starting ANY work, read or create the module's status file:**
14
33
 
15
34
  ```json
16
35
  {
36
+ "module": "moduleName",
17
37
  "currentTask": "Task 1",
18
38
  "completed": false,
19
39
  "completedItems": []
20
40
  }
21
41
  ```
22
42
 
23
- ** IMPORTANT: All tasks in this guide use a global unique numbering system (Task x.x.x.x). You can always find your current position by checking `docs/STATUS.json`, which tracks the exact Task number you were working on.**
43
+ ** IMPORTANT: All tasks in this guide use a global unique numbering system (Task x.x.x.x). You can always find your current position by checking `docs/{module}.status.json`, which tracks the exact Task number you were working on for that module.**
44
+
45
+ **Task Numbering Hierarchy:**
46
+ - **Top-level tasks**: Task 1, Task 2, Task 3 (major phases)
47
+ - **Sub-tasks**: Task 1.1, Task 1.2, Task 1.3, Task 1.4, etc. (steps within a phase)
48
+ - **Sub-sub-tasks**: Task 1.1.1, Task 3.1.4.3, etc. (nested steps)
49
+ - **Rule**: Extract the first digit to determine which sub-agent handles the task
50
+
51
+ ** IMPORTANT: Module-Based Generation - All generated artifacts should be organized by module name read from `.currentmodule` file.**
24
52
 
25
53
  ## Task-Based Workflow System
26
54
 
27
55
  **📖 STEP 1: Check Current Progress**
28
- 1. Read `docs/STATUS.json` to find your current task number (e.g., "Task 1", "Task 2", "Task 3")
29
- 2. If the file doesn't exist, you should start with Task 1
56
+ 1. Read current module name from `.currentmodule` file
57
+ 2. Read `docs/{module}.status.json` to find your current task number (e.g., "Task 1.3", "Task 2.1", "Task 3.1.4.3")
58
+ 3. If the status file doesn't exist, you should start with Task 1
59
+
60
+ **📖 STEP 2: Determine Sub-Agent from Task Number**
30
61
 
31
- **📖 STEP 2: Execute Corresponding Task**
32
- Based on the current task in `docs/STATUS.json`, use the appropriate sub-agent:
62
+ **Extract top-level task (first digit) from currentTask to determine sub-agent:**
63
+
64
+ Algorithm:
65
+ ```
66
+ if currentTask starts with "Task 3.1.4.3": use computation-generation-handler
67
+ else if currentTask starts with "Task 3.2.2": use permission-generation-handler
68
+ else:
69
+ topLevel = first digit of currentTask
70
+ if topLevel == 1: use requirements-analysis-handler
71
+ if topLevel == 2: use implement-design-handler
72
+ if topLevel == 3: use code-generation-handler
73
+ if topLevel == 4: use implement-integration-handler
74
+ ```
33
75
 
34
- - **Task 1** → Use sub-agent `requirements-analysis-handler`
35
- - **Task 2**Use sub-agent `implement-design-handler`
36
- - **Task 3**Use sub-agent `code-generation-handler` (default for Task 3)
37
- - **Exception: Task 3.1.4.3 - Computation Implementation Loop** Use sub-agent `computation-generation-handler` during the implementation loop
38
- - **Exception: Task 3.2.2 - Permission and Business Rule Implementation Loop** Use sub-agent `permission-generation-handler` during the implementation loop
76
+ Examples:
77
+ - "Task 1.3"Top-level is 1 → `requirements-analysis-handler`
78
+ - "Task 2.5.2"Top-level is 2 → `implement-design-handler`
79
+ - "Task 3.1.4.3" Exception → `computation-generation-handler`
80
+ - "Task 3.2.2" Exception → `permission-generation-handler`
81
+ - "Task 3.x" (other) → Top-level is 3 → `code-generation-handler`
82
+ - "Task 4.2" → Top-level is 4 → `implement-integration-handler`
83
+
84
+ **📖 STEP 3: Execute Task with Sub-Agent**
85
+
86
+ Sub-agent mapping:
87
+ - **Task 1.x** (any sub-task of Task 1) → Use `requirements-analysis-handler`
88
+ - **Task 2.x** (any sub-task of Task 2) → Use `implement-design-handler`
89
+ - **Task 3.x** (any sub-task of Task 3) → Use `code-generation-handler`
90
+ - **Exception: Task 3.1.4.3.x** → Use `computation-generation-handler`
91
+ - **Exception: Task 3.2.2.x** → Use `permission-generation-handler`
92
+ - **Task 4.x** (any sub-task of Task 4) → Use `implement-integration-handler`
93
+ - **Error Checking** → Use `error-check-handler` when user requests error checking
94
+
95
+ **CRITICAL - Task Continuation Logic:**
96
+ - **Within same top-level**: Task 1.3 → Task 1.4 (stay in same sub-agent, do NOT jump to Task 2)
97
+ - **Move to next top-level**: Only when status shows `"currentTask": "Task 1"` (no suffix) AND `"completed": true`, then move to Task 2
98
+ - Each sub-agent handles its own task progression; only switch sub-agents when explicitly moving to a new top-level task
99
+
100
+ **📋 STEP 4: Error Checking (Optional)**
101
+
102
+ At any point in the workflow, you can use the `error-check-handler` sub-agent to perform comprehensive error checking:
103
+ - Creates a detailed error report in `docs/{module}.error-check-report.md`
104
+ - Checks all phases systematically (Module Setup, Requirements, Design, Code Generation, Frontend, Integration)
105
+ - Identifies CRITICAL, HIGH PRIORITY, and MEDIUM PRIORITY errors
106
+ - Provides specific file paths, line numbers, and suggested fixes
107
+ - Does NOT fix errors - only finds and reports them
108
+
109
+ **When to use error-check-handler:**
110
+ - User explicitly requests error checking or quality assurance
111
+ - Before marking any major phase complete (Task 1, Task 2, Task 3)
112
+ - After completing implementation but before moving to production
113
+ - When debugging issues or trying to understand problems
39
114
 
40
115
  **🔴 CRITICAL - AUTORUN EXECUTION CONTROL:**
41
116
 
42
- **For Top-Level Tasks (Task 1, Task 2, Task 3):**
43
- - **Check `SCHEDULE.json`**: When `"autorun": true`, automatically proceed to the next top-level task after completing the current one
44
- - **Example**: If Task 1 is completed and `autorun: true`, automatically start Task 2 without waiting for user instruction
117
+ **For Top-Level Tasks (Task 1, Task 2, Task 3, Task 4):**
118
+ - **IMPORTANT**: "Task 1 complete" means status shows `"currentTask": "Task 1"` (NOT "Task 1.x") AND `"completed": true`
119
+ - **Task 1.3 is WITHIN Task 1**: Continue to Task 1.4 within same sub-agent; do NOT jump to Task 2
120
+ - **Check `SCHEDULE.json`**: When `"autorun": true`, automatically proceed to next top-level task ONLY after current top-level shows as fully completed
121
+ - **Example**: Status shows "Task 1.3" → Continue to Task 1.4 (stay in requirements-analysis-handler)
122
+ - **Example**: Status shows "Task 1" with `completed: true` and `autorun: true` → Start Task 2 (switch to implement-design-handler)
123
+ - **Example**: Status shows "Task 3" with `completed: true` and `autorun: true` → Start Task 4 (switch to implement-integration-handler)
45
124
  - **When `autorun` is false or doesn't exist**: Stop after completing each top-level task and wait for user's instruction to continue
46
125
 
47
126
  **For Loop Tasks Within Sub-Tasks:**
48
127
  - **Check `SCHEDULE.json`**: When `"autorun": true`, automatically complete the loop task cycles continuously. When `autorun` doesn't exist or is `false`, execute only one iteration of the loop task then stop and wait for user's manual instruction to proceed with the next iteration
49
- - **Loop Termination Condition**: Continue looping until the `completionCriteria` in `docs/STATUS.json` is fully satisfied
128
+ - **Loop Termination Condition**: Continue looping until the `completionCriteria` in `docs/{module}.status.json` is fully satisfied
50
129
  - **Example**: For Task 3.1.4.3, if autorun is true, keep implementing computations one by one until all items in `docs/computation-implementation-plan.json` have `completed: true`
51
130
  - **Example**: For Task 3.2.2, if autorun is true, keep implementing permissions/rules one by one until all items in `docs/business-rules-and-permission-control-implementation-plan.json` have `completed: true`
52
131
  - **IMPORTANT**: Only after the completion criteria is met can you proceed to the next task
@@ -2,14 +2,20 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- This guide helps you select the appropriate computation type for each entity, property, relation, and dictionary based on the structured information in `data-design.json` and `interaction-design.md`.
5
+ This guide helps you select the appropriate computation type for each entity, property, relation, and dictionary based on the structured information in `requirements/{module}.data-design.json` and `requirements/{module}.interaction-design.md`.
6
+
7
+ **IMPORTANT**: First read the current module name from `.currentmodule` file in project root, and use it to construct the file paths. For example, if `.currentmodule` contains `user-management`, then the paths would be:
8
+ - `requirements/user-management.data-design.json`
9
+ - `requirements/user-management.interaction-design.md`
6
10
 
7
11
 
8
12
  ## Input Files
9
13
 
10
14
  You will receive two input files:
11
- 1. **data-design.json**: Contains structured data dependencies and lifecycle information
12
- 2. **interaction-design.md**: Describes all interactions and their effects
15
+ 1. **requirements/{module}.data-design.json**: Contains structured data dependencies and lifecycle information
16
+ 2. **requirements/{module}.interaction-design.md**: Describes all interactions and their effects
17
+
18
+ Note: Replace `{module}` with the value from `.currentmodule` file.
13
19
 
14
20
  ## Direct Mapping Rules
15
21
 
@@ -27,13 +33,17 @@ The `_owner` notation indicates that this property's value is fully controlled b
27
33
 
28
34
  Properties marked with `_owner` don't need separate computation control - their logic is embedded in the owner's creation or derivation process.
29
35
 
36
+ Note: Properties with `controlType: "integration-result"` are NOT marked as `_owner` - they use `StateMachine` to observe and extract values from API Call entity updates.
37
+
30
38
  ### 1. Entity-Level Computations
31
39
 
32
40
  Look at the entity's `lifecycle.creation` and `lifecycle.deletion`:
33
41
 
34
42
  | Creation Type | Deletion | Computation Decision |
35
43
  |---------------|----------|---------------------|
44
+ | `"integration-event"` | Always `canBeDeleted: false` | `None` - Entity is externally controlled by webhook/callback from external systems |
36
45
  | `"created-with-parent"` | Any | `_parent:[lifecycle.creation.parent]` (created by parent's computation) |
46
+ | `"mutation-derived"` | Any | `Transform` from record mutation events (both interaction-created and entity-created produce mutations) |
37
47
  | `"interaction-created"` | `canBeDeleted: false` | `Transform` with `InteractionEventEntity` |
38
48
  | `"interaction-created"` | `canBeDeleted: true` with `hard-delete` | `Transform` + `HardDeletionProperty` with `StateMachine` |
39
49
  | `"interaction-created"` | `canBeDeleted: true` with `soft-delete` | `Transform` + status property with `StateMachine` |
@@ -61,11 +71,17 @@ Check `lifecycle.creation` and `lifecycle.deletion`:
61
71
 
62
72
  ### 3. Property-Level Computations
63
73
 
74
+ **🔴 CRITICAL RULE: Properties can NEVER use Transform computation**
75
+ - Transform is ONLY for Entity/Relation creation
76
+ - Properties must use: _owner, StateMachine, computed, aggregations (Count/Sum/etc.), or Custom
77
+ - Even if a property needs to respond to external events (like Integration Events), use StateMachine with appropriate triggers
78
+
64
79
  First check the property's `controlType`, then analyze dependencies if needed:
65
80
 
66
81
  | Control Type | Computation Decision |
67
82
  |--------------|---------------------|
68
83
  | `creation-only` | `_owner` - controlled by entity/relation creation |
84
+ | `integration-result` | `StateMachine` - observes API Call entity updates, extracts result from response data |
69
85
  | `derived-with-parent` | `_owner` - controlled by parent's derivation |
70
86
  | `independent` | Further analysis needed (see below) |
71
87
 
@@ -75,29 +91,52 @@ Analyze the property's `dataDependencies`, `interactionDependencies`, and `compu
75
91
 
76
92
  | Condition | Computation Decision |
77
93
  |-----------|---------------------|
78
- | Has `interactionDependencies` that can modify it | `StateMachine` for state transitions or value updates |
79
- | Has `dataDependencies` with relations/entities | Aggregation computation based on `computationMethod` |
94
+ | `calculationMethod` contains "sum of", "count of", "aggregate", or involves Record entities | `Custom` or aggregation (e.g., balance = sum(deposits) - sum(withdrawals)) |
95
+ | Has `interactionDependencies` that can modify it | `StateMachine` for state transitions or value updates (even for external events) |
96
+ | Has `dataDependencies` with relations/entities (including Integration Events) | `StateMachine` if triggered by events, otherwise aggregation computation |
80
97
  | `dataDependencies` = self properties only | `computed` function |
81
98
  | Complex calculation with multiple entities | `Custom` |
82
99
  | Only has `initialValue`, no dependencies | No computation (use `defaultValue`) |
83
100
 
101
+ **Common Pattern - Integration Result Properties:**
102
+ - **If `controlType: "integration-result"`** → **Always use `StateMachine`**
103
+ - Pattern: Property computed from API Call entity's response data
104
+ - Example: `Donation.voiceUrl` computed from `TTSAPICall.responseData`
105
+ - Implementation:
106
+ - Trigger: Monitor API Call entity creation/update
107
+ - ComputeTarget: Find the business entity that needs the result
108
+ - ComputeValue: Extract value from API Call entity's response field
109
+
110
+ **Common Pattern - Integration Event Updates:**
111
+ - Property needs to update based on Integration Event (e.g., TTSEvent) → Use `StateMachine`
112
+ - Set trigger to monitor the Integration Event Entity creation: `trigger: { recordName: 'TTSEvent', type: 'create' }`
113
+ - Use `computeTarget` to find the target entity/relation to update
114
+ - Use `computeValue` to extract and return the new value from the event
115
+
84
116
  #### Decision Priority (check in order):
85
117
 
86
118
  1. **Check `controlType` first**:
87
119
  - `creation-only` → **_owner** (property controlled by entity/relation creation)
120
+ - `integration-result` → **StateMachine** (observes API Call entity, extracts from response)
88
121
  - `derived-with-parent` → **_owner** (property controlled by parent derivation)
89
122
  - `independent` → Continue to step 2
90
123
 
91
- 2. **If has `interactionDependencies` that can modify**:
124
+ 2. **Check `calculationMethod` for aggregate patterns**:
125
+ - Contains "sum of", "count of", "aggregate" keywords → `Custom` or aggregation
126
+ - Involves multiple Record entities (deposits/withdrawals) → `Custom`
127
+ - Example: balance = sum(RechargeRecord) - sum(DonationRecord) → `Custom`
128
+ - If found, use `Custom` or aggregation, **skip step 3**
129
+
130
+ 3. **If has `interactionDependencies` that can modify**:
92
131
  - Property changes in response to interactions → `StateMachine`
93
132
  - For timestamps: Use StateMachine with `computeValue`
94
133
  - For status fields: Use StateMachine with StateNodes
95
134
 
96
- 3. **If has `dataDependencies` (no interactions)**:
135
+ 4. **If has `dataDependencies` (no interactions)**:
97
136
  - Check `computationMethod` for aggregation type
98
137
  - Relations/entities involved → Use appropriate aggregation
99
138
 
100
- 4. **If uses only own entity properties**:
139
+ 5. **If uses only own entity properties**:
101
140
  - Simple derivation → `computed` function
102
141
  - Better performance than Custom
103
142
 
@@ -123,32 +162,39 @@ Based on `computationMethod` description:
123
162
  ## Automated Decision Process
124
163
 
125
164
  ### Step 1: Parse Input Files
126
- Read `data-design.json` and extract:
165
+ First, read the module name from `.currentmodule` file in project root to get the current module name.
166
+
167
+ Then read `requirements/{module}.data-design.json` and extract:
127
168
  - Entity definitions with their properties and lifecycle (creation and deletion)
128
169
  - Relation definitions with their lifecycle
129
170
  - Dictionary definitions
130
171
 
131
172
  ### Step 2: Apply Mapping Rules
132
173
  For each element:
133
- 1. Check lifecycle.creation.type and lifecycle.deletion for entities and relations
134
- 2. For properties, check controlType first:
174
+ 1. **For entities**: Check in this priority order:
175
+ - First check if `isIntegrationEvent: true` → set computation to "None" (externally controlled)
176
+ - Then check if `isAPICallEntity: true` → set computation to "Transform" (mutation-derived pattern)
177
+ - Then check lifecycle.creation.type and lifecycle.deletion
178
+ - For entities that can be hard-deleted, use Transform + HardDeletionProperty with StateMachine
179
+ 2. **For relations**: Check lifecycle.creation.type and lifecycle.deletion
180
+ - For relations that can be hard-deleted, use Transform + HardDeletionProperty with StateMachine
181
+ 3. **For properties**: Check controlType first (PRIORITY ORDER):
135
182
  - If `creation-only` or `derived-with-parent` → use `_owner`
183
+ - **If `integration-result` → DIRECTLY use `StateMachine` (no further analysis)**
136
184
  - If `independent` → apply standard dependency analysis rules
137
- 3. Apply the appropriate rules based on creation type
138
- 4. For entities/relations that can be hard-deleted, use Transform + HardDeletionProperty with StateMachine
139
185
 
140
186
  ### Step 3: Generate Output Document
141
187
 
142
- Create `docs/computation-analysis.json` with this structure:
188
+ Create `requirements/{module}.computation-analysis.json` (using the module name from `.currentmodule`) with this structure:
143
189
 
144
190
  ```json
145
191
  {
146
192
  "entities": [
147
193
  {
148
- "name": "<from data-design.json>",
194
+ "name": "<from requirements/{module}.data-design.json>",
149
195
  "entityAnalysis": {
150
- "purpose": "<from data-design.json>",
151
- "lifecycle": "<directly copy from lifecycle field in data-design.json>",
196
+ "purpose": "<from requirements/{module}.data-design.json>",
197
+ "lifecycle": "<directly copy from lifecycle field in requirements/{module}.data-design.json>",
152
198
  "computationDecision": "<Transform/_parent:[ParentName]/None based on rules>",
153
199
  "reasoning": "<automated based on lifecycle and deletion capability>",
154
200
  "calculationMethod": "<from computationMethod>"
@@ -156,14 +202,14 @@ Create `docs/computation-analysis.json` with this structure:
156
202
  "propertyAnalysis": [
157
203
  {
158
204
  "propertyName": "<property name>",
159
- "type": "<from data-design.json>",
160
- "purpose": "<from data-design.json>",
161
- "controlType": "<from data-design.json: creation-only/derived-with-parent/independent>",
205
+ "type": "<from requirements/{module}.data-design.json>",
206
+ "purpose": "<from requirements/{module}.data-design.json>",
207
+ "controlType": "<from requirements/{module}.data-design.json: creation-only/integration-result/derived-with-parent/independent>",
162
208
  "dataSource": "<from computationMethod>",
163
209
  "computationDecision": "<_owner/StateMachine/Count/etc. based on controlType and rules>",
164
210
  "reasoning": "<automated based on controlType and rules>",
165
211
  "dependencies": <convert dataDependencies to proper format>,
166
- "interactionDependencies": <from data-design.json>,
212
+ "interactionDependencies": <from requirements/{module}.data-design.json>,
167
213
  "calculationMethod": "<from computationMethod>"
168
214
  }
169
215
  ]
@@ -171,10 +217,10 @@ Create `docs/computation-analysis.json` with this structure:
171
217
  ],
172
218
  "relations": [
173
219
  {
174
- "name": "<from data-design.json>",
220
+ "name": "<from requirements/{module}.data-design.json>",
175
221
  "relationAnalysis": {
176
- "purpose": "<from data-design.json>",
177
- "lifecycle": "<directly copy from lifecycle field in data-design.json>",
222
+ "purpose": "<from requirements/{module}.data-design.json>",
223
+ "lifecycle": "<directly copy from lifecycle field in requirements/{module}.data-design.json>",
178
224
  "computationDecision": "<Transform/_parent:[ParentName] based on rules>",
179
225
  "reasoning": "<automated based on lifecycle>",
180
226
  "calculationMethod": "<from computationMethod>"
@@ -183,15 +229,15 @@ Create `docs/computation-analysis.json` with this structure:
183
229
  ],
184
230
  "dictionaries": [
185
231
  {
186
- "name": "<from data-design.json>",
232
+ "name": "<from requirements/{module}.data-design.json>",
187
233
  "dictionaryAnalysis": {
188
- "purpose": "<from data-design.json>",
189
- "type": "<from data-design.json>",
234
+ "purpose": "<from requirements/{module}.data-design.json>",
235
+ "type": "<from requirements/{module}.data-design.json>",
190
236
  "collection": "<determine from type>",
191
237
  "computationDecision": "<apply dictionary rules>",
192
238
  "reasoning": "<automated based on computationMethod>",
193
239
  "dependencies": <format properly>,
194
- "interactionDependencies": <from data-design.json>,
240
+ "interactionDependencies": <from requirements/{module}.data-design.json>,
195
241
  "calculationMethod": "<from computationMethod>"
196
242
  }
197
243
  }
@@ -218,12 +264,14 @@ Examples:
218
264
 
219
265
  ```
220
266
  1. Entity Lifecycle?
267
+ ├─ isIntegrationEvent: true? → None (externally controlled)
268
+ ├─ isAPICallEntity: true? → Transform (mutation-derived pattern)
221
269
  ├─ lifecycle.creation.type: "created-with-parent"? → _parent:[parent]
270
+ ├─ lifecycle.creation.type: "mutation-derived"? → Transform from record mutation event
222
271
  ├─ lifecycle.creation.type: "interaction-created" + canBeDeleted: true (hard)? → Transform + HardDeletionProperty with StateMachine
223
272
  ├─ lifecycle.creation.type: "interaction-created" + canBeDeleted: true (soft)? → Transform + status StateMachine
224
273
  ├─ lifecycle.creation.type: "interaction-created" + canBeDeleted: false? → Transform with InteractionEventEntity
225
274
  └─ lifecycle.creation.type: "derived"? → Transform from source entity
226
- └─ lifecycle.creation.type: "mutation-derived"? → Transform from record mutation event
227
275
 
228
276
  2. Relation Lifecycle?
229
277
  ├─ lifecycle.creation.type: "created-with-entity"? → _parent:[parent]
@@ -231,11 +279,14 @@ Examples:
231
279
  ├─ Needs audit trail? → Transform + status StateMachine (soft delete)
232
280
  └─ Never deleted? → Transform (if interaction-created) or _parent:[parent]
233
281
 
234
- 3. Property Value?
282
+ 3. Property Value? (🔴 NEVER Transform - Transform is ONLY for Entity/Relation)
235
283
  ├─ controlType: "creation-only"? → _owner (controlled by entity/relation)
284
+ ├─ controlType: "integration-result"? → StateMachine (observe API Call entity)
236
285
  ├─ controlType: "derived-with-parent"? → _owner (controlled by parent)
237
286
  ├─ controlType: "independent"?
287
+ │ ├─ calculationMethod has "sum of"/"count of"/"aggregate" or Record entities? → Custom or aggregation
238
288
  │ ├─ Has interactionDependencies that can modify? → StateMachine
289
+ │ ├─ Depends on Integration Event? → StateMachine with event trigger
239
290
  │ ├─ Has dataDependencies with relations? → Aggregation computation
240
291
  │ ├─ Only uses own properties? → computed
241
292
  │ └─ Complex with multiple entities? → Custom
@@ -255,11 +306,52 @@ Examples:
255
306
  - With defined transitions: Use StateMachine with StateNodes
256
307
  - Example: pending → approved/rejected
257
308
 
309
+ ### Integration Result Properties
310
+ **🔴 DIRECT RULE: `controlType: "integration-result"` → Always `StateMachine`**
311
+
312
+ Properties with `controlType: "integration-result"` are computed from external API/integration results:
313
+ - **Pattern**: Extract values from API Call entity's response data
314
+ - **Computation**: Always use `StateMachine`
315
+ - **Trigger**: Observe API Call entity creation/update events
316
+ - **Logic**:
317
+ - Use `computeTarget` to find the business entity that owns this property
318
+ - Use `computeValue` to extract the result from API Call entity's response field
319
+ - Typically extract from the LATEST successful API Call (status='completed')
320
+
321
+ **Example**:
322
+ ```json
323
+ {
324
+ "propertyName": "voiceUrl",
325
+ "controlType": "integration-result",
326
+ "dataDependencies": ["TTSAPICall.responseData", "TTSAPICall.status"],
327
+ "computationDecision": "StateMachine",
328
+ "reasoning": "controlType is 'integration-result' - directly maps to StateMachine to observe API Call entity"
329
+ }
330
+ ```
331
+
332
+ **Implementation notes**:
333
+ - Monitor related API Call entity (via relation) for updates
334
+ - Extract result when API Call reaches completed status
335
+ - Handle multiple API Call attempts (retries) by using the latest successful one
336
+
258
337
  ### Counts and Aggregations
259
338
  - Simple counts: Use `Count`
260
339
  - Sums: Use `Summation`
261
340
  - Calculated totals (price × quantity): Use `WeightedSummation`
262
341
 
342
+ ### Balance/Accumulation Properties
343
+ **🔴 CRITICAL**: Properties that aggregate from transaction records should use `Custom`, NOT `StateMachine`
344
+ - Pattern: `balance = sum(deposits) - sum(withdrawals)`
345
+ - Examples:
346
+ - `UserGiftProfile.giftBalance = sum(RechargeRecord.amount) - sum(DonationRecord.giftAmount)`
347
+ - `Account.balance = sum(CreditRecord.amount) - sum(DebitRecord.amount)`
348
+ - `Inventory.stockLevel = sum(PurchaseOrder.quantity) - sum(SalesOrder.quantity)`
349
+ - **How to identify**:
350
+ - `calculationMethod` contains "sum of", "aggregate", "increased by", "decreased by"
351
+ - Involves multiple Record entities (entities ending in "Record", "Transaction", "Event")
352
+ - Even if has `interactionDependencies`, prioritize aggregation over StateMachine
353
+ - Use `Custom` computation to aggregate from related records reactively
354
+
263
355
  ### Deletion Patterns
264
356
 
265
357
  #### For Entities:
@@ -278,23 +370,31 @@ Examples:
278
370
  ## Validation
279
371
 
280
372
  Before finalizing, verify:
281
- 1. Every entity with `interactionDependencies` has appropriate computation:
373
+ 1. **🔴 CRITICAL**: NO property has `computationDecision: "Transform"` - Transform is ONLY for Entity/Relation
374
+ 2. Every entity with `isIntegrationEvent: true` has `computationDecision: "None"` or no computation
375
+ 3. Every entity with `isAPICallEntity: true` has `computationDecision: "Transform"`
376
+ 4. Every entity with `interactionDependencies` has appropriate computation:
282
377
  - If `canBeDeleted: true` with `hard-delete` → Must use Transform + HardDeletionProperty with StateMachine
283
- - If `canBeDeleted: false` → Can use Transform (unless `created-with-parent`)
284
- 2. Entities/relations with `lifecycle.creation.type: "created-with-parent/entity"` use `_parent:[ParentName]`
285
- 3. Properties with `controlType: "creation-only"` or `"derived-with-parent"` have computation `_owner`
286
- 4. Properties with `controlType: "independent"` are analyzed for appropriate computation
287
- 5. Properties with modifying `interactionDependencies` use StateMachine (if `controlType: "independent"`)
288
- 6. Properties with only `dataDependencies` use data-based computation (if `controlType: "independent"`)
289
- 7. All entities or relations with `canBeDeleted:true` and `hard-delete` use Transform + HardDeletionProperty
290
- 8. All dependencies are properly formatted with specific properties
291
- 9. `InteractionEventEntity` is included when interactions are dependencies
292
- 10. The parent name in `_parent:[ParentName]` matches `lifecycle.creation.parent`
378
+ - If `canBeDeleted: false` → Can use Transform (unless `created-with-parent` or `integration-event`)
379
+ 5. Entities/relations with `lifecycle.creation.type: "created-with-parent/entity"` use `_parent:[ParentName]`
380
+ 6. Properties with `controlType: "creation-only"` or `"derived-with-parent"` have computation `_owner`
381
+ 7. Properties with `controlType: "integration-result"` use `StateMachine` to observe API Call entities
382
+ 8. Properties with `controlType: "independent"` are analyzed for appropriate computation
383
+ 9. Properties with modifying `interactionDependencies` use StateMachine (if `controlType: "independent"`)
384
+ 10. Properties that depend on Integration Events use StateMachine with event triggers (NOT Transform)
385
+ 11. Properties with only `dataDependencies` use data-based computation (if `controlType: "independent"`)
386
+ 12. All entities or relations with `canBeDeleted:true` and `hard-delete` use Transform + HardDeletionProperty
387
+ 13. All dependencies are properly formatted with specific properties
388
+ 14. `InteractionEventEntity` is included when interactions are dependencies
389
+ 15. The parent name in `_parent:[ParentName]` matches `lifecycle.creation.parent`
293
390
 
294
391
 
295
392
  ## Implementation Checklist
296
393
 
297
- - [ ] Parse `data-design.json` completely
394
+ - [ ] Read module name from `.currentmodule` file in project root
395
+ - [ ] Parse `requirements/{module}.data-design.json` completely
396
+ - [ ] Check for entities with `isIntegrationEvent: true` and set computation to "None"
397
+ - [ ] Check for entities with `isAPICallEntity: true` and set computation to "Transform"
298
398
  - [ ] Apply mapping rules for every entity (check deletion capability)
299
399
  - [ ] Check `controlType` for every property first
300
400
  - [ ] Apply mapping rules for properties based on `controlType`
@@ -304,6 +404,7 @@ Before finalizing, verify:
304
404
  - [ ] Separate `dependencies` and `interactionDependencies`
305
405
  - [ ] Add `InteractionEventEntity` when needed
306
406
  - [ ] Verify properties with `controlType: "creation-only"` or `"derived-with-parent"` use `_owner`
407
+ - [ ] Verify entities with `lifecycle.creation.type: "integration-event"` have no computation
307
408
  - [ ] Verify Transform + HardDeletionProperty is used for deletable entities (hard-delete)
308
409
  - [ ] Verify Transform + HardDeletionProperty is used for deletable relations (hard-delete)
309
- - [ ] Generate complete `computation-analysis.json`
410
+ - [ ] Generate complete `requirements/{module}.computation-analysis.json`