- Replaced rigid TIERs with continuous COMPLEXITY 1-5 scale in semantics.md - Updated generate_semantic_map.py to parse and score based on Complexity - Added backward compatibility mapping for legacy TIERs - Migrated all .ai/shots examples to use @COMPLEXITY and updated relation syntax - Added trivial_utility.py shot to demonstrate implicit Complexity 1 token savings
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
# [DEF:TrivialUtilityShot:Module]
|
|
# @COMPLEXITY: 1
|
|
# @PURPOSE: Reference implementation of a zero-overhead utility using implicit Complexity 1.
|
|
|
|
import re
|
|
from datetime import datetime, timezone
|
|
from typing import Optional
|
|
|
|
# [DEF:slugify:Function]
|
|
# @PURPOSE: Converts a string to a URL-safe slug.
|
|
def slugify(text: str) -> str:
|
|
if not text:
|
|
return ""
|
|
text = text.lower().strip()
|
|
text = re.sub(r'[^\w\s-]', '', text)
|
|
return re.sub(r'[-\s]+', '-', text)
|
|
# [/DEF:slugify:Function]
|
|
|
|
# [DEF:get_utc_now:Function]
|
|
def get_utc_now() -> datetime:
|
|
"""Returns current UTC datetime (purpose is omitted because it's obvious)."""
|
|
return datetime.now(timezone.utc)
|
|
# [/DEF:get_utc_now:Function]
|
|
|
|
# [DEF:PaginationDTO:Class]
|
|
class PaginationDTO:
|
|
# [DEF:__init__:Function]
|
|
def __init__(self, page: int = 1, size: int = 50):
|
|
self.page = max(1, page)
|
|
self.size = min(max(1, size), 1000)
|
|
# [/DEF:__init__:Function]
|
|
|
|
# [DEF:offset:Function]
|
|
@property
|
|
def offset(self) -> int:
|
|
return (self.page - 1) * self.size
|
|
# [/DEF:offset:Function]
|
|
# [/DEF:PaginationDTO:Class]
|
|
|
|
# [/DEF:TrivialUtilityShot:Module] |