Skip to content

tenets.core.prompt Package

Prompt parsing and understanding system.

This package provides intelligent prompt analysis to extract intent, keywords, entities, temporal context, and external references from user queries. The parser supports various input formats including plain text, URLs (GitHub issues, JIRA tickets, Linear, Notion, etc.), and structured queries.

Core Features: - Intent detection (implement, debug, test, refactor, etc.) - Keyword extraction using multiple algorithms (YAKE, TF-IDF, frequency) - Entity recognition (classes, functions, files, APIs, databases) - Temporal parsing (dates, ranges, recurring patterns) - External source integration (GitHub, GitLab, JIRA, Linear, Asana, Notion) - Intelligent caching with TTL management - Programming pattern recognition - Scope and focus area detection

The parser leverages centralized NLP components for: - Keyword extraction via nlp.keyword_extractor - Tokenization via nlp.tokenizer - Stopword filtering via nlp.stopwords - Programming patterns via nlp.programming_patterns

Example

from tenets.core.prompt import PromptParser from tenets.config import TenetsConfig

Create parser with config

config = TenetsConfig() parser = PromptParser(config)

Parse a prompt

context = parser.parse("implement OAuth2 authentication for the API") print(f"Intent: {context.intent}") print(f"Keywords: {context.keywords}") print(f"Task type: {context.task_type}")

Parse from GitHub issue

context = parser.parse("https://github.com/org/repo/issues/123") print(f"External source: {context.external_context['source']}") print(f"Issue title: {context.text}")

Classes

AsanaHandler

Python
AsanaHandler(cache_manager: Optional[CacheManager] = None)

Bases: ExternalSourceHandler

Handler for Asana tasks.

Functions

can_handle
Python
can_handle(url: str) -> bool

Check if URL is an Asana URL.

extract_identifier
Python
extract_identifier(url: str) -> Tuple[str, Dict[str, Any]]

Extract Asana task identifier from URL.

fetch_content
Python
fetch_content(url: str, metadata: Dict[str, Any]) -> Optional[ExternalContent]

Fetch content from Asana API.

ExternalContentdataclass

Python
ExternalContent(title: str, body: str, metadata: Dict[str, Any], source_type: str, url: str, cached_at: Optional[datetime] = None, ttl_hours: int = 24)

Parsed content from an external source.

Attributes

titleinstance-attribute
Python
title: str
bodyinstance-attribute
Python
body: str
metadatainstance-attribute
Python
metadata: Dict[str, Any]
source_typeinstance-attribute
Python
source_type: str
urlinstance-attribute
Python
url: str
cached_atclass-attributeinstance-attribute
Python
cached_at: Optional[datetime] = None
ttl_hoursclass-attributeinstance-attribute
Python
ttl_hours: int = 24

ExternalSourceHandler

Python
ExternalSourceHandler(cache_manager: Optional[CacheManager] = None)

Bases: ABC

Base class for external source handlers.

Initialize handler with optional cache.

PARAMETERDESCRIPTION
cache_manager

Optional cache manager for caching fetched content

TYPE:Optional[CacheManager]DEFAULT:None

Attributes

loggerinstance-attribute
Python
logger = get_logger(__name__)
cacheinstance-attribute
Python
cache = cache_manager

Functions

can_handleabstractmethod
Python
can_handle(url: str) -> bool

Check if this handler can process the given URL.

extract_identifierabstractmethod
Python
extract_identifier(url: str) -> Tuple[str, Dict[str, Any]]

Extract identifier and metadata from URL.

RETURNSDESCRIPTION
Tuple[str, Dict[str, Any]]

Tuple of (identifier, metadata)

fetch_contentabstractmethod
Python
fetch_content(url: str, metadata: Dict[str, Any]) -> Optional[ExternalContent]

Fetch content from the external source.

get_cached_content
Python
get_cached_content(url: str) -> Optional[ExternalContent]

Get cached content if available and valid.

PARAMETERDESCRIPTION
url

URL to check cache for

TYPE:str

RETURNSDESCRIPTION
Optional[ExternalContent]

Cached content or None if not cached/expired

cache_content
Python
cache_content(url: str, content: ExternalContent) -> None

Cache fetched content.

PARAMETERDESCRIPTION
url

URL as cache key

TYPE:str

content

Content to cache

TYPE:ExternalContent

process
Python
process(url: str) -> Optional[ExternalContent]

Process URL with caching support.

PARAMETERDESCRIPTION
url

URL to process

TYPE:str

RETURNSDESCRIPTION
Optional[ExternalContent]

External content or None if failed

ExternalSourceManager

Python
ExternalSourceManager(cache_manager: Optional[CacheManager] = None)

Manages all external source handlers.

Initialize with all available handlers.

PARAMETERDESCRIPTION
cache_manager

Optional cache manager for handlers

TYPE:Optional[CacheManager]DEFAULT:None

Attributes

loggerinstance-attribute
Python
logger = get_logger(__name__)
cache_managerinstance-attribute
Python
cache_manager = cache_manager
handlersinstance-attribute
Python
handlers = [GitHubHandler(cache_manager), GitLabHandler(cache_manager), JiraHandler(cache_manager), LinearHandler(cache_manager), AsanaHandler(cache_manager), NotionHandler(cache_manager)]

Functions

process_url
Python
process_url(url: str) -> Optional[ExternalContent]

Process a URL with the appropriate handler.

PARAMETERDESCRIPTION
url

URL to process

TYPE:str

RETURNSDESCRIPTION
Optional[ExternalContent]

External content or None if no handler can process it

extract_reference
Python
extract_reference(text: str) -> Optional[Tuple[str, str, Dict[str, Any]]]

Extract external reference from text.

PARAMETERDESCRIPTION
text

Text that may contain a URL

TYPE:str

RETURNSDESCRIPTION
Optional[Tuple[str, str, Dict[str, Any]]]

Tuple of (url, identifier, metadata) or None

GitHubHandler

Python
GitHubHandler(cache_manager: Optional[CacheManager] = None)

Bases: ExternalSourceHandler

Handler for GitHub issues, PRs, discussions, and gists.

Functions

can_handle
Python
can_handle(url: str) -> bool

Check if URL is a GitHub URL.

extract_identifier
Python
extract_identifier(url: str) -> Tuple[str, Dict[str, Any]]

Extract GitHub identifier from URL.

fetch_content
Python
fetch_content(url: str, metadata: Dict[str, Any]) -> Optional[ExternalContent]

Fetch content from GitHub API.

GitLabHandler

Python
GitLabHandler(cache_manager: Optional[CacheManager] = None)

Bases: ExternalSourceHandler

Handler for GitLab issues, MRs, and snippets.

Functions

can_handle
Python
can_handle(url: str) -> bool

Check if URL is a GitLab URL.

extract_identifier
Python
extract_identifier(url: str) -> Tuple[str, Dict[str, Any]]

Extract GitLab identifier from URL.

fetch_content
Python
fetch_content(url: str, metadata: Dict[str, Any]) -> Optional[ExternalContent]

Fetch content from GitLab API.

JiraHandler

Python
JiraHandler(cache_manager: Optional[CacheManager] = None)

Bases: ExternalSourceHandler

Handler for JIRA tickets.

Functions

can_handle
Python
can_handle(url: str) -> bool

Check if URL is a JIRA URL.

extract_identifier
Python
extract_identifier(url: str) -> Tuple[str, Dict[str, Any]]

Extract JIRA ticket identifier from URL.

fetch_content
Python
fetch_content(url: str, metadata: Dict[str, Any]) -> Optional[ExternalContent]

Fetch content from JIRA API.

LinearHandler

Python
LinearHandler(cache_manager: Optional[CacheManager] = None)

Bases: ExternalSourceHandler

Handler for Linear issues.

Functions

can_handle
Python
can_handle(url: str) -> bool

Check if URL is a Linear URL.

extract_identifier
Python
extract_identifier(url: str) -> Tuple[str, Dict[str, Any]]

Extract Linear identifier from URL.

fetch_content
Python
fetch_content(url: str, metadata: Dict[str, Any]) -> Optional[ExternalContent]

Fetch content from Linear API using GraphQL.

NotionHandler

Python
NotionHandler(cache_manager: Optional[CacheManager] = None)

Bases: ExternalSourceHandler

Handler for Notion pages and databases.

Functions

can_handle
Python
can_handle(url: str) -> bool

Check if URL is a Notion URL.

extract_identifier
Python
extract_identifier(url: str) -> Tuple[str, Dict[str, Any]]

Extract Notion page/database identifier from URL.

fetch_content
Python
fetch_content(url: str, metadata: Dict[str, Any]) -> Optional[ExternalContent]

Fetch content from Notion API.

CacheEntrydataclass

Python
CacheEntry(key: str, value: Any, created_at: datetime, accessed_at: datetime, ttl_seconds: int, hit_count: int = 0, metadata: Dict[str, Any] = None)

A cache entry with metadata.

Attributes

keyinstance-attribute
Python
key: str
valueinstance-attribute
Python
value: Any
created_atinstance-attribute
Python
created_at: datetime
accessed_atinstance-attribute
Python
accessed_at: datetime
ttl_secondsinstance-attribute
Python
ttl_seconds: int
hit_countclass-attributeinstance-attribute
Python
hit_count: int = 0
metadataclass-attributeinstance-attribute
Python
metadata: Dict[str, Any] = None

Functions

is_expired
Python
is_expired() -> bool

Check if this entry has expired.

touch
Python
touch()

Update access time and increment hit count.

PromptCache

Python
PromptCache(cache_manager: Optional[Any] = None, enable_memory_cache: bool = True, enable_disk_cache: bool = True, memory_cache_size: int = 100)

Intelligent caching for prompt parsing operations.

Initialize prompt cache.

PARAMETERDESCRIPTION
cache_manager

External cache manager to use

TYPE:Optional[Any]DEFAULT:None

enable_memory_cache

Whether to use in-memory caching

TYPE:boolDEFAULT:True

enable_disk_cache

Whether to use disk caching

TYPE:boolDEFAULT:True

memory_cache_size

Maximum items in memory cache

TYPE:intDEFAULT:100

Attributes

DEFAULT_TTLSclass-attributeinstance-attribute
Python
DEFAULT_TTLS = {'parsed_prompt': 3600, 'external_content': 21600, 'entity_recognition': 1800, 'intent_detection': 1800, 'temporal_parsing': 3600}
TTL_MODIFIERSclass-attributeinstance-attribute
Python
TTL_MODIFIERS = {'github_open': 0.25, 'github_closed': 4.0, 'jira_active': 0.5, 'notion_page': 2.0, 'high_confidence': 1.5, 'low_confidence': 0.5}
loggerinstance-attribute
Python
logger = get_logger(__name__)
cache_managerinstance-attribute
Python
cache_manager = cache_manager if cache_manager and CacheManager else None
enable_memoryinstance-attribute
Python
enable_memory = enable_memory_cache
enable_diskinstance-attribute
Python
enable_disk = enable_disk_cache and cache_manager is not None
memory_cacheinstance-attribute
Python
memory_cache: Dict[str, CacheEntry] = {}
memory_cache_sizeinstance-attribute
Python
memory_cache_size = memory_cache_size
statsinstance-attribute
Python
stats = {'hits': 0, 'misses': 0, 'evictions': 0, 'expirations': 0}

Functions

get
Python
get(key: str, check_disk: bool = True) -> Optional[Any]

Get a value from cache.

PARAMETERDESCRIPTION
key

Cache key

TYPE:str

check_disk

Whether to check disk cache if not in memory

TYPE:boolDEFAULT:True

RETURNSDESCRIPTION
Optional[Any]

Cached value or None if not found/expired

put
Python
put(key: str, value: Any, ttl_seconds: Optional[int] = None, metadata: Optional[Dict[str, Any]] = None, write_disk: bool = True) -> None

Put a value in cache.

PARAMETERDESCRIPTION
key

Cache key

TYPE:str

value

Value to cache

TYPE:Any

ttl_seconds

TTL in seconds (uses default if not specified)

TYPE:Optional[int]DEFAULT:None

metadata

Additional metadata for TTL calculation

TYPE:Optional[Dict[str, Any]]DEFAULT:None

write_disk

Whether to write to disk cache

TYPE:boolDEFAULT:True

cache_parsed_prompt
Python
cache_parsed_prompt(prompt: str, result: Any, metadata: Optional[Dict[str, Any]] = None) -> None

Cache a parsed prompt result.

PARAMETERDESCRIPTION
prompt

Original prompt text

TYPE:str

result

Parsing result

TYPE:Any

metadata

Additional metadata

TYPE:Optional[Dict[str, Any]]DEFAULT:None

get_parsed_prompt
Python
get_parsed_prompt(prompt: str) -> Optional[Any]

Get cached parsed prompt result.

PARAMETERDESCRIPTION
prompt

Original prompt text

TYPE:str

RETURNSDESCRIPTION
Optional[Any]

Cached result or None

cache_external_content
Python
cache_external_content(url: str, content: Any, metadata: Optional[Dict[str, Any]] = None) -> None

Cache external content fetch result.

PARAMETERDESCRIPTION
url

URL that was fetched

TYPE:str

content

Fetched content

TYPE:Any

metadata

Additional metadata (source, state, etc.)

TYPE:Optional[Dict[str, Any]]DEFAULT:None

get_external_content
Python
get_external_content(url: str) -> Optional[Any]

Get cached external content.

PARAMETERDESCRIPTION
url

URL to check

TYPE:str

RETURNSDESCRIPTION
Optional[Any]

Cached content or None

cache_entities
Python
cache_entities(text: str, entities: List[Any], confidence: float = 0.0) -> None

Cache entity recognition results.

PARAMETERDESCRIPTION
text

Text that was analyzed

TYPE:str

entities

Recognized entities

TYPE:List[Any]

confidence

Average confidence score

TYPE:floatDEFAULT:0.0

get_entities
Python
get_entities(text: str) -> Optional[List[Any]]

Get cached entity recognition results.

PARAMETERDESCRIPTION
text

Text to check

TYPE:str

RETURNSDESCRIPTION
Optional[List[Any]]

Cached entities or None

cache_intent
Python
cache_intent(text: str, intent: Any, confidence: float = 0.0) -> None

Cache intent detection result.

PARAMETERDESCRIPTION
text

Text that was analyzed

TYPE:str

intent

Detected intent

TYPE:Any

confidence

Confidence score

TYPE:floatDEFAULT:0.0

get_intent
Python
get_intent(text: str) -> Optional[Any]

Get cached intent detection result.

PARAMETERDESCRIPTION
text

Text to check

TYPE:str

RETURNSDESCRIPTION
Optional[Any]

Cached intent or None

invalidate
Python
invalidate(pattern: str) -> int

Invalidate cache entries matching a pattern.

PARAMETERDESCRIPTION
pattern

Key pattern to match (prefix)

TYPE:str

RETURNSDESCRIPTION
int

Number of entries invalidated

clear_all
Python
clear_all() -> None

Clear all cache entries.

cleanup_expired
Python
cleanup_expired() -> int

Remove expired entries from cache.

RETURNSDESCRIPTION
int

Number of entries removed

get_stats
Python
get_stats() -> Dict[str, Any]

Get cache statistics.

RETURNSDESCRIPTION
Dict[str, Any]

Cache statistics dictionary

warm_cache
Python
warm_cache(common_prompts: List[str]) -> None

Pre-warm cache with common prompts.

PARAMETERDESCRIPTION
common_prompts

List of common prompts to pre-cache

TYPE:List[str]

Entitydataclass

Python
Entity(name: str, type: str, confidence: float, context: str = '', start_pos: int = -1, end_pos: int = -1, source: str = 'regex', metadata: Dict[str, Any] = dict())

Recognized entity with confidence and context.

Attributes

nameinstance-attribute
Python
name: str
typeinstance-attribute
Python
type: str
confidenceinstance-attribute
Python
confidence: float
contextclass-attributeinstance-attribute
Python
context: str = ''
start_posclass-attributeinstance-attribute
Python
start_pos: int = -1
end_posclass-attributeinstance-attribute
Python
end_pos: int = -1
sourceclass-attributeinstance-attribute
Python
source: str = 'regex'
metadataclass-attributeinstance-attribute
Python
metadata: Dict[str, Any] = field(default_factory=dict)

EntityPatternMatcher

Python
EntityPatternMatcher(patterns_file: Optional[Path] = None)

Regex-based entity pattern matching.

Initialize with entity patterns.

PARAMETERDESCRIPTION
patterns_file

Path to entity patterns JSON file

TYPE:Optional[Path]DEFAULT:None

Attributes

loggerinstance-attribute
Python
logger = get_logger(__name__)
patternsinstance-attribute
Python
patterns = _load_patterns(patterns_file)
compiled_patternsinstance-attribute
Python
compiled_patterns = _compile_patterns()

Functions

extract
Python
extract(text: str) -> List[Entity]

Extract entities using regex patterns.

PARAMETERDESCRIPTION
text

Text to extract entities from

TYPE:str

RETURNSDESCRIPTION
List[Entity]

List of extracted entities

FuzzyEntityMatcher

Python
FuzzyEntityMatcher(known_entities: Optional[Dict[str, List[str]]] = None)

Fuzzy matching for entity recognition.

Initialize fuzzy matcher.

PARAMETERDESCRIPTION
known_entities

Dictionary of entity type -> list of known entity names

TYPE:Optional[Dict[str, List[str]]]DEFAULT:None

Attributes

loggerinstance-attribute
Python
logger = get_logger(__name__)
known_entitiesinstance-attribute
Python
known_entities = known_entities or _get_default_known_entities()

Functions

find_fuzzy_matches
Python
find_fuzzy_matches(text: str, threshold: float = 0.8) -> List[Entity]

Find fuzzy matches for known entities.

PARAMETERDESCRIPTION
text

Text to search in

TYPE:str

threshold

Similarity threshold (0-1)

TYPE:floatDEFAULT:0.8

RETURNSDESCRIPTION
List[Entity]

List of matched entities

HybridEntityRecognizer

Python
HybridEntityRecognizer(use_nlp: bool = True, use_fuzzy: bool = True, patterns_file: Optional[Path] = None, spacy_model: str = 'en_core_web_sm', known_entities: Optional[Dict[str, List[str]]] = None)

Main entity recognizer combining all approaches.

Initialize hybrid entity recognizer.

PARAMETERDESCRIPTION
use_nlp

Whether to use NLP-based NER

TYPE:boolDEFAULT:True

use_fuzzy

Whether to use fuzzy matching

TYPE:boolDEFAULT:True

patterns_file

Path to entity patterns JSON

TYPE:Optional[Path]DEFAULT:None

spacy_model

spaCy model name

TYPE:strDEFAULT:'en_core_web_sm'

known_entities

Known entities for fuzzy matching

TYPE:Optional[Dict[str, List[str]]]DEFAULT:None

Attributes

loggerinstance-attribute
Python
logger = get_logger(__name__)
pattern_matcherinstance-attribute
Python
pattern_matcher = EntityPatternMatcher(patterns_file)
nlp_recognizerinstance-attribute
Python
nlp_recognizer = None
fuzzy_matcherinstance-attribute
Python
fuzzy_matcher = None
keyword_extractorinstance-attribute
Python
keyword_extractor = KeywordExtractor(use_stopwords=True, stopword_set='prompt')

Functions

recognize
Python
recognize(text: str, merge_overlapping: bool = True, min_confidence: float = 0.5) -> List[Entity]

Recognize entities using all available methods.

PARAMETERDESCRIPTION
text

Text to extract entities from

TYPE:str

merge_overlapping

Whether to merge overlapping entities

TYPE:boolDEFAULT:True

min_confidence

Minimum confidence threshold

TYPE:floatDEFAULT:0.5

RETURNSDESCRIPTION
List[Entity]

List of recognized entities

get_entity_summary
Python
get_entity_summary(entities: List[Entity]) -> Dict[str, Any]

Get summary statistics about recognized entities.

PARAMETERDESCRIPTION
entities

List of entities

TYPE:List[Entity]

RETURNSDESCRIPTION
Dict[str, Any]

Summary dictionary

NLPEntityRecognizer

Python
NLPEntityRecognizer(model_name: str = 'en_core_web_sm')

NLP-based named entity recognition using spaCy.

Initialize NLP entity recognizer.

PARAMETERDESCRIPTION
model_name

spaCy model to use

TYPE:strDEFAULT:'en_core_web_sm'

Attributes

loggerinstance-attribute
Python
logger = get_logger(__name__)
nlpinstance-attribute
Python
nlp = load(model_name)

Functions

extract
Python
extract(text: str) -> List[Entity]

Extract entities using NLP.

PARAMETERDESCRIPTION
text

Text to extract entities from

TYPE:str

RETURNSDESCRIPTION
List[Entity]

List of extracted entities

HybridIntentDetector

Python
HybridIntentDetector(use_ml: bool = True, patterns_file: Optional[Path] = None, model_name: str = 'all-MiniLM-L6-v2')

Main intent detector combining pattern and ML approaches.

Initialize hybrid intent detector.

PARAMETERDESCRIPTION
use_ml

Whether to use ML-based detection

TYPE:boolDEFAULT:True

patterns_file

Path to intent patterns JSON

TYPE:Optional[Path]DEFAULT:None

model_name

Embedding model name for ML

TYPE:strDEFAULT:'all-MiniLM-L6-v2'

Attributes

loggerinstance-attribute
Python
logger = get_logger(__name__)
pattern_detectorinstance-attribute
Python
pattern_detector = PatternBasedDetector(patterns_file)
semantic_detectorinstance-attribute
Python
semantic_detector = None
keyword_extractorinstance-attribute
Python
keyword_extractor = KeywordExtractor(use_stopwords=True, stopword_set='prompt')

Functions

detect
Python
detect(text: str, combine_method: str = 'weighted', pattern_weight: float = 0.75, ml_weight: float = 0.25, min_confidence: float = 0.3) -> Intent

Detect the primary intent from text.

PARAMETERDESCRIPTION
text

Text to analyze

TYPE:str

combine_method

How to combine results ('weighted', 'max', 'vote')

TYPE:strDEFAULT:'weighted'

pattern_weight

Weight for pattern-based detection

TYPE:floatDEFAULT:0.75

ml_weight

Weight for ML-based detection

TYPE:floatDEFAULT:0.25

min_confidence

Minimum confidence threshold

TYPE:floatDEFAULT:0.3

RETURNSDESCRIPTION
Intent

Primary intent detected

detect_multiple
Python
detect_multiple(text: str, max_intents: int = 3, min_confidence: float = 0.3) -> List[Intent]

Detect multiple intents from text.

PARAMETERDESCRIPTION
text

Text to analyze

TYPE:str

max_intents

Maximum number of intents to return

TYPE:intDEFAULT:3

min_confidence

Minimum confidence threshold

TYPE:floatDEFAULT:0.3

RETURNSDESCRIPTION
List[Intent]

List of detected intents

get_intent_context
Python
get_intent_context(intent: Intent) -> Dict[str, Any]

Get additional context for an intent.

PARAMETERDESCRIPTION
intent

Intent to get context for

TYPE:Intent

RETURNSDESCRIPTION
Dict[str, Any]

Context dictionary

Intentdataclass

Python
Intent(type: str, confidence: float, evidence: List[str], keywords: List[str], metadata: Dict[str, Any], source: str)

Detected intent with confidence and metadata.

Attributes

typeinstance-attribute
Python
type: str
confidenceinstance-attribute
Python
confidence: float
evidenceinstance-attribute
Python
evidence: List[str]
keywordsinstance-attribute
Python
keywords: List[str]
metadatainstance-attribute
Python
metadata: Dict[str, Any]
sourceinstance-attribute
Python
source: str

Functions

to_dict
Python
to_dict() -> Dict[str, Any]

Convert to dictionary.

PatternBasedDetector

Python
PatternBasedDetector(patterns_file: Optional[Path] = None)

Pattern-based intent detection.

Initialize with intent patterns.

PARAMETERDESCRIPTION
patterns_file

Path to intent patterns JSON file

TYPE:Optional[Path]DEFAULT:None

Attributes

loggerinstance-attribute
Python
logger = get_logger(__name__)
patternsinstance-attribute
Python
patterns = _load_patterns(patterns_file)
compiled_patternsinstance-attribute
Python
compiled_patterns = _compile_patterns()

Functions

detect
Python
detect(text: str) -> List[Intent]

Detect intents using patterns.

PARAMETERDESCRIPTION
text

Text to analyze

TYPE:str

RETURNSDESCRIPTION
List[Intent]

List of detected intents

SemanticIntentDetector

Python
SemanticIntentDetector(model_name: str = 'all-MiniLM-L6-v2')

ML-based semantic intent detection using embeddings.

Initialize semantic intent detector.

PARAMETERDESCRIPTION
model_name

Embedding model name

TYPE:strDEFAULT:'all-MiniLM-L6-v2'

Attributes

loggerinstance-attribute
Python
logger = get_logger(__name__)
modelinstance-attribute
Python
model = create_embedding_model(model_name=model_name)
similarity_calculatorinstance-attribute
Python
similarity_calculator = SemanticSimilarity(model)
intent_examplesinstance-attribute
Python
intent_examples = _get_intent_examples()

Functions

detect
Python
detect(text: str, threshold: float = 0.6) -> List[Intent]

Detect intents using semantic similarity.

PARAMETERDESCRIPTION
text

Text to analyze

TYPE:str

threshold

Similarity threshold

TYPE:floatDEFAULT:0.6

RETURNSDESCRIPTION
List[Intent]

List of detected intents

PromptParser

Python
PromptParser(config: TenetsConfig, cache_manager: Optional[Any] = None, use_cache: bool = True, use_ml: bool = None, use_nlp_ner: bool = None, use_fuzzy_matching: bool = True)

Comprehensive prompt parser with modular components and caching.

Attributes

configinstance-attribute
Python
config = config
loggerinstance-attribute
Python
logger = get_logger(__name__)
cacheinstance-attribute
Python
cache = None

Functions

parse
Python
parse(prompt: str, use_cache: bool = True, fetch_external: bool = True, min_entity_confidence: float = 0.5, min_intent_confidence: float = 0.3) -> PromptContext
get_cache_stats
Python
get_cache_stats() -> Optional[Dict[str, Any]]

Get cache statistics.

RETURNSDESCRIPTION
Optional[Dict[str, Any]]

Dictionary with cache statistics or None if cache is disabled

Example

stats = parser.get_cache_stats() if stats: ... print(f"Cache hit rate: {stats['hit_rate']:.2%}")

clear_cache
Python
clear_cache() -> None

Clear all cached data.

This removes all cached parsing results, external content, entities, and intents from both memory and disk cache.

Example

parser.clear_cache() print("Cache cleared")

warm_cache
Python
warm_cache(common_prompts: List[str]) -> None

Pre-warm cache with common prompts.

This method pre-parses a list of common prompts to populate the cache, improving performance for frequently used queries.

PARAMETERDESCRIPTION
common_prompts

List of common prompts to pre-parse

TYPE:List[str]

Example

common = [ ... "implement authentication", ... "fix bug", ... "understand architecture" ... ] parser.warm_cache(common)

TemporalExpressiondataclass

Python
TemporalExpression(text: str, type: str, start_date: Optional[datetime], end_date: Optional[datetime], is_relative: bool, is_recurring: bool, recurrence_pattern: Optional[str], confidence: float, metadata: Dict[str, Any])

Parsed temporal expression with metadata.

Attributes

textinstance-attribute
Python
text: str
typeinstance-attribute
Python
type: str
start_dateinstance-attribute
Python
start_date: Optional[datetime]
end_dateinstance-attribute
Python
end_date: Optional[datetime]
is_relativeinstance-attribute
Python
is_relative: bool
is_recurringinstance-attribute
Python
is_recurring: bool
recurrence_patterninstance-attribute
Python
recurrence_pattern: Optional[str]
confidenceinstance-attribute
Python
confidence: float
metadatainstance-attribute
Python
metadata: Dict[str, Any]
timeframeproperty
Python
timeframe: str

Get human-readable timeframe description.

TemporalParser

Python
TemporalParser(patterns_file: Optional[Path] = None)

Main temporal parser combining all approaches.

Initialize temporal parser.

PARAMETERDESCRIPTION
patterns_file

Path to temporal patterns JSON file

TYPE:Optional[Path]DEFAULT:None

Attributes

loggerinstance-attribute
Python
logger = get_logger(__name__)
pattern_matcherinstance-attribute
Python
pattern_matcher = TemporalPatternMatcher(patterns_file)

Functions

parse
Python
parse(text: str) -> List[TemporalExpression]

Parse temporal expressions from text.

PARAMETERDESCRIPTION
text

Text to parse

TYPE:str

RETURNSDESCRIPTION
List[TemporalExpression]

List of temporal expressions

get_temporal_context
Python
get_temporal_context(expressions: List[TemporalExpression]) -> Dict[str, Any]

Get overall temporal context from expressions.

PARAMETERDESCRIPTION
expressions

List of temporal expressions

TYPE:List[TemporalExpression]

RETURNSDESCRIPTION
Dict[str, Any]

Temporal context summary

extract_temporal_features
Python
extract_temporal_features(text: str) -> Dict[str, Any]

Extract all temporal features from text.

PARAMETERDESCRIPTION
text

Text to analyze

TYPE:str

RETURNSDESCRIPTION
Dict[str, Any]

Dictionary with temporal features and context

TemporalPatternMatcher

Python
TemporalPatternMatcher(patterns_file: Optional[Path] = None)

Pattern-based temporal expression matching.

Initialize with temporal patterns.

PARAMETERDESCRIPTION
patterns_file

Path to temporal patterns JSON file

TYPE:Optional[Path]DEFAULT:None

Attributes

loggerinstance-attribute
Python
logger = get_logger(__name__)
patternsinstance-attribute
Python
patterns = _load_patterns(patterns_file)
compiled_patternsinstance-attribute
Python
compiled_patterns = _compile_patterns()

PromptContextdataclass

Python
PromptContext(text: str, original: Optional[str] = None, keywords: list[str] = list(), task_type: str = 'general', intent: str = 'understand', entities: list[dict[str, Any]] = list(), file_patterns: list[str] = list(), focus_areas: list[str] = list(), temporal_context: Optional[dict[str, Any]] = None, scope: dict[str, Any] = dict(), external_context: Optional[dict[str, Any]] = None, metadata: dict[str, Any] = dict(), confidence_scores: dict[str, float] = dict(), session_id: Optional[str] = None, timestamp: datetime = datetime.now(), include_tests: bool = False)

Context extracted from user prompt.

Contains all information parsed from the prompt to guide file selection and ranking. This is the primary data structure that flows through the system after prompt parsing.

ATTRIBUTEDESCRIPTION
text

The processed prompt text (cleaned and normalized)

TYPE:str

original

Original input (may be URL or raw text)

TYPE:Optional[str]

keywords

Extracted keywords for searching

TYPE:list[str]

task_type

Type of task detected

TYPE:str

intent

User intent classification

TYPE:str

entities

Named entities found (classes, functions, modules)

TYPE:list[dict[str, Any]]

file_patterns

File patterns to match (.py, test_, etc)

TYPE:list[str]

focus_areas

Areas to focus on (auth, api, database, etc)

TYPE:list[str]

temporal_context

Time-related context (recent, yesterday, etc)

TYPE:Optional[dict[str, Any]]

scope

Scope indicators (modules, directories, exclusions)

TYPE:dict[str, Any]

external_context

Context from external sources (GitHub, JIRA)

TYPE:Optional[dict[str, Any]]

metadata

Additional metadata for processing

TYPE:dict[str, Any]

confidence_scores

Confidence scores for various extractions

TYPE:dict[str, float]

session_id

Associated session if any

TYPE:Optional[str]

timestamp

When context was created

TYPE:datetime

Attributes

textinstance-attribute
Python
text: str
originalclass-attributeinstance-attribute
Python
original: Optional[str] = None
keywordsclass-attributeinstance-attribute
Python
keywords: list[str] = field(default_factory=list)
task_typeclass-attributeinstance-attribute
Python
task_type: str = 'general'
intentclass-attributeinstance-attribute
Python
intent: str = 'understand'
entitiesclass-attributeinstance-attribute
Python
entities: list[dict[str, Any]] = field(default_factory=list)
file_patternsclass-attributeinstance-attribute
Python
file_patterns: list[str] = field(default_factory=list)
focus_areasclass-attributeinstance-attribute
Python
focus_areas: list[str] = field(default_factory=list)
temporal_contextclass-attributeinstance-attribute
Python
temporal_context: Optional[dict[str, Any]] = None
scopeclass-attributeinstance-attribute
Python
scope: dict[str, Any] = field(default_factory=dict)
external_contextclass-attributeinstance-attribute
Python
external_context: Optional[dict[str, Any]] = None
metadataclass-attributeinstance-attribute
Python
metadata: dict[str, Any] = field(default_factory=dict)
confidence_scoresclass-attributeinstance-attribute
Python
confidence_scores: dict[str, float] = field(default_factory=dict)
session_idclass-attributeinstance-attribute
Python
session_id: Optional[str] = None
timestampclass-attributeinstance-attribute
Python
timestamp: datetime = field(default_factory=now)
include_testsclass-attributeinstance-attribute
Python
include_tests: bool = False

Functions

add_keyword
Python
add_keyword(keyword: str, confidence: float = 1.0) -> None

Add a keyword with confidence score.

add_entity
Python
add_entity(name: str, entity_type: str, confidence: float = 1.0) -> None

Add an entity with type and confidence.

add_focus_area
Python
add_focus_area(area: str) -> None

Add a focus area if not already present.

merge_with
Python
merge_with(other: PromptContext) -> PromptContext

Merge this context with another.

to_dict
Python
to_dict() -> dict[str, Any]

Convert to dictionary representation.

from_dictclassmethod
Python
from_dict(data: dict[str, Any]) -> PromptContext

Create PromptContext from dictionary.

get_hash
Python
get_hash() -> str

Compute a deterministic cache key for this prompt context.

The hash incorporates the normalized prompt text, task type, and the ordered list of unique keywords. MD5 is chosen (with usedforsecurity=False) for speed; collision risk is acceptable for internal memoization.

RETURNSDESCRIPTION
str

Hex digest suitable for use as an internal cache key.

TYPE:str

TaskType

Bases: Enum

Types of tasks detected in prompts.

Attributes

FEATUREclass-attributeinstance-attribute
Python
FEATURE = 'feature'
DEBUGclass-attributeinstance-attribute
Python
DEBUG = 'debug'
TESTclass-attributeinstance-attribute
Python
TEST = 'test'
REFACTORclass-attributeinstance-attribute
Python
REFACTOR = 'refactor'
UNDERSTANDclass-attributeinstance-attribute
Python
UNDERSTAND = 'understand'
REVIEWclass-attributeinstance-attribute
Python
REVIEW = 'review'
DOCUMENTclass-attributeinstance-attribute
Python
DOCUMENT = 'document'
OPTIMIZEclass-attributeinstance-attribute
Python
OPTIMIZE = 'optimize'
SECURITYclass-attributeinstance-attribute
Python
SECURITY = 'security'
ARCHITECTUREclass-attributeinstance-attribute
Python
ARCHITECTURE = 'architecture'
MIGRATIONclass-attributeinstance-attribute
Python
MIGRATION = 'migration'
GENERALclass-attributeinstance-attribute
Python
GENERAL = 'general'

Functions

from_stringclassmethod
Python
from_string(value: str) -> TaskType

Create TaskType from string value.

Functions

create_parser

Python
create_parser(config=None, use_cache: bool = True, use_ml: bool = None, cache_manager=None) -> PromptParser

Create a configured prompt parser.

Convenience function to quickly create a parser with sensible defaults.

PARAMETERDESCRIPTION
config

Optional TenetsConfig instance (creates default if None)

DEFAULT:None

use_cache

Whether to enable caching (default: True)

TYPE:boolDEFAULT:True

use_ml

Whether to use ML features (None = auto-detect from config)

TYPE:boolDEFAULT:None

cache_manager

Optional cache manager for persistence

DEFAULT:None

Uses centralized NLP components for all text processing.

RETURNSDESCRIPTION
PromptParser

Configured PromptParser instance

Example

parser = create_parser() context = parser.parse("add user authentication") print(context.intent)

parse_prompt

Python
parse_prompt(prompt: str, config=None, fetch_external: bool = True, use_cache: bool = False) -> Any

Parse a prompt without managing parser instances.

Convenience function for one-off prompt parsing. Uses centralized NLP components including keyword extraction and tokenization.

PARAMETERDESCRIPTION
prompt

The prompt text or URL to parse

TYPE:str

config

Optional TenetsConfig instance

DEFAULT:None

fetch_external

Whether to fetch external content (default: True)

TYPE:boolDEFAULT:True

use_cache

Whether to use caching (default: False for one-off)

TYPE:boolDEFAULT:False

RETURNSDESCRIPTION
Any

PromptContext with extracted information

Example

context = parse_prompt("implement caching layer") print(f"Keywords: {context.keywords}") print(f"Intent: {context.intent}")

extract_keywords

Python
extract_keywords(text: str, max_keywords: int = 20) -> List[str]

Extract keywords from text using NLP components.

Uses the centralized keyword extractor with YAKE/TF-IDF/frequency fallback chain for robust keyword extraction.

PARAMETERDESCRIPTION
text

Input text to analyze

TYPE:str

max_keywords

Maximum number of keywords to extract

TYPE:intDEFAULT:20

RETURNSDESCRIPTION
List[str]

List of extracted keywords

Example

keywords = extract_keywords("implement OAuth2 authentication") print(keywords) # ['oauth2', 'authentication', 'implement']

detect_intent

Python
detect_intent(prompt: str, use_ml: bool = False) -> str

Analyzes prompt text to determine user intent.

PARAMETERDESCRIPTION
prompt

The prompt text to analyze

TYPE:str

use_ml

Whether to use ML-based detection (requires ML dependencies)

TYPE:boolDEFAULT:False

RETURNSDESCRIPTION
str

Intent type string (implement, debug, understand, etc.)

Example

intent = detect_intent("fix the authentication bug") print(intent) # 'debug'

extract_entities

Python
extract_entities(text: str, min_confidence: float = 0.5, use_nlp: bool = False, use_fuzzy: bool = True) -> List[Dict[str, Any]]

Extract named entities from text.

Identifies classes, functions, files, modules, and other programming entities mentioned in the text.

PARAMETERDESCRIPTION
text

Input text to analyze

TYPE:str

min_confidence

Minimum confidence threshold

TYPE:floatDEFAULT:0.5

use_nlp

Whether to use NLP-based NER (requires spaCy)

TYPE:boolDEFAULT:False

use_fuzzy

Whether to use fuzzy matching

TYPE:boolDEFAULT:True

RETURNSDESCRIPTION
List[Dict[str, Any]]

List of entity dictionaries with name, type, and confidence

Example

entities = extract_entities("update the UserAuth class in auth.py") for entity in entities: ... print(f"{entity['type']}: {entity['name']}")

parse_external_reference

Python
parse_external_reference(url: str) -> Optional[Dict[str, Any]]

Parse an external reference URL.

Extracts information from GitHub issues, JIRA tickets, GitLab MRs, Linear issues, Asana tasks, Notion pages, and other external references.

PARAMETERDESCRIPTION
url

URL to parse

TYPE:str

RETURNSDESCRIPTION
Optional[Dict[str, Any]]

Dictionary with reference information or None if not recognized

Example

ref = parse_external_reference("https://github.com/org/repo/issues/123") print(ref['type']) # 'github' print(ref['identifier']) # 'org/repo#123'

extract_temporal

Python
extract_temporal(text: str) -> List[Dict[str, Any]]

Extract temporal expressions from text.

Identifies dates, time ranges, relative dates, and recurring patterns.

PARAMETERDESCRIPTION
text

Input text to analyze

TYPE:str

RETURNSDESCRIPTION
List[Dict[str, Any]]

List of temporal expression dictionaries

Example

temporal = extract_temporal("changes from last week") for expr in temporal: ... print(f"{expr['text']}: {expr['type']}")

Modules