util
Checkpointer
Source code in src/ursa/util/__init__.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
from_path(db_path, db_name='checkpointer.db')
classmethod
Make checkpointer sqlite db.
Args
- db_path: The path to the SQLite database file (e.g. ./checkpoint.db) to be created.
Source code in src/ursa/util/__init__.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
diff_renderer
DiffRenderer
Renderable diff—console.print(DiffRenderer(...))
Source code in src/ursa/util/diff_renderer.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
github_research
Fetch recent issues & PRs from GitHub repos for planning context.
Uses the gh CLI (https://cli.github.com/) which handles authentication
transparently. Falls back gracefully when gh is not installed or when a
repo URL does not point at GitHub.
fetch_repo_context(owner, repo, *, max_issues=10, max_prs=10, issue_state='all', pr_state='all')
Fetch recent issues and PRs for a single GitHub repo.
Returns a formatted text block suitable for inclusion in a planner prompt.
Source code in src/ursa/util/github_research.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
gather_github_context(repos, *, max_issues=10, max_prs=10)
Gather GitHub context for all repos that have GitHub URLs.
Parameters
repos:
List of repo config dicts (each must have at least url and name).
max_issues:
Maximum recent issues to fetch per repo.
max_prs:
Maximum recent PRs to fetch per repo.
Returns
Formatted text block with issues/PRs across repos, or None if nothing
was fetched (e.g. no GitHub URLs, gh not installed).
Source code in src/ursa/util/github_research.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
parse_github_owner_repo(url)
Extract (owner, repo) from a GitHub clone URL.
Supports both HTTPS and SSH URLs. Returns None for non-GitHub URLs.
Source code in src/ursa/util/github_research.py
21 22 23 24 25 26 27 28 29 | |
has_optional_dep_group
has_optional_dep_group(dep)
Check whether an optional dependency group is installed.
Attempts to import each module.
Source code in src/ursa/util/has_optional_dep_group.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
helperFunctions
run_tool_calls(ai_msg, tools)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ai_msg
|
AIMessage
|
The LLM's AIMessage containing tool calls. |
required |
tools
|
ToolRegistry | Iterable[Runnable | Callable[..., Any]]
|
Either a dict {name: tool} or an iterable of tools (must have |
required |
Returns:
| Name | Type | Description |
|---|---|---|
out |
list[BaseMessage]
|
list[BaseMessage] to feed back to the model |
Source code in src/ursa/util/helperFunctions.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
logo_generator
generate_logo_sync(*, problem_text, workspace, out_dir, filename=None, model=DEFAULT_IMAGE_MODEL, size=None, background='opaque', quality='high', n=1, overwrite=False, style='sticker', allow_text=False, palette=None, mode='logo', aspect='square', style_intensity='overt', aperture=DEFAULT_APERTURE, console=None, image_model_provider='openai', image_provider_kwargs=None)
Generate images.
Key change (diversity): - We no longer rely on a single prompt with n>1 siblings for scenes. - If mode='scene' and style='random' and n>1, we pick n distinct scene styles (horror/fantasy/etc) and generate 1 image per style/prompt.
Return value
- Returns the "main" path (first generated image). Additional variants are saved alongside it.
Source code in src/ursa/util/logo_generator.py
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 | |
mcp
memory_logger
AgentMemory
Simple wrapper around a persistent Chroma vector-store for agent-conversation memory.
Parameters
path : str | Path | None
Where to keep the on-disk Chroma DB. If None, a folder called
agent_memory_db is created in the package’s base directory.
collection_name : str
Name of the Chroma collection.
embedding_model :
Notes
- Requires
langchain-chroma, andchromadb.
Source code in src/ursa/util/memory_logger.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
add_memories(new_chunks, metadatas=None)
Append new text chunks to the existing store (must call build_index
first if the DB is empty).
Raises
RuntimeError If the vector store is not yet initialised.
Source code in src/ursa/util/memory_logger.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
build_index(chunks, metadatas=None)
Create a fresh vector store from chunks. Existing data (if any)
are overwritten.
Parameters
chunks : Sequence[str]
Text snippets (already chunked) to embed.
metadatas : Sequence[dict] | None
Optional metadata dict for each chunk, same length as chunks.
Source code in src/ursa/util/memory_logger.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
retrieve(query, k=4, with_scores=False, **search_kwargs)
Return the k most similar chunks for query.
Parameters
query : str
Natural-language question or statement.
k : int
How many results to return.
with_scores : bool
If True, also return similarity scores.
**search_kwargs
Extra kwargs forwarded to Chroma’s similarity_search* helpers.
Returns
list[Document] | list[tuple[Document, float]]
Source code in src/ursa/util/memory_logger.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
delete_database(path=None)
Simple wrapper around a persistent Chroma vector-store for agent-conversation memory.
Parameters
path : str | Path | None
Where the on-disk Chroma DB is for deleting. If None, a folder called
agent_memory_db is created in the package’s base directory.
Source code in src/ursa/util/memory_logger.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
parse
extract_json(text)
Extract a JSON object or array from text that might contain markdown or other content.
The function attempts three strategies
- Extract JSON from a markdown code block labeled as JSON.
- Extract JSON from any markdown code block.
- Use bracket matching to extract a JSON substring starting with '{' or '['.
Returns:
| Type | Description |
|---|---|
list[dict]
|
A Python object parsed from the JSON string (dict or list). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no valid JSON is found. |
Source code in src/ursa/util/parse.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
extract_main_text_only(html, *, max_chars=250000)
Returns plain text with navigation/ads/scripts removed. Prefers trafilatura -> jusText -> BS4 paragraphs.
Source code in src/ursa/util/parse.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
read_text_file(path)
Reads in a file at a given path into a string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
string filename, with path, to read in |
required |
Source code in src/ursa/util/parse.py
665 666 667 668 669 670 671 672 673 674 675 676 677 | |
resolve_pdf_from_osti_record(rec, *, headers=None, unpaywall_email=None, timeout=25)
Returns (pdf_url, landing_used, note) - pdf_url: direct downloadable PDF URL if found (or a strong candidate) - landing_used: landing page URL we parsed (if any) - note: brief trace of how we found it
Source code in src/ursa/util/parse.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |
plan_execute_utils
Shared utilities for plan_execute workflows.
This module contains common functionality used by both single-repo and multi-repo plan/execute workflows to reduce duplication and improve maintainability.
deep_merge_dicts(base, override)
Recursively merge override into base and return a new dict. - dict + dict => deep merge - otherwise => override wins
Source code in src/ursa/util/plan_execute_utils.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
fmt_elapsed(seconds)
Format elapsed seconds as compact h:mm:ss or m:ss.
Source code in src/ursa/util/plan_execute_utils.py
530 531 532 533 534 535 536 537 538 539 | |
generate_workspace_name(project='run')
Generate a workspace name using randomname, with timestamp fallback.
Source code in src/ursa/util/plan_execute_utils.py
60 61 62 63 64 65 66 | |
hash_plan(plan_steps)
Generate a stable hash of plan steps for change detection.
Source code in src/ursa/util/plan_execute_utils.py
137 138 139 140 141 142 143 144 145 146 147 | |
load_json_file(path, default)
Load JSON from a file path, returning default on missing/invalid JSON.
Source code in src/ursa/util/plan_execute_utils.py
85 86 87 88 89 90 91 92 93 | |
load_yaml_config(path)
Load a YAML config file and return as a SimpleNamespace.
Source code in src/ursa/util/plan_execute_utils.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
looks_like_secret_key(name)
Check if a parameter name looks like it contains sensitive data.
Source code in src/ursa/util/plan_execute_utils.py
165 166 167 168 | |
mask_secret(value, keep_start=6, keep_end=4)
Mask a secret-like string, keeping only the beginning and end. Example: sk-proj-abc123456789xyz -> sk-proj-...9xyz
Source code in src/ursa/util/plan_execute_utils.py
171 172 173 174 175 176 177 178 179 180 | |
print_llm_init_banner(agent_name, provider, model_name, provider_extra, llm_kwargs, model_obj=None)
Print a Rich panel showing LLM initialization details.
Source code in src/ursa/util/plan_execute_utils.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
resolve_llm_kwargs_for_agent(models_cfg, agent_name)
Given the YAML models: dict, compute merged kwargs for init_chat_model(...)
for a specific agent ('planner' or 'executor').
Merge order (later wins): 1) {} (empty) 2) models.defaults.params (optional) 3) models.profiles[defaults.profile] (optional) 4) models.agents[agent_name].profile (optional; merges that profile on top) 5) models.agents[agent_name].params (optional)
Source code in src/ursa/util/plan_execute_utils.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
resolve_model_choice(model_choice, models_cfg)
Accepts strings like 'openai:gpt-5.2' or 'my_endpoint:openai/gpt-oss-120b'. Looks up per-provider settings from cfg.models.providers.
Returns: (model_provider, pure_model, provider_extra_kwargs_for_init)
Source code in src/ursa/util/plan_execute_utils.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
sanitize_for_logging(obj)
Recursively sanitize secrets from config objects for safe logging.
Source code in src/ursa/util/plan_execute_utils.py
183 184 185 186 187 188 189 190 191 192 193 194 195 | |
save_json_file(path, payload, *, indent=2, ensure_parent=True)
Write JSON payload to disk with optional parent directory creation.
Source code in src/ursa/util/plan_execute_utils.py
96 97 98 99 100 101 102 103 104 105 106 107 | |
setup_llm(model_choice, models_cfg=None, agent_name=None)
Build a LangChain chat model via init_chat_model(...), optionally applying YAML-driven params from models.profiles, models.defaults, models.agents.
Source code in src/ursa/util/plan_execute_utils.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | |
setup_workspace(user_specified_workspace, project='run', model_name='openai:gpt-5-mini')
Set up a workspace directory for a plan/execute run. Returns the workspace path as a string.
Source code in src/ursa/util/plan_execute_utils.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
snapshot_sqlite_db(src_path, dst_path)
Make a consistent copy of the SQLite database at src_path into dst_path, using the sqlite3 backup API. Safe with WAL; no need to copy -wal/-shm.
Source code in src/ursa/util/plan_execute_utils.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
timed_input_with_countdown(prompt, timeout)
Read a line with a per-second countdown. Returns: - the user's input (str) if provided, - None if timeout expires, - None if non-interactive or timeout<=0.
Source code in src/ursa/util/plan_execute_utils.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
plan_renderer
render_plan_steps_rich(plan_steps, highlight_index=None)
Pretty table for a list of plan steps (strings or dicts), with an optional highlighted row.
Source code in src/ursa/util/plan_renderer.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
traced
types
AsciiStr = Annotated[str, StringConstraints(strip_whitespace=True, strict=True, pattern='^[\\x20-\\x7E\\t\\n\\r\\f\\v]+$')]
module-attribute
Limit strings to "text" ASCII characters (letters, digits, symbols, whitespace)