Python modules and classes¶
This page is generated from inline docstrings via mkdocstrings. The sections below are grouped by package or client.
packages/mewbo_core (core runtime)¶
mewbo_core.loop.orchestrator
¶
Session orchestration entrypoint.
Orchestrator
¶
Unified tool-use orchestration loop.
Source code in packages/mewbo_core/src/mewbo_core/loop/orchestrator.py
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 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 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 350 351 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 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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 | |
__init__(*, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, session_store: SessionStoreBase | None = None, tool_registry: ToolRegistry | None = None, permission_policy: PermissionPolicy | None = None, approval_callback: Callable[[ActionStep], bool] | None = None, hook_manager: HookManager | None = None, cwd: str | None = None, session_step_budget: int = 0, system_instructions_store: SystemInstructionsStoreBase | None = None, session_mcp_servers: dict[str, dict] | None = None) -> None
¶
Initialize orchestration dependencies.
session_mcp_servers are MCP servers a caller attaches to THIS run, in
the standard {name: {command|url, …}} config shape. They are merged
into the registry build below alongside the plugin-contributed ones, and
their discovered tool ids are admitted through this run's
allowed_tools (:meth:_session_mcp_tool_ids).
It is deliberately NOT named extra_mcp_servers, even though that is
the parameter it feeds. The two carry different grants, and reusing one
name for both senses is the trap the house rules name outright: a
plugin-contributed server's tools are subject to allowed_tools like
any other registry tool, while a server named HERE is admitted by the act
of naming it — the caller attaching a server for one run IS the grant, and
it has no other way to express one, since a server's tool ids are not
knowable until discovery has run. Widening the existing parameter's
meaning instead would silently admit every plugin server's tools into
every scoped session in the deployment.
Discovery is a network/subprocess cost and it belongs HERE rather than at whichever caller assembled the config: this constructor already runs on the background run thread, which is the offline side of the acceptance/execution boundary. A caller resolving the ids itself would be paying for discovery on its own request path.
Source code in packages/mewbo_core/src/mewbo_core/loop/orchestrator.py
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 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
arun(user_query: str, *, max_iters: int = 3, initial_plan: Plan | None = None, return_state: bool = False, session_id: str | None = None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False) -> TaskQueue | tuple[TaskQueue, OrchestrationState]
async
¶
Run orchestration asynchronously (async-first entry point).
Awaits the orchestration coroutine directly, so an environment that
already owns a running event loop (browser-hosted Pyodide's WebLoop,
async test harnesses) can drive a query with native await and NO
nested asyncio.run. The sync :meth:run wrapper is the CPython
entry point and delegates here; the two share this single body.
Source code in packages/mewbo_core/src/mewbo_core/loop/orchestrator.py
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 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 | |
run(user_query: str, *, max_iters: int = 3, initial_plan: Plan | None = None, return_state: bool = False, session_id: str | None = None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False) -> TaskQueue | tuple[TaskQueue, OrchestrationState]
¶
Run orchestration for a session (sync wrapper around :meth:arun).
Backward-compatible synchronous entry point for CLI / API request
threads / tests. Owns the event-loop lifecycle via asyncio.run, so
every existing sync caller behaves exactly as before. Environments that
already drive an event loop (browser-hosted Pyodide's WebLoop) must call
:meth:arun instead — it awaits the same body with NO nested
asyncio.run (the "WebLoop wall").
Source code in packages/mewbo_core/src/mewbo_core/loop/orchestrator.py
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 350 351 352 353 354 355 356 357 358 359 | |
mewbo_core.loop.task_master
¶
Task planning and orchestration loop for Mewbo.
generate_action_plan(user_query: str, model_name: str | None = None, tool_registry: ToolRegistry | None = None, session_summary: str | None = None, recent_events: list[EventRecord] | None = None, selected_events: list[EventRecord] | None = None, *, mode: str = 'act', feedback: str | None = None) -> Plan
¶
Generate a plan for a user query.
Source code in packages/mewbo_core/src/mewbo_core/loop/task_master.py
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 | |
orchestrate_session(user_query: str, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, max_iters: int = 3, initial_plan: Plan | None = None, return_state: bool = False, session_id: str | None = None, session_store: SessionStoreBase | None = None, tool_registry: ToolRegistry | None = None, permission_policy: PermissionPolicy | None = None, approval_callback: Callable[[ActionStep], bool] | None = None, hook_manager: HookManager | None = None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, cwd: str | None = None, session_step_budget: int = 0, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False, session_mcp_servers: dict[str, dict] | None = None) -> TaskQueue | tuple[TaskQueue, OrchestrationState]
¶
Run the orchestration loop synchronously.
Thin sync wrapper over :func:orchestrate_session_async — mirrors
Orchestrator.run() = asyncio.run(self.arun(...)) one layer up, so
there is exactly one place (here) that constructs the Orchestrator
and forwards every kwarg for both the sync and async entry points.
Source code in packages/mewbo_core/src/mewbo_core/loop/task_master.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 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 | |
orchestrate_session_async(user_query: str, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, max_iters: int = 3, initial_plan: Plan | None = None, return_state: bool = False, session_id: str | None = None, session_store: SessionStoreBase | None = None, tool_registry: ToolRegistry | None = None, permission_policy: PermissionPolicy | None = None, approval_callback: Callable[[ActionStep], bool] | None = None, hook_manager: HookManager | None = None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, cwd: str | None = None, session_step_budget: int = 0, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False, session_mcp_servers: dict[str, dict] | None = None) -> TaskQueue | tuple[TaskQueue, OrchestrationState]
async
¶
Run the orchestration loop on an already-running event loop.
Async mirror of :func:orchestrate_session for environments (Pyodide's
WebLoop, async test harnesses) where asyncio.run cannot be used because
the loop is already active. Same signature and semantics as the sync entry
point — it awaits :meth:Orchestrator.arun instead of calling
:meth:Orchestrator.run, so no nested asyncio.run is created.
Source code in packages/mewbo_core/src/mewbo_core/loop/task_master.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
mewbo_core.loop.tool_use_loop
¶
Async tool-use conversation loop with sub-agent support.
ResilienceNote
dataclass
¶
Bounded, factual record of this run's LLM retry/fallback events.
The model is otherwise BLIND to its own retries: RetryStrategy.run has
only two outward channels — emit (event log / console / CLI) and
raise — and never touches the message list, so a run that quietly
re-drives a failing model, or escalates down its ladder, never sees any of
it. This note carries the SAME grounded facts the event log already holds —
which model was tried, how many attempts, the error class, whether a switch
occurred — into a dedicated system-prompt slot.
Holds only the most recent max_events records (hot in-process runtime
state — a plain dataclass, no trust boundary). :meth:render returns the
whole note, or "" when nothing has gone wrong yet, so a clean run pays
nothing and the slot stays empty.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
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 | |
record(event: Event) -> None
¶
Append a compact summary for a retry/fallback event; ignore the rest.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
175 176 177 178 179 180 181 182 183 | |
render() -> str
¶
The full note text, or "" when no resilience event has occurred.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
199 200 201 202 203 204 | |
ToolBatch
dataclass
¶
A batch of tool calls with shared concurrency mode.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
330 331 332 333 334 335 | |
ToolCallResult
dataclass
¶
Result of executing a single tool call.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
ToolUseLoop
¶
Async tool-use conversation loop.
Each instance owns one conversation with one LLM. Sub-agents are
created by spawning new ToolUseLoop instances via the
spawn_agent internal tool.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
348 349 350 351 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 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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 | |
active_model: str
property
¶
The model this loop last generated with — the one that SERVED the run.
Read by the orchestrator, which otherwise builds its failure record from the model frozen at construction: a run that escalated A -> B -> C then died named A, and an operator reading that benches a model that had not been active for minutes. Equal to the configured model until a sticky escalation promotes it, so the ordinary path is unchanged.
__init__(*, agent_context: AgentContext, tool_registry: ToolRegistry, permission_policy: PermissionPolicy, approval_callback: Callable[[ActionStep], bool] | None = None, hook_manager: HookManager, safety_plane: SafetyPlane | None = None, project_instructions: str | None = None, user_instructions: str | None = None, skill_instructions: str | None = None, skill_registry: Any = None, agent_registry: Any = None, session_tool_registry: SessionToolRegistry | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, cwd: str | None = None, session_id: str | None = None, session_capabilities: tuple[str, ...] = (), extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, project_catalog: ProjectCatalog | None = None, session_context_reader: Callable[[], dict[str, object]] | None = None, contract: DelegationContract | None = None, verification: CommandVerification | None = None, verifier_runner: VerifierRunner | None = None, watchdog_sleeper: Callable[[float], Awaitable[None]] | None = None) -> None
¶
Initialize the tool-use loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_context
|
AgentContext
|
Required — carries model, cancel, logger, registry. |
required |
tool_registry
|
ToolRegistry
|
Registered tools available to this agent. |
required |
permission_policy
|
PermissionPolicy
|
Permission rules for tool execution. |
required |
approval_callback
|
Callable[[ActionStep], bool] | None
|
Optional callback for ASK decisions (None for sub-agents). |
None
|
hook_manager
|
HookManager
|
Lifecycle hooks. |
required |
safety_plane
|
SafetyPlane | None
|
Operator-owned tool-call gate and session observer,
built once by the orchestrator from config + |
None
|
project_instructions
|
str | None
|
CLAUDE.md / AGENTS.md content discovered at session start. |
None
|
user_instructions
|
str | None
|
Operator-authored custom instructions, ALREADY RENDERED
by |
None
|
skill_instructions
|
str | None
|
Pre-rendered skill body (from user /skill invocation). |
None
|
skill_registry
|
Any
|
SkillRegistry for auto-invocation catalog + activate_skill handling. |
None
|
agent_registry
|
Any
|
AgentRegistry for agent type catalog + spawn_agent type lookup. |
None
|
session_tool_registry
|
SessionToolRegistry | None
|
Registry of plugin-contributed session-tool
factories. Each matching factory (filtered by |
None
|
allowed_tools
|
list[str] | None
|
The agent's allowlist used to filter which session
tools the plugin registry should build for this agent. |
None
|
denied_tools
|
list[str] | None
|
Session-tool ids withheld regardless of which gate in
|
None
|
strict_tool_scope
|
bool
|
Whether |
False
|
cwd
|
str | None
|
Working directory for this agent (project root). |
None
|
session_id
|
str | None
|
Session identifier — used for plan-mode path scoping. |
None
|
session_capabilities
|
tuple[str, ...]
|
Client-advertised capability tuple from the
|
()
|
extra_session_tools
|
list[SessionTool] | None
|
Caller-injected |
None
|
enable_skills
|
bool
|
When |
True
|
project_autoselect
|
bool
|
When |
False
|
project_catalog
|
ProjectCatalog | None
|
The catalog those two tools read and resolve
through, built by the caller ( |
None
|
session_context_reader
|
Callable[[], dict[str, object]] | None
|
Reads back the session's CURRENT effective
context — the most-recent |
None
|
contract
|
DelegationContract | None
|
The spawner's declared |
None
|
verification
|
CommandVerification | None
|
The spawner's declared ground-truth completion check
for THIS agent — |
None
|
verifier_runner
|
VerifierRunner | None
|
Injected |
None
|
watchdog_sleeper
|
Callable[[float], Awaitable[None]] | None
|
Injected wait between watchdog sweeps (defaults
to |
None
|
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
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 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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 | |
llm_call_stall_age(now: float) -> float | None
¶
Seconds the in-flight LLM call has been outstanding, else None.
Pure read over (_llm_call_started_at, now) with no clock of its own,
so the liveness rule is exercisable at any age without waiting for one
— the watchdog supplies time.monotonic(), a test supplies a number.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 | |
rebind_workspace(entry: ProjectEntry) -> dict[str, object]
¶
Re-point this loop at entry's directory. THE one mutation seam.
Everything derived from the working directory moves together here,
because a partial switch is worse than none: the agent believes it moved
and half the machinery did not. Returns the facts switch_project
renders back to the model.
The step that is easiest to miss is the SPAWN seam.
:class:~mewbo_core.agents.spawn_agent.SpawnAgentTool holds its OWN copy of the
workspace and forwards it verbatim to every child loop it builds, so a
switch that updates only self._cwd leaves every sub-agent spawned
afterwards working in the OLD project — silently, and with results that
look plausible right up until they are applied to the wrong tree.
Two deliberate limits, stated so nobody reads them as bugs:
- The spec set NARROWS to what this run already held. A switch must
never widen the tool ceiling the caller granted at run start, so a new
project's own MCP servers are not admitted mid-run; a fresh run
against that project resolves them normally, and the
contextevent written here is what makes that fresh run land in the right place. - Skills ACCUMULATE rather than being replaced. The registry also holds plugin-contributed and user-level skills that a fresh scan of the new directory alone would drop, and losing those costs more than carrying the previous project's.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 | |
run(user_query: str, *, tool_specs: list[ToolSpec], context: ContextSnapshot | None = None, plan: Plan | None = None, mode: str = 'act') -> tuple[TaskQueue, OrchestrationState]
async
¶
Run the async tool-use loop and return TaskQueue + OrchestrationState.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 | |
mewbo_core.agents.agent_context
¶
Immutable agent context propagated through the agent hierarchy.
AgentContext is the per-agent state carried by every ToolUseLoop
instance. The root agent creates one via AgentContext.root(); child
agents receive one via parent_ctx.child().
The hypervisor control plane (AgentHypervisor, AgentHandle) lives
in :mod:mewbo_core.agents.hypervisor.
AgentContext
dataclass
¶
Immutable context propagated through the agent hierarchy.
Every ToolUseLoop instance requires an AgentContext. The root agent
creates one via AgentContext.root(). Child agents receive one
via parent_ctx.child().
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_context.py
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 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
can_spawn: bool
property
¶
True if this agent is allowed to create children.
remaining_depth: int
property
¶
Number of spawn levels remaining below this agent.
child(*, model_name: str | None = None, capability_mode: str = 'all', workspace_mode: str = 'full_access', atomic: bool = False) -> AgentContext
¶
Create a child context with depth+1.
capability_mode is the child's REQUESTED delegation privilege
ceiling; the stored value is the narrower of it and this (parent)
agent's own capability_mode — a child can only restrict, so
an unset request (default "all") simply inherits the parent's mode.
workspace_mode is the SAME story on the filesystem-containment
axis: the child's requested tier is narrowed min-wins against this
agent's own, so an unset request (default "full_access") inherits the
parent's tier and a grandchild under a read_only ancestor stays
read_only.
atomic is this child's OWN requested firebreak (from
its DelegationContract); the stored value is self.atomic or
atomic — a simple OR, never narrower — so an atomic ancestor's
descendants can never climb back to open_ended.
model_name falls back to self.model_name, which the inheriting
child then runs on. That fallback is only correct while this context's
model_name is the parent's LIVE model, and a parent that heals down
its fallback ladder promotes a new one mid-run — on the loop, since this
context is frozen. So the loop re-seats the spawn seam's context (via
dataclasses.replace) whenever it escalates: without that, a parent
that had just escaped a dead model would fan every un-overridden child
straight back onto it, and the children would die at step 0 while the
parent ran healthy.
Raises:
| Type | Description |
|---|---|
AgentDepthExceeded
|
If |
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_context.py
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 | |
root(*, model_name: str, max_depth: int = 5, fallback_models: tuple[str, ...] = (), should_cancel: Callable[[], bool] | None = None, event_logger: Callable[[Event], None] | None = None, registry: AgentHypervisor | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, workspace_mode: str = 'full_access', capability_mode: str = 'all') -> AgentContext
staticmethod
¶
Create the root agent context.
workspace_mode seeds the root of the filesystem-containment
axis from agent.default_workspace_mode (default "full_access");
every child narrows from here. Left at the default, the whole tree is
unrestricted.
capability_mode seeds the root of the delegation-privilege axis the
same way (default "all" — no filtering). A caller resolving a
principal's role ceiling passes a narrower tier (read_only for a
viewer) so the ROOT agent — not only its spawned children — is capped;
every child then narrows monotonically from here via :meth:child. Left
at "all" the whole tree is unrestricted.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_context.py
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 240 241 242 243 244 245 246 247 248 249 | |
AgentDepthExceeded
¶
Bases: Exception
Raised when attempting to spawn beyond max_depth.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_context.py
27 28 29 30 31 32 33 34 | |
__init__(attempted: int, maximum: int) -> None
¶
Initialize with the attempted and maximum depth values.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_context.py
30 31 32 33 34 | |
AgentHandle
dataclass
¶
Mutable runtime state for a single agent — lives in the hypervisor.
Created when an agent registers and updated throughout its lifecycle. Fields are read by the CLI agent tree display and the hypervisor's query/cancellation methods.
Handle starts as submitted, transitions to
running when the loop begins, then to a terminal state.
last_step_at enables tool-call-granularity
stall detection without destroying accumulated context.
message_queue enables bidirectional
adaptive coordination — the hypervisor injects NL feedback.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
342 343 344 345 346 347 348 349 350 351 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 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
AgentHypervisor
¶
Hypervisor control plane — manages the full agent tree for a session.
Thread-safe via asyncio.Lock. A single instance is shared across all
agents in the hierarchy through AgentContext.registry.
Responsibilities
- Admission control:
accept()/accept_batch()/release()gate concurrency through an injected :class:AgentQueue(default 20 running slots) that QUEUES over-cap work instead of dropping it. - Registration:
register()/unregister()track agent handles keyed byagent_id. - Status:
update_step()/mark_done()record execution progress and terminal state. - Queries:
list_children()/list_descendants()/list_all()expose the live tree for display and introspection. - Cancellation:
cancel_agent()cancels a single agent;cleanup()tears down the entire tree on session exit.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 | |
free_slots: int
property
¶
Slots a spawn could be dispatched into right now.
pending_dispatch: int
property
¶
Accepted spawns not yet started.
NOT a status: those agents are submitted like any other, and this
is only the scheduler's count of how many are still waiting on a slot.
total_steps: int
property
¶
Total tool steps executed across all agents in the session.
__init__(*, max_concurrent: int = 20, session_step_budget: int = 0, attestation: AttestationChain | None = None, queue: AgentQueue | None = None) -> None
¶
Initialize hypervisor with concurrency and budget limits.
Session-wide budget with graduated enforcement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_concurrent
|
int
|
Maximum number of concurrently RUNNING agents. |
20
|
session_step_budget
|
int
|
Total tool steps allowed across all agents in the session. 0 means unlimited. |
0
|
attestation
|
AttestationChain | None
|
optional provenance hash chain for
this session's agent tree. The hypervisor never constructs one
itself (it has no session_id, no store) — the orchestrator
injects it, seeded from the store's last persisted record, when
the feature is config-enabled. |
None
|
queue
|
AgentQueue | None
|
the admission scheduler. Injected so a deployment (or a
test) can seat a differently-sized or differently-ordered one
without the hypervisor learning how scheduling works; the
default is an :class: |
None
|
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
accept(unit: SpawnUnit) -> bool
async
¶
Admit ONE spawn: True = dispatched now, False = deferred.
Never refuses for capacity — that is the whole point of the queue.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
721 722 723 724 725 726 | |
accept_batch(units: Sequence[SpawnUnit]) -> list[bool]
async
¶
Admit a whole fan-out at once — see :meth:AgentQueue.accept_batch.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
728 729 730 | |
agent_step_state(agent_id: str) -> str
async
¶
Per-contract step-budget state for one agent.
"ok" for an unregistered agent or one whose contract carries no
step bound — the same inert default as a disabled contract.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
948 949 950 951 952 953 954 955 956 957 958 | |
agent_token_state(agent_id: str) -> str
async
¶
Per-contract advisory token state for one agent.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
960 961 962 963 964 965 966 | |
budget_exhausted() -> bool
¶
Check if the session step budget is exhausted (0 = unlimited).
Graduated enforcement — this is the trigger check. The response (NL warning injection) happens in ToolUseLoop.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
912 913 914 915 916 917 918 | |
budget_remaining() -> int
¶
Steps remaining in the session budget (0 = unlimited).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
920 921 922 923 924 | |
budget_warning(*, headroom: int = 5) -> bool
¶
True when within headroom steps of the session budget (0 = off).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
926 927 928 929 930 | |
cancel_agent(agent_id: str) -> str | None
async
¶
Cancel an agent, whether it has started or is still waiting for a slot.
Returns None on success, or a diagnostic string on failure.
The waiting case is checked FIRST and it is not an optimization.
asyncio_task is populated by the child driver, which runs only
AFTER dispatch — so a capacity-deferred agent has no task, the
task-cancellation path reported no asyncio task, and the agent then
STARTED anyway the moment a sibling freed a slot. Refusing to cancel
something and then running it is the worst of both answers, and it is
reachable the instant a fan-out exceeds the concurrency limit.
Dropping it from the scheduler is what makes the cancel real.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 | |
cancel_pending() -> list[str]
async
¶
Drop every accepted-but-undispatched spawn, settling each as cancelled.
A waiting agent holds no slot and owns no asyncio.Task, so neither
cancel_agent nor the cleanup sweep's task cancellation can reach
it — it would sit submitted forever and read as live. Returns the
ids dropped. Called before teardown so a manager settling on the way
out cannot pump a brand-new child into a run that is already ending.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | |
cleanup(timeout: float = 5.0) -> None
async
¶
Cancel all agents with graceful escalation.
Requests cancellation on all active asyncio tasks, waits up to timeout seconds for them to finish, then force-marks any still pending as cancelled.
Covers every :data:ACTIVE_STATUSES agent, not just running: one
still at submitted never had a loop task to cancel — and one still
waiting for a slot never had a task at all — which is exactly why
either would otherwise survive shutdown unmarked. Waiting units are
dropped from the scheduler FIRST, so a manager settling during the
wait window cannot pump a fresh child into a hypervisor that is being
torn down.
Marking here is deliberately IN-MEMORY only — the hypervisor holds no event logger, and wiring one in would invert the layering (the session owns the transcript, the hypervisor owns the tree). The durable terminal is written by whichever peer can still reach the log:
- While the task is still alive (during the request or the wait):
cancelling it raises
CancelledErrorinside the agent's own lifecycle handler, which writes the terminalstopbefore unwinding. That is the normal path. - Once the wait times out, at the final force-mark sweep (the task is wedged, or the process is being torn down mid-flight): nothing in-process can still write, so the durable terminal comes from the startup sweep on the NEXT boot, which settles agent spans left open under a run that has since ended.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 | |
collect_completed(parent_id: str) -> list[AgentHandle]
async
¶
Return children that reached a terminal state with a stored result.
Async CU retrieval — parent reads results when ready, not when child finishes.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 | |
collect_running(parent_id: str) -> list[AgentHandle]
async
¶
Return children of parent_id that are still active.
Reads :data:ACTIVE_STATUSES rather than re-listing the states. That
matters beyond tidiness: this method is the promise-as-completion
gate's ownership index AND what check_agents reports, so a
capacity-deferred child — submitted, registered, not yet started —
must appear here. A refused unit was registered nowhere, which is
exactly why a parent that over-subscribed the fleet was told all its
work was done.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 | |
get(agent_id: str) -> AgentHandle | None
async
¶
Return a single agent handle, or None.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
870 871 872 873 | |
list_all() -> list[AgentHandle]
async
¶
Full tree view — for CLI/API user visibility.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
893 894 895 896 | |
list_children(parent_id: str) -> list[AgentHandle]
async
¶
List direct children of a parent. Enforces isolation.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
875 876 877 878 | |
list_descendants(ancestor_id: str) -> list[AgentHandle]
async
¶
List all descendants recursively.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
880 881 882 883 884 885 886 887 888 889 890 891 | |
list_visible(exclude_agent_id: str | None = None) -> list[AgentHandle]
async
¶
Snapshot of agents excluding the caller — used by check_agents.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
898 899 900 901 | |
mark_done(agent_id: str, status: AgentStatus, error: str | AgentError | None = None) -> None
async
¶
Mark an agent as done with a terminal status.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
mark_tool_start(agent_id: str, tool_id: str | None) -> None
async
¶
Stamp (or clear) the tool actually in flight for stall attribution.
update_step only stamps last_tool_id on
COMPLETION, so a watchdog check firing mid-call would misattribute the
stall to the previous, already-finished tool. Call this at dispatch
start with the tool name, and again with None once the call
resolves (success, timeout, or exception) so active_tool_id never
lingers stale once the agent moves on.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 | |
over_wall_deadline_agents(now: float | None = None) -> list[tuple[AgentHandle, str]]
async
¶
Running agents whose contract wall-clock deadline is warn/over.
Mirrors :meth:stalled_agents — a per-contract cousin of the stall
sweep, keyed on started_at rather than last-progress. now
arrives as a clock ARG (never read internally), so a caller can drive
this deterministically without sleeping a real clock.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |
record_compaction(agent_id: str) -> None
async
¶
Record that an agent compacted its context.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1031 1032 1033 1034 1035 1036 1037 | |
register(handle: AgentHandle) -> None
async
¶
Register a new agent in the hypervisor.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
803 804 805 806 | |
release() -> None
async
¶
Settle one running agent's slot, dispatching whatever waits on it.
Async because it is the DISPATCH PUMP, not a bare counter decrement:
the freed slot is handed to the next waiting unit, which means starting
it. This is deliberately the completion path every settling agent
already calls, and exactly-once is already guaranteed there — a pump
hung off on_agent_stop instead would fire while the slot is still
held and find the queue full every time.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
732 733 734 735 736 737 738 739 740 741 742 | |
render_agent_tree(*, exclude_agent_id: str | None = None) -> str
async
¶
Render a concise text summary of the agent tree for the root's system prompt.
Structural transparency — the root agent (the hypervisor's "brain") gets a live view of all agents so it can reason about the delegation state and intervene if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclude_agent_id
|
str | None
|
If provided, omit this agent from the rendered tree. Used so the calling agent does not see itself listed. |
None
|
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
send_message(agent_id: str, message: str) -> str | None
async
¶
Send a steering message to a running agent.
Returns None on success, or a diagnostic string on failure.
Adaptive coordination — the hypervisor injects NL feedback (budget warnings, stall nudges) into the agent's message queue. The ToolUseLoop drains this queue between steps. Bidirectional system↔agent feedback loop.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
send_to_parent(child_agent_id: str, message: str) -> str | None
async
¶
Route a message from a child agent to its parent's queue.
Returns None on success, or a diagnostic string on failure.
Bidirectional message passing — enables lifecycle manager to notify parent on child completion.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 | |
stalled_agents(threshold: float = 120.0) -> list[AgentHandle]
async
¶
Return agents not making progress within threshold seconds.
Internal trigger: delegatee unresponsive → diagnose → evaluate → intervene.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
unregister(agent_id: str) -> AgentHandle | None
async
¶
Remove an agent from the hypervisor.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
808 809 810 811 812 813 814 815 | |
update_step(agent_id: str, tool_id: str) -> None
async
¶
Record a completed tool execution step.
Track at tool-call granularity, not agent granularity. Updates last_step_at for stall detection and total_steps for session budget enforcement.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
mewbo_core.agents.hypervisor
¶
Agent hypervisor — active governor for multi-agent delegation.
The hypervisor is the centralized control plane that manages the full agent tree for a session. It acts as an active governor (not just a registry), mediating every delegation decision and result handoff.
Scientific grounding: - Adaptive coordination cycle — the hypervisor monitors agents and intervenes via NL feedback when triggers fire. - Structural transparency — configurable monitoring with lifecycle events at each phase transition. - Graduated enforcement — warn, throttle, feedback (never kill first; killing destroys 31-48% of accumulated context). - Task state machine — agents progress through submitted → running → completed/failed/cancelled/rejected. - Communication Units — structured AgentResult with compressed summary field enables inter-agent context passing.
Responsibilities: - Admission control — bounding concurrent agents via semaphore. - Lifecycle tracking — AgentHandle with delegation phase awareness. - Active monitoring — budget tracking, stall detection, NL interventions. - Global eye — render_agent_tree() gives the root agent a live view. - Bidirectional messaging — send_message() enables parent→child steering. - Structured results — AgentResult carries Communication Units between agents. - Graceful shutdown — 3-phase escalation: cancel → wait → force-mark.
AgentHandle
dataclass
¶
Mutable runtime state for a single agent — lives in the hypervisor.
Created when an agent registers and updated throughout its lifecycle. Fields are read by the CLI agent tree display and the hypervisor's query/cancellation methods.
Handle starts as submitted, transitions to
running when the loop begins, then to a terminal state.
last_step_at enables tool-call-granularity
stall detection without destroying accumulated context.
message_queue enables bidirectional
adaptive coordination — the hypervisor injects NL feedback.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
342 343 344 345 346 347 348 349 350 351 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 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
AgentHypervisor
¶
Hypervisor control plane — manages the full agent tree for a session.
Thread-safe via asyncio.Lock. A single instance is shared across all
agents in the hierarchy through AgentContext.registry.
Responsibilities
- Admission control:
accept()/accept_batch()/release()gate concurrency through an injected :class:AgentQueue(default 20 running slots) that QUEUES over-cap work instead of dropping it. - Registration:
register()/unregister()track agent handles keyed byagent_id. - Status:
update_step()/mark_done()record execution progress and terminal state. - Queries:
list_children()/list_descendants()/list_all()expose the live tree for display and introspection. - Cancellation:
cancel_agent()cancels a single agent;cleanup()tears down the entire tree on session exit.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 | |
free_slots: int
property
¶
Slots a spawn could be dispatched into right now.
pending_dispatch: int
property
¶
Accepted spawns not yet started.
NOT a status: those agents are submitted like any other, and this
is only the scheduler's count of how many are still waiting on a slot.
total_steps: int
property
¶
Total tool steps executed across all agents in the session.
__init__(*, max_concurrent: int = 20, session_step_budget: int = 0, attestation: AttestationChain | None = None, queue: AgentQueue | None = None) -> None
¶
Initialize hypervisor with concurrency and budget limits.
Session-wide budget with graduated enforcement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_concurrent
|
int
|
Maximum number of concurrently RUNNING agents. |
20
|
session_step_budget
|
int
|
Total tool steps allowed across all agents in the session. 0 means unlimited. |
0
|
attestation
|
AttestationChain | None
|
optional provenance hash chain for
this session's agent tree. The hypervisor never constructs one
itself (it has no session_id, no store) — the orchestrator
injects it, seeded from the store's last persisted record, when
the feature is config-enabled. |
None
|
queue
|
AgentQueue | None
|
the admission scheduler. Injected so a deployment (or a
test) can seat a differently-sized or differently-ordered one
without the hypervisor learning how scheduling works; the
default is an :class: |
None
|
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | |
accept(unit: SpawnUnit) -> bool
async
¶
Admit ONE spawn: True = dispatched now, False = deferred.
Never refuses for capacity — that is the whole point of the queue.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
721 722 723 724 725 726 | |
accept_batch(units: Sequence[SpawnUnit]) -> list[bool]
async
¶
Admit a whole fan-out at once — see :meth:AgentQueue.accept_batch.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
728 729 730 | |
agent_step_state(agent_id: str) -> str
async
¶
Per-contract step-budget state for one agent.
"ok" for an unregistered agent or one whose contract carries no
step bound — the same inert default as a disabled contract.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
948 949 950 951 952 953 954 955 956 957 958 | |
agent_token_state(agent_id: str) -> str
async
¶
Per-contract advisory token state for one agent.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
960 961 962 963 964 965 966 | |
budget_exhausted() -> bool
¶
Check if the session step budget is exhausted (0 = unlimited).
Graduated enforcement — this is the trigger check. The response (NL warning injection) happens in ToolUseLoop.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
912 913 914 915 916 917 918 | |
budget_remaining() -> int
¶
Steps remaining in the session budget (0 = unlimited).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
920 921 922 923 924 | |
budget_warning(*, headroom: int = 5) -> bool
¶
True when within headroom steps of the session budget (0 = off).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
926 927 928 929 930 | |
cancel_agent(agent_id: str) -> str | None
async
¶
Cancel an agent, whether it has started or is still waiting for a slot.
Returns None on success, or a diagnostic string on failure.
The waiting case is checked FIRST and it is not an optimization.
asyncio_task is populated by the child driver, which runs only
AFTER dispatch — so a capacity-deferred agent has no task, the
task-cancellation path reported no asyncio task, and the agent then
STARTED anyway the moment a sibling freed a slot. Refusing to cancel
something and then running it is the worst of both answers, and it is
reachable the instant a fan-out exceeds the concurrency limit.
Dropping it from the scheduler is what makes the cancel real.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 | |
cancel_pending() -> list[str]
async
¶
Drop every accepted-but-undispatched spawn, settling each as cancelled.
A waiting agent holds no slot and owns no asyncio.Task, so neither
cancel_agent nor the cleanup sweep's task cancellation can reach
it — it would sit submitted forever and read as live. Returns the
ids dropped. Called before teardown so a manager settling on the way
out cannot pump a brand-new child into a run that is already ending.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | |
cleanup(timeout: float = 5.0) -> None
async
¶
Cancel all agents with graceful escalation.
Requests cancellation on all active asyncio tasks, waits up to timeout seconds for them to finish, then force-marks any still pending as cancelled.
Covers every :data:ACTIVE_STATUSES agent, not just running: one
still at submitted never had a loop task to cancel — and one still
waiting for a slot never had a task at all — which is exactly why
either would otherwise survive shutdown unmarked. Waiting units are
dropped from the scheduler FIRST, so a manager settling during the
wait window cannot pump a fresh child into a hypervisor that is being
torn down.
Marking here is deliberately IN-MEMORY only — the hypervisor holds no event logger, and wiring one in would invert the layering (the session owns the transcript, the hypervisor owns the tree). The durable terminal is written by whichever peer can still reach the log:
- While the task is still alive (during the request or the wait):
cancelling it raises
CancelledErrorinside the agent's own lifecycle handler, which writes the terminalstopbefore unwinding. That is the normal path. - Once the wait times out, at the final force-mark sweep (the task is wedged, or the process is being torn down mid-flight): nothing in-process can still write, so the durable terminal comes from the startup sweep on the NEXT boot, which settles agent spans left open under a run that has since ended.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 | |
collect_completed(parent_id: str) -> list[AgentHandle]
async
¶
Return children that reached a terminal state with a stored result.
Async CU retrieval — parent reads results when ready, not when child finishes.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 | |
collect_running(parent_id: str) -> list[AgentHandle]
async
¶
Return children of parent_id that are still active.
Reads :data:ACTIVE_STATUSES rather than re-listing the states. That
matters beyond tidiness: this method is the promise-as-completion
gate's ownership index AND what check_agents reports, so a
capacity-deferred child — submitted, registered, not yet started —
must appear here. A refused unit was registered nowhere, which is
exactly why a parent that over-subscribed the fleet was told all its
work was done.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 | |
get(agent_id: str) -> AgentHandle | None
async
¶
Return a single agent handle, or None.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
870 871 872 873 | |
list_all() -> list[AgentHandle]
async
¶
Full tree view — for CLI/API user visibility.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
893 894 895 896 | |
list_children(parent_id: str) -> list[AgentHandle]
async
¶
List direct children of a parent. Enforces isolation.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
875 876 877 878 | |
list_descendants(ancestor_id: str) -> list[AgentHandle]
async
¶
List all descendants recursively.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
880 881 882 883 884 885 886 887 888 889 890 891 | |
list_visible(exclude_agent_id: str | None = None) -> list[AgentHandle]
async
¶
Snapshot of agents excluding the caller — used by check_agents.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
898 899 900 901 | |
mark_done(agent_id: str, status: AgentStatus, error: str | AgentError | None = None) -> None
async
¶
Mark an agent as done with a terminal status.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
mark_tool_start(agent_id: str, tool_id: str | None) -> None
async
¶
Stamp (or clear) the tool actually in flight for stall attribution.
update_step only stamps last_tool_id on
COMPLETION, so a watchdog check firing mid-call would misattribute the
stall to the previous, already-finished tool. Call this at dispatch
start with the tool name, and again with None once the call
resolves (success, timeout, or exception) so active_tool_id never
lingers stale once the agent moves on.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 | |
over_wall_deadline_agents(now: float | None = None) -> list[tuple[AgentHandle, str]]
async
¶
Running agents whose contract wall-clock deadline is warn/over.
Mirrors :meth:stalled_agents — a per-contract cousin of the stall
sweep, keyed on started_at rather than last-progress. now
arrives as a clock ARG (never read internally), so a caller can drive
this deterministically without sleeping a real clock.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |
record_compaction(agent_id: str) -> None
async
¶
Record that an agent compacted its context.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1031 1032 1033 1034 1035 1036 1037 | |
register(handle: AgentHandle) -> None
async
¶
Register a new agent in the hypervisor.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
803 804 805 806 | |
release() -> None
async
¶
Settle one running agent's slot, dispatching whatever waits on it.
Async because it is the DISPATCH PUMP, not a bare counter decrement:
the freed slot is handed to the next waiting unit, which means starting
it. This is deliberately the completion path every settling agent
already calls, and exactly-once is already guaranteed there — a pump
hung off on_agent_stop instead would fire while the slot is still
held and find the queue full every time.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
732 733 734 735 736 737 738 739 740 741 742 | |
render_agent_tree(*, exclude_agent_id: str | None = None) -> str
async
¶
Render a concise text summary of the agent tree for the root's system prompt.
Structural transparency — the root agent (the hypervisor's "brain") gets a live view of all agents so it can reason about the delegation state and intervene if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclude_agent_id
|
str | None
|
If provided, omit this agent from the rendered tree. Used so the calling agent does not see itself listed. |
None
|
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
send_message(agent_id: str, message: str) -> str | None
async
¶
Send a steering message to a running agent.
Returns None on success, or a diagnostic string on failure.
Adaptive coordination — the hypervisor injects NL feedback (budget warnings, stall nudges) into the agent's message queue. The ToolUseLoop drains this queue between steps. Bidirectional system↔agent feedback loop.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
send_to_parent(child_agent_id: str, message: str) -> str | None
async
¶
Route a message from a child agent to its parent's queue.
Returns None on success, or a diagnostic string on failure.
Bidirectional message passing — enables lifecycle manager to notify parent on child completion.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 | |
stalled_agents(threshold: float = 120.0) -> list[AgentHandle]
async
¶
Return agents not making progress within threshold seconds.
Internal trigger: delegatee unresponsive → diagnose → evaluate → intervene.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
unregister(agent_id: str) -> AgentHandle | None
async
¶
Remove an agent from the hypervisor.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
808 809 810 811 812 813 814 815 | |
update_step(agent_id: str, tool_id: str) -> None
async
¶
Record a completed tool execution step.
Track at tool-call granularity, not agent granularity. Updates last_step_at for stall detection and total_steps for session budget enforcement.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
AgentQueue
¶
Admission scheduler — bounds concurrency WITHOUT dropping work.
Admission is not a two-outcome question. Take-a-slot-or-be-refused makes "the fleet is busy" indistinguishable from "this task was impossible", and silently loses a wide fan-out's surplus. There is a third answer, and it is the one a scheduler owes its caller: accept now, dispatch later.
THE LAW: waiting is free; only RUNNING consumes a slot. A unit sitting
in :attr:waiting holds nothing, so a parent blocked on a child can never
be part of a capacity cycle — which is what makes deferred admission safe
here where it would otherwise deadlock a tree of nested delegations.
Note the vocabulary: units here are waiting or dispatched, never
"queued". The agent-facing lifecycle has no such state, and it must not
grow one — a waiting unit is submitted like any other accepted agent.
No lock, and none is needed: every capacity decision below is a synchronous read-modify-write on the event-loop thread, with awaits confined to the launch calls that follow them. Bounded concurrency is enforcement, and enforcement that discards work is not graduated, it is a kill.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 | |
capacity: int
property
¶
Maximum number of simultaneously RUNNING agents.
free_slots: int
property
¶
Slots a unit could be dispatched into right now.
running: int
property
¶
Units dispatched and not yet settled.
waiting: int
property
¶
Units accepted and waiting for a slot.
__init__(*, capacity: int = 20) -> None
¶
Initialize with the number of agents that may RUN at once.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
497 498 499 500 501 502 503 504 505 506 507 508 | |
accept(unit: SpawnUnit) -> bool
async
¶
Accept ONE unit. True = dispatched now, False = deferred.
Never refuses — see :meth:accept_batch, whose single-entry case this
is (one implementation, so a single spawn and a batch entry can never
be admitted under different rules).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
530 531 532 533 534 535 536 537 | |
accept_batch(units: Sequence[SpawnUnit]) -> list[bool]
async
¶
Accept EVERY unit; dispatch what fits, queue the rest.
Returns one flag per unit, positionally aligned: True dispatched,
False deferred. Atomic in acceptance, staggered in dispatch — the
capacity decisions run as one synchronous pass with no await between
them, so a settle landing mid-batch can only add dispatches and can
never split the batch or refuse part of it. Every unit is accepted
either way; the return value says only which ones started immediately.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | |
clear() -> list[ScheduledSpawn]
¶
Drop every waiting unit, returning the records so a caller settles them.
A waiting unit holds no slot and owns no task, so nothing else can end
it: teardown has to reach in here or those agents stay submitted
forever and read as live to every liveness consumer.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
614 615 616 617 618 619 620 621 622 623 | |
discard(agent_id: str) -> ScheduledSpawn | None
¶
Remove ONE waiting unit, returning its record — None if not waiting.
The cancellation seam for a unit that has not been dispatched. Such a
unit owns no asyncio.Task, so task cancellation cannot touch it and
it would otherwise start minutes later on a slot a sibling freed —
after its canceller was told the cancel had failed.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
601 602 603 604 605 606 607 608 609 610 611 612 | |
release() -> None
async
¶
Settle one dispatched unit — and pump the queue. THE DISPATCH PUMP.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
573 574 575 | |
AgentResult
dataclass
¶
Structured result from a sub-agent — the Communication Unit.
Each agent produces a CU that grows with relevant info
and drops irrelevant content, preventing context explosion in chains.
cannot_solve status enables explicit failure
admission as a first-class outcome, saving downstream waste.
summary serves as a checkpoint
snapshot — even on failure, partial work survives for retry.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
DelegationContract
dataclass
¶
Per-spawn delegation bounds a caller can put on ONE child.
Every field's zero/off value leaves the child unbounded, so a spawn that
never declares a contract is constrained by nothing here — this is an
opt-in ceiling, never a default constraint. Distinct from the
hypervisor's SESSION-wide session_step_budget: that is a shared pool
across the whole agent tree; this is one caller's bound on one child,
checked in addition to (never instead of) the session budget.
Privilege attenuation — autonomy is
the hard delegation firebreak (an atomic child can never itself spawn,
and the bit only ever narrows down the tree, see AgentContext.child).
Graduated enforcement — step_state/
wall_state/token_state each expose a warn tier before the hard
stop, mirroring the session budget's own warn-then-halt shape.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 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 | |
atomic: bool
property
¶
True when this contract strips the child's own delegation rights.
enabled: bool
property
¶
True when the contract carries at least one real constraint.
from_value(value: object) -> DelegationContract
classmethod
¶
Parse + validate the schema contract object. Unset/invalid → OFF.
Validation is total (never raises), mirroring RetryPolicy.from_value:
a malformed field degrades to the safe default rather than failing a
spawn, since contract is an optional caller-declared ceiling, not a
correctness contract. Unknown keys are dropped after ONE warning per
parse (never per-key) so a typo'd field doesn't spam the log.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 | |
resolve_model_override(explicit: str | None, tier_map: Mapping[str, str], allowed: Any = None) -> str | None
¶
Resolve model_tier against a deployment's tier→model map.
Returns None (fall through to the caller's existing resolution)
when: an explicit model was already given (it always wins — this
is the LOWEST-priority model source); no model_tier is declared;
the tier has no map entry; or the mapped model is excluded by
allowed (when non-empty). Otherwise returns the mapped model id.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
snapshot() -> dict[str, Any]
¶
Bounded-scalar serialization.
The ONE shared shape read by check_agents and by attestation
provenance.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
333 334 335 336 337 338 339 | |
step_state(steps_completed: int) -> Literal['ok', 'warn', 'over']
¶
Graduated step-budget state — ok when unset (0 = unlimited).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
274 275 276 277 278 279 280 281 282 | |
token_state(total_tokens: int) -> Literal['ok', 'warn', 'over']
¶
Feature-detected advisory token state — best-effort, never a hard promise.
total_tokens <= 0 means the caller has no usage signal at all (a
model/proxy that never surfaced usage_metadata), so absence of
data reads as ok, never over — the same feature-detection
posture as _UsageNormalizingLiteLLM. Likewise a contract with no
max_tokens declared is always ok: this axis is advisory only,
cost accounting is out of scope.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
294 295 296 297 298 299 300 301 302 303 304 305 306 | |
wall_state(elapsed_s: float) -> Literal['ok', 'warn', 'over']
¶
Graduated wall-clock state — warn at 80%, over at 100% of the bound.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
284 285 286 287 288 289 290 291 292 | |
ScheduledSpawn
¶
Bases: BaseModel
One accepted sub-agent, as the admission scheduler sees it.
The agent_id is minted at ACCEPTANCE, not at dispatch: a unit waiting
for a slot is already a real agent, registered and submitted, which is
what lets collect_running and check_agents see it and what makes
"accepted" a promise the scheduler must keep rather than a hope. A refused
unit registered nowhere at all would leave a parent asking
check_agents(wait=true) told everything was done — that blindness, not
the refusal itself, is what makes a loss silent.
Ordering lives ON the record (:meth:ordering_key) rather than in a
comparator beside the queue — a scheduling policy kept apart from the data
it orders drifts from it the moment a field is added, the same reason
TriggerSpec owns its own due-ness. Clocks arrive as VALUES too:
enqueued_at is stamped by the caller that owns one and
:meth:waited_for takes now as an argument, so nothing here reads a
clock and a test needs no patching to drive it.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
ordering_key() -> tuple[int, float, int]
¶
Sort key: priority first, then arrival, then declared batch order.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
451 452 453 454 | |
waited_for(now: float) -> float
¶
Seconds spent waiting, measured against a caller-supplied clock.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
456 457 458 | |
SpawnUnit
dataclass
¶
A scheduled spawn paired with the callable that starts it.
The record is a validated contract; the launcher is a live closure over
in-process spawn state that crosses no trust boundary — the same split the
package already draws between a persisted spec and a hot RunHandle.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
461 462 463 464 465 466 467 468 469 470 471 | |
mewbo_core.agents.spawn_agent
¶
Sub-agent spawning tool for the agent hypervisor.
SpawnAgentTool creates a child ToolUseLoop instance, registers it
in the AgentHypervisor, runs it to completion, and returns the result.
Tool scoping follows the "filter before binding" pattern: denied
tools are removed from the child's bind_tools() list so the child LLM
never sees them.
AgentError
dataclass
¶
Structured error context from a failed sub-agent.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
ChildWorkspace
dataclass
¶
The directory ONE child runs in, paired with the rules that govern it.
The two are ONE fact, so they travel as one value: a child pointed at another project must read THAT project's instruction files, and a pair free to drift is how a fleet ends up working in one repository under another's rules — a miss that produces plausible work rather than an error.
Resolved ONCE per spawn, at admission, rather than read off the tool at each
attempt: :meth:SpawnAgentTool.rebind_cwd may move the workspace between a
child's retry attempts, and a child must finish where it started.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
RetryPolicy
dataclass
¶
Bounded auto-retry / re-delegation policy for a spawned sub-agent.
Opt-in via the retry spawn-schema field; DEFAULT OFF (max == 0)
so an unset/absent retry runs the child exactly once. On a retryable
terminal failure the spawn bridge
re-delegates the same task on the same handle (retaining the one already
held semaphore slot for the whole sequence) up to max extra attempts,
sleeping :meth:backoff_for with exponential growth between them.
Model-level causes are deliberately NOT re-escalated here: every child
ToolUseLoop run already drives the fallback ladder internally, so a
fresh attempt gets a fresh ladder — this layer only re-runs a whole child
whose loop died. rejected (declined at admission, before the loop) and
cancelled (parent-cancelled → CancelledError, re-raised, never
retried) are structurally unreachable by the retry loop.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
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 350 351 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 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
enabled: bool
property
¶
True when at least one retry is permitted.
backoff_for(attempt: int) -> float
¶
Exponential backoff (seconds) before the next attempt.
attempt is the failed attempt's index (1-based), so the first retry
waits backoff, the second 2 * backoff, etc.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
393 394 395 396 397 398 399 | |
classify_cause(exc: BaseException) -> str
staticmethod
¶
Map a child-loop exception to a coarse retry cause.
Reuses the RetryStrategy classifier's reason taxonomy (DRY — the
delegation layer never re-derives provider/timeout semantics): a
timeout/deadline-flavoured failure is "timeout"; everything else
(transient or otherwise) collapses to the generic "failed".
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
from_value(value: object) -> RetryPolicy
classmethod
¶
Parse + validate the schema retry object. Unset/invalid → OFF.
Validation is total (never raises): a malformed field degrades to the
safe default rather than failing a spawn, since retry is an optional
resilience hint, not a correctness contract.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
351 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 | |
should_retry(cause: str, attempt: int) -> bool
¶
True when another attempt is allowed for this failure cause.
attempt is the number of attempts made so far (the one that just
failed). Total attempts are bounded at max + 1.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
385 386 387 388 389 390 391 | |
SpawnAgentTask
¶
Bases: BaseModel
One entry in a spawn_agents batch.
Carries the SAME per-task fields as the single spawn_agent schema, but
validated at definition: extra="forbid" rejects stray keys so a
malformed fan-out fails fast instead of silently dropping a field, and a
blank task is refused (an empty delegation is never intentional).
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
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 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 | |
to_args() -> dict[str, Any]
¶
Project to the args dict the single-spawn path consumes.
Unset (None) fields are dropped so the downstream args.get(...)
defaults apply exactly as they do for an ad-hoc spawn_agent call —
keeping the batch a thin reuse of _spawn_one rather than a fork.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
189 190 191 192 193 194 195 196 | |
SpawnAgentTool
¶
Spawns a child ToolUseLoop as a sub-agent.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 | |
__init__(*, agent_context: AgentContext, tool_registry: ToolRegistry, permission_policy: PermissionPolicy, approval_callback: Callable[[ActionStep], bool] | None = None, hook_manager: HookManager, safety_plane: SafetyPlane | None = None, project_instructions: str | None = None, user_instructions: str | None = None, cwd: str | None = None, agent_registry: Any = None, session_tool_registry: SessionToolRegistry | None = None, session_capabilities: tuple[str, ...] = (), enable_skills: bool = True, catalog: ProjectCatalog | None = None) -> None
¶
Initialize with parent context and shared registries.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 | |
await_lifecycle_managers(timeout: float = 3.0) -> None
async
¶
Settle every background lifecycle manager before the run tears down.
Called from ToolUseLoop.run()'s finally block. Collect-or-cancel:
managers get timeout to finish on their own, then the stragglers are
cancelled — and, crucially, AWAITED.
Cancelling without awaiting is what leaked children. cancel() only
schedules the CancelledError; the handler that marks the child done
and writes its ONE terminal stop runs on a later turn of the event
loop, which never comes if the loop tears down first. The child was then
settled by nothing in this process — its span stayed open until a boot
sweep reaped it days later, or forever. Awaiting here is what makes
settlement in-process rather than next-boot.
Exceptions are swallowed by return_exceptions: these tasks own their
own terminal reporting, and a manager that fails while being torn down
must not take down the run that is already ending.
The set to await is not fixed at entry. Every manager that settles hands its slot to a QUEUED child through the dispatch pump, which creates a new manager — so this DRAINS in rounds against one deadline rather than awaiting a snapshot. Cancelling waiting units up front would be the simpler code and the wrong behaviour: it would discard, at teardown, exactly the work this scheduler exists to stop discarding. Only once the budget is spent are the still-waiting units dropped — after that nothing will ever dispatch them, so they must be settled rather than left reading as live.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 | |
handle_check_agents(action_step: ActionStep) -> MockSpeaker
async
¶
Return agent tree state with completed results and progress.
Emits a JSON payload with kind: "agent_tree". The text field
carries the rendered ASCII tree the LLM consumes; the agents list
is the structured snapshot the console uses to render CheckAgentsCard.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 | |
handle_steer_agent(action_step: ActionStep) -> MockSpeaker
async
¶
Send a steering message to or cancel a running agent.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 | |
has_live_owned_runs() -> bool
async
¶
True while any agent this session owns is still non-terminal.
The ownership index behind the promise-as-completion gate: a clean terminal declared while owned work is live is a promise, not a completion. Exposed here because the hypervisor is the only thing that knows, and the seam that must ask is the one accepting a completion claim.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 | |
rebind_active_model(model_name: str) -> None
¶
Re-seat this tool's parent context onto an escalated model.
The public seam for the loop's sticky model escalation. A parent that
healed itself onto a rescue model must not keep spawning children onto
the dead one: :meth:_resolve_model falls back to the parent context's
model_name, and each child's own context is derived from it, so a
stale value here re-infects the whole subtree.
AgentContext is frozen, so this REPLACES rather than mutates — and
that is exactly why the seam is a method and not an attribute write.
Knowing the context is a frozen dataclass is this class's business, not
the loop's; reaching in to do the replace from outside couples the
caller to a representation it should never have to know. Idempotent, so
the loop may call it on every turn.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 | |
rebind_cwd(cwd: str, *, project_instructions: str | None) -> None
¶
Re-point the workspace every FUTURE child inherits.
The seam a session-level project switch drives: from here on, a spawn
that names no project of its own lands in cwd and reads
project_instructions instead of the ones this tool was built with.
Already-running children are deliberately untouched. A live child's loop
captured its own directory when it was built and has been resolving
paths against it ever since; moving that out from under it would be a
race no one owns — its containment root, its verifier's working
directory and its half-finished edits would disagree about where it is.
A child finishes where it started; the switch applies to the next one.
That is also why a spawn resolves its :class:ChildWorkspace once at
admission rather than re-reading these fields on each retry attempt.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 | |
run_async(action_step: ActionStep) -> MockSpeaker
async
¶
Execute a single sub-agent. Returns the result as a MockSpeaker.
Thin wrapper over :meth:_spawn_one — the batch path
(:meth:run_batch_async) shares the same core. The outcome is
projected through :meth:_SpawnOutcome.report, not read off
content: reading the string would throw away the refusal's status
and typed cause, handing the model a bare sentence for five different
failures.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 | |
run_batch_async(action_step: ActionStep) -> MockSpeaker
async
¶
Fan out a batch of independent sub-agents from ONE tool call.
Pure composition over :meth:_spawn_one, in two phases. Each entry is
RESOLVED first (its workspace, agent type and model settled, its handle
registered, its id minted), then the whole batch is handed to the
scheduler in ONE atomic acceptance: every entry that resolved is
accepted, and the scheduler decides only which start now and which
wait. A batch is therefore throttled by concurrency, never truncated by
it. Marking the surplus rejected and discarding it would read to
the caller as N agents when only max_concurrent existed.
Returns the ordered agent_ids; the model collects results via the
existing check_agents. The orchestration loop is untouched.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 | |
substitute_agent_body(body: str, subs: Mapping[str, str], env: Mapping[str, str] | None = None) -> str
staticmethod
¶
Render an agent's body with plugin-generic variable substitution.
Three passes, in order:
${KEY}literal substitution from subs. Core passesSESSION_IDandCLAUDE_PLUGIN_ROOT; plugins author their prompts against these names.- Bash-style
${VAR:-default}— ifVARis unset in env, the text expands todefault. IfVARis set, it expands to the env value. This keeps plugin prompts self-documenting (operator override path is obvious in the source). - Plain
$VARexpansion as a final pass, matching :func:os.path.expandvarssemantics. Unset variables remain literal so authors can spot typos at glance.
A staticmethod on this class rather than a loose module function:
this tool is the only production caller, and subs/env arrive as
ARGS so the renderer stays testable with a fake environment. The
module-level substitute_agent_body name is a thin alias over it, so
the import path plugins and tests already use is unchanged.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 | |
mewbo_core.loop.planning
¶
Prompt construction and planning helpers.
Planner
¶
Generate action plans via LLM.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 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 | |
__init__(tool_registry: ToolRegistry | None) -> None
¶
Initialize the planner.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
181 182 183 184 | |
generate(user_query: str, model_name: str, context: ContextSnapshot | None = None, *, tool_specs: list[ToolSpec] | None = None, mode: str = 'act', feedback: str | None = None, project_instructions: str | None = None) -> Plan
¶
Generate a plan from the user query.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
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 240 241 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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
PromptBuilder
¶
Build system prompts with contextual sections.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
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 166 167 168 169 170 171 172 173 174 175 | |
__init__(tool_registry: ToolRegistry | None) -> None
¶
Initialize prompt builder dependencies.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
91 92 93 | |
build(base_prompt: str, context: ContextSnapshot | None, component_status: Iterable[ComponentStatus] | None = None, *, mode: str = 'act', tool_specs=None, include_tool_guidance: bool = True, project_instructions: str | None = None) -> str
¶
Build an augmented system prompt string.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
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 | |
mewbo_core.loop.session_runtime
¶
Shared session runtime utilities for CLI and API.
GoalRetryGate
¶
Re-invoke a session ONCE when it ended without meeting its stated goal.
The escalation that begins where the in-band gates stop. A run that claims a
clean terminal while a declared obligation is unmet is nudged inside the
turn, with the context still warm and bounded to three attempts; that is
strictly the cheaper correction and it stays the first line. This gate is
what remains when the nudges are spent and the session has already ended
unmet_goal — the case a human otherwise fixes by clicking Continue,
which routinely produces the missing result in ONE further step.
Exactly one automatic attempt, ever. The ledger is the recovery
transcript event the recovery path already writes: this gate stamps it with
trigger="auto_goal_unmet", and refuses whenever a marker carrying that
trigger is already present. Durable, restart-proof, and no new store field.
Cost ceiling — state it plainly, because nothing else in the system bounds a
session's token spend (TokenBudget is compaction accounting, not a wallet):
one additional run per session, whose own cost is bounded only by that
run's step/wall budget. Worst case a session costs twice what it otherwise
would. That is the entire price, and it cannot compound: the second run's
terminal reaches this gate too, finds its own marker, and refuses.
action="continue" is load-bearing, not a preference. retry truncates
the transcript back past the failed turn, which would delete the marker and
make the one-shot guard structurally impossible to enforce.
Cost class: O(one record) — one digest fold plus one transcript read for
the marker scan, on a terminal path, once per run.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 523 524 525 526 527 528 529 530 | |
__init__(*, runtime: SessionRuntime) -> None
¶
Bind the gate to the runtime that owns the session it re-drives.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
413 414 415 | |
maybe_retry(session_id: str, relaunch: Callable[[str], str]) -> bool
¶
Re-drive session_id once if its run ended with an unmet goal.
relaunch starts a fresh run on the session with the given query,
carrying the ORIGINAL run's collaborators (tool registry, hooks,
capability mode, cwd …) unchanged, and returns its run id — "" when
the registry refused. Returns True only when a retry was actually
started.
Total by construction: a best-effort correction must never break the completion of the run that triggered it, so every failure is logged and swallowed. It is called from the run's own thread after that run's registry slot has been released.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
RunHandle
dataclass
¶
Active orchestration tracking.
A run is backed by EITHER a daemon thread (CPython sync-wrapper path) or an
event-loop task (Pyodide WebLoop / async harnesses). Exactly one of
thread / loop_active reflects liveness; every other field applies
uniformly. is_alive() is the backend-agnostic liveness check.
task holds the loop-backed run's asyncio.Task (mirrors
AgentHandle.asyncio_task in hypervisor.py / _lifecycle_tasks in
spawn_agent.py): register_loop_run mints the handle before the
coroutine exists, so task starts None and is attached via
:meth:RunRegistry.attach_loop_task right after loop.create_task(...).
Holding this strong reference on the registry-owned handle is what keeps
asyncio from garbage-collecting the fire-and-forget task mid-run — a bare
local task = loop.create_task(...) with no held reference is eligible
for GC as soon as the enclosing function returns.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
is_alive() -> bool
¶
Return whether the underlying run is still in progress.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
196 197 198 199 200 | |
RunRegistry
¶
Track active orchestration runs (thread- or loop-backed) per session.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.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 240 241 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 275 276 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 350 351 352 353 | |
__init__() -> None
¶
Initialize the run registry.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
206 207 208 209 | |
attach_loop_task(session_id: str, task: asyncio.Task) -> None
¶
Attach a loop-backed run's asyncio.Task to its handle.
register_loop_run reserves the run's slot before the coroutine —
and thus the task — exists, so the task is attached here right after
the caller's loop.create_task(...). From that point on the
registry (via the handle) holds a strong reference for the run's
lifetime, preventing the fire-and-forget task from being garbage
collected mid-run. A no-op if the handle is already gone (e.g. the
task finished and its done-callback finalized the run before this
call — not expected in practice but harmless).
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
cancel(session_id: str) -> bool
¶
Request cancellation for an active session run.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
329 330 331 332 333 334 335 336 | |
finalize_loop_run(session_id: str) -> None
¶
Mark a loop-backed run as completed and drop its handle.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
294 295 296 297 298 299 | |
get_cancel_event(session_id: str) -> threading.Event | None
¶
Return the cancel event for a session, if present.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
344 345 346 347 348 | |
get_handle(session_id: str) -> RunHandle | None
¶
Return the run handle for a session, if present.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
350 351 352 353 | |
is_running(session_id: str) -> bool
¶
Return True if the session has an active run.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
338 339 340 341 342 | |
register_loop_run(session_id: str, *, cancel_event: threading.Event, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None) -> bool
¶
Register a loop-backed run (no thread). Mirror of :meth:start.
Used when the caller is already inside a running event loop (Pyodide's
WebLoop) and drives the orchestration as an asyncio task rather than
a daemon thread. Returns False if a live run already exists for the
session. The caller must invoke :meth:finalize_loop_run from the
task's done-callback so the registry stays consistent.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 275 | |
start(session_id: str, target: Callable[[threading.Event], None], *, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, on_release: Callable[[], None] | None = None) -> bool
¶
Start a new thread-backed run for the session if not already active.
on_release fires once, on the run's own thread, AFTER the handle has
been dropped — so the session's slot is genuinely free and a callback
may start a follow-up run on it. Firing it any earlier (from the run's
own finally, say) cannot work: this registry still holds the slot
there, so a same-session start_async refuses and returns "".
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 240 241 242 243 244 245 246 | |
SessionRuntime
¶
Shared orchestration runtime surface for CLI and API.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 | |
session_store: SessionStoreBase
property
¶
Expose the underlying session store.
__init__(*, session_store: SessionStoreBase | None = None, run_registry: RunRegistry | None = None, goal_retry_gate: GoalRetryGate | None = None) -> None
¶
Initialize the runtime with session storage and optional run registry.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
active_run_handle(session_id: str) -> RunHandle | None
¶
The live :class:RunHandle for session_id, if a run is active.
Read-only steering-signal access for in-run collaborators — the
ask-user question dispatcher polls the handle's cancel_event /
interrupt_step / message_queue while blocked so a steer or
interrupt supersedes a pending question instead of deadlocking behind
it. Callers must treat the handle as read-only.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 | |
append_context_event(session_id: str, context: dict[str, object]) -> None
¶
Append a context event to the session transcript.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
615 616 617 618 619 | |
append_event(session_id: str, event: dict[str, object]) -> None
¶
Append a raw transcript event verbatim.
Unlike :meth:append_context_event (which wraps payloads as
{"type": "context", ...}), this writes the event as-is, so a
completion event reaches :meth:summarize_session — the single
status authority — instead of being hidden inside a context payload.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
632 633 634 635 636 637 638 639 640 | |
approve_plan(session_id: str) -> bool
¶
Approve a pending plan proposal episodically.
Emits a plan_approved event to the transcript. Does NOT start
a new run — the caller (API endpoint) is responsible for starting
the act-mode run via start_async.
Returns False if no pending plan proposal exists or a run is already active.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 | |
arun(*, user_query: str, session_id: str, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, max_iters: int = 3, initial_plan: Plan | None = None, tool_registry=None, permission_policy=None, approval_callback=None, hook_manager=None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, cwd: str | None = None, session_step_budget: int = 0, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False, session_mcp_servers: dict[str, dict] | None = None) -> TaskQueue
async
¶
Run an orchestration request inside an existing event loop.
Async counterpart of :meth:run_sync. Use this when the caller is
itself a coroutine (e.g. an in-browser Flask handler running on
Pyodide's WebLoop) so the orchestration can await without
asyncio.run. Same signature and semantics as :meth:run_sync.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 | |
cancel(session_id: str) -> bool
¶
Cancel an active run if present.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1560 1561 1562 | |
enqueue_message(session_id: str, text: str) -> bool
¶
Enqueue a steering message for the root agent of a running session.
The message is also persisted as a "user" event so it appears in
the session transcript (console timeline, CLI history, Langfuse).
Returns False if no active run or no message queue.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 | |
ensure_session(session_id: str) -> None
¶
Idempotently materialise a session record for a pre-minted id.
Thin delegate to the store's ensure_session. A caller that minted a
session_id outside resolve_session (e.g. the realtime recorder,
which pre-mints to open a Langfuse trace before any store write) calls
this so the session is a real RECORD — visible to list_sessions and
every read surface — not an orphan transcript.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
604 605 606 607 608 609 610 611 612 613 | |
interrupt_step(session_id: str) -> bool
¶
Interrupt the current tool execution step.
The loop continues after the interrupted step with error results. Returns False if no active run or no interrupt event.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 | |
is_running(session_id: str) -> bool
¶
Return True if session has an active run.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1564 1565 1566 | |
is_terminated(session_id: str) -> bool
¶
Return True iff the session was permanently terminated.
The ONE choke point every entry-point guard reads — a thin read-through
to the store so there is zero duplicated status derivation. An unknown
session reads False (no stamp).
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1579 1580 1581 1582 1583 1584 1585 1586 | |
list_sessions(query: SessionQuery | None = None, *, limit: int | None = None, offset: int = 0) -> list[dict[str, object]]
¶
List sessions with summary metadata, narrowed by query.
O(collection) in rows, and never O(all history) in reads. TWO
batched store calls serve the whole page, and neither scales with how
much any session has recorded:
- :meth:
~SessionStoreBase.list_session_digestsreturns each session's transcript reduced to the events a summary folds. A per-idload_transcripthere would make a listing read every event ever stored, and degrade monotonically forever. load_session_recordsreturns the metadata that is stored ON the session rather than folded from events (title, archived, terminated, owner, tags,pinned_at,projects) in one call for the page instead of per-row reads.
query narrows the digest fetch itself, and that ORDER is what makes
it compose with a page. The whole query goes to
list_session_digests (still called EXACTLY ONCE per listing, which a
test pins), so every predicate answerable from the session record —
owner/archived/pinned/projects — is applied by the store
before it decides which candidates to page, and a session the query
rejects is never opened. Filtering afterwards instead would be worse
than merely slower once limit exists: paging first and filtering the
page would make pinned=True return only the pinned sessions inside
the newest N candidates, which is usually none of them.
The fold itself is unchanged and still single-sourced.
summarize_session sees a smaller event list, not a different
derivation — re-deriving a row's fields with a store-side aggregation
would be a second implementation, free to drift until a row disagrees
with the session it names.
limit/offset bound how many CANDIDATES this call examines, not
how many rows it is guaranteed to return. They page
list_session_digests after query has narrowed the candidate set but
before the two VISIBILITY rules below run, which is what lets a
Mongo-backed store scope its expensive read to the page instead of the
whole collection (see that method's docstring for the measured saving) —
but a candidate dropped below (no visible event and not running, or no
created_at) shrinks the page rather than being backfilled from the
next one. Those two rules stay here because they are the only ones that
need the transcript's EVENTS, so no store query can decide them; they
are hygiene rather than user filters, which is why shrinkage is
acceptable for them and would not have been for pinned.
limit=None (the default) is an unpaginated call.
Ordering is pinned first, then newest first. Two stable sorts rather than one composite key: the second pass only has to move pinned rows to the front, and stability preserves the recency order the first pass established within each group. Pinning is applied HERE, as an ordering over what the query already admitted — never as a way around it. A caller that hides an origin keeps hiding it when the row is pinned, because filtering a sorted list preserves relative order. That is what makes "a mobile surface shows only its own pinned sessions" true by construction, with no surface-specific branch anywhere in this method.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 | |
load_events(session_id: str, after: str | None = None) -> list[EventRecord]
¶
Load a session's events, narrowed to those newer than after.
O(matched events) on a driver that can range-read, O(one session's
events) on one that cannot — the store decides, which is the point.
Materialising the whole transcript and filtering it in Python would
make after narrow the RESPONSE while the read stayed the record's
entire history: a cursor in name only. Measure the TIME, not the
payload — a shrinking response hides constant work.
An unparseable after returns everything, unchanged: an in-process
caller has no channel to be refused on, and most of them pass no cursor
at all. That widening is a DEFENSIVE default and nothing may rely on it
— the refusal belongs to the surface that accepted the value from a
client, and the /events route 400s before reaching here.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 | |
register_on_terminate(callback: Callable[[str], int | None]) -> None
¶
Register a callback fired once when a session is terminated.
The Wave-2 cascade-cancel seam: the callback receives the terminated
session_id and MAY return an int count of downstream artifacts it
cancelled (e.g. scheduled triggers), which :meth:terminate_session
sums into cancelled_triggers. Best-effort — a raising callback is
logged and skipped, never blocking termination.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
reinject_recovery_context(session_id: str) -> None
¶
Re-emit capability-gating fields so a recovered run keeps them.
The orchestrator reads the most-recent context event when it
builds the system prompt and resolves capability-gated AgentDefs.
After a recovery turn the latest context event may be a plain
mode/model update that does NOT carry the original
client_capabilities / structured_workspace — so a recovered
wiki/QA/structured session would silently lose its capability and
spawn_agent lookups for the gated AgentDefs would fail.
This scans the transcript for the latest value of each gating key
(preserving exactly what the session already had — no origin→capability
map) and appends a single fresh context event carrying them, so the
most-recent context event after recovery still gates correctly. A no-op
when the session never declared any gating field.
Shared by BOTH the API recover endpoint and the CLI recovery command — the single source of truth for recovery capability re-injection.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 | |
reject_plan(session_id: str) -> bool
¶
Reject a pending plan proposal.
Emits a plan_rejected event. The session stays dormant —
the user can type refinement guidance as a new message, which
starts a fresh plan-mode run.
Returns False if no pending plan proposal exists or a run is already active.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 | |
resolve_recovery_query(session_id: str, action: RecoveryAction, *, from_ts: str | None = None, replacement_text: str | None = None, trigger: RecoveryTrigger | None = None) -> str
¶
Resolve the user query text for a retry/continue recovery action.
Appends a recovery audit event to the transcript and returns the
query text the caller should pass to :meth:start_async. The
orchestrator automatically picks up prior events via
:class:ContextBuilder, so the caller does not need to trim the
transcript.
replacement_text substitutes the query this method would otherwise
build: for retry the original user message (enabling "edit and
regenerate"), for continue the generic resume prompt. An automatic
re-drive supplies its own deterministic prompt that way rather than
appending a second turn of its own.
trigger names a NON-HUMAN originator on the recovery marker (see
:data:RecoveryTrigger); omitted for every operator-driven recovery.
It is what an automatic re-drive reads back to know it has already
fired.
Raises :class:ValueError when action is unrecognised, there is
no prior user message to recover from, or (for retry) the last
user message is empty.
Raises :class:RuntimeError if a run is already active for the
session — cancel it first.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 | |
resolve_session(*, session_id: str | None = None, session_tag: str | None = None, fork_from: str | None = None, fork_at_ts: str | None = None, owner: str | None = None) -> str
¶
Resolve session identifiers, tags, and forks to a session id.
When fork_at_ts is provided alongside fork_from, only events up to (and including) that timestamp are copied into the new session.
owner stamps whichever NEW session this call mints — a fresh one or a
fork. It is an opaque subject string; core never learns what a principal
is (see SessionStoreBase.create_session). Resolving to an EXISTING
session ignores it: ownership is established once, at creation, so
re-engaging someone else's session can never quietly re-stamp it.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | |
run_sync(*, user_query: str, session_id: str, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, max_iters: int = 3, initial_plan: Plan | None = None, tool_registry=None, permission_policy=None, approval_callback=None, hook_manager=None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, cwd: str | None = None, session_step_budget: int = 0, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False, session_mcp_servers: dict[str, dict] | None = None) -> TaskQueue
¶
Run an orchestration request synchronously.
enable_skills=False opts a headless product drive (search/wiki) out
of auto-skill injection so the agent never burns its first step
activating a host ~/.claude skill (default True — CLI/channel
behavior unchanged). capability_mode is the root delegation-privilege
ceiling (default "all" — no filtering); see :meth:start_async.
project_autoselect=True binds list_projects / switch_project
on the ROOT agent so the run chooses its own workspace; default
False binds neither.
user_turn_persisted=True says an upstream seam already wrote this
turn's user event, so the orchestration body must not write a second
one. Default False — a direct caller (the CLI turn engine, the
structured runners) still owns the append.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 | |
set_session_pinned(session_id: str, pinned: bool) -> str | None
¶
Pin or unpin a session, returning the resulting pinned_at stamp.
Lives on the runtime for the same reason archive/rename/fork do: it is the ONE place a session's record is mutated, so every surface reaches the store through it rather than around it.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1076 1077 1078 1079 1080 1081 1082 1083 1084 | |
start_async(*, session_id: str, user_query: str, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, max_iters: int = 3, initial_plan: Plan | None = None, tool_registry=None, permission_policy=None, approval_callback=None, hook_manager=None, mode: str | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, cwd: str | None = None, session_step_budget: int = 0, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, session_mcp_servers: dict[str, dict] | None = None) -> str
¶
Start an asynchronous orchestration run for the session.
capability_mode is the ROOT delegation-privilege ceiling (default
"all" — no filtering). A caller that resolved a
principal's role into a narrower tier (read_only for a viewer)
passes it here so the session's own tools — not only spawned children —
are capped; it travels unchanged into AgentContext.root alongside
workspace_mode.
fallback_models (when provided) opts this run into cross-model
fallback; None defers to the resolved config policy.
Returns a storeless per-run handle run_id of the form
"<session_id>:r<seq>" where seq is the 1-based count of runs
started on this session so far (so one session can host many runs).
The run_id is resolvable back to the session id by splitting on the
first : — no new store or index is required. When the run
registry refuses the start (a run is already active for this
session), an empty string is returned so existing if not started
callers still detect the refusal.
Accepting a turn PERSISTS it: the user event is written here, before
the run is handed off, so a caller that got a run_id can rely on the
transcript already holding the turn. See the block below for why the
executor's own append is suppressed rather than deduplicated.
When the run ends without meeting an explicit goal, :class:GoalRetryGate
re-drives the session ONCE from the post-release seam below. That retry
replays THIS call's arguments unchanged, so it inherits the same tool
registry, hooks, capability ceiling and workspace the operator's run had.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 | |
start_command(session_id: str, target: Callable[[threading.Event], None]) -> bool
¶
Start a non-orchestration background run for a slash command.
Reuses the same RunRegistry as start_async so is_running()
and the events-polling pipeline treat command runs identically to
query runs. The FE drives all in-flight UI off the same
authoritative server state — no browser-side patching required.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 | |
summarize_session(session_id: str, *, events: list[EventRecord] | None = None, record: SessionRecord | None = None) -> dict[str, object]
¶
Return a summarized view of a session.
record supplies the session's stored metadata (title, archived,
terminated, owner, tags) when the caller has already batch-loaded it for
a whole page — see :meth:list_sessions. Omitting it reads the same
five facts one at a time, which is what every single-session caller
does and what this method has always done, so the derived summary is
identical either way; only the number of store reads differs.
With no events, the fold's input is the store's DIGEST of the session rather than its whole transcript — the same projection a listing row gets, and identical in result. It matters most on the poll path, which re-derives status once a second per open client: on the largest live session that read was 0.211 s of a 0.470 s poll, for a status that had not changed.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 | |
tag_session(session_id: str, tag: str) -> None
¶
Associate a provenance/lookup tag with a session.
Thin delegate to the store so callers that already hold a resolved
session_id (e.g. a structured/realtime run stamping its origin tag)
don't reach into session_store directly. resolve_session remains
the seam for tag-keyed resolution; this is the write-only sibling for
tagging a session you've already created.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
621 622 623 624 625 626 627 628 629 630 | |
terminate_session(session_id: str) -> dict[str, object]
¶
Permanently terminate a session — idempotent and irreversible.
First call: stamps terminated_at, cancels any live run (cooperative,
via the run registry's cancel event), fires the on_terminate
callbacks (summing any returned cancelled-artifact counts), and appends
a session_terminated transcript event — which rides the standard
append_event → SessionEventBus → SSE choke-point, so a live
stream observes the termination with no new transport. A repeat call is
a no-op that returns the SAME shape with the ORIGINAL terminated_at
and cancelled_triggers: 0 (the side effects never re-fire).
Side effects fire exactly once, arbitrated by the store's set-once
write: SessionStoreBase.terminate_session returns True only to
the call that newly stamped the timestamp, so two concurrent FIRST
calls (Flask is threaded even at --workers 1) can't both pass an
unlocked read and duplicate the event + callback fan-out — exactly one
of them wins the race and runs the block below.
Callers guard unknown-session (404) upstream; this assumes the session
exists. Returns {session_id, status:"terminated", terminated_at,
cancelled_triggers}.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 | |
SessionTerminatedError
¶
Bases: ValueError
Raised when an operation targets a permanently terminated session.
Termination is a kill switch: a dead session must not be runnable, steerable, recoverable, or fork-resurrectable — copying a terminated transcript into a fresh session would let an agent launder its way around the kill. Raised at the core seam so every caller inherits enforcement; HTTP surfaces map it to 410 Gone.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
137 138 139 140 141 142 143 144 145 | |
parse_core_command(text: str) -> str | None
¶
Return the core command token if present.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
160 161 162 163 164 165 | |
mewbo_core.session.session_store
¶
Session transcript storage and management.
Provides a SessionStoreBase ABC, a filesystem-backed SessionStore
implementation, and a create_session_store() factory that returns the
configured driver (json or mongodb).
SessionPaths
dataclass
¶
Resolved filesystem paths for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
SessionRecord
dataclass
¶
The per-session metadata a summary row needs, minus the transcript.
Everything here is stored ON the session record rather than derived by folding events, which is exactly why it can be batch-loaded: a listing needs all of it for every row and none of it depends on reading a transcript.
A plain frozen dataclass, not a Pydantic model: it never crosses a trust boundary — the store builds it from data it just read out of its own backend — so validating each field would buy nothing on a path whose entire purpose is to be cheap.
tags is the reverse tag index for this session (the same list
tags_for_session returns), carried here so a batch resolves the index
once instead of per row.
pinned_at/projects are the two filterable facets
(session/CLAUDE.md → "Filterable facets") and belong here for the same
reason as every other field: both are stored ON the record rather than
folded from events, so a caller reading them one session at a time is
paying the exact per-row round-trip cost this class exists to collapse.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
SessionStore
¶
Bases: SessionStoreBase
Filesystem-backed storage for session transcripts and summaries.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 | |
__init__(root_dir: str | None = None) -> None
¶
Initialize the store and ensure the root directory exists.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
818 819 820 821 822 823 824 | |
archive_session(session_id: str) -> None
¶
Mark a session as archived.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1081 1082 1083 1084 1085 1086 | |
create_session(owner: str | None = None) -> str
¶
Create a new session directory and return its identifier.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
857 858 859 860 861 | |
ensure_session(session_id: str, owner: str | None = None) -> None
¶
Idempotently create the session directory for a known id.
For the filesystem driver a session "record" IS its directory (that's
what :meth:list_sessions enumerates), so materialisation is a
makedirs — exist_ok=True makes it a safe no-op on replay.
The owner lands in its own index bucket beside archived/terminated
rather than in a per-session file, so the list filter costs one index read
instead of one stat per session.
The stamp is written ONLY when this call is the one that materialised the
record — the filesystem analogue of the Mongo driver's $setOnInsert,
and the reason the directory's prior existence is checked before creating
it. Stamping on any call would make an ALREADY-UNOWNED session claimable
by whoever touched it next, and since an unowned session is visible to
every lister, that is not necessarily its creator. An unowned call never
writes at all, so a deployment with no identity configured leaves the
index exactly as it was.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
get_owner(session_id: str) -> str | None
¶
Return the stamped owning subject, or None if unowned.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
892 893 894 | |
get_pinned_at(session_id: str) -> str | None
¶
Return the stored pinned timestamp, or None.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1039 1040 1041 1042 1043 | |
get_terminated_at(session_id: str) -> str | None
¶
Return the stored terminated_at timestamp, or None.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1119 1120 1121 1122 | |
is_archived(session_id: str) -> bool
¶
Return True if a session is archived.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1097 1098 1099 1100 1101 | |
list_tags() -> dict[str, str]
¶
Return a mapping of tags to session IDs.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1076 1077 1078 1079 | |
load_summary(session_id: str) -> str | None
¶
Load a previously saved summary, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
965 966 967 968 969 970 971 972 | |
load_title(session_id: str) -> str | None
¶
Load a previously saved title, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
981 982 983 984 985 986 987 988 989 | |
load_transcript(session_id: str) -> list[EventRecord]
¶
Load all transcript events for a session. O(one session's events).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
913 914 915 | |
projects_for_session(session_id: str) -> list[str]
¶
Return every project identity recorded for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1060 1061 1062 1063 | |
query_sessions(query: SessionQuery) -> list[str]
¶
List session IDs in the root directory, narrowed by query.
Reads the index ONCE for the whole listing rather than once per
predicate per session — the filesystem driver's every index-backed fact
is a full read-and-parse of index.json, so a per-session lookup would
turn one file read into four times the session count.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | |
record_project(session_id: str, project: str) -> None
¶
Append project to the session's recorded set, if new.
Returns without writing when the project is already recorded, which is the common case: every turn of a bound session re-emits the same context.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | |
resolve_tag(tag: str) -> str | None
¶
Resolve a tag to a session ID, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1071 1072 1073 1074 | |
save_summary(session_id: str, summary: str) -> None
¶
Persist a summary for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
958 959 960 961 962 963 | |
save_title(session_id: str, title: str) -> None
¶
Persist a display title for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
974 975 976 977 978 979 | |
session_dir(session_id: str) -> str
¶
Return the directory path for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
900 901 902 | |
set_pinned(session_id: str, pinned: bool) -> None
¶
Stamp or clear pinned for a session in the index.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 | |
stream_transcript(session_id: str) -> Iterator[EventRecord]
¶
Yield transcript events one parsed line at a time.
O(1) in memory, which is what makes the base
:meth:~SessionStoreBase.list_session_digests template usable here: a
listing folds each session's file as it reads and retains only the
relevant events, instead of holding a whole transcript to produce one
row. The PARSE still costs O(one session's events) — a JSONL file
carries no index, so there is no honest way to find a session's
completion event without reading past everything before it, and this
driver's listing therefore stays O(all history) in CPU. That is the
floor for the default driver, and the reason MongoDB is the recommended
backend for a store that has accumulated real history.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 | |
tag_session(session_id: str, tag: str) -> None
¶
Associate a tag with a session ID for quick lookup.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1065 1066 1067 1068 1069 | |
terminate_session(session_id: str) -> bool
¶
Stamp terminated_at in the index once (never overwrites).
Returns whether THIS call inserted the stamp — checked before the
write so a repeat call reports False without touching the file.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | |
truncate_after(session_id: str, cutoff_ts: str) -> int
¶
Rewrite the transcript keeping only events with ts <= cutoff_ts.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
944 945 946 947 948 949 950 951 952 953 954 955 956 | |
unarchive_session(session_id: str) -> None
¶
Remove archived status from a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1088 1089 1090 1091 1092 1093 1094 1095 | |
SessionStoreBase
¶
Bases: ABC
Abstract interface for session storage backends.
Each driver implements the 13 abstract storage primitives. Higher-level
operations (fork_session, load_recent_events, compact_session)
are concrete template methods built on top of those primitives.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 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 350 351 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 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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 | |
__init__() -> None
¶
Initialise the in-memory termination cache shared by every backend.
Populated by :meth:_mark_terminated_cached (called from each
backend's terminate_session) and consulted by
:meth:_guard_append, so a hot-path append never pays a Mongo
round-trip / index-file read to learn whether its own session was
just terminated. Best-effort and per-process only: a session
terminated by a DIFFERENT process/worker is still caught by the
durable terminated_at stamp at every other termination-aware seam
(resolve_session, recovery) — this cache only shortcuts the
common same-process race between a live run and a concurrent
/terminate call.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
append_event(session_id: str, event: Event) -> None
¶
Append a single event record to the session transcript.
No-ops (after a dropped-event log, once per session) once
:meth:terminate_session has stamped this session terminated — see
:meth:_guard_append. The ONE deliberate exception is
:meth:append_terminal_event, used for the termination tombstone
itself.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
161 162 163 164 165 166 167 168 169 170 171 172 173 | |
append_terminal_event(session_id: str, event: Event) -> None
¶
Append an event exempt from the termination guard.
SessionRuntime.terminate_session writes the session_terminated
tombstone through this seam immediately after the store's own
terminate_session has already cached the session as terminated —
an ordinary :meth:append_event call would otherwise drop its own
closing event. No other caller should use this.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
233 234 235 236 237 238 239 240 241 242 | |
append_user_turn(session_id: str, text: str, attachments: list[dict] | None = None) -> None
¶
Append the user event that records ONE accepted turn.
The single builder of that payload, because two seams write it: the
acceptance seam (SessionRuntime.start_async, so the turn is durable
before the executor's cold start) and the orchestration body itself (for
every caller that reaches Orchestrator directly). A second
hand-rolled {"type": "user", ...} literal in either place is free to
drift from this one — silently, since both would still write a
transcript event the readers accept.
attachments is written only when non-empty, mirroring
:class:~mewbo_core.contracts.types.UserPayload's NotRequired key,
so a turn without attachments carries no such key. It additively
duplicates the sibling context event's
descriptors so a client can render attachment cards above the user turn
without joining across events.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
archive_session(session_id: str) -> None
abstractmethod
¶
Mark a session as archived.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
407 408 409 | |
compact_session(session_id: str, mode: CompactionMode | None = None, **kwargs: Any) -> CompactionResult
async
¶
Compact a session's transcript using structured summarization.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | |
create_session(owner: str | None = None) -> str
abstractmethod
¶
Create a new session and return its identifier.
owner is an OPAQUE subject string, never an identity object: core sits
below the identity kernel in the dependency DAG and must not learn what a
principal is. The caller that HAS one resolves it to a string first.
None means unowned, which is what every session created without an
authenticated caller is — see :meth:list_sessions for what that implies
on the read side.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
118 119 120 121 122 123 124 125 126 127 128 | |
ensure_session(session_id: str, owner: str | None = None) -> None
abstractmethod
¶
Idempotently materialise a session RECORD for a known id.
create_session mints its own uuid; some callers (the realtime
write-behind recorder) need to back a session whose id was pre-minted
elsewhere — e.g. for an in-flight Langfuse trace opened before any store
write. Without a record, list_sessions (and every read surface built
on it) never sees the id, so the transcript is an orphan: events exist,
the session is invisible.
This is the seam that closes that gap. It is idempotent — calling it on
an existing session is a no-op (never resets created_at / archived state).
create_session is implemented on top of it (mint id → materialise).
The owner stamp is SET-ONCE at materialisation, like created_at and
unlike archived_at: a replay must not be able to re-point an existing
session at a different subject, which would be an ownership takeover
written through an idempotent no-op path.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
fork_session(source_session_id: str, owner: str | None = None) -> str
¶
Create a new session by copying events, summary, and title from another.
The fork is stamped for whoever asked for it, NOT for the source's owner: a fork is a new session that happens to start with a copy of a transcript. Leaving it unstamped would be worse than either — an unowned fork of an owned session is visible to every lister, so forking would launder a session out of its owner's scope.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
fork_session_at(source_session_id: str, cutoff_ts: str, owner: str | None = None) -> str
¶
Fork a session, keeping only events with ts <= cutoff_ts.
Composes :meth:fork_session + :meth:truncate_after and clears the
copied summary (which may reference events beyond the cutoff).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
568 569 570 571 572 573 574 575 576 577 578 579 | |
get_owner(session_id: str) -> str | None
abstractmethod
¶
Return the owning subject, or None if the session is unowned.
The read-through sibling of the stamp ensure_session writes, mirroring
how is_archived reads archive_session's write.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
269 270 271 272 273 274 275 | |
get_pinned_at(session_id: str) -> str | None
abstractmethod
¶
Return the stored pinned_at stamp, or None if unpinned.
The read-through sibling of :meth:set_pinned, mirroring how
is_archived reads archive_session's write.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
352 353 354 355 356 357 358 | |
get_terminated_at(session_id: str) -> str | None
abstractmethod
¶
Return the ISO terminated_at timestamp, or None if live.
The read-through sibling of :meth:terminate_session (mirrors how
is_archived reads archive_session's write).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
437 438 439 440 441 442 443 | |
is_archived(session_id: str) -> bool
abstractmethod
¶
Return True if a session is archived.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
415 416 417 | |
is_terminated(session_id: str) -> bool
¶
Return True iff a session was permanently terminated.
Concrete over :meth:get_terminated_at so both backends share one
implementation — the single derivation every termination guard reads.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
445 446 447 448 449 450 451 | |
last_attestation_hash(session_id: str) -> str
¶
Return the attestation chain's head to re-seed on recovery.
Concrete default over :meth:load_transcript: scans for the most
recent type == "attestation" event and returns its persisted
record_hash, else the chain's genesis hash — mirrors the
tags_for_session concrete-default idiom so every backend shares
one scan; MongoSessionStore overrides with a targeted query.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | |
latest_context(session_id: str) -> dict[str, object]
¶
Return the session's merged context (most-recent context event wins).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
522 523 524 | |
latest_event_of_type(session_id: str, event_type: str, *, payload_key: str | None = None) -> EventRecord | None
¶
Return the NEWEST event of event_type, or None when there is none.
O(one session's events) here and O(1) on a driver that can walk
an index backwards (MongoSessionStore overrides). Same honest split
as :meth:load_events_after and :meth:load_recent_events: the base
has no cheap reverse read, so it streams and keeps the last match — a
caller must not read this primitive as cheap on every backend. Memory
stays O(1): it holds one event, never the transcript.
Bounded by the TYPE, never by a count. Tailing the last N events is the tempting cheap answer and it is a wrong one — the newest event of a sparse type sits arbitrarily far back in a session with a long run since the last one, so a window that misses it reports "no such event". That is a wrong ANSWER, not a slow one, and a caller turns it into a refusal.
payload_key narrows further, to events whose payload satisfies
:meth:payload_key_is_set. It exists because "the newest event of this
type" and "the newest event of this type that CARRIES the field I came
for" are different questions, and a caller answering the second with the
first is wrong whenever a later event of the same type omits the field.
Context events are exactly that shape: they are merged key-by-key
(:meth:merge_context_events), so a session can write a project
and then several context events that say nothing about one. Measured on
the deployed store, 15 of the 204 sessions carrying a project
anywhere in context had a NEWER context event without it.
Returns the EVENT, not a field off it, so a second caller wanting a different key out of the same event is served by the same read.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
721 722 723 724 725 726 727 728 729 730 731 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 | |
list_session_digests(query: SessionQuery | None = None, *, limit: int | None = None, offset: int = 0) -> list[SessionDigest]
¶
Return one listing digest per session matching query.
The seam a LISTING reads instead of calling :meth:load_transcript per
id. One digest per session, in the order :meth:query_sessions returns
them when limit is None; a session with no events yields an empty
digest rather than being dropped, because whether it belongs on a
listing is the caller's rule (a running session has no events until its
first append). None means an unnarrowed call — every session,
archived included — leaving a caller that filters for itself to do so.
Cost is per DRIVER, and the base template is the expensive one.
This default folds every transcript, so it is O(all history) —
honest, correct, and the reason MongoSessionStore overrides it with
a projection that is O(collection) in rows plus O(summary-relevant
events) in reads. A backend that gains an index owes an override; a
backend that cannot must say so here rather than let a caller assume the
listing is cheap.
What the default still buys: the fold STREAMS, so peak memory is the RELEVANT events rather than the whole transcript — a 10,266-event session never has to be resident to contribute one row.
limit/offset page the RESULT of the fold this driver already pays
for — the file backend has no cheap way to learn a session's first
timestamp without opening it, so paging here narrows what is RETURNED,
not what is READ. MongoSessionStore overrides this to narrow the
read too; see its docstring for why that split is real. Sort key is
each digest's first event's ts (== the eventual created_at for
every row that survives the caller's own visibility filter — see
SessionRuntime.list_sessions), descending, so a page here orders the
same way the final listing does.
The page is cut from what query already admitted. Even on a driver
where paging cannot narrow the read, the two must compose in that order:
filtering a page instead of paging the filtered set would make
pinned=True with a limit return only the pinned sessions inside
the newest N candidates, which is usually none of them.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
list_sessions(owner: str | None = None) -> list[str]
¶
List session IDs, optionally narrowed to what owner may see.
Concrete delegate over :meth:query_sessions, kept because it is the
established call shape. include_archived=True is the contract: this
method returns archived sessions too, and the archived filter is applied
by the caller.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
397 398 399 400 401 402 403 404 405 | |
list_tags() -> dict[str, str]
abstractmethod
¶
Return a mapping of tags to session IDs.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
289 290 291 | |
load_events_after(session_id: str, cursor: EventCursor | None) -> list[EventRecord]
¶
Return the events strictly newer than cursor (all of them if None).
O(one session's events) here, and that is the point of the seam
rather than an acceptance of it: the base has no index to narrow with,
so it streams and tests, but a driver that CAN turn the cursor into a
range read overrides this and becomes O(matched events). Filtering a
fully-materialised transcript in Python is a cursor in name only — the
response shrinks and the work does not.
A None cursor means "everything". It never means "the cursor was
bad": an unparseable value is refused at the boundary that received it,
because a filter that cannot be applied must not widen to the whole
collection.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | |
load_recent_events(session_id: str, limit: int = 8, include_types: set[str] | None = None) -> list[EventRecord]
¶
Load the most recent events, optionally filtered by type.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
689 690 691 692 693 694 695 696 697 698 699 700 701 | |
load_session_records(session_ids: list[str]) -> dict[str, SessionRecord]
¶
Batch-load the per-session metadata one summary row needs.
A LISTING derives every row's title, archived flag, termination stamp, owner, tags, pin stamp and project set. Fetching them one session at a time is seven store reads per row — on a networked driver, seven ROUND TRIPS per row, so the cost of listing scales with the session count times a per-call latency that has nothing to do with how much data is involved. This is the seam that collapses them: one call for the whole page.
This default is the CORRECT-everywhere implementation, not the fast one.
It still reads per session, but it already removes the worst repetition
by resolving the reverse tag index ONCE for the whole batch instead of
rescanning it per row. A driver that can answer the whole batch in a
single query overrides this (see MongoSessionStore); a driver that
cannot inherits behaviour identical to what the caller did by hand, so
adding a driver can never silently produce a WRONG row — only a slower
one.
Unknown ids are returned with an empty record rather than omitted, so a caller can index the result without a membership test.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
load_summary(session_id: str) -> str | None
abstractmethod
¶
Load a previously saved summary, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
257 258 259 | |
load_title(session_id: str) -> str | None
abstractmethod
¶
Load a previously saved title, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
265 266 267 | |
load_transcript(session_id: str) -> list[EventRecord]
abstractmethod
¶
Load all transcript events for a session. O(one session's events).
A PER-SESSION read. It must never be called in a loop over sessions —
that is O(all history) wearing a listing's clothes, and it is exactly
the shape :meth:list_session_digests exists to replace.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
244 245 246 247 248 249 250 251 | |
merge_context_events(events: list[EventRecord]) -> dict[str, object]
staticmethod
¶
Reduce a transcript to its current context (most-recent payload wins).
One reducer shared by :meth:latest_context (the trace-provenance path)
and SessionRuntime.summarize_session (the origin/recovery path) so the
rule for "what context is this session running under" lives in exactly one
place. context events are sparse, so a full scan is cheap.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
payload_key_is_set(event: EventRecord, key: str) -> bool
staticmethod
¶
Is key present on this event's payload with a value worth reading?
The ONE spelling of the narrowing :meth:latest_event_of_type applies
for payload_key, published here so MongoSessionStore can push an
equivalent query down rather than restate the rule. Present, not
None, not the empty string — deliberately no further judgement: what
counts as a USABLE value belongs to the caller that knows what the key
means, and a store that guessed would silently skip an event a caller
would have accepted.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | |
projects_for_session(session_id: str) -> list[str]
abstractmethod
¶
Return every project identity recorded for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
370 371 372 | |
query_sessions(query: SessionQuery) -> list[str]
abstractmethod
¶
Return the session IDs matching query, narrowed at the STORE.
The point of narrowing here rather than at the caller is that the caller
builds each row by loading that session's whole transcript — so a
session rejected by the query is one that is never opened. Every field of
:class:SessionQuery is answerable from the session record alone,
precisely so this can be a single indexed read.
query.owner=None lists EVERYTHING — what a caller holding a
read-all authority (or no identity at all) gets.
A non-None owner narrows to that subject's own sessions PLUS every
UNOWNED one. Unowned is not a hole in the filter, it is the migration
semantic: sessions predating the owner stamp carry no subject, and no
subject can be reconstructed for them after the fact. Hiding them would
make a user's existing work vanish from their own list, which is a worse
failure than showing a pre-existing session to someone who could already
list it before the stamp existed. The unowned set is closed and shrinking
— every session created by an authenticated caller from here on is
stamped — so this is a fading allowance, not a permanent widening.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
record_project(session_id: str, project: str) -> None
abstractmethod
¶
Add project to the set this session has worked in (idempotent).
A SET, not a field, because a session can move: an auto-select session starts with no project and the agent may switch several times, and a filter has to find it under every one of them. Recording is additive and order-free, so a replayed context event is a no-op.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
360 361 362 363 364 365 366 367 368 | |
resolve_tag(tag: str) -> str | None
abstractmethod
¶
Resolve a tag to a session ID, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
285 286 287 | |
save_summary(session_id: str, summary: str) -> None
abstractmethod
¶
Persist a summary for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
253 254 255 | |
save_title(session_id: str, title: str) -> None
abstractmethod
¶
Persist a display title for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
261 262 263 | |
session_digest(session_id: str) -> SessionDigest
¶
Return ONE session's listing digest — the single-session sibling above.
O(one session's summary-relevant events) for a driver that projects,
O(one session's events) for one that folds. Exists because a
summary is not only a listing concern: the poll path re-derives status
for a single session on every tick, and doing that from the full
transcript is the same defect at a different scale — 0.211 s per poll on
the largest live session, once a second, per open client.
Deliberately NOT expressed as list_session_digests narrowed to one
id: that route pays the listing's own setup (enumerating sessions) to
answer a question about one.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | |
session_dir(session_id: str) -> str
abstractmethod
¶
Return the local directory path for a session (used for attachments).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
277 278 279 | |
set_pinned(session_id: str, pinned: bool) -> None
abstractmethod
¶
Pin or unpin a session, stamping pinned_at on the record.
Stored as a TIMESTAMP rather than a bool, matching archived_at and
terminated_at, because it doubles as the ordering key: a surface
shows most-recently-pinned first without a second field. Unlike those
two the stamp is REVERSIBLE by design — a pin is a user's assertion
about their own list, not a lifecycle terminal.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
341 342 343 344 345 346 347 348 349 350 | |
stamp(event: Event) -> EventRecord
staticmethod
¶
Build the durable record for event, stamping or canonicalising ts.
The ONE place a stored timestamp is spelled, called by every backend's
_write_event. An event that carries no ts — everything the engine
appends — gets the clock's. One that DOES is normalised to the same UTC
spelling rather than stored verbatim: the mirror-ingest endpoint accepts
a client's own timestamps, and a differing UTC offset would order
differently as TEXT than as an instant. Every ts comparison in this
package is textual (load_transcript's sort, truncate_after's
range, the cursor floor a store pushes down), so a single foreign
spelling would sort a real event into the wrong place — silently, since
text comparison never raises. The INSTANT is preserved; only its
spelling is fixed.
A value that cannot be parsed is kept exactly as sent. It is still evidence of what a client claimed, and replacing it with the clock would forge a timestamp for an event that already has one.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
stream_transcript(session_id: str) -> Iterator[EventRecord]
¶
Yield a session's events in ts order without materialising them.
O(one session's events) in time, O(1) in memory for a driver that
overrides it. The default just iterates :meth:load_transcript, so it
buys nothing on its own — it exists so :meth:list_session_digests has
one seam a line-oriented backend can make genuinely streaming.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
679 680 681 682 683 684 685 686 687 | |
tag_session(session_id: str, tag: str) -> None
abstractmethod
¶
Associate a tag with a session ID for quick lookup.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
281 282 283 | |
tags_for_session(session_id: str) -> list[str]
¶
Return every tag pointing at session_id (reverse of resolve_tag).
Concrete default over list_tags so all backends share one
implementation; the tag set is small. Provenance classification reads
this to recover a session's origin (see session_provenance).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
293 294 295 296 297 298 299 300 | |
terminate_session(session_id: str) -> bool
abstractmethod
¶
Permanently mark a session terminated (irreversible).
Stamps terminated_at once — a repeat call never moves the
original timestamp. There is deliberately NO un-terminate primitive:
termination is a one-way door. Mirrors
archive_session but without the reverse operation.
Returns True iff THIS call was the one that newly stamped the
timestamp, False if the session was already terminated. This is
the arbitration signal SessionRuntime.terminate_session reads to
run its side effects (cancel + callbacks + event) exactly once even
under concurrent callers — the store's set-once write is the only
thing racing safely, so the runtime must never decide on its own
unlocked read.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
truncate_after(session_id: str, cutoff_ts: str) -> int
abstractmethod
¶
Delete all events with ts > cutoff_ts.
Returns the number of deleted events. Used by the recovery pipeline to clean up a failed run before re-driving.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
453 454 455 456 457 458 459 | |
unarchive_session(session_id: str) -> None
abstractmethod
¶
Remove archived status from a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
411 412 413 | |
create_session_store(root_dir: str | None = None) -> SessionStoreBase
¶
Return the configured session store driver.
Reads storage.driver from the app config. Defaults to "json"
(filesystem). Set to "mongodb" to use MongoDB.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 | |
mewbo_core.session.context
¶
Context selection and rendering helpers.
ContextBuilder
¶
Build short-term and selected context for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 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 350 351 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 | |
__init__(session_store: SessionStoreBase) -> None
¶
Initialize the context builder.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
197 198 199 | |
build(session_id: str, user_query: str, model_name: str | None) -> ContextSnapshot
¶
Build a context snapshot for planning and synthesis.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
201 202 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 240 241 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 275 276 277 278 279 280 281 282 283 284 285 286 | |
ContextSelection
¶
Bases: BaseModel
Model output for selecting context events.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
31 32 33 34 35 | |
ContextSnapshot
dataclass
¶
Context snapshot for planning and synthesis.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
event_payload_text(event: EventRecord) -> str
¶
Return a readable payload string for an event.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
55 56 57 58 59 60 61 62 63 64 65 | |
render_event_lines(events: list[EventRecord]) -> str
¶
Render events into bullet lines for prompts.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
68 69 70 71 72 73 74 75 76 | |
mewbo_core.session.compaction
¶
Lossless pre-compaction utilities.
This module intentionally contains only one thing: a pre_compact hook
that strips ANSI escapes and truncates huge tool outputs before the LLM
summarizer sees them. Zero tokens, zero risk.
Prior versions also shipped should_compact (an event-count heuristic)
and summarize_events (a fallback "summary" that concatenated raw
event text). Both were deleted: compaction decisions are now driven
purely by the API-reported usage_metadata.input_tokens, and failed
structured compaction must not be masked with raw-text noise.
micro_compact_events(events: list[EventRecord]) -> list[EventRecord]
¶
Lossless pre-compaction: strip ANSI escapes and truncate large tool outputs.
Intended for use as a pre_compact hook — no LLM call, zero cost.
The two jobs are INDEPENDENT and applied as such. They used to be one branch, so an escape-laden result under the cap kept every escape — and raising the cap silently widened that band. Stripping is unconditional; only the truncation consults the cap.
Source code in packages/mewbo_core/src/mewbo_core/session/compaction.py
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 | |
mewbo_core.session.token_budget
¶
Token budgeting anchored on LiteLLM-authoritative model metadata.
Philosophy: trust the API, not estimates. LiteLLM's get_model_info is
the source of truth for each model's max_input_tokens; LangChain's
response.usage_metadata.input_tokens is the source of truth for what
the current prompt actually consumed. No char-count heuristics, no fake
overhead additions, no regex guessing from the model name.
TokenBudget
dataclass
¶
Token accounting snapshot used to decide compaction.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
needs_compact: bool
property
¶
Return True when utilization meets or exceeds the configured threshold.
build_usage_numbers(events: list[EventRecord], root_model: str | None) -> dict[str, Any]
¶
Walk a transcript once and return raw usage numbers.
Split by depth so clients can render root (hypervisor) vs sub-agents without conflation. Numbers only — no formatting, no color states, no labels. Clients format what they need.
Returned keys (input has two semantics, output only one):
Context-pressure (peak) — what matters for compaction / window math.
input_tokens on an llm_call_end event is the prompt size for
that call. Within a turn the prompt GROWS as tool results accumulate
(step 1: ~13K baseline, step 11: ~27K), so summing gives a nonsense
number that double-counts the baseline once per call. The peak (max
across root calls) is the real context pressure:
- root_peak_input_tokens: max input_tokens seen on any depth==0 call.
- sub_peak_input_tokens: sum of per-sub-agent peaks (each sub-agent
runs in an isolated context, so summing their peaks — not their sum
inputs — represents "combined peak pressure of parallel sub-contexts").
Cumulative (billable) — what the provider charges for.
Sum across all calls. Useful for cost dashboards. Named with
_billed_in suffix to make the semantic explicit:
- root_input_tokens_billed, sub_input_tokens_billed.
Output is additive everywhere. Each output token is produced once;
summing is correct:
- root_output_tokens, sub_output_tokens.
Other keys: root_model, root_max_input_tokens,
root_last_input_tokens, root_utilization,
tokens_until_compact, compact_threshold,
root_llm_calls, sub_llm_calls, sub_agent_count,
total_input_tokens_billed, total_output_tokens,
compaction_count, compaction_tokens_saved,
models_used (distinct model IDs in first-seen order, collected from
context.model, sub_agent.model, and llm_fallback.to_model).
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
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 275 276 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 350 351 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 398 | |
estimate_event_tokens(events: Iterable[EventRecord]) -> int
¶
Estimate total tokens for a sequence of events (fallback only).
Used only when no real usage_metadata is available (e.g. a fresh
session before the first LLM call). After the first response lands,
last_input_tokens from the API is the authoritative signal.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
180 181 182 183 184 185 186 187 188 189 190 191 | |
estimate_summary_tokens(summary: str | None) -> int
¶
Estimate token usage for the stored summary.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
194 195 196 197 198 | |
forget_cached_context_windows() -> None
¶
Drop memoized catalogue answers after the catalogue changes.
_litellm_max_input_tokens memoizes a MISS as readily as a hit, so a
lookup that ran before the proxy bridge hydrated the catalogue would pin
the pre-hydration answer for the life of the process — and the API serves
usage reads that resolve a window without ever constructing a client.
Registration is the only event that invalidates those answers.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
151 152 153 154 155 156 157 158 159 160 | |
get_model_max_input_tokens(model_name: str | None) -> int
¶
Resolve the maximum input tokens for a model.
Priority: user override -> LiteLLM catalogue -> config default.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
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 | |
get_token_budget(events: Iterable[EventRecord], summary: str | None, model_name: str | None, threshold: float | None = None, *, last_input_tokens: int | None = None) -> TokenBudget
¶
Calculate token utilization and remaining context budget.
When last_input_tokens is supplied (from a real
response.usage_metadata read), it is used as the authoritative
total. Otherwise we fall back to estimating from events + summary.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
201 202 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 240 | |
read_last_input_tokens(events: list[EventRecord]) -> int | None
¶
Return the most recent llm_call_end event's input_tokens.
Session-store counterpart to the in-memory _last_input_tokens field
on ToolUseLoop. Lets callers outside the loop (e.g. the orchestrator's
compaction check) read the authoritative per-call token count that was
already persisted.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
mewbo_core.tooling.tool_registry
¶
Tool registry and manifest loading for Mewbo.
ToolRegistry
¶
Registry of configured tools and their instantiated runners.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
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 240 241 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 275 276 277 278 279 280 281 282 283 284 285 286 | |
__init__() -> None
¶
Initialize an empty registry.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
208 209 210 211 | |
disable(tool_id: str, reason: str) -> None
¶
Disable a tool and store a reason for later reporting.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
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 240 241 242 | |
get(tool_id: str) -> ToolRunner | None
¶
Return an enabled tool runner, instantiating it if needed.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
get_spec(tool_id: str) -> ToolSpec | None
¶
Return the tool specification, even if disabled.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
266 267 268 | |
list_specs(include_disabled: bool = False) -> list[ToolSpec]
¶
List tool specifications, optionally including disabled tools.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
270 271 272 273 274 275 | |
register(spec: ToolSpec) -> None
¶
Register a tool specification and update action validation.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
244 245 246 247 248 249 | |
tool_catalog() -> list[dict[str, str]]
¶
Return a serialized catalog of registered tool metadata.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
277 278 279 280 281 282 283 284 285 286 | |
ToolRegistryCache
¶
Process-wide reuse of built ToolRegistry objects, keyed by build inputs.
Orchestrator.__init__ builds the tool registry on every run (per-query),
paying load_registry's cost — reading the MCP manifest, constructing every
ToolSpec, probing Home-Assistant/LSP status — before the run emits its
first event. That work is identical across runs whose inputs are identical, so
the result is cached and the SAME registry handed back on the next run within a
session (kill the blank-shell wait).
The key is exactly the set of inputs that change what load_registry
produces: the project cwd, any plugin-contributed extra_mcp_servers,
and the resolved MCP-config fingerprint (so an edit to mcp.json still forces
a rebuild — the same signal that gates the manifest rebuild in
_ensure_auto_manifest). Allowed-tools scoping is applied per-run downstream
(filter_specs over list_specs), never at build time, so it is
deliberately NOT part of the key.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 | |
__init__() -> None
¶
Initialize an empty, lock-guarded cache.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1519 1520 1521 1522 | |
clear() -> None
¶
Drop every cached registry.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1573 1574 1575 1576 | |
get_or_build(*, cwd: str | None = None, extra_mcp_servers: dict[str, dict] | None = None, trust_cwd: bool = True) -> ToolRegistry
¶
Return a cached registry for these inputs, building exactly once.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 | |
ToolRunner
¶
Bases: Protocol
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
79 80 81 82 83 84 85 86 87 88 | |
run(action_step: ActionStep) -> MockSpeaker
¶
Execute an action step and return a speaker response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_step
|
ActionStep
|
Action step payload to execute. |
required |
Returns:
| Type | Description |
|---|---|
MockSpeaker
|
MockSpeaker response from the tool. |
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
80 81 82 83 84 85 86 87 88 | |
ToolSpec
dataclass
¶
Metadata describing a tool available to the assistant.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
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 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 | |
capability_tier() -> str | None
¶
Resolve this tool's privilege tier for capability_mode filtering.
Returns "read" / "write" / "execute", or None when the
tool makes no declaration. A read_only tool is read-tier by
construction (no side effects), so the fallback keeps read_only and
capability in lockstep — a new read-only tool is correctly admitted
under read_only mode without a second annotation, and the failure
mode for a forgotten declaration is safe-deny, not silent grant.
None is deliberately NOT treated as read: an undeclared tool is
withheld from a read_only child.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
knob_mismatches(declared: ToolSpec) -> dict[str, tuple[object, object]]
¶
Fields where THIS spec disagrees with its declared counterpart.
Maps each differing field to (mine, declared). Pure comparison, no
I/O — the two specs arrive as values so a caller can compare a
manifest-loaded spec against the built-in registration that authored it.
This exists because the defect class is cached data outliving the declaration, which nothing else can see: a manifest written before a field existed carries no key for it, the reader defaults it, and the result is a spec that is internally consistent, loads clean, and is wrong. Only a comparison against the declaration catches that.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
with_declared_knobs(declared: ToolSpec) -> ToolSpec
¶
Return this spec with declared's knob values overlaid.
The built-in registration is the AUTHORITY for these fields and the manifest entry is a cache of it, so the declaration wins — which is what lets an already-written manifest self-heal on the next load with no operator step and no regeneration. Everything else on the manifest entry (identity, schema, enablement, MCP wiring) is untouched.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
173 174 175 176 177 178 179 180 181 182 183 184 | |
capability_mode_admits(capability_mode: str, tier: str | None) -> bool
¶
True if a tool of privilege tier survives capability_mode.
The ONE home of the mode→tier law, shared by the registry filter
(:func:filter_specs) AND the session-tool build
(SessionToolRegistry.ids_for) so the two enforcement surfaces can never
drift (the two-surface trap). all — and any unrecognised mode, since
the authoritative validation is the Literal at the SpawnAgentTask
boundary — admits everything (the gate is skipped). An undeclared tier
(None) is admitted ONLY by all: safe-deny under any restrictive mode.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
classify_tool_scope(spec: ToolSpec, *, global_servers: set[str], plugin_servers: set[str]) -> str
¶
Classify a tool spec into its deployment scope.
The four real scope categories:
builtin— a core built-in Python tool (spec.kind != "mcp"), not an MCP server at all.system— an MCP tool whose server is configured in the shared, deployed-instancemcp.json(global_servers).plugin— an MCP tool contributed by an installed plugin (plugin_servers).project— an MCP tool whose server is configured only in the current project's local MCP config (neither of the above).
A genuine user tier — a personal ~/.mewbo config distinct from
the deployed $MEWBO_HOME system instance — is deliberately NOT
implemented: no current infra distinguishes the two in a way worth
surfacing yet.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
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 | |
filter_specs(specs: list[ToolSpec], *, allowed: list[str] | None = None, denied: list[str] | None = None, capability_mode: str = 'all') -> list[ToolSpec]
¶
Filter tool specs by allowlist, capability mode, and/or denylist.
allowed is THREE-STATE and tested with is None, never truthiness:
None is unrestricted (no allowlist gate), [] grants NOTHING, and a
non-empty list grants exactly those ids. Collapsing [] into None
would turn "this principal gets no tools" into "this principal gets every
tool" — the fail-open direction, on the gate that binds an agent's whole
tool surface.
When the gate applies, only specs whose tool_id is in the list are
kept — EXCEPT always_load specs (the tool_search tool),
which are exempt from the allowlist gate so a scoped sub-agent never
loses the means to fetch its deferred MCP tools.
capability_mode is a coarse privilege pre-filter
applied AFTER the allowlist and layered UNDER it: it can only remove more
tools, never resurrect one the allowlist dropped. Only specs whose
:meth:ToolSpec.capability_tier is admitted by the mode survive — see
CapabilityMode for the tier law. always_load is exempt here too
(harmless discovery), mirroring the allowlist gate; "all" (the default)
and any unrecognised mode skip the gate entirely.
Then any spec whose tool_id appears in denied (merged with the config
agent.default_denied_tools) is removed. Deny always takes precedence
over allow AND capability_mode — an explicit deny removes even an
always_load tool.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 | |
get_or_build_registry(*, cwd: str | None = None, extra_mcp_servers: dict[str, dict] | None = None, trust_cwd: bool = True) -> ToolRegistry
¶
Return a cached ToolRegistry for these inputs, building once per scope.
The single seam Orchestrator uses to avoid rebuilding the registry on
every run in a session. Falls through to :func:load_registry on a cache
miss. See :class:ToolRegistryCache for the keying contract.
Pass trust_cwd=False when cwd holds content this deployment did not
author. A caller that does not know can leave it alone and register the
directory with :data:mewbo_core.config.register_untrusted_cwd instead —
that is read here too, and overrides an affirmative argument.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 | |
is_always_load(spec: ToolSpec) -> bool
¶
Return True if the tool's full schema must always be in the bound list.
Marked via metadata.always_load=True. An opt-out from deferral —
used by tools that the model needs immediately
(the search tool itself, or any tool whose absence would block the
model from making progress).
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
406 407 408 409 410 411 412 413 414 | |
is_deferred(spec: ToolSpec) -> bool
¶
Return True if the tool's schema should be omitted from the initial bind.
Deferred tools surface as names only via <available-deferred-tools> —
the model fetches their schemas on demand via tool_search. The
deferral rule: always_load wins, the search tool
itself never defers, all MCP tools defer, and other tools opt-in via
metadata.deferred=True.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
load_registry(manifest_path: str | None = None, *, cwd: str | None = None, extra_mcp_servers: dict[str, dict] | None = None, trust_cwd: bool = True) -> ToolRegistry
¶
Load tool registry, auto-discovering MCP tools when configured.
trust_cwd is the caller's explicit statement about cwd: False means
the directory holds content this deployment did not author, so neither its
own .mcp.json nor any beneath it may name a server. The decision is
carried onto every MCPToolRunner built here, because a runner
re-resolves the config at invocation time — covering the boundary at build
time alone would leak at call time.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 | |
mcp_tool_id(server_name: str, tool_name: str) -> str
¶
Public alias for the canonical mcp_<server>_<tool> id convention.
Anything that must NAME an executable MCP tool outside the registry (the
SCG route projection emitting a probe's allowed_tools, allowlist
builders, trace labels) must derive the id HERE — never by string-mangling
a source_key. A graph source_key (<source>#<Capability>) is a
graph address, not a tool id; passing it to allowed_tools silently
grants nothing (the run-c52e9597 probe failure).
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
889 890 891 892 893 894 895 896 897 898 899 | |
reset_registry_cache() -> None
¶
Drop all cached registries (tests; an explicit /mcp refresh).
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1604 1605 1606 | |
mewbo_core.classes
¶
Core data models and tool abstractions for Mewbo orchestration.
AbstractTool
¶
Bases: ABC
Base tool with shared initialization helpers.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
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 350 351 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 | |
__init__(name: str, description: str, model_name: str | None = None, use_llm: bool = True) -> None
¶
Initialize tool configuration.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
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 | |
get_state(action_step: ActionStep | None = None) -> MockSpeaker
¶
Perform a read-only action.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
375 376 377 378 | |
run(action_step: ActionStep) -> MockSpeaker
¶
Execute the action based on the operation.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
380 381 382 383 384 385 386 | |
set_state(action_step: ActionStep | None = None) -> MockSpeaker
¶
Perform a state-changing action.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
370 371 372 373 | |
ActionStep
¶
Bases: BaseModel
Action step with validation metadata.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
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 | |
OrchestrationState
¶
Bases: BaseModel
State for the orchestration loop.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
terminal_status() -> Literal['completed', 'failed', 'cancelled']
¶
Project this settled state onto the terminal a spawner is told.
done answers "did the loop stop", never "did the task succeed", and
reading it as the latter is what let a doom-looped or budget-spent child
report completed to its parent. A run that stopped short is
failed; only a genuine natural completion whose ground-truth check
did not fail is completed.
verified is False is checked in its own right rather than trusted to
the reason: it is the authoritative record that a ground-truth check ran
and did not pass, and a claim contradicted by ground truth must not
depend on a second field spelling it the same way. It is checked BEFORE
cancellation because a contradicted claim is a substantive failure,
whereas a stop is only a stop.
A cancelled run is neither: nobody claimed the goal was reached and
nothing contradicted a claim, so folding it into failed would report
an error that never happened while completed reports a success that
never happened. It gets the AgentStatus member that means what
occurred. A completed/failed projection cannot express the one
terminal a user causes directly, which is why there is a third member.
The returned values are members of the hypervisor's AgentStatus
vocabulary — this is a NARROWING of that authority, not a vocabulary of
its own, and it is exactly SettledStatus. A halt reports as
failed because AgentStatus has no "stopped short" arm; the
precise reason is not lost — it rides the stop event's detail
and the attestation's done_reason.
Lives on the model rather than on whichever service happens to settle a run: the projection reads nothing but this state's own fields, so a second copy at another call site could only ever drift from this one.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
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 240 241 242 243 244 245 246 247 248 249 | |
Plan
¶
Bases: BaseModel
Plan with human-readable steps.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
116 117 118 119 120 121 122 123 124 | |
PlanStep
¶
Bases: BaseModel
High-level plan step produced by the planner.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
109 110 111 112 113 | |
TaskQueue
¶
Bases: BaseModel
Queue of executed tool steps and results.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
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 | |
validate_actions(field: list[ActionStep]) -> list[ActionStep]
classmethod
¶
Normalize and validate action steps.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
ToolResult
dataclass
¶
Structured tool execution result.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
51 52 53 54 55 56 57 58 59 | |
create_plan(step_data: list[dict[str, str]] | None = None, is_example: bool = True) -> Plan
¶
Create a Plan from serialized step data.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
404 405 406 407 408 409 410 411 412 413 414 415 | |
create_task_queue(action_data: list[ActionStepPayload] | None = None, is_example: bool = True) -> TaskQueue
¶
Create a TaskQueue from serialized action data.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
389 390 391 392 393 394 395 396 397 398 399 400 401 | |
get_task_master_examples(example_id: int = 0, available_tools: Sequence[str] | None = None) -> str
¶
Return serialized example plan data.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
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 | |
set_available_tools(tool_ids: list[str]) -> None
¶
Update available tool IDs for validation.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
62 63 64 65 | |
mewbo_core.contracts.types
¶
Shared type definitions for core components.
ActionPlanPayload
¶
Bases: TypedDict
Payload describing an action plan.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
21 22 23 24 | |
ActionStepPayload
¶
Bases: TypedDict
Serialized tool call data sent to/from execution.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
27 28 29 30 31 32 33 34 35 36 | |
AgentMessagePayload
¶
Bases: TypedDict
Payload describing an intermediate agent text message.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
161 162 163 164 165 166 | |
AssistantPayload
¶
Bases: TypedDict
Payload describing an assistant response.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
95 96 97 98 | |
CompletionPayload
¶
Bases: TypedDict
Payload describing overall completion state.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.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 | |
DeviceToolCallPayload
¶
Bases: TypedDict
Payload for a client-declared device-tool invocation (device_tool_call).
Emitted when a session-bound ClientDeclaredTool (see client_tools.py)
is invoked; delivered to the client over the session's existing SSE stream.
The client fulfils the call by POSTing its result back, presenting
call_token (single-use, hmac.compare_digest-compared). Honest
threat model: this proves the responder had SESSION-STREAM READ ACCESS
(received the SSE event) and prevents replay (single-use, consumed-once)
— it does NOT prove the response came from the physical device the call
was dispatched to. Any concurrent viewer of the same session's stream
(e.g. a console tab) receives the same token and could answer on the
device's behalf; this is the accepted threat model, distinct from the
session's own API key.
expires_at is an epoch-seconds deadline after which the server gives
up waiting and resolves the tool call with a device_timeout error.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
Event
¶
Bases: TypedDict
Base event payload stored in transcripts.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
443 444 445 446 447 | |
EventRecord
¶
Bases: Event
Event payload with a persisted timestamp.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
450 451 452 453 | |
LlmCallEndPayload
¶
Bases: TypedDict
Payload emitted for a SUCCESSFUL llm_call_end event.
Brackets the whole RetryStrategy logical call — retries and fallback
attempts included, not just the final attempt — so duration_ms is the
wall time a caller actually waited, not the cheapest leg of it. The failed
variant of this event (success: False) carries error_type/reason
instead and is a separate, untyped payload — it never reaches this arm.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
LlmFallbackPayload
¶
Bases: TypedDict
Payload emitted when the run advances to another model (llm_fallback).
reason is either a classifier reason (quota_exhausted,
no_deployments, context_window, auth) for a switch_model
decision, or retries_exhausted when the per-model retry cap tripped on a
transient error. sticky is true when the destination model is pinned for
the rest of the run (always true under the escalation policy).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
LlmRetryPayload
¶
Bases: TypedDict
Payload emitted before a same-model LLM retry (llm_retry event).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
198 199 200 201 202 203 204 205 206 207 208 209 210 | |
PermissionPayload
¶
Bases: TypedDict
Payload emitted for permission decisions.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
39 40 41 42 43 44 45 | |
PlanApprovedPayload
¶
Bases: TypedDict
Payload emitted when the user approves a proposed plan.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
178 179 180 181 182 | |
PlanProposedPayload
¶
Bases: TypedDict
Payload emitted when the LLM calls exit_plan_mode.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
169 170 171 172 173 174 175 | |
PlanRejectedPayload
¶
Bases: TypedDict
Payload emitted when the user rejects a proposed plan.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
185 186 187 188 189 | |
PlanStepPayload
¶
Bases: TypedDict
Payload describing a single plan step.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
14 15 16 17 18 | |
RecoveryHaltPayload
¶
Bases: TypedDict
Payload emitted when the doom-loop guard halts a no-progress run.
The recovery event with action == "halt_no_progress" — distinct from
:class:RecoveryPayload (user-triggered retry/continue).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
258 259 260 261 262 263 264 265 266 267 268 269 | |
RecoveryPayload
¶
Bases: TypedDict
Payload emitted when the user triggers retry/continue after a failure.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
192 193 194 195 | |
SubAgentPayload
¶
Bases: TypedDict
Payload describing a sub-agent lifecycle event.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
TodoItemPayload
¶
Bases: TypedDict
One authoritative todo item: a label plus its lifecycle status.
status is one of pending / in_progress / completed (see
update_todos.TODO_STATUSES).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
272 273 274 275 276 277 278 279 280 | |
TodosPayload
¶
Bases: TypedDict
Payload for the authoritative live todo list (todos event).
Re-emitted in FULL on every update_todos call (compaction-resilient).
source discriminates the agent's live working set (agent) from an
approved plan's roadmap (plan); agent_id attributes it to the
emitting agent (the root, in practice).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
283 284 285 286 287 288 289 290 291 292 293 294 | |
ToolCallPayload
¶
Bases: TypedDict
Payload describing a tool invocation that is about to be dispatched.
The initiation half of a tool call, emitted BEFORE the tool is awaited so a
client can show the step while it runs rather than only once it finished.
tool_call_id is the provider's call id and the only correlation key to the
matching :class:ToolResultPayload; it is "" when the provider supplied
none, which means "not correlatable" and never "shares a key with the others".
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
ToolResultPayload
¶
Bases: TypedDict
Payload describing the outcome of a tool invocation.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
UserPayload
¶
Bases: TypedDict
Payload describing a user message.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
83 84 85 86 87 88 89 90 91 92 | |
UserQuestionAnswerItemPayload
¶
Bases: TypedDict
One delivered answer (indexes XOR text) on the answered event.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
365 366 367 368 369 | |
UserQuestionAnsweredPayload
¶
Bases: TypedDict
Resolution record for a question group (user_question_answered).
outcome is answered / declined (user sent a message instead)
/ interrupted / cancelled / timed_out; answers and
notes are present only when answered. Every surface — not just the one
that answered — folds this onto its pending card.
Only answered settles a card. The other four record that the RUN
stopped waiting, which is not the same as the question being resolved: the
user may still answer, and that answer reaches the session as a new turn.
A surface that greys out its card on any terminal outcome would be hiding
the affordance precisely when the user finally came back to use it.
delivery distinguishes the two landing paths for an answered
outcome — run (the blocked tool call took it) vs message (the run
had moved on, so it arrived as a new turn).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
UserQuestionItemPayload
¶
Bases: TypedDict
One question in a user_question event's group.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
329 330 331 332 333 334 335 | |
UserQuestionOptionPayload
¶
Bases: TypedDict
One selectable option on a user_question event.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
322 323 324 325 326 | |
UserQuestionPayload
¶
Bases: TypedDict
Payload announcing a pending ask-user question group (user_question).
Emitted by the api's question dispatcher when the root agent calls
ask_user_question (see ask_user.py); rides the session's SSE
stream + backlog replay so every attached surface renders the card.
call_token follows the device_tool_call threat model verbatim:
it proves session-stream read access and prevents replay — not which
surface answered.
This event is the DURABLE record of the question, and that is what makes
a late answer possible. The in-process waiter registry is a rendezvous,
not a store; it dies with the run. A client rendering this card long after
the run moved on can still answer, because the answer route recovers the
questions and the token from THIS payload. So the two additive fields are
not decoration: timeout_seconds is what a surface needs to show how
long the run will wait, and notes_placeholder is what makes it render
the free-text box at all. Both are None when the run declared neither.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
VerificationPayload
¶
Bases: TypedDict
One verifier-gate check verdict (verification event).
Bounded scalars ONLY: the grounded verifier stdout/stderr is injected into
the model's own context (a SystemMessage), never onto the wire — so a
chatty command can't bloat transcripts. attempt is 1-based; passed
is the interpreted verdict; exit_code/timed_out explain a failure.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
mewbo_core.config
¶
Central JSON configuration for Mewbo.
APIAuthConfig
¶
Bases: BaseModel
Identity & access management for the REST API (opt-in).
Off by default: with no auth block — or enabled: false — every
request resolves to the built-in full-power identity and the server behaves
exactly as it did before IAM existed. The union-shaped fields
(authenticators, the group mappings, bootstrap) are carried here as
open objects and validated in full against the identity kernel's typed models
at server startup, which refuses to boot on an invalid block. These settings
are documented in full in docs/authentication.md.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 | |
APIAuthScimConfig
¶
Bases: BaseModel
SCIM 2.0 provisioning settings.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 | |
APIAuthSessionConfig
¶
Bases: BaseModel
Browser session/cookie settings for federated logins.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 | |
APIConfig
¶
Bases: BaseModel
REST API authentication.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 | |
AgentConfig
¶
Bases: EnvOverridable
Sub-agent hypervisor settings.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 | |
ladder_budget_seconds(fallback_count: int) -> float
¶
Worst-case seconds the configured model ladder can spend in one turn.
The primary rung may spend llm_call_timeout x llm_call_retries; every
fallback rung may spend llm_call_timeout x retry.fallback_retries.
The rung count arrives as an ARGUMENT because the ladder is declared
under llm, not here — this model must never reach across the config
tree to read it.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 | |
unreachable_rung(fallback_count: int) -> tuple[float, float] | None
¶
(needed, deadline) when the ladder cannot fit, else None.
THE BUDGET LAW. retry.turn_deadline bounds ONE logical LLM call
across every retry and every fallback, and it is checked between
attempts. So rungs that can together consume the whole budget leave
every rung below them unreachable — the chain advances, finds the
deadline spent, and stops. Cross-model fallback then silently never
runs, which reads as a provider-wide outage rather than as the tuning
mistake it is.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 | |
AppConfig
¶
Bases: BaseModel
Typed configuration for the Mewbo runtime.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 | |
load(path: str | Path) -> AppConfig
classmethod
¶
Load configuration from a JSON file.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3994 3995 3996 3997 3998 | |
preflight(*, disable_on_failure: bool = True) -> dict[str, dict[str, Any]]
async
¶
Run async validation checks for optional integrations.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 | |
probe_write_access(path: str | Path) -> ConfigWriteAccess
classmethod
¶
Report whether path could be persisted to, without modifying it.
The probe creates and removes a temporary file in the directory an
atomic :meth:write would stage into — exactly the permission that
write needs — so it never opens, truncates or replaces an existing
config. A missing parent is probed at its nearest existing ancestor
(where mkdir would have to write) rather than being created, so the
probe itself has no side effects at all.
It answers for the SAME rungs :meth:write will try, fallback
included. Reporting a directory-only verdict would say "not writable"
for a single-file-mounted config that saves perfectly well in place,
and a console that disables its Save button on this would then be
refusing a write the server would have accepted.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 | |
to_json(*, indent: int = 2) -> str
¶
Serialize config to JSON.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4000 4001 4002 | |
write(path: str | Path, *, indent: int = 2) -> None
¶
Atomically persist THIS MODEL as the whole config file.
Renders every declared field, so an unset one is written out at its
resolved default. That suits a caller scaffolding a fresh config; it is
the wrong tool for saving an edit to a file someone already maintains —
use :meth:write_document for that and see the warning there.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4004 4005 4006 4007 4008 4009 4010 4011 4012 | |
write_document(path: str | Path, document: Mapping[str, Any], *, indent: int = 2) -> None
classmethod
¶
Atomically persist an already-shaped config document.
Editing a config means writing back the operator's OWN document with
their change applied — never a re-rendering of the validated model.
Re-rendering looks equivalent and is not, in two ways that both corrupt
a shared file. It converts every unset field into an explicit default,
so "leave this to the runtime" silently becomes "pin this forever". And
because several defaults are derived from the environment of whichever
process happens to save (MEWBO_HOME feeding the runtime.*
directories, the storage driver's URI), a save from inside a container
rewrites the shared file with container-only absolute paths and
hostnames, which then breaks every other consumer of it. The model is
still the validator — nothing unvalidated reaches disk — it is just not
the thing serialized. This also keeps a key the model does not declare
($schema, a block for a feature with no typed field yet) instead of
dropping it, since extra="ignore" discards those at validation.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 | |
AuthenticatorEntry
¶
Bases: BaseModel
One identity source in api.auth.authenticators.
Deliberately PERMISSIVE (extra="allow"): the authoritative model is the
identity kernel's discriminated authenticator union, which sits a layer
above core and must never be imported down into it. Every kind-specific
setting therefore rides through here untyped and is re-validated STRICTLY —
per-kind, extra="forbid" — when the server builds its auth settings at
startup, which refuses to boot on an invalid entry. So this model is not a
second validator and must not grow into one.
What it DOES declare is the plaintext credentials, because the config API
redacts by SCHEMA: a field carries x-secret or its value is returned to
every caller holding config.read. An untyped dict contributes no
schema, so nothing marked these and they were served in the clear. Core
knows these two NAMES — a stable wire contract it shares with the identity
kernel — without knowing which kind each belongs to or what it means, which
is precisely the sliver of knowledge redaction needs and no more.
kind/name stay typed so an entry is self-describing.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 | |
CLIConfig
¶
Bases: BaseModel
Terminal CLI display and interaction settings.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 | |
CliRemoteConfig
¶
Bases: BaseModel
Opt-in remote endpoint for the terminal CLI; CLI-scoped ONLY.
Every other surface ignores this block. When base_url is set the CLI is
still a strictly-local engine (the run loop + authoritative JSONL transcript
stay on this host), but it additionally (a) mirrors each session event to the
remote REST API fire-and-forget for cross-device visibility and (b)
auto-registers the Mewbo MCP server so the product tools
(ask_wiki/search/structured_query + wiki-graph reads) appear in
the CLI registry and execute remotely (compute offload). Empty ⇒ fully local.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 | |
enabled: bool
property
¶
True when a remote base URL is configured (sync + product tools on).
CompactionConfig
¶
Bases: BaseModel
Summarization prompt selection for conversation compaction.
caveman_mode enables a rule-augmented "caveman" prompt that
instructs the summarizer LLM to drop articles, filler, pleasantries,
and hedging while preserving code, paths, URLs, and error strings
verbatim. Reduces output tokens in the compaction summary without
changing the
<analysis>/<summary> response structure downstream parsers expect.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 | |
ConfigCheck
dataclass
¶
Result of a configuration preflight check.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 | |
to_dict() -> dict[str, Any]
¶
Serialize the check result to a dictionary.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4302 4303 4304 4305 4306 4307 4308 4309 4310 | |
ConfigWriteAccess
¶
Bases: BaseModel
Whether the configuration store can be persisted to.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3500 3501 3502 3503 3504 3505 3506 3507 | |
ConfigWriteError
¶
Bases: RuntimeError
Raised when the configuration file cannot be persisted.
A bare OSError escaping the persistence path reaches an HTTP surface as
an opaque 500 with a traceback and nothing a deployment can act on. This
carries the two things a caller needs instead: a stable machine code to
branch on and an operator-actionable reason to render. The absolute
path stays on the exception (and therefore in the logs) rather than in
the prose, because reason is user-facing copy and a server path is not.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 | |
__init__(path: Path, code: str, reason: str) -> None
¶
Build the failure from an already-classified code/reason.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3470 3471 3472 3473 3474 3475 | |
classify(exc: OSError) -> tuple[str, str]
classmethod
¶
Map an OSError to its stable (code, reason) pair.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3482 3483 3484 3485 3486 | |
from_oserror(path: Path, exc: OSError) -> ConfigWriteError
classmethod
¶
Build the typed failure for an OSError raised while persisting.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3493 3494 3495 3496 3497 | |
is_structural(exc: OSError) -> bool
classmethod
¶
Whether exc means atomic replacement can never work at this path.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3488 3489 3490 3491 | |
reason_for(code: str) -> str
classmethod
¶
Return the operator-facing prose for a stable machine code.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3477 3478 3479 3480 | |
ContextConfig
¶
Bases: BaseModel
Context window selection and event filtering.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 927 928 929 930 931 932 933 934 935 936 937 938 | |
EnvOverridable
¶
Bases: BaseModel
Base for a section whose fields may be OVERRIDDEN from the environment.
A field declares the variable that overrides it next to the field itself, and this base applies every such declaration in one place::
driver: str = Field(
"json",
json_schema_extra={"x-env-var": "MEWBO_STORAGE_DRIVER"},
)
Adding an override is therefore a declaration, not another hand-written
validator that reads os.environ. A hand-written one is invisible to
configs/app.schema.json and so to the console and the docs; a
declaration reaches both, because x-env-var is emitted on the field's
schema node like every other x- annotation.
This is the OPPOSITE direction to :class:EnvRef, and the two are not
interchangeable:
- an :class:
EnvRefis written BY the operator inapp.jsonas the value${VARIABLE}, names a variable the file has chosen to defer to, and is an error at load when that variable is unset; - an override is declared BY this module on a field the operator may have set to a perfectly good literal, and takes precedence over it. An unset — or empty — variable is simply "not overridden", never an error, because the file value is still the answer.
The override is applied to the raw payload, so the field's own validators
still run over it: a bad MEWBO_STORAGE_DRIVER is rejected exactly as a
bad driver in the file is.
Cost: O(1) — one pass over a section's declared fields, at validation.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
EnvRef
¶
Bases: BaseModel
A config value that NAMES an environment variable instead of holding one.
Written as a value that is exactly ${VARIABLE}, so a secret can stay in
the environment and out of app.json::
{"llm": {"api_key": "${OPENAI_API_KEY}"}}
Two deliberate limits, both there so this stays a naming convention rather than a template language:
- the reference is the WHOLE value or it is not a reference at all — a value
that merely contains
${is left exactly as written, which is what lets a literal password contain those characters with nothing to escape; - a reference to a variable that is not set is an error at load, never an empty string. Substituting empty turns a missing secret into a puzzling 401 much later; naming a variable is a claim that it will be there, and a claim is worth checking. A variable set to the empty string IS set, and resolves to empty — that is the way to say a value is deliberately blank.
Not to be confused with :class:EnvOverridable, which runs the other way
round: there the FIELD names a variable that overrides whatever the file
says, and an unset variable is a no-op rather than an error.
Cost: O(one record) — one walk of the config document, on load only.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 | |
parse(value: Any) -> EnvRef | None
classmethod
¶
Return the reference value spells, or None if it spells none.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3544 3545 3546 3547 3548 3549 3550 | |
resolve(environ: Mapping[str, str], where: str) -> str
¶
Return the variable's value, or raise naming both it and where.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 | |
resolve_document(payload: Any, environ: Mapping[str, str], where: str = '') -> Any
classmethod
¶
Rebuild payload with every reference in it replaced by its value.
Returns the payload unchanged — the same object, not a copy — when it
holds no reference, so the common case allocates nothing and the
caller's document is never touched. See
:meth:AppConfig._drop_retired_keys for why not touching it matters.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 | |
FallbackConfig
¶
Bases: BaseModel
Opt-in cross-model fallback policy.
Disabled by default so a run never fans out to a different model, with different cost, latency, output style and prompt-cache behaviour, without an explicit opt-in. When disabled, an error that is hopeless on the current model (e.g. quota exhausted) halts cleanly for one-click recovery instead.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
HomeAssistantConfig
¶
Bases: BaseModel
Home Assistant smart-home integration.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 | |
HookEntry
¶
Bases: BaseModel
A single hook configuration entry.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 | |
HooksConfig
¶
Bases: BaseModel
External shell hooks fired during the session lifecycle.
Command hooks run unsandboxed shell commands with the API/CLI process's
own privileges (see HookEntry.command's docstring) — a caller who can
PATCH this section can execute arbitrary code on the host. x-protected
puts the whole section in the same never-read-never-written-via-API tier
as the other host-level settings in this file: settable only by editing
the config file directly, never over the network regardless of
credential (see ConfigSchemaView in apps/mewbo_api).
Source code in packages/mewbo_core/src/mewbo_core/config.py
1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 | |
LLMConfig
¶
Bases: BaseModel
LLM provider connection and model selection.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 | |
effective_fallback_models() -> list[str]
¶
Resolve the active fallback ladder from this instance.
The precedence rule lives HERE, on the data that owns it, so the
module-level accessor (which reads the process-wide config) and any
validator holding a not-yet-installed AppConfig cannot disagree
about how long the ladder is.
Source code in packages/mewbo_core/src/mewbo_core/config.py
690 691 692 693 694 695 696 697 698 699 700 | |
resolve_available_model(model: str, *, fallback: str, timeout: float = 4.0) -> str
¶
Return model if the proxy still advertises it, else fallback.
Guards a persisted/stale model id (e.g. a wiki reindex replaying an old
submission) against a model the proxy has since retired, which would
otherwise fast-fail the whole run on an invalid-model 400. Best-effort:
if the model list can't be fetched we trust model (the caller's
retry/fallback ladder is the backstop). The provider prefix is ignored
on both sides (openai/x matches a bare x the proxy advertises).
Source code in packages/mewbo_core/src/mewbo_core/config.py
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 | |
LSPConfig
¶
Bases: BaseModel
Language Server Protocol integration settings.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 | |
LangfuseConfig
¶
Bases: BaseModel
Langfuse LLM observability integration.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 | |
MongoDBConfig
¶
Bases: EnvOverridable
MongoDB connection settings.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 | |
PermissionsConfig
¶
Bases: BaseModel
Tool execution permission policy.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 | |
PluginsConfig
¶
Bases: BaseModel
Plugin system configuration.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 | |
resolve_install_dir() -> Path
¶
Uses install_path if set, otherwise resolve_mewbo_home() / 'plugins'.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1729 1730 1731 1732 1733 | |
resolve_marketplace_dirs(*, sync: bool = True) -> list[Path]
¶
Paths to search for marketplace.json caches.
Scans both Claude Code's and our own marketplace directories.
When sync is True and self.marketplaces lists repos that aren't
yet cloned locally, sync_marketplaces clones them first.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 | |
resolve_registry_paths() -> list[Path]
¶
Paths to search for installed_plugins.json: CC cache + our own.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1735 1736 1737 1738 1739 1740 1741 | |
ProjectConfig
¶
Bases: BaseModel
A project directory exposed to the REST API for session scoping.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 | |
RetiredKey
¶
Bases: BaseModel
One config key that no longer exists, and what to tell whoever still sets it.
Deleting a field does not delete the key from the OPERATOR'S app.json,
and what that key does next is opposite in the two section kinds: under
extra="ignore" it is swallowed in silence, so a knob that stopped
working looks exactly like one that works; under extra="forbid" it is a
ValidationError during startup, so the process will not boot.
A retired key is therefore pruned from the payload before validation — so a
forbid section never sees it — and announced once per key per process,
so the silence becomes an instruction to delete the line.
Cost: O(one record) — one walk per declared retired key over the config
document, on the load path only.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 | |
dotted: str
property
¶
The key as an operator would read it in app.json.
prune(payload: dict[str, Any]) -> tuple[dict[str, Any], bool]
¶
Return payload without this key, plus whether it was there at all.
Copies only the dicts ALONG the key's own path and shares every other
branch, so the caller's document is never mutated and nothing else in it
is duplicated. A whole-document deep copy would be the obvious
alternative and is not available: a payload reaching model_validate
may already hold constructed submodels, which do not survive a
JSON round trip.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 | |
RetryConfig
¶
Bases: BaseModel
Automatic LLM-call retry / fallback resilience knobs.
Same-model retry hardening (full-jitter backoff, circuit breaker, retry
budget, wall-clock deadline, doom-loop halt) is always on; cross-model
fallback is opt-in via llm.fallback. Defaults are calibrated from
production agent loops, not the tighter vendor-SDK defaults.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 | |
RuntimeConfig
¶
Bases: BaseModel
Runtime environment settings.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 275 276 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 350 351 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 | |
SafetyConfig
¶
Bases: BaseModel
Master switch for the operator-owned tool-call gate and session observer.
OFF by default. While off, .mewbo/policy/ and .mewbo/monitor/ are
never read, no rule is built and no event is emitted — a deployment that
never sets this section pays nothing. There is deliberately no per-project
override and no other knob here: discovery path, rule precedence and the
built-in self-protection rule are fixed by the plane itself, not
config-tunable, because a knob that could redirect discovery or reorder
rules would be a knob that could weaken the guardrail it configures.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 | |
ScgConfig
¶
Bases: BaseModel
Operator-facing knobs for the Source Capability Graph (agentic search).
Source code in packages/mewbo_core/src/mewbo_core/config.py
3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 | |
ScgTierModelsConfig
¶
Bases: BaseModel
Per-tier model mapping: the tier picks the brain, not just the budget.
A tier maps to the LLM that drives the whole run (orchestrator session AND
its probe sub-agents, which inherit the session model). An empty string
falls back to llm.default_model. An explicit per-request model
override (where the endpoint offers one) always wins over the tier map.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 | |
ScgTraversalConfig
¶
Bases: BaseModel
Traversal defaults for SCG search (the per-run tier budget knob).
Source code in packages/mewbo_core/src/mewbo_core/config.py
3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 | |
SpeechConfig
¶
Bases: BaseModel
Which gateway models handle speech, and which gateway serves them.
The three connection fields are all optional and all empty by default,
because the common deployment has one gateway: speech falls back to
llm.api_base/llm.api_key whenever these are blank, so an install
that never writes a speech block still works. They exist for the
deployment that genuinely splits the two, which is a real shape — a
self-hosted synthesis backend beside a hosted chat provider — and refusing
to represent it would only push the operator into running one gateway they
do not want.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
SpeechSttConfig
¶
Bases: BaseModel
Speech to text: which model turns a recording into words.
Source code in packages/mewbo_core/src/mewbo_core/config.py
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 | |
SpeechTtsConfig
¶
Bases: BaseModel
Text to speech: which model reads an answer aloud, and in whose voice.
Source code in packages/mewbo_core/src/mewbo_core/config.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 | |
StorageConfig
¶
Bases: EnvOverridable
Session storage backend configuration.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 | |
TokenBudgetConfig
¶
Bases: BaseModel
Token budget and auto-compaction thresholds.
Source code in packages/mewbo_core/src/mewbo_core/config.py
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | |
ToolSearchConfig
¶
Bases: BaseModel
Deferred tool loading via on-demand schema fetching.
When mode='on', MCP tool schemas (and any spec with
metadata.deferred=True) are stripped from the initial bind_tools
call and surfaced to the model by name only via
<available-deferred-tools>. The model fetches schemas it actually
needs by calling the built-in tool_search tool. Mirrors Claude
Code's ToolSearchTool mechanism, saving substantial context tokens
on sessions with many MCP servers connected.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 | |
TriggersConfig
¶
Bases: BaseModel
Reverse-invocation trigger subsystem.
The durable peer of the sub-agent hypervisor: a background watcher that
fires time / cron / CI / forge-PR / webhook triggers and re-invokes the
sessions that armed them. OFF by default (enabled=False), so the feature
is un-enableable until an operator turns it on and a stock deployment pays
nothing. The lower half of this section is the admission policy the
schedule_trigger tool + the arm route enforce (mirrors
mewbo_core.triggers.policy.TriggerPolicy field-for-field; to_policy
builds one).
Source code in packages/mewbo_core/src/mewbo_core/config.py
1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 | |
to_policy() -> Any
¶
Build the TriggerPolicy these fields describe.
Lazy import keeps this config module free of any dependency on the
triggers domain package (and sidesteps an import cycle, since the
trigger store reads get_config_value from here).
Source code in packages/mewbo_core/src/mewbo_core/config.py
1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 | |
UntrustedCwdRegistry
¶
Directories whose own .mcp.json must never enter the merged config.
A working directory is normally a developer's own project, so its
.mcp.json legitimately contributes MCP servers at the highest priority
tier. That stops being true the moment the directory holds content this
deployment did not author — a repository cloned for indexing being the
worked example: its .mcp.json is attacker-supplied, and admitting it
both OVERRIDES a same-named operator server and, because _deep_merge
recurses, lets a file naming only env keep the operator's command
and credential while adding a variable of its own. Merge order cannot fix
that — the tier has to be excluded, not out-prioritised.
The caller that CREATED the directory is the only one that knows this, so it registers the root here once. Every resolution of the merged config then excludes it — the initial registry build and every re-resolution a tool runner performs at invocation time alike — without the knowledge having to be threaded through each of them. Registration is by explicit path, never by pattern-matching one: a heuristic on the directory name would be exactly the accidental control this exists to remove.
Registering a root covers that directory and everything beneath it, so one registration of a clone ROOT covers every job that clones into it.
Cost: O(registered roots) per lookup, on a path already doing file I/O.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 | |
__init__() -> None
¶
Initialize an empty, lock-guarded registry.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4560 4561 4562 4563 | |
clear() -> None
¶
Drop every registered root (tests).
Source code in packages/mewbo_core/src/mewbo_core/config.py
4590 4591 4592 4593 | |
contains(path: str | Path | None) -> bool
¶
True when path is at or below a registered untrusted root.
A path that cannot be resolved is reported as untrusted: this gate is the one place where failing closed costs a feature and failing open spawns a process.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 | |
register(path: str | Path) -> None
¶
Mark path and everything under it as an untrusted working directory.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4573 4574 4575 4576 4577 4578 4579 4580 | |
roots() -> tuple[str, ...]
¶
Return the registered roots, sorted, for diagnostics.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4595 4596 4597 4598 | |
unregister(path: str | Path) -> None
¶
Drop a previously registered root (no-op when absent).
Source code in packages/mewbo_core/src/mewbo_core/config.py
4582 4583 4584 4585 4586 4587 4588 | |
WebIdeConfig
¶
Bases: EnvOverridable
Config for the per-session code-server "Open in Web IDE" feature.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 | |
WikiConfig
¶
Bases: BaseModel
Operator-facing knobs for the wiki subsystem.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 | |
WikiEmbeddingConfig
¶
Bases: BaseModel
Embedding settings for the wiki indexer.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 | |
WikiMemoryConfig
¶
Bases: BaseModel
Knobs for the multiplex memory layer (atomic insights over the graph).
Source code in packages/mewbo_core/src/mewbo_core/config.py
3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 | |
WikiPhaseTimeoutsConfig
¶
Bases: BaseModel
How long each long-running indexing phase may run before it is called wedged.
These are WEDGE DETECTORS, not pacing knobs. Every phase below runs off the agent's event loop, so raising a value never makes indexing feel slower and lowering one never makes it faster — the only thing a timeout decides is how long a stuck phase is allowed to look like a working one. Each default is sized from that phase's own honest worst case, which depends on the repositories and the hardware a deployment actually has; that is why they are knobs rather than constants. When a phase does expire, its work is NOT stopped (a thread mid-parse or mid-clone reaches no cancellation point) — the tool reports the phase as wedged and the work continues in the background.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 | |
WikiRefreshConfig
¶
Bases: BaseModel
Thresholds for the on-demand incremental refresh.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 | |
effective_fallback_models() -> list[str]
¶
Resolve the active fallback model chain honoring the opt-in policy.
Precedence: when llm.fallback.enabled is set, use llm.fallback.models
(falling back to the flat llm.fallback_models if the typed list is
empty). When fallback is disabled, a non-empty llm.fallback_models is
still honored; otherwise there is no fallback.
A thin accessor over :meth:LLMConfig.effective_fallback_models, which owns
the rule — the config-load-time budget check has to apply the SAME
precedence to an AppConfig that is not the process-wide one yet.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 | |
ensure_app_config(path: str | Path) -> None
¶
Write the default config file if missing.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4450 4451 4452 4453 4454 4455 | |
ensure_example_configs(app_path: str | Path | None = None, mcp_path: str | Path | None = None) -> tuple[Path, Path]
¶
Write example config files if missing. Returns (app_path, mcp_path).
Source code in packages/mewbo_core/src/mewbo_core/config.py
4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 | |
get_app_config_path() -> str
¶
Return the configured app JSON path.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4373 4374 4375 4376 4377 | |
get_config() -> AppConfig
¶
Return cached AppConfig instance.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 | |
get_config_section(*keys: str) -> dict[str, Any]
¶
Return a config section as a dictionary.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4440 4441 4442 4443 4444 4445 4446 4447 | |
get_config_value(*keys: str, default: Any | None = None) -> Any
¶
Return a nested config value or default.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 | |
get_last_preflight() -> dict[str, dict[str, Any]] | None
¶
Return the most recent preflight results if available.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4287 4288 4289 | |
get_mcp_config_path() -> str
¶
Return the configured MCP JSON path.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4380 4381 4382 4383 4384 4385 4386 | |
get_merged_mcp_config(cwd: str | None = None, *, extra_servers: dict[str, Any] | None = None, trust_cwd: bool = True) -> dict[str, Any]
¶
Load and merge MCP configs: plugin extras + global + subtree + CWD .mcp.json.
Priority (lowest → highest): extra_servers < global < subtree (deep→shallow) < CWD.
Returns the merged config dict with a servers key.
When MCP is disabled (via set_mcp_config_path(None)), returns {}.
A server entry is a command this process will spawn, and the spawn
happens during config resolution rather than at invocation — so no
downstream tool allowlist can gate it. The two directory-derived tiers
(cwd itself and the subtree walk beneath it) are therefore admitted
only when the directory is trusted: pass trust_cwd=False, or register
the directory via :data:register_untrusted_cwd, and BOTH are skipped
entirely rather than merged at a lower priority — a partial merge would
still let a repo-supplied env ride inside an operator's server.
trust_cwd defaults to True as a COMPATIBILITY AFFORDANCE, not
because trusting is the safe answer. The default exists so a developer's
own project keeps contributing its .mcp.json, which is a real feature.
It is not a judgement that an unspecified directory is safe, and it is why
a caller who simply forgets this parameter gets the permissive behaviour.
Any cwd derived from request input MUST pass trust_cwd=False
explicitly — a path off a query string, a repository checkout, a PR
worktree, an indexing clone. Registering the directory via
:data:register_untrusted_cwd covers directories this deployment creates,
but it can never cover a path a CALLER names: such a path is by
construction absent from that registry, and those are exactly the ones
that need denying. There is no fallback behind this argument.
Cost: O(one directory tree) — the subtree walk is depth-capped, and is
skipped altogether for an untrusted directory.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 | |
get_version() -> str
¶
Return the package version from pyproject.toml (via importlib.metadata).
Tries mewbo-core first (always installed), then the workspace
package (only available in local dev with uv sync).
Source code in packages/mewbo_core/src/mewbo_core/config.py
148 149 150 151 152 153 154 155 156 157 158 159 | |
reset_config() -> None
¶
Clear cached configuration and overrides.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 | |
resolve_mewbo_home() -> Path
¶
Return the Mewbo home directory ($MEWBO_HOME or ~/.mewbo).
Source code in packages/mewbo_core/src/mewbo_core/config.py
79 80 81 82 83 84 | |
set_app_config_path(path: str | Path) -> None
¶
Override the app config path (tests only).
Source code in packages/mewbo_core/src/mewbo_core/config.py
4333 4334 4335 4336 4337 | |
set_config_override(payload: dict[str, Any], *, replace: bool = False) -> None
¶
Override config values in-memory (tests/CLI).
Source code in packages/mewbo_core/src/mewbo_core/config.py
4363 4364 4365 4366 4367 4368 4369 4370 | |
set_mcp_config_path(path: str | Path | None) -> None
¶
Override the MCP config path (tests only).
Source code in packages/mewbo_core/src/mewbo_core/config.py
4340 4341 4342 4343 4344 4345 4346 4347 4348 | |
start_preflight(config: AppConfig | None = None, *, disable_on_failure: bool = True, on_complete: Callable[[dict[str, dict[str, Any]]], None] | None = None) -> threading.Thread
¶
Run config preflight checks in a background thread.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 | |
mewbo_core.components
¶
Helpers for optional components and observability integration.
ComponentStatus
dataclass
¶
Describe whether a component is enabled and why.
Source code in packages/mewbo_core/src/mewbo_core/components.py
68 69 70 71 72 73 74 75 | |
LangfuseTraceLink
dataclass
¶
The trace — and the observation inside it — a new span must attach to.
trace_context is the ONLY channel through which a span can name a
parent observation, and naming one is not optional: given a trace_id
with no parent_span_id the SDK mints a RANDOM 16-hex span id, wraps it
in a NonRecordingSpan and parents the new span to it, so the exported
parentObservationId points at an observation that is never sent. Every
span opened that way is an orphan by construction, at every depth — which
is why a span tree built from those spans cannot be walked root→child and
per-agent token attribution from a trace alone is impossible.
The cure is to pass trace_context only where it buys something:
- Inside one task, ambient OTel context already carries the enclosing
span, so a nested span needs no
trace_contextat all — omitting it is what makes it a real child rather than a phantom-parented root. - Across an
asyncio.create_taskboundary, the spawning span is no longer the ambient one by the time the child opens its first span. There the link must be captured on the spawning side and handed over, which is the one case where an explicitparent_span_idis the right answer. - With nothing ambient at all (the first span of an invocation) the trace id still has to be pinned, so the phantom parent is unavoidable — it lands once, on a genuine trace root, instead of on every span.
Every read of live tracer state is best-effort: tracing is a side effect at
the edge, so a link that cannot be captured degrades to None and the
span falls back to the behaviour it had before rather than failing a run.
Source code in packages/mewbo_core/src/mewbo_core/components.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 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 | |
as_trace_context() -> TraceContext
¶
Render this link as the mapping the Langfuse SDK accepts.
Source code in packages/mewbo_core/src/mewbo_core/components.py
302 303 304 305 306 307 | |
bind() -> Iterator[None]
¶
Bind this link for the duration of the block.
asyncio.create_task copies the calling context, so a task created
inside this block carries the link and opens its first span as a real
child of the captured observation.
Source code in packages/mewbo_core/src/mewbo_core/components.py
321 322 323 324 325 326 327 328 329 330 331 332 333 | |
capture() -> LangfuseTraceLink | None
classmethod
¶
Capture the span a task started from HERE, before the task starts.
Call this on the spawning side of an asyncio.create_task boundary,
while the spawning span is still ambient. The live ambient observation
wins; a context with no ambient span falls back to whatever link is
already bound, so capturing twice down one spawn path is idempotent
rather than parent-erasing.
Source code in packages/mewbo_core/src/mewbo_core/components.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
current() -> LangfuseTraceLink | None
classmethod
¶
The link bound to this context by :func:langfuse_session_context.
Source code in packages/mewbo_core/src/mewbo_core/components.py
266 267 268 269 | |
from_trace_context(trace_context: TraceContext | None) -> LangfuseTraceLink | None
classmethod
¶
Read a link out of the SDK's TraceContext mapping, if it holds one.
Source code in packages/mewbo_core/src/mewbo_core/components.py
256 257 258 259 260 261 262 263 264 | |
trace_context_for_new_span() -> TraceContext | None
¶
What a span opening under this link should pass as trace_context.
None means "nest ambiently" — the enclosing span of this same trace
is already current, so OTel parents the new span for free and passing a
context would replace that real parent with a phantom one.
Source code in packages/mewbo_core/src/mewbo_core/components.py
309 310 311 312 313 314 315 316 317 318 319 | |
build_langfuse_handler(*, user_id: str, session_id: str, trace_name: str, version: str, release: str, trace_context: TraceContext | None = None) -> LangfuseCallbackHandler | None
¶
Create a Langfuse callback handler when configured.
Source code in packages/mewbo_core/src/mewbo_core/components.py
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 | |
format_component_status(statuses: Iterable[ComponentStatus]) -> str
¶
Format component statuses for inclusion in prompts.
Source code in packages/mewbo_core/src/mewbo_core/components.py
175 176 177 178 179 180 181 182 | |
langfuse_child_task_link(link: LangfuseTraceLink | None = None) -> Iterator[None]
¶
Hand a parent span to tasks created inside this block.
The one seam for the asyncio.create_task boundary. It takes both shapes
the boundary comes in: pass a link captured earlier when the task is
launched somewhere other than where it was spawned (a deferred unit), or
omit it to capture the ambient span right here. Either way it degrades to a
plain no-op when there is nothing to hand over — Langfuse disabled, or no
trace bound to this context.
Source code in packages/mewbo_core/src/mewbo_core/components.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
langfuse_invoke_config(*, user_id: str, session_id: str, trace_name: str) -> dict[str, Any]
¶
Build the LangChain invoke/astream config that exports a trace.
The "langfuse_metadata 3-line pattern" (see tool_use_loop), extracted so
the no-loop synthesis primitives (StructuredSynthesizer / DraftStreamer)
export to Langfuse too. langfuse_session_context only propagates
attributes — it creates no observation, so a model call that doesn't ATTACH
the CallbackHandler produces zero exported spans (a known defect: realtime
synthesis traced nothing, ever). Attaching the handler is the seam that makes
the generation land in the session-grouped trace.
Returns a config dict carrying callbacks (+ metadata when the
handler exposes langfuse_metadata), or {} when Langfuse is disabled /
unavailable — pass it straight to model.ainvoke(messages, config=cfg or None).
Cheap to call (no network, no flush) so it is safe on a latency-critical path;
the handler batches/exports asynchronously.
version / release are read from config here so callers stay 3 args.
Source code in packages/mewbo_core/src/mewbo_core/components.py
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 | |
langfuse_propagate(*, tags: list[str] | None = None, metadata: dict[str, str] | None = None, session_id: str | None = None, user_id: str | None = None, trace_name: str | None = None, version: str | None = None) -> Iterator[None]
¶
Propagate Langfuse attributes to all child observations.
Thin wrapper around langfuse.propagate_attributes that gracefully
degrades when Langfuse is disabled or unavailable.
trace_name is the ONE channel that names a trace from outside an observation: a trace otherwise inherits the name of whatever runnable opened its root span, which is why an untouched export is a wall of identically named traces. version rides along for the same reason — both are first-class trace fields, never tags.
Source code in packages/mewbo_core/src/mewbo_core/components.py
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 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
langfuse_session_context(session_id: str, *, user_id: str | None = None, invocation_id: str | None = None, source_platform: str | None = None, trace_name: str | None = None, tags: list[str] | None = None, metadata: dict[str, str] | None = None) -> Iterator[None]
¶
Bind a Langfuse trace context to the current invocation.
Each call gets a unique trace (via invocation_id) while Langfuse groups traces under the same session_id.
trace_name names that trace. Omitting it does not leave the trace unnamed: it leaves it named after whichever LangChain runnable happened to open the root span, which is a property of the client library rather than of the work.
tags / metadata carry pre-derived trace provenance
(see session_provenance.TraceProvenance) and are merged into the
propagated baseline so every child observation — including nested LangChain
CallbackHandler generations and langfuse_trace_span spans — is filterable
by product, workspace, project, repo, branch, surface, etc. This seam stays
taxonomy-free: it propagates whatever it is handed. When provenance is
supplied its surface:<…> tag supersedes the coarse
channel:<source_platform> fallback (kept only for callers that pass
source_platform alone).
Source code in packages/mewbo_core/src/mewbo_core/components.py
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 475 476 477 | |
langfuse_trace_span(name: str, *, as_type: ObservationKind = 'span', metadata: dict[str, str] | None = None, input_data: Any = None, level: str | None = None, attributes: dict[str, str] | None = None) -> Iterator[object | None]
¶
Open a Langfuse observation bound to the current session trace context.
as_type selects how Langfuse renders the observation — an agent, a tool
call and a plain span are the same OTel span with different types, and a
trace built entirely of untyped spans loses the one axis the UI groups by.
metadata is attached for filtering. input_data is set as the input.
level sets the log level (e.g. "ERROR"). attributes are raw OTel
span attributes, stamped as early as the SDK allows (see
:func:_stamp_span_attributes).
Source code in packages/mewbo_core/src/mewbo_core/components.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 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 563 564 565 566 | |
record_span_exception(span, exc=None, *, message=None, attributes=None)
¶
Record an exception on a Langfuse span: ERROR status + an OTel event.
Two writes, because Langfuse reads them from different places: the span's
own level/status_message drive the UI's error surface, while the
exception tooling queries OTel exception events — span.update(
level="ERROR") alone sets status with no cause attached. Setting the
status here (rather than leaving it to each call site) is what makes the
non-empty guarantee in :func:_span_status_message hold for every writer.
Fully graceful: no span / no otel / disabled → no-op.
Source code in packages/mewbo_core/src/mewbo_core/components.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
resolve_home_assistant_status() -> ComponentStatus
¶
Determine whether the Home Assistant tool is configured.
Source code in packages/mewbo_core/src/mewbo_core/components.py
164 165 166 167 168 169 170 171 172 | |
resolve_langfuse_status() -> ComponentStatus
¶
Determine whether Langfuse callbacks are available and configured.
Source code in packages/mewbo_core/src/mewbo_core/components.py
78 79 80 81 | |
mewbo_core.permissions
¶
Permission policies for tool execution.
PermissionDecision
¶
Bases: str, Enum
Outcomes for a permission check.
Source code in packages/mewbo_core/src/mewbo_core/permissions.py
23 24 25 26 27 28 | |
PermissionPolicy
¶
Evaluate permission rules for action steps.
Source code in packages/mewbo_core/src/mewbo_core/permissions.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
__init__(rules: list[PermissionRule] | None = None, default_by_operation: dict[str, PermissionDecision] | None = None, default_decision: PermissionDecision = PermissionDecision.ASK) -> None
¶
Initialize the permission policy.
Source code in packages/mewbo_core/src/mewbo_core/permissions.py
49 50 51 52 53 54 55 56 57 58 | |
decide(action_step: ActionStep) -> PermissionDecision
¶
Return the permission decision for an action step.
Source code in packages/mewbo_core/src/mewbo_core/permissions.py
60 61 62 63 64 65 66 67 68 | |
PermissionRule
dataclass
¶
Rule describing a tool/action permission decision.
Source code in packages/mewbo_core/src/mewbo_core/permissions.py
31 32 33 34 35 36 37 38 39 40 41 42 43 | |
matches(action_step: ActionStep) -> bool
¶
Return True when the action step matches the rule pattern.
Source code in packages/mewbo_core/src/mewbo_core/permissions.py
39 40 41 42 43 | |
approval_callback_from_config() -> Callable[[ActionStep], bool] | None
¶
Return an approval callback based on config settings.
Source code in packages/mewbo_core/src/mewbo_core/permissions.py
149 150 151 152 153 154 155 156 157 | |
auto_approve(_: ActionStep) -> bool
¶
Approval callback that always approves.
Source code in packages/mewbo_core/src/mewbo_core/permissions.py
160 161 162 | |
auto_deny(_: ActionStep) -> bool
¶
Approval callback that always denies.
Source code in packages/mewbo_core/src/mewbo_core/permissions.py
165 166 167 | |
load_permission_policy(path: str | None = None) -> PermissionPolicy
¶
Load permission policy configuration from disk or defaults.
Source code in packages/mewbo_core/src/mewbo_core/permissions.py
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 | |
mewbo_core.hooks
¶
Hook manager for orchestration lifecycle events.
HookDispatch
dataclass
¶
The background threads behind every fire-and-forget hook, joinable.
A dispatch nobody can join is only observable by sleeping and hoping the
thread won. That is a RACE, not a slow caller: on a loaded machine the
observation is simply WRONG rather than late. Holding the handles here
gives any caller that needs the outcome — a shutdown path, a test — a
bounded wait to join on, while every hot-path caller keeps ignoring the
return value and the fire-and-forget semantics are unchanged.
Process-wide by construction (:data:HOOK_DISPATCH) rather than per
manager: the threads are the process's, a plugin-translated hook is
dispatched with no manager in reach of the factory, and "has every
dispatched hook landed" is the only question a joiner actually has.
Cost: O(1) per submit and O(1) per completion — a thread drops
itself from the set when it ends, so nothing ever sweeps the set and the
dispatch a hook pays for does not grow with how many are already in flight.
Memory is bounded by what is genuinely in flight, for the same reason.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
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 | |
submit(target: Callable[..., None], *args: Any) -> threading.Thread
¶
Run target on a daemon thread and return it, tracked until it ends.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
163 164 165 166 167 168 169 | |
wait(timeout: float = 5.0) -> bool
¶
Join everything in flight within timeout; return whether all landed.
Never raises and never re-raises a hook's own failure — a joiner is
asking whether the work finished, not taking on responsibility for what
it did. A timeout logs once and returns False.
Cost: O(in-flight dispatches) joins, bounded overall by timeout.
No caller is on a hot path — production never joins; this is for a
shutdown path or a test.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
HookManager
dataclass
¶
Container for hook callbacks used during orchestration.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 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 350 351 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 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 | |
load_from_config(hooks_config: HooksConfig) -> HookManager
classmethod
¶
Create a HookManager with hooks loaded from config.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
run_on_agent_start(handle: AgentHandle) -> None
¶
Notify hooks that an agent has started.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
317 318 319 320 321 322 323 | |
run_on_agent_stop(handle: AgentHandle) -> None
¶
Notify hooks that an agent has stopped.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
325 326 327 328 329 330 331 | |
run_on_compact(session_id: str, *, summary: str = '', tokens_before: int = 0, tokens_saved: int = 0, events_summarized: int = 0) -> None
¶
Notify hooks that compaction occurred.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
run_on_event(session_id: str, event: EventRecord) -> None
¶
Notify hooks that an event was appended to a session transcript.
Runs on the event-append hot path (via the SessionEventBus
observer), so every registered hook is itself fire-and-forget; this
loop only dispatches and is failure-isolated per hook.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
387 388 389 390 391 392 393 394 395 396 397 398 | |
run_on_session_end(session_id: str, error: str | None = None) -> list[OutcomeAssertion]
¶
Notify hooks a session ended; collect any outcome assertions they report.
A hook MAY return an :class:OutcomeAssertion to report that the
session's purpose was not achieved. Returning None asserts nothing
— see that class for why absence must stay distinguishable from success.
The return value is COLLECTED, not discarded — discarding it is how a job that never reached its terminal state still presents as a clean completion, with the hook able to SEE the failure and nowhere to put it.
Failure-isolated per hook like every other lifecycle dispatch, and deliberately strict about what it accepts: a hook returning something that is not an assertion is logged and IGNORED rather than coerced, because a truthy stray return would otherwise invent a failure.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
341 342 343 344 345 346 347 348 349 350 351 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 | |
run_on_session_start(session_id: str) -> None
¶
Notify hooks that a session has started.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
333 334 335 336 337 338 339 | |
run_permission_request(action_step: ActionStep, decision: PermissionDecision) -> PermissionDecision
¶
Apply permission hooks to a decision outcome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_step
|
ActionStep
|
Action step under review. |
required |
decision
|
PermissionDecision
|
Current decision to modify. |
required |
Returns:
| Type | Description |
|---|---|
PermissionDecision
|
Updated permission decision after hooks run. |
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
run_post_tool_use(action_step: ActionStep, result: MockSpeaker) -> MockSpeaker
¶
Apply post-tool hooks to a tool result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_step
|
ActionStep
|
Action step that was executed. |
required |
result
|
MockSpeaker
|
Result returned by the tool. |
required |
Returns:
| Type | Description |
|---|---|
MockSpeaker
|
Updated result after hooks run. |
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
run_pre_compact(events: Iterable[EventRecord]) -> list[EventRecord]
¶
Apply compaction hooks to events prior to summarization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
Iterable[EventRecord]
|
Iterable of event records. |
required |
Returns:
| Type | Description |
|---|---|
list[EventRecord]
|
List of event records after hooks run. |
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
run_pre_tool_use(action_step: ActionStep) -> ActionStep
¶
Apply pre-tool hooks to an action step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_step
|
ActionStep
|
Action step to process. |
required |
Returns:
| Type | Description |
|---|---|
ActionStep
|
Updated action step after hooks run. |
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
OutcomeAssertion
¶
Bases: BaseModel
A session-end hook's report that the session's PURPOSE was not achieved.
The return channel a session-end hook needs in order to CONTRADICT a clean
terminal. A session can end with no exception, no halt and no blocked
envelope — every signal the loop owns says success — while the job it
existed to perform never reached its terminal state. Nothing the loop can
see distinguishes that from a real completion. Only the hook holding the
owning job can, and until this existed it had no way to say so: the return
value of run_on_session_end was discarded, so the one component able to
evaluate a session's real outcome could write a warning to its own job log
and nothing more.
Absence is not an assertion. A hook that returns None — every
command hook, every http hook, and any python hook that declines to judge —
reports nothing, which is why the contract is an OPTIONAL RETURN and not a
boolean: "did not report" and "reported success" must never collapse into
each other, or the channel would invent an assertion for every hook that
does not use it.
reason is a PRODUCT-OWNED token and deliberately not a Literal:
core would otherwise have to learn every product's vocabulary before that
product could tell the truth about itself. It never drives dispatch — the
status this produces comes from the TYPE of this object, never from parsing
the string — so it stays data, not a magic string.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
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 | |
default_hook_manager() -> HookManager
¶
Create a hook manager with no custom hooks registered.
Returns:
| Type | Description |
|---|---|
HookManager
|
Empty HookManager instance. |
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
726 727 728 729 730 731 732 | |
merge_plugin_hooks(manager: HookManager, hooks_json: dict[str, Any], plugin_root: str) -> None
¶
Translate Claude Code plugin hooks.json into HookManager callbacks.
Supports: PreToolUse, PostToolUse, SessionStart, SessionEnd. Substitutes ${CLAUDE_PLUGIN_ROOT} in command strings.
Source code in packages/mewbo_core/src/mewbo_core/hooks.py
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 | |
mewbo_core.common
¶
Common helpers shared across the assistant runtime.
InstructionSource
dataclass
¶
A single source of project/user instructions.
Source code in packages/mewbo_core/src/mewbo_core/common.py
269 270 271 272 273 274 275 276 | |
MockSpeaker
¶
Bases: NamedTuple
Simple mock response container used across tools and tests.
Source code in packages/mewbo_core/src/mewbo_core/common.py
28 29 30 31 32 33 34 35 36 37 38 39 | |
count_tokens(text: str, model: str = 'gpt-4') -> int
¶
Estimate token count for text using tiktoken.
Falls back to a rough character-based estimate if encoding lookup fails.
Source code in packages/mewbo_core/src/mewbo_core/common.py
220 221 222 223 224 225 226 227 228 229 | |
discover_all_instructions(cwd: str | None = None) -> list[InstructionSource]
¶
Discover instructions from all levels, ordered by priority (lowest first).
Levels (ascending priority): 1. User: ~/.claude/CLAUDE.md (priority 10) 2. Project: CLAUDE.md, .claude/CLAUDE.md walking up to git root (priority 20-29) 3. Rules: .claude/rules/*.md in CWD (priority 30) 4. Local: CLAUDE.local.md in CWD (priority 40)
Source code in packages/mewbo_core/src/mewbo_core/common.py
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 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
discover_project_instructions(cwd: str | None = None) -> str | None
¶
Discover and load project instruction files. Uses hierarchical discovery.
Falls back to a root AGENTS.md when no hierarchical sources are found.
Files containing <!-- mewbo:noload --> on the first line are skipped.
Additionally walks the subtree to build a lightweight index of nested instruction files so the model knows they exist and can read them on demand.
Returns the composed instruction text, or None if no files are found.
Source code in packages/mewbo_core/src/mewbo_core/common.py
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 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
discover_subtree_instructions(cwd: str | None = None, *, max_depth: int = _MAX_SUBTREE_DEPTH) -> list[InstructionSource]
¶
Walk DOWN from CWD to find CLAUDE.md and AGENTS.md in subdirectories.
Returns lightweight InstructionSource entries with empty content.
The model is made aware these files exist and can read them on demand.
Respects the <!-- mewbo:noload --> marker (checked via first line).
Source code in packages/mewbo_core/src/mewbo_core/common.py
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 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
format_tool_input(tool_input: object) -> str
¶
Format a tool input for logs and prompts.
Source code in packages/mewbo_core/src/mewbo_core/common.py
509 510 511 512 513 | |
get_git_context(cwd: str | None = None, max_status_chars: int = 2000) -> str | None
¶
Gather git context (branch, status, recent commits) for system prompt injection.
Returns formatted git context string, or None if not in a git repo.
Source code in packages/mewbo_core/src/mewbo_core/common.py
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 | |
get_logger(name: str | None = None)
¶
Get the logger for the module.
Source code in packages/mewbo_core/src/mewbo_core/common.py
199 200 201 202 203 204 | |
get_mock_speaker() -> type[MockSpeaker]
¶
Return a mock speaker for testing.
Source code in packages/mewbo_core/src/mewbo_core/common.py
42 43 44 | |
get_system_prompt(name: str = 'action-planner') -> str
¶
Get the system prompt for the task queue.
Routes through the central prompt registry when name has a file.*
entry (the standalone, system.txt-sized prompts inventoried in
prompts/registry/files.yaml), which the registry does not strip, so
this shim applies the .strip() its callers expect. Names the registry
does not inventory (tool prompts loaded by path) fall back to a raw file
read.
Source code in packages/mewbo_core/src/mewbo_core/common.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
get_unique_timestamp() -> int
¶
Get a unique timestamp for the task queue.
Source code in packages/mewbo_core/src/mewbo_core/common.py
232 233 234 235 236 | |
ha_render_system_prompt(all_entities: object | None = None, name: str = 'homeassistant-set-state') -> str
¶
Render the Home Assistant Jinja2 system prompt.
Source code in packages/mewbo_core/src/mewbo_core/common.py
633 634 635 636 637 638 639 640 | |
num_tokens_from_string(string: str, encoding_name: str = 'cl100k_base') -> int
¶
Get the number of tokens in a string using a specific model.
Source code in packages/mewbo_core/src/mewbo_core/common.py
212 213 214 215 216 217 | |
pydantic_to_openai_tool(model_cls: type, *, name: str, schema_generator: type | None = None) -> dict[str, object]
¶
Build an OpenAI function-calling tool dict from a Pydantic model.
Uses the model's docstring as the tool description and its JSON schema
as the parameters. Strips Pydantic's title fields that are irrelevant
to function-calling. Output matches the shape used by the existing
hand-written internal tool schemas (SPAWN_AGENT_SCHEMA, etc.) so
callers can migrate piecewise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_cls
|
type
|
A Pydantic |
required |
name
|
str
|
The tool name (function name visible to the LLM). |
required |
schema_generator
|
type | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in packages/mewbo_core/src/mewbo_core/common.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
render_jinja_prompt(name: str, **variables: object) -> str
¶
Render a Jinja2 prompt template from mewbo_core/prompts/.
Looks up {name}.j2 first, falls back to {name}.txt for
backward-compatibility with existing prompts that use Jinja2 syntax
inside .txt files (e.g. homeassistant-*.txt).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Template stem without extension. |
required |
**variables
|
object
|
Keyword variables bound to the template. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
Rendered prompt string. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no template is found (chained from the final
|
Source code in packages/mewbo_core/src/mewbo_core/common.py
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 | |
session_log_context(session_id: str, log_dir: str | None = None)
¶
Context manager that logs all session output to a session log file.
Source code in packages/mewbo_core/src/mewbo_core/common.py
188 189 190 191 192 193 194 195 196 | |
set_cli_log_file(log_file_path: str, *, overwrite: bool = False, quiet_console: bool = True) -> str
¶
Stream all CLI logs to a file, keeping the terminal (TUI) output clean.
Adds an unfiltered loguru file sink at the active verbosity level. When
quiet_console is set (the default), the stderr sink is removed so log
lines cannot interleave with the Rich/Textual UI — they go only to the
file. overwrite truncates the file at startup instead of appending.
Returns the absolute path actually written to.
Source code in packages/mewbo_core/src/mewbo_core/common.py
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 | |
utc_now_iso() -> str
¶
Return an ISO-8601 UTC timestamp string (the shared storage timestamp).
Source code in packages/mewbo_core/src/mewbo_core/common.py
207 208 209 | |
mewbo_core.contracts.errors
¶
Core error types for tool/runtime coordination.
ToolInputError
¶
Bases: Exception
Raised when a tool input is invalid but the tool remains healthy.
Source code in packages/mewbo_core/src/mewbo_core/contracts/errors.py
7 8 | |
mewbo_core.session.notifications
¶
Lightweight notification storage for Mewbo.
NotificationRecord
dataclass
¶
Typed record for serialized notifications.
Source code in packages/mewbo_core/src/mewbo_core/session/notifications.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
NotificationStore
¶
JSON-backed notification store for single-user UI.
Source code in packages/mewbo_core/src/mewbo_core/session/notifications.py
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 | |
__init__(root_dir: str | None = None, filename: str = 'notifications.json') -> None
¶
Initialize the notification store location.
Source code in packages/mewbo_core/src/mewbo_core/session/notifications.py
40 41 42 43 44 45 46 47 | |
add(*, title: str, message: str, level: str = 'info', session_id: str | None = None, event_type: str | None = None, metadata: dict[str, object] | None = None) -> dict[str, object]
¶
Add a new notification record and return it.
Source code in packages/mewbo_core/src/mewbo_core/session/notifications.py
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 | |
clear(*, dismissed_only: bool = True) -> int
¶
Clear dismissed notifications (or all when requested).
Source code in packages/mewbo_core/src/mewbo_core/session/notifications.py
125 126 127 128 129 130 131 132 133 134 135 | |
dismiss(ids: Sequence[str]) -> int
¶
Mark notifications as dismissed.
Source code in packages/mewbo_core/src/mewbo_core/session/notifications.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
list(*, include_dismissed: bool = False) -> list[dict[str, object]]
¶
Return notifications, optionally including dismissed ones.
Source code in packages/mewbo_core/src/mewbo_core/session/notifications.py
67 68 69 70 71 72 73 74 75 76 77 | |
mewbo_core.session.share_store
¶
Session share token storage.
ShareStore
¶
JSON-backed share token store for session exports.
Source code in packages/mewbo_core/src/mewbo_core/session/share_store.py
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 | |
__init__(root_dir: str | None = None, filename: str = 'shares.json') -> None
¶
Initialize the share token store location.
Source code in packages/mewbo_core/src/mewbo_core/session/share_store.py
22 23 24 25 26 27 28 29 | |
create(session_id: str) -> dict[str, object]
¶
Create and store a new share token.
Source code in packages/mewbo_core/src/mewbo_core/session/share_store.py
49 50 51 52 53 54 55 56 57 | |
resolve(token: str) -> dict[str, object] | None
¶
Resolve a share token to its record.
Source code in packages/mewbo_core/src/mewbo_core/session/share_store.py
59 60 61 62 63 64 65 66 67 68 | |
revoke(token: str) -> bool
¶
Revoke a share token.
Source code in packages/mewbo_core/src/mewbo_core/session/share_store.py
70 71 72 73 74 75 76 77 78 79 80 | |
mewbo_core.llm.llm
¶
Model configuration helpers for ChatLiteLLM.
ChatModel
¶
Bases: Protocol
Protocol for LangChain-compatible chat models.
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
39 40 41 42 43 44 45 46 47 48 49 50 | |
ainvoke(input_data: object, config: object | None = None, **kwargs: object) -> BaseMessage
async
¶
Invoke the model asynchronously.
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
47 48 49 50 | |
invoke(input_data: object, config: object | None = None, **kwargs: object) -> BaseMessage
¶
Invoke the model synchronously.
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
42 43 44 45 | |
build_chat_model(model_name: str, *, openai_api_base: str | None = None, api_key: str | None = None) -> ChatModel
¶
Build a ChatLiteLLM model with reasoning-effort compatibility.
openai_api_base and api_key default to llm.api_base and
llm.api_key from config when None. Pass them explicitly only
to override the configured values (e.g. tests, multi-tenant routing).
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
model_prefers_structured_patch(model_name: str | None) -> bool
¶
Return True if the model works better with the per-file structured_patch tool.
GPT-5-class, o3/o4, and Codex models use structured JSON tool calls that
map naturally to file_edit_tool (structured_patch). Claude and Gemini
are trained on diff/patch text formats and work better with
aider_edit_block_tool (search_replace_block).
Precedence (the model→tool-variant map is now controllable data):
1. llm.structured_patch_models config allowlist (runtime override layer).
2. The operator-tunable prompts/model_variants.yaml map, loaded through
ModelVariantRegistry — this is where the built-in defaults now live
(gpt-5/o3/o4/codex/gpt-4), so they are editable without touching code.
Its conservative defaults.edit_tool (search_replace_block) is the
sane built-in fallback when no profile matches.
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
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 | |
model_supports_prompt_caching(model_name: str | None) -> bool
¶
Return True when LiteLLM reports the model supports prompt caching.
Single source of truth: litellm.utils.supports_prompt_caching, which
reads the bundled model_cost.json (extensible at runtime via
litellm.register_model). Returns False on unknown models or any
lookup error so the caller can skip caching gracefully without crashing
the agent loop.
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
model_supports_reasoning_effort(model_name: str | None) -> bool
¶
Return True if the model is known to support reasoning_effort.
LiteLLM translates reasoning_effort per-provider: - Claude → output_config.effort - Gemini → thinking budget_tokens or thinking_level - OpenAI (o3/gpt-5) → native reasoning_effort
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
register_proxy_model_capabilities(api_base: str | None, api_key: str | None, *, timeout: float = 5.0) -> int
¶
Pull proxy /v1/model/info and register advertised models.
Hydrates LiteLLM's local model_cost map with the routes the proxy
operator defined.
This is the bridge that lets litellm.utils.supports_prompt_caching (and
every other supports_* helper) report accurately for proxy-fronted
custom model names — the SDK only consults its bundled model_cost.json
by default, which doesn't know about routes the proxy operator defined.
Idempotent per process: each distinct api_base is fetched at most once.
Failures are logged and swallowed — Stage 1's per-model gate just stays
conservative, never crashes.
Returns the number of models newly registered (0 if cached, no-op, or error).
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
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 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 | |
resolve_reasoning_effort(model_name: str | None) -> str | None
¶
Resolve the reasoning effort for a model.
Returns the configured value if set, otherwise None (let the
provider decide). Only returns a value when the model supports
the parameter and a value is explicitly configured.
LiteLLM translates this per-provider:
- Claude: output_config.effort
- Gemini: thinking budget_tokens or thinking_level
- OpenAI: native reasoning_effort
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
response_text(response: Any) -> str
¶
Visible assistant text from an LLM response, whatever shape it arrives in.
A cross-model normalization, which is why it lives at this seam rather than at each caller (see this package's CLAUDE.md: format differences are fixed here, never detected upstream). Three shapes reach us:
- a plain
str— most models; - a list of
{"type": "text", "text": ...}blocks — Anthropic-style; - a list mixing
thinking/reasoningblocks with the answer as a BARE STRING element — what a reasoning model returns through the proxy.
Callers used to take the FIRST type == "text" dict, which yields ""
for that third shape. The failure is silent — no exception, no log, just an
empty answer — so a session title and a compaction summary each simply
stopped being produced the moment a reasoning model became the default.
Reasoning blocks are deliberately dropped: they are the model's scratchpad,
not its answer.
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | |
sanitize_tool_schema(schema: Any) -> Any
¶
Recursively fix JSON Schema issues that strict LLM providers reject.
Runs at the specs_to_langchain_tools funnel so every tool schema —
MCP, built-in, plugin — is covered. Fixes are valid JSON Schema, safe
for all providers.
Current fixes:
- array without items → add "items": {} (required by OpenAI).
- drop maxLength / maxItems / maxProperties, which make a
grammar-constrained backend fail to start.
WHY THE UPPER BOUNDS GO. A backend that constrains decoding with a grammar
(llama.cpp/Ollama, and anything else compiling JSON Schema to GBNF) expands
an upper bound into that many literal repetitions, and inlines every
$ref while doing it. In a RECURSIVE schema the two multiply. Measured:
present_ui — whose Card.children is a oneOf over
eleven component types including Card itself — made Ollama answer
400 Failed to initialize samplers: failed to parse grammar for the whole
17-tool request. Dropping these three keywords fixed it; dropping
minLength, pattern, const, default, discriminator,
anyOf or additionalProperties did not.
Magnitude is what bites, not presence: the same schema compiled with
maxLength forced to 8, and failed again with maxItems raised to
2000. A size threshold would still be unsound, because the blow-up
scales with nesting depth as well as with the bound, so a limit that is
safe at one depth is fatal one level down. Dropping unconditionally is the
only rule that does not need to know the shape of the schema.
Dropping is strictly PERMISSIVE and cannot truncate or reject a valid
argument — it only stops advertising a ceiling. Lower bounds stay: they are
small in practice and carry real intent. Callers that need the ceiling
enforced still get it, because tool arguments are validated against the
original schema on our side (EmitStructuredResponseTool.handle).
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
specs_to_langchain_tools(specs: list[object]) -> list[dict[str, Any]]
¶
Convert ToolSpecs to LangChain bind_tools() format.
Each spec must have tool_id, description, and metadata["schema"].
Specs without a schema are silently skipped.
Delegates to LangChain's :func:convert_to_openai_tool (Anthropic-format
input) so that schema normalisation is handled by the library rather than
hand-rolled here.
Source code in packages/mewbo_core/src/mewbo_core/llm/llm.py
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 | |
mewbo_core.tooling.plugins
¶
Plugin discovery, manifest parsing, marketplace reading, and install/uninstall.
All path resolution is done by the CALLER via PluginsConfig.resolve_*() methods.
This module accepts resolved paths as parameters — no hardcoded ~/.mewbo/ or
~/.claude/ paths.
The only place ${CLAUDE_PLUGIN_ROOT} is resolved is substitute_plugin_vars.
It is applied once per plugin at discovery time via _deep_substitute.
GitSubdirPluginSource
¶
Bases: _GitPluginSourceBase
A plugin vendored from a subdirectory of a larger repo.
{"source": "git-subdir", "url": ..., "path": ...}. path is
REQUIRED here (unlike the shared optional field on the base class) — it
is the entire reason this discriminator exists as distinct from url.
url resolves through the SAME shared :func:_resolve_git_url the
github variant uses, not verbatim — a bare host/owner/repo
shorthand must work here exactly as it does for repo, since this is
the one variant most likely to be hand-written.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 | |
resolve_git_url(*, default_host: str = 'github.com') -> str
¶
Resolve url through the shared host-agnostic resolver.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
778 779 780 | |
GithubPluginSource
¶
Bases: _GitPluginSourceBase
{"source": "github", "repo": ...} — a host-agnostic repo shorthand.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
733 734 735 736 737 738 739 740 741 | |
resolve_git_url(*, default_host: str = 'github.com') -> str
¶
Resolve repo through the shared host-agnostic resolver.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
739 740 741 | |
PluginComponents
dataclass
¶
Fan-out of a single plugin's contributions to existing registries.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
PluginFanOut
dataclass
¶
Aggregated components from all enabled plugins, ready for registry injection.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 | |
PluginManifest
dataclass
¶
Parsed .claude-plugin/plugin.json manifest.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
PluginSource
¶
Bases: RootModel[PluginSourceUnion]
Parse seam for a plugin manifest's dict-shaped source field.
Wraps the discriminated union in a RootModel so a mode="before"
validator can run BEFORE Pydantic reads the source discriminator: a
bare {"repo": ...} entry with no source key has no tag for the union
to dispatch on until this stamps one. Installed manifests carry that shape
and must keep resolving as github.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
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 | |
parse(data: Mapping[str, object]) -> GithubPluginSource | UrlPluginSource | GitSubdirPluginSource
classmethod
¶
Parse a raw source dict into its concrete variant.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
809 810 811 812 813 814 | |
UrlPluginSource
¶
Bases: _GitPluginSourceBase
{"source": "url", "url": ...} — used verbatim, never resolved.
Trap: the url type is already expected to be a full, clonable
reference — routing it through :func:_resolve_git_url (as
:class:GitSubdirPluginSource correctly does) would be harmless for a
real URL but silently wrong for anything else callers pass here as-is
(e.g. a local path in a test fixture).
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 | |
resolve_git_url(*, default_host: str = 'github.com') -> str
¶
Return url unchanged — never resolved, unlike repo.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
757 758 759 | |
discover_builtin_plugins(root: Path | str) -> list[PluginComponents]
¶
Discover first-party plugins shipped inside the core package.
Walks immediate subdirectories of root (no registry indirection)
and returns :class:PluginComponents for each directory that
contains a .claude-plugin/plugin.json. Built-in plugins bypass
installed_plugins.json because they ship with the core wheel —
their presence is a property of the installation, not user action.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
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 | |
discover_installed_plugins(registry_paths: list[Path | str], *, enabled: list[str] | None = None) -> list[PluginComponents]
¶
Read installed plugin registries and return discovered components.
Registry format::
{
"version": 2,
"plugins": {
"name@marketplace": [
{"scope": "user", "installPath": "/abs/path", "version": "1.0.0"}
]
}
}
- Takes the FIRST entry in the list for each key (highest-priority scope).
- Filters by the name part (before
@) when enabled is non-empty. - Deduplicates by name — first registry_path wins.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
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 475 476 477 478 479 480 481 482 483 484 485 486 | |
discover_marketplace_plugins(marketplace_dirs: list[Path | str]) -> list[dict]
¶
Read marketplace.json from each directory and return a flat list of plugin dicts.
Each dict contains: name, description, category, marketplace,
installed (always False — caller can enrich).
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | |
discover_plugin_components(plugin_dir: Path | str) -> PluginComponents
¶
Scan plugin_dir for all plugin contributions.
Returns a :class:PluginComponents instance. If plugin.json is absent
the manifest will be None but other components are still discovered.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
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 350 351 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 | |
install_plugin(name: str, marketplace: str, *, marketplace_dirs: list[Path], install_base: Path) -> PluginManifest
¶
Install a plugin from a marketplace into install_base.
- Finds the plugin entry in marketplace.json by searching marketplace_dirs.
- For local sources (string starting with
./): copies the directory. - For git sources: clones the repo.
- Updates
install_base/installed_plugins.json. - Returns the parsed :class:
PluginManifest.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 | |
load_all_plugin_components() -> PluginFanOut
¶
Discover all enabled plugins and aggregate their components.
Uses PluginsConfig from the live config for all path resolution.
Returns a :class:PluginFanOut that callers can inject into their
registries. This is the single point of truth for "what do plugins
contribute?" — used by both Orchestrator.__init__ and the API
endpoints so they stay in sync.
Results are cached and only recomputed when the installed-plugins registry file changes (mtime comparison).
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 | |
marketplace_dir_name(entry: str, *, default_host: str = 'github.com') -> str
¶
Stable, collision-free local cache-dir name for a marketplace entry.
Derived from the resolved git URL's host + path (scheme, user@, and a
trailing .git stripped) so entries that share a leaf name but differ in
host or owner never collide. For example
anthropics/claude-plugins-official →
github.com-anthropics-claude-plugins-official.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
parse_plugin_manifest(plugin_dir: Path | str) -> PluginManifest | None
¶
Parse .claude-plugin/plugin.json from plugin_dir.
Returns None on any error (missing file, bad JSON, missing name).
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
286 287 288 289 290 291 292 293 294 295 | |
register_builtin_root(root: Path | str) -> None
¶
Register an extra built-in plugin root (idempotent; down-only push).
A capability library above core in the DAG calls this on import so its
bundled plugin suites are discovered by :func:load_all_plugin_components
alongside the core wheel's own builtin_plugins/ — without core ever
importing the library. Invalidates the fan-out cache so a freshly
registered root is picked up on the next load.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
substitute_plugin_vars(text: str, plugin_root: str) -> str
¶
Replace ${CLAUDE_PLUGIN_ROOT} with plugin_root in text.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
216 217 218 | |
sync_marketplaces(marketplace_repos: list[str], install_base: Path, *, default_host: str = 'github.com') -> list[Path]
¶
Ensure marketplace catalogs are cloned locally, return their directory paths.
Each entry in marketplace_repos is resolved host-agnostically via
:func:_resolve_git_url — a full git URL, an host/owner/repo shorthand,
or a bare owner/repo (cloned from default_host). The catalog is cloned
into install_base/marketplaces/<marketplace_dir_name(entry)>/ if not
already present. Cloning uses plain git clone, so it inherits the
ambient git credential helpers, SSH agent, and TLS configuration — private
and self-hosted catalogs work without a GitHub-specific path. Returns the
list of marketplace directories (same contract as
PluginsConfig.resolve_marketplace_dirs()).
This is the bridge between the plugins.marketplaces config list and the
filesystem-based marketplace discovery. Without it, standalone deployments
(e.g. Docker without ~/.claude) would have zero marketplaces.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
uninstall_plugin(name: str, *, install_base: Path) -> bool
¶
Remove name from the installed plugins registry and delete its cache directory.
Returns True if the plugin was found and removed, False otherwise.
Source code in packages/mewbo_core/src/mewbo_core/tooling/plugins.py
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 | |
mewbo_core.agents.agent_registry
¶
Agent definition registry for the Mewbo assistant.
An agent definition is an agents/*.md file (YAML frontmatter + markdown body)
loaded from a Claude Code plugin or personal/project directory. Agent definitions
tell Mewbo what sub-agents are available, what tools they may use, and what their
system prompt should be.
This module mirrors the structure of skills.py — same frontmatter regex, same
frozen dataclass pattern, same registry pattern with no-override semantics.
AgentDef
dataclass
¶
An agent definition loaded from an agents/*.md file.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_registry.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
AgentRegistry
¶
Registry of agent definitions.
First-registered agent wins — later registrations with the same name are silently ignored (same semantics as the subtree skill discovery).
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_registry.py
233 234 235 236 237 238 239 240 241 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 275 276 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 | |
get(name: str, session_capabilities: Iterable[str] = ()) -> AgentDef | None
¶
Return the agent definition with the given name, or None.
Agents gated by requires_capabilities that the session hasn't
advertised are treated as if they don't exist.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_registry.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
list_all() -> list[AgentDef]
¶
Return all registered agent definitions.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_registry.py
285 286 287 | |
register(agent_def: AgentDef, *, capabilities: Iterable[str] = (), plugin_root: str = '') -> None
¶
Register an agent. Does NOT override existing entries.
When capabilities is non-empty, they are unioned into the
agent's requires_capabilities before registration — the
standard way a plugin fans its bundle-level requirements out
over every contributed agent.
When plugin_root is provided and the agent does not already
have one, it is stamped on so downstream consumers (e.g. the
${CLAUDE_PLUGIN_ROOT} substitution in spawn_agent) can
locate the plugin's on-disk assets.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_registry.py
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 | |
render_catalog(session_capabilities: Iterable[str] = ()) -> str
¶
Render a compact agent catalog for system prompt injection.
Applies capability filtering before rendering so capability-gated agents stay invisible to sessions that don't advertise them.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_registry.py
293 294 295 296 297 298 299 300 301 302 303 | |
visible_for(session_capabilities: Iterable[str]) -> list[AgentDef]
¶
Return agents visible given the session's advertised capabilities.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_registry.py
289 290 291 | |
map_cc_tool_names(cc_names: list[str]) -> list[str]
¶
Map a list of CC tool names to Mewbo tool IDs.
Unknown names pass through unchanged. Duplicates are removed while preserving first-occurrence order (multiple CC names may map to the same Mewbo tool ID).
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_registry.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
parse_agent_file(path: Path, source: str) -> AgentDef | None
¶
Parse an agents/*.md file into an :class:AgentDef, or None on failure.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_registry.py
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 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 220 221 222 223 224 225 | |
packages/mewbo_tools (tool integrations)¶
mewbo_tools.integration.mcp
¶
MCP tool runner for integrating MCP servers into Mewbo.
MCPToolRunner
¶
Wrapper to invoke MCP tools via langchain-mcp-adapters.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
494 495 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 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
__init__(server_name: str, tool_name: str, *, cwd: str | None = None, trust_cwd: bool = True) -> None
¶
Initialize the MCP tool runner for a specific server tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_name
|
str
|
MCP server name from configuration. |
required |
tool_name
|
str
|
Tool name to invoke on the server. |
required |
cwd
|
str | None
|
Project working directory for merged config loading. |
None
|
trust_cwd
|
bool
|
Whether cwd may contribute its own |
True
|
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
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 | |
arun(action_step: ActionStep) -> MockSpeaker
async
¶
Async execution — preferred when called from an async context.
Calls _invoke_async directly, avoiding the asyncio.run()
wrapper that would fail inside a running event loop.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
616 617 618 619 620 621 622 623 624 625 626 | |
run(action_step: ActionStep) -> MockSpeaker
¶
Sync execution — for use from sync-only callers.
Raises:
| Type | Description |
|---|---|
ValueError
|
If action_step is None. |
RuntimeError
|
If called from inside a running event loop. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
628 629 630 631 632 633 634 635 636 637 638 639 | |
disabled_servers() -> frozenset[str]
¶
Server names switched off in config at the most recent load.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
110 111 112 | |
discover_mcp_tool_details(config: dict[str, Any]) -> dict[str, list[dict[str, Any]]]
¶
Discover MCP tool names and schemas per server from configuration.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
438 439 440 | |
discover_mcp_tool_details_with_failures(config: dict[str, Any]) -> tuple[dict[str, list[dict[str, Any]]], dict[str, Exception]]
¶
Discover MCP tool names, schemas, and per-server failures.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
443 444 445 446 447 448 449 450 451 | |
discover_mcp_tools(config: dict[str, Any]) -> dict[str, list[str]]
¶
Discover MCP tool names per server from configuration.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
429 430 431 432 433 434 435 | |
get_last_config_error() -> dict[str, str] | None
¶
Return the most recent malformed-MCP-config diagnostic, if any.
Read by MCPConnectionPool.status_snapshot so a broken config file is
visible in /mcp alongside per-server connect states.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
208 209 210 211 212 213 214 | |
get_last_discovery_failures() -> dict[str, str]
¶
Return last MCP discovery failures per server (if any).
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
461 462 463 | |
list_server_tool_schemas(server_name: str, *, cwd: str | None = None, trust_cwd: bool = True) -> list[dict[str, Any]]
¶
Return one configured server's live tool schemas via the shared pool.
The public introspection seam for callers that need a server's advertised
tool list (name / description / input schema) without binding the tools:
loads the merged MCP config for cwd, refreshes the pool fingerprint, and
connects on demand (the MCPToolRunner._invoke_via_pool pattern). Only
schema-bearing attributes are read off each tool — never connection or
auth material.
Raises:
| Type | Description |
|---|---|
LookupError
|
server_name has no entry in the merged MCP config. |
RuntimeError
|
the config could not be read, or the live introspection (pool connect / handshake) failed. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
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 | |
mark_tool_auto_approved(config: dict[str, Any], server_name: str, tool_name: str) -> dict[str, Any]
¶
Record a tool as auto-approved in the MCP config.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
479 480 481 482 483 484 485 486 487 488 489 490 491 | |
save_mcp_config(config: dict[str, Any], path: str | None = None) -> None
¶
Persist an MCP configuration payload to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
MCP configuration payload to write. |
required |
path
|
str | None
|
Optional explicit file path (defaults to the configured MCP path). |
None
|
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
tool_auto_approved(config: dict[str, Any], server_name: str, tool_name: str) -> bool
¶
Return True when a tool is marked as auto-approved.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/mcp.py
466 467 468 469 470 471 472 473 474 475 476 | |
mewbo_tools.integration.homeassistant
¶
Home Assistant integration tools and data models.
CacheHolder
¶
Bases: Protocol
Protocol describing objects with a Home Assistant cache attribute.
Attributes:
| Name | Type | Description |
|---|---|---|
cache |
HomeAssistantCache
|
Home Assistant cache payload. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
46 47 48 49 50 51 52 53 54 | |
HomeAssistant
¶
Bases: AbstractTool
A service to manage and interact with Home Assistant.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
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 350 351 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 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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
__init__() -> None
¶
Initialize the Home Assistant tool with environment defaults.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
call_service(domain: str, service: str, entity_id: str, data: dict | None = None) -> tuple[bool, list[dict[str, Any]]]
¶
Call a service in Home Assistant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
Home Assistant domain name (e.g., "light"). |
required |
service
|
str
|
Service name within the domain (e.g., "turn_on"). |
required |
entity_id
|
str
|
Entity ID to target. |
required |
data
|
dict | None
|
Optional extra payload for the service call. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[bool, list[dict[str, Any]]]
|
Tuple of success flag and JSON response payload. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the domain is not allowed. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
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 | |
get_state(action_step: ActionStep | None = None) -> MockSpeaker
¶
Generate response for a given action step based on sensors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_step
|
ActionStep | None
|
Action step describing the desired query. |
None
|
Returns:
| Type | Description |
|---|---|
MockSpeaker
|
MockSpeaker with the generated response. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If action_step is None. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
set_state(action_step: ActionStep | None = None) -> MockSpeaker
¶
Predict and call a service for a given action step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_step
|
ActionStep | None
|
Action step describing the desired change. |
None
|
Returns:
| Type | Description |
|---|---|
MockSpeaker
|
MockSpeaker with a status message. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If action_step is None. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
update_cache() -> None
¶
Update the entire cache.
Raises:
| Type | Description |
|---|---|
ValueError
|
If entity IDs cannot be derived. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
385 386 387 388 389 390 391 392 393 394 395 | |
update_entities() -> bool
¶
Update the list of entities from Home Assistant.
Returns:
| Type | Description |
|---|---|
bool
|
True when entities are fetched successfully. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
update_entity_ids() -> bool
¶
Update the list of entity IDs from Home Assistant.
Returns:
| Type | Description |
|---|---|
bool
|
True when entity IDs are populated. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no entities are available for ID extraction. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
update_services() -> bool
¶
Update the list of services from Home Assistant.
Returns:
| Type | Description |
|---|---|
bool
|
True when services are fetched successfully. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
HomeAssistantCache
¶
Bases: TypedDict
Cached Home Assistant entity and service metadata.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
34 35 36 37 38 39 40 41 42 43 | |
HomeAssistantCall
¶
Bases: BaseModel
Structured Home Assistant service call extracted from the model output.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
validate_domain(domain: str, info: ValidationInfo) -> str
classmethod
¶
Validate the domain against the cache when available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type[Any]
|
Pydantic model class. |
required |
domain
|
str
|
Domain string to validate. |
required |
info
|
ValidationInfo
|
Pydantic validation info with access to other field values. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Validated domain string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the domain is not found in the cache. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
validate_entity_id(entity_id: str, info: ValidationInfo) -> str
classmethod
¶
Validate the entity_id against the cache when available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type[Any]
|
Pydantic model class. |
required |
entity_id
|
str
|
Candidate entity identifier. |
required |
info
|
ValidationInfo
|
Pydantic validation info with access to other field values. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Validated entity identifier. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the entity ID is not found in the cache. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
SupportsInvoke
¶
Bases: Protocol
Protocol for runnable chains that return HomeAssistantCall.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
57 58 59 60 61 62 63 64 65 66 67 68 69 | |
invoke(input_data: dict[str, Any]) -> HomeAssistantCall
¶
Invoke the chain with structured input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
dict[str, Any]
|
Input payload for the chain. |
required |
Returns:
| Type | Description |
|---|---|
HomeAssistantCall
|
Parsed HomeAssistantCall. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
60 61 62 63 64 65 66 67 68 69 | |
cache_monitor(func: Callable[Concatenate[SelfT, P], R]) -> Callable[Concatenate[SelfT, P], R]
¶
Decorator to monitor and update the cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[Concatenate[SelfT, P], R]
|
Method that updates a portion of the cache. |
required |
Returns:
| Type | Description |
|---|---|
Callable[Concatenate[SelfT, P], R]
|
Wrapped function that normalizes cache contents after execution. |
Source code in packages/mewbo_tools/src/mewbo_tools/integration/homeassistant.py
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 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 | |
mewbo_tools.integration.lsp
¶
Native LSP integration for Mewbo.
Provides a single lsp_tool that the agent can optionally invoke for
code diagnostics, go-to-definition, find-references, and hover info.
Language servers are spawned lazily and scoped per-session.
get_lsp_manager(cwd: str) -> LSPServerManager
¶
Return (or create) the LSP manager for cwd.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/__init__.py
78 79 80 81 82 83 84 85 86 87 | |
get_passive_diagnostics(file_path: str, cwd: str) -> str | None
¶
Return formatted diagnostics for file_path, or None.
Called by the tool-use loop after file edits to provide passive
feedback to the LLM. Returns None if LSP is unavailable or
no errors/warnings were found.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/__init__.py
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 | |
run_lsp_async(coro: Coroutine[object, object, T], *, timeout: float = 30) -> T
¶
Run an async coroutine on the persistent LSP event loop.
This bridges the sync tool code to the async pygls client without creating/destroying event loops on each call.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/__init__.py
60 61 62 63 64 65 66 67 68 | |
shutdown_lsp_managers() -> None
async
¶
Shut down all LSP managers. Called on session end.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/__init__.py
133 134 135 136 137 138 139 140 141 142 143 | |
mewbo_tools.integration.lsp.manager
¶
LSP server manager — lazy startup, per-session lifecycle.
Uses pygls.lsp.client.BaseLanguageClient for all protocol handling.
We only manage lifecycle and map file extensions to servers.
LSPServerManager
¶
Per-session language server manager.
Servers are started lazily on first request for a matching file type.
All servers are shut down via :meth:shutdown_all on session end.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/manager.py
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 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 | |
ensure_server(file_path: str) -> BaseLanguageClient | None
async
¶
Start the appropriate server for file_path if not running.
Returns None if no server is available or the server is marked
failed.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/manager.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
get_cached_diagnostics(file_path: str) -> list[types.Diagnostic]
¶
Return diagnostics pushed by the server for file_path.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/manager.py
79 80 81 82 | |
open_file(client: BaseLanguageClient, file_path: str) -> None
async
¶
Notify the server that a file has been opened.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/manager.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
server_for_file(file_path: str) -> ServerDef | None
¶
Return the server definition for file_path, or None.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/manager.py
59 60 61 62 | |
shutdown_all() -> None
async
¶
Shut down all running language servers.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/manager.py
109 110 111 112 113 114 115 116 117 118 119 120 | |
mewbo_tools.integration.lsp.servers
¶
Built-in language server definitions.
ServerDef
dataclass
¶
A language server that can be spawned for files matching extensions.
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/servers.py
9 10 11 12 13 14 15 16 17 | |
available_servers(overrides: dict[str, dict] | None = None) -> list[ServerDef]
¶
Return servers whose command binary is installed on the system.
overrides can disable built-in servers ({"pyright": {"disabled": true}})
or add custom ones ({"my-lsp": {"command": [...], "extensions": [...], ...}}).
Source code in packages/mewbo_tools/src/mewbo_tools/integration/lsp/servers.py
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 | |
packages/mewbo_graph (knowledge-graph capability library)¶
The optional substrate shared by Agentic Wiki and Mewbo Search. Requires the library extras (treesitter, retrieval); absent when uninstalled.
Agentic Wiki substrate (mewbo_graph.wiki)¶
mewbo_graph.wiki.graph
¶
Wiki code-graph module.
Two atomic classes share the same domain (the code knowledge graph) at different phases:
GraphIndexruns at indexing time — tree-sitter-driven AST extraction yielding flatGraphNode+GraphEdgelists that the store persists.KnowledgeGraphViewruns at view time — loads a slug's persisted nodes- edges, computes lightweight stats, and serialises a Cytoscape-friendly
wire shape for the
/v1/wiki/projects/<slug>/graphendpoint.
Keeping both in one module avoids splitting the same domain across files; each class owns its own state and behaviour over that state.
GraphIndex
¶
AST-graph extractor.
Constructed once per wiki indexing job. Caches loaded languages and compiled queries so per-file parse is a hot-loop friendly call.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/graph.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 | |
__init__() -> None
¶
Initialise caches and verify that the wiki extras are installed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/graph.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
parse_file(slug: str, file_path: Path, *, repo_root: Path) -> GraphParseResult
¶
Parse a single file.
Returns an empty result — the path lands in skipped, same as an
unsupported extension — for a file with no supported extension, one
under a vendored directory, or one that looks minified. This is the
ONE seam every caller funnels through (parse_repo, the agent-driven
wiki_build_graph tool, and the zero-LLM GraphOnlyIndexer each
build their own file list independently and never share a walk), so
gating it here is what makes the exclusion apply everywhere rather
than needing to be re-applied at each caller's own file-collection
site.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/graph.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
parse_repo(slug: str, repo_root: Path, files: list[Path], *, on_progress: Callable[[int, int, str], None] | None = None) -> GraphParseResult
¶
Parse every file. Files outside the supported set go to skipped.
on_progress(done, total, path) is called after each file when
supplied. It is INJECTED rather than written here because progress is
persisted against an indexing job, which this parser knows nothing about
— and because the loop is the only place that knows how far along it is.
The throttling is the callee's business (see PhaseProgress); this
loop reports every file and never decides what is worth writing.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/graph.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
GraphParseResult
dataclass
¶
Output of a single-file or repo parse.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/graph.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
__add__(other: GraphParseResult) -> GraphParseResult
¶
Merge two results by concatenating their node, edge, and skipped lists.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/graph.py
159 160 161 162 163 164 165 | |
KnowledgeGraphView
dataclass
¶
Slug-scoped projection of the persisted MULTIPLEX graph for the viewer.
Three node layers share one viewer payload: the tree-sitter ast layer
(File/Class/Function/… + synthesized External convergence nodes), the
abstract entity layer, and the atomic-note memory layer. Edges carry
a layer tag — ast (CONTAINS/IMPORTS/CALLS/EXTENDS/REFERENCES),
entity (entity↔entity RELATES, open-vocab verb in label), memory
(note RELATES) and cross (ANCHORS spanning layers).
Construction is exclusively via for_slug so the invariant — every node +
edge belongs to the same slug, and every emitted edge endpoint is a real
node in the payload — stays enforced in one place. Once built, the instance
is immutable; safe to share across requests and trivially cacheable upstream.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/graph.py
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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 | |
edge_count: int
property
¶
AST-layer edges in this view (post-filter).
kinds: dict[str, int]
property
¶
Per-kind histogram over EVERY node this view puts on the wire.
Counts the Entity, Memory and Folder classes alongside the AST kinds because the FE derives its whole legend from this one map: it lists a kind only when the tally is positive, and sums the same map to decide which LAYERS to offer. Counting the AST layer alone therefore did not merely under-report — it drew those three classes on the canvas with no legend entry and no toggle, so a user could neither identify them nor turn them off.
Folder is counted only in the hierarchy wire mode, which is the only mode that emits Folder nodes.
node_count: int
property
¶
AST nodes in this view (real + External), drives the truncation banner.
for_slug(store: WikiStoreBase, slug: str, *, node_limit: int | None = None, hierarchy: bool = False, scope: CommitScope | None = None) -> KnowledgeGraphView
classmethod
¶
Load the full multiplex (ast + entity + memory layers) for slug.
Commit-scoped. scope defaults to store.live_scope(slug) — the
project's own commit — so the viewer shows the code as it is now. Before
this the AST layer was read unscoped, which is why the payload was the
union of every generation ever indexed: deleted code rendered alongside
live code with nothing distinguishing them, and the node count grew
monotonically with re-indexes rather than with the repository.
Pass an explicit scope to read a specific generation; pass
CommitScope.every() to restore the pre-scoping union (which the
entity-anchor repair below relies on, and nothing else should).
AST connectivity: a cross-file IMPORTS/CALLS/EXTENDS edge carries the
raw target_name; if that name resolves to a real in-repo node it is
re-pointed there (genuinely connecting File-clusters through shared
symbols), otherwise every reference to the same external name converges
on ONE synthesized External view-node.
node_limit (when set and exceeded) degree-prunes the whole AST
payload — real nodes AND the view-synthesized External nodes
together, not the persisted layer alone. The AST nodes are pruned
first (unchanged from before: highest-degree kept, ties on
node_id); External nodes then get whatever budget is left,
pruned by the same degree-then-node_id rule over their surviving
edges. A node_limit that the AST layer alone does not exceed can
still cap externals down, and an AST layer that exhausts the whole
budget leaves externals at zero — both are the cap "governing the
whole payload" rather than only the persisted one. Entity + memory
layers are always fully included (they're small) and never counted
against this cap. total_nodes/total_edges always reflect the
full AST graph so the wire response can honestly say "showing N of M".
Cross-layer ANCHORS are reconciled to real node ids in O(nodes+edges):
memory ANCHORS targets (EntityKey / entity:<id>) batch-resolve
through the existing CodeStructureProvider + EntityAnchorResolver;
an anchor that resolves to nothing is dropped (no dangling edges).
hierarchy (default off) synthesises a directory scaffold via
FolderTree from the kept File nodes' paths — folder nodes + folder
CONTAINS edges, and a single parentId per node — and stamps it
onto the wire in to_wire. Off ⇒ the wire is byte-identical to the
default mode (the SCG / Agentic Search reuse path is undisturbed).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/graph.py
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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 | |
to_wire() -> dict[str, Any]
¶
Wire shape: {slug, nodes, edges, stats} over all three layers.
Each node/edge is Cytoscape-ready ({data: {...}}) and carries a
layer tag so the FE can style/filter per layer. The FE hands the
arrays straight to cy.add(elements) with no intermediate transform.
When the view was built with hierarchy=True the directory scaffold
is merged in: synthesised Folder nodes + their CONTAINS edges
are appended, and every emitted node gains a parentId /
folderPath (folderCount lands in stats). With hierarchy off
the folder_tree is None and the payload is byte-identical to the
default mode.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/graph.py
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 | |
LanguageSpec
dataclass
¶
One tree-sitter-backed language the code-graph extractor supports.
query_file defaults to <name>.scm — set it only when a language's
query file diverges from its language name, as tsx does: it is a
SEPARATE grammar from typescript (the two disagree about whether
<T> opens a type assertion or a JSX element) but the node types the
graph captures are identical, so one query file serves both.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/graph.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
query_filename: str
property
¶
Resolved query file name — query_file override, else <name>.scm.
mewbo_graph.wiki.structure_provider
¶
StructureProvider — the code↔multiplex-key bridge.
entity_key (path/to/file.py#Qualified.Name, no byte offsets) is the
shared identity that joins the memory and docs layers to the code graph.
This module owns the only derivation of an entity_key from a
GraphNode and the resolution back to a live node.
StructureProvider is a Protocol so the structural layer is pluggable
(corpus-agnostic seam — code today; PDF sections / DB schemas later). v1 ships
exactly one implementation, CodeStructureProvider, which composes over the
wiki store. Keep it stateless: a refresh mutates the graph, so a cached map
would go stale.
CodeStructureProvider
¶
StructureProvider over the tree-sitter code graph (v1).
The two directions read different commit scopes, on purpose.
resolve/resolve_many answer "where does this key live now", so
they read the live generation: an entity_key carries no byte offset, so
it re-resolves cleanly onto whatever generation is current, and returning a
superseded node would hand the caller a node id no live payload contains.
entity_key_of answers the opposite question about a node id recorded in
the PAST — a QA provenance ref from an earlier session — so it must read
the union or it would fail to label exactly the historical refs it exists
to label.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/structure_provider.py
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 | |
__init__(store: WikiStoreBase, *, scope: CommitScope | None = None) -> None
¶
Compose over a wiki store; scope defaults to the slug's live commit.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/structure_provider.py
72 73 74 75 | |
entity_key_of(slug: str, node_id: str) -> EntityKey | None
¶
Return the entity_key for a code node_id, or None.
Reads EVERY generation deliberately — see the class docstring. The
callers hand it node ids captured during earlier sessions, and a node
id embeds the symbol's byte offset, so any edit since then re-keyed it
out of the live generation. Scoping this would turn a resolvable
historical citation into an unknown(...) label.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/structure_provider.py
104 105 106 107 108 109 110 111 112 113 114 115 116 | |
resolve(slug: str, entity_key: EntityKey) -> GraphNode | None
¶
Return the node addressed by entity_key, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/structure_provider.py
81 82 83 84 85 86 | |
resolve_many(slug: str, entity_keys: list[EntityKey]) -> dict[EntityKey, GraphNode]
¶
Resolve a batch in one graph pass; misses are omitted.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/structure_provider.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
StructureProvider
¶
Bases: Protocol
Resolves between entity_key and the underlying structural unit.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/structure_provider.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
entity_key_of(slug: str, node_id: str) -> EntityKey | None
¶
Return the entity_key for a code node_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/structure_provider.py
53 54 55 | |
resolve(slug: str, entity_key: EntityKey) -> GraphNode | None
¶
Return the node addressed by entity_key, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/structure_provider.py
43 44 45 | |
resolve_many(slug: str, entity_keys: list[EntityKey]) -> dict[EntityKey, GraphNode]
¶
Resolve a batch in one pass; misses are omitted from the result.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/structure_provider.py
47 48 49 50 51 | |
entity_key_for_node(node: GraphNode) -> EntityKey
¶
Derive the multiplex entity_key for a code node.
File nodes key on their bare path; every other symbol keys on
file#name. name is the tree-sitter symbol name — class→method
qualification lands with the graph's scoping work, so two same-named
methods in one file currently collapse to one key (an accepted v1
over-approximation: a false anchor is wasted work, never data loss).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/structure_provider.py
25 26 27 28 29 30 31 32 33 34 35 36 | |
mewbo_graph.wiki.embedder
¶
Embedder — thin wrapper around litellm.embedding.
LiteLLM is the project's canonical LLM client (chat completions already route through it), so embeddings ride the same proxy plumbing for free. This module's job is to:
- Read the configured embedding model from
wiki.embedding.model. - Normalise it with the proxy prefix (
openai/<model>) so LiteLLM sends the request to our OpenAI-compatible LiteLLM proxy instead of trying to dispatch directly to a provider SDK. - Wrap
litellm.embeddingso its return value materialises into our typedEmbeddingrecords (with slug + node_id + dim). - Provide
cosineandsearchstatic helpers.
Embedding is I/O-bound, not CPU-bound: a large indexing pass spends its
time waiting on the network, one blocking call after another, while the
process itself sits near idle. _EmbeddingPacer is what turns that into
a bounded, rate-limit-aware pool of concurrent requests instead of a
serial loop — see its docstring for the pacing/backoff contract.
KISS: no third-party LangChain abstraction layer, no batching wrappers — LiteLLM already handles batching and provider routing; this module adds only the concurrency/pacing layer LiteLLM does not provide.
Embedder
¶
Thin facade: litellm.embedding + typed Embedding records.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 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 350 351 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 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 475 476 477 478 479 480 481 482 483 484 485 486 | |
__init__(*, model: str | None = None, batch_size: int | None = None, concurrency: int | None = None, requests_per_minute: int | None = None, tokens_per_minute: int | None = None, max_retries: int | None = None, sleeper: Callable[[float], None] | None = None) -> None
¶
Construct the Embedder from config + kwargs.
sleeper is the retry wait, injected as a collaborator so a caller
observing the backoff observes only THIS object's waiting. Patching
time.sleep on the stdlib module instead reaches every module and
every thread in the process: the observation picks up unrelated
waiting, and neutering it turns any concurrent poll loop into a spin.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
238 239 240 241 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 275 276 277 278 279 280 281 282 283 284 285 286 | |
cosine(a: list[float], b: list[float]) -> float
staticmethod
¶
Cosine similarity. Returns 0.0 if either vector is zero-length.
Delegates to the shared, dependency-free mewbo_graph._util.cosine so
the wiki vector math and the entity resolution ladder can never desync.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
466 467 468 469 470 471 472 473 | |
embed_nodes(items: list[tuple[str, str]], *, slug: str = '') -> list[Embedding]
¶
Embed (node_id, text) pairs and return Embedding records.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
embed_query(text: str) -> list[float]
¶
Embed a single query string. Stays cheap: never spins up a pool.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
332 333 334 335 | |
enabled() -> bool
staticmethod
¶
True when node embedding is switched on (wiki.embedding.enabled).
The switch lives with the class that owns embedding rather than beside one of its callers: every path that embeds — the full index and the scoped refresh — has to read the same knob, and an operator who turns embedding off has no way to tell which caller re-implemented the read. Defaults to on, so an absent key never silently disables retrieval.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
288 289 290 291 292 293 294 295 296 297 298 | |
search(qvec: list[float], vectors: list[list[float]], k: int = 10) -> list[tuple[int, float]]
staticmethod
¶
Return (index, cosine_score) for the top-k matches, sorted desc.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
475 476 477 478 479 480 481 482 483 484 485 486 | |
EmbedderProtocol
¶
Bases: Protocol
The duck-typed embedder surface retriever/ingestor depend on.
Embedder (litellm-backed) and _NullEmbedder (BM25-fallback null
object) both satisfy this; typing against it instead of Any catches
wiring errors at definition.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
embed_nodes(items: list[tuple[str, str]], *, slug: str = '') -> list[Embedding]
¶
Embed (node_id, text) pairs into Embedding records.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
65 66 67 68 69 | |
embed_query(text: str) -> list[float]
¶
Embed a single query string into a vector.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
71 72 73 | |
make_embedder() -> Embedder
¶
Construct the wiki Embedder using the configured proxy + model.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
76 77 78 | |
make_embedder_for(store: Any, slug: str) -> Embedder
¶
Build the Embedder bound to slug's own embedding model.
THE reason this exists rather than each caller reading config: the write
side and the read side have to agree. Two embedding models rarely share a
vector width, and vector_search scores cosine over whatever is stored —
so a query embedded with a different model than the vectors it is scored
against returns wrong neighbours rather than an error. Resolving both sides
through one function is what makes that agreement structural instead of a
convention every new retrieval site has to remember.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
104 105 106 107 108 109 110 111 112 113 114 115 | |
make_embedder_for_or_none(store: Any, slug: str) -> Embedder | None
¶
Build slug's Embedder, or None when the caller may fall back to BM25.
The graceful twin of :func:make_embedder_for, for the write paths where a
missing embedding backend must degrade retrieval rather than fail an index.
It resolves the project's model and then goes through
:func:make_embedder_or_none rather than constructing directly, so there
stays exactly ONE graceful construction path however the model was chosen.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
118 119 120 121 122 123 124 125 126 127 | |
make_embedder_or_none(model: str | None = None) -> Embedder | None
¶
Build an Embedder, or None if it can't be constructed (BM25-only).
The single construction path for callers that must degrade gracefully when no embedding backend is configured — used by insight ingestion so a missing proxy never fails a write.
model is the project's own embedding model, or None to inherit the
deployment default. It is a defaulted parameter rather than a second
function because every caller degrades identically; splitting them would
give the graceful path two implementations, and a test patching one of them
would let the other build a live Embedder and reach the network.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
project_embedding_model(store: Any, slug: str) -> str | None
¶
The embedding model slug is indexed and searched with, or None.
None means "inherit wiki.embedding.model" — the answer for every
project indexed before the override existed, and for every project whose
operator never set one.
Best-effort by construction: a store that cannot be read answers None
rather than raising. Falling back to the deployment default is what the
caller would have done anyway, so a store hiccup degrades to today's
behaviour instead of failing an index or a search.
Cost class: O(one record) — a single slug-keyed settings read.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/embedder.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
mewbo_graph.wiki.retriever
¶
HybridRetriever — BM25 + cosine + RRF fusion + graph/memory expansion.
Operates over two base candidate sets: wiki pages (text bodies) and graph nodes (name + docstring text). BM25 always runs over both. Vector cosine only over graph nodes (pages aren't embedded in v1). Final ranking is reciprocal-rank-fusion (RRF, k=60).
The memory multiplex layer is an additive overlay: with memory_expand,
MultiplexExpander seeds atomic memory notes by cosine, then follows each
note's ANCHORS edges back to code entities (+ their 1-hop structural
neighbours), additive-fusing a small w_ppr booster (GAAMA's
0.1·ppr + 1.0·sim). Hubs are degree-damped. memory_expand=False skips
the overlay entirely, leaving the RRF ranking above untouched.
HybridHit
dataclass
¶
Single ranked result returned by HybridRetriever.search.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/retriever.py
38 39 40 41 42 43 44 45 46 | |
HybridRetriever
¶
Atomic retriever — store + embedder at construction; one public search method.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/retriever.py
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 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 220 221 222 223 224 225 | |
__init__(*, store: WikiStoreBase, embedder: EmbedderProtocol, expander: MultiplexExpander | None = None) -> None
¶
Initialise with a store backend, an embedder, and optional expander.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/retriever.py
52 53 54 55 56 57 58 59 60 61 62 | |
search(slug: str, query: str, *, k: int = 10, types: list[str] | None = None, graph_expand: bool = False, sources: Literal['pages', 'graph', 'both'] = 'both', memory_expand: bool = False, memory_filters: MemoryFilter | None = None) -> list[HybridHit]
¶
Return up to k results fused from BM25, cosine, graph/memory expansion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Project slug (e.g. "org/repo"). |
required |
query
|
str
|
Free-text search query. |
required |
k
|
int
|
Maximum number of results to return. |
10
|
types
|
list[str] | None
|
Filter graph candidates to these node types (e.g. ["Class"]). |
None
|
graph_expand
|
bool
|
When True, 1-hop neighbours of top graph hits are added. |
False
|
sources
|
Literal['pages', 'graph', 'both']
|
Which candidate pools to include — "pages", "graph", or "both". |
'both'
|
memory_expand
|
bool
|
When True, additive-fuse the memory multiplex layer. |
False
|
memory_filters
|
MemoryFilter | None
|
Optional |
None
|
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/retriever.py
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 | |
MultiplexExpander
¶
Cross-layer retrieval: memory seeds → anchored code → structural hops.
Atomic, injectable (store + optional structure provider). Seeds atomic
memory notes by cosine (memory_vector_search, MemoryFilter-aware,
invalidated-excluded), then for each note follows its ANCHORS edges
back to live code entities and their ≤expansion_hops structural
neighbours, scoring an additive w_ppr booster and damping hub nodes
(degree > hub_degree).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/retriever.py
231 232 233 234 235 236 237 238 239 240 241 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 275 276 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 350 351 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 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
provider: StructureProvider
property
¶
Lazily build the default code structure provider.
__init__(*, store: WikiStoreBase, provider: StructureProvider | None = None, w_ppr: float = 0.1, hub_degree: int = 50, expansion_hops: int = 1, rrf_k: int = _RRF_K) -> None
¶
Inject store + (lazy) structure provider and fusion knobs.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/retriever.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
expand(slug: str, query_vec: list[float], *, k: int = 10, filt: MemoryFilter | None = None) -> list[HybridHit]
¶
Return memory-seed hits + their anchored/expanded code hits.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/retriever.py
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 350 351 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 | |
from_store(store: WikiStoreBase, *, provider: StructureProvider | None = None, w_ppr: float | None = None, hub_degree: int | None = None, expansion_hops: int | None = None) -> MultiplexExpander
classmethod
¶
Build an expander with the wiki.memory.* fusion knobs applied.
The one composition root a production caller reaches (HybridRetriever
builds its default expander through it), so the knobs are read HERE and
passed down as arguments rather than inside the class. Each constructor
default already equals its config default, which is exactly what made
the gap invisible: an expander built with none of them behaves like a
correctly configured one on a default deployment, so an operator who
retunes hub_degree sees no error and no effect. Keeping the read out
of the class body also keeps it pure DI — a test constructs it directly
and is never at the mercy of a deployment setting it cannot see.
Config decides the DEFAULT, never "whether": an explicitly passed knob
(or an expander injected into HybridRetriever) still wins.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/retriever.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
mewbo_graph.wiki.memory
¶
Insight ingestion — the DRY write core behind all memory surfaces.
One InsightIngestor backs the SessionTool, the REST endpoint, and the MCP
tool. Given a claim (or raw text to condense) plus optional
anchors, it: condenses → embeds → resolves/auto-resolves anchors → runs the
3-tier dedup/merge ladder → upserts node + embedding + edges. Every
collaborator (store, embedder, structure provider, deduper, condenser, clock)
is constructor-injected so the core is unit-testable with stubs only at the
LLM/embedding I/O boundary.
Atomicity is load-bearing: a condensed blob becomes several ≤200-char notes, and a merge keeps the crisper of two overlapping notes (Molecular Facts / AtomicRAG) rather than concatenating them.
AnchorResolver
¶
Bases: Protocol
The node-agnostic anchor seam the ingestor depends on.
The ingestor only needs to map a node_id back to its entity_key and
to test which anchor keys resolve to a live unit — it never inspects the
resolved node itself. Typing that surface as Mapping[..., object] (a
covariant value) lets any corpus's provider satisfy it: the wiki
CodeStructureProvider (code graph) and the SCG ScgAnchorResolver
(connector graph) both conform without a cast, so an alternate corpus plugs
its own node type in cleanly. StructureProvider is a structural subtype.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
entity_key_of(slug: str, node_id: str) -> EntityKey | None
¶
Return the entity_key for a resolved node_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
64 65 66 | |
resolve_many(slug: str, entity_keys: list[EntityKey]) -> Mapping[EntityKey, object]
¶
Resolve a batch of anchor keys; misses are omitted from the result.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
58 59 60 61 62 | |
DedupDecision
dataclass
¶
Verdict from the dedup ladder for a candidate note.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
160 161 162 163 164 165 166 | |
IngestResult
¶
Bases: BaseModel
Aggregate result of one ingest call (one+ claims).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
116 117 118 119 120 121 122 123 124 125 126 | |
ok: bool
property
¶
True if at least one claim was stored (not all rejected).
IngestedClaim
¶
Bases: BaseModel
Outcome for a single atomic claim processed by the ingestor.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
103 104 105 106 107 108 109 110 111 112 113 | |
InsightCondenser
¶
LLM decomposition of raw text into atomic claims (raw path only).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
__init__(llm: Any) -> None
¶
Inject a chat model (.invoke → text).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
142 143 144 | |
condense(raw: str) -> list[str]
¶
Return atomic claims for raw. May raise — callers treat as non-fatal.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
146 147 148 149 150 151 152 153 154 | |
InsightDeduper
¶
3-tier dedup/merge: exact node_id → fuzzy Jaccard → LLM over cosine-kNN.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 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 | |
__init__(*, store: WikiStoreBase, llm: Any = None, fuzzy_jaccard: float = 0.85, dedup_k: int = 5, dedup_cosine: float = 0.6, min_token_len: int = 3) -> None
¶
Inject the store; llm optional (tier-3 degrades to NEW).
Similarity uses the stateless Embedder.cosine + the store's
memory_vector_search, so no embedder instance is needed here.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
classify(slug: str, candidate: MemoryNode, *, candidate_vec: list[float] | None = None) -> DedupDecision
¶
Classify candidate against existing notes (NONE-default → NEW).
SCALE: tiers 2+3 run over the cosine-kNN candidate set (the single
memory_vector_search ANN seam), NOT the whole store — so dedup is
O(dedup_k) similarity work per ingest, and upgrading that one seam
to a real ANN index makes the entire ladder sublinear. (A lexical
near-duplicate is also an embedding near-duplicate, so scoping fuzzy
to the kNN set never misses one.) Only when no embedding is available
(BM25-only) does it fall back to a bounded full scan.
DRY: tiers 2+3 delegate the block→score→decide step to the ONE generic
ResolutionLadder shared with entity resolution. The injected
strategies hold the tier thresholds EXACTLY — fuzzy_jaccard
⇒ the merge band, dedup_cosine ⇒ the LLM (flag) band, NONE-default
⇒ NEW — so the ladder's bands and the tiers are one rule (see
_build_ladder).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
201 202 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 240 241 242 243 244 245 246 247 248 | |
InsightIngestor
¶
DRY write core: condense → embed → anchor → dedup/merge → upsert.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
349 350 351 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 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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 | |
__init__(*, store: WikiStoreBase, embedder: EmbedderProtocol, provider: AnchorResolver, deduper: InsightDeduper, condenser: InsightCondenser | None = None, clock: Any = None, max_anchors: int = 8, max_chars: int = MAX_INSIGHT_CHARS, auto_anchor_k: int = 3) -> None
¶
Wire collaborators (all injected); condenser is optional.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
from_store(store: WikiStoreBase, *, embedder: EmbedderProtocol | None = None, slug: str | None = None, llm: Any = None, condenser: InsightCondenser | None = None, clock: Any = None, provider: AnchorResolver | None = None, deduper: InsightDeduper | None = None, max_anchors: int | None = None, max_chars: int | None = None) -> InsightIngestor
classmethod
¶
Build an ingestor with the standard collaborators (DRY across surfaces).
The single construction path shared by the SessionTool, the REST
endpoint, and the MCP tool, so every surface dedups/anchors
identically. embedder defaults to the wiki Embedder (BM25-only
_NullEmbedder when none can be built); llm/condenser are
opt-in (the in-session tool leaves them off — agents pre-atomize).
provider overrides the default CodeStructureProvider so an
alternate corpus (e.g. the SCG connector graph) can resolve its own
anchors; None keeps the code-graph default (backward-compatible).
The wiki.memory.* knobs are read HERE, at the one composition root
every production caller goes through, and passed down as arguments. The
failure mode that made this necessary is invisible: this class and
InsightDeduper take each knob as a keyword argument whose default
EQUALS the config default, so an ingestor built with none of them
behaves exactly like a correctly configured one on a default
deployment — an operator who retunes dedup_k or max_anchors
sees no error and no effect. Reading them here keeps both classes pure
DI: a class that read config itself could not be constructed in a test
without one, and a directly-constructed one would silently start
obeying a deployment setting the test had no way to see.
Config decides the DEFAULT, never "whether" — an explicitly passed
deduper/max_anchors/max_chars still wins.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
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 | |
ingest(slug: str, content: str | None = None, *, raw: str | None = None, anchors: list[EntityKey] | None = None, links: list[str] | None = None, kind: MemoryKind = 'propositional', labels: list[str] | None = None, corpus: str = 'code', condense: bool = False, source: MemorySource = 'indexer', author_agent: str = 'insight', session_id: str | None = None) -> IngestResult
¶
Ingest a claim (or condensed raw blob) into the memory graph.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
llm_text(llm: Any, prompt: str) -> str
¶
Invoke a chat model and coerce its reply to plain text.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory.py
93 94 95 96 97 | |
mewbo_graph.wiki.memory_types
¶
Pydantic models for the multiplex memory layer.
These overlay an evolving memory + docs graph on the existing tree-sitter
code graph (types.py). Three node families share one identity namespace
(EntityKey):
- Code entities — the existing
GraphNode/GraphEdge(untouched). - Memory notes —
MemoryNode(ultra-small atomic claims) reified as nodes thatANCHORSto code entities andRELATESto siblings. - Doc pages —
DocPageNote(one generated wiki page = one node) anchored to the code it documents.
Conventions match types.py: model_config = ConfigDict(extra="forbid",
populate_by_name=True) and snake_case attributes. MemoryNode.node_id is
derived — sha1(slug | content.strip().lower())[:16] — so two notes with
the same normalized claim collapse to the same id (the exact-dup dedup tier).
DocPageNote
¶
Bases: BaseModel
A generated wiki page as a first-class multiplex node.
Anchored to code via anchor_keys (resolved from the page's
frontmatter relevantSources). The incremental refresh propagates
change impact onto these to decide keep/edit/regenerate/create.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory_types.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 | |
FileManifest
¶
Bases: BaseModel
Per-(slug, path) content-hash + entity index for scoped retraction.
The incremental refresh diffs the stored content_hash against the
working tree and, for dirty files, retracts exactly the listed
entity_keys instead of rebuilding the whole graph.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory_types.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
MemoryEdge
¶
Bases: BaseModel
Directed multiplex edge.
ANCHORS: memory node_id → code EntityKey (the de-facto
hyperedge fan-out). RELATES: memory node_id → memory node_id.
Validity is a single nullable axis — invalid_at=None means live;
setting it invalidates the edge (Graphiti invalidate-don't-delete).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory_types.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
MemoryEmbedding
¶
Bases: BaseModel
Dense embedding vector for a memory node (mirrors Embedding).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory_types.py
119 120 121 122 123 124 125 126 127 128 | |
MemoryFilter
¶
Bases: BaseModel
Optional facets applied to memory retrieval (all default to no-op).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory_types.py
201 202 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 | |
matches_node(node: MemoryNode) -> bool
¶
Return True if node satisfies the node-level facets.
Edge-level validity (valid_at / exclude_invalidated) is
applied separately by the store/retriever against the edge set.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory_types.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
MemoryNode
¶
Bases: BaseModel
An atomic memory claim reified as a multiplex graph node.
node_id is always derived from (slug, content) — any supplied
value is overwritten. This makes identical normalized claims share one
id, which is exactly the exact-match tier of the dedup ladder.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory_types.py
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 | |
compute_node_id(slug: str, content: str) -> str
staticmethod
¶
Deterministic id over (slug, normalized content).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory_types.py
84 85 86 87 88 | |
MemoryProvenance
¶
Bases: BaseModel
Who/when/how a memory note was created — citable audit trail.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/memory_types.py
48 49 50 51 52 53 54 55 56 57 | |
mewbo_graph.wiki.store
¶
Wiki persistence layer.
JSON-file backed implementation (default) + abstract base for the
MongoDB impl that lands in Task 1.4. Layout under $MEWBO_HOME/wiki/:
projects/<slug>.json (Project model — DISPLAY snapshot)
settings/<slug>.json (ProjectSettings — the editable record)
pages/<slug>/_index.json (page-id→title index for fast listing)
pages/<slug>/<page_id>.json (full WikiPage including body)
jobs/<job_id>/job.json (IndexingJob model)
jobs/<job_id>/events.jsonl (append-only event log with idx)
jobs/<job_id>/session.txt (Mewbo session_id — one line)
qa/<answer_id>/answer.json (QaAnswer model)
qa/<answer_id>/events.jsonl (append-only event log with idx)
Slugs that contain slashes (e.g. "org/repo") are escaped as "org__repo" so they map safely to a single directory/filename segment.
JobPatch
dataclass
¶
The IndexingJob fields a caller NAMED, validated and nothing else.
The unit both drivers write, and what keeps two overlapping writers from losing each other's changes: "set these fields" and "rewrite the document that happens to hold them" are not the same operation. The second reverts every field a CONCURRENT writer changed between this writer's read and its write — a cancel landing between a progress writer's read and its write was silently undone, and the job carried on running with no record that a cancel had ever been asked for. Carrying only the named fields lets each backend narrow its write to what the caller actually asked for, so writers touching disjoint fields stop colliding at all.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
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 | |
apply(job: IndexingJob) -> IndexingJob
¶
Return job with this patch's fields set, re-validated as a whole.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
147 148 149 150 151 | |
build(job: IndexingJob, fields: Mapping[str, Any]) -> JobPatch
classmethod
¶
Validate fields against the WHOLE job, then keep only those keys.
Validation stays whole-document — an unknown key still fails
extra="forbid" and every value is still coerced by the field that
owns it — because what needed narrowing is the WRITE, not the check.
An explicit None is a VALUE here, never an omission: emit_phase
clears the three phase_progress_* fields by naming them, so dropping
falsy values (as the PROJECT_UPDATABLE filter does, for a surface
whose None genuinely means "not supplied") would silently discard
the write the progress invariant depends on.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
JsonWikiStore
¶
Bases: WikiStoreBase
File-backed implementation under $MEWBO_HOME/wiki/ (or a custom root).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 | |
__init__(root_dir: str | Path | None = None) -> None
¶
Initialise and create the directory tree.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 | |
append_qa_event(answer_id: str, event: dict[str, Any]) -> int
¶
Append event to the QA event log; return the monotonic idx.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1960 1961 1962 | |
attach_job_session(job_id: str, session_id: str) -> None
¶
Associate a Mewbo session_id with an indexing job.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1605 1606 1607 1608 1609 | |
attach_qa_session(answer_id: str, session_id: str) -> None
¶
Associate a Mewbo session_id with a QA answer.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1934 1935 1936 1937 1938 | |
bump_recovery_attempts(slug: str) -> int
¶
Atomically increment slug's recovery counter; return the new value.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1866 1867 1868 1869 1870 1871 1872 1873 | |
cancel_job(job_id: str) -> bool
¶
Cancel job_id; return True on first cancel, False if already cancelled.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 | |
claim_job_page(slug: str, job_id: str, page_id: str) -> PageClaim
¶
Record page_id under job_id, under the lock; count = set size.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 | |
count_entities(slug: str, *, commit_sha: str | None) -> int
¶
Count slug entities stamped exactly commit_sha (None matches None).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2580 2581 2582 2583 2584 2585 2586 | |
count_graph_nodes(slug: str, *, commit_sha: str | None) -> int
¶
Count slug nodes stamped exactly commit_sha (None matches None).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2156 2157 2158 2159 2160 2161 2162 | |
create_job(job: IndexingJob) -> None
¶
Persist a new indexing job.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1525 1526 1527 1528 | |
create_project(project: Project) -> None
¶
Persist a new project record.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1256 1257 1258 | |
delete_credentials(slug: str) -> bool
¶
Delete slug's credential file; return True if one existed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1814 1815 1816 1817 1818 1819 1820 | |
delete_doc_note(slug: str, page_id: str) -> bool
¶
Delete a doc-page note; return True if one was removed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2483 2484 2485 2486 2487 2488 2489 2490 2491 | |
delete_edges_by_source_file(slug: str, file: str) -> int
¶
Delete edges whose source node belongs to file; return count.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 | |
delete_file_manifest(slug: str, path: str) -> bool
¶
Delete a file-manifest entry; return True if one was removed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2519 2520 2521 2522 2523 2524 2525 2526 2527 | |
delete_memory_node(slug: str, node_id: str) -> bool
¶
Delete a memory node + its embedding; return True if one was removed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 | |
delete_nodes_by_file(slug: str, file: str) -> int
¶
Delete file's code nodes AND their vectors; return the NODE count.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 | |
delete_page(slug: str, page_id: str) -> bool
¶
Delete a single page on disk + drop it from the index.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 | |
delete_project(slug: str) -> bool
¶
Delete project slug; return True if deleted, False if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1273 1274 1275 1276 1277 1278 1279 | |
delete_project_settings(slug: str) -> bool
¶
Delete slug's settings file; return True if one existed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1297 1298 1299 1300 1301 1302 1303 | |
entity_vector_search(slug: str, qvec: list[float], k: int = 10) -> list[EntityEmbedding]
¶
Return top-k entity embeddings for slug by cosine similarity.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2612 2613 2614 2615 2616 2617 | |
find_job_by_session(session_id: str) -> str | None
¶
Reverse lookup: scan job dirs for the session.txt that matches session_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 | |
find_qa_by_session(session_id: str) -> str | None
¶
Reverse lookup: scan qa dirs for the session.txt that matches session_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 | |
get_act_plan(job_id: str) -> dict[str, Any] | None
¶
Return the persisted act-stage record, or None if stage 1 hasn't finished.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 | |
get_credentials(slug: str) -> dict[str, Any] | None
¶
Return the encoded credential blob for slug, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 | |
get_doc_note(slug: str, page_id: str) -> DocPageNote | None
¶
Return a single doc-page note, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2472 2473 2474 2475 2476 2477 | |
get_entity(slug: str, entity_id: str) -> Entity | None
¶
Return a single entity, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2564 2565 2566 2567 2568 2569 | |
get_entity_recommendations(slug: str) -> list[EntityRecommendation]
¶
Return every persisted entity recommendation for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2660 2661 2662 | |
get_file_manifest(slug: str, path: str) -> FileManifest | None
¶
Return a single file-manifest entry, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2508 2509 2510 2511 2512 2513 | |
get_job(job_id: str) -> IndexingJob | None
¶
Return the indexing job, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1530 1531 1532 | |
get_job_page_ids(slug: str, job_id: str) -> frozenset[str]
¶
Return the page ids job_id wrote (claim record, else attribution).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1745 1746 1747 | |
get_job_plan(job_id: str) -> list[dict[str, Any]] | None
¶
Return the page-plan list, or None if no plan has been committed yet.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 | |
get_job_session(job_id: str) -> str | None
¶
Return the session_id attached to job_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1611 1612 1613 1614 1615 1616 | |
get_job_submission(job_id: str) -> dict[str, Any] | None
¶
Return the persisted submission dict, or None if not yet saved.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 | |
get_job_submitted_count(job_id: str) -> int
¶
Return the number of pages submitted so far for job_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1708 1709 1710 1711 | |
get_memory_node(slug: str, node_id: str) -> MemoryNode | None
¶
Return a single memory node, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2341 2342 2343 2344 2345 2346 | |
get_project(slug: str) -> Project | None
¶
Return the project for slug, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1260 1261 1262 | |
get_project_settings(slug: str) -> ProjectSettings | None
¶
Return slug's settings record, or None when never written.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1293 1294 1295 | |
get_qa(answer_id: str) -> QaAnswer | None
¶
Return the QA answer, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1909 1910 1911 | |
get_qa_session(answer_id: str) -> str | None
¶
Return the session_id attached to answer_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1940 1941 1942 1943 1944 1945 | |
get_recovery_attempts(slug: str) -> int
¶
Return the recovery-attempt count for slug (0 if never recovered).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 | |
get_resume_plan(job_id: str) -> dict[str, Any] | None
¶
Return the persisted resume-plan dict, or None if the job isn't resuming.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 | |
list_credentials() -> dict[str, dict[str, Any]]
¶
Return every stored credential blob keyed by scope.
The scope is read from the blob's scope field (stamped by
CredentialStore.save) — authoritative and lossless. Only a blob
missing that field falls back to inverting :func:_slug_to_path
(__ → /), which corrupts a scope containing a literal __;
malformed files are skipped. Read-only: never creates the dir.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 | |
list_doc_notes(slug: str) -> list[DocPageNote]
¶
Return every doc-page note for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2479 2480 2481 | |
list_edges(slug: str, *, scope: CommitScope) -> list[GraphEdge]
¶
See WikiStoreBase.list_edges.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2148 2149 2150 2151 2152 2153 2154 | |
list_entity_edges(slug: str, *, source_id: str | None = None) -> list[EntityRelation]
¶
Return entity relations, optionally scoped to source_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2637 2638 2639 2640 2641 2642 2643 2644 | |
list_file_manifest(slug: str) -> list[FileManifest]
¶
Return every file-manifest entry for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2515 2516 2517 | |
list_jobs(slug: str | None = None) -> list[IndexingJob]
¶
Return all jobs, newest first by phase_started_at, filtered to slug.
iterdir() yields entries in arbitrary, platform-dependent filesystem
order, so the list MUST be sorted before return, and NOT by job_id —
a uuid4 hex sorts RANDOMLY with respect to when a job actually ran,
which is not merely unhelpful but ACTIVELY MISLEADING: at least one
caller (resolve_qa_clone_dir) assumes this method returns
most-recent-first and picks the FIRST complete hit, which under such
a sort could be an arbitrary old checkout on any slug with 2+ completed
jobs. phase_started_at is ISO-8601, so lexicographic ==
chronological; a job that never emitted a phase (no timestamp) sorts
last, never winning over one that has. :meth:latest_job is a thin
convenience over this order (narrow by status, take the first).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 | |
list_memory_edges(slug: str, *, node_id: str | None = None, include_invalidated: bool = False) -> list[MemoryEdge]
¶
Return memory edges, optionally scoped to source == node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 | |
list_pages(slug: str) -> list[WikiPage]
¶
Return all pages for project slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 | |
list_projects() -> list[Project]
¶
Return all projects sorted by indexed_at descending.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1264 1265 1266 1267 1268 1269 1270 1271 | |
list_qa(status: str | None = None) -> list[QaAnswer]
¶
Return all QA answers, optionally filtered to status.
iterdir() order is arbitrary — this is a boot-time/offline scan
(mirrors :meth:list_jobs), never an interactive listing, so no
ordering guarantee is made or needed here.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 | |
load_job_events(job_id: str, after_idx: int = -1) -> list[dict[str, Any]]
¶
Return job events with idx > after_idx (-1 returns all).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1588 1589 1590 1591 1592 | |
load_qa_events(answer_id: str, after_idx: int = -1) -> list[dict[str, Any]]
¶
Return QA events with idx > after_idx (-1 returns all).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1964 1965 1966 1967 1968 | |
memories_anchored_to(slug: str, entity_keys: Iterable[EntityKey], *, include_invalidated: bool = False) -> list[str]
¶
Reverse ANCHORS lookup: entity_keys → distinct memory node_ids.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 | |
memory_vector_search(slug: str, qvec: list[float], k: int = 10, *, filt: MemoryFilter | None = None) -> list[MemoryEmbedding]
¶
Top-k memory embeddings by cosine, after applying filt.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 | |
page_ids_for_job(slug: str, job_id: str) -> frozenset[str]
¶
Page ids whose attribution sidecar entry names job_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1749 1750 1751 1752 1753 1754 1755 | |
query_entities(slug: str, *, filt: EntityFilter | None = None) -> list[Entity]
¶
Return entities matching filt's facets.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2571 2572 2573 2574 2575 2576 2577 2578 | |
query_graph(slug: str, *, scope: CommitScope, node_type: str | None = None, name_match: str | None = None, neighbors_of: str | None = None, node_ids: Collection[str] | None = None) -> list[GraphNode]
¶
See WikiStoreBase.query_graph.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 | |
query_memory(slug: str, *, filt: MemoryFilter | None = None) -> list[MemoryNode]
¶
Return memory nodes matching filt's node-level facets.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2364 2365 2366 2367 2368 2369 2370 2371 | |
reap_slug(slug: str) -> dict[str, int]
¶
See WikiStoreBase.reap_slug.
Counts are taken from each JSONL/file BEFORE its owning directory is
removed, so a family's number here means the same thing as the Mongo
driver's delete_many().deleted_count — one count per row, not "the
directory existed". Graph/entity/memory each live under ONE directory
(_graph_dir/_memory_dir), and pages under another
(_pages_dir), so counting + removing those collapses into directory
operations rather than per-file bookkeeping. Jobs and QA are id-keyed,
not slug-keyed: their ids are gathered FIRST, before anything is
deleted, then each owning directory is removed by id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 | |
reset_recovery_attempts(slug: str) -> None
¶
Clear slug's recovery counter file (user-initiated resume fresh budget).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1875 1876 1877 1878 1879 1880 | |
restamp_graph_artifacts(slug: str, *, from_commit: str, to_commit: str) -> dict[str, int]
¶
See WikiStoreBase.restamp_graph_artifacts.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 | |
save_act_plan(job_id: str, plan: dict[str, Any]) -> None
¶
Persist the act-stage record for job_id; overwrites any previous one.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1691 1692 1693 1694 1695 | |
save_credentials(slug: str, blob: dict[str, Any]) -> None
¶
Persist the encoded credential blob for slug at mode 0600.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1794 1795 1796 1797 1798 1799 1800 1801 | |
save_entity_recommendation(slug: str, rec: EntityRecommendation) -> None
¶
Upsert a recommendation for slug; dedup by id (a replay converges).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 | |
save_job_plan(job_id: str, plan: list[dict[str, Any]]) -> None
¶
Persist the page-plan list for job_id; overwrites any previous plan.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1649 1650 1651 1652 1653 | |
save_job_submission(job_id: str, submission: dict[str, Any]) -> None
¶
Persist the wizard submission dict for job_id (token must be absent).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1761 1762 1763 1764 1765 | |
save_page(slug: str, page: WikiPage, *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Persist page for the project slug; overwrites if same page_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 | |
save_project_settings(slug: str, settings: ProjectSettings) -> None
¶
Persist (upsert) the editable settings record for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1289 1290 1291 | |
save_qa(answer: QaAnswer) -> None
¶
Persist a QA answer record (slug round-trips through answer.json).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1896 1897 1898 1899 | |
save_resume_plan(job_id: str, plan: dict[str, Any]) -> None
¶
Persist the resume-plan dict for job_id; overwrites any previous one.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1670 1671 1672 1673 1674 | |
supersede_graph_artifacts(slug: str, *, keep_commit_sha: str) -> dict[str, int]
¶
Drop prior-commit graph + entity artifacts, preserving None-stamped rows.
A row survives iff its commit_sha is None (a QA-minted or
pre-isolation record) OR equals keep_commit_sha. Everything else — the
artifacts of a superseded commit — is dropped.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 | |
update_qa_fields(answer: QaAnswer) -> None
¶
Non-destructive field update.
Session + events are separate files here, so a plain answer.json rewrite already preserves them.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1901 1902 1903 1904 1905 1906 1907 | |
upsert_doc_notes(slug: str, notes: Iterable[DocPageNote]) -> None
¶
Upsert doc-page notes for slug; dedup by page_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 | |
upsert_edges(slug: str, edges: Iterable[GraphEdge], *, commit_sha: str | None = None, job_id: str | None = None, on_progress: Callable[[int, int], None] | None = None) -> None
¶
Upsert graph edges for slug; dedup by (source, target, type).
Cost: O(edges) — offline. The JSON driver writes one atomic file, so
one non-empty input is one persistence batch.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 | |
upsert_embeddings(slug: str, items: Iterable[Embedding], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert embedding vectors for slug; dedup by node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 | |
upsert_entities(slug: str, entities: Iterable[Entity], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert entities for slug; dedup by id, stamp attribution.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 | |
upsert_entity_edges(slug: str, edges: Iterable[EntityRelation], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert entity relations for slug; dedup by id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 | |
upsert_entity_embeddings(slug: str, items: Iterable[EntityEmbedding], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert entity embedding vectors for slug; dedup by entity_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 | |
upsert_file_manifest(slug: str, entries: Iterable[FileManifest]) -> None
¶
Upsert file-manifest entries for slug; dedup by path.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 | |
upsert_memory_edges(slug: str, edges: Iterable[MemoryEdge]) -> None
¶
Upsert memory edges for slug; dedup by (source, target, type).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 | |
upsert_memory_embeddings(slug: str, items: Iterable[MemoryEmbedding]) -> None
¶
Upsert memory embedding vectors for slug; dedup by node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 | |
upsert_memory_nodes(slug: str, nodes: Iterable[MemoryNode]) -> None
¶
Upsert memory nodes for slug; dedup by node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 | |
upsert_nodes(slug: str, nodes: Iterable[GraphNode], *, commit_sha: str | None = None, job_id: str | None = None, on_progress: Callable[[int, int], None] | None = None) -> None
¶
Upsert graph nodes for slug; dedup by node_id, stamp attribution.
Cost: O(nodes) — offline. The JSON driver writes one atomic file, so
one non-empty input is one persistence batch.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 | |
vector_search(slug: str, qvec: list[float], k: int = 10) -> list[Embedding]
¶
Return top-k embeddings for slug by cosine similarity.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 | |
MongoWikiStore
¶
Bases: WikiStoreBase
MongoDB-backed wiki persistence.
Collections:
wiki_projects(slug PK)wiki_pages((slug, page_id) compound PK)wiki_jobs(job_id PK; includesevent_countfor atomic$inc)wiki_job_events((job_id, idx) compound; append-only)wiki_qa(answer_id PK; includesevent_count)wiki_qa_events((answer_id, idx) compound; append-only)
Graph/embeddings collections are not created here — the methods raise
NotImplementedError inherited from WikiStoreBase.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 | |
__init__(*, client: Any = None, uri: str | None = None, database: str | None = None) -> None
¶
Initialize MongoDB connection and ensure indexes exist.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 | |
append_qa_event(answer_id: str, event: dict[str, Any]) -> int
¶
Append event to the QA event log; return the monotonic idx.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3370 3371 3372 3373 3374 3375 3376 | |
attach_job_session(job_id: str, session_id: str) -> None
¶
Associate a Mewbo session_id with an indexing job.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3084 3085 3086 3087 3088 3089 | |
attach_qa_session(answer_id: str, session_id: str) -> None
¶
Associate a Mewbo session_id with a QA answer.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3345 3346 3347 3348 3349 3350 | |
bump_recovery_attempts(slug: str) -> int
¶
Atomically increment slug's recovery counter; return the new value.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 | |
cancel_job(job_id: str) -> bool
¶
Cancel job_id; return True on first cancel, False if already cancelled.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 | |
claim_job_page(slug: str, job_id: str, page_id: str) -> PageClaim
¶
Claim + count in ONE conditional update, so racing writers can't double-count.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 | |
count_entities(slug: str, *, commit_sha: str | None) -> int
¶
Count slug entities stamped exactly commit_sha (None matches None).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4131 4132 4133 4134 4135 4136 4137 4138 | |
count_graph_nodes(slug: str, *, commit_sha: str | None) -> int
¶
Count slug nodes stamped exactly commit_sha (None matches None).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3643 3644 3645 3646 3647 3648 3649 3650 | |
create_job(job: IndexingJob) -> None
¶
Persist a new indexing job.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2995 2996 2997 2998 | |
create_project(project: Project) -> None
¶
Persist a new project record.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2821 2822 2823 2824 2825 2826 | |
delete_credentials(slug: str) -> bool
¶
Delete slug's credential document; return True if one existed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3265 3266 3267 3268 | |
delete_doc_note(slug: str, page_id: str) -> bool
¶
Delete a doc-page note; return True if one was removed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4042 4043 4044 4045 4046 4047 | |
delete_edges_by_source_file(slug: str, file: str) -> int
¶
Delete edges whose source node belongs to file; return count.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 | |
delete_file_manifest(slug: str, path: str) -> bool
¶
Delete a file-manifest entry; return True if one was removed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4078 4079 4080 4081 4082 4083 | |
delete_memory_node(slug: str, node_id: str) -> bool
¶
Delete a memory node + its embedding; return True if one was removed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3904 3905 3906 3907 3908 3909 3910 3911 3912 | |
delete_nodes_by_file(slug: str, file: str) -> int
¶
Delete file's code nodes AND their vectors; return the NODE count.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 | |
delete_page(slug: str, page_id: str) -> bool
¶
Delete a single wiki page document. Returns True on a hit.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2978 2979 2980 2981 2982 2983 | |
delete_project(slug: str) -> bool
¶
Delete project slug; return True if deleted, False if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2840 2841 2842 2843 | |
delete_project_settings(slug: str) -> bool
¶
Delete slug's settings document; return True if one existed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2867 2868 2869 | |
entity_vector_search(slug: str, qvec: list[float], k: int = 10) -> list[EntityEmbedding]
¶
Return top-k entity embeddings for slug by cosine (in-memory scoring).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4159 4160 4161 4162 4163 4164 4165 4166 4167 | |
find_job_by_session(session_id: str) -> str | None
¶
Reverse lookup: return the job_id for session_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3099 3100 3101 3102 3103 3104 3105 3106 3107 | |
find_qa_by_session(session_id: str) -> str | None
¶
Reverse lookup: return the answer_id for session_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3360 3361 3362 3363 3364 3365 3366 3367 3368 | |
get_act_plan(job_id: str) -> dict[str, Any] | None
¶
Return the persisted act-stage record, or None if stage 1 hasn't finished.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3146 3147 3148 3149 3150 3151 3152 | |
get_credentials(slug: str) -> dict[str, Any] | None
¶
Return the encoded credential blob for slug, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3257 3258 3259 3260 3261 3262 3263 | |
get_doc_note(slug: str, page_id: str) -> DocPageNote | None
¶
Return a single doc-page note, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4028 4029 4030 4031 4032 4033 | |
get_entity(slug: str, entity_id: str) -> Entity | None
¶
Return a single entity, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4109 4110 4111 4112 4113 4114 4115 4116 | |
get_entity_recommendations(slug: str) -> list[EntityRecommendation]
¶
Return every persisted entity recommendation for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4213 4214 4215 4216 4217 4218 4219 4220 | |
get_file_manifest(slug: str, path: str) -> FileManifest | None
¶
Return a single file-manifest entry, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4064 4065 4066 4067 4068 4069 | |
get_job(job_id: str) -> IndexingJob | None
¶
Return the indexing job, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3000 3001 3002 3003 3004 3005 | |
get_job_page_ids(slug: str, job_id: str) -> frozenset[str]
¶
Return the page ids job_id wrote (claim record, else attribution).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 | |
get_job_plan(job_id: str) -> list[dict[str, Any]] | None
¶
Return the page-plan list, or None if no plan has been committed yet.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3116 3117 3118 3119 3120 3121 3122 | |
get_job_session(job_id: str) -> str | None
¶
Return the session_id attached to job_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3091 3092 3093 3094 3095 3096 3097 | |
get_job_submission(job_id: str) -> dict[str, Any] | None
¶
Return the persisted submission dict, or None if not yet saved.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3241 3242 3243 3244 3245 3246 3247 | |
get_job_submitted_count(job_id: str) -> int
¶
Return the number of pages submitted so far for job_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3154 3155 3156 3157 3158 3159 | |
get_memory_node(slug: str, node_id: str) -> MemoryNode | None
¶
Return a single memory node, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3897 3898 3899 3900 3901 3902 | |
get_project(slug: str) -> Project | None
¶
Return the project for slug, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2828 2829 2830 2831 2832 2833 | |
get_project_settings(slug: str) -> ProjectSettings | None
¶
Return slug's settings record, or None when never written.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 | |
get_qa(answer_id: str) -> QaAnswer | None
¶
Return the QA answer, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3330 3331 3332 3333 3334 3335 | |
get_qa_session(answer_id: str) -> str | None
¶
Return the session_id attached to answer_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3352 3353 3354 3355 3356 3357 3358 | |
get_recovery_attempts(slug: str) -> int
¶
Return the recovery-attempt count for slug (0 if never recovered).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3289 3290 3291 3292 | |
get_resume_plan(job_id: str) -> dict[str, Any] | None
¶
Return the persisted resume-plan dict, or None if the job isn't resuming.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3131 3132 3133 3134 3135 3136 3137 | |
list_credentials() -> dict[str, dict[str, Any]]
¶
Return every stored credential blob keyed by scope (full scan).
Prefers the blob's own scope field (stamped by
CredentialStore.save, matching the JSON driver's precedence); falls
back to the document's slug key for a blob missing that field.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 | |
list_doc_notes(slug: str) -> list[DocPageNote]
¶
Return every doc-page note for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4035 4036 4037 4038 4039 4040 | |
list_edges(slug: str, *, scope: CommitScope) -> list[GraphEdge]
¶
See WikiStoreBase.list_edges.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3638 3639 3640 3641 | |
list_entity_edges(slug: str, *, source_id: str | None = None) -> list[EntityRelation]
¶
Return entity relations, optionally scoped to source_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 | |
list_file_manifest(slug: str) -> list[FileManifest]
¶
Return every file-manifest entry for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4071 4072 4073 4074 4075 4076 | |
list_jobs(slug: str | None = None) -> list[IndexingJob]
¶
Return all jobs, newest first by phase_started_at, filtered to slug.
Mongo find() has no inherent order, and sorting by job_id for
reproducibility would not fix that: job_id is a uuid4 hex, which
sorts RANDOMLY with respect to when a job actually ran, and at least one
caller (resolve_qa_clone_dir) assumes this returns most-recent-first
and picks the FIRST complete hit — under such a sort an arbitrary
old checkout. Sorted in Python
rather than via a Mongo-side .sort() so both drivers apply the
IDENTICAL rule (ISO-8601 phase_started_at, so lexicographic ==
chronological; a job with no timestamp sorts last) instead of relying
on each backend's own null-ordering semantics to happen to agree.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 | |
list_memory_edges(slug: str, *, node_id: str | None = None, include_invalidated: bool = False) -> list[MemoryEdge]
¶
Return memory edges, optionally scoped to source == node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 | |
list_pages(slug: str) -> list[WikiPage]
¶
Return all pages for project slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 | |
list_projects() -> list[Project]
¶
Return all projects sorted by indexed_at descending.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2835 2836 2837 2838 | |
list_qa(status: str | None = None) -> list[QaAnswer]
¶
Return all QA answers, optionally filtered to status (server-side).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3337 3338 3339 3340 3341 3342 3343 | |
load_job_events(job_id: str, after_idx: int = -1) -> list[dict[str, Any]]
¶
Return job events with idx > after_idx (-1 returns all).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 | |
load_qa_events(answer_id: str, after_idx: int = -1) -> list[dict[str, Any]]
¶
Return QA events with idx > after_idx (-1 returns all).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 | |
memories_anchored_to(slug: str, entity_keys: Iterable[EntityKey], *, include_invalidated: bool = False) -> list[str]
¶
Reverse ANCHORS lookup: entity_keys → distinct memory node_ids.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 | |
memory_vector_search(slug: str, qvec: list[float], k: int = 10, *, filt: MemoryFilter | None = None) -> list[MemoryEmbedding]
¶
Top-k memory embeddings by cosine, after applying filt.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 | |
page_ids_for_job(slug: str, job_id: str) -> frozenset[str]
¶
Page ids whose stored attribution column names job_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3224 3225 3226 3227 3228 3229 3230 3231 3232 | |
prune_pages(slug: str, keep: Iterable[str]) -> int
¶
Bulk-drop pages not in keep in a single Mongo round-trip.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2985 2986 2987 2988 2989 2990 2991 | |
query_entities(slug: str, *, filt: EntityFilter | None = None) -> list[Entity]
¶
Return entities matching filt's facets.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 | |
query_graph(slug: str, *, scope: CommitScope, node_type: str | None = None, name_match: str | None = None, neighbors_of: str | None = None, node_ids: Collection[str] | None = None) -> list[GraphNode]
¶
See WikiStoreBase.query_graph.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 | |
query_memory(slug: str, *, filt: MemoryFilter | None = None) -> list[MemoryNode]
¶
Return memory nodes matching filt's node-level facets.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 | |
reap_slug(slug: str) -> dict[str, int]
¶
See WikiStoreBase.reap_slug.
wiki_job_events/wiki_qa_events carry only their owning id
(job_id/answer_id), never slug — so those ids are read from
wiki_jobs/wiki_qa FIRST, before either collection is touched,
and the two event collections are then swept by id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 | |
reset_recovery_attempts(slug: str) -> None
¶
Clear slug's recovery counter document (user-initiated resume fresh budget).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3306 3307 3308 | |
restamp_graph_artifacts(slug: str, *, from_commit: str, to_commit: str) -> dict[str, int]
¶
See WikiStoreBase.restamp_graph_artifacts.
An EXACT commit_sha match, deliberately not the $nin shape
supersede_graph_artifacts uses: supersede asks "everything except
the keeper", which would here sweep up older generations and
field-absent rows and stamp genuinely dead code as live.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 | |
save_act_plan(job_id: str, plan: dict[str, Any]) -> None
¶
Persist the act-stage record on the job doc; overwrites any previous one.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3139 3140 3141 3142 3143 3144 | |
save_credentials(slug: str, blob: dict[str, Any]) -> None
¶
Persist the encoded credential blob for slug (slug PK, upsert).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3251 3252 3253 3254 3255 | |
save_entity_recommendation(slug: str, rec: EntityRecommendation) -> None
¶
Upsert a recommendation for slug; dedup by (slug, id).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 | |
save_job_plan(job_id: str, plan: list[dict[str, Any]]) -> None
¶
Persist the page-plan list for job_id; overwrites any previous plan.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3109 3110 3111 3112 3113 3114 | |
save_job_submission(job_id: str, submission: dict[str, Any]) -> None
¶
Persist the wizard submission dict for job_id (token must be absent).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3234 3235 3236 3237 3238 3239 | |
save_page(slug: str, page: WikiPage, *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Persist page for the project slug; overwrites if same page_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 | |
save_project_settings(slug: str, settings: ProjectSettings) -> None
¶
Persist (upsert) the editable settings record for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
2847 2848 2849 2850 2851 | |
save_qa(answer: QaAnswer) -> None
¶
Persist a QA answer record (creation: resets event_count, no session yet).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3312 3313 3314 3315 3316 3317 | |
save_resume_plan(job_id: str, plan: dict[str, Any]) -> None
¶
Persist the resume-plan dict on the job doc; overwrites any previous one.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3124 3125 3126 3127 3128 3129 | |
supersede_graph_artifacts(slug: str, *, keep_commit_sha: str) -> dict[str, int]
¶
Drop prior-commit graph + entity artifacts, preserving None-stamped rows.
{"$nin": [None, keep]} matches a REAL commit other than keep while
leaving both None-valued and field-absent rows untouched — the
QA-minted / pre-isolation records supersede must not reap.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 | |
update_qa_fields(answer: QaAnswer) -> None
¶
In-place $set of the QaAnswer fields only.
Leaves event_count + session_id (this backend packs both into the
same doc) intact, unlike save_qa's full replace.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 | |
upsert_doc_notes(slug: str, notes: Iterable[DocPageNote]) -> None
¶
Upsert doc-page notes for slug; dedup by (slug, page_id).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 | |
upsert_edges(slug: str, edges: Iterable[GraphEdge], *, commit_sha: str | None = None, job_id: str | None = None, on_progress: Callable[[int, int], None] | None = None) -> None
¶
Upsert graph edges for slug; dedup by (slug, source, target, type).
Cost: O(edges) — offline, the graph phase. Batched through
_bulk_upsert, so the round-trip count is O(edges / batch).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 | |
upsert_embeddings(slug: str, items: Iterable[Embedding], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert embedding vectors for slug; dedup by (slug, node_id).
Cost: O(vectors) — offline, the graph phase. Batched through
_bulk_upsert, so the round-trip count is O(vectors / batch).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 | |
upsert_entities(slug: str, entities: Iterable[Entity], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert entities for slug; dedup by (slug, id), stamp attribution.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 | |
upsert_entity_edges(slug: str, edges: Iterable[EntityRelation], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert entity relations for slug; dedup by (slug, id).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 | |
upsert_entity_embeddings(slug: str, items: Iterable[EntityEmbedding], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert entity embedding vectors for slug; dedup by (slug, entity_id).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 | |
upsert_file_manifest(slug: str, entries: Iterable[FileManifest]) -> None
¶
Upsert file-manifest entries for slug; dedup by (slug, path).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 | |
upsert_memory_edges(slug: str, edges: Iterable[MemoryEdge]) -> None
¶
Upsert memory edges for slug; dedup by (slug, source, target, type).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 | |
upsert_memory_embeddings(slug: str, items: Iterable[MemoryEmbedding]) -> None
¶
Upsert memory embedding vectors for slug; dedup by (slug, node_id).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 | |
upsert_memory_nodes(slug: str, nodes: Iterable[MemoryNode]) -> None
¶
Upsert memory nodes for slug; dedup by (slug, node_id).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 | |
upsert_nodes(slug: str, nodes: Iterable[GraphNode], *, commit_sha: str | None = None, job_id: str | None = None, on_progress: Callable[[int, int], None] | None = None) -> None
¶
Upsert graph nodes for slug; dedup by (slug, node_id), stamp attribution.
Cost: O(nodes) — offline, the graph phase. Batched through
_bulk_upsert, so the round-trip count is O(nodes / batch).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 | |
vector_search(slug: str, qvec: list[float], k: int = 10) -> list[Embedding]
¶
Return top-k embeddings for slug by cosine similarity.
Cost: O(embeddings for the slug) — every stored vector is still
scored, so this remains the documented scale seam. What the packed path
removes is the per-element Python cost of getting there: it reads only
node_id + the _VEC_F32 buffer, scores the whole project as one
NumPy matrix product, and materialises exactly k Embedding models.
Falls back to the pure-Python scan when NumPy is absent or any row
lacks _VEC_F32 — never to a PARTIAL result.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 | |
PageClaim
dataclass
¶
Outcome of a job claiming one page id: the new count + whether it was new.
One answer rather than two reads. The read-then-increment this replaces asked the store twice — "does this page exist" and then "bump the counter" — so two page-writers landing together could both see "new" and over-count, and a caller that saw "not new" had to go back for the count.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
92 93 94 95 96 97 98 99 100 101 102 103 | |
WikiStoreBase
¶
Bases: ABC
Abstract base for wiki persistence backends.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 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 350 351 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 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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 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 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 | |
append_job_event(job_id: str, event: dict[str, Any]) -> int
¶
Validate then append one job event; return its monotonic index.
The discriminated event model is the durable trust boundary: both the JSON and Mongo timelines, and therefore SSE, receive one known wire shape. Concrete drivers only own their atomic append mechanics.
Cost: O(1).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
444 445 446 447 448 449 450 451 452 453 454 | |
append_qa_event(answer_id: str, event: dict[str, Any]) -> int
abstractmethod
¶
Append event to the QA event log; return the monotonic idx.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
677 678 679 | |
attach_job_session(job_id: str, session_id: str) -> None
abstractmethod
¶
Associate a Mewbo session_id with an indexing job (forward mapping).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
475 476 477 | |
attach_qa_session(answer_id: str, session_id: str) -> None
abstractmethod
¶
Associate a Mewbo session_id with a QA answer (forward mapping).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
665 666 667 | |
bump_recovery_attempts(slug: str) -> int
abstractmethod
¶
Atomically increment slug's recovery counter; return the new value.
Slug-keyed (not job-keyed) so the cap bounds re-drives across recovery
generations / new job_ids. Lives on its OWN persistent surface so it
never pollutes the wizard-submission sidecar (which validates strictly
as a WizardSubmission).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
612 613 614 615 616 617 618 619 620 | |
cancel_job(job_id: str) -> bool
abstractmethod
¶
Cancel job_id; return True on first cancel, False if already cancelled.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
471 472 473 | |
claim_job_page(slug: str, job_id: str, page_id: str) -> PageClaim
abstractmethod
¶
Atomically record page_id as written by job_id; return the claim.
The submitted-pages counter belongs to the JOB, so its dedup key has to
be the job's OWN set of claimed ids. Keying on the slug instead — "does a
page with this id already exist for the slug" — answers yes for every
page a PREVIOUS index of the same repository wrote, so a refresh would
count zero new pages, emit no page_committed events, and leave the
progress bar dead for the whole re-index.
The returned count is the SIZE of that set, never a free-running
increment. A counter that only ever counts distinct pages cannot drift
past what the job actually wrote, where a read-then-$inc can: a
resumed job whose counter carried over from an earlier attempt reports
90 pages written against a 50-page plan.
A job with no claim record seeds its set from page attribution
(:meth:page_ids_for_job) on first touch, so an interrupted index
resumes with its earlier pages counted rather than from zero.
Raises KeyError when job_id is unknown.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | |
count_entities(slug: str, *, commit_sha: str | None) -> int
¶
Count entities for slug minted by exactly commit_sha (None matches None).
The enrich-phase analogue of :meth:count_graph_nodes: "entities for
THIS commit are minted" is count_entities(slug, commit_sha=X) > 0,
which the resume skip predicate needs instead of the union count.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1111 1112 1113 1114 1115 1116 1117 1118 | |
count_graph_nodes(slug: str, *, commit_sha: str | None) -> int
¶
Count nodes for slug built by exactly commit_sha (None matches None).
The commit-scoped count the resume skip predicate keys on: "the graph
for THIS commit is built" is count_graph_nodes(slug, commit_sha=X) >
0.
commit_sha here is an EXACT match — None counts the rows stamped
NULL, it does not mean "any commit". :class:CommitScope exists to keep
that convention unambiguous on the read methods, which is why
query_graph takes a scope rather than re-using this parameter name
with the opposite sense; count_graph_nodes(slug, commit_sha=X) and
len(query_graph(slug, scope=CommitScope.at(X))) agree by
construction.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 | |
create_job(job: IndexingJob) -> None
abstractmethod
¶
Persist a new indexing job.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
373 374 375 | |
create_project(project: Project) -> None
abstractmethod
¶
Persist a new project record.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
164 165 166 | |
delete_credentials(slug: str) -> bool
abstractmethod
¶
Delete slug's credential; return True if one was removed, else False.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
593 594 595 | |
delete_doc_note(slug: str, page_id: str) -> bool
¶
Delete a doc-page note; return True if one was removed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1058 1059 1060 | |
delete_edges_by_source_file(slug: str, file: str) -> int
¶
Delete edges originating from any node in file; return count.
"Originating" = the edge source node_id belongs to a node whose
file is file. Call BEFORE :meth:delete_nodes_by_file for the
same file so the source nodes are still present to resolve.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
908 909 910 911 912 913 914 915 | |
delete_file_manifest(slug: str, path: str) -> bool
¶
Delete a file-manifest entry; return True if one was removed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1078 1079 1080 | |
delete_memory_node(slug: str, node_id: str) -> bool
¶
Delete a memory node + its embedding; return True if one was removed.
Edges are NOT touched (callers invalidate them separately so history survives). Used when a merge supersedes a note under a new identity.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
931 932 933 934 935 936 937 | |
delete_nodes_by_file(slug: str, file: str) -> int
¶
Delete every code node in file AND its vectors; return the NODE count.
The embedding cascade is part of this method rather than a second call
the caller makes first, because :class:Embedding carries no file
field: a vector is reachable only through the node it points at, so once
that node is deleted the vector can no longer be found by file, by
commit, or by anything else — it is simply unreachable, unreapable, and
still scoreable by :meth:vector_search. Cascading here makes "no
orphaned vectors" a property of the store instead of a call-ordering
discipline every future caller has to rediscover.
The return value stays the NODE count so the delete reads the same as every other scoped delete on this class.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 | |
delete_page(slug: str, page_id: str) -> bool
abstractmethod
¶
Delete a single wiki page. Returns True if a page was removed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
367 368 369 | |
delete_project(slug: str) -> bool
abstractmethod
¶
Delete project slug; return True if deleted, False if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
176 177 178 | |
delete_project_settings(slug: str) -> bool
abstractmethod
¶
Delete slug's settings record; return True if one existed.
Called on project delete so a re-created slug can't inherit the dead project's settings (the rule the freshness cache eviction already follows).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
248 249 250 251 252 253 254 | |
entity_vector_search(slug: str, qvec: list[float], k: int = 10) -> list[EntityEmbedding]
¶
Top-k entity embeddings by cosine (the ANN block seam for ER).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1131 1132 1133 1134 1135 | |
find_job_by_session(session_id: str) -> str | None
abstractmethod
¶
Reverse lookup: return the job_id for session_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
483 484 485 | |
find_qa_by_session(session_id: str) -> str | None
abstractmethod
¶
Reverse lookup: return the answer_id for session_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
673 674 675 | |
get_act_plan(job_id: str) -> dict[str, Any] | None
¶
Return the persisted act-stage record, or None if stage 1 hasn't finished.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
525 526 527 | |
get_credentials(slug: str) -> dict[str, Any] | None
abstractmethod
¶
Return the encoded credential blob for slug, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
589 590 591 | |
get_doc_note(slug: str, page_id: str) -> DocPageNote | None
¶
Return a single doc-page note, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1050 1051 1052 | |
get_entity(slug: str, entity_id: str) -> Entity | None
¶
Return a single entity, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1101 1102 1103 | |
get_entity_recommendations(slug: str) -> list[EntityRecommendation]
¶
Return every persisted entity recommendation for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1166 1167 1168 | |
get_file_manifest(slug: str, path: str) -> FileManifest | None
¶
Return a single file-manifest entry, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1070 1071 1072 | |
get_job(job_id: str) -> IndexingJob | None
abstractmethod
¶
Return the indexing job, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
377 378 379 | |
get_job_page_ids(slug: str, job_id: str) -> frozenset[str]
abstractmethod
¶
Return the page ids job_id wrote — its claim set, else attribution.
The fallback is what makes a PRE-EXISTING interrupted job resumable: its meta carries a bare counter and no claim record, so reading the claim alone reported nothing done and the resume regenerated every page it had already written correctly — the exact waste the claim exists to prevent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
557 558 559 560 561 562 563 564 565 | |
get_job_plan(job_id: str) -> list[dict[str, Any]] | None
abstractmethod
¶
Return the page-plan list, or None if no plan has been committed yet.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
493 494 495 | |
get_job_session(job_id: str) -> str | None
abstractmethod
¶
Return the session_id attached to job_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
479 480 481 | |
get_job_submission(job_id: str) -> dict[str, Any] | None
abstractmethod
¶
Return the persisted submission dict, or None if not yet saved.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
579 580 581 | |
get_job_submitted_count(job_id: str) -> int
abstractmethod
¶
Return the number of pages submitted so far for job_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
529 530 531 | |
get_memory_node(slug: str, node_id: str) -> MemoryNode | None
¶
Return a single memory node, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
927 928 929 | |
get_page(slug: str, page_id: str) -> WikiPage | None
¶
Return a single wiki page, or None if absent.
THE single doc-content read seam: every upstream doc reader (the API
page route, the wiki_read_page Q&A tool, the MCP read_wiki_page
facade over the route) funnels through here, so guarding it once makes a
graph-only project's "no documentation" failure deterministic everywhere.
A project indexed in graph-only (developer) mode carries
graph_only=True and has ZERO pages — reading page content then raises
:class:DocumentationUnavailableError from this ONE place rather than
returning a confusing None. The driver-specific fetch lives in
:meth:_get_page_raw; this template method only adds the guard. The graph
endpoint never calls this, so visualisation stays unaffected.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
get_project(slug: str) -> Project | None
abstractmethod
¶
Return the project for slug, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
168 169 170 | |
get_project_settings(slug: str) -> ProjectSettings | None
abstractmethod
¶
Return slug's settings record, or None when it has never been written.
None is a NORMAL state, not an error — the caller falls back to
the per-job submission scan.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
240 241 242 243 244 245 246 | |
get_qa(answer_id: str) -> QaAnswer | None
abstractmethod
¶
Return the QA answer, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
651 652 653 | |
get_qa_session(answer_id: str) -> str | None
abstractmethod
¶
Return the session_id attached to answer_id, or None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
669 670 671 | |
get_recovery_attempts(slug: str) -> int
abstractmethod
¶
Return the recovery-attempt count for slug (0 if never recovered).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
608 609 610 | |
get_resume_plan(job_id: str) -> dict[str, Any] | None
¶
Return the persisted resume-plan dict, or None if the job isn't resuming.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
507 508 509 | |
latest_job(slug: str, *, statuses: Iterable[str] | None = None) -> IndexingJob | None
¶
Return slug's most recent job, ordered by phase_started_at.
The ONE "what is the latest attempt for this slug" answer — a thin
convenience over :meth:list_jobs, which already returns newest-first
by phase_started_at (never job_id, a uuid4 hex that sorts
RANDOMLY with respect to when a job actually ran). statuses narrows
the candidates before taking the first, e.g. {"complete"} for a
freshness or QA-source baseline. Returns None when no job
(matching statuses, if given) exists.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
list_credentials() -> dict[str, dict[str, Any]]
abstractmethod
¶
Return every stored credential blob keyed by scope (slug or bare host).
The management surface (CredentialStore.list → the /v1/git/credentials
route) reads this. Values are the raw encoded blobs; the caller decodes +
redacts. The scope key is a full slug (host/owner/repo) or a bare host.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
597 598 599 600 601 602 603 604 | |
list_doc_notes(slug: str) -> list[DocPageNote]
¶
Return every doc-page note for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1054 1055 1056 | |
list_edges(slug: str, *, scope: CommitScope) -> list[GraphEdge]
¶
Return slug's edges for scope's generation (graph-viewer endpoint).
scope is required for the same reason as on query_graph — and it
must agree with the scope the nodes were read under, or the view is
assembled from edges whose endpoints belong to a different generation.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
874 875 876 877 878 879 880 881 | |
list_entity_edges(slug: str, *, source_id: str | None = None) -> list[EntityRelation]
¶
Return entity relations, optionally scoped to source_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1148 1149 1150 1151 1152 | |
list_file_manifest(slug: str) -> list[FileManifest]
¶
Return every file-manifest entry for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1074 1075 1076 | |
list_jobs(slug: str | None = None) -> list[IndexingJob]
abstractmethod
¶
Return all jobs, optionally filtered to slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
421 422 423 | |
list_memory_edges(slug: str, *, node_id: str | None = None, include_invalidated: bool = False) -> list[MemoryEdge]
¶
Return memory edges, optionally scoped to source == node_id.
Invalidated edges (invalid_at set) are excluded unless
include_invalidated is True.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
949 950 951 952 953 954 955 956 957 958 959 960 961 | |
list_pages(slug: str) -> list[WikiPage]
abstractmethod
¶
Return all pages for project slug.
NOT doc-guarded: list_pages is also the page-id roster used by the
deterministic internal paths (finalize prune, resume, retriever,
QaFinalizer.tag_page_citations), so guarding it would break indexing
and finalize themselves. A graph-only project simply returns [] here
(it has no pages); the guard lives on the doc-CONTENT read (:meth:get_page).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
341 342 343 344 345 346 347 348 349 350 | |
list_projects() -> list[Project]
abstractmethod
¶
Return all projects sorted by indexed_at descending.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
172 173 174 | |
list_qa(status: str | None = None) -> list[QaAnswer]
abstractmethod
¶
Return all QA answers, optionally filtered to status.
Boot-time/offline use only (mirrors :meth:list_jobs) — an
unfiltered call reads every persisted answer, so a caller on an
interactive path must narrow with status rather than filtering the
full list in Python.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
655 656 657 658 659 660 661 662 663 | |
live_scope(slug: str) -> CommitScope
¶
The generation slug's readers should see: the project's own commit.
A project row carries the commit its last completed index built from, so that — not the union of every commit ever indexed — is what "the code as it is now" means. Lives here because the store is what holds the project row; every graph reader already has one, so nobody has to thread a commit sha through their own call chain to read correctly.
A project with no commit_sha (a commit-less catalog ingestion, or a
slug with no project row yet) has exactly one generation, so scoping it
could only be a way to get it wrong — the union and the live generation
are the same set, and every() says so without asserting a commit
that does not exist.
Cost: O(one record).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 | |
load_job_events(job_id: str, after_idx: int = -1) -> list[dict[str, Any]]
abstractmethod
¶
Return job events with idx > after_idx (-1 returns all).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
465 466 467 468 469 | |
load_qa_events(answer_id: str, after_idx: int = -1) -> list[dict[str, Any]]
abstractmethod
¶
Return QA events with idx > after_idx (-1 returns all).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
681 682 683 684 685 | |
memories_anchored_to(slug: str, entity_keys: Iterable[EntityKey], *, include_invalidated: bool = False) -> list[str]
¶
Reverse ANCHORS lookup: entity_keys → distinct memory node_ids.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
963 964 965 966 967 968 969 970 971 | |
memory_vector_search(slug: str, qvec: list[float], k: int = 10, *, filt: MemoryFilter | None = None) -> list[MemoryEmbedding]
¶
Top-k memory embeddings by cosine, after applying filt.
Scale seam — keep signature stable. v1 is brute-force cosine; IVF / Matryoshka / quantization slot in here without touching callers.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
979 980 981 982 983 984 985 986 987 988 989 990 991 992 | |
page_ids_for_job(slug: str, job_id: str) -> frozenset[str]
abstractmethod
¶
Page ids under slug whose stored attribution names job_id.
save_page stamps attribution independently of the claim record,
which is why this can answer for a job the claim record cannot.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
567 568 569 570 571 572 573 | |
prune_pages(slug: str, keep: Iterable[str]) -> int
¶
Drop every page for slug whose page_id is not in keep.
Default impl uses list_pages + per-page delete_page so
backends only need a single primitive. Returns the number of
pages dropped.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
query_entities(slug: str, *, filt: EntityFilter | None = None) -> list[Entity]
¶
Return entities matching filt's facets (no filter ⇒ all).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1105 1106 1107 1108 1109 | |
query_graph(slug: str, *, scope: CommitScope, node_type: str | None = None, name_match: str | None = None, neighbors_of: str | None = None, node_ids: Collection[str] | None = None) -> list[GraphNode]
¶
Query the code graph for slug, restricted to scope's generation.
node_ids fetches an explicit set by id. It exists so a caller holding
a bounded list of ids — the knowledge-graph view repairing entity
anchors that point into a superseded generation — can look exactly
those up instead of reading a whole generation to find a handful. An
empty collection returns nothing; None means "no id filter".
scope is REQUIRED and has no default on purpose. This store holds the
UNION of every commit ever indexed for a slug, so "which generation"
has no safe default — and a default of CommitScope.every() would be
precisely the fail-open filter the root guidance forbids: a caller that
forgot to scope would silently read every generation and still return
200. Required means a missed call site is a typecheck failure
instead. See :class:CommitScope for why this is not a commit_sha
parameter (count_graph_nodes already owns that name with the
opposite meaning for None).
Cost: O(nodes for the slug in scope) — a read of one project's
graph generation, not of all history.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
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 | |
query_memory(slug: str, *, filt: MemoryFilter | None = None) -> list[MemoryNode]
¶
Return memory nodes matching filt's node-level facets.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
939 940 941 942 943 | |
reap_slug(slug: str) -> dict[str, int]
¶
Delete every family this store persists for slug; return the counts.
The exceptions are the three the delete-project ROUTE already owns
directly: wiki_projects
(:meth:delete_project), wiki_settings (:meth:delete_project_settings),
and a git credential (CredentialStore.delete — repo-scope ONLY; a
host-scoped credential is shared by every repo on that host and must
NEVER cascade off one project's delete, so this method never touches
credentials at all).
Everything else a completed or in-flight index could have written under slug is deleted here: pages, the code graph (nodes/edges/embeddings), the entity layer (entities/entity-edges/entity-embeddings/ recommendations), the memory layer (nodes/edges/embeddings), doc notes, the file manifest, the recovery-attempt counter, every indexing job (with its plan/resume/submission/session sidecars and its event log), and every QA answer for this slug (with its event log). Without this, a project delete orphans the large majority of what an index ever wrote — it stays reachable by nothing, forever, and a slug reused later inherits none of it (the same "clean slate" reasoning behind clearing settings/ credentials/the freshness cache above, extended to the rest of the store).
Returns per-family deleted-row counts (mirroring
:meth:supersede_graph_artifacts's shape) so a caller can report exactly
what was removed. Idempotent: a second call for an already-reaped slug
finds nothing and returns all-zero counts.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
reset_recovery_attempts(slug: str) -> None
¶
Clear slug's recovery counter (a user-initiated resume gets a fresh budget).
A human asking to retry an index must not be blocked by prior automatic re-drives, so the manual resume path resets the auto-recovery cap. Concrete default no-op so a backend that never tracks the counter is unaffected.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
622 623 624 625 626 627 628 | |
restamp_graph_artifacts(slug: str, *, from_commit: str, to_commit: str) -> dict[str, int]
¶
Carry from_commit's surviving artifacts forward onto to_commit.
Concrete-raising rather than @abc.abstractmethod, matching its
sibling supersede_graph_artifacts and the rest of this graph family:
an abstract method here is inherited by every partial test double of
this base and stops it being instantiable at all, which turns a new
store capability into a broad, unrelated test failure.
The counterpart a SCOPED re-index needs and a full one does not. A full
index re-stamps every artifact by rewriting them all, so afterwards one
generation describes the whole slug and live_scope finds everything.
An incremental refresh re-stamps only what it re-parsed, so without this
the untouched majority keeps the PREVIOUS commit while the project row
advances — and since live_scope is at(project.commit_sha), every
reader (the graph view, the retriever, the agent graph tools) would see
only the handful of files that happened to change. Not deleted, not
erroring: invisible. That is the failure this method exists to prevent,
and it is the precondition the delta indexer's own unscoped reads name.
The semantic is a claim, and it is a true one: an artifact built from a file that did NOT change describes to_commit just as accurately as it described from_commit, so moving its stamp forward asserts nothing false.
Why this is a MOVE from a named generation rather than "stamp
everything". The store can hold generations older than from_commit —
a supersede that never ran, or the field-absent rows the isolation
backfill exists for. Those describe code that is genuinely gone.
Blanket-stamping them onto to_commit would resurrect deleted symbols
into the live view, which is a worse bug than the one being fixed. Rows
stamped None are likewise left alone, matching
supersede_graph_artifacts' preserve rule.
Returns per-family moved counts. Idempotent: a second call finds nothing left at from_commit.
Cost: O(artifacts at from_commit) — an offline finalize step.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
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 | |
save_act_plan(job_id: str, plan: dict[str, Any]) -> None
¶
Persist the act-stage record for job_id; overwrites any previous one.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
521 522 523 | |
save_credentials(slug: str, blob: dict[str, Any]) -> None
abstractmethod
¶
Persist the (already encoded) credential blob for slug; overwrite.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
585 586 587 | |
save_entity_recommendation(slug: str, rec: EntityRecommendation) -> None
¶
Upsert a resolution-recommendation record (a prior for the next pass).
Keyed on rec.id (deterministic over action + sorted subjects + type),
NOT appended: these records are read back as priors by EntityResolver,
so an unkeyed insert let a replayed enrich pass state the same prior
twice and re-weight the ladder purely by having run again.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 | |
save_job_plan(job_id: str, plan: list[dict[str, Any]]) -> None
abstractmethod
¶
Persist the page-plan list for job_id; overwrites any previous plan.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
489 490 491 | |
save_job_submission(job_id: str, submission: dict[str, Any]) -> None
abstractmethod
¶
Persist the wizard submission dict for job_id (token must be absent).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
575 576 577 | |
save_page(slug: str, page: WikiPage, *, commit_sha: str | None = None, job_id: str | None = None) -> None
abstractmethod
¶
Persist page for the project slug; overwrites if same page_id.
commit_sha/job_id attribute the page to its owning index. Unlike
the graph families, page attribution is a store-internal column, never a
WikiPage field — the page IS a console wire type serialized whole, so
keeping attribution off the model preserves that wire byte-for-byte. Page
supersession is unaffected: wiki_finalize already prunes pages to the
committed plan, so this is provenance, not the supersede mechanism.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
save_project_settings(slug: str, settings: ProjectSettings) -> None
abstractmethod
¶
Persist (upsert) the editable settings record for slug.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
236 237 238 | |
save_qa(answer: QaAnswer) -> None
abstractmethod
¶
Persist a QA answer record. Use ONLY to create it (resets bookkeeping).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
632 633 634 | |
save_resume_plan(job_id: str, plan: dict[str, Any]) -> None
¶
Persist the resume-plan dict for job_id; overwrites any previous one.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
503 504 505 | |
supersede_graph_artifacts(slug: str, *, keep_commit_sha: str) -> dict[str, int]
¶
Reap prior-commit graph + entity artifacts once keep_commit_sha completes.
Deletes every node/edge/embedding/entity/entity-edge/entity-embedding for
slug whose commit_sha is a REAL value other than keep_commit_sha.
Rows stamped None are PRESERVED — for entities that is a QA-minted or
pre-isolation record (accretive memory, not a per-commit snapshot); for
code nodes there are none on a git slug (every index stamps its commit).
Returns per-collection delete counts. Idempotent: a second call for the
same keep_commit_sha finds nothing to reap.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
816 817 818 819 820 821 822 823 824 825 826 827 828 829 | |
update_job(job_id: str, **fields: Any) -> IndexingJob
¶
Partially update job_id with fields; return the updated record.
Concrete on the base because the rule both drivers owe their callers is
ONE rule: only the fields the caller NAMED are written. Persisting the
whole merged document instead turns every write into a read-modify-write
over every field, so two writers that overlap lose one another's changes
even when the fields they touch are disjoint. The phase tools write
progress on a 50ms-to-5s cadence while an HTTP thread writes status,
so a cancel silently reverting to running needs no exotic timing to
reproduce.
The narrowing lives here; making the narrow write INDIVISIBLE is
per-backend (:meth:_write_job_patch), because a lock and a
field-scoped update are not the same cure.
Raises KeyError when the job is absent and ValidationError when
a field is unknown to the model or its value is wrong for it. Naming no
field at all is a read: there is nothing to narrow, so nothing is
written.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
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 | |
update_project(slug: str, fields: dict[str, Any]) -> Project | None
¶
Apply a partial update to slug's Project; return the new state.
Cost: O(one record) — one project read and one upsert of that same
record, regardless of how much the project has indexed.
Returns None when the project is absent. Only keys in
:data:PROJECT_UPDATABLE are honoured — an unknown or None value is
ignored, so a caller can hand over a whole PATCH body without pre-filtering
(mirrors agentic_search.store.update_workspace). None meaning "not
supplied" is the OPPOSITE of update_job's rule, where a named None
is a value to be written — do not carry one convention onto the other.
Concrete on the base rather than per-backend: create_project is an
UPSERT in both drivers, so read → model_copy → upsert needs no
duplicated JSON/Mongo pair that could drift. It is a read-modify-write with
the same (non-)atomicity as every other Project write in this store.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
197 198 199 200 201 202 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 | |
update_qa_fields(answer: QaAnswer) -> None
abstractmethod
¶
Update a QA answer's content fields in place — NON-destructive.
Persists every QaAnswer field but MUST NOT disturb store bookkeeping
that some backends pack alongside the record: the event_count idx
counter and the session_id mapping. save_qa does a FULL replace,
which on Mongo resets event_count to 0 (so the next append_qa_event
collides at idx 0) AND drops session_id (breaking
find_qa_by_session). Mid-stream writers (QaFinalizer) MUST use
this; save_qa is for creation only. (The JSON backend keeps session +
events in separate files, so for it this is just an answer.json rewrite —
the divergence is why a JSON-only test cannot catch the Mongo failure.)
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 | |
upsert_doc_notes(slug: str, notes: Iterable[DocPageNote]) -> None
¶
Upsert doc-page notes; dedup by page_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1046 1047 1048 | |
upsert_edges(slug: str, edges: Iterable[GraphEdge], *, commit_sha: str | None = None, job_id: str | None = None, on_progress: Callable[[int, int], None] | None = None) -> None
¶
Upsert code-graph edges, reporting completed persistence batches.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
721 722 723 724 725 726 727 728 729 730 731 | |
upsert_embeddings(slug: str, items: Iterable[Embedding], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert dense embedding vectors.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
733 734 735 736 737 738 739 740 741 742 | |
upsert_entities(slug: str, entities: Iterable[Entity], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert entities; dedup by id (= sha1(normalized_name|type)).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 | |
upsert_entity_edges(slug: str, edges: Iterable[EntityRelation], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert entity relations; dedup by id (= source|type|target).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 | |
upsert_entity_embeddings(slug: str, items: Iterable[EntityEmbedding], *, commit_sha: str | None = None, job_id: str | None = None) -> None
¶
Upsert entity embedding vectors; dedup by entity_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 | |
upsert_file_manifest(slug: str, entries: Iterable[FileManifest]) -> None
¶
Upsert per-file manifest entries; dedup by path.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
1064 1065 1066 1067 1068 | |
upsert_memory_edges(slug: str, edges: Iterable[MemoryEdge]) -> None
¶
Upsert memory edges; dedup by (source, target, type).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
945 946 947 | |
upsert_memory_embeddings(slug: str, items: Iterable[MemoryEmbedding]) -> None
¶
Upsert memory embedding vectors; dedup by node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
973 974 975 976 977 | |
upsert_memory_nodes(slug: str, nodes: Iterable[MemoryNode]) -> None
¶
Upsert memory nodes; dedup by node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
923 924 925 | |
upsert_nodes(slug: str, nodes: Iterable[GraphNode], *, commit_sha: str | None = None, job_id: str | None = None, on_progress: Callable[[int, int], None] | None = None) -> None
¶
Upsert code-graph nodes, reporting completed persistence batches.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
709 710 711 712 713 714 715 716 717 718 719 | |
vector_search(slug: str, qvec: list[float], k: int = 10) -> list[Embedding]
¶
Nearest-neighbour vector search.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
883 884 885 886 887 | |
create_wiki_store() -> WikiStoreBase
¶
Return the configured wiki store driver.
Reads storage.driver from the app config. Defaults to "json"
(filesystem). Set to "mongodb" to use MongoDB.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 | |
get_wiki_store() -> WikiStoreBase
¶
Return the process-wide wiki store, constructing it on first use.
The single instance both the API routes and the wiki SessionTools share
— the same singleton+factory+reset_for_tests shape as the SCG store
and the run store. It lets the relocated plugins reach the store down
through this factory instead of up through the API runtime; the JSON/Mongo
backend is config-addressed, so a fresh instance still sees the same data.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 | |
reset_for_tests(root_dir: str | Path | None = None) -> WikiStoreBase
¶
Swap in a fresh JSON store (under root_dir if given) for test isolation.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4267 4268 4269 4270 4271 | |
set_wiki_store(store: WikiStoreBase | None) -> None
¶
Pin the process-wide wiki store (API startup wiring / test injection).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/store.py
4261 4262 4263 4264 | |
mewbo_graph.wiki.types
¶
Pydantic v2 mirrors of the frontend wiki API wire types.
Every model here corresponds 1-to-1 with a TypeScript interface or type alias
declared in apps/mewbo_console/src/components/wiki/api/types.ts.
Conventions:
- model_config = ConfigDict(extra="forbid", populate_by_name=True)
- Python attributes are snake_case; camelCase wire names use Field(alias=...).
- Discriminated unions are wrapped in RootModel for model_validate access.
AccordionBlock
¶
Bases: BaseModel
Accordion (collapsible) block.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
308 309 310 311 312 313 314 | |
BlockCloseEvent
¶
Bases: BaseModel
Emitted when the current block is finalised.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1704 1705 1706 1707 1708 1709 | |
BlockDeltaEvent
¶
Bases: BaseModel
Emitted for each text chunk appended to the current block.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1695 1696 1697 1698 1699 1700 1701 | |
BlockOpenEvent
¶
Bases: BaseModel
Emitted when a new block starts streaming.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1686 1687 1688 1689 1690 1691 1692 | |
BlockUnion
¶
Bases: RootModel[_BlockAnnotated]
Discriminated union of all block kinds; use BlockUnion.model_validate.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
356 357 | |
CancelledEvent
¶
Bases: BaseModel
Terminal event: indexing was cancelled.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1471 1472 1473 1474 1475 | |
CatalogDocument
¶
Bases: BaseModel
One programmatically-ingested catalog record (a product, FAQ, doc, …).
The wire shape POST /v1/wiki/projects/{slug}/documents accepts. Each
record becomes BOTH a WikiPage (BM25 + wiki_search_pages) AND a
graph node carrying the text (embeddings + wiki_code_search) so the
existing :class:HybridRetriever grounds it with no pipeline change.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | |
CatalogIngestReport
¶
Bases: BaseModel
Outcome of a :class:CatalogIngestor.ingest call.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
ClassNode
¶
Bases: GraphNodeBase
A class / struct definition.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1959 1960 1961 1962 | |
CodeGraph
¶
Bases: BaseModel
Whole-graph validated bundle of nodes + edges (schema v2).
Assembled + validated ONCE at ingest (build_graph_core) before the store
persists the flat lists. The model_validator enforces three invariants a
per-node/edge check can't: (1) node-id uniqueness; (2) referential integrity
— a non-synthetic edge's endpoints must both resolve to a node (a synthetic
cross-file edge carrying target_name may point out-of-repo, and its
source may itself be a by-name id); (3) CPG-style per-edge-type endpoint
rules. An already-trusted persisted graph can skip re-validation via
model_construct.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 | |
CommitScope
dataclass
¶
Which generation of a slug's persisted graph a read covers.
The store holds the UNION of every commit ever indexed for a slug, so a reader has to say which generation it means. There are exactly two answers, they are not orderable, and one of them is not expressible as a commit sha — hence a type rather than another optional string:
CommitScope.at(sha)— rows stamped exactly sha.at(None)matches rows stamped NULL (a commit-less catalog node, or any unstamped node), which is a real generation, not "no filter".CommitScope.every()— every generation ever indexed.
Why this is not a commit_sha: str | None parameter.
count_graph_nodes and supersede_graph_artifacts already take that
parameter, and None there means "stamped NULL" — an exact match, which
is precisely how they count and preserve the pre-isolation generation.
Adding commit_sha: str | None = None to query_graph with "unscoped"
semantics would give one parameter name OPPOSITE meanings on two methods of
the same class, so a reader who learned it on one would be wrong on the
other with nothing to warn them.
Both projections live here rather than in the drivers because the two
drivers filter through different mechanisms — the JSON driver tests a
loaded row, Mongo narrows a query document — and a rule typed twice is a
rule that drifts. filter_fields returns plain field equality, not a
Mongo operator, so it stays storage-agnostic.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 | |
at(sha: str | None) -> CommitScope
classmethod
¶
Scope to rows stamped exactly sha (None matches NULL-stamped).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1840 1841 1842 1843 | |
every() -> CommitScope
classmethod
¶
Every generation ever indexed for the slug (the union).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1845 1846 1847 1848 | |
filter_fields() -> dict[str, str | None]
¶
Field-equality predicate for this scope; empty dict when unscoped.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1854 1855 1856 | |
matches(row_commit: str | None) -> bool
¶
Does a row stamped row_commit fall in this scope?
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1850 1851 1852 | |
CompleteEvent
¶
Bases: BaseModel
Terminal event: indexing succeeded.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1462 1463 1464 1465 1466 1467 1468 | |
DiagramBlock
¶
Bases: BaseModel
Mermaid diagram reference block.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
334 335 336 337 338 339 | |
Embedding
¶
Bases: BaseModel
Dense embedding vector for a graph node.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 | |
ErrorEvent
¶
Bases: BaseModel
Terminal event: indexing failed with an error.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1478 1479 1480 1481 1482 1483 | |
ExternalNode
¶
Bases: GraphNodeBase
VIEW-only convergence node for an unresolved out-of-repo symbol.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1995 1996 1997 1998 | |
FileNode
¶
Bases: GraphNodeBase
A source file — the container every in-file symbol hangs off.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1947 1948 1949 1950 | |
FinalizingEvent
¶
Bases: BaseModel
Emitted when all files are scanned and final pages are being written.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1453 1454 1455 1456 1457 1458 1459 | |
FingerprintDecision
¶
Bases: BaseModel
The three-state, honest verdict from comparing two fingerprints.
Mirrors RepoFreshness.check: "no prior fingerprint to compare against"
(reason="unknown") must never collapse into "compared and it matched"
(reason="match") — the first means a full rebuild is the safe default,
the second means reuse is permitted, and rendering them the same would be
exactly the false-green RepoFreshness already refuses to produce.
can_reuse is DERIVED from reason, never independently settable —
a plain @property, not a computed_field: this model is frozen (a
computed verdict, not mutable state), and a derived key inside
model_dump would be a second writer of the same fact reason
already carries.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
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 927 928 929 930 931 932 933 934 935 936 937 938 | |
can_reuse: bool
property
¶
True only when a prior fingerprint was compared and every field matched.
compute(current: IndexFingerprint, prior: IndexFingerprint | None) -> FingerprintDecision
classmethod
¶
Compare current against prior — prior=None reads unknown.
Accumulates EVERY mismatching field rather than stopping at the
first, so a caller (a log line, a console readout) can report every
reason a rebuild is needed in one pass, per :data:_FINGERPRINT_FIELDS.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 | |
FingerprintMismatch
¶
Bases: BaseModel
One field where a prior fingerprint and the current one disagree.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
881 882 883 884 885 886 887 888 | |
FolderNode
¶
Bases: GraphNodeBase
VIEW-only directory supernode (hierarchy wire mode).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
2001 2002 2003 2004 | |
Frontmatter
¶
Bases: BaseModel
Parsed frontmatter from a wiki page.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
371 372 373 374 375 376 377 378 379 380 | |
FunctionNode
¶
Bases: GraphNodeBase
A top-level (unbound) function.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1971 1972 1973 1974 | |
GraphEdge
¶
Bases: BaseModel
Directed edge in the code graph.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 | |
GraphNodeBase
¶
Bases: BaseModel
Shared identity + provenance for every code-graph node kind.
frozen — a node is a value object the extractor emits once and every
downstream layer only READS (the view stamps hierarchy onto the wire dict,
never the node), so immutability is free and makes nodes hashable/cacheable.
Per-kind subclasses narrow type to a Literal; the discriminated
:data:GraphNode union dispatches on it. subkind/attributes
default, so a persisted node lacking them still validates.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 | |
embedding_text: str
property
¶
The text an embedder vectorises this node as.
Lives ON the node because it is a projection of the node's own fields,
and because two paths embed the same graph — the full index and the
scoped incremental refresh. Held as a helper beside one of them, the
other silently embeds a DIFFERENT string, and the same symbol lands in a
different vector neighbourhood depending on which path last touched its
file. The file segment is dropped when it merely repeats name
(a File node names itself) so it never counts twice.
GraphResolution
¶
Bases: BaseModel
What exact cross-file symbol resolution achieved for one indexed commit.
A code graph built without exact resolution is not visibly broken — it is fully populated, passes validation and renders — so "were this graph's cross-file edges resolved exactly, or guessed by name?" cannot be answered from the graph itself. It is answerable from this record, which the graph phase writes onto the project it indexed.
Lives on TWO records for the same reason IndexFingerprint does:
IndexingJob.resolution is what THIS run achieved, Project.resolution
is the snapshot describing the graph currently in the store.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 | |
degraded: bool
property
¶
True when the stored graph's cross-file edges are not exact ones.
The single question a reader asks of this record: a graph whose resolution never ran, covered part of the repository, or produced no edges answers every "who calls this" by name matching. Reading it off the project record is what makes that visible without counting edges by hand.
faithful: bool
property
¶
True when exact resolution ran and covered every root it discovered.
This is the one condition under which a name-matched cross-file edge may be dropped in favour of a resolved one: a partial pass leaves the roots it missed with no exact edges at all, so dropping theirs would remove the only edges those files have.
describe() -> str
¶
One line naming the outcome — for a job log or an operator readout.
On the model rather than at the call site because every surface that reports a pass wants the same sentence, and the counters only mean something together.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 | |
H2Block
¶
Bases: BaseModel
Level-2 heading block.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
275 276 277 278 279 280 281 | |
H3Block
¶
Bases: BaseModel
Level-3 heading block.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
284 285 286 287 288 289 290 | |
HeartbeatEvent
¶
Bases: BaseModel
Keep-alive event; consumers must ignore it.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1486 1487 1488 1489 1490 | |
HrBlock
¶
Bases: BaseModel
Horizontal-rule block.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
293 294 295 296 297 | |
IndexFingerprint
¶
Bases: BaseModel
The non-content inputs that can invalidate a hash-identical index.
Stamped by build_graph_core at the moment it actually builds the
graph — never re-derived later, and never re-probed live at finalize (a
live probe would describe "now", not "what built the artifacts actually
in the store" — see the comment at the stamp site for the resume-skip
case this avoids). Lives on TWO records for the same reason commit_sha
already does: IndexingJob.fingerprint is what THIS run used,
Project.fingerprint is a copy taken at finalize — the snapshot of
what produced the index currently in the store.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
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 | |
IndexingEventUnion
¶
Bases: RootModel[_IndexingEventAnnotated]
Discriminated union of all indexing SSE events.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1564 1565 | |
IndexingJob
¶
Bases: BaseModel
Snapshot of an in-progress or finished indexing job.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 | |
is_active: bool
property
¶
True while the job is still working — the "Indexing now" question.
A restart-stranded (interrupted) job counts as active: it is
awaiting recovery, not finished, and hiding it would leave a repository
looking un-indexed while its job is still queued for a re-drive.
is_recoverable: bool
property
¶
True when restart recovery should re-drive this job on boot.
Deliberately excludes failed even though a failed job may still hold
reusable checkpoints: an automatic re-drive of a job that already
exhausted its retry budget is how a dying index loops the API. A human
can still resume it — see :attr:is_resumable.
is_resumable: bool
property
¶
True when a checkpoint resume is worth attempting.
Broader than :attr:is_recoverable: a failed job is not re-driven
automatically but a user may still ask to resume it, and ResumePlan
decides what of it can actually be reused.
is_terminal: bool
property
¶
True when the job settled on its own terms (finished, or stopped).
The question a session-end reconciler asks: may I leave this alone?
failed answers False on purpose — a session ending cleanly on a
failed job is a mismatch between what the run believed and what it
built, and that mismatch is worth reporting.
format_stamp(now: datetime) -> str
staticmethod
¶
Render now in the one spelling this model's timestamp fields use.
The write half of :meth:seconds_since_progress. Both live here so the
format is stated once: a writer that spells it differently produces a
stamp its own reader cannot parse, and the reader's failure mode is a
silent None rather than an exception.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 | |
regresses_to(phase: str) -> bool
¶
True when phase sits BEFORE the one this job already reached.
A resume is told to re-clone and re-scan so the source is back on disk
before pages are written, so those tools legitimately run again and
re-stamp phases the job passed long ago. Both progress surfaces read
phase off this snapshot, so without this question being asked the
bar walks backwards mid-resume — a job that had already built its graph
reported scan again, with a phase_started_at later than the
graph build's.
Unknown phase names are never a regression: an unrecognised value is a vocabulary the caller knows about and this model does not, and silently swallowing its transition would hide real progress.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 | |
seconds_since_progress(now: datetime) -> float | None
¶
Seconds between now and the last progress write, or None.
None means "no usable baseline" — either nothing has reported
progress yet or the stored stamp is unreadable. Both answers say the
same thing to a caller (there is nothing to compare against), and
neither may be reported as "0 seconds ago", which would read as a job
that just moved.
The clock arrives as an ARGUMENT: this model is persisted and wired, and a model that reads a clock cannot be tested without patching one.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 | |
InlineNode
¶
Bases: RootModel[str | list['InlineNode'] | dict]
Recursive inline rich-text node.
Valid root values:
str— plain textlist[InlineNode]— sequence of inline nodes{"code": str}— inline code span{"link": str, "text": str}— hyperlink{"kind": "src", "path": str, "lines"?: str}— source reference
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
248 249 250 251 252 253 254 255 256 257 258 | |
InterfaceNode
¶
Bases: GraphNodeBase
An interface / trait / protocol definition.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1965 1966 1967 1968 | |
Language
¶
Bases: BaseModel
Language option shown in the wizard.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
206 207 208 209 210 211 212 213 | |
LogEvent
¶
Bases: BaseModel
Free-form milestone line shown in the indexing timeline.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1538 1539 1540 1541 1542 1543 1544 | |
MetaEvent
¶
Bases: BaseModel
First QA event of a turn, carrying answer ID and chosen model.
Emitted once per turn — at the start of :meth:WikiQaSession.start AND
:meth:WikiQaSession.follow_up — so it also marks where each turn's
events begin in the append-only log (see QaFinalizer.current_turn_events).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 | |
MethodNode
¶
Bases: GraphNodeBase
A method bound to a class/struct/object.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1977 1978 1979 1980 | |
ModuleNode
¶
Bases: GraphNodeBase
An imported module target (synthetic cross-file IMPORTS endpoint).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1953 1954 1955 1956 | |
NavEntry
¶
Bases: BaseModel
Sidebar navigation entry.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
219 220 221 222 223 224 225 226 227 | |
ObjectNode
¶
Bases: GraphNodeBase
A singleton object (Kotlin object / companion object; Scala later).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1983 1984 1985 1986 | |
PBlock
¶
Bases: BaseModel
Paragraph block.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
267 268 269 270 271 272 | |
PageCommittedEvent
¶
Bases: BaseModel
One page just landed; index is 0-based.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1525 1526 1527 1528 1529 1530 1531 1532 | |
PagePlan
¶
Bases: BaseModel
Planned wiki page — used by the indexing pipeline before writing.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 | |
PhaseEvent
¶
Bases: BaseModel
Coarse-phase transition; drives the phase-weighted progress bar.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1509 1510 1511 1512 1513 1514 | |
PlanCommittedEvent
¶
Bases: BaseModel
Plan has landed — drives the denominator of the page-write bar.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1517 1518 1519 1520 1521 1522 | |
Platform
¶
Bases: BaseModel
Git-hosting platform descriptor (used in wizard).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
Project
¶
Bases: BaseModel
Landing-card model for a wiki project.
Slug is fully qualified — host/owner/repo — so the identity is
unambiguous across self-hosted and enterprise instances. A two-segment
slug (owner/repo) also reads, with host then None.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
measured_steps(records: list[StepRecord], *, declared_keys: set[str], now: datetime) -> dict[str, StepMeasurement]
¶
Blend this run's completed records into the calibrated step costs.
Cost: O(declared steps). A 75/25 rolling blend retains most of the
prior reading while admitting a repository's current shape; one run is
noisy, but a repository can also change size between indexes. Only
declared, completed records participate, so resume-skipped steps retain
the previous reading instead of becoming falsely free.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
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 | |
ProjectSettings
¶
Bases: BaseModel
The EDITABLE settings of an INDEXED wiki project, keyed by slug.
Why this exists. :class:Project is a DISPLAY snapshot —
wiki_finalize / GraphOnlyIndexer rebuild it WHOLESALE on every
successful (re)index, so any field written directly onto it is silently wiped
by the next reindex. The settings a project is actually re-indexed WITH have
always been the :class:WizardSubmission — but that was persisted as a
JOB-keyed sidecar, which gave an editor no stable write target (and made
"latest submission" a scan over jobs).
This record is that target: ONE per slug, holding the submission contract
minus the never-persisted token, plus a desc display override.
WikiIndexingJob.refresh consults it FIRST, falling back to the per-job
scan when a project has no record — which is what makes an edit actually
take effect on the next index.
Two fields are deliberately absent. slug is the store key for pages, jobs,
credentials and freshness, so it is immutable — there is no rename primitive.
token never lands here: credentials resolve through the ONE registry
(mewbo_graph.wiki.credentials), and a secret in this record would be a
third source of truth.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | |
from_submission(sub: WizardSubmission, *, desc: str | None = None) -> ProjectSettings
classmethod
¶
Project a :class:WizardSubmission onto the durable settings record.
sub.token is dropped (the credential registry owns it). desc carries
an existing override forward, so re-seeding this record from a submission
— which every WikiIndexingJob.start does, including the one a refresh
drives — cannot clobber a user's edited description.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
to_submission() -> WizardSubmission
¶
Rebuild the :class:WizardSubmission a re-index replays.
Always token-less: the clone tool's resolve_chain reads the durable
credential itself at clone time, so a refresh never needs to carry one.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | |
PropertyNode
¶
Bases: GraphNodeBase
A field / property / constant.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1989 1990 1991 1992 | |
QaAnswer
¶
Bases: BaseModel
Complete Q&A answer returned after streaming finishes.
Top-level question/blocks/summary_sources/accessed_sources/
models_used/status always describe the LATEST turn — the shape a
single-shot consumer (MCP ask_wiki, a fresh GET) already expects,
byte-compatible with before turns existed. turns additively carries
every PRIOR completed turn once a session is continued via
WikiQaSession.follow_up; a never-followed-up answer has an
empty turns list.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 | |
QaCancelledEvent
¶
Bases: BaseModel
Terminal QA event: answer generation was cancelled.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1720 1721 1722 1723 1724 | |
QaCompleteEvent
¶
Bases: BaseModel
Terminal QA event: answer generation succeeded.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1712 1713 1714 1715 1716 1717 | |
QaErrorEvent
¶
Bases: BaseModel
Terminal QA event: answer generation failed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1727 1728 1729 1730 1731 1732 | |
QaEventUnion
¶
Bases: RootModel[_QaEventAnnotated]
Discriminated union of all Q&A SSE events.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1756 1757 | |
QaHeartbeatEvent
¶
Bases: BaseModel
QA keep-alive event; consumers must ignore it.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1735 1736 1737 1738 1739 | |
QaTurn
¶
Bases: BaseModel
One completed question+answer round within a continued QA answer.
Snapshotted from QaAnswer's top-level fields when
WikiQaSession.follow_up starts a new turn on the same answer/session
— see QaAnswer.turns.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 | |
QueuedEvent
¶
Bases: BaseModel
Emitted when a job is accepted into the queue.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1423 1424 1425 1426 1427 1428 1429 1430 | |
RefreshDecision
¶
Bases: BaseModel
Which refresh path a project takes, and — when it is full — why.
The ONE answer to "scoped or full", computed once per refresh and then
carried everywhere it is needed: the route's response body, the
IndexingJob snapshot (so a console can say why a rebuild was full), and
the resume branch that must re-drive a stranded scoped job the same way it
ran the first time. One record rather than a mode flag plus a reason string
plus a mismatch list, because those three can only ever disagree.
:meth:decide is PURE — it takes the already-probed inputs as arguments and
touches no store, no clock and no subprocess, so the whole policy is
testable without a repository on disk. Probing belongs to the callers at the
edges.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 | |
decide(*, mode: RefreshMode, project: Project, current: IndexFingerprint) -> RefreshDecision
classmethod
¶
Choose the refresh path for project under mode.
Ordered cheapest-and-most-decisive first, so the reason a reader is
shown is the one that would still hold if everything after it were
fixed. current is what THIS refresh would build with; it is compared
against what the stored index was actually built with
(Project.fingerprint) through the same three-state
:class:FingerprintDecision the graph phase already stamps — "never
compared" stays distinct from "compared and matched", so an index
nothing fingerprinted rebuilds instead of silently reusing.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 | |
RepoCredential
¶
Bases: BaseModel
A persisted repository credential — a git token OR an SSH/deploy key.
Stored per-scope in the isolated credential store (CredentialScope —
see mewbo_graph.wiki.credentials, which also owns the host-covers-repo
sharing rule). The credential itself carries NO scope field: the scope is
the store KEY, and it is stamped into the blob at save time — one binding,
not two that can disagree. Plaintext-at-rest behind the store's
_encode/_decode seam; ALWAYS redacted in-flight (SSE / transcript /
logs).
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 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 | |
dedup_key: tuple[str, str, str | None]
property
¶
The identity two credentials must share to be considered the same one.
username is part of it deliberately: a value shared by two usernames
(a GitLab oauth2 deploy token vs a PAT) authenticates DIFFERENTLY, so
the resolution chain must try both rather than dedup the second away.
ScannedEvent
¶
Bases: BaseModel
Emitted after a file has been analysed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1443 1444 1445 1446 1447 1448 1449 1450 | |
ScanningEvent
¶
Bases: BaseModel
Emitted just before a file is analysed.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1433 1434 1435 1436 1437 1438 1439 1440 | |
ScopePreview
¶
Bases: BaseModel
Counts describing what one scoped refresh actually touched.
Produced by RefreshReport.scope_preview() in
mewbo_graph.wiki.refresh and carried on both the job's SSE stream and
its snapshot. It lives HERE rather than beside its producer because
IndexingJob persists it: a model the store round-trips is a wire type,
and refresh.py already imports this module, so defining it there and
importing it back would close a cycle.
Deliberately FLAT rather than mirroring RefreshReport's four-stage
shape. The reader is a progress panel rendering a row of counts, and a
nested payload would make it walk three levels to reach an integer it
displays verbatim.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 | |
SourceRef
¶
Bases: BaseModel
Source-file reference with optional line range.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
363 364 365 366 367 368 | |
SourcesBlock
¶
Bases: BaseModel
Cited sources block.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
317 318 319 320 321 322 | |
StepMeasurement
¶
Bases: BaseModel
One completed step's observed elapsed time and final unit count.
The record belongs on :class:Project, the stable current-index snapshot,
rather than a job that the next index has to search for. It stays bounded by
the declared plan: one measurement per step, never per file, node, or page.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
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 | |
blended_with(observed: StepMeasurement) -> StepMeasurement
¶
Blend a newer reading into this one. Cost: O(1).
The previous reading keeps 75% of the result and the newest completed run supplies 25%, which damps one-off noise without making calibration stale. When both readings count units, blend their rates projected onto the new count — otherwise a doubled repository would inherit half its time.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
from_record(record: StepRecord, now: datetime) -> StepMeasurement | None
classmethod
¶
Project one completed non-skipped ledger record into a measurement.
Cost: O(1). The clock arrives from the caller for testability. A
skipped resumed phase has no fresh cost, so it must not replace an earlier
measurement with a near-zero duration.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
SummaryReadyEvent
¶
Bases: BaseModel
Emitted once summary sources are known.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1678 1679 1680 1681 1682 1683 | |
TableBlock
¶
Bases: BaseModel
Table block.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
325 326 327 328 329 330 331 | |
TocEntry
¶
Bases: BaseModel
In-page table-of-contents entry.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
230 231 232 233 234 235 236 237 | |
UlBlock
¶
Bases: BaseModel
Unordered-list block.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
300 301 302 303 304 305 | |
WikiError
¶
Bases: BaseModel
Typed error returned by wiki API endpoints and streamed events.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 | |
WikiPage
¶
Bases: BaseModel
Full wiki page including body, TOC, and sidebar nav.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
383 384 385 386 387 388 389 390 391 392 393 | |
WizardSubmission
¶
Bases: BaseModel
Wizard POST body for triggering a new indexing job.
repo_url is optional: a NON-git "catalog" workspace (programmatic
document ingestion via CatalogIngestor / POST .../documents) has no
clone URL. The git indexing pipeline still requires it — its own validation
rejects a clone with an empty URL — but the model itself no longer forces
one so the same submission shape carries a repo-less catalog project.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | |
check_custom_instructions(v: str | None) -> str | None
classmethod
¶
Strip, collapse blank to None, and cap the length.
THE rule for this field, delegated to by :class:ProjectSettings and by
the api's ProjectSettingsPatch so the three hops cannot disagree
about what a valid value is.
The cap is why this is a validator rather than a bare field: the text is appended to the page-writer prompt of EVERY page in the fan-out, so it is paid once per page, not once per index — a repository with 200 pages pays for it 200 times.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
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 489 | |
check_mcp_servers(v: dict[str, dict] | None) -> dict[str, dict] | None
classmethod
¶
Validate the server map's shape; an empty map collapses to None.
THE rule for this field, shared by the same three hops as
:meth:check_custom_instructions. Deliberately shallow: the VALUE is the
standard MCP server-config shape that get_merged_mcp_config consumes
verbatim, and re-modelling it here would be a second, drifting copy of a
schema this package does not own. What is checked is what this layer
genuinely owns — that the map is name→object, with usable names.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | |
make_graph_node(**data: Any) -> GraphNode
¶
Construct the per-kind GraphNode subclass for a dynamic type.
Thin factory over :data:_NODE_CLS_BY_TYPE for the (few) call sites whose
type is only known at runtime — collapsing an otherwise-repeated
per-kind branch (DRY). Static sites should use the per-kind class directly.
Source code in packages/mewbo_graph/src/mewbo_graph/wiki/types.py
2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 | |
Source Capability Graph (mewbo_graph.scg)¶
mewbo_graph.scg.router
¶
ScgRouter — the cheap query→route mechanism over the SCG (spec §6).
Routing is the graph's only query-time job: control routing. Given a natural
-language query, the router embeds it, vector-searches seed nodes in the store,
expands one hop along capability/route edges to assemble candidate
:class:RouteRecipes, and ranks them with a deterministic, zero-LLM score
(cosine(seed) + edge weight). The agentic traversal engine consumes
the ranked recipes; spending sub-agents is a downstream concern.
This is the lightweight pre-rank, not the full hypothesis search. It mirrors HippoRAG2's "cheap structural pre-rank before spending agents" stance: route first, traverse second.
SCALE SEAM — Personalized PageRank¶
A query-seeded Personalized PageRank (PPR) over the SCG with hub damping is the
documented upgrade for ranking quality at catalog scale (HippoRAG2
2502.14802, PathRAG 2502.14902). It lands behind this same
route() signature — callers never change. It is deliberately NOT
implemented now: the additive cosine + weight score is cheaper, fully
deterministic, and sufficient for the small catalogs SCG ships with first.
ScgRouter
¶
Cheap, deterministic query→route over the Source Capability Graph.
Dependency-injected with an :class:ScgStore and a query embedder (the wiki
:class:~mewbo_graph.wiki.embedder.Embedder by default; tests inject a fake).
An OPTIONAL :class:~mewbo_graph.scg.memory_bridge.ScgMemoryBridge makes
routing memory-aware: when injected, the top-k learned connector
notes for the query boost pathways already known to produce results and damp
discovered dead ends — a retrieval-plus-arithmetic step, NO LLM, so the
zero-LLM routing core is preserved. Omit it (None) and routing is
memory-blind (the historical structure-only behaviour).
Holds no per-query state — all behaviour is expressed over the injected collaborators, so a single router instance is reusable across queries.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/router.py
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 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 | |
__init__(*, store: ScgStore, embedder: _QueryEmbedder, memory_bridge: ScgMemoryBridge | None = None) -> None
¶
Bind the SCG store + query embedder (+ optional memory bridge).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/router.py
72 73 74 75 76 77 78 79 80 81 82 | |
route(query: str, *, k: int = 5) -> list[RouteRecipe]
¶
Return up to k :class:RouteRecipes best matching query.
Thin wrapper over :meth:route_with_memory that drops the bias map — the
stable, historical signature for callers that only need the ranked
recipes (the memory bias still applies when a bridge is injected).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/router.py
84 85 86 87 88 89 90 91 92 | |
route_with_memory(query: str, *, k: int = 5) -> tuple[list[RouteRecipe], ScgMemoryBias]
¶
Rank recipes AND return the learned-memory bias map that shaped them.
Embed → vector-search seed nodes → expand one hop along capability/route
edges → assemble candidate recipes → rank by cosine(seed) + edge
weight + memory_boost (still zero-LLM — the memory term is a vector
read + a polarity-weighted sum). Returns ([], empty_bias) for an
empty graph or no match.
The returned :class:ScgMemoryBias carries the per-capability anchored
HINTS too, so the scg_route plugin tool can surface "how to call this
right" guidance on each recipe without re-reading memory.
Honours the ambient :class:ScgScope: a candidate recipe whose
steps reach an out-of-scope source is dropped, AND a memory note anchored
to an out-of-scope source contributes no bias — routing and learning both
stay inside the workspace over the otherwise GLOBAL shared graph.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/router.py
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 | |
mewbo_graph.scg.parser
¶
ScgParser — the registry that maps sources into the persisted SCG (spec §6).
This is the parser's control layer: the per-type
:class:~mewbo_graph.scg.providers.base.SourceStructureProviders do
the descriptor→graph parsing; ScgParser owns persistence, embedding, and the
cross-capability / cross-source joins that no single provider can see:
- :meth:
parse_source— dispatch one descriptor to the provider for itssource_type, clean re-map (store.delete_sourcefirst so a re-index never accumulates stale/duplicate nodes), persist nodes/edges/recipes + the descriptor, then embed every node and upsert an :class:ScgEmbedding. - :meth:
link_sources— run the injected :class:TypeAlignerto depositRESOLVES_TOhypothesis edges across sources (no-op without an aligner). - :meth:
compute_param_edges— the In-N-Out (2509.01560) producer→consumer join: match a capability'sPRODUCESoutput field to another capability's input binding by field name and emit aCONSUMESedge carryingbinds=(out_key, in_key)so traversal can chain ops into qualified paths.
The embedder is the wiki :class:~mewbo_graph.wiki.embedder.Embedder (constructed
via make_embedder() by default; tests inject a fake). Embedding is
best-effort — a missing/failed embedding backend degrades to a structure-only
SCG, never a hard failure (mirrors the wiki's BM25-fallback stance).
Security invariant (spec §6): nodes carry only redacted descriptors; this class copies no token/credential/data — it persists exactly what the providers emit.
ScgParser
¶
Maps mapped sources into the persisted Source Capability Graph.
Dependency-injected with the :class:ScgStore to persist into, the list of
:class:SourceStructureProviders to dispatch over (built into an internal
:class:StructureProviderRegistry), a node embedder (the wiki
:class:Embedder by default), and an optional :class:TypeAligner for the
cross-source RESOLVES_TO pass. Holds no per-source state — every method
operates over the injected store, so one parser instance maps a whole
catalog.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/parser.py
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 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
__init__(*, store: ScgStore, providers: list[SourceStructureProvider], embedder: _NodeEmbedder | None = None, aligner: TypeAligner | None = None) -> None
¶
Bind the store, providers (→ registry), embedder, and aligner.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/parser.py
91 92 93 94 95 96 97 98 99 100 101 102 103 | |
compute_param_edges() -> list[ScgEdge]
¶
Wire CONSUMES edges from producing ops to consuming ops by field.
The In-N-Out join (2509.01560): a capability's PRODUCES output
field (<cap>.<name>) matched to another capability's input binding
of the same field name yields a CONSUMES edge
producer → consumer carrying binds=(out_key, in_key) — the seam
the router chains into qualified multi-hop paths. Deterministic;
self-edges are skipped. Returns (and persists) the edges emitted.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/parser.py
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 | |
link_sources(source_ids: list[str]) -> list[ScgEdge]
¶
Run the injected aligner across source_ids, persisting RESOLVES_TO.
Returns the emitted edges (already upserted by the aligner). Without an
aligner injected this is a deterministic no-op ([]), never a raise.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/parser.py
154 155 156 157 158 159 160 161 162 | |
parse_source(descriptor: SourceDescriptor) -> StructureGraph
¶
Map one source into the SCG and return its parsed structure graph.
Clean re-map: every prior node/edge/recipe/embedding for this source is
deleted first, so re-indexing replaces rather than accumulates. The
descriptor is persisted (with its tool-list :class:ManifestHash stamped
on schema_version) so later link_sources / re-maps can find it and
the workspace-save drift check can compare the live surface against the
mapped one.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/parser.py
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 | |
mewbo_graph.scg.entity_resolution
¶
Type-level cross-source entity resolution — spec §6 (abstain-by-default).
:class:TypeAligner runs at map time: it compares entity_type nodes
across the given sources and deposits durable RESOLVES_TO edges
(method="type_align") for the type correspondences it is confident about —
e.g. Jira.Issue <=> Linear.Ticket. The edge is a weighted, provenanced
hypothesis (Graphiti validity window already on :class:ScgEdge), never an
asserted truth: traversal weighs it, it is not a hard join.
Abstain by default. An edge is emitted only on positive evidence:
- a name/field-overlap heuristic produces a similarity in
[0, 1]; - pairs at/above
confident_thresholdare emitted on the heuristic alone; - pairs in the ambiguous band (
band_low..confident_threshold) are emitted only if an injected LLM affirms them (one call per band pair); with no LLM injected, band pairs abstain (NONE-default — mirrors the memory layer's dedup tier-3 stance); - everything below
band_lowabstains.
Cross-source only: same-source pairs and non-entity_type nodes are skipped.
Instance-level ER is explicitly NOT here. Resolving two concrete records ("is Jira issue #42 the same work item as Linear ticket ENG-7?") happens online, inside the probe agent, which keys-blocks and selects natively over live data. This class owns only the offline, type-level schema correspondence that scopes where the probe agent should even look — never the data behind it.
Security invariant (spec §6): operates purely over SCG structure nodes, which carry only redacted descriptors — no token, credential, or record value.
TypeAligner
¶
Map-time, type-level cross-source entity resolver (abstain-by-default).
Dependency-injected: a :class:ScgStore to read entity_type nodes from
and persist hypothesis edges into, plus an optional Callable[[str], str]
that disambiguates only the ambiguous band (the confident and reject tiers
never spend a token). Thresholds are read once from scg.entity_resolution
config with calibrated code defaults, so the whole feature stays gated and
tunable without editing this class.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/entity_resolution.py
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 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 220 221 222 223 224 225 226 227 | |
__init__(*, store: ScgStore, llm: Callable[[str], str] | None = None) -> None
¶
Inject the store and (optionally) the band-disambiguation LLM.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/entity_resolution.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
align(source_ids: list[str]) -> list[ScgEdge]
¶
Emit durable RESOLVES_TO edges for confident type correspondences.
Compares every cross-source pair of entity_type nodes drawn from
source_ids, abstains by default, and upserts the surviving hypothesis
edges into the store. Returns the edges emitted (empty when none clear
the bar). Deterministic for a fixed store + injected LLM.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/entity_resolution.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
mewbo_graph.scg.memory_bridge
¶
ScgMemoryBridge — the learned-layer flywheel over the SCG.
The SCG structure (schemas + pathways) is search-owned; the learned layer is shared with the wiki layer's memory substrate — there is ZERO re-implementation of the atomic-note / anchor / dedup machinery here. This module is a thin seam that:
- lets the wiki layer's :class:
~mewbo_graph.wiki.memory.InsightIngestorresolve connector anchors against the SCG instead of the code graph (:class:ScgAnchorResolver), and - deposits / retrieves connector insights under
corpus="connector"(:class:ScgMemoryBridge).
Why the resolver is correctness-critical: memory_vector_search defaults to
exclude_invalidated=True, which only returns notes that have a live
ANCHORS edge. The ingestor creates that edge only for anchors its
StructureProvider can resolve. The default CodeStructureProvider resolves
file#Name code keys — it can never resolve a connector source_key, so a
connector insight would be written but then silently dropped on read.
ScgAnchorResolver resolves source_key → :class:ScgNode, so the edge is
created and the insight surfaces.
Retrieval goes straight through the store's memory_vector_search ANN seam
(NOT MultiplexExpander): the expander's code-graph neighbour expansion
no-ops for connectors — they have no tree-sitter CALLS/IMPORTS edges to walk.
ScgAnchorResolver
¶
StructureProvider backed by the SCG store (source_key → node).
Implements the wiki layer's StructureProvider Protocol (resolve /
resolve_many / entity_key_of) so the shared InsightIngestor can
resolve connector source_key anchors instead of dropping them.
Stateless beyond the injected store — a re-map mutates the
graph, so caching would go stale (mirrors CodeStructureProvider).
The multiplex entity_key for a connector is simply its source_key
(<source_id>#<Qualified.Name>); SCG nodes already carry no byte offsets,
so anchors survive a re-index.
A source_key is resolved KIND-AGNOSTICALLY across _ANCHORABLE_KINDS
because node_id is content-addressed per (source_key, kind): an MCP
tool-list source maps each tool to a capability node while an OpenAPI
source exposes entity_type nodes, so a fixed-kind probe drops every
anchor of the other shape — which is exactly the bug that left connector
insights edge-less (and thus invisible to memory_vector_search).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
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 | |
__init__(store: ScgStore) -> None
¶
Compose over an SCG store (dependency-injected).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
115 116 117 | |
entity_key_of(slug: str, node_id: str) -> EntityKey | None
¶
Return the source_key (== entity_key) for an SCG node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
142 143 144 145 | |
resolve(slug: str, entity_key: EntityKey) -> ScgNode | None
¶
Return the SCG node addressed by entity_key (a source_key).
Probes each anchorable kind in priority order (capability first, the
MCP-tool-list shape; then entity_type, the OpenAPI shape) and returns
the first live node — so a connector source_key resolves regardless
of which structure the source's provider emitted.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
119 120 121 122 123 124 125 126 127 | |
resolve_many(slug: str, entity_keys: list[EntityKey]) -> dict[EntityKey, ScgNode]
¶
Resolve a batch by source_key; misses are omitted from the result.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
129 130 131 132 133 134 135 136 137 138 139 140 | |
ScgMemoryBridge
¶
Deposit / retrieve connector insights over the wiki layer's memory substrate.
The learned-layer flywheel for Agentic Search: data-location wins, failure
constraints, resolved bindings and learned edge weights are written as
atomic connector notes and read back to bias traversal. All atomic-note /
dedup / anchor work is the shared InsightIngestor — this class only
pins corpus="connector" and swaps in the SCG-backed anchor resolver.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
resolver: ScgAnchorResolver
property
writable
¶
The anchor resolver; lazily bound to the process-wide SCG store.
__init__(*, wiki_store: WikiStoreBase, embedder: object, llm: object | None = None) -> None
¶
Wire collaborators (all injected); llm is opt-in (dedup tier-3).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
read_anchored_insights(slug: str, query_vec: list[float], *, k: int = 10) -> list[tuple[MemoryNode, float, list[SourceKey]]]
¶
Top-k connector insights, each with its cosine score + live anchors.
The retrieval surface memory-aware routing consumes: a note is
useless to routing without knowing WHICH capability source_key it
hangs off, so this returns (note, score, anchored_source_keys) in one
pass — the live ANCHORS edge targets per note are read off the store's
edge index (list_memory_edges already excludes invalidated edges).
The score is the same brute-force cosine the router uses, so the bias is
commensurate with the seed similarity it blends into.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
read_insights(slug: str, query_vec: list[float], *, k: int = 10) -> list[MemoryNode]
¶
Return the top-k connector insights for query_vec.
Reads through the store's memory_vector_search ANN seam filtered to
corpus="connector" (NOT MultiplexExpander — its code-graph
neighbour expansion no-ops for connectors). Embeddings are resolved back
to their nodes in rank order; the corpus filter already excludes other
corpora, so the node lookup never returns a non-connector note.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
write_insight(slug: str, content: str, *, source_keys: list[str], kind: MemoryKind = 'propositional', labels: list[str] | None = None, polarity: Polarity = _DEFAULT_POLARITY, workspace: str | None = None) -> IngestResult
¶
Deposit one connector insight anchored to source_keys.
Routes through the shared InsightIngestor with corpus="connector"
and the SCG-backed anchor resolver, so resolvable anchors create the live
ANCHORS edge that retrieval requires. The resolver is passed at
construction (provider=) — connector source_keys resolve instead of
being dropped, with no post-construction mutation of the ingestor.
polarity records whether the fact is positive evidence or a dead end;
it rides a reserved scg:<polarity> label so memory-aware routing can
boost / damp the anchored capability. workspace (if given —
ambient from :class:ScgScope at the call site) rides a reserved
ws:<id> label for attribution only, NEVER a partition: the shared
graph cross-pollinates, so a cross-workspace read still surfaces the note.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
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 240 241 242 243 244 245 246 247 | |
polarity_label(polarity: Polarity) -> str
¶
The reserved label encoding polarity (the one canonical mapping).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
65 66 67 | |
polarity_of(node: MemoryNode) -> Polarity
¶
Read a note's polarity off its labels; default positive if unlabelled.
A dead-end label damps routing; anything else, an untagged note included, reads as positive evidence — the conservative default, so an untagged corpus keeps biasing toward known-good pathways with no backfill.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/memory_bridge.py
70 71 72 73 74 75 76 77 78 79 | |
mewbo_graph.scg.store
¶
Persistence for the Source Capability Graph (SCG) — JSON or MongoDB.
The SCG structure store is search-owned and deliberately SEPARATE from the
run store (agentic_search_runs): a re-map of a source rewrites graph nodes
without touching any in-flight run. It mirrors the project/wiki/run dual-backend
pattern: an abstract base + a filesystem driver + a Mongo driver + a
config-driven factory + a process-wide singleton.
Five entity families, each in its own storage namespace:
- nodes — :class:
ScgNode, keyed on the derivednode_id. - edges — :class:
ScgEdge, keyed on the(source, target, kind)triple. - recipes — :class:
RouteRecipe, keyed onsource_key. - embeddings — :class:
ScgEmbedding, keyed onnode_id. - sources — :class:
SourceDescriptor, keyed onsource_id.
JSON layout under <cache_dir>/agentic_search/scg/ — one file per collection
holding a {key: doc} map (small graphs; whole-file rewrite under a lock)::
nodes.json
edges.json
recipes.json
embeddings.json
sources.json
Mongo collections: agentic_search_scg_nodes, agentic_search_scg_edges,
agentic_search_scg_recipes, agentic_search_scg_embeddings,
agentic_search_scg_sources.
Per-source mappings are GLOBAL and content-addressed (node_id =
sha1(source_key|kind)[:16]) — the SCG is "a tenant of the same three-layer
multiplex graph that powers the Agentic Wiki" and the layers cross-pollinate
without explicit wiring (docs/features-search.md). That scope therefore does NOT
hard-partition this store by workspace; a workspace is a scoped VIEW over the
shared graph — see :mod:mewbo_graph.scg.scope (the source-id allowlist
:class:ScgRouter honours at query time) — so a re-map in one workspace stays a
cheap idempotent upsert that every workspace mapping that source benefits from.
Security invariant (spec §6): SCG nodes carry only a redacted auth_scope
descriptor — this store never sees or persists a token/credential.
JsonScgStore
¶
Bases: ScgStore
Filesystem-backed SCG store under <cache_dir>/agentic_search/scg/.
Each collection is one JSON file holding a {natural_key: doc} map. All
mutations take _lock and rewrite the whole file — SCGs are small enough
that this is simpler and safer than partial writes (single-instance use;
the Mongo driver is the multi-worker path).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
273 274 275 276 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 350 351 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 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 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
__init__(root_dir: str | Path | None = None) -> None
¶
Initialise + create the directory tree.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
288 289 290 291 292 293 294 295 296 | |
delete_source(source_id: str) -> int
¶
Delete every entity for source_id; return the count removed.
NOTE — non-atomic: the scoped delete is a sequence of per-collection file rewrites under one lock, so a mid-sequence crash can leave dangling edges pointing at an already-removed node. Acceptable for the single-instance dev (JSON) path; the multi-worker path is the Mongo backend. No transaction is layered on here (YAGNI for JSON v1).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
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 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
get_node(node_id: str) -> ScgNode | None
¶
Return one node by id, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
368 369 370 371 372 | |
list_edges(*, source: SourceKey | None = None, kind: str | None = None) -> list[ScgEdge]
¶
Return edges matching every supplied filter (AND-composed).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
list_embeddings() -> list[ScgEmbedding]
¶
Return all embeddings.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
430 431 432 433 434 | |
list_recipes(*, source_id: str | None = None) -> list[RouteRecipe]
¶
Return route recipes, optionally scoped to one source_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
417 418 419 420 421 422 423 424 425 426 427 428 | |
list_sources() -> list[SourceDescriptor]
¶
Return all source descriptors.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
436 437 438 439 440 | |
neighbors(source_key: SourceKey) -> list[ScgEdge]
¶
Return the outgoing edges whose source is source_key.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
413 414 415 | |
upsert_edges(edges: list[ScgEdge]) -> None
¶
Upsert edges, keyed on the (source, target, kind) triple.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
339 340 341 342 343 | |
upsert_embeddings(embeddings: list[ScgEmbedding]) -> None
¶
Upsert embeddings, keyed on node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
352 353 354 355 356 357 | |
upsert_nodes(nodes: list[ScgNode]) -> None
¶
Upsert nodes, keyed on node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
332 333 334 335 336 337 | |
upsert_recipes(recipes: list[RouteRecipe]) -> None
¶
Upsert route recipes, keyed on source_key.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
345 346 347 348 349 350 | |
upsert_source(descriptor: SourceDescriptor) -> None
¶
Upsert a source descriptor, keyed on source_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
359 360 361 362 363 364 | |
MongoScgStore
¶
Bases: ScgStore
MongoDB-backed SCG store.
Collections (one per family): agentic_search_scg_nodes (node_id PK),
agentic_search_scg_edges ((source, target, kind) PK),
agentic_search_scg_recipes (source_key PK),
agentic_search_scg_embeddings (node_id PK),
agentic_search_scg_sources (source_id PK).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
__init__(*, client: _MongoClient | None = None, uri: str | None = None, database: str | None = None) -> None
¶
Connect + ensure unique indexes for each upsert key.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
delete_source(source_id: str) -> int
¶
Delete every entity for source_id; return the count removed.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
get_node(node_id: str) -> ScgNode | None
¶
Return one node by id, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
628 629 630 631 | |
list_edges(*, source: SourceKey | None = None, kind: str | None = None) -> list[ScgEdge]
¶
Return edges matching every supplied filter (AND-composed).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
652 653 654 655 656 657 658 659 660 661 662 | |
list_embeddings() -> list[ScgEmbedding]
¶
Return all embeddings.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
676 677 678 679 | |
list_recipes(*, source_id: str | None = None) -> list[RouteRecipe]
¶
Return route recipes, optionally scoped to one source_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
668 669 670 671 672 673 674 | |
list_sources() -> list[SourceDescriptor]
¶
Return all source descriptors.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
681 682 683 684 | |
neighbors(source_key: SourceKey) -> list[ScgEdge]
¶
Return the outgoing edges whose source is source_key.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
664 665 666 | |
upsert_edges(edges: list[ScgEdge]) -> None
¶
Upsert edges, keyed on the (source, target, kind) triple.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
595 596 597 598 599 600 601 602 | |
upsert_embeddings(embeddings: list[ScgEmbedding]) -> None
¶
Upsert embeddings, keyed on node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
611 612 613 614 615 616 | |
upsert_nodes(nodes: list[ScgNode]) -> None
¶
Upsert nodes, keyed on node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
587 588 589 590 591 592 593 | |
upsert_recipes(recipes: list[RouteRecipe]) -> None
¶
Upsert route recipes, keyed on source_key.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
604 605 606 607 608 609 | |
upsert_source(descriptor: SourceDescriptor) -> None
¶
Upsert a source descriptor, keyed on source_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
618 619 620 621 622 623 624 | |
ScgStore
¶
Bases: ABC
Abstract base for SCG structure-persistence backends.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
__init__() -> None
¶
Initialise the shared node-query cache (drivers must super().__init__).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
151 152 153 | |
delete_source(source_id: str) -> int
abstractmethod
¶
Delete every node/edge/recipe/embedding/source for source_id.
Scoped wipe for a clean re-map; returns the total document count removed.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
260 261 262 263 264 265 | |
get_node(node_id: str) -> ScgNode | None
abstractmethod
¶
Return one node by id, or None if absent.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
183 184 185 | |
list_edges(*, source: SourceKey | None = None, kind: str | None = None) -> list[ScgEdge]
abstractmethod
¶
Return edges matching every supplied filter (AND-composed).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
220 221 222 223 224 | |
list_embeddings() -> list[ScgEmbedding]
abstractmethod
¶
Return all embeddings.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
234 235 236 | |
list_recipes(*, source_id: str | None = None) -> list[RouteRecipe]
abstractmethod
¶
Return route recipes, optionally scoped to one source_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
230 231 232 | |
list_sources() -> list[SourceDescriptor]
abstractmethod
¶
Return all source descriptors.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
238 239 240 | |
neighbors(source_key: SourceKey) -> list[ScgEdge]
abstractmethod
¶
Return the outgoing edges whose source is source_key.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
226 227 228 | |
query_nodes(*, source_id: str | None = None, kind: str | None = None, name_contains: str | None = None) -> list[ScgNode]
¶
Return nodes matching every supplied filter (AND-composed).
Memoized by the filter triple (see :class:_NodeQueryCache); node writes
invalidate the cache. Backends implement the raw scan in
:meth:_query_nodes_uncached.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
upsert_edges(edges: list[ScgEdge]) -> None
abstractmethod
¶
Upsert edges, keyed on the (source, target, kind) triple.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
165 166 167 | |
upsert_embeddings(embeddings: list[ScgEmbedding]) -> None
abstractmethod
¶
Upsert embeddings, keyed on node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
173 174 175 | |
upsert_nodes(nodes: list[ScgNode]) -> None
abstractmethod
¶
Upsert nodes, keyed on node_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
161 162 163 | |
upsert_recipes(recipes: list[RouteRecipe]) -> None
abstractmethod
¶
Upsert route recipes, keyed on source_key.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
169 170 171 | |
upsert_source(descriptor: SourceDescriptor) -> None
abstractmethod
¶
Upsert a source descriptor, keyed on source_id.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
177 178 179 | |
vector_search(qvec: list[float], k: int) -> list[tuple[str, float]]
¶
Return (node_id, cosine_score) for the top-k embeddings.
Brute-force cosine over every stored vector — the documented scale seam
(mirrors the wiki vector_search): an ANN index lands behind this
signature without changing callers.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
create_scg_store() -> ScgStore
¶
Return the configured SCG store driver (storage.driver; default JSON).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
722 723 724 725 726 727 | |
get_scg_store() -> ScgStore
¶
Return the process-wide SCG store, creating it on first use.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
734 735 736 737 738 739 740 | |
reset_for_tests() -> None
¶
Swap in a fresh, empty JSON store under a throwaway temp dir.
Keeps unit tests isolated from real data while still exercising the JSON
backend end-to-end (mirrors the run store's reset_for_tests).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
750 751 752 753 754 755 756 757 | |
set_scg_store(store: ScgStore | None) -> None
¶
Override the process-wide SCG store (used by tests).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/store.py
743 744 745 746 747 | |
mewbo_graph.scg.types
¶
Typed contracts for the Source Capability Graph (SCG) — spec §6.
The SCG indexes reachability — the schemas and qualified pathways a source
exposes, never the data behind them. These models are the shared surface
the structure providers, parser, router, and traversal engine all build
against; everything else in the scg package references them.
Conventions mirror :mod:mewbo_api.agentic_search.schemas and the wiki types:
- Every model subclasses :class:
_Wire(extra="forbid",populate_by_name=True) so unknown keys are rejected at the boundary. node_idis a deterministicsha1(source_key|kind)[:16]derived by :meth:ScgNode.make_idand overwritten on every validate — that derivation is the single source of node identity (mirrors the wiki graph's_stable_idand the memory layer's content-addressed node ids).
Security invariant (spec §6): SCG nodes carry only a redacted auth_scope
descriptor string — never persist tokens, credentials, or any secret.
CapabilityBinding
¶
Bases: _Wire
One field a capability binds, with its access mode + allowed operators.
Binding patterns keep traversal honest: a capability "queryable by
service_id, not free-text" emits mode="bound" so the router only
proposes executable plans (Florescu/Vassalos SIGMOD'99).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/types.py
65 66 67 68 69 70 71 72 73 74 75 | |
RouteRecipe
¶
Bases: _Wire
A precomputed qualified path (ordered SourceKey steps) over the SCG.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/types.py
140 141 142 143 144 145 | |
ScgEdge
¶
Bases: _Wire
A directed, weighted, provenanced edge between two SourceKey nodes.
binds records the (source-field, target-field) pair an edge aligns on;
method is the parser's evidence kind. valid_at / invalid_at
carry the invalidate-don't-delete validity window (Graphiti) so learned
edges can be retired without losing provenance.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/types.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
ScgEmbedding
¶
Bases: _Wire
A dense embedding vector for an SCG node (parallels the wiki Embedding).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/types.py
151 152 153 154 155 156 157 | |
ScgNode
¶
Bases: _Wire
A node in the Source Capability Graph.
node_id is always the canonical sha1(source_key|kind)[:16] — any
supplied value is overwritten on validate so identity stays content-addressed
and stable across re-indexes.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/types.py
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 | |
make_id(source_key: SourceKey, kind: NodeKind) -> str
staticmethod
¶
Deterministic node id over (source_key, kind) — sha1[:16].
Source code in packages/mewbo_graph/src/mewbo_graph/scg/types.py
100 101 102 103 | |
SourceDescriptor
¶
Bases: _Wire
The raw, source-type-specific descriptor a structure provider parses.
raw is the opaque provider payload (OpenAPI doc, MCP tool list, GraphQL
SDL, SQL schema…). Carries no secrets — auth lives in the connector config,
not here.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/types.py
163 164 165 166 167 168 169 170 171 172 173 174 | |
StructureGraph
¶
Bases: _Wire
The normalized provider output: nodes + edges + recipes for one source.
A provider returns one source's subgraph; ScgParser.parse_source upserts
it into the persisted whole-catalog SCG directly (one source at a time).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/types.py
180 181 182 183 184 185 186 187 188 189 | |
field_leaf(field_key: SourceKey) -> str
¶
Return the trailing .-segment of a <cap>.<name> field key (lower).
The one canonical home for the "trailing field-name segment, lower-cased" idiom shared by the parser's field indexing and the type aligner's field-overlap heuristic (DRY).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/types.py
36 37 38 39 40 41 42 43 | |
mewbo_graph.scg.providers
¶
SCG structure providers — the information→graph parser seam.
One :class:SourceStructureProvider per source type (RML declarative shell):
OpenAPI, MCP tool list, and an LLM fallback for schemaless sources. A
:class:StructureProviderRegistry dispatches a
:class:~mewbo_graph.scg.types.SourceDescriptor to the matching
provider by source_type. New source type = one class + one register call.
LlmStructureProvider
¶
Coarse single-capability provider for schemaless sources (DI LLM).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/llm_fallback.py
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 | |
__init__(*, llm: Callable[[str], str] | None = None) -> None
¶
Inject the text LLM callable; None (default) raises on use.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/llm_fallback.py
36 37 38 | |
build_structure(descriptor: SourceDescriptor) -> StructureGraph
¶
Emit a source node + one coarse capability node from a description.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/llm_fallback.py
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 | |
McpToolListStructureProvider
¶
Parse an MCP tool-list descriptor.raw into a StructureGraph.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/mcp_tool_list.py
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 | |
build_structure(descriptor: SourceDescriptor) -> StructureGraph
¶
Build a capability-per-tool subgraph for one MCP server source.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/mcp_tool_list.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
OpenApiStructureProvider
¶
Parse an OpenAPI/Swagger descriptor.raw dict into a StructureGraph.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/openapi.py
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 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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
build_structure(descriptor: SourceDescriptor) -> StructureGraph
¶
Build the source/entity/capability subgraph for one OpenAPI source.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/openapi.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
SourceStructureProvider
¶
Bases: Protocol
Parse one source type's descriptor into a normalized structure graph.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/base.py
27 28 29 30 31 32 33 34 35 36 | |
build_structure(descriptor: SourceDescriptor) -> StructureGraph
¶
Parse descriptor.raw into a :class:StructureGraph. No network.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/base.py
34 35 36 | |
StructureProviderRegistry
¶
Dispatches a :class:SourceDescriptor to the provider for its type.
The declarative shell of the RML pattern: providers register by
source_type and the registry routes build(descriptor) to the match.
Construct via :meth:with_defaults for the built-in OpenAPI + MCP set.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/base.py
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 | |
__init__(providers: list[SourceStructureProvider] | None = None) -> None
¶
Build a registry, optionally seeded with providers.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/base.py
47 48 49 50 51 52 53 | |
build(descriptor: SourceDescriptor) -> StructureGraph
¶
Dispatch descriptor to its provider and return the parsed graph.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/base.py
80 81 82 | |
for_type(source_type: str) -> SourceStructureProvider
¶
Return the provider for source_type, or raise KeyError.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/base.py
73 74 75 76 77 78 | |
providers() -> list[SourceStructureProvider]
¶
Return the registered providers (the parser's seam — public accessor).
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/base.py
69 70 71 | |
register(provider: SourceStructureProvider) -> None
¶
Add or replace the provider for its source_type.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/base.py
65 66 67 | |
with_defaults() -> StructureProviderRegistry
classmethod
¶
Registry seeded with the schema-bearing built-in providers.
Schemaless sources (LlmStructureProvider) are not auto-registered:
they need an injected llm callable, so the caller wires them
explicitly via :meth:register.
Source code in packages/mewbo_graph/src/mewbo_graph/scg/providers/base.py
55 56 57 58 59 60 61 62 63 | |
Clients (apps/)¶
- API entry point:
apps/mewbo_api/src/mewbo_api/backend.py - Console:
apps/mewbo_console/(React + Vite, connects via REST API) - CLI entry point:
apps/mewbo_cli/src/mewbo_cli/cli_master.py
Home Assistant integration (mewbo_ha_conversation)¶
mewbo_ha_conversation.api
¶
Mewbo API client.
MewboApiClient
¶
Mewbo API Client.
Source code in apps/mewbo_ha_conversation/api.py
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 166 167 168 169 170 171 172 173 | |
__init__(base_url: str, api_key: str, timeout: int, session: aiohttp.ClientSession) -> None
¶
Initialize the API client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Base URL for the Mewbo API. |
required |
api_key
|
str
|
Key sent as the |
required |
timeout
|
int
|
Request timeout in seconds. |
required |
session
|
ClientSession
|
Shared aiohttp client session. |
required |
Source code in apps/mewbo_ha_conversation/api.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
async_generate(data: dict[str, Any] | None = None) -> MewboQueryResponse
async
¶
Generate a completion from the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any] | None
|
Request payload including prompt and optional session ID. |
None
|
Returns:
| Type | Description |
|---|---|
MewboQueryResponse
|
Parsed query response payload. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If prompt data is missing. |
ApiJsonError
|
If the API returns unexpected data. |
Source code in apps/mewbo_ha_conversation/api.py
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 | |
async_get_heartbeat() -> bool
async
¶
Get heartbeat from the API.
Returns:
| Type | Description |
|---|---|
bool
|
True when the service is considered healthy. |
Source code in apps/mewbo_ha_conversation/api.py
57 58 59 60 61 62 63 64 | |
async_get_models() -> str
async
¶
Get models from the API.
Returns:
| Type | Description |
|---|---|
str
|
JSON-serialized model list. |
Source code in apps/mewbo_ha_conversation/api.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
MewboQueryResponse
¶
Bases: TypedDict
Schema for the main query response.
Source code in apps/mewbo_ha_conversation/api.py
23 24 25 26 27 28 29 | |
ModelsResponse
¶
Bases: TypedDict
Schema for the models list endpoint response.
Source code in apps/mewbo_ha_conversation/api.py
17 18 19 20 | |
mewbo_ha_conversation.config_flow
¶
Adds config flow for Mewbo.
MewboConfigFlow
¶
Bases: ConfigFlow
Handle a config flow for Mewbo Conversation. Handles UI wizard.
Source code in apps/mewbo_ha_conversation/config_flow.py
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 | |
async_get_options_flow(config_entry: config_entries.ConfigEntry) -> config_entries.OptionsFlow
staticmethod
¶
Create the options flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_entry
|
ConfigEntry
|
Existing config entry to edit. |
required |
Returns:
| Type | Description |
|---|---|
OptionsFlow
|
Options flow handler. |
Source code in apps/mewbo_ha_conversation/config_flow.py
112 113 114 115 116 117 118 119 120 121 122 123 124 | |
async_step_user(user_input: dict[str, Any] | None = None) -> FlowResult
async
¶
Handle the initial config flow step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_input
|
dict[str, Any] | None
|
Submitted form data, if available. |
None
|
Returns:
| Type | Description |
|---|---|
FlowResult
|
FlowResult for the configuration step. |
Source code in apps/mewbo_ha_conversation/config_flow.py
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 | |
MewboOptionsFlow
¶
Bases: OptionsFlow
Mewbo config flow options handler.
Source code in apps/mewbo_ha_conversation/config_flow.py
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 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 | |
__init__(config_entry: config_entries.ConfigEntry) -> None
¶
Initialize options flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_entry
|
ConfigEntry
|
Config entry to manage. |
required |
Source code in apps/mewbo_ha_conversation/config_flow.py
130 131 132 133 134 135 136 137 | |
async_step_all_set(user_input: dict[str, Any] | None = None) -> FlowResult
async
¶
Handle the "all_set" options step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_input
|
dict[str, Any] | None
|
Submitted form data, if available. |
None
|
Returns:
| Type | Description |
|---|---|
FlowResult
|
FlowResult for the options menu. |
Source code in apps/mewbo_ha_conversation/config_flow.py
150 151 152 153 154 155 156 157 158 159 | |
async_step_general_config(user_input: dict[str, Any] | None = None) -> FlowResult
async
¶
Handle the general configuration step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_input
|
dict[str, Any] | None
|
Submitted form data, if available. |
None
|
Returns:
| Type | Description |
|---|---|
FlowResult
|
FlowResult for the options menu. |
Source code in apps/mewbo_ha_conversation/config_flow.py
161 162 163 164 165 166 167 168 169 170 171 172 | |
async_step_init(user_input: dict[str, Any] | None = None) -> FlowResult
async
¶
Show the options menu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_input
|
dict[str, Any] | None
|
Submitted form data, if available. |
None
|
Returns:
| Type | Description |
|---|---|
FlowResult
|
FlowResult for the options menu. |
Source code in apps/mewbo_ha_conversation/config_flow.py
139 140 141 142 143 144 145 146 147 148 | |
async_step_model_config(user_input: dict[str, Any] | None = None) -> FlowResult
async
¶
Handle the model configuration step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_input
|
dict[str, Any] | None
|
Submitted form data, if available. |
None
|
Returns:
| Type | Description |
|---|---|
FlowResult
|
FlowResult for the options menu. |
Source code in apps/mewbo_ha_conversation/config_flow.py
187 188 189 190 191 192 193 194 195 196 | |
async_step_prompt_system(user_input: dict[str, Any] | None = None) -> FlowResult
async
¶
Handle the prompt system configuration step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_input
|
dict[str, Any] | None
|
Submitted form data, if available. |
None
|
Returns:
| Type | Description |
|---|---|
FlowResult
|
FlowResult for the options menu. |
Source code in apps/mewbo_ha_conversation/config_flow.py
174 175 176 177 178 179 180 181 182 183 184 185 | |
mewbo_ha_conversation.const
¶
Constants for mewbo_conversation.
mewbo_ha_conversation.coordinator
¶
DataUpdateCoordinator for mewbo_conversation.
MewboDataUpdateCoordinator
¶
Bases: DataUpdateCoordinator
Class to manage fetching data from the API.
Source code in apps/mewbo_ha_conversation/coordinator.py
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 | |
__init__(hass: HomeAssistant, client: MewboApiClient) -> None
¶
Initialize the coordinator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hass
|
HomeAssistant
|
Home Assistant core instance. |
required |
client
|
MewboApiClient
|
API client for Mewbo. |
required |
Source code in apps/mewbo_ha_conversation/coordinator.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
mewbo_ha_conversation.exceptions
¶
The exceptions used by Extended OpenAI Conversation.
ApiClientError
¶
Bases: HomeAssistantError
Exception to indicate a general API error.
Source code in apps/mewbo_ha_conversation/exceptions.py
6 7 | |
ApiCommError
¶
Bases: ApiClientError
Exception to indicate a communication error.
Source code in apps/mewbo_ha_conversation/exceptions.py
10 11 | |
ApiJsonError
¶
Bases: ApiClientError
Exception to indicate an error with json response.
Source code in apps/mewbo_ha_conversation/exceptions.py
14 15 | |
ApiTimeoutError
¶
Bases: ApiClientError
Exception to indicate a timeout error.
Source code in apps/mewbo_ha_conversation/exceptions.py
18 19 | |
mewbo_ha_conversation.helpers
¶
Helper functions for Mewbo.
ExposedEntity
¶
Bases: TypedDict
Typed representation of a Home Assistant entity exposed to conversation.
Source code in apps/mewbo_ha_conversation/helpers.py
13 14 15 16 17 18 19 | |
get_exposed_entities(hass: HomeAssistant) -> list[ExposedEntity]
¶
Return exposed entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hass
|
HomeAssistant
|
Home Assistant core instance. |
required |
Returns:
| Type | Description |
|---|---|
list[ExposedEntity]
|
List of exposed entities and their metadata. |
Source code in apps/mewbo_ha_conversation/helpers.py
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 | |