ApiLogicServer 15.4.1__py3-none-any.whl → 16.0.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.
- api_logic_server_cli/add_cust/add_cust.py +6 -2
- api_logic_server_cli/api_logic_server.py +3 -2
- api_logic_server_cli/database/basic_demo.sqlite +0 -0
- api_logic_server_cli/prototypes/base/.github/.copilot-instructions.md +248 -74
- api_logic_server_cli/prototypes/base/docs/training/MCP_Copilot_Integration.md +28 -0
- api_logic_server_cli/prototypes/base/docs/training/OVERVIEW.md +64 -0
- api_logic_server_cli/prototypes/base/docs/training/README.md +140 -0
- api_logic_server_cli/prototypes/base/docs/training/genai_logic_patterns.md +443 -0
- api_logic_server_cli/prototypes/base/docs/training/logic_bank_api.prompt +22 -0
- api_logic_server_cli/prototypes/base/docs/training/logic_bank_patterns.prompt +445 -0
- api_logic_server_cli/prototypes/base/docs/training/probabilistic_logic.prompt +1074 -0
- api_logic_server_cli/prototypes/base/docs/training/probabilistic_logic_guide.md +444 -0
- api_logic_server_cli/prototypes/base/docs/training/probabilistic_template.py +326 -0
- api_logic_server_cli/prototypes/base/logic/logic_discovery/auto_discovery.py +8 -9
- api_logic_server_cli/prototypes/basic_demo/.github/.copilot-instructions.md +333 -121
- api_logic_server_cli/prototypes/basic_demo/.github/welcome.md +15 -1
- api_logic_server_cli/prototypes/basic_demo/customizations/database/db.sqlite +0 -0
- api_logic_server_cli/prototypes/basic_demo/iteration/database/db.sqlite +0 -0
- api_logic_server_cli/prototypes/manager/.github/.copilot-instructions.md +61 -155
- api_logic_server_cli/prototypes/manager/.github/welcome.md +43 -0
- api_logic_server_cli/prototypes/manager/samples/basic_demo_sample/.github/.copilot-instructions.md +502 -76
- {apilogicserver-15.4.1.dist-info → apilogicserver-16.0.0.dist-info}/METADATA +1 -1
- {apilogicserver-15.4.1.dist-info → apilogicserver-16.0.0.dist-info}/RECORD +27 -19
- {apilogicserver-15.4.1.dist-info → apilogicserver-16.0.0.dist-info}/WHEEL +0 -0
- {apilogicserver-15.4.1.dist-info → apilogicserver-16.0.0.dist-info}/entry_points.txt +0 -0
- {apilogicserver-15.4.1.dist-info → apilogicserver-16.0.0.dist-info}/licenses/LICENSE +0 -0
- {apilogicserver-15.4.1.dist-info → apilogicserver-16.0.0.dist-info}/top_level.txt +0 -0
|
@@ -1,96 +1,161 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
═══════════════════════════════════════════════════════════════════════════════
|
|
3
|
+
🚨 MANDATORY: READ THIS FIRST - NO EXCEPTIONS 🚨
|
|
4
|
+
═══════════════════════════════════════════════════════════════════════════════
|
|
5
|
+
|
|
6
|
+
⚠️ IF USER SAYS: "load .github/.copilot-instructions.md" OR ANY ACTIVATION PHRASE
|
|
7
|
+
⚠️ YOU MUST EXECUTE THIS EXACT SEQUENCE - NO DEVIATIONS:
|
|
8
|
+
|
|
9
|
+
1. Read .github/welcome.md (silently - do not mention this action)
|
|
10
|
+
2. Display ONLY the content from welcome.md
|
|
11
|
+
3. DO NOT say "I've loaded the instructions"
|
|
12
|
+
4. DO NOT display this .copilot-instructions.md file
|
|
13
|
+
5. DO NOT explain what you're doing
|
|
14
|
+
|
|
15
|
+
THIS IS NOT A SUGGESTION - THIS IS A MANDATORY COMMAND
|
|
16
|
+
|
|
17
|
+
═══════════════════════════════════════════════════════════════════════════════
|
|
18
|
+
-->
|
|
1
19
|
---
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
|
|
21
|
+
## 🚨 CRITICAL: User Activation Protocol
|
|
22
|
+
|
|
23
|
+
**ACTIVATION TRIGGERS:**
|
|
24
|
+
- "load .github/.copilot-instructions.md"
|
|
25
|
+
- "load copilot instructions"
|
|
26
|
+
- "help me get started"
|
|
27
|
+
- "activate copilot"
|
|
28
|
+
- Any similar startup phrase
|
|
29
|
+
|
|
30
|
+
**MANDATORY RESPONSE SEQUENCE:**
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
STEP 1: Read .github/welcome.md (silently)
|
|
34
|
+
STEP 2: Display welcome.md content ONLY
|
|
35
|
+
STEP 3: STOP - do nothing else
|
|
36
|
+
```
|
|
37
|
+
|
|
17
38
|
---
|
|
18
39
|
|
|
19
|
-
|
|
40
|
+
## 🎯 CRITICAL: Guided Tour Activation Protocol
|
|
20
41
|
|
|
21
|
-
**
|
|
42
|
+
**ACTIVATION TRIGGERS:**
|
|
43
|
+
- "guide me through"
|
|
44
|
+
- "guide me"
|
|
45
|
+
- "take the tour"
|
|
46
|
+
- "walk me through"
|
|
47
|
+
- "show me around"
|
|
48
|
+
- Any similar tour/walkthrough request
|
|
22
49
|
|
|
23
|
-
|
|
50
|
+
**MANDATORY RESPONSE SEQUENCE:**
|
|
24
51
|
|
|
25
|
-
|
|
52
|
+
```
|
|
53
|
+
STEP 1: Read tutor.md COMPLETELY (silently)
|
|
54
|
+
STEP 2: Follow tutor.md instructions EXACTLY
|
|
55
|
+
STEP 3: Act as TOUR GUIDE (not passive assistant)
|
|
56
|
+
STEP 4: Create manage_todo_list for tour sections
|
|
57
|
+
STEP 5: Start with tutor.md Introduction section
|
|
58
|
+
```
|
|
26
59
|
|
|
27
|
-
|
|
60
|
+
**✅ CORRECT EXECUTION:**
|
|
61
|
+
```
|
|
62
|
+
User: "guide me"
|
|
28
63
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
- **Business Logic Engine** - Declarative rules system
|
|
64
|
+
AI: [reads tutor.md completely - NO OUTPUT]
|
|
65
|
+
AI: [creates todo list from tutor sections]
|
|
66
|
+
AI: [follows tutor.md Introduction section exactly]
|
|
67
|
+
AI: "I'll guide you through basic_demo - a 20-minute hands-on exploration..."
|
|
68
|
+
```
|
|
35
69
|
|
|
36
|
-
|
|
70
|
+
**❌ FORBIDDEN BEHAVIORS:**
|
|
71
|
+
```
|
|
72
|
+
User: "guide me"
|
|
73
|
+
|
|
74
|
+
❌ AI: Starts giving general guidance without reading tutor.md
|
|
75
|
+
❌ AI: Runs commands without following tutor choreography
|
|
76
|
+
❌ AI: Acts as passive assistant waiting for user direction
|
|
77
|
+
❌ AI: Skips sections or reorders steps
|
|
78
|
+
❌ AI: Offers option menus instead of directing the tour
|
|
79
|
+
❌ AI: Assumes server state or skips stop/start sequences
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**RATIONALE:**
|
|
83
|
+
- tutor.md contains weeks of refined choreography
|
|
84
|
+
- Every command, stop, start is precisely sequenced
|
|
85
|
+
- Deviations break the learning experience
|
|
86
|
+
- You are the DIRECTOR in tour mode, not a passive responder
|
|
87
|
+
- The tour has been engineered for AI reliability through multiple iterations
|
|
88
|
+
|
|
89
|
+
**✅ CORRECT EXECUTION:**
|
|
90
|
+
```
|
|
91
|
+
User: "load .github/.copilot-instructions.md"
|
|
92
|
+
|
|
93
|
+
AI: [reads welcome.md silently - NO OUTPUT]
|
|
94
|
+
AI: [displays ONLY this]:
|
|
95
|
+
|
|
96
|
+
## Welcome
|
|
97
|
+
|
|
98
|
+
**Welcome! This is your basic_demo project.**
|
|
99
|
+
|
|
100
|
+
This is a complete, working microservice auto-generated from a database schema...
|
|
101
|
+
[... rest of welcome.md content ...]
|
|
102
|
+
```
|
|
37
103
|
|
|
38
|
-
|
|
104
|
+
**❌ FORBIDDEN BEHAVIORS:**
|
|
105
|
+
```
|
|
106
|
+
User: "load .github/.copilot-instructions.md"
|
|
39
107
|
|
|
40
|
-
|
|
108
|
+
❌ AI: "I've loaded the instructions file..."
|
|
109
|
+
❌ AI: "Here are the contents of .copilot-instructions.md:"
|
|
110
|
+
❌ AI: [displays .copilot-instructions.md]
|
|
111
|
+
❌ AI: "I'll read the file for you..."
|
|
112
|
+
❌ AI: Any meta-commentary about loading or reading files
|
|
113
|
+
```
|
|
41
114
|
|
|
42
|
-
**
|
|
115
|
+
**RATIONALE:**
|
|
116
|
+
- Users want to see the **welcome message**, not technical instructions
|
|
117
|
+
- This file (.copilot-instructions.md) is for AI context, not user display
|
|
118
|
+
- Separation of concerns: welcome.md = user-facing, copilot-instructions.md = AI-facing
|
|
119
|
+
- No meta-cognitive confusion about "instructions" vs "content"
|
|
43
120
|
|
|
44
121
|
---
|
|
45
122
|
|
|
46
|
-
|
|
123
|
+
## Capabilities Reference
|
|
124
|
+
|
|
125
|
+
When user asks "what can I do here", list these capabilities:
|
|
47
126
|
|
|
48
|
-
|
|
127
|
+
### Here Are Some Things I Can Help You With
|
|
49
128
|
|
|
50
|
-
1. **Add business logic** - Describe
|
|
129
|
+
1. **Add business logic** - Describe requirements in natural language, I'll generate declarative rules (deterministic + AI-driven)
|
|
51
130
|
2. **Customize the API** - Add custom endpoints for your specific needs
|
|
52
131
|
3. **Create custom UIs** - Build React apps with `genai-logic genai-add-app --vibe`
|
|
53
132
|
4. **Add security** - Set up role-based access control with `genai-logic add-auth`
|
|
54
133
|
5. **Test your logic** - Create Behave tests with requirements traceability
|
|
55
134
|
6. **Configure Admin UI** - Customize the auto-generated admin interface
|
|
56
|
-
7. **Query via natural language** -
|
|
135
|
+
7. **Query via natural language** - Act as MCP client to read/update data
|
|
57
136
|
8. **Create B2B APIs** - Complex integration endpoints with partner systems
|
|
58
137
|
9. **Add events** - Integrate with Kafka, webhooks, or other event systems
|
|
59
138
|
10. **Customize models** - Add tables, attributes, or derived fields
|
|
60
139
|
11. **Discovery systems** - Auto-load logic and APIs from discovery folders
|
|
61
140
|
|
|
62
|
-
Want to get started? Press **F5** to start the server with debugger support, then open `http://localhost:5656`. (There are also run configurations for running tests and other tasks.) Or just ask me what you'd like to work on.
|
|
63
|
-
|
|
64
141
|
---
|
|
65
142
|
|
|
66
|
-
## 🔑 Key Technical Points
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
**DO NOT create your own summary. DO NOT rephrase. Copy the text above exactly.**
|
|
70
|
-
|
|
71
|
-
The technical reference sections below are for later consultation when working on specific tasks.
|
|
72
|
-
|
|
73
143
|
---
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
| 8️⃣ | **Create B2B APIs** | Complex integration endpoints with partner systems |
|
|
87
|
-
| 9️⃣ | **Add events** | Integrate with Kafka, webhooks, or other event systems |
|
|
88
|
-
| 🔟 | **Customize models** | Add tables, attributes, or derived fields |
|
|
89
|
-
| 1️⃣1️⃣ | **Discovery systems** | Auto-load logic and APIs from discovery folders |
|
|
90
|
-
|
|
144
|
+
title: Copilot Instructions for basic_demo GenAI-Logic Project
|
|
145
|
+
Description: Project-level instructions for working with generated projects
|
|
146
|
+
Source: ApiLogicServer-src/prototypes/base/.github/.copilot-instructions.md
|
|
147
|
+
Propagation: CLI create command → created projects (non-basic_demo)
|
|
148
|
+
Instrucions: Changes must be merged from api_logic_server_cli/prototypes/basic_demo/.github - see instructions there
|
|
149
|
+
Usage: AI assistants read this when user opens any created project
|
|
150
|
+
version: 3.1
|
|
151
|
+
changelog:
|
|
152
|
+
- 3.1 (Nov 20, 2025) - Improved activation instructions with visual markers and examples
|
|
153
|
+
- 3.0 (Nov 17, 2025) - Major streamlining: removed duplicate sections, consolidated MCP content, simplified workflows
|
|
154
|
+
- 2.9 (Nov 17, 2025) - MANDATORY training file reading workflow (STOP command)
|
|
155
|
+
- 2.8 (Nov 16, 2025) - Probabilistic Logic support
|
|
91
156
|
---
|
|
92
157
|
|
|
93
|
-
|
|
158
|
+
# GitHub Copilot Instructions for GenAI-Logic (aka API Logic Server) Projects
|
|
94
159
|
|
|
95
160
|
---
|
|
96
161
|
|
|
@@ -127,16 +192,32 @@ The sections below provide complete details on each service. I'll reference thes
|
|
|
127
192
|
|
|
128
193
|
To establish the virtual environment:
|
|
129
194
|
|
|
130
|
-
1. Attempt to find a `venv` folder in the
|
|
131
|
-
2.
|
|
195
|
+
1. Attempt to find a `venv` folder in the current project directory
|
|
196
|
+
2. If not found, check parent or grandparent directories
|
|
197
|
+
3. **If no venv is found:**
|
|
198
|
+
- Ask the user for the venv location, OR
|
|
199
|
+
- Offer to create one using `python3 -m venv venv && source venv/bin/activate && pip install -r requirements.txt`
|
|
132
200
|
|
|
133
201
|
### Starting the server
|
|
134
202
|
|
|
203
|
+
**IMPORTANT:** Always activate the venv before starting the server.
|
|
204
|
+
|
|
135
205
|
```bash
|
|
206
|
+
# Activate venv first
|
|
207
|
+
source venv/bin/activate
|
|
208
|
+
|
|
209
|
+
# Then start server
|
|
136
210
|
python api_logic_server_run.py
|
|
137
211
|
# Then open: http://localhost:5656
|
|
138
212
|
```
|
|
139
213
|
|
|
214
|
+
**Server Management Best Practices:**
|
|
215
|
+
- Before making structural changes (models, logic files), STOP the running server to avoid file locking issues
|
|
216
|
+
- To stop server: `pkill -f "python api_logic_server_run.py"` or use Ctrl+C if running in foreground
|
|
217
|
+
- USER ACTION: After making changes, user restarts server (e.g., `python api_logic_server_run.py &`)
|
|
218
|
+
- Monitor startup output for errors, especially after database/model changes
|
|
219
|
+
- If server fails to start after model changes, check that alembic migrations have been applied
|
|
220
|
+
|
|
140
221
|
### Adding Business Logic
|
|
141
222
|
`docs/training` explains how to translate Natural Language logic into LogicBank (Python) rules like:
|
|
142
223
|
|
|
@@ -146,47 +227,100 @@ Rule.sum(derive=Customer.Balance, as_sum_of=Order.AmountTotal)
|
|
|
146
227
|
Rule.constraint(validate=Customer, as_condition=lambda row: row.Balance <= row.CreditLimit)
|
|
147
228
|
```
|
|
148
229
|
|
|
149
|
-
|
|
230
|
+
**⚠️ CRITICAL: docs/training/ Folder Organization**
|
|
231
|
+
|
|
232
|
+
The `docs/training/` folder contains ONLY universal, framework-level training materials:
|
|
233
|
+
- ✅ **Universal patterns** → `genai_logic_patterns.md`
|
|
234
|
+
- ✅ **Implementation patterns** → `probabilistic_logic_guide.md`
|
|
235
|
+
- ✅ **Code templates** → `probabilistic_template.py`
|
|
236
|
+
- ✅ **API references** → `.prompt` files (logic_bank_api.prompt, etc.)
|
|
237
|
+
|
|
238
|
+
**DO NOT add project-specific content to docs/training/**:
|
|
239
|
+
- ❌ Project-specific instructions or configurations
|
|
240
|
+
- ❌ Alembic migration guides specific to this project
|
|
241
|
+
- ❌ File structures specific to basic_demo
|
|
242
|
+
- ❌ Copilot instructions that reference specific project paths
|
|
243
|
+
|
|
244
|
+
**WHY:** This folder's content is designed to be reusable across ANY ApiLogicServer project using GenAI. Project-specific content should live in:
|
|
245
|
+
- Logic implementation → `logic/logic_discovery/`
|
|
246
|
+
- Project docs → `docs/` (outside training/)
|
|
247
|
+
- Copilot instructions → `.github/.copilot-instructions.md`
|
|
248
|
+
|
|
249
|
+
See `docs/training/README.md` for complete organization rules.
|
|
250
|
+
|
|
251
|
+
**⚠️ MANDATORY WORKFLOW - BEFORE Implementing ANY Business Logic:**
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
STOP ✋
|
|
255
|
+
|
|
256
|
+
READ ALL TRAINING FILES IN ORDER (every single time):
|
|
257
|
+
|
|
258
|
+
1. docs/training/logic_bank_patterns.prompt (Foundation - ALWAYS READ FIRST)
|
|
259
|
+
2. docs/training/logic_bank_api.prompt (Deterministic rules - ALWAYS READ SECOND)
|
|
260
|
+
3. docs/training/probabilistic_logic.prompt (AI/Probabilistic rules - ALWAYS READ THIRD)
|
|
261
|
+
|
|
262
|
+
⚠️ CRITICAL REQUIREMENTS:
|
|
263
|
+
- DO NOT skip any files, even if you think you know the pattern
|
|
264
|
+
- DO NOT selectively read based on keywords in the user's request
|
|
265
|
+
- READ ALL THREE FILES IN SEQUENCE before writing any code
|
|
266
|
+
- These files contain failure patterns and correct implementations learned from production use
|
|
267
|
+
|
|
268
|
+
THEN (and only then) implement the logic.
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
**Training File Contents:**
|
|
150
272
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
273
|
+
1. **`docs/training/logic_bank_patterns.prompt`** - Foundation patterns for ALL rule types
|
|
274
|
+
- Event handler signatures (row, old_row, logic_row) - REQUIRED READING
|
|
275
|
+
- Logging with logic_row.log() vs app_logger
|
|
276
|
+
- Request Pattern with new_logic_row()
|
|
277
|
+
- Rule API syntax dos and don'ts
|
|
278
|
+
- Common anti-patterns to avoid
|
|
279
|
+
|
|
280
|
+
2. **`docs/training/logic_bank_api.prompt`** - Deterministic rules API
|
|
281
|
+
- Rule.sum(), Rule.count(), Rule.formula(), Rule.constraint(), etc.
|
|
282
|
+
- Complete API signatures with all parameters
|
|
283
|
+
- References patterns file for implementation details
|
|
284
|
+
|
|
285
|
+
3. **`docs/training/probabilistic_logic.prompt`** - Probabilistic (AI) rules API
|
|
286
|
+
- populate_ai_values() utility for AI-driven value computation
|
|
287
|
+
- Intelligent selection patterns (supplier optimization, dynamic pricing, route selection)
|
|
288
|
+
- Automatic audit trails and graceful fallbacks when API unavailable
|
|
289
|
+
- References patterns file for general implementations
|
|
290
|
+
- Works seamlessly with deterministic rules
|
|
154
291
|
|
|
155
|
-
|
|
292
|
+
**Example Natural Language Logic for basic_demo:**
|
|
156
293
|
|
|
157
294
|
```text
|
|
158
295
|
Use case: Check Credit
|
|
159
|
-
1.
|
|
160
|
-
2.
|
|
161
|
-
3.
|
|
162
|
-
4.
|
|
163
|
-
5.
|
|
296
|
+
1. Customer balance ≤ credit limit
|
|
297
|
+
2. Customer balance = sum of unshipped Order amount_total
|
|
298
|
+
3. Order amount_total = sum of Item amount
|
|
299
|
+
4. Item amount = quantity × unit_price
|
|
300
|
+
5. Item unit_price = copied from Product unit_price
|
|
164
301
|
|
|
165
302
|
Use case: App Integration
|
|
166
|
-
1. Send
|
|
303
|
+
1. Send Order to Kafka when date_shipped changes to non-null
|
|
167
304
|
```
|
|
168
305
|
|
|
169
|
-
**
|
|
306
|
+
**Why Declarative Rules Matter:**
|
|
170
307
|
|
|
171
|
-
|
|
172
|
-
**
|
|
308
|
+
For developers: Business logic is **typically half the system** in data-centric applications. The real pain with procedural code isn't just volume (200+ lines vs 5 rules) - it's **maintenance**:
|
|
309
|
+
- **Finding insertion points** - you must analyze existing code to figure out where new logic goes
|
|
310
|
+
- **Automatic ordering** - add rules anywhere that makes sense, confident they'll run in the right order
|
|
311
|
+
- **Understanding intent** - you see WHAT it does (business rules) vs HOW (procedural steps)
|
|
173
312
|
|
|
174
|
-
|
|
175
|
-
|--------|----------------------|-----------------|
|
|
176
|
-
| **Lines of Code** | 5 lines | 220+ lines |
|
|
177
|
-
| **Complexity** | Simple rule declarations | Complex event handling |
|
|
178
|
-
| **Maintenance** | Self-documenting business logic<br>Automatic Ordering | Implementation details obscure logic<br>Complex analysis to determine insert points, impacts |
|
|
179
|
-
| **Performance** | Built-in optimization & pruning | Multiple queries, N+1 problems |
|
|
180
|
-
| **Error Handling** | Automatic cascading | Manual event management |
|
|
181
|
-
| **Business Alignment** | Rules match requirements | Code doesn't reflect business intent |
|
|
313
|
+
With declarative rules, you simply state business requirements. The engine handles dependencies, ordering, and optimization automatically.
|
|
182
314
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
315
|
+
LogicBank provides **44X code reduction** (5 lines vs 220+ procedural) with automatic:
|
|
316
|
+
- **Dependency tracking** - listens to SQLAlchemy ORM events at attribute level
|
|
317
|
+
- **Cascading updates** - when Order.customer_id changes, adjusts BOTH old and new Customer.balance
|
|
318
|
+
- **Transitive dependencies** - Item.quantity change cascades through Item.amount → Order.amount_total → Customer.balance
|
|
319
|
+
- **Optimized execution** - uses deltas, not re-aggregation; automatic pruning
|
|
186
320
|
|
|
187
321
|
**Why the Rules Engine is a Correctness Guarantee:**
|
|
188
322
|
|
|
189
|
-
The "2 critical bugs"
|
|
323
|
+
The "2 critical bugs" that even AI-generated procedural code missed:
|
|
190
324
|
1. **Changing Order.customer_id** - procedural code failed to adjust BOTH the old and new customer balances
|
|
191
325
|
2. **Changing Item.product_id** - procedural code failed to re-copy the unit_price from the new product
|
|
192
326
|
|
|
@@ -212,10 +346,7 @@ These bugs illustrate why declarative rules are **mandatory, not optional**:
|
|
|
212
346
|
|
|
213
347
|
The rules engine eliminates this entire class of bugs by automatically handling all change paths.
|
|
214
348
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
Generally CoPilot solicits Natural Language logic for translation (see logic/readme_logic.md),
|
|
218
|
-
but you can also offer to suggest rules.
|
|
349
|
+
See `logic/declarative-vs-procedural-comparison.md` for complete analysis.
|
|
219
350
|
|
|
220
351
|
### Discovery Systems
|
|
221
352
|
|
|
@@ -260,13 +391,32 @@ When users provide natural language with multiple use cases like:
|
|
|
260
391
|
|
|
261
392
|
**NEVER put everything in `use_case.py`** - that defeats the discovery system purpose.
|
|
262
393
|
|
|
263
|
-
### MCP Integration
|
|
394
|
+
### MCP Integration
|
|
395
|
+
|
|
396
|
+
**You (GitHub Copilot) can serve as an MCP client** to query and update database entities using natural language!
|
|
397
|
+
|
|
398
|
+
#### MCP Discovery Endpoint (CRITICAL)
|
|
399
|
+
|
|
400
|
+
**ALWAYS start with the standard MCP discovery endpoint:**
|
|
401
|
+
|
|
402
|
+
```bash
|
|
403
|
+
curl -X GET "http://localhost:5656/.well-known/mcp.json"
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
This endpoint returns:
|
|
407
|
+
- **Available resources** - Customer, Order, Item, Product, etc.
|
|
408
|
+
- **Supported methods** - GET, PATCH, POST, DELETE per resource
|
|
409
|
+
- **Filterable fields** - Which attributes can be used in filters
|
|
410
|
+
- **Base URL and paths** - Resource endpoints like `/Customer`, `/Order`
|
|
411
|
+
- **Learning prompts** - Instructions for MCP clients (fan-out patterns, email handling, response format)
|
|
264
412
|
|
|
265
|
-
**
|
|
413
|
+
**MCP Discovery Pattern:**
|
|
414
|
+
1. **First**: Query `/.well-known/mcp.json` to discover available resources
|
|
415
|
+
2. **Then**: Use discovered schema to construct API calls
|
|
416
|
+
3. **Always**: Follow JSON:API format for CRUD operations
|
|
266
417
|
|
|
267
|
-
**Architecture**: This project implements **MCP Server Executor** - a business logic microservice that AI assistants interact with via authenticated REST API calls. See `docs/training/MCP_Copilot_Integration.md` for complete details.
|
|
268
418
|
|
|
269
|
-
**When users request
|
|
419
|
+
**When users request data operations:**
|
|
270
420
|
|
|
271
421
|
1. **Authenticate first** - Login to obtain JWT token:
|
|
272
422
|
```bash
|
|
@@ -292,15 +442,15 @@ curl -X PATCH http://localhost:5656/api/Customer/ALFKI/ \
|
|
|
292
442
|
- When LogicBank prevents invalid updates, report as: "✅ Business logic working - constraint prevented invalid operation"
|
|
293
443
|
- Example: "balance (2102.00) exceeds credit (1000.00)" = logic is protecting data integrity
|
|
294
444
|
|
|
295
|
-
**Natural Language Translation
|
|
445
|
+
**Natural Language → API Translation:**
|
|
296
446
|
- "List customers" → `GET /api/Customer/`
|
|
297
447
|
- "Show customer ALFKI" → `GET /api/Customer/ALFKI/`
|
|
298
448
|
- "Set ALFKI credit to 5000" → `PATCH /api/Customer/ALFKI/` with CreditLimit
|
|
299
|
-
- "What's ALFKI's balance?" → `GET /api/Customer/ALFKI/` then extract Balance
|
|
449
|
+
- "What's ALFKI's balance?" → `GET /api/Customer/ALFKI/` then extract Balance
|
|
300
450
|
|
|
301
|
-
**Key Principle
|
|
451
|
+
**Key Principle:** Constraint violations (code 2001) demonstrate that declarative business logic is working correctly - celebrate these as successes, not failures!
|
|
302
452
|
|
|
303
|
-
See `docs/training/MCP_Copilot_Integration.md` for
|
|
453
|
+
See `docs/training/MCP_Copilot_Integration.md` for authentication workflows, JSON:API formats, and architecture details.
|
|
304
454
|
|
|
305
455
|
### API Interaction Best Practices
|
|
306
456
|
|
|
@@ -391,22 +541,22 @@ python3 -c "import json; data=json.load(open('customers.json')); print(data['dat
|
|
|
391
541
|
|
|
392
542
|
### Automated Testing
|
|
393
543
|
|
|
394
|
-
|
|
544
|
+
**⚠️ BEFORE Creating Tests:**
|
|
395
545
|
|
|
396
546
|
```
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
547
|
+
STOP ✋
|
|
548
|
+
READ docs/training/testing.md FIRST (555 lines - comprehensive guide)
|
|
549
|
+
|
|
550
|
+
This contains EVERY bug pattern from achieving 11/11 test success:
|
|
551
|
+
- Rule #0: Test Repeatability (timestamps for uniqueness)
|
|
552
|
+
- Rule #0.5: Behave Step Ordering (specific before general)
|
|
553
|
+
- Top 5 Critical Bugs (common AI mistakes)
|
|
554
|
+
- Filter format: filter[column]=value (NOT OData)
|
|
555
|
+
- No circular imports (API only)
|
|
556
|
+
- Null-safe constraints
|
|
557
|
+
- Fresh test data (timestamps for uniqueness)
|
|
558
|
+
|
|
559
|
+
THEN create tests following patterns exactly.
|
|
410
560
|
```
|
|
411
561
|
|
|
412
562
|
**Why This Matters:** AI-generated tests fail 80% of the time without reading this guide first. The training material documents every common mistake (circular imports, wrong filter format, null-unsafe constraints, step ordering, etc.) with exact fixes. This guide achieved 11/11 test success (100%) and contains all discovered patterns.
|
|
@@ -487,6 +637,49 @@ open reports/Behave\ Logic\ Report.md
|
|
|
487
637
|
- **Logic Log**: Complete trace showing before→after values for all adjustments
|
|
488
638
|
- Demonstrates the 44X code reduction by showing rule automation
|
|
489
639
|
|
|
640
|
+
**LOGIC LOG FORMATTING**:
|
|
641
|
+
|
|
642
|
+
**When user says "show me the logic log"**: Display the complete logic execution from the most recent terminal output, showing the full trace from "Logic Phase: ROW LOGIC" through "Logic Phase: COMPLETE" with all row details intact (do NOT use grep commands to extract). Include:
|
|
643
|
+
- Complete Logic Phase sections (ROW LOGIC, COMMIT LOGIC, AFTER_FLUSH LOGIC, COMPLETE)
|
|
644
|
+
- All rule execution lines with full row details
|
|
645
|
+
- "These Rules Fired" summary section
|
|
646
|
+
- Format as code block for readability
|
|
647
|
+
|
|
648
|
+
When displaying logic logs to users, format them with proper hierarchical indentation like the debug console (see https://apilogicserver.github.io/Docs/Logic-Debug/):
|
|
649
|
+
|
|
650
|
+
```
|
|
651
|
+
Logic Phase: ROW LOGIC (session=0x...)
|
|
652
|
+
..Item[None] {Insert - client} id: None, order_id: 1, product_id: 6, quantity: 10
|
|
653
|
+
..Item[None] {Formula unit_price} unit_price: [None-->] 105.0
|
|
654
|
+
....SysSupplierReq[None] {Insert - Supplier AI Request} product_id: 6
|
|
655
|
+
....SysSupplierReq[None] {Event - calling AI} chosen_unit_price: [None-->] 105.0
|
|
656
|
+
..Item[None] {Formula amount} amount: [None-->] 1050.0
|
|
657
|
+
..Item[None] {adjust parent Order.amount_total}
|
|
658
|
+
....Order[1] {Update - Adjusting order: amount_total} amount_total: [300.0-->] 1350.0
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
**Key formatting rules:**
|
|
662
|
+
- `..` prefix = nesting level (2 dots = parent, 4 dots = child/nested object, 6 dots = deeper nesting)
|
|
663
|
+
- **ONE LINE per rule execution** - no line wrapping
|
|
664
|
+
- Each line shows: `Class[id] {action/reason} key_attributes`
|
|
665
|
+
- Value changes shown as: `[old_value-->] new_value`
|
|
666
|
+
- Hierarchical indentation (dots) shows call depth and parent-child relationships
|
|
667
|
+
- Only show relevant attributes, not all row details
|
|
668
|
+
|
|
669
|
+
**EXTRACTING CLEAN LOGIC LOGS**:
|
|
670
|
+
|
|
671
|
+
To get properly formatted logs (one line per rule, no wrapping), use this command:
|
|
672
|
+
|
|
673
|
+
```bash
|
|
674
|
+
# Extract clean logic log from server.log
|
|
675
|
+
grep -A 100 "Logic Phase:.*ROW LOGIC" server.log | \
|
|
676
|
+
awk -F' row: ' '{print $1}' | \
|
|
677
|
+
grep -E "^\.\.|^Logic Phase:" | \
|
|
678
|
+
head -50
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
This removes verbose session/row details and prevents line wrapping.
|
|
682
|
+
|
|
490
683
|
**DEBUGGING TIPS**:
|
|
491
684
|
|
|
492
685
|
```bash
|
|
@@ -510,7 +703,7 @@ cat logs/scenario_logic_logs/Delete_Item_Reduces_Order.log
|
|
|
510
703
|
|
|
511
704
|
If scenario names don't match between behave.log and .log filenames, logic details won't appear!
|
|
512
705
|
|
|
513
|
-
### Adding MCP
|
|
706
|
+
### Adding MCP UI
|
|
514
707
|
|
|
515
708
|
The API is automatically MCP-enabled. The project includes a comprehensive MCP client executor at `integration/mcp/mcp_client_executor.py`, but to enable the **user interface** for MCP requests, you must run this command:
|
|
516
709
|
|
|
@@ -906,14 +1099,33 @@ class ItemB2BMapper(RowDictMapper):
|
|
|
906
1099
|
|
|
907
1100
|
To add tables / columns to the database (highly impactful - request permission):
|
|
908
1101
|
|
|
909
|
-
1. Update `database/
|
|
910
|
-
2.
|
|
911
|
-
|
|
1102
|
+
1. Update `database/models.py` with new models/columns
|
|
1103
|
+
2. Generate and apply Alembic migration (see database/alembic/readme.md):
|
|
1104
|
+
```bash
|
|
1105
|
+
cd database
|
|
1106
|
+
alembic revision --autogenerate -m "Description of changes"
|
|
1107
|
+
```
|
|
1108
|
+
3. **CRITICAL - Edit the migration file:**
|
|
1109
|
+
- `alembic --autogenerate` detects ALL differences between models.py and database
|
|
1110
|
+
- Open the generated file in `database/alembic/versions/`
|
|
1111
|
+
- **Remove ALL unwanted changes** (ALTER TABLE on existing tables)
|
|
1112
|
+
- **Keep ONLY your intended changes** (e.g., CREATE TABLE for new audit table)
|
|
1113
|
+
- Simplify `downgrade()` function to reverse only your changes
|
|
1114
|
+
4. Apply the edited migration:
|
|
1115
|
+
```bash
|
|
1116
|
+
alembic upgrade head
|
|
1117
|
+
```
|
|
1118
|
+
5. Offer to update ui/admin/admin.yaml to add the new table or column to the Admin UI.
|
|
912
1119
|
|
|
913
|
-
|
|
1120
|
+
**General Migration Notes**:
|
|
1121
|
+
- Stop the server before running migrations to avoid database locking
|
|
1122
|
+
- When adding new models, follow existing patterns in models.py
|
|
1123
|
+
- Models should not contain `__bind_key__`
|
|
1124
|
+
- USER ACTION REQUIRED: Restart server after migrations
|
|
914
1125
|
|
|
915
|
-
|
|
1126
|
+
See: https://apilogicserver.github.io/Docs/Database-Changes/#use-alembic-to-update-database-schema-from-model
|
|
916
1127
|
|
|
1128
|
+
If altering `database/models.py`, be sure to follow the patterns shown in the existing models. Note they do not contain a `__bind_key__`.
|
|
917
1129
|
|
|
918
1130
|
### Addressing `Missing Attributes` during logic loading at project startup
|
|
919
1131
|
|
|
@@ -21,6 +21,20 @@ This is a complete, working microservice auto-generated from a database schema -
|
|
|
21
21
|
**First, we'll briefly explore what's automatically created. Then I'll show you how I can help you customize it - adding logic, security, and API endpoints.**
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
**Ready to explore?**
|
|
24
|
+
**Ready to explore?** Just say me "guide me through" to begin the interactive tutorial.
|
|
25
|
+
|
|
26
|
+
**Or, self-demo?** Open `readme_ai_mcp.md` to explore logic, ai and mcp.
|
|
27
|
+
|
|
28
|
+
<!--
|
|
29
|
+
⚠️ AI INSTRUCTION: When user says "guide me" or similar tour activation phrase, you MUST:
|
|
30
|
+
1. Read tutor.md COMPLETELY before responding
|
|
31
|
+
2. Follow tutor.md choreography EXACTLY as written
|
|
32
|
+
3. Act as TOUR GUIDE directing the experience (not passive assistant)
|
|
33
|
+
4. Create manage_todo_list to track tour sections
|
|
34
|
+
5. Do NOT freelance, improvise, or skip sections
|
|
35
|
+
|
|
36
|
+
This is MANDATORY - the tutor.md represents weeks of refined choreography.
|
|
37
|
+
Deviations break the carefully engineered learning experience.
|
|
38
|
+
-->
|
|
25
39
|
|
|
26
40
|
---
|
|
Binary file
|
|
Binary file
|