feat: AI coordination protocol and advanced audit operations
This commit is contained in:
@@ -7,6 +7,12 @@ Any AI or session MUST respect these mandatory rules.
|
|||||||
- **UI & Code Language**: All web interfaces, functions, variables, and any text inside the application MUST BE DIRECTLY AND ONLY IN ENGLISH.
|
- **UI & Code Language**: All web interfaces, functions, variables, and any text inside the application MUST BE DIRECTLY AND ONLY IN ENGLISH.
|
||||||
- **Communication Language**: Conversation with the user will be in Romanian or English, preferably Romanian.
|
- **Communication Language**: Conversation with the user will be in Romanian or English, preferably Romanian.
|
||||||
|
|
||||||
|
## Multi-AI Coordination & Handover
|
||||||
|
- **MANDATORY STARTUP**: Every AI session MUST first read `dev_docs/SESSION_STATE.md` to understand current context.
|
||||||
|
- **MANDATORY HANDOVER**: At the end of every task/session, create or update a handover note in `dev_docs/SESSION_STATE.md`. Specify: **Active AI**, **Current Status**, **Technical Context** (details not in code), and **Next Steps**.
|
||||||
|
- **ARCHIVAL RULE**: To prevent `SESSION_STATE.md` from bloating, incoming AI agents MUST move all content of the *previous* session handover into the top of `dev_docs/SESSION_HISTORY.md` before writing their own new state. This keeps `SESSION_STATE.md` focused only on the *active* session.
|
||||||
|
- **NO INTERACTION OVERLAP**: Never modify a file if another AI session is explicitly working on it according to `SESSION_STATE.md`.
|
||||||
|
|
||||||
## Implementation Completion
|
## Implementation Completion
|
||||||
- All code modifications MUST be committed in git before the task is considered finished. `VERSION.json` must be updated on EACH commit.
|
- All code modifications MUST be committed in git before the task is considered finished. `VERSION.json` must be updated on EACH commit.
|
||||||
- **MANDATORY GIT RULE:** Never push to remote unless explicitly requested by the user. Only commit locally with proper messages. Always assume the user will handle all `git push` operations. If a task requires pushing, ask for explicit permission first.
|
- **MANDATORY GIT RULE:** Never push to remote unless explicitly requested by the user. Only commit locally with proper messages. Always assume the user will handle all `git push` operations. If a task requires pushing, ask for explicit permission first.
|
||||||
|
|||||||
@@ -60,3 +60,65 @@ def check_out_item(op: schemas.OperationCreate, db: Session = Depends(get_db)):
|
|||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(item)
|
db.refresh(item)
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
@router.post("/trash", response_model=schemas.Item)
|
||||||
|
def trash_item(op: schemas.TrashOperationCreate, db: Session = Depends(get_db)):
|
||||||
|
if op.quantity <= 0:
|
||||||
|
raise HTTPException(status_code=400, detail="Quantity must be greater than zero")
|
||||||
|
|
||||||
|
item = db.query(models.Item).filter(models.Item.barcode == op.barcode).first()
|
||||||
|
if not item:
|
||||||
|
raise HTTPException(status_code=404, detail="Item not found")
|
||||||
|
|
||||||
|
if item.quantity < op.quantity:
|
||||||
|
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Insufficient stock to trash")
|
||||||
|
|
||||||
|
# Update quantity
|
||||||
|
item.quantity -= op.quantity
|
||||||
|
|
||||||
|
# Create Mandatory Audit Log with TRASH action and reason
|
||||||
|
audit = models.AuditLog(
|
||||||
|
user_id=op.user_id,
|
||||||
|
action=f"TRASH: {op.reason}",
|
||||||
|
target_item_id=item.id,
|
||||||
|
quantity_change=-op.quantity
|
||||||
|
)
|
||||||
|
|
||||||
|
db.add(audit)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(item)
|
||||||
|
return item
|
||||||
|
|
||||||
|
@router.post("/bulk-check-out")
|
||||||
|
def bulk_check_out(bulk_op: schemas.BulkOperationCreate, db: Session = Depends(get_db)):
|
||||||
|
results = {"success": [], "errors": []}
|
||||||
|
|
||||||
|
for op in bulk_op.items:
|
||||||
|
try:
|
||||||
|
item = db.query(models.Item).filter(models.Item.barcode == op.barcode).first()
|
||||||
|
if not item:
|
||||||
|
results["errors"].append({"barcode": op.barcode, "error": "Not found"})
|
||||||
|
continue
|
||||||
|
|
||||||
|
if item.quantity < op.quantity:
|
||||||
|
results["errors"].append({"barcode": op.barcode, "error": f"Insufficient stock (Available: {item.quantity})"})
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Update quantity
|
||||||
|
item.quantity -= op.quantity
|
||||||
|
|
||||||
|
# Log individual audit for this item
|
||||||
|
audit = models.AuditLog(
|
||||||
|
user_id=bulk_op.user_id,
|
||||||
|
action="BULK_CHECK_OUT",
|
||||||
|
target_item_id=item.id,
|
||||||
|
quantity_change=-op.quantity
|
||||||
|
)
|
||||||
|
db.add(audit)
|
||||||
|
results["success"].append({"barcode": op.barcode, "new_quantity": item.quantity})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
results["errors"].append({"barcode": op.barcode, "error": str(e)})
|
||||||
|
|
||||||
|
db.commit()
|
||||||
|
return results
|
||||||
|
|||||||
@@ -27,6 +27,16 @@ class OperationCreate(BaseModel):
|
|||||||
quantity: float
|
quantity: float
|
||||||
user_id: int
|
user_id: int
|
||||||
|
|
||||||
|
class BulkOperationCreate(BaseModel):
|
||||||
|
user_id: int
|
||||||
|
items: List[OperationCreate]
|
||||||
|
|
||||||
|
class TrashOperationCreate(BaseModel):
|
||||||
|
barcode: str
|
||||||
|
quantity: float
|
||||||
|
user_id: int
|
||||||
|
reason: Optional[str] = "unspecified"
|
||||||
|
|
||||||
# --- Audit Logs ---
|
# --- Audit Logs ---
|
||||||
class AuditLogResponse(BaseModel):
|
class AuditLogResponse(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
|
|||||||
@@ -29,3 +29,14 @@ Each entry MUST be formatted chronologically.
|
|||||||
- `backend/routers/items.py` (NEW)
|
- `backend/routers/items.py` (NEW)
|
||||||
- `backend/routers/operations.py` (NEW)
|
- `backend/routers/operations.py` (NEW)
|
||||||
- `backend/main.py` (UPDATED)
|
- `backend/main.py` (UPDATED)
|
||||||
|
|
||||||
|
### [2026-04-10 13:58] AI Coordination & Bulk Operations (Phase 3)
|
||||||
|
**Purpose:** Established Multi-AI handover protocol with archival logic. Extended backend to support bulk check-outs and trash operations with mandatory audit logging.
|
||||||
|
**Modified Files:**
|
||||||
|
- `dev_docs/SESSION_STATE.md` (NEW)
|
||||||
|
- `dev_docs/SESSION_HISTORY.md` (NEW)
|
||||||
|
- `AI_RULES.md` (UPDATED)
|
||||||
|
- `backend/schemas.py` (UPDATED)
|
||||||
|
- `backend/routers/operations.py` (UPDATED)
|
||||||
|
|
||||||
|
**Test Results:** Scheme support bulk and trash objects. Logging logic verified in code for session state compliance.
|
||||||
|
|||||||
6
dev_docs/SESSION_HISTORY.md
Normal file
6
dev_docs/SESSION_HISTORY.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# AI Session History
|
||||||
|
|
||||||
|
Archive of previous AI handover notes from `SESSION_STATE.md`.
|
||||||
|
Entries are added here when a new AI session starts.
|
||||||
|
|
||||||
|
---
|
||||||
17
dev_docs/SESSION_STATE.md
Normal file
17
dev_docs/SESSION_STATE.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# AI Session State
|
||||||
|
|
||||||
|
**Status**: Active - Implementation of AI Coordination and Advanced Operations.
|
||||||
|
**Current AI Agent**: Gemini (Antigravity)
|
||||||
|
**Context**:
|
||||||
|
- Backend is initialized with FastAPI and SQLite.
|
||||||
|
- Core Item and Operation routers are registered.
|
||||||
|
- `AI_RULES.md` is initialized.
|
||||||
|
|
||||||
|
**Specific Implementation Logic**:
|
||||||
|
- Audit logging is central to all operations.
|
||||||
|
- Using `html5-qrcode` for the PWA later.
|
||||||
|
- Avoid native mobile apps, use PWA with service workers.
|
||||||
|
|
||||||
|
**Handovers**:
|
||||||
|
- Starting work on `trash` and `bulk-check-out` endpoints.
|
||||||
|
- Coordination files being established.
|
||||||
Reference in New Issue
Block a user