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
|
@@ -270,8 +270,12 @@ def add_cust(project: Project, models_py_path: Path, project_name: str):
|
|
|
270
270
|
add_basic_demo_customizations(project=project)
|
|
271
271
|
check_credit_path = project.project_directory_path.joinpath('logic/logic_discovery/check_credit.py')
|
|
272
272
|
if check_credit_path.exists():
|
|
273
|
-
check_credit_path.
|
|
274
|
-
log.debug(f'.. .. ..
|
|
273
|
+
check_credit_path.rename(check_credit_path.with_suffix('.pyZ'))
|
|
274
|
+
log.debug(f'.. .. ..Renamed logic_discovery/check_credit.py to .pyZ (from readme_ai_mcp)')
|
|
275
|
+
supplier_selection_path = project.project_directory_path.joinpath('logic/logic_discovery/ai_requests/supplier_selection.py')
|
|
276
|
+
if supplier_selection_path.exists():
|
|
277
|
+
supplier_selection_path.rename(supplier_selection_path.with_suffix('.pyZ'))
|
|
278
|
+
log.debug(f'.. .. ..Renamed logic_discovery/ai_requests/supplier_selection.py to .pyZ (from readme_ai_mcp)')
|
|
275
279
|
else:
|
|
276
280
|
add_basic_demo_iteration(project=project)
|
|
277
281
|
|
|
@@ -12,10 +12,11 @@ ApiLogicServer CLI: given a database url, create [and run] customizable ApiLogic
|
|
|
12
12
|
Called from api_logic_server_cli.py, by instantiating the ProjectRun object.
|
|
13
13
|
'''
|
|
14
14
|
|
|
15
|
-
__version__ = "
|
|
15
|
+
__version__ = "16.00.00" # last public release: 15.04.01
|
|
16
16
|
recent_changes = \
|
|
17
17
|
f'\n\nRecent Changes:\n' +\
|
|
18
|
-
"\t11/
|
|
18
|
+
"\t11/21/2025 - 16.00.00: Probabalistic logic - see basic_demo/readme_ai_mcp.md \n"\
|
|
19
|
+
"\t11/12/2025 - 15.04.03: Copilot rules on updates, tighter basic_demo startup, allow for demo_ai_mcp/then tutorial \n"\
|
|
19
20
|
"\t11/08/2025 - 15.04.00: Nat lang Copilot data access, fix Manager/Copilot startup, finding venv in project \n"\
|
|
20
21
|
"\t10/29/2025 - 15.03.00: Stable Tutor 3.3 (working, vibe transtion) \n"\
|
|
21
22
|
"\t10/26/2025 - 15.02.07: Clarify order created for ship test, security fixes [105], tutor 2.1 \n"\
|
|
Binary file
|
|
@@ -3,32 +3,57 @@ title: Copilot Instructions for GenAI-Logic Projects
|
|
|
3
3
|
Description: Project-level instructions for working with generated projects
|
|
4
4
|
Source: ApiLogicServer-src/prototypes/base/.github/.copilot-instructions.md
|
|
5
5
|
Propagation: CLI create command → created projects (non-basic_demo)
|
|
6
|
-
Instrucions: Changes must be merged from
|
|
6
|
+
Instrucions: Changes must be merged from api_logic_server_cli/prototypes/basic_demo/.github - see instructions there
|
|
7
7
|
Usage: AI assistants read this when user opens any created project
|
|
8
|
-
version:
|
|
8
|
+
version: 3.0
|
|
9
9
|
changelog:
|
|
10
|
-
-
|
|
11
|
-
- 2.
|
|
12
|
-
- 2.
|
|
13
|
-
- 2.2 (Oct 29, 2025 - Clear 1st message about reading Welcome section verbatim)
|
|
14
|
-
- 2.1 (Oct 2025) - Streamlined OBX for non-tutorial projects, friendly collaborative tone
|
|
15
|
-
- 2.0 (Oct 2025) - Added front matter, updated for OBX improvements
|
|
16
|
-
- 1.0 (Initial) - Comprehensive technical reference
|
|
10
|
+
- 3.0 (Nov 17, 2025) - Major streamlining: removed duplicate sections, consolidated MCP content, simplified workflows
|
|
11
|
+
- 2.9 (Nov 17, 2025) - MANDATORY training file reading workflow (STOP command)
|
|
12
|
+
- 2.8 (Nov 16, 2025) - Probabilistic Logic support
|
|
17
13
|
---
|
|
18
14
|
|
|
19
15
|
# GitHub Copilot Instructions for GenAI-Logic (aka API Logic Server) Projects
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ⚠️ INSTRUCTION FOR AI ASSISTANTS
|
|
20
|
+
|
|
21
|
+
**Interaction Tone:** I (Copilot) speak as "I" when helping you. This creates a friendly, collaborative partnership where I assist with your development work.
|
|
22
|
+
|
|
23
|
+
**User activation phrases:**
|
|
24
|
+
- "Please load .github/.copilot-instructions.md"
|
|
25
|
+
- "Load copilot instructions"
|
|
26
|
+
- "What can I do here?"
|
|
27
|
+
- "Help me get started"
|
|
28
|
+
- OR when user first opens this project workspace and greets you
|
|
29
|
+
|
|
30
|
+
**When you see these phrases (or when reading these instructions), IMMEDIATELY:**
|
|
31
|
+
|
|
32
|
+
**Present the Welcome section below** - NO preamble, NO summary, NO meta-commentary
|
|
33
|
+
|
|
34
|
+
**CRITICAL - Do NOT:**
|
|
35
|
+
- Say "I've loaded the instructions"
|
|
36
|
+
- Say "I've read the file"
|
|
37
|
+
- Summarize or describe what's in this file
|
|
38
|
+
- Add any commentary about reading instructions
|
|
39
|
+
|
|
40
|
+
**CRITICAL - DO:**
|
|
41
|
+
- Present the Welcome content directly (exactly) as your response
|
|
42
|
+
- Start with: "Welcome! This is your GenAI-Logic project."
|
|
43
|
+
- Act like you're naturally greeting the user
|
|
44
|
+
- Include the "guide me through" call-to-action
|
|
45
|
+
|
|
46
|
+
---
|
|
22
47
|
|
|
23
48
|
## Welcome
|
|
24
49
|
|
|
25
|
-
**Welcome!
|
|
50
|
+
**Welcome! This is your GenAI-Logic project.**
|
|
26
51
|
|
|
27
52
|
This is a complete, working microservice auto-generated from your database schema.
|
|
28
53
|
|
|
29
54
|
**What's already built:**
|
|
30
55
|
- **Admin Web Application** - Live at `http://localhost:5656`
|
|
31
|
-
- **REST API Endpoints** - All database tables exposed at `/api/*`
|
|
56
|
+
- **REST API Endpoints** - All database tables exposed at `/api/*` (discoverable by MCP clients)
|
|
32
57
|
- **Database Models** - Complete SQLAlchemy ORM in `database/models.py`
|
|
33
58
|
- **Authentication System** - JWT-based auth framework
|
|
34
59
|
- **Business Logic Engine** - Declarative rules system
|
|
@@ -37,18 +62,20 @@ This is a complete, working microservice auto-generated from your database schem
|
|
|
37
62
|
|
|
38
63
|
## Here are some things I can help you with
|
|
39
64
|
|
|
40
|
-
1. **Add business logic** - Describe
|
|
65
|
+
1. **Add business logic** - Describe requirements in natural language, I'll generate declarative rules (deterministic + AI-driven)
|
|
41
66
|
2. **Customize the API** - Add custom endpoints for your specific needs
|
|
42
67
|
3. **Create custom UIs** - Build React apps with `genai-logic genai-add-app --vibe`
|
|
43
68
|
4. **Add security** - Set up role-based access control with `genai-logic add-auth`
|
|
44
69
|
5. **Test your logic** - Create Behave tests with requirements traceability
|
|
45
70
|
6. **Configure Admin UI** - Customize the auto-generated admin interface
|
|
46
|
-
7. **Query via natural language** -
|
|
71
|
+
7. **Query via natural language** - Act as MCP client to read/update data
|
|
47
72
|
8. **Create B2B APIs** - Complex integration endpoints with partner systems
|
|
48
73
|
9. **Add events** - Integrate with Kafka, webhooks, or other event systems
|
|
49
74
|
10. **Customize models** - Add tables, attributes, or derived fields
|
|
50
75
|
11. **Discovery systems** - Auto-load logic and APIs from discovery folders
|
|
51
76
|
|
|
77
|
+
---
|
|
78
|
+
|
|
52
79
|
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.
|
|
53
80
|
|
|
54
81
|
---
|
|
@@ -117,16 +144,32 @@ The sections below provide complete details on each service. I'll reference thes
|
|
|
117
144
|
|
|
118
145
|
To establish the virtual environment:
|
|
119
146
|
|
|
120
|
-
1. Attempt to find a `venv` folder in the
|
|
121
|
-
2.
|
|
147
|
+
1. Attempt to find a `venv` folder in the current project directory
|
|
148
|
+
2. If not found, check parent or grandparent directories
|
|
149
|
+
3. **If no venv is found:**
|
|
150
|
+
- Ask the user for the venv location, OR
|
|
151
|
+
- Offer to create one using `python3 -m venv venv && source venv/bin/activate && pip install -r requirements.txt`
|
|
122
152
|
|
|
123
153
|
### Starting the server
|
|
124
154
|
|
|
155
|
+
**IMPORTANT:** Always activate the venv before starting the server.
|
|
156
|
+
|
|
125
157
|
```bash
|
|
158
|
+
# Activate venv first
|
|
159
|
+
source venv/bin/activate
|
|
160
|
+
|
|
161
|
+
# Then start server
|
|
126
162
|
python api_logic_server_run.py
|
|
127
163
|
# Then open: http://localhost:5656
|
|
128
164
|
```
|
|
129
165
|
|
|
166
|
+
**Server Management Best Practices:**
|
|
167
|
+
- Before making structural changes (models, logic files), STOP the running server to avoid file locking issues
|
|
168
|
+
- To stop server: `pkill -f "python api_logic_server_run.py"` or use Ctrl+C if running in foreground
|
|
169
|
+
- USER ACTION: After making changes, user restarts server (e.g., `python api_logic_server_run.py &`)
|
|
170
|
+
- Monitor startup output for errors, especially after database/model changes
|
|
171
|
+
- If server fails to start after model changes, check that alembic migrations have been applied
|
|
172
|
+
|
|
130
173
|
### Adding Business Logic
|
|
131
174
|
`docs/training` explains how to translate Natural Language logic into LogicBank (Python) rules like:
|
|
132
175
|
|
|
@@ -136,47 +179,100 @@ Rule.sum(derive=Customer.Balance, as_sum_of=Order.AmountTotal)
|
|
|
136
179
|
Rule.constraint(validate=Customer, as_condition=lambda row: row.Balance <= row.CreditLimit)
|
|
137
180
|
```
|
|
138
181
|
|
|
139
|
-
|
|
182
|
+
**⚠️ CRITICAL: docs/training/ Folder Organization**
|
|
183
|
+
|
|
184
|
+
The `docs/training/` folder contains ONLY universal, framework-level training materials:
|
|
185
|
+
- ✅ **Universal patterns** → `genai_logic_patterns.md`
|
|
186
|
+
- ✅ **Implementation patterns** → `probabilistic_logic_guide.md`
|
|
187
|
+
- ✅ **Code templates** → `probabilistic_template.py`
|
|
188
|
+
- ✅ **API references** → `.prompt` files (logic_bank_api.prompt, etc.)
|
|
189
|
+
|
|
190
|
+
**DO NOT add project-specific content to docs/training/**:
|
|
191
|
+
- ❌ Project-specific instructions or configurations
|
|
192
|
+
- ❌ Alembic migration guides specific to this project
|
|
193
|
+
- ❌ File structures specific to basic_demo
|
|
194
|
+
- ❌ Copilot instructions that reference specific project paths
|
|
195
|
+
|
|
196
|
+
**WHY:** This folder's content is designed to be reusable across ANY ApiLogicServer project using GenAI. Project-specific content should live in:
|
|
197
|
+
- Logic implementation → `logic/logic_discovery/`
|
|
198
|
+
- Project docs → `docs/` (outside training/)
|
|
199
|
+
- Copilot instructions → `.github/.copilot-instructions.md`
|
|
200
|
+
|
|
201
|
+
See `docs/training/README.md` for complete organization rules.
|
|
202
|
+
|
|
203
|
+
**⚠️ MANDATORY WORKFLOW - BEFORE Implementing ANY Business Logic:**
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
STOP ✋
|
|
207
|
+
|
|
208
|
+
READ ALL TRAINING FILES IN ORDER (every single time):
|
|
209
|
+
|
|
210
|
+
1. docs/training/logic_bank_patterns.prompt (Foundation - ALWAYS READ FIRST)
|
|
211
|
+
2. docs/training/logic_bank_api.prompt (Deterministic rules - ALWAYS READ SECOND)
|
|
212
|
+
3. docs/training/probabilistic_logic.prompt (AI/Probabilistic rules - ALWAYS READ THIRD)
|
|
213
|
+
|
|
214
|
+
⚠️ CRITICAL REQUIREMENTS:
|
|
215
|
+
- DO NOT skip any files, even if you think you know the pattern
|
|
216
|
+
- DO NOT selectively read based on keywords in the user's request
|
|
217
|
+
- READ ALL THREE FILES IN SEQUENCE before writing any code
|
|
218
|
+
- These files contain failure patterns and correct implementations learned from production use
|
|
219
|
+
|
|
220
|
+
THEN (and only then) implement the logic.
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Training File Contents:**
|
|
140
224
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
225
|
+
1. **`docs/training/logic_bank_patterns.prompt`** - Foundation patterns for ALL rule types
|
|
226
|
+
- Event handler signatures (row, old_row, logic_row) - REQUIRED READING
|
|
227
|
+
- Logging with logic_row.log() vs app_logger
|
|
228
|
+
- Request Pattern with new_logic_row()
|
|
229
|
+
- Rule API syntax dos and don'ts
|
|
230
|
+
- Common anti-patterns to avoid
|
|
231
|
+
|
|
232
|
+
2. **`docs/training/logic_bank_api.prompt`** - Deterministic rules API
|
|
233
|
+
- Rule.sum(), Rule.count(), Rule.formula(), Rule.constraint(), etc.
|
|
234
|
+
- Complete API signatures with all parameters
|
|
235
|
+
- References patterns file for implementation details
|
|
236
|
+
|
|
237
|
+
3. **`docs/training/probabilistic_logic.prompt`** - Probabilistic (AI) rules API
|
|
238
|
+
- populate_ai_values() utility for AI-driven value computation
|
|
239
|
+
- Intelligent selection patterns (supplier optimization, dynamic pricing, route selection)
|
|
240
|
+
- Automatic audit trails and graceful fallbacks when API unavailable
|
|
241
|
+
- References patterns file for general implementations
|
|
242
|
+
- Works seamlessly with deterministic rules
|
|
144
243
|
|
|
145
|
-
|
|
244
|
+
**Example Natural Language Logic for basic_demo:**
|
|
146
245
|
|
|
147
246
|
```text
|
|
148
247
|
Use case: Check Credit
|
|
149
|
-
1.
|
|
150
|
-
2.
|
|
151
|
-
3.
|
|
152
|
-
4.
|
|
153
|
-
5.
|
|
248
|
+
1. Customer balance ≤ credit limit
|
|
249
|
+
2. Customer balance = sum of unshipped Order amount_total
|
|
250
|
+
3. Order amount_total = sum of Item amount
|
|
251
|
+
4. Item amount = quantity × unit_price
|
|
252
|
+
5. Item unit_price = copied from Product unit_price
|
|
154
253
|
|
|
155
254
|
Use case: App Integration
|
|
156
|
-
1. Send
|
|
255
|
+
1. Send Order to Kafka when date_shipped changes to non-null
|
|
157
256
|
```
|
|
158
257
|
|
|
159
|
-
**
|
|
160
|
-
|
|
161
|
-
<analysis>
|
|
162
|
-
**LogicBank declarative rules provide a 44X reduction in code complexity** compared to traditional procedural implementations:
|
|
258
|
+
**Why Declarative Rules Matter:**
|
|
163
259
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
| **Maintenance** | Self-documenting business logic<br>Automatic Ordering | Implementation details obscure logic<br>Complex analysis to determine insert points, impacts |
|
|
169
|
-
| **Performance** | Built-in optimization & pruning | Multiple queries, N+1 problems |
|
|
170
|
-
| **Error Handling** | Automatic cascading | Manual event management |
|
|
171
|
-
| **Business Alignment** | Rules match requirements | Code doesn't reflect business intent |
|
|
260
|
+
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**:
|
|
261
|
+
- **Finding insertion points** - you must analyze existing code to figure out where new logic goes
|
|
262
|
+
- **Automatic ordering** - add rules anywhere that makes sense, confident they'll run in the right order
|
|
263
|
+
- **Understanding intent** - you see WHAT it does (business rules) vs HOW (procedural steps)
|
|
172
264
|
|
|
173
|
-
|
|
265
|
+
With declarative rules, you simply state business requirements. The engine handles dependencies, ordering, and optimization automatically.
|
|
174
266
|
|
|
175
|
-
|
|
267
|
+
LogicBank provides **44X code reduction** (5 lines vs 220+ procedural) with automatic:
|
|
268
|
+
- **Dependency tracking** - listens to SQLAlchemy ORM events at attribute level
|
|
269
|
+
- **Cascading updates** - when Order.customer_id changes, adjusts BOTH old and new Customer.balance
|
|
270
|
+
- **Transitive dependencies** - Item.quantity change cascades through Item.amount → Order.amount_total → Customer.balance
|
|
271
|
+
- **Optimized execution** - uses deltas, not re-aggregation; automatic pruning
|
|
176
272
|
|
|
177
273
|
**Why the Rules Engine is a Correctness Guarantee:**
|
|
178
274
|
|
|
179
|
-
The "2 critical bugs"
|
|
275
|
+
The "2 critical bugs" that even AI-generated procedural code missed:
|
|
180
276
|
1. **Changing Order.customer_id** - procedural code failed to adjust BOTH the old and new customer balances
|
|
181
277
|
2. **Changing Item.product_id** - procedural code failed to re-copy the unit_price from the new product
|
|
182
278
|
|
|
@@ -202,10 +298,7 @@ These bugs illustrate why declarative rules are **mandatory, not optional**:
|
|
|
202
298
|
|
|
203
299
|
The rules engine eliminates this entire class of bugs by automatically handling all change paths.
|
|
204
300
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
Generally CoPilot solicits Natural Language logic for translation (see logic/readme_logic.md),
|
|
208
|
-
but you can also offer to suggest rules.
|
|
301
|
+
See `logic/declarative-vs-procedural-comparison.md` for complete analysis.
|
|
209
302
|
|
|
210
303
|
### Discovery Systems
|
|
211
304
|
|
|
@@ -250,13 +343,32 @@ When users provide natural language with multiple use cases like:
|
|
|
250
343
|
|
|
251
344
|
**NEVER put everything in `use_case.py`** - that defeats the discovery system purpose.
|
|
252
345
|
|
|
253
|
-
### MCP Integration
|
|
346
|
+
### MCP Integration
|
|
347
|
+
|
|
348
|
+
**You (GitHub Copilot) can serve as an MCP client** to query and update database entities using natural language!
|
|
349
|
+
|
|
350
|
+
#### MCP Discovery Endpoint (CRITICAL)
|
|
254
351
|
|
|
255
|
-
**
|
|
352
|
+
**ALWAYS start with the standard MCP discovery endpoint:**
|
|
256
353
|
|
|
257
|
-
|
|
354
|
+
```bash
|
|
355
|
+
curl -X GET "http://localhost:5656/.well-known/mcp.json"
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
This endpoint returns:
|
|
359
|
+
- **Available resources** - Customer, Order, Item, Product, etc.
|
|
360
|
+
- **Supported methods** - GET, PATCH, POST, DELETE per resource
|
|
361
|
+
- **Filterable fields** - Which attributes can be used in filters
|
|
362
|
+
- **Base URL and paths** - Resource endpoints like `/Customer`, `/Order`
|
|
363
|
+
- **Learning prompts** - Instructions for MCP clients (fan-out patterns, email handling, response format)
|
|
364
|
+
|
|
365
|
+
**MCP Discovery Pattern:**
|
|
366
|
+
1. **First**: Query `/.well-known/mcp.json` to discover available resources
|
|
367
|
+
2. **Then**: Use discovered schema to construct API calls
|
|
368
|
+
3. **Always**: Follow JSON:API format for CRUD operations
|
|
258
369
|
|
|
259
|
-
|
|
370
|
+
|
|
371
|
+
**When users request data operations:**
|
|
260
372
|
|
|
261
373
|
1. **Authenticate first** - Login to obtain JWT token:
|
|
262
374
|
```bash
|
|
@@ -282,15 +394,15 @@ curl -X PATCH http://localhost:5656/api/Customer/ALFKI/ \
|
|
|
282
394
|
- When LogicBank prevents invalid updates, report as: "✅ Business logic working - constraint prevented invalid operation"
|
|
283
395
|
- Example: "balance (2102.00) exceeds credit (1000.00)" = logic is protecting data integrity
|
|
284
396
|
|
|
285
|
-
**Natural Language Translation
|
|
397
|
+
**Natural Language → API Translation:**
|
|
286
398
|
- "List customers" → `GET /api/Customer/`
|
|
287
399
|
- "Show customer ALFKI" → `GET /api/Customer/ALFKI/`
|
|
288
400
|
- "Set ALFKI credit to 5000" → `PATCH /api/Customer/ALFKI/` with CreditLimit
|
|
289
|
-
- "What's ALFKI's balance?" → `GET /api/Customer/ALFKI/` then extract Balance
|
|
401
|
+
- "What's ALFKI's balance?" → `GET /api/Customer/ALFKI/` then extract Balance
|
|
290
402
|
|
|
291
|
-
**Key Principle
|
|
403
|
+
**Key Principle:** Constraint violations (code 2001) demonstrate that declarative business logic is working correctly - celebrate these as successes, not failures!
|
|
292
404
|
|
|
293
|
-
See `docs/training/MCP_Copilot_Integration.md` for
|
|
405
|
+
See `docs/training/MCP_Copilot_Integration.md` for authentication workflows, JSON:API formats, and architecture details.
|
|
294
406
|
|
|
295
407
|
### API Interaction Best Practices
|
|
296
408
|
|
|
@@ -381,22 +493,22 @@ python3 -c "import json; data=json.load(open('customers.json')); print(data['dat
|
|
|
381
493
|
|
|
382
494
|
### Automated Testing
|
|
383
495
|
|
|
384
|
-
|
|
496
|
+
**⚠️ BEFORE Creating Tests:**
|
|
385
497
|
|
|
386
498
|
```
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
499
|
+
STOP ✋
|
|
500
|
+
READ docs/training/testing.md FIRST (555 lines - comprehensive guide)
|
|
501
|
+
|
|
502
|
+
This contains EVERY bug pattern from achieving 11/11 test success:
|
|
503
|
+
- Rule #0: Test Repeatability (timestamps for uniqueness)
|
|
504
|
+
- Rule #0.5: Behave Step Ordering (specific before general)
|
|
505
|
+
- Top 5 Critical Bugs (common AI mistakes)
|
|
506
|
+
- Filter format: filter[column]=value (NOT OData)
|
|
507
|
+
- No circular imports (API only)
|
|
508
|
+
- Null-safe constraints
|
|
509
|
+
- Fresh test data (timestamps for uniqueness)
|
|
510
|
+
|
|
511
|
+
THEN create tests following patterns exactly.
|
|
400
512
|
```
|
|
401
513
|
|
|
402
514
|
**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.
|
|
@@ -477,6 +589,49 @@ open reports/Behave\ Logic\ Report.md
|
|
|
477
589
|
- **Logic Log**: Complete trace showing before→after values for all adjustments
|
|
478
590
|
- Demonstrates the 44X code reduction by showing rule automation
|
|
479
591
|
|
|
592
|
+
**LOGIC LOG FORMATTING**:
|
|
593
|
+
|
|
594
|
+
**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:
|
|
595
|
+
- Complete Logic Phase sections (ROW LOGIC, COMMIT LOGIC, AFTER_FLUSH LOGIC, COMPLETE)
|
|
596
|
+
- All rule execution lines with full row details
|
|
597
|
+
- "These Rules Fired" summary section
|
|
598
|
+
- Format as code block for readability
|
|
599
|
+
|
|
600
|
+
When displaying logic logs to users, format them with proper hierarchical indentation like the debug console (see https://apilogicserver.github.io/Docs/Logic-Debug/):
|
|
601
|
+
|
|
602
|
+
```
|
|
603
|
+
Logic Phase: ROW LOGIC (session=0x...)
|
|
604
|
+
..Item[None] {Insert - client} id: None, order_id: 1, product_id: 6, quantity: 10
|
|
605
|
+
..Item[None] {Formula unit_price} unit_price: [None-->] 105.0
|
|
606
|
+
....SysSupplierReq[None] {Insert - Supplier AI Request} product_id: 6
|
|
607
|
+
....SysSupplierReq[None] {Event - calling AI} chosen_unit_price: [None-->] 105.0
|
|
608
|
+
..Item[None] {Formula amount} amount: [None-->] 1050.0
|
|
609
|
+
..Item[None] {adjust parent Order.amount_total}
|
|
610
|
+
....Order[1] {Update - Adjusting order: amount_total} amount_total: [300.0-->] 1350.0
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
**Key formatting rules:**
|
|
614
|
+
- `..` prefix = nesting level (2 dots = parent, 4 dots = child/nested object, 6 dots = deeper nesting)
|
|
615
|
+
- **ONE LINE per rule execution** - no line wrapping
|
|
616
|
+
- Each line shows: `Class[id] {action/reason} key_attributes`
|
|
617
|
+
- Value changes shown as: `[old_value-->] new_value`
|
|
618
|
+
- Hierarchical indentation (dots) shows call depth and parent-child relationships
|
|
619
|
+
- Only show relevant attributes, not all row details
|
|
620
|
+
|
|
621
|
+
**EXTRACTING CLEAN LOGIC LOGS**:
|
|
622
|
+
|
|
623
|
+
To get properly formatted logs (one line per rule, no wrapping), use this command:
|
|
624
|
+
|
|
625
|
+
```bash
|
|
626
|
+
# Extract clean logic log from server.log
|
|
627
|
+
grep -A 100 "Logic Phase:.*ROW LOGIC" server.log | \
|
|
628
|
+
awk -F' row: ' '{print $1}' | \
|
|
629
|
+
grep -E "^\.\.|^Logic Phase:" | \
|
|
630
|
+
head -50
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
This removes verbose session/row details and prevents line wrapping.
|
|
634
|
+
|
|
480
635
|
**DEBUGGING TIPS**:
|
|
481
636
|
|
|
482
637
|
```bash
|
|
@@ -500,7 +655,7 @@ cat logs/scenario_logic_logs/Delete_Item_Reduces_Order.log
|
|
|
500
655
|
|
|
501
656
|
If scenario names don't match between behave.log and .log filenames, logic details won't appear!
|
|
502
657
|
|
|
503
|
-
### Adding MCP
|
|
658
|
+
### Adding MCP UI
|
|
504
659
|
|
|
505
660
|
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:
|
|
506
661
|
|
|
@@ -896,14 +1051,33 @@ class ItemB2BMapper(RowDictMapper):
|
|
|
896
1051
|
|
|
897
1052
|
To add tables / columns to the database (highly impactful - request permission):
|
|
898
1053
|
|
|
899
|
-
1. Update `database/
|
|
900
|
-
2.
|
|
901
|
-
|
|
1054
|
+
1. Update `database/models.py` with new models/columns
|
|
1055
|
+
2. Generate and apply Alembic migration (see database/alembic/readme.md):
|
|
1056
|
+
```bash
|
|
1057
|
+
cd database
|
|
1058
|
+
alembic revision --autogenerate -m "Description of changes"
|
|
1059
|
+
```
|
|
1060
|
+
3. **CRITICAL - Edit the migration file:**
|
|
1061
|
+
- `alembic --autogenerate` detects ALL differences between models.py and database
|
|
1062
|
+
- Open the generated file in `database/alembic/versions/`
|
|
1063
|
+
- **Remove ALL unwanted changes** (ALTER TABLE on existing tables)
|
|
1064
|
+
- **Keep ONLY your intended changes** (e.g., CREATE TABLE for new audit table)
|
|
1065
|
+
- Simplify `downgrade()` function to reverse only your changes
|
|
1066
|
+
4. Apply the edited migration:
|
|
1067
|
+
```bash
|
|
1068
|
+
alembic upgrade head
|
|
1069
|
+
```
|
|
1070
|
+
5. Offer to update ui/admin/admin.yaml to add the new table or column to the Admin UI.
|
|
902
1071
|
|
|
903
|
-
|
|
1072
|
+
**General Migration Notes**:
|
|
1073
|
+
- Stop the server before running migrations to avoid database locking
|
|
1074
|
+
- When adding new models, follow existing patterns in models.py
|
|
1075
|
+
- Models should not contain `__bind_key__`
|
|
1076
|
+
- USER ACTION REQUIRED: Restart server after migrations
|
|
904
1077
|
|
|
905
|
-
|
|
1078
|
+
See: https://apilogicserver.github.io/Docs/Database-Changes/#use-alembic-to-update-database-schema-from-model
|
|
906
1079
|
|
|
1080
|
+
If altering `database/models.py`, be sure to follow the patterns shown in the existing models. Note they do not contain a `__bind_key__`.
|
|
907
1081
|
|
|
908
1082
|
### Addressing `Missing Attributes` during logic loading at project startup
|
|
909
1083
|
|
|
@@ -40,6 +40,34 @@ GitHub Copilot can serve as an interactive MCP client by:
|
|
|
40
40
|
3. **Executing** - Make authenticated HTTP calls
|
|
41
41
|
4. **Reporting** - Present results or explain constraint violations
|
|
42
42
|
|
|
43
|
+
## ⚠️ CRITICAL SAFETY RULES FOR COPILOT
|
|
44
|
+
|
|
45
|
+
**When acting as MCP client, Copilot MUST follow these rules:**
|
|
46
|
+
|
|
47
|
+
### Rule 1: NEVER Update Data Without Explicit Permission
|
|
48
|
+
- ❌ **WRONG**: User asks "update quantity to 100" → fails constraint → Copilot changes credit limit to make it work
|
|
49
|
+
- ✅ **CORRECT**: User asks "update quantity to 100" → fails constraint → Copilot reports the constraint violation and asks what to do
|
|
50
|
+
|
|
51
|
+
### Rule 2: Constraint Violations Are SUCCESS, Not Problems to Bypass
|
|
52
|
+
- When update returns error code 2001, this demonstrates business logic is **working correctly**
|
|
53
|
+
- **DO NOT** try to "fix" constraints by modifying other data
|
|
54
|
+
- **DO** report: "✅ Business logic prevented this operation because [reason]"
|
|
55
|
+
|
|
56
|
+
### Rule 3: Only Perform the Requested Operation
|
|
57
|
+
- If user asks to update Field A, **only update Field A**
|
|
58
|
+
- Do not modify Field B, Field C, or related entities to "help" the operation succeed
|
|
59
|
+
- Let business rules enforce constraints - that's their job!
|
|
60
|
+
|
|
61
|
+
### Rule 4: Ask Permission for Side Effects
|
|
62
|
+
- Before updating any data beyond what user explicitly requested, **ask first**
|
|
63
|
+
- Example: "The credit limit constraint is blocking this. Would you like me to increase the credit limit to allow it?"
|
|
64
|
+
|
|
65
|
+
### Rule 5: Read Operations Are Safe, Write Operations Require Care
|
|
66
|
+
- GET requests are safe to execute
|
|
67
|
+
- PATCH/POST/DELETE require user's explicit instruction for each field being modified
|
|
68
|
+
|
|
69
|
+
**Why These Rules Matter**: When demonstrating to customers, accidentally modifying their data (even to "help") destroys trust and demonstrates poor AI safety practices.
|
|
70
|
+
|
|
43
71
|
## Copilot Usage Pattern
|
|
44
72
|
|
|
45
73
|
### Step 1: Authentication
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Training Documentation Overview
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
This folder contains **generic, reusable training materials** for ApiLogicServer projects with GenAI integration.
|
|
6
|
+
|
|
7
|
+
## Critical Principle
|
|
8
|
+
|
|
9
|
+
**⚠️ ALL FILES IN THIS FOLDER MUST BE PROJECT-AGNOSTIC**
|
|
10
|
+
|
|
11
|
+
- ✅ Generic patterns that apply to ANY ApiLogicServer project
|
|
12
|
+
- ✅ Universal LogicBank API documentation
|
|
13
|
+
- ✅ Framework-level integration patterns
|
|
14
|
+
- ❌ **NEVER include project-specific details** (file names, use cases, workflows)
|
|
15
|
+
- ❌ **NEVER reference project-specific files** (like readme_probabilistic.md)
|
|
16
|
+
|
|
17
|
+
## Intended Use
|
|
18
|
+
|
|
19
|
+
These training files are:
|
|
20
|
+
1. **Read by AI assistants** (GitHub Copilot, ChatGPT) via `.github/.copilot-instructions.md`
|
|
21
|
+
2. **Copied to new projects** when creating similar systems
|
|
22
|
+
3. **Maintained centrally** and propagated across projects
|
|
23
|
+
|
|
24
|
+
## File Organization
|
|
25
|
+
|
|
26
|
+
- **`*.prompt`** - API documentation and pattern libraries for AI consumption
|
|
27
|
+
- **`*_guide.md`** - Human-readable implementation guides
|
|
28
|
+
- **`template_*.py`** - Working code examples (generic patterns only)
|
|
29
|
+
- **`testing.md`** - Universal testing patterns and conventions
|
|
30
|
+
- **`README.md`** - Navigation and file descriptions
|
|
31
|
+
|
|
32
|
+
## Adding New Content
|
|
33
|
+
|
|
34
|
+
When adding training materials:
|
|
35
|
+
|
|
36
|
+
1. **Ask: "Does this apply to ALL projects?"**
|
|
37
|
+
- If YES → Add here
|
|
38
|
+
- If NO → Keep in project root (e.g., `readme_*.md`)
|
|
39
|
+
|
|
40
|
+
2. **Use generic examples:**
|
|
41
|
+
- ✅ "Customer/Order/Item" domain
|
|
42
|
+
- ✅ "SysXxxReq" audit table pattern
|
|
43
|
+
- ❌ Specific product names, table names, or use cases
|
|
44
|
+
|
|
45
|
+
3. **Remove project context:**
|
|
46
|
+
- No mentions of "PDL project"
|
|
47
|
+
- No references to project-specific scripts
|
|
48
|
+
- No project-specific file paths
|
|
49
|
+
|
|
50
|
+
## Maintenance
|
|
51
|
+
|
|
52
|
+
This folder should be **stable and rarely changed**. Updates typically come from:
|
|
53
|
+
- LogicBank API changes
|
|
54
|
+
- New universal patterns discovered
|
|
55
|
+
- Framework architecture improvements
|
|
56
|
+
|
|
57
|
+
**NOT from:**
|
|
58
|
+
- Project-specific implementations
|
|
59
|
+
- One-off use cases
|
|
60
|
+
- Debugging specific projects
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
**Remember:** If you're describing how YOUR project works, it doesn't belong here.
|