statable 3.1.0__py3-none-any.whl
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.
- codegen/__init__.py +38 -0
- codegen/c_code_generator.py +1752 -0
- codegen/code_merger.py +371 -0
- codegen/code_templates.py +509 -0
- codegen/config.py +167 -0
- codegen/enum_generator.py +377 -0
- codegen/event_queue_generator.py +303 -0
- codegen/interrupt_generator.py +345 -0
- codegen/naming_convention.py +171 -0
- codegen/osal_generator.py +282 -0
- codegen/role_function_generator.py +1244 -0
- codegen/sample_data.py +269 -0
- codegen/state_actions_generator.py +395 -0
- codegen/struct_generator.py +721 -0
- codegen/timer_generator.py +299 -0
- codegen/transition_generator.py +907 -0
- codegen/type_mapper.py +69 -0
- codegen/validate/__init__.py +38 -0
- codegen/validate/change_actions.py +90 -0
- codegen/validate/change_applier.py +416 -0
- codegen/validate/clipboard_manager.py +47 -0
- codegen/validate/data/__init__.py +30 -0
- codegen/validate/data/action_definitions.py +200 -0
- codegen/validate/data/keywords.py +46 -0
- codegen/validate/data/prompt_templates.py +176 -0
- codegen/validate/data/validation_rules.py +205 -0
- codegen/validate/items/__init__.py +30 -0
- codegen/validate/items/base_validator.py +25 -0
- codegen/validate/items/cell_validator.py +275 -0
- codegen/validate/items/custom_type_validator.py +75 -0
- codegen/validate/items/event_validator.py +78 -0
- codegen/validate/items/flag_validator.py +74 -0
- codegen/validate/items/interrupt_validator.py +75 -0
- codegen/validate/items/queue_validator.py +73 -0
- codegen/validate/items/role_function_validator.py +175 -0
- codegen/validate/items/state_validator.py +88 -0
- codegen/validate/items/timer_validator.py +120 -0
- codegen/validate/items/transition_validator.py +113 -0
- codegen/validate/items/variable_validator.py +132 -0
- codegen/validate/logger.py +52 -0
- codegen/validate/models.py +177 -0
- codegen/validate/prompt_generator.py +724 -0
- codegen/validate/response_parser.py +154 -0
- codegen/validate/response_validator.py +275 -0
- codegen/validate/validation_dialog.py +322 -0
- codegen/validate/validator.py +94 -0
- codegen/variable_generator.py +419 -0
- statable/__init__.py +71 -0
- statable/__main__.py +49 -0
- statable/cli.py +251 -0
- statable/global_defs.py +256 -0
- statable/mermaid_gen.py +144 -0
- statable/model.py +426 -0
- statable/parser.py +64 -0
- statable/sample_data.py +435 -0
- statable/shared/__init__.py +24 -0
- statable/shared/condition_library.py +63 -0
- statable/shared/literal_library.py +66 -0
- statable/shared/role_function_library.py +150 -0
- statable/state_machine.py +121 -0
- statable/xml_io.py +1164 -0
- statable-3.1.0.dist-info/METADATA +151 -0
- statable-3.1.0.dist-info/RECORD +117 -0
- statable-3.1.0.dist-info/WHEEL +5 -0
- statable-3.1.0.dist-info/entry_points.txt +2 -0
- statable-3.1.0.dist-info/top_level.txt +3 -0
- statable_gui/__init__.py +23 -0
- statable_gui/action_edit_dialog.py +214 -0
- statable_gui/code_generation_dialog.py +486 -0
- statable_gui/code_generation_settings_dialog.py +522 -0
- statable_gui/common_widgets.py +537 -0
- statable_gui/condition_builder_dialog.py +500 -0
- statable_gui/condition_edit_dialog.py +123 -0
- statable_gui/condition_template_dialog.py +58 -0
- statable_gui/config.py +21 -0
- statable_gui/dialogs.py +439 -0
- statable_gui/event_definition_dialog.py +605 -0
- statable_gui/event_delivery_settings_dialog.py +191 -0
- statable_gui/event_queue_dialog.py +245 -0
- statable_gui/global_defs.py +167 -0
- statable_gui/global_defs_dialog.py +796 -0
- statable_gui/i18n/__init__.py +118 -0
- statable_gui/interrupt_handler_edit_dialog.py +810 -0
- statable_gui/layer_settings_dialog.py +180 -0
- statable_gui/libcntrl/__init__.py +23 -0
- statable_gui/libcntrl/condition_library.py +13 -0
- statable_gui/libcntrl/literal_library.py +13 -0
- statable_gui/libcntrl/literal_management_dialog.py +185 -0
- statable_gui/libcntrl/role_function_edit_dialog.py +145 -0
- statable_gui/libcntrl/role_function_library.py +13 -0
- statable_gui/literal_definition_dialog.py +62 -0
- statable_gui/logger.py +83 -0
- statable_gui/main_window.py +1380 -0
- statable_gui/matrix_table.py +413 -0
- statable_gui/preference_keys.py +18 -0
- statable_gui/preferences.py +74 -0
- statable_gui/role_function_dialog.py +244 -0
- statable_gui/sample_data.py +11 -0
- statable_gui/state_actions_dialog.py +398 -0
- statable_gui/symbol_picker.py +170 -0
- statable_gui/traceball.py +37 -0
- statable_gui/transition_editor_direct/__init__.py +15 -0
- statable_gui/transition_editor_direct/actions_tab.py +856 -0
- statable_gui/transition_editor_direct/code_widget.py +344 -0
- statable_gui/transition_editor_direct/coverage_analyzer.py +163 -0
- statable_gui/transition_editor_direct/dialog.py +335 -0
- statable_gui/transition_editor_direct/draft.py +270 -0
- statable_gui/transition_editor_direct/edit_dialogs.py +160 -0
- statable_gui/transition_editor_direct/overview_tab.py +173 -0
- statable_gui/transition_editor_direct/palette_widget.py +233 -0
- statable_gui/transition_editor_direct/relations_edit_dialog.py +156 -0
- statable_gui/transition_editor_direct/relations_tab.py +230 -0
- statable_gui/transition_editor_direct/system_global_dialog.py +52 -0
- statable_gui/transition_editor_direct/transition_actions_dialog.py +109 -0
- statable_gui/transition_editor_direct/transitions_tab.py +620 -0
- statable_gui/validation_dialog.py +285 -0
- statable_gui/widgets.py +1315 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# codegen/validate/data/__init__.py
|
|
2
|
+
"""\nValidation data package\n"""
|
|
3
|
+
|
|
4
|
+
from .validation_rules import VALIDATION_RULES
|
|
5
|
+
from .prompt_templates import (
|
|
6
|
+
PROMPT_TEMPLATES,
|
|
7
|
+
FEW_SHOT_EXAMPLE,
|
|
8
|
+
VALIDATION_POINTS,
|
|
9
|
+
)
|
|
10
|
+
from .action_definitions import (
|
|
11
|
+
ACTION_DEFINITIONS,
|
|
12
|
+
format_action_definitions,
|
|
13
|
+
)
|
|
14
|
+
from .keywords import (
|
|
15
|
+
IGNORE_KEYWORDS,
|
|
16
|
+
MARKERS,
|
|
17
|
+
PARSE_KEYWORDS,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
'VALIDATION_RULES',
|
|
22
|
+
'PROMPT_TEMPLATES',
|
|
23
|
+
'FEW_SHOT_EXAMPLE',
|
|
24
|
+
'VALIDATION_POINTS',
|
|
25
|
+
'ACTION_DEFINITIONS',
|
|
26
|
+
'format_action_definitions',
|
|
27
|
+
'IGNORE_KEYWORDS',
|
|
28
|
+
'MARKERS',
|
|
29
|
+
'PARSE_KEYWORDS',
|
|
30
|
+
]
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# codegen/validate/data/action_definitions.py
|
|
2
|
+
"""
|
|
3
|
+
Action definitions (data only).
|
|
4
|
+
|
|
5
|
+
[v1.6 change]
|
|
6
|
+
- Extended the type enum of add_state to 7 kinds (matching StateType)
|
|
7
|
+
- Added remove_role_function
|
|
8
|
+
|
|
9
|
+
[v2.2 §12-6 change]
|
|
10
|
+
- Added 7 cell-level AI actions:
|
|
11
|
+
add_cell / remove_cell
|
|
12
|
+
add_action_step / remove_action_step
|
|
13
|
+
add_transition_relation / remove_transition_relation
|
|
14
|
+
set_early_return
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
ACTION_DEFINITIONS = {
|
|
18
|
+
'set_initial': {
|
|
19
|
+
'description': 'Set initial state',
|
|
20
|
+
'params': {
|
|
21
|
+
'state': {'type': 'str', 'required': True, 'description': 'State name'},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
'add_transition': {
|
|
25
|
+
'description': 'Add transition',
|
|
26
|
+
'params': {
|
|
27
|
+
'source': {'type': 'str', 'required': True, 'description': 'Source'},
|
|
28
|
+
'event': {'type': 'str', 'required': True, 'description': 'Event name'},
|
|
29
|
+
'target': {'type': 'str', 'required': True, 'description': 'Target'},
|
|
30
|
+
'condition': {'type': 'str', 'required': False, 'description': 'Condition'},
|
|
31
|
+
'action_name': {'type': 'str', 'required': False, 'description': 'Action name'},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
'add_state': {
|
|
35
|
+
'description': 'Add state',
|
|
36
|
+
'params': {
|
|
37
|
+
'name': {'type': 'str', 'required': True, 'description': 'State name'},
|
|
38
|
+
'type': {
|
|
39
|
+
'type': 'enum',
|
|
40
|
+
'required': False,
|
|
41
|
+
'values': [
|
|
42
|
+
'NORMAL', 'CONCURRENT', 'REGION', 'INITIAL',
|
|
43
|
+
'FINAL', 'CHOICE', 'JUNCTION',
|
|
44
|
+
],
|
|
45
|
+
'description': 'State type',
|
|
46
|
+
},
|
|
47
|
+
'description': {'type': 'str', 'required': False, 'description': 'Description'},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
'add_event': {
|
|
51
|
+
'description': 'Add event',
|
|
52
|
+
'params': {
|
|
53
|
+
'name': {'type': 'str', 'required': True, 'description': 'Event name'},
|
|
54
|
+
'kind': {'type': 'enum', 'required': False,
|
|
55
|
+
'values': ['SIGNAL', 'CALL', 'TIME', 'CHANGE'],
|
|
56
|
+
'description': 'Event kind'},
|
|
57
|
+
'description': {'type': 'str', 'required': False, 'description': 'Description'},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
'remove_transition': {
|
|
61
|
+
'description': 'Delete transition',
|
|
62
|
+
'params': {
|
|
63
|
+
'source': {'type': 'str', 'required': True, 'description': 'Source'},
|
|
64
|
+
'event': {'type': 'str', 'required': True, 'description': 'Event name'},
|
|
65
|
+
'target': {'type': 'str', 'required': True, 'description': 'Target'},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
'update_transition': {
|
|
69
|
+
'description': 'Update transition',
|
|
70
|
+
'params': {
|
|
71
|
+
'source': {'type': 'str', 'required': True, 'description': 'Source'},
|
|
72
|
+
'event': {'type': 'str', 'required': True, 'description': 'Event name'},
|
|
73
|
+
'new_target': {'type': 'str', 'required': False, 'description': 'New target'},
|
|
74
|
+
'new_condition': {'type': 'str', 'required': False, 'description': 'New condition'},
|
|
75
|
+
'new_action': {'type': 'str', 'required': False, 'description': 'New action'},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
'add_role_function': {
|
|
79
|
+
'description': 'Add role function',
|
|
80
|
+
'params': {
|
|
81
|
+
'name': {'type': 'str', 'required': True, 'description': 'Function name'},
|
|
82
|
+
'return_type': {'type': 'str', 'required': True, 'description': 'Return type'},
|
|
83
|
+
'description': {'type': 'str', 'required': False, 'description': 'Description'},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
'remove_role_function': {
|
|
87
|
+
'description': 'Delete role function',
|
|
88
|
+
'params': {
|
|
89
|
+
'name': {'type': 'str', 'required': True,
|
|
90
|
+
'description': 'Function name (bare name or namespace.name)'},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
'add_variable': {
|
|
94
|
+
'description': 'Add variable',
|
|
95
|
+
'params': {
|
|
96
|
+
'name': {'type': 'str', 'required': True, 'description': 'Variable name'},
|
|
97
|
+
'type': {'type': 'str', 'required': True, 'description': 'Type'},
|
|
98
|
+
'group': {'type': 'str', 'required': False, 'description': 'Group'},
|
|
99
|
+
'description': {'type': 'str', 'required': False, 'description': 'Description'},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
'add_flag': {
|
|
103
|
+
'description': 'Add flag',
|
|
104
|
+
'params': {
|
|
105
|
+
'name': {'type': 'str', 'required': True, 'description': 'Flag name'},
|
|
106
|
+
'min_value': {'type': 'int', 'required': False, 'description': 'Min value'},
|
|
107
|
+
'max_value': {'type': 'int', 'required': False, 'description': 'Max value'},
|
|
108
|
+
'group': {'type': 'str', 'required': False, 'description': 'Group'},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
# ==============================================================
|
|
112
|
+
# v2.2 §12-6: Cell-level AI actions
|
|
113
|
+
# ==============================================================
|
|
114
|
+
'add_cell': {
|
|
115
|
+
'description': 'Add (or ensure) a cell for (source, event)',
|
|
116
|
+
'params': {
|
|
117
|
+
'source': {'type': 'str', 'required': True, 'description': 'Source state name'},
|
|
118
|
+
'event': {'type': 'str', 'required': True, 'description': 'Event name (empty for completion)'},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
'remove_cell': {
|
|
122
|
+
'description': 'Remove a cell (actions + relations) for (source, event)',
|
|
123
|
+
'params': {
|
|
124
|
+
'source': {'type': 'str', 'required': True, 'description': 'Source state name'},
|
|
125
|
+
'event': {'type': 'str', 'required': True, 'description': 'Event name (empty for completion)'},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
'add_action_step': {
|
|
129
|
+
'description': 'Add a Pre/Post action step to a cell',
|
|
130
|
+
'params': {
|
|
131
|
+
'source': {'type': 'str', 'required': True, 'description': 'Source state name'},
|
|
132
|
+
'event': {'type': 'str', 'required': True, 'description': 'Event name'},
|
|
133
|
+
'role_function': {'type': 'str', 'required': True, 'description': 'Role function name'},
|
|
134
|
+
'trigger': {
|
|
135
|
+
'type': 'enum',
|
|
136
|
+
'required': False,
|
|
137
|
+
'values': ['before_transitions', 'after_transitions'],
|
|
138
|
+
'description': 'Action trigger (default: before_transitions)',
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
'remove_action_step': {
|
|
143
|
+
'description': 'Remove a Pre/Post action step from a cell',
|
|
144
|
+
'params': {
|
|
145
|
+
'source': {'type': 'str', 'required': True, 'description': 'Source state name'},
|
|
146
|
+
'event': {'type': 'str', 'required': True, 'description': 'Event name'},
|
|
147
|
+
'role_function': {'type': 'str', 'required': True, 'description': 'Role function name'},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
'add_transition_relation': {
|
|
151
|
+
'description': 'Add a transition relation (group / sequential / exclusive)',
|
|
152
|
+
'params': {
|
|
153
|
+
'source': {'type': 'str', 'required': True, 'description': 'Source state name'},
|
|
154
|
+
'event': {'type': 'str', 'required': True, 'description': 'Event name'},
|
|
155
|
+
'kind': {
|
|
156
|
+
'type': 'enum',
|
|
157
|
+
'required': True,
|
|
158
|
+
'values': ['sequential', 'exclusive', 'group'],
|
|
159
|
+
'description': 'Relation kind',
|
|
160
|
+
},
|
|
161
|
+
'members': {'type': 'list', 'required': True, 'description': 'Transition labels (e.g. ["T1","T2"])'},
|
|
162
|
+
'shared_condition': {'type': 'str', 'required': False,
|
|
163
|
+
'description': 'Required for kind == "group"'},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
'remove_transition_relation': {
|
|
167
|
+
'description': 'Remove a transition relation by kind + shared_condition',
|
|
168
|
+
'params': {
|
|
169
|
+
'source': {'type': 'str', 'required': True, 'description': 'Source state name'},
|
|
170
|
+
'event': {'type': 'str', 'required': True, 'description': 'Event name'},
|
|
171
|
+
'kind': {'type': 'str', 'required': True, 'description': 'Relation kind'},
|
|
172
|
+
'shared_condition': {'type': 'str', 'required': False,
|
|
173
|
+
'description': 'Match shared_condition (optional)'},
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
'set_early_return': {
|
|
177
|
+
'description': 'Set early_return (Commit) flag on a transition',
|
|
178
|
+
'params': {
|
|
179
|
+
'source': {'type': 'str', 'required': True, 'description': 'Source state name'},
|
|
180
|
+
'event': {'type': 'str', 'required': True, 'description': 'Event name'},
|
|
181
|
+
'label': {'type': 'str', 'required': True, 'description': 'Transition label (e.g. "T1")'},
|
|
182
|
+
'early_return': {'type': 'bool', 'required': True,
|
|
183
|
+
'description': 'True = Commit, False = Tentative'},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def format_action_definitions() -> str:
|
|
190
|
+
"""Convert action definitions to prompt text."""
|
|
191
|
+
lines = ["[Available actions]"]
|
|
192
|
+
for i, (action, definition) in enumerate(ACTION_DEFINITIONS.items(), 1):
|
|
193
|
+
params = definition['params']
|
|
194
|
+
param_strs = []
|
|
195
|
+
for key, param in params.items():
|
|
196
|
+
required = "Required" if param['required'] else "Optional"
|
|
197
|
+
param_strs.append(f'"{key}": {param["description"]}({required})')
|
|
198
|
+
lines.append(f"{i}. {action}: {definition['description']}")
|
|
199
|
+
lines.append(f" params: {{{', '.join(param_strs)}}}")
|
|
200
|
+
return '\n'.join(lines)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# codegen/validate/data/keywords.py
|
|
2
|
+
"""\nKeyword definitions (data only)\n"""
|
|
3
|
+
|
|
4
|
+
IGNORE_KEYWORDS = {
|
|
5
|
+
'greeting': ['Understood', 'Understood', 'Understood', 'Yes,', 'Hello'],
|
|
6
|
+
'preface': ['Below', 'Analysis result', 'Validated', 'Confirmed', 'The following is'],
|
|
7
|
+
'explanation': ['is', 'does', 'Considering', 'I think', 'is.'],
|
|
8
|
+
'supplement': ['Note,', 'By the way', 'For reference', 'Supplement'],
|
|
9
|
+
'closing': ['That is all', 'The above is', 'Please confirm', 'Best regards'],
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
MARKERS = {
|
|
13
|
+
'primary': {
|
|
14
|
+
'start': '---CHANGES_START---',
|
|
15
|
+
'end': '---CHANGES_END---',
|
|
16
|
+
},
|
|
17
|
+
'alternatives': [
|
|
18
|
+
{'start': '```json', 'end': '```'},
|
|
19
|
+
{'start': '```JSON', 'end': '```'},
|
|
20
|
+
{'start': '<<<CHANGES_START>>>', 'end': '<<<CHANGES_END>>>'},
|
|
21
|
+
{'start': '[[CHANGES_START]]', 'end': '[[CHANGES_END]]'},
|
|
22
|
+
{'start': '===CHANGES_START===', 'end': '===CHANGES_END==='},
|
|
23
|
+
],
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
PARSE_KEYWORDS = {
|
|
27
|
+
'severity': {
|
|
28
|
+
'error': ['ERROR', 'Error', 'Critical'],
|
|
29
|
+
'warning': ['WARNING', 'Warning'],
|
|
30
|
+
'info': ['INFO', 'Info'],
|
|
31
|
+
},
|
|
32
|
+
'category': {
|
|
33
|
+
'state': ['State'],
|
|
34
|
+
'event': ['Event'],
|
|
35
|
+
'transition': ['Transition'],
|
|
36
|
+
'role_function': ['Role function', 'Function'],
|
|
37
|
+
'variable': ['Variable'],
|
|
38
|
+
'flag': ['Flag'],
|
|
39
|
+
'queue': ['Queue'],
|
|
40
|
+
'interrupt': ['Interrupt'],
|
|
41
|
+
'timer': ['Timer'],
|
|
42
|
+
'custom_type': ['Type', 'Struct'],
|
|
43
|
+
},
|
|
44
|
+
'suggestion': ['Fix method', 'Fix proposal', 'Proposal', 'Corresponds', 'Solution'],
|
|
45
|
+
'target': ['Target', 'State', 'Function', 'Variable', 'Event'],
|
|
46
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# codegen/validate/data/prompt_templates.py
|
|
2
|
+
"""
|
|
3
|
+
Prompt template definitions (data only)
|
|
4
|
+
|
|
5
|
+
[v2.8.0 / SPEC_AI_PROMPT_v1.1]
|
|
6
|
+
Full refresh of the diagnosis prompt:
|
|
7
|
+
- XML-style tag structure (system/workflow/task/...)
|
|
8
|
+
- Two few-shot examples (basic + evidence-based)
|
|
9
|
+
- Explicit <output_schema> and <response_format>
|
|
10
|
+
- Evidence / confidence / priority fields documented
|
|
11
|
+
- Backward-compatible parser fallback still accepts the
|
|
12
|
+
legacy <json> marker and the plain { ... } form.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
# ======================================================================
|
|
16
|
+
# Output schema (passed as a format argument, so braces need no escape)
|
|
17
|
+
# ======================================================================
|
|
18
|
+
OUTPUT_SCHEMA = """{
|
|
19
|
+
"version": "1.0",
|
|
20
|
+
"summary": "<one-line overview, optional>",
|
|
21
|
+
"changes": [
|
|
22
|
+
{
|
|
23
|
+
"id": "C-001",
|
|
24
|
+
"action": "<one of the allowed actions>",
|
|
25
|
+
"params": { "<param-name>": "<value>" },
|
|
26
|
+
"reason": "<why this change is needed>",
|
|
27
|
+
"evidence": ["<validation code or identifier>"],
|
|
28
|
+
"priority": "high|medium|low",
|
|
29
|
+
"confidence": 0.0
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}"""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# ======================================================================
|
|
36
|
+
# Few-shot example 1: basic changes (set_initial + add_transition)
|
|
37
|
+
# ======================================================================
|
|
38
|
+
FEW_SHOT_EXAMPLE_1 = """{
|
|
39
|
+
"version": "1.0",
|
|
40
|
+
"summary": "Set the missing initial state and add an error recovery transition.",
|
|
41
|
+
"changes": [
|
|
42
|
+
{
|
|
43
|
+
"id": "C-001",
|
|
44
|
+
"action": "set_initial",
|
|
45
|
+
"params": { "state": "INIT" },
|
|
46
|
+
"reason": "Initial state is not set.",
|
|
47
|
+
"evidence": ["STATE_NO_INITIAL"],
|
|
48
|
+
"priority": "high",
|
|
49
|
+
"confidence": 0.95
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"id": "C-002",
|
|
53
|
+
"action": "add_transition",
|
|
54
|
+
"params": {
|
|
55
|
+
"source": "ERROR",
|
|
56
|
+
"event": "RESET",
|
|
57
|
+
"target": "IDLE",
|
|
58
|
+
"action_name": "ResetError"
|
|
59
|
+
},
|
|
60
|
+
"reason": "No error recovery transition from the error state.",
|
|
61
|
+
"evidence": ["STATE_NO_TRANSITION:ERROR"],
|
|
62
|
+
"priority": "high",
|
|
63
|
+
"confidence": 0.90
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}"""
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# ======================================================================
|
|
70
|
+
# Few-shot example 2: removal with multiple evidence items
|
|
71
|
+
# ======================================================================
|
|
72
|
+
FEW_SHOT_EXAMPLE_2 = """{
|
|
73
|
+
"version": "1.0",
|
|
74
|
+
"summary": "Remove the transition to the unreachable Halt state.",
|
|
75
|
+
"changes": [
|
|
76
|
+
{
|
|
77
|
+
"id": "C-001",
|
|
78
|
+
"action": "remove_transition",
|
|
79
|
+
"params": {
|
|
80
|
+
"source": "Idle",
|
|
81
|
+
"event": "STOP",
|
|
82
|
+
"target": "Halt"
|
|
83
|
+
},
|
|
84
|
+
"reason": "Halt is unreachable because no state can reach it.",
|
|
85
|
+
"evidence": [
|
|
86
|
+
"STATE_UNREACHABLE:Halt",
|
|
87
|
+
"TRANSITION_DEAD_END:Idle-STOP-Halt"
|
|
88
|
+
],
|
|
89
|
+
"priority": "medium",
|
|
90
|
+
"confidence": 0.75
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
}"""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# ======================================================================
|
|
97
|
+
# Main template
|
|
98
|
+
# ======================================================================
|
|
99
|
+
PROMPT_TEMPLATES = {
|
|
100
|
+
'diagnosis': {
|
|
101
|
+
'template': """<system>
|
|
102
|
+
You are an expert in embedded software state transition design.
|
|
103
|
+
Your task is to diagnose a state machine design and propose minimal,
|
|
104
|
+
correct, and safe changes.
|
|
105
|
+
</system>
|
|
106
|
+
|
|
107
|
+
<workflow>
|
|
108
|
+
You are part of a semi-automatic design-improvement loop:
|
|
109
|
+
validation -> your proposal -> user review -> apply -> re-validate.
|
|
110
|
+
Your output is a PROPOSAL, not an automatic change.
|
|
111
|
+
Prefer minimal, evidence-based changes that a human can trust.
|
|
112
|
+
If no change is needed, return an empty "changes" array.
|
|
113
|
+
</workflow>
|
|
114
|
+
|
|
115
|
+
<task>
|
|
116
|
+
Diagnose the state machine design shown in <context> using the
|
|
117
|
+
internal validation results in <validation>. Propose minimal, safe
|
|
118
|
+
changes as JSON that conform to <output_schema>.
|
|
119
|
+
</task>
|
|
120
|
+
|
|
121
|
+
<output_schema>
|
|
122
|
+
{output_schema}
|
|
123
|
+
</output_schema>
|
|
124
|
+
|
|
125
|
+
<examples>
|
|
126
|
+
<example id="1">
|
|
127
|
+
{example_1}
|
|
128
|
+
</example>
|
|
129
|
+
|
|
130
|
+
<example id="2">
|
|
131
|
+
{example_2}
|
|
132
|
+
</example>
|
|
133
|
+
</examples>
|
|
134
|
+
|
|
135
|
+
<constraints>
|
|
136
|
+
- Output ONLY the JSON inside <response>...</response> tags.
|
|
137
|
+
- Do NOT invent new state names, event names, or role function names
|
|
138
|
+
unless explicitly required by an error.
|
|
139
|
+
- For every change, provide evidence (validation code or state/event name).
|
|
140
|
+
- Prefer minimal changes: one logical fix per change item.
|
|
141
|
+
- Set "version" to "1.0" exactly.
|
|
142
|
+
</constraints>
|
|
143
|
+
|
|
144
|
+
<context>
|
|
145
|
+
{context}
|
|
146
|
+
</context>
|
|
147
|
+
|
|
148
|
+
<validation>
|
|
149
|
+
{validation}
|
|
150
|
+
</validation>
|
|
151
|
+
|
|
152
|
+
<actions>
|
|
153
|
+
{actions}
|
|
154
|
+
</actions>
|
|
155
|
+
|
|
156
|
+
<response_format>
|
|
157
|
+
Output exactly ONE JSON object wrapped in <response>...</response> tags.
|
|
158
|
+
No text, no markdown fences, no explanations outside the tags.
|
|
159
|
+
</response_format>
|
|
160
|
+
""",
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
# Legacy constants kept for backward compatibility with older code
|
|
166
|
+
# that imports them. They are not used by the new template.
|
|
167
|
+
FEW_SHOT_EXAMPLE = FEW_SHOT_EXAMPLE_1
|
|
168
|
+
|
|
169
|
+
VALIDATION_POINTS = """[Validation points]
|
|
170
|
+
1. Is the initial state set?
|
|
171
|
+
2. Are transitions defined for all states?
|
|
172
|
+
3. Is there a recovery transition from the error state?
|
|
173
|
+
4. Are all events that each state should handle covered?
|
|
174
|
+
5. Are there any unreachable states?
|
|
175
|
+
6. Is there any possibility of deadlock?
|
|
176
|
+
"""
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# codegen/validate/data/validation_rules.py
|
|
2
|
+
"""Validation rule definitions (data only)."""
|
|
3
|
+
|
|
4
|
+
VALIDATION_RULES = {
|
|
5
|
+
'state': {
|
|
6
|
+
'STATE_NO_INITIAL': {
|
|
7
|
+
'severity': 'error',
|
|
8
|
+
'message': 'Initial state is not set',
|
|
9
|
+
'suggestion': 'Please set initial state with set_initial()',
|
|
10
|
+
},
|
|
11
|
+
'STATE_UNREACHABLE': {
|
|
12
|
+
'severity': 'warning',
|
|
13
|
+
'message': 'State "{name}" is unreachable',
|
|
14
|
+
'suggestion': 'Add a transition or delete the state',
|
|
15
|
+
},
|
|
16
|
+
'STATE_NO_TRANSITION': {
|
|
17
|
+
'severity': 'warning',
|
|
18
|
+
'message': 'State "{name}" has no outgoing transition',
|
|
19
|
+
'suggestion': 'Add a transition or mark this as a terminal state',
|
|
20
|
+
},
|
|
21
|
+
'STATE_DUPLICATE': {
|
|
22
|
+
'severity': 'warning',
|
|
23
|
+
'message': 'State names "{name}" and "{other}" differ in case',
|
|
24
|
+
'suggestion': 'Please unify the naming convention',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
'event': {
|
|
28
|
+
'EVENT_UNUSED': {
|
|
29
|
+
'severity': 'warning',
|
|
30
|
+
'message': 'Event "{name}" is not used',
|
|
31
|
+
'suggestion': 'Add a transition or delete the event',
|
|
32
|
+
},
|
|
33
|
+
'EVENT_NO_TRANSITION': {
|
|
34
|
+
'severity': 'warning',
|
|
35
|
+
'message': 'No transition defined for event "{name}"',
|
|
36
|
+
'suggestion': 'Please add a transition',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
'transition': {
|
|
40
|
+
'TRANSITION_TARGET_UNDEFINED': {
|
|
41
|
+
'severity': 'error',
|
|
42
|
+
'message': 'Target "{target}" is not defined',
|
|
43
|
+
'suggestion': 'Please define the target state',
|
|
44
|
+
},
|
|
45
|
+
'TRANSITION_EVENT_UNDEFINED': {
|
|
46
|
+
'severity': 'error',
|
|
47
|
+
'message': 'Event "{event}" is not defined',
|
|
48
|
+
'suggestion': 'Please define the event',
|
|
49
|
+
},
|
|
50
|
+
'TRANSITION_SOURCE_UNDEFINED': {
|
|
51
|
+
'severity': 'error',
|
|
52
|
+
'message': 'Source "{source}" is not defined',
|
|
53
|
+
'suggestion': 'Please define the source state',
|
|
54
|
+
},
|
|
55
|
+
'TRANSITION_DUPLICATE': {
|
|
56
|
+
'severity': 'warning',
|
|
57
|
+
'message': 'Transition "{source} --[{event}]--> {target}" is duplicated',
|
|
58
|
+
'suggestion': 'Please delete the duplicate transition',
|
|
59
|
+
},
|
|
60
|
+
'TRANSITION_SELF_LOOP': {
|
|
61
|
+
'severity': 'info',
|
|
62
|
+
'message': 'Self transition "{source} --[{event}]--> {source}"',
|
|
63
|
+
'suggestion': 'Please confirm whether the self transition is intentional',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
'role_function': {
|
|
67
|
+
'ROLE_FUNC_NO_RETURN_TYPE': {
|
|
68
|
+
'severity': 'error',
|
|
69
|
+
'message': 'Role function "{name}" has no return type defined',
|
|
70
|
+
'suggestion': 'Please set the return type',
|
|
71
|
+
},
|
|
72
|
+
'ROLE_FUNC_ARG_MISMATCH': {
|
|
73
|
+
'severity': 'error',
|
|
74
|
+
'message': 'Role function "{name}" has incomplete argument definitions',
|
|
75
|
+
'suggestion': 'Please set argument names and types correctly',
|
|
76
|
+
},
|
|
77
|
+
'ROLE_FUNC_UNUSED': {
|
|
78
|
+
'severity': 'warning',
|
|
79
|
+
'message': 'Role function "{name}" is not used',
|
|
80
|
+
'suggestion': 'Please use it or delete it',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
'variable': {
|
|
84
|
+
'VAR_DUPLICATE_NAME': {
|
|
85
|
+
'severity': 'error',
|
|
86
|
+
'message': 'Variable name "{name}" is duplicated',
|
|
87
|
+
'suggestion': 'Please change the variable name',
|
|
88
|
+
},
|
|
89
|
+
'VAR_INVALID_TYPE': {
|
|
90
|
+
'severity': 'warning',
|
|
91
|
+
'message': 'Variable "{name}" has invalid type "{type}"',
|
|
92
|
+
'suggestion': 'Please specify a valid type',
|
|
93
|
+
},
|
|
94
|
+
'VAR_INVALID_ARRAY_SIZE': {
|
|
95
|
+
'severity': 'error',
|
|
96
|
+
'message': 'Variable "{name}" has an invalid array size',
|
|
97
|
+
'suggestion': 'Array size must be greater than 0',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
'flag': {
|
|
101
|
+
'FLAG_DUPLICATE_NAME': {
|
|
102
|
+
'severity': 'error',
|
|
103
|
+
'message': 'Flag name "{name}" is duplicated',
|
|
104
|
+
'suggestion': 'Please change the flag name',
|
|
105
|
+
},
|
|
106
|
+
'FLAG_INVALID_RANGE': {
|
|
107
|
+
'severity': 'warning',
|
|
108
|
+
'message': 'Flag "{name}" has invalid range',
|
|
109
|
+
'suggestion': 'min_value <= max_value required',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
'queue': {
|
|
113
|
+
'QUEUE_INVALID_SIZE': {
|
|
114
|
+
'severity': 'error',
|
|
115
|
+
'message': 'Queue "{name}" has an invalid size',
|
|
116
|
+
'suggestion': 'Size must be greater than 0',
|
|
117
|
+
},
|
|
118
|
+
'QUEUE_UNDEFINED_EVENT': {
|
|
119
|
+
'severity': 'warning',
|
|
120
|
+
'message': 'Queue "{name}" contains undefined events',
|
|
121
|
+
'suggestion': 'Please confirm the event definitions',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
'interrupt': {
|
|
125
|
+
'INTERRUPT_DUPLICATE_NAME': {
|
|
126
|
+
'severity': 'error',
|
|
127
|
+
'message': 'Interrupt name "{name}" is duplicated',
|
|
128
|
+
'suggestion': 'Please change the interrupt name',
|
|
129
|
+
},
|
|
130
|
+
'INTERRUPT_UNDEFINED_EVENT': {
|
|
131
|
+
'severity': 'warning',
|
|
132
|
+
'message': 'Interrupt "{name}" contains undefined events',
|
|
133
|
+
'suggestion': 'Please confirm the event definitions',
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
'timer': {
|
|
137
|
+
'TIMER_DUPLICATE_VARIABLE': {
|
|
138
|
+
'severity': 'error',
|
|
139
|
+
'message': 'Timer variable "{name}" duplicates an existing variable',
|
|
140
|
+
'suggestion': 'Please change the variable name',
|
|
141
|
+
},
|
|
142
|
+
'TIMER_INVALID_MULTIPLIER': {
|
|
143
|
+
'severity': 'error',
|
|
144
|
+
'message': 'Timer "{name}" has an invalid multiplier',
|
|
145
|
+
'suggestion': 'Multiplier must be > 0',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
'custom_type': {
|
|
149
|
+
'TYPE_DUPLICATE_NAME': {
|
|
150
|
+
'severity': 'error',
|
|
151
|
+
'message': 'Type name "{name}" is duplicated',
|
|
152
|
+
'suggestion': 'Please change the type name',
|
|
153
|
+
},
|
|
154
|
+
'TYPE_NO_MEMBERS': {
|
|
155
|
+
'severity': 'warning',
|
|
156
|
+
'message': 'Type "{name}" has no members defined',
|
|
157
|
+
'suggestion': 'Please add a member',
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
# ==============================================================
|
|
161
|
+
# v2.2: cell-level validation rules
|
|
162
|
+
# ==============================================================
|
|
163
|
+
'cell': {
|
|
164
|
+
'CELL_EMPTY_CONDITION': {
|
|
165
|
+
'severity': 'warning',
|
|
166
|
+
'message': 'Transition has no condition and no target (no-op)',
|
|
167
|
+
'suggestion': 'Remove the no-op transition or add a condition/target',
|
|
168
|
+
},
|
|
169
|
+
'CELL_DUPLICATE_LABEL': {
|
|
170
|
+
'severity': 'error',
|
|
171
|
+
'message': 'Duplicate transition label "{label}"',
|
|
172
|
+
'suggestion': 'Assign a unique label to each transition',
|
|
173
|
+
},
|
|
174
|
+
'CELL_DANGLING_RELATION': {
|
|
175
|
+
'severity': 'error',
|
|
176
|
+
'message': 'Relation references missing label "{label}"',
|
|
177
|
+
'suggestion': 'Fix the relation members or add the referenced transition',
|
|
178
|
+
},
|
|
179
|
+
'CELL_UNREACHABLE_TRANSITION': {
|
|
180
|
+
'severity': 'warning',
|
|
181
|
+
'message': 'Transition "{label}" is unreachable',
|
|
182
|
+
'suggestion': 'Remove it or adjust the preceding Commit transition',
|
|
183
|
+
},
|
|
184
|
+
'CELL_OVERLAP_POSSIBLE': {
|
|
185
|
+
'severity': 'warning',
|
|
186
|
+
'message': 'Two transitions share condition "{condition}"',
|
|
187
|
+
'suggestion': 'Differentiate the conditions or merge the transitions',
|
|
188
|
+
},
|
|
189
|
+
'CELL_DUPLICATE_TARGET': {
|
|
190
|
+
'severity': 'info',
|
|
191
|
+
'message': 'Multiple transitions target "{target}"',
|
|
192
|
+
'suggestion': 'Confirm whether this is intentional',
|
|
193
|
+
},
|
|
194
|
+
'CELL_EXCLUSIVE_NO_RETURN': {
|
|
195
|
+
'severity': 'info',
|
|
196
|
+
'message': 'Exclusive member "{label}" lacks early_return=True',
|
|
197
|
+
'suggestion': 'Enable early_return to enforce mutual exclusion',
|
|
198
|
+
},
|
|
199
|
+
'CELL_EMPTY_TARGET': {
|
|
200
|
+
'severity': 'warning',
|
|
201
|
+
'message': 'Transition "{label}" has no target and no early_return',
|
|
202
|
+
'suggestion': 'Set a target or enable early_return',
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
}
|