interaqt 0.1.0 → 0.2.1
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/agent/.claude/agents/code-generation-handler.md +598 -0
- package/agent/.claude/agents/computation-generation-handler.md +290 -0
- package/agent/.claude/agents/implement-design-handler.md +179 -0
- package/agent/.claude/agents/permission-generation-handler.md +202 -0
- package/agent/.claude/agents/requirements-analysis-handler-bak.md +530 -0
- package/agent/.claude/agents/requirements-analysis-handler.md +720 -0
- package/agent/.claude/settings.local.json +46 -0
- package/agent/CLAUDE.md +72 -0
- package/dist/index.js +10508 -4
- package/dist/index.js.map +1 -1
- package/dist/runtime/ComputationSourceMap.d.ts +117 -0
- package/dist/runtime/ComputationSourceMap.d.ts.map +1 -0
- package/dist/runtime/Controller.d.ts +37 -26
- package/dist/runtime/Controller.d.ts.map +1 -1
- package/dist/runtime/ExternalSynchronizer.d.ts +6 -0
- package/dist/runtime/ExternalSynchronizer.d.ts.map +1 -0
- package/dist/runtime/MonoSystem.d.ts +29 -17
- package/dist/runtime/MonoSystem.d.ts.map +1 -1
- package/dist/runtime/Mysql.d.ts +2 -2
- package/dist/runtime/PGLite.d.ts +35 -0
- package/dist/runtime/PGLite.d.ts.map +1 -0
- package/dist/runtime/PostgreSQL.d.ts +2 -2
- package/dist/runtime/SQLite.d.ts +3 -3
- package/dist/runtime/SQLite.d.ts.map +1 -1
- package/dist/runtime/Scheduler.d.ts +28 -61
- package/dist/runtime/Scheduler.d.ts.map +1 -1
- package/dist/runtime/System.d.ts +18 -224
- package/dist/runtime/System.d.ts.map +1 -1
- package/dist/runtime/{ActivityCall.d.ts → activity/ActivityCall.d.ts} +6 -7
- package/dist/runtime/activity/ActivityCall.d.ts.map +1 -0
- package/dist/runtime/activity/ActivityManager.d.ts +44 -0
- package/dist/runtime/activity/ActivityManager.d.ts.map +1 -0
- package/dist/runtime/{InteractionCall.d.ts → activity/InteractionCall.d.ts} +28 -41
- package/dist/runtime/activity/InteractionCall.d.ts.map +1 -0
- package/dist/runtime/computations/Any.d.ts +71 -0
- package/dist/runtime/computations/Any.d.ts.map +1 -0
- package/dist/runtime/computations/Average.d.ts +69 -0
- package/dist/runtime/computations/Average.d.ts.map +1 -0
- package/dist/runtime/computations/Computation.d.ts +138 -0
- package/dist/runtime/computations/Computation.d.ts.map +1 -0
- package/dist/runtime/computations/Count.d.ts +73 -0
- package/dist/runtime/computations/Count.d.ts.map +1 -0
- package/dist/runtime/computations/Custom.d.ts +45 -0
- package/dist/runtime/computations/Custom.d.ts.map +1 -0
- package/dist/runtime/computations/Every.d.ts +74 -0
- package/dist/runtime/computations/Every.d.ts.map +1 -0
- package/dist/runtime/computations/MathResolver.d.ts +60 -0
- package/dist/runtime/computations/MathResolver.d.ts.map +1 -0
- package/dist/runtime/computations/RealTime.d.ts +66 -0
- package/dist/runtime/computations/RealTime.d.ts.map +1 -0
- package/dist/runtime/{computedDataHandles → computations}/StateMachine.d.ts +31 -22
- package/dist/runtime/computations/StateMachine.d.ts.map +1 -0
- package/dist/runtime/computations/Summation.d.ts +66 -0
- package/dist/runtime/computations/Summation.d.ts.map +1 -0
- package/dist/runtime/computations/Transform.d.ts +29 -0
- package/dist/runtime/computations/Transform.d.ts.map +1 -0
- package/dist/runtime/computations/TransitionFinder.d.ts +11 -0
- package/dist/runtime/computations/TransitionFinder.d.ts.map +1 -0
- package/dist/runtime/computations/WeightedSummation.d.ts +71 -0
- package/dist/runtime/computations/WeightedSummation.d.ts.map +1 -0
- package/dist/runtime/computations/index.d.ts +22 -0
- package/dist/runtime/computations/index.d.ts.map +1 -0
- package/dist/runtime/errors/ActivityErrors.d.ts +40 -0
- package/dist/runtime/errors/ActivityErrors.d.ts.map +1 -0
- package/dist/runtime/errors/ComputationErrors.d.ts +61 -0
- package/dist/runtime/errors/ComputationErrors.d.ts.map +1 -0
- package/dist/runtime/errors/ConditionErrors.d.ts +33 -0
- package/dist/runtime/errors/ConditionErrors.d.ts.map +1 -0
- package/dist/runtime/errors/FrameworkError.d.ts +77 -0
- package/dist/runtime/errors/FrameworkError.d.ts.map +1 -0
- package/dist/runtime/errors/InteractionErrors.d.ts +21 -0
- package/dist/runtime/errors/InteractionErrors.d.ts.map +1 -0
- package/dist/runtime/errors/SystemErrors.d.ts +16 -0
- package/dist/runtime/errors/SystemErrors.d.ts.map +1 -0
- package/dist/runtime/errors/index.d.ts +37 -0
- package/dist/runtime/errors/index.d.ts.map +1 -0
- package/dist/runtime/index.d.ts +9 -7
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/shared/Action.d.ts +38 -0
- package/dist/shared/Action.d.ts.map +1 -0
- package/dist/shared/Activity.d.ts +178 -0
- package/dist/shared/Activity.d.ts.map +1 -0
- package/dist/shared/Any.d.ts +82 -0
- package/dist/shared/Any.d.ts.map +1 -0
- package/dist/shared/Attributive.d.ts +92 -0
- package/dist/shared/Attributive.d.ts.map +1 -0
- package/dist/shared/Average.d.ts +59 -0
- package/dist/shared/Average.d.ts.map +1 -0
- package/dist/shared/BoolExp.d.ts +139 -63
- package/dist/shared/BoolExp.d.ts.map +1 -1
- package/dist/shared/Computation.d.ts +23 -0
- package/dist/shared/Computation.d.ts.map +1 -0
- package/dist/shared/Condition.d.ts +43 -0
- package/dist/shared/Condition.d.ts.map +1 -0
- package/dist/shared/Conditions.d.ts +38 -0
- package/dist/shared/Conditions.d.ts.map +1 -0
- package/dist/shared/Count.d.ts +77 -0
- package/dist/shared/Count.d.ts.map +1 -0
- package/dist/shared/Custom.d.ts +108 -0
- package/dist/shared/Custom.d.ts.map +1 -0
- package/dist/shared/Data.d.ts +121 -0
- package/dist/shared/Data.d.ts.map +1 -0
- package/dist/shared/DataAttributives.d.ts +38 -0
- package/dist/shared/DataAttributives.d.ts.map +1 -0
- package/dist/shared/Entity.d.ts +96 -0
- package/dist/shared/Entity.d.ts.map +1 -0
- package/dist/shared/Event.d.ts +36 -0
- package/dist/shared/Event.d.ts.map +1 -0
- package/dist/shared/Every.d.ts +85 -0
- package/dist/shared/Every.d.ts.map +1 -0
- package/dist/shared/Gateway.d.ts +36 -0
- package/dist/shared/Gateway.d.ts.map +1 -0
- package/dist/shared/Interaction.d.ts +108 -0
- package/dist/shared/Interaction.d.ts.map +1 -0
- package/dist/shared/Payload.d.ts +39 -0
- package/dist/shared/Payload.d.ts.map +1 -0
- package/dist/shared/PayloadItem.d.ts +85 -0
- package/dist/shared/PayloadItem.d.ts.map +1 -0
- package/dist/shared/Property.d.ts +83 -0
- package/dist/shared/Property.d.ts.map +1 -0
- package/dist/shared/RealDictionary.d.ts +94 -0
- package/dist/shared/RealDictionary.d.ts.map +1 -0
- package/dist/shared/RealTime.d.ts +66 -0
- package/dist/shared/RealTime.d.ts.map +1 -0
- package/dist/shared/RefContainer.d.ts +89 -0
- package/dist/shared/RefContainer.d.ts.map +1 -0
- package/dist/shared/Relation.d.ts +140 -0
- package/dist/shared/Relation.d.ts.map +1 -0
- package/dist/shared/SideEffect.d.ts +45 -0
- package/dist/shared/SideEffect.d.ts.map +1 -0
- package/dist/shared/StateMachine.d.ts +55 -0
- package/dist/shared/StateMachine.d.ts.map +1 -0
- package/dist/shared/StateNode.d.ts +45 -0
- package/dist/shared/StateNode.d.ts.map +1 -0
- package/dist/shared/StateTransfer.d.ts +63 -0
- package/dist/shared/StateTransfer.d.ts.map +1 -0
- package/dist/shared/Summation.d.ts +59 -0
- package/dist/shared/Summation.d.ts.map +1 -0
- package/dist/shared/Transform.d.ts +54 -0
- package/dist/shared/Transform.d.ts.map +1 -0
- package/dist/shared/User.d.ts +10 -0
- package/dist/shared/User.d.ts.map +1 -0
- package/dist/shared/WeightedSummation.d.ts +82 -0
- package/dist/shared/WeightedSummation.d.ts.map +1 -0
- package/dist/shared/index.d.ts +35 -9
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/init.d.ts +3 -0
- package/dist/shared/init.d.ts.map +1 -0
- package/dist/shared/interfaces.d.ts +72 -0
- package/dist/shared/interfaces.d.ts.map +1 -0
- package/dist/shared/types.d.ts +77 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/utils.d.ts +16 -10
- package/dist/shared/utils.d.ts.map +1 -1
- package/dist/storage/erstorage/AttributeInfo.d.ts +8 -3
- package/dist/storage/erstorage/AttributeInfo.d.ts.map +1 -1
- package/dist/storage/erstorage/AttributeQuery.d.ts +4 -3
- package/dist/storage/erstorage/AttributeQuery.d.ts.map +1 -1
- package/dist/storage/erstorage/EntityQueryHandle.d.ts +18 -17
- package/dist/storage/erstorage/EntityQueryHandle.d.ts.map +1 -1
- package/dist/storage/erstorage/EntityToTableMap.d.ts +27 -5
- package/dist/storage/erstorage/EntityToTableMap.d.ts.map +1 -1
- package/dist/storage/erstorage/FilteredEntityManager.d.ts +70 -0
- package/dist/storage/erstorage/FilteredEntityManager.d.ts.map +1 -0
- package/dist/storage/erstorage/LinkInfo.d.ts +10 -3
- package/dist/storage/erstorage/LinkInfo.d.ts.map +1 -1
- package/dist/storage/erstorage/MatchExp.d.ts +19 -9
- package/dist/storage/erstorage/MatchExp.d.ts.map +1 -1
- package/dist/storage/erstorage/MergedItemProcessor.d.ts +25 -0
- package/dist/storage/erstorage/MergedItemProcessor.d.ts.map +1 -0
- package/dist/storage/erstorage/Modifier.d.ts +1 -1
- package/dist/storage/erstorage/NewRecordData.d.ts +16 -9
- package/dist/storage/erstorage/NewRecordData.d.ts.map +1 -1
- package/dist/storage/erstorage/RecordInfo.d.ts +11 -2
- package/dist/storage/erstorage/RecordInfo.d.ts.map +1 -1
- package/dist/storage/erstorage/RecordQuery.d.ts +9 -8
- package/dist/storage/erstorage/RecordQuery.d.ts.map +1 -1
- package/dist/storage/erstorage/RecordQueryAgent.d.ts +26 -13
- package/dist/storage/erstorage/RecordQueryAgent.d.ts.map +1 -1
- package/dist/storage/erstorage/Setup.d.ts +49 -11
- package/dist/storage/erstorage/Setup.d.ts.map +1 -1
- package/dist/storage/erstorage/util.d.ts.map +1 -1
- package/package.json +44 -20
- package/README.md +0 -53
- package/dist/runtime/ActivityCall.d.ts.map +0 -1
- package/dist/runtime/ActivityCall.js +0 -379
- package/dist/runtime/ActivityCall.js.map +0 -1
- package/dist/runtime/Controller.js +0 -225
- package/dist/runtime/Controller.js.map +0 -1
- package/dist/runtime/InteractionCall.d.ts.map +0 -1
- package/dist/runtime/InteractionCall.js +0 -385
- package/dist/runtime/InteractionCall.js.map +0 -1
- package/dist/runtime/MonoSystem.js +0 -331
- package/dist/runtime/MonoSystem.js.map +0 -1
- package/dist/runtime/Mysql.js +0 -171
- package/dist/runtime/Mysql.js.map +0 -1
- package/dist/runtime/PostgreSQL.js +0 -172
- package/dist/runtime/PostgreSQL.js.map +0 -1
- package/dist/runtime/SQLite.js +0 -146
- package/dist/runtime/SQLite.js.map +0 -1
- package/dist/runtime/Scheduler.js +0 -457
- package/dist/runtime/Scheduler.js.map +0 -1
- package/dist/runtime/System.js +0 -90
- package/dist/runtime/System.js.map +0 -1
- package/dist/runtime/asyncInteractionContext.js +0 -3
- package/dist/runtime/asyncInteractionContext.js.map +0 -1
- package/dist/runtime/boolExpression.js +0 -43
- package/dist/runtime/boolExpression.js.map +0 -1
- package/dist/runtime/computedDataHandles/Any.d.ts +0 -52
- package/dist/runtime/computedDataHandles/Any.d.ts.map +0 -1
- package/dist/runtime/computedDataHandles/Any.js +0 -152
- package/dist/runtime/computedDataHandles/Any.js.map +0 -1
- package/dist/runtime/computedDataHandles/Computation.d.ts +0 -108
- package/dist/runtime/computedDataHandles/Computation.d.ts.map +0 -1
- package/dist/runtime/computedDataHandles/Computation.js +0 -49
- package/dist/runtime/computedDataHandles/Computation.js.map +0 -1
- package/dist/runtime/computedDataHandles/ComputedDataHandle.d.ts +0 -42
- package/dist/runtime/computedDataHandles/ComputedDataHandle.d.ts.map +0 -1
- package/dist/runtime/computedDataHandles/ComputedDataHandle.js +0 -4
- package/dist/runtime/computedDataHandles/ComputedDataHandle.js.map +0 -1
- package/dist/runtime/computedDataHandles/Count.d.ts +0 -45
- package/dist/runtime/computedDataHandles/Count.d.ts.map +0 -1
- package/dist/runtime/computedDataHandles/Count.js +0 -85
- package/dist/runtime/computedDataHandles/Count.js.map +0 -1
- package/dist/runtime/computedDataHandles/Every.d.ts +0 -56
- package/dist/runtime/computedDataHandles/Every.d.ts.map +0 -1
- package/dist/runtime/computedDataHandles/Every.js +0 -178
- package/dist/runtime/computedDataHandles/Every.js.map +0 -1
- package/dist/runtime/computedDataHandles/StateMachine.d.ts.map +0 -1
- package/dist/runtime/computedDataHandles/StateMachine.js +0 -180
- package/dist/runtime/computedDataHandles/StateMachine.js.map +0 -1
- package/dist/runtime/computedDataHandles/Transform.d.ts +0 -26
- package/dist/runtime/computedDataHandles/Transform.d.ts.map +0 -1
- package/dist/runtime/computedDataHandles/Transform.js +0 -106
- package/dist/runtime/computedDataHandles/Transform.js.map +0 -1
- package/dist/runtime/computedDataHandles/TransitionFinder.d.ts +0 -57
- package/dist/runtime/computedDataHandles/TransitionFinder.d.ts.map +0 -1
- package/dist/runtime/computedDataHandles/TransitionFinder.js +0 -40
- package/dist/runtime/computedDataHandles/TransitionFinder.js.map +0 -1
- package/dist/runtime/computedDataHandles/WeightedSummation.d.ts +0 -57
- package/dist/runtime/computedDataHandles/WeightedSummation.d.ts.map +0 -1
- package/dist/runtime/computedDataHandles/WeightedSummation.js +0 -146
- package/dist/runtime/computedDataHandles/WeightedSummation.js.map +0 -1
- package/dist/runtime/computedDataHandles/index.d.ts +0 -7
- package/dist/runtime/computedDataHandles/index.d.ts.map +0 -1
- package/dist/runtime/computedDataHandles/index.js +0 -7
- package/dist/runtime/computedDataHandles/index.js.map +0 -1
- package/dist/runtime/index.js +0 -15
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/server.d.ts +0 -35
- package/dist/runtime/server.d.ts.map +0 -1
- package/dist/runtime/server.js +0 -171
- package/dist/runtime/server.js.map +0 -1
- package/dist/runtime/types/boolExpression.js +0 -6
- package/dist/runtime/types/boolExpression.js.map +0 -1
- package/dist/runtime/util.js +0 -39
- package/dist/runtime/util.js.map +0 -1
- package/dist/shared/BoolExp.js +0 -252
- package/dist/shared/BoolExp.js.map +0 -1
- package/dist/shared/activity/Activity.d.ts +0 -465
- package/dist/shared/activity/Activity.d.ts.map +0 -1
- package/dist/shared/activity/Activity.js +0 -264
- package/dist/shared/activity/Activity.js.map +0 -1
- package/dist/shared/activity/Condition.d.ts +0 -75
- package/dist/shared/activity/Condition.d.ts.map +0 -1
- package/dist/shared/activity/Condition.js +0 -51
- package/dist/shared/activity/Condition.js.map +0 -1
- package/dist/shared/activity/Data.d.ts +0 -115
- package/dist/shared/activity/Data.d.ts.map +0 -1
- package/dist/shared/activity/Data.js +0 -89
- package/dist/shared/activity/Data.js.map +0 -1
- package/dist/shared/attributive.d.ts +0 -93
- package/dist/shared/attributive.d.ts.map +0 -1
- package/dist/shared/attributive.js +0 -59
- package/dist/shared/attributive.js.map +0 -1
- package/dist/shared/computed.d.ts +0 -607
- package/dist/shared/computed.d.ts.map +0 -1
- package/dist/shared/computed.js +0 -202
- package/dist/shared/computed.js.map +0 -1
- package/dist/shared/createClass.d.ts +0 -102
- package/dist/shared/createClass.d.ts.map +0 -1
- package/dist/shared/createClass.js +0 -276
- package/dist/shared/createClass.js.map +0 -1
- package/dist/shared/dictionary/Dictionary.d.ts +0 -40
- package/dist/shared/dictionary/Dictionary.d.ts.map +0 -1
- package/dist/shared/dictionary/Dictionary.js +0 -51
- package/dist/shared/dictionary/Dictionary.js.map +0 -1
- package/dist/shared/entity/Entity.d.ts +0 -149
- package/dist/shared/entity/Entity.d.ts.map +0 -1
- package/dist/shared/entity/Entity.js +0 -226
- package/dist/shared/entity/Entity.js.map +0 -1
- package/dist/shared/index.js +0 -11
- package/dist/shared/index.js.map +0 -1
- package/dist/shared/user/User.d.ts +0 -21
- package/dist/shared/user/User.d.ts.map +0 -1
- package/dist/shared/user/User.js +0 -11
- package/dist/shared/user/User.js.map +0 -1
- package/dist/shared/utils.js +0 -19
- package/dist/shared/utils.js.map +0 -1
- package/dist/storage/erstorage/AttributeInfo.js +0 -147
- package/dist/storage/erstorage/AttributeInfo.js.map +0 -1
- package/dist/storage/erstorage/AttributeQuery.js +0 -190
- package/dist/storage/erstorage/AttributeQuery.js.map +0 -1
- package/dist/storage/erstorage/EntityQueryHandle.js +0 -78
- package/dist/storage/erstorage/EntityQueryHandle.js.map +0 -1
- package/dist/storage/erstorage/EntityToTableMap.js +0 -262
- package/dist/storage/erstorage/EntityToTableMap.js.map +0 -1
- package/dist/storage/erstorage/LinkInfo.js +0 -89
- package/dist/storage/erstorage/LinkInfo.js.map +0 -1
- package/dist/storage/erstorage/MatchExp.js +0 -211
- package/dist/storage/erstorage/MatchExp.js.map +0 -1
- package/dist/storage/erstorage/Modifier.js +0 -24
- package/dist/storage/erstorage/Modifier.js.map +0 -1
- package/dist/storage/erstorage/NewRecordData.js +0 -178
- package/dist/storage/erstorage/NewRecordData.js.map +0 -1
- package/dist/storage/erstorage/RecordInfo.js +0 -111
- package/dist/storage/erstorage/RecordInfo.js.map +0 -1
- package/dist/storage/erstorage/RecordQuery.js +0 -158
- package/dist/storage/erstorage/RecordQuery.js.map +0 -1
- package/dist/storage/erstorage/RecordQueryAgent.js +0 -1130
- package/dist/storage/erstorage/RecordQueryAgent.js.map +0 -1
- package/dist/storage/erstorage/Setup.js +0 -400
- package/dist/storage/erstorage/Setup.js.map +0 -1
- package/dist/storage/erstorage/util.js +0 -25
- package/dist/storage/erstorage/util.js.map +0 -1
- package/dist/storage/index.js +0 -13
- package/dist/storage/index.js.map +0 -1
- package/dist/storage/utils.js +0 -48
- package/dist/storage/utils.js.map +0 -1
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: computation-generation-handler
|
|
3
|
+
description: when task 3.1.4.3
|
|
4
|
+
model: inherit
|
|
5
|
+
color: blue
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
**⚠️ IMPORTANT: Strictly follow the steps below to execute the task. Do not compress content or skip any steps.**
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## START: Select Next Uncompleted Item
|
|
12
|
+
|
|
13
|
+
**📖 Reference:** `./agentspace/knowledge/generator/computation-implementation.md` - Detailed computation implementation patterns and examples
|
|
14
|
+
|
|
15
|
+
**🔴 CRITICAL: Implement ONLY ONE computation per session, then STOP and wait for user confirmation.**
|
|
16
|
+
|
|
17
|
+
1. **Read `docs/computation-implementation-plan.json`** to find the FIRST item with `completed: false`
|
|
18
|
+
- ALWAYS select the FIRST item where `completed` field is `false`
|
|
19
|
+
- NEVER skip ahead - dependencies must be completed in order
|
|
20
|
+
- Phase 1 must complete before Phase 2, etc.
|
|
21
|
+
|
|
22
|
+
2. **Check if item has `lastError` field:**
|
|
23
|
+
- If YES → Execute DEEP DEBUG MODE below
|
|
24
|
+
- If NO → Execute NORMAL IMPLEMENTATION FLOW below
|
|
25
|
+
|
|
26
|
+
## DEEP DEBUG MODE (when lastError exists):
|
|
27
|
+
|
|
28
|
+
1. **Review Previous Error**: Read the error document at the path in `lastError` to understand what failed and what was already attempted
|
|
29
|
+
|
|
30
|
+
2. **Analyze Root Cause**:
|
|
31
|
+
- Verify implementation code correctness
|
|
32
|
+
- Check all `expandedDependencies` are properly handled
|
|
33
|
+
- Cross-reference with `requirements/interaction-matrix.md` for business logic
|
|
34
|
+
- Confirm test expectations match business requirements
|
|
35
|
+
- Review similar successful computations for patterns
|
|
36
|
+
|
|
37
|
+
3. **Apply Fix Based on Analysis**:
|
|
38
|
+
- **Implementation Issue** → Fix computation code in backend/index.ts (refer to API reference)
|
|
39
|
+
- **Test Issue** → Fix test case logic or expectations
|
|
40
|
+
- **Dependency Issue** → Fix data creation order
|
|
41
|
+
- **Business Logic Issue** → Re-read requirements and adjust
|
|
42
|
+
|
|
43
|
+
4. **Test the Fix**:
|
|
44
|
+
- Run `npm run check` for type verification
|
|
45
|
+
- Run the specific test
|
|
46
|
+
- If successful: Remove `lastError` field, mark `"completed": true`, return to START
|
|
47
|
+
- If still failing: Update error document with new attempts
|
|
48
|
+
- After 3 additional attempts, STOP and wait for user guidance
|
|
49
|
+
|
|
50
|
+
## NORMAL IMPLEMENTATION FLOW (when no lastError):
|
|
51
|
+
|
|
52
|
+
**🔴 CRITICAL: You MUST strictly follow the steps below to update the todo list and strictly adhere to each step's requirements and standards. Do not skip or modify any step.**
|
|
53
|
+
|
|
54
|
+
1. **Implement the Computation** (following API Reference)
|
|
55
|
+
- **📖 MANDATORY FIRST STEP: Completely read `./agentspace/knowledge/generator/api-reference.md` to understand all API usage before writing any code**
|
|
56
|
+
- **📖 MANDATORY SECOND STEP: Completely read `./backend/index.ts` to understand all existing implementations from previous tasks**
|
|
57
|
+
- **🔴 SPECIAL CASE 1: `_parent:[parent]` notation**
|
|
58
|
+
- If the computation name contains `_parent:[parent]` (e.g., `_parent:[User]`), this means:
|
|
59
|
+
- You should modify the PARENT entity's computation, not the current entity
|
|
60
|
+
- Example: For `_parent:[User]`, modify the `User` entity's computation that creates Posts
|
|
61
|
+
- This typically occurs when a child entity needs to be created by a parent's Transform computation
|
|
62
|
+
- **How to create child entities**: Use the relation's source/target property name in the parent's Transform return value
|
|
63
|
+
- Example: If `OrderItemRelation` has `sourceProperty: 'items'`, then in Order's Transform:
|
|
64
|
+
```typescript
|
|
65
|
+
Order.computation = Transform.create({
|
|
66
|
+
record: InteractionEventEntity,
|
|
67
|
+
callback: function(event) {
|
|
68
|
+
if (event.interactionName === 'CreateOrder') {
|
|
69
|
+
return {
|
|
70
|
+
orderNumber: event.payload.orderNumber,
|
|
71
|
+
customerName: event.payload.customerName,
|
|
72
|
+
items: event.payload.items // Creates OrderItem entities via 'items' relation property
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
- **🔴 SPECIAL CASE 2: `_owner` notation**
|
|
80
|
+
- If the computation decision is `_owner`, this means:
|
|
81
|
+
- The property's value is fully controlled by its owner entity/relation's computation
|
|
82
|
+
- You should modify the OWNER entity/relation's creation or derivation logic, not add a separate property computation
|
|
83
|
+
- For `controlType: "creation-only"`: Add the property assignment logic in the entity/relation's creation Transform or StateMachine
|
|
84
|
+
- For `controlType: "derived-with-parent"`: The property is part of the parent's derivation computation
|
|
85
|
+
- Example: For a `createdAt` property with `_owner`, add timestamp assignment in the entity's Transform that creates it
|
|
86
|
+
- Add computation code using assignment pattern at end of file:
|
|
87
|
+
```typescript
|
|
88
|
+
// At end of backend/index.ts, after exports:
|
|
89
|
+
|
|
90
|
+
// Normal property computation
|
|
91
|
+
User.properties.find(p => p.name === 'postCount').computation = Count.create({
|
|
92
|
+
property: 'posts'
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
// For _owner properties, modify the owner entity's computation instead:
|
|
96
|
+
Post.computationTarget = Transform.create({
|
|
97
|
+
items: [
|
|
98
|
+
TransformItem.create({
|
|
99
|
+
from: 'InteractionEventEntity',
|
|
100
|
+
name: 'event',
|
|
101
|
+
transform: async function(this: Controller, event: InteractionEventEntity) {
|
|
102
|
+
if (event.interaction === 'CreatePost') {
|
|
103
|
+
// Create the Post entity with _owner properties
|
|
104
|
+
return {
|
|
105
|
+
title: event.payload.title,
|
|
106
|
+
content: event.payload.content,
|
|
107
|
+
createdAt: Math.floor(Date.now() / 1000), // _owner property set here
|
|
108
|
+
status: 'draft' // _owner property set here
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return null
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
- Remove any `defaultValue` if adding computation to that property
|
|
118
|
+
- Never use Transform in Property computation
|
|
119
|
+
- For `_owner` properties, always set them in the owner's creation/derivation logic
|
|
120
|
+
|
|
121
|
+
2. **Type Check**
|
|
122
|
+
- Run `npm run check`
|
|
123
|
+
- Fix all type errors before proceeding to tests
|
|
124
|
+
|
|
125
|
+
3. **Create Test Case Plan**
|
|
126
|
+
- Read item details from `docs/computation-implementation-plan.json`
|
|
127
|
+
- Check `expandedDependencies` to understand all required dependencies
|
|
128
|
+
- Write test plan comment with: dependencies, test steps, business logic notes
|
|
129
|
+
- Cross-reference with `requirements/interaction-matrix.md` and `docs/data-design.json`
|
|
130
|
+
- **🔴 For `_parent:[parent]` computations**: Test the parent entity's behavior that creates/manages the child entities
|
|
131
|
+
- **🔴 For `_owner` computations**: Test that the property is correctly set when the owner entity/relation is created
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
test('User.dormitoryCount computation', async () => {
|
|
135
|
+
/**
|
|
136
|
+
* Test Plan for: User.dormitoryCount
|
|
137
|
+
* Dependencies: User entity, UserDormitoryRelation
|
|
138
|
+
* Steps: 1) Create user 2) Create dormitories 3) Create relations 4) Verify count
|
|
139
|
+
* Business Logic: Count of dormitories user is assigned to
|
|
140
|
+
*/
|
|
141
|
+
// Implementation...
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
// For _parent:[parent] computations:
|
|
145
|
+
test('Post creation through User Transform (_parent:[User])', async () => {
|
|
146
|
+
/**
|
|
147
|
+
* Test Plan for: _parent:[User]
|
|
148
|
+
* This tests the User's Transform computation that creates Posts
|
|
149
|
+
* Steps: 1) Trigger interaction that creates User 2) Verify Posts are created
|
|
150
|
+
* Business Logic: User's Transform creates related Posts
|
|
151
|
+
*/
|
|
152
|
+
// Implementation...
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
// For _owner computations:
|
|
156
|
+
test('Post.createdAt set by owner computation (_owner)', async () => {
|
|
157
|
+
/**
|
|
158
|
+
* Test Plan for: _owner
|
|
159
|
+
* This tests that createdAt is properly set when Post is created
|
|
160
|
+
* Steps: 1) Trigger interaction that creates Post 2) Verify createdAt is set
|
|
161
|
+
* Business Logic: Post's creation computation sets createdAt timestamp
|
|
162
|
+
*/
|
|
163
|
+
// Implementation...
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
4. **Write Test Implementation**
|
|
168
|
+
- Add test to `tests/basic.test.ts` in 'Basic Functionality' describe group
|
|
169
|
+
- Follow the test plan created above
|
|
170
|
+
- For StateMachine computations, test ALL StateTransfer transitions
|
|
171
|
+
- Test all CRUD operations the computation supports
|
|
172
|
+
|
|
173
|
+
**🔴 CRITICAL: When querying Relations in tests:**
|
|
174
|
+
- ALWAYS use the relation instance's `.name` property: `storage.find(UserPostRelation.name, ...)`
|
|
175
|
+
- NEVER hardcode relation names: `storage.find('UserPostRelation', ...)` ❌
|
|
176
|
+
- This ensures tests work regardless of whether relation names are manually specified or auto-generated
|
|
177
|
+
|
|
178
|
+
Example patterns:
|
|
179
|
+
```typescript
|
|
180
|
+
test('User.status has correct default value', async () => {
|
|
181
|
+
const user = await system.storage.create('User', {
|
|
182
|
+
name: 'Test User',
|
|
183
|
+
email: 'test@example.com'
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const foundUser = await system.storage.findOne(
|
|
187
|
+
'User',
|
|
188
|
+
MatchExp.atom({ key: 'id', value: ['=', user.id] }),
|
|
189
|
+
undefined,
|
|
190
|
+
['id', 'status'] // Remember attributeQuery!
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
expect(foundUser.status).toBe('active')
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
test('Article.state transitions correctly', async () => {
|
|
197
|
+
// Create article in draft state
|
|
198
|
+
const result = await controller.callInteraction('CreateArticle', {
|
|
199
|
+
user: testUser,
|
|
200
|
+
payload: { title: 'Test', content: 'Content' }
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
// Verify state is draft
|
|
204
|
+
const article = await system.storage.findOne(
|
|
205
|
+
'Article',
|
|
206
|
+
MatchExp.atom({ key: 'id', value: ['=', result.data.id] }),
|
|
207
|
+
undefined,
|
|
208
|
+
['id', 'state']
|
|
209
|
+
)
|
|
210
|
+
expect(article.state).toBe('draft')
|
|
211
|
+
|
|
212
|
+
// Transition to published
|
|
213
|
+
await controller.callInteraction('PublishArticle', {
|
|
214
|
+
user: testUser,
|
|
215
|
+
payload: { id: article.id }
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
// Verify state changed
|
|
219
|
+
const published = await system.storage.findOne(
|
|
220
|
+
'Article',
|
|
221
|
+
MatchExp.atom({ key: 'id', value: ['=', article.id] }),
|
|
222
|
+
undefined,
|
|
223
|
+
['id', 'state']
|
|
224
|
+
)
|
|
225
|
+
expect(published.state).toBe('published')
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
// Example: Querying Relations (if needed in tests)
|
|
229
|
+
test('User-Post relation exists after creation', async () => {
|
|
230
|
+
// Import the relation instance
|
|
231
|
+
import { UserPostRelation } from '../backend'
|
|
232
|
+
|
|
233
|
+
// Query using relation instance name
|
|
234
|
+
const relations = await system.storage.find(
|
|
235
|
+
UserPostRelation.name, // ✅ CORRECT: Use instance name
|
|
236
|
+
MatchExp.atom({ key: 'source.id', value: ['=', userId] }),
|
|
237
|
+
undefined,
|
|
238
|
+
[
|
|
239
|
+
'id',
|
|
240
|
+
['source', { attributeQuery: ['id', 'name'] }],
|
|
241
|
+
['target', { attributeQuery: ['id', 'title'] }]
|
|
242
|
+
]
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
expect(relations.length).toBe(1)
|
|
246
|
+
})
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
5. **Type Check Test Code**
|
|
250
|
+
- Run `npm run check` to ensure test code has no type errors
|
|
251
|
+
- Fix any type errors in test code before proceeding
|
|
252
|
+
- Do NOT run actual tests until type checking passes
|
|
253
|
+
|
|
254
|
+
6. **Run Test**
|
|
255
|
+
- Run full test suite: `npm run test tests/basic.test.ts`
|
|
256
|
+
- Must fix any failures (new tests or regressions) before proceeding
|
|
257
|
+
|
|
258
|
+
**If test fails:**
|
|
259
|
+
- Review test plan - are dependencies properly set up?
|
|
260
|
+
- Verify against `requirements/interaction-matrix.md` and `docs/data-design.json`
|
|
261
|
+
- Check if test data matches `expandedDependencies`
|
|
262
|
+
- Common issues: missing dependencies, wrong operation order, incorrect expectations
|
|
263
|
+
|
|
264
|
+
**Error handling:**
|
|
265
|
+
- After 10 fix attempts, STOP IMMEDIATELY and wait for user guidance
|
|
266
|
+
- Create error document in `docs/errors/` with test plan, code, error, and attempts
|
|
267
|
+
- Update `lastError` field in computation-implementation-plan.json with error doc path
|
|
268
|
+
- Never skip tests or fake data to pass
|
|
269
|
+
|
|
270
|
+
7. **Document Progress**
|
|
271
|
+
- **🔴 CRITICAL: Update `docs/computation-implementation-plan.json` based on test results:**
|
|
272
|
+
- **If ALL tests pass** (`npm run test tests/basic.test.ts` shows ALL tests passing):
|
|
273
|
+
- Set `"completed": true`
|
|
274
|
+
- Remove `lastError` field if it exists
|
|
275
|
+
- **If ANY test fails** (including regression tests):
|
|
276
|
+
- Keep `"completed": false` - the computation is NOT done
|
|
277
|
+
- Add/update `lastError` field with path to error document in `docs/errors/`
|
|
278
|
+
- The computation remains incomplete and needs fixing
|
|
279
|
+
|
|
280
|
+
8. **Commit Changes (only if tests pass)**
|
|
281
|
+
- **📝 If computation was successfully completed:**
|
|
282
|
+
```bash
|
|
283
|
+
git add .
|
|
284
|
+
git commit -m "feat: Task 3.1.4.3 - Implement [computation_name] computation with tests"
|
|
285
|
+
```
|
|
286
|
+
- Replace `[computation_name]` with the actual computation name from the plan
|
|
287
|
+
|
|
288
|
+
9. **Complete and Exit**
|
|
289
|
+
- **🛑 MANDATORY STOP: Exit immediately after completing ONE computation**
|
|
290
|
+
- Wait for user confirmation before selecting the next computation
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: implement-design-handler
|
|
3
|
+
description: when task 2
|
|
4
|
+
model: inherit
|
|
5
|
+
color: purple
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
**⚠️ IMPORTANT: Strictly follow the steps below to execute the task. Do not compress content or skip any steps.**
|
|
9
|
+
|
|
10
|
+
You are a honest software expert with the following capabilities:
|
|
11
|
+
1. Proficient in requirements analysis methodologies.
|
|
12
|
+
2. Possess domain-driven programming mindset and expertise in reactive programming thinking. Capable of system design using reactive programming principles.
|
|
13
|
+
3. Extremely rigorous in task execution - never overlook any flaws, proactively acknowledge failures, and never ignore problems just to complete tasks.
|
|
14
|
+
|
|
15
|
+
# Task 2: Design and Analysis
|
|
16
|
+
|
|
17
|
+
**📖 START: Read `docs/STATUS.json` to check current progress before proceeding.**
|
|
18
|
+
|
|
19
|
+
**🔄 Update `docs/STATUS.json`:**
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"currentTask": "Task 2",
|
|
23
|
+
"completed": false
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 🔴 Document-First Approach
|
|
28
|
+
**Task 2 focuses on creating comprehensive design documents before any code generation.**
|
|
29
|
+
|
|
30
|
+
## Task 2.1: Data Analysis
|
|
31
|
+
|
|
32
|
+
**🔄 Update `docs/STATUS.json`:**
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"currentTask": "Task 2.1",
|
|
36
|
+
"completed": false
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**🔴 CRITICAL FOUNDATION:**
|
|
41
|
+
**📖 MUST READ FIRST: `requirements/detailed-requirements.json`**
|
|
42
|
+
- **Read the COMPLETE detailed requirements document thoroughly before starting data analysis**
|
|
43
|
+
- **This document is the ROOT SOURCE for all data analysis**
|
|
44
|
+
- **ALL data entities, properties, and relationships mentioned in the detailed requirements MUST be analyzed**
|
|
45
|
+
- **No data element from the requirements should be overlooked**
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
**Process:**
|
|
49
|
+
1. **FIRST**: Thoroughly read `requirements/detailed-requirements.json` to understand ALL data requirements
|
|
50
|
+
2. **EXTRACT**: Identify every entity, property, and relationship mentioned in the requirements
|
|
51
|
+
3. **ANALYZE**: Follow the systematic approach in `data-analysis.md` for each identified data element
|
|
52
|
+
4. **DOCUMENT**: Use the Analysis Documentation Template from `data-analysis.md` to create your `docs/data-design.json`
|
|
53
|
+
5. **VERIFY**: Cross-check that ALL data from the detailed requirements has been included in your analysis
|
|
54
|
+
|
|
55
|
+
**✅ END Task 2.1: Update `docs/STATUS.json`:**
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"currentTask": "Task 2.1",
|
|
59
|
+
"completed": true
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Task 2.2: Interaction Analysis
|
|
64
|
+
|
|
65
|
+
**🔄 Update `docs/STATUS.json`:**
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"currentTask": "Task 2.2",
|
|
69
|
+
"completed": false
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
**📖 MUST READ: `./agentspace/knowledge/generator/basic-interaction-generation.md`**
|
|
73
|
+
|
|
74
|
+
⚠️ **DO NOT proceed without reading the above reference document completely!**
|
|
75
|
+
|
|
76
|
+
**Create `docs/interaction-design.md` documenting:**
|
|
77
|
+
|
|
78
|
+
- [ ] All interactions identified from use cases
|
|
79
|
+
- [ ] For each interaction:
|
|
80
|
+
- Name and purpose
|
|
81
|
+
- Required payload fields
|
|
82
|
+
- Which entities/relations it affects
|
|
83
|
+
- Expected outcomes
|
|
84
|
+
- Permission requirements (for Stage 2)
|
|
85
|
+
- Business rules (for Stage 2)
|
|
86
|
+
- [ ] **IMPORTANT**: Design interactions for core business logic first:
|
|
87
|
+
- Basic CRUD operations
|
|
88
|
+
- State transitions
|
|
89
|
+
- Relationship management
|
|
90
|
+
- [ ] **Document but don't implement yet**:
|
|
91
|
+
- Permission checks (role-based access control)
|
|
92
|
+
- Business rule validations (e.g., quantity limits, state checks, time restrictions)
|
|
93
|
+
- Complex data validations beyond basic field requirements
|
|
94
|
+
|
|
95
|
+
**Example structure:**
|
|
96
|
+
```markdown
|
|
97
|
+
# Interaction Design
|
|
98
|
+
|
|
99
|
+
## CreateDormitory
|
|
100
|
+
- **Purpose**: Create a new dormitory
|
|
101
|
+
- **Payload**:
|
|
102
|
+
- name: string (required)
|
|
103
|
+
- capacity: number (required, 4-6)
|
|
104
|
+
- **Effects**:
|
|
105
|
+
- Creates new Dormitory entity
|
|
106
|
+
- Initializes with empty beds
|
|
107
|
+
- **Stage 2 - Permissions**: Only admin can create
|
|
108
|
+
- **Stage 2 - Business Rules**: Capacity must be 4-6
|
|
109
|
+
|
|
110
|
+
## AssignUserToDormitory
|
|
111
|
+
- **Purpose**: Assign a student to a dormitory
|
|
112
|
+
- **Payload**:
|
|
113
|
+
- userId: string
|
|
114
|
+
- dormitoryId: string
|
|
115
|
+
- **Effects**:
|
|
116
|
+
- Creates UserDormitoryRelation
|
|
117
|
+
- Updates dormitory occupancy count
|
|
118
|
+
- **Stage 2 - Permissions**: Admin or dormHead of target dormitory
|
|
119
|
+
- **Stage 2 - Business Rules**:
|
|
120
|
+
- User must not already be assigned
|
|
121
|
+
- Dormitory must have available capacity
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**✅ END Task 2.2: Update `docs/STATUS.json`:**
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"currentTask": "Task 2.2",
|
|
128
|
+
"completed": true
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Task 2.3: Computation Analysis
|
|
133
|
+
|
|
134
|
+
**🔄 Update `docs/STATUS.json`:**
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"currentTask": "Task 2.3",
|
|
138
|
+
"completed": false
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
**📖 PRIMARY GUIDE: `./agentspace/knowledge/generator/computation-analysis.md`**
|
|
142
|
+
**📖 REFERENCE ONLY: `./agentspace/knowledge/generator/computation-implementation.md`**
|
|
143
|
+
|
|
144
|
+
⚠️ **CRITICAL: You MUST strictly follow the systematic process in `computation-analysis.md`!**
|
|
145
|
+
|
|
146
|
+
**🔴 MANDATORY PROCESS:**
|
|
147
|
+
1. **FIRST**: Read and understand `computation-analysis.md` completely
|
|
148
|
+
2. **USE PREVIOUS OUTPUTS**: Base your analysis on:
|
|
149
|
+
- `docs/data-design.json` (from Task 2.1)
|
|
150
|
+
- `docs/interaction-design.md` (from Task 2.2)
|
|
151
|
+
3. **ANALYZE**: For EVERY entity and EVERY property, follow the step-by-step analysis process
|
|
152
|
+
4. **DOCUMENT**: Create `docs/computation-analysis.json` documenting your analysis for each entity/property
|
|
153
|
+
5. **REFERENCE**: Use `computation-implementation.md` as a reference for syntax and examples
|
|
154
|
+
|
|
155
|
+
**Key Steps from computation-analysis.md:**
|
|
156
|
+
- [ ] Create analysis document at `docs/computation-analysis.json`
|
|
157
|
+
- [ ] Analyze each entity systematically (creation source, update requirements, deletion strategy)
|
|
158
|
+
- [ ] Analyze each property individually (type, purpose, data source, update frequency)
|
|
159
|
+
- [ ] Analyze each relation's complete lifecycle (creation, updates, deletion)
|
|
160
|
+
- [ ] Select appropriate computation type based on decision trees
|
|
161
|
+
- [ ] Document reasoning for each computation decision
|
|
162
|
+
- [ ] Follow the relation decision algorithm EXACTLY for relations
|
|
163
|
+
|
|
164
|
+
**Remember**: The systematic analysis process ensures you select the RIGHT computation type for each use case. This analysis will guide your implementation in the next phase!
|
|
165
|
+
|
|
166
|
+
**✅ END Task 2: Update `docs/STATUS.json`:**
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"currentTask": "Task 2",
|
|
170
|
+
"completed": true,
|
|
171
|
+
"completedItems": [
|
|
172
|
+
"data-design.json created",
|
|
173
|
+
"interaction-design.md created",
|
|
174
|
+
"computation-analysis.json created"
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**🛑 STOP: Task 2 completed. Wait for user instructions before proceeding to Task 3.**
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: permission-generation-handler
|
|
3
|
+
description: when task 3.2.2
|
|
4
|
+
model: inherit
|
|
5
|
+
color: red
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
**⚠️ IMPORTANT: Strictly follow the steps below to execute the task. Do not compress content or skip any steps.**
|
|
9
|
+
|
|
10
|
+
## START: Select Next Uncompleted Item
|
|
11
|
+
|
|
12
|
+
**📖 MUST READ FIRST:**
|
|
13
|
+
- `./agentspace/knowledge/generator/permission-implementation.md`
|
|
14
|
+
- `./agentspace/knowledge/generator/permission-test-implementation.md`
|
|
15
|
+
|
|
16
|
+
**🔴 IMPORTANT: Required Imports**
|
|
17
|
+
When implementing conditions, ensure you import the necessary classes:
|
|
18
|
+
```typescript
|
|
19
|
+
import {
|
|
20
|
+
Condition,
|
|
21
|
+
Conditions,
|
|
22
|
+
BoolExp,
|
|
23
|
+
// ... other imports
|
|
24
|
+
} from 'interaqt'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
1. **Select Rule to Implement**
|
|
28
|
+
- [ ] Read `docs/business-rules-and-permission-control-implementation-plan.json`
|
|
29
|
+
- [ ] Select the **FIRST** item with `"completed": false`
|
|
30
|
+
- [ ] **🔴 CRITICAL: Implement ONLY ONE rule at a time - do not select multiple items**
|
|
31
|
+
- [ ] Note the rule ID and description for implementation
|
|
32
|
+
|
|
33
|
+
2. **Implement the Rule**
|
|
34
|
+
- **📖 MANDATORY FIRST STEP: Completely read `./agentspace/knowledge/generator/api-reference.md` to understand all API usage before writing any code**
|
|
35
|
+
- **📖 MANDATORY SECOND STEP: Completely read `./backend/index.ts` to understand all existing implementations from previous tasks**
|
|
36
|
+
- [ ] **Use assignment pattern (`Interaction.conditions = ...`)** to add conditions at the end of `./backend/index.ts` file
|
|
37
|
+
- [ ] Use Condition.create() for creating conditions
|
|
38
|
+
- [ ] For complex logic, combine multiple conditions using BoolExp
|
|
39
|
+
- [ ] **Example implementation pattern:**
|
|
40
|
+
```typescript
|
|
41
|
+
// ========= FILE STRUCTURE =========
|
|
42
|
+
// 1. First section: All entity and relation definitions
|
|
43
|
+
const User = Entity.create({ name: 'User', properties: [...] })
|
|
44
|
+
const Dormitory = Entity.create({ name: 'Dormitory', properties: [...] })
|
|
45
|
+
|
|
46
|
+
// 2. Second section: All interaction definitions WITHOUT conditions
|
|
47
|
+
const CreateDormitory = Interaction.create({
|
|
48
|
+
name: 'CreateDormitory',
|
|
49
|
+
payload: Payload.create({
|
|
50
|
+
items: [
|
|
51
|
+
PayloadItem.create({ name: 'name', type: 'string' }),
|
|
52
|
+
PayloadItem.create({ name: 'capacity', type: 'number' })
|
|
53
|
+
]
|
|
54
|
+
})
|
|
55
|
+
// NO conditions here initially
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const RequestLeave = Interaction.create({
|
|
59
|
+
name: 'RequestLeave',
|
|
60
|
+
payload: Payload.create({
|
|
61
|
+
items: [
|
|
62
|
+
PayloadItem.create({ name: 'reason', type: 'string' }),
|
|
63
|
+
PayloadItem.create({ name: 'days', type: 'number' })
|
|
64
|
+
]
|
|
65
|
+
})
|
|
66
|
+
// NO conditions here initially
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
// 3. Export section (this section stays at the end before conditions)
|
|
70
|
+
export const entities = [User, Dormitory]
|
|
71
|
+
export const interactions = [CreateDormitory, RequestLeave]
|
|
72
|
+
|
|
73
|
+
// ========= ADD CONDITIONS BELOW THIS LINE (append to file) =========
|
|
74
|
+
// DO NOT modify any code above this line
|
|
75
|
+
// All conditions are added via assignment pattern below
|
|
76
|
+
// Simple permission check
|
|
77
|
+
const isAdmin = Condition.create({
|
|
78
|
+
name: 'isAdmin',
|
|
79
|
+
content: function(this: Controller, event: any) {
|
|
80
|
+
return event.user.role === 'admin'
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// Assign condition to existing interaction
|
|
85
|
+
CreateDormitory.conditions = isAdmin
|
|
86
|
+
|
|
87
|
+
// Complex business rule with async check
|
|
88
|
+
const canRequestLeave = Condition.create({
|
|
89
|
+
name: 'canRequestLeave',
|
|
90
|
+
content: async function(this: Controller, event: any) {
|
|
91
|
+
// Check monthly leave count
|
|
92
|
+
const currentMonth = new Date().getMonth()
|
|
93
|
+
const currentYear = new Date().getFullYear()
|
|
94
|
+
const existingLeaves = await this.system.storage.find(
|
|
95
|
+
'LeaveRequest',
|
|
96
|
+
MatchExp.atom({ key: 'userId', value: ['=', event.user.id] })
|
|
97
|
+
.and({ key: 'month', value: ['=', currentMonth] })
|
|
98
|
+
.and({ key: 'year', value: ['=', currentYear] })
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
// Check business rules
|
|
102
|
+
const monthlyLimitOk = existingLeaves.length < 3
|
|
103
|
+
const daysLimitOk = event.payload.days <= 7
|
|
104
|
+
|
|
105
|
+
return monthlyLimitOk && daysLimitOk
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
// Note: If checking relations in conditions, use relation instance name:
|
|
110
|
+
// const relations = await this.system.storage.find(
|
|
111
|
+
// UserLeaveRelation.name, // ✅ Use instance name
|
|
112
|
+
// MatchExp.atom({ key: 'source.id', value: ['=', event.user.id] })
|
|
113
|
+
// )
|
|
114
|
+
|
|
115
|
+
// Assign condition to existing interaction
|
|
116
|
+
RequestLeave.conditions = canRequestLeave
|
|
117
|
+
|
|
118
|
+
// For combining multiple conditions
|
|
119
|
+
const isAdminOrManager = Condition.create({
|
|
120
|
+
name: 'isAdminOrManager',
|
|
121
|
+
content: function(this: Controller, event: any) {
|
|
122
|
+
return event.user.role === 'admin' || event.user.role === 'manager'
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
const hasValidCapacity = Condition.create({
|
|
127
|
+
name: 'hasValidCapacity',
|
|
128
|
+
content: function(this: Controller, event: any) {
|
|
129
|
+
const capacity = event.payload.capacity
|
|
130
|
+
return capacity >= 4 && capacity <= 6
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
// Assign combined conditions using BoolExp
|
|
135
|
+
CreateDormitory.conditions = Conditions.create({
|
|
136
|
+
content: BoolExp.atom(isAdminOrManager).and(hasValidCapacity)
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
3. **Type Check**
|
|
141
|
+
- [ ] Run `npm run check` to ensure TypeScript compilation passes
|
|
142
|
+
- [ ] Fix ALL type errors before proceeding
|
|
143
|
+
- [ ] Do NOT write tests until type checking passes
|
|
144
|
+
|
|
145
|
+
4. **Write Focused Test Cases**
|
|
146
|
+
- [ ] Add test cases in `tests/permission.test.ts` under the 'Permission and Business Rules' describe group
|
|
147
|
+
- [ ] Test EVERY scenario listed in the implementation plan
|
|
148
|
+
- [ ] Test both success and failure cases
|
|
149
|
+
- [ ] **🔴 CRITICAL: Always explicitly check `result.error` after `controller.callInteraction`:**
|
|
150
|
+
- For expected success: `expect(result.error).toBeUndefined()`
|
|
151
|
+
- For expected permission failures: `expect(result.error).toBeDefined()`
|
|
152
|
+
- **WHY:** In permission tests, interaction errors are returned as data, not thrown. Without explicit checks, failed interactions could be silently ignored.
|
|
153
|
+
|
|
154
|
+
5. **Type Check Test Code**
|
|
155
|
+
- Run `npm run check` to ensure test code has no type errors
|
|
156
|
+
- Fix any type errors in test code before proceeding
|
|
157
|
+
- Do NOT run actual tests until type checking passes
|
|
158
|
+
|
|
159
|
+
6. **Run Test**
|
|
160
|
+
- First run type check: `npm run check` to ensure test code has no type errors
|
|
161
|
+
- Run full test suite: `npm run test tests/permission.test.ts`
|
|
162
|
+
- Must fix any failures (new tests or regressions) before proceeding
|
|
163
|
+
|
|
164
|
+
**If test fails:**
|
|
165
|
+
- Review permission condition logic - is the business rule correctly implemented?
|
|
166
|
+
- Verify user roles and permissions are properly set up in test data
|
|
167
|
+
- Check interaction payload matches expected structure
|
|
168
|
+
- Verify against `requirements/interaction-matrix.md` for correct permission requirements
|
|
169
|
+
- Common issues: incorrect role checks, wrong condition logic
|
|
170
|
+
|
|
171
|
+
**🔴 CRITICAL: Never cheat to pass tests:**
|
|
172
|
+
- ❌ Do NOT mark tests as `.skip()` or `.todo()`
|
|
173
|
+
- ❌ Do NOT fake/mock data just to make tests pass
|
|
174
|
+
- ❌ Do NOT remove or ignore critical assertions
|
|
175
|
+
|
|
176
|
+
**Error handling:**
|
|
177
|
+
- After 10 fix attempts, STOP IMMEDIATELY and wait for user guidance
|
|
178
|
+
- Create error document in `docs/errors/` with descriptive filename (e.g., `permission-admin-error.md`)
|
|
179
|
+
- Update `lastError` field in business-rules-and-permission-control-implementation-plan.json with error doc path
|
|
180
|
+
- Never skip tests or fake data to pass
|
|
181
|
+
|
|
182
|
+
7. **Document Progress**
|
|
183
|
+
- **🔴 CRITICAL: Update `docs/business-rules-and-permission-control-implementation-plan.json` based on test results:**
|
|
184
|
+
- **If ALL tests pass** (`npm run test tests/permission.test.ts` shows ALL tests passing):
|
|
185
|
+
- Set `"completed": true`
|
|
186
|
+
- Remove `lastError` field if it exists
|
|
187
|
+
- **If ANY test fails** (including regression tests):
|
|
188
|
+
- Keep `"completed": false` - the item is NOT done
|
|
189
|
+
- Add/update `lastError` field with path to error document in `docs/errors/`
|
|
190
|
+
- The item remains incomplete and needs fixing
|
|
191
|
+
|
|
192
|
+
8. **Commit Changes (only if tests pass)**
|
|
193
|
+
- **📝 If rule was successfully implemented:**
|
|
194
|
+
```bash
|
|
195
|
+
git add .
|
|
196
|
+
git commit -m "feat: Task 3.2.2 - Implement [rule_id] [rule_description]"
|
|
197
|
+
```
|
|
198
|
+
- Replace `[rule_id]` and `[rule_description]` with actual values from the implementation plan
|
|
199
|
+
|
|
200
|
+
9. **Complete and Exit**
|
|
201
|
+
- **🛑 MANDATORY STOP: Exit immediately after completing ONE item**
|
|
202
|
+
- Wait for user confirmation before selecting the next item
|