ltcai 11.1.0 → 11.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -54
- package/docs/CHANGELOG.md +94 -0
- package/docs/COMMUNITY_AND_PLUGINS.md +1 -1
- package/docs/DEVELOPMENT.md +1 -1
- package/docs/FEATURE_AUDIT_v11.2.0.md +393 -0
- package/docs/LAYOUT_REBUILD_SPEC.md +9 -1
- package/docs/MULTI_AGENT_RUNTIME.md +1 -1
- package/docs/ONBOARDING.md +1 -1
- package/docs/OPERATIONS.md +6 -2
- package/docs/PERMISSION_MODE.md +1 -1
- package/docs/TRUST_MODEL.md +1 -1
- package/docs/WHY_LATTICE.md +1 -1
- package/docs/architecture.md +6 -2
- package/docs/kg-schema.md +2 -2
- package/docs/v11.3.0_PLAN.md +202 -0
- package/docs/v11.4.0_RUST_FOUNDATION_PLAN.md +176 -0
- package/lattice_brain/__init__.py +1 -1
- package/lattice_brain/gates.py +125 -0
- package/lattice_brain/graph/_kg_common/__init__.py +287 -0
- package/lattice_brain/graph/_kg_common/extraction.py +516 -0
- package/lattice_brain/graph/_kg_common/relations.py +161 -0
- package/lattice_brain/graph/_kg_common/text.py +479 -0
- package/lattice_brain/graph/discovery_index/__init__.py +35 -0
- package/lattice_brain/graph/discovery_index/cleanup.py +182 -0
- package/lattice_brain/graph/discovery_index/extract.py +137 -0
- package/lattice_brain/graph/discovery_index/scan.py +411 -0
- package/lattice_brain/graph/discovery_index/upsert.py +495 -0
- package/lattice_brain/graph/fusion.py +35 -4
- package/lattice_brain/graph/projection/__init__.py +42 -0
- package/lattice_brain/graph/projection/curation.py +500 -0
- package/lattice_brain/graph/{projection.py → projection/v2_schema.py} +81 -485
- package/lattice_brain/graph/retrieval/__init__.py +54 -0
- package/lattice_brain/graph/retrieval/context.py +197 -0
- package/lattice_brain/graph/retrieval/graph_view.py +319 -0
- package/lattice_brain/graph/retrieval/hybrid.py +488 -0
- package/lattice_brain/graph/retrieval/maintenance.py +121 -0
- package/lattice_brain/graph/retrieval/signals.py +95 -0
- package/lattice_brain/graph/retrieval_vector/__init__.py +42 -0
- package/lattice_brain/graph/retrieval_vector/fingerprint.py +97 -0
- package/lattice_brain/graph/retrieval_vector/indexing.py +347 -0
- package/lattice_brain/graph/retrieval_vector/search.py +560 -0
- package/lattice_brain/graph/retrieval_vector/status.py +374 -0
- package/lattice_brain/graph/schema.py +9 -0
- package/lattice_brain/graph/store.py +9 -0
- package/lattice_brain/graph/vector_index/selector.py +32 -2
- package/lattice_brain/ingestion/__init__.py +130 -0
- package/lattice_brain/ingestion/_contract.py +90 -0
- package/lattice_brain/ingestion/constants.py +127 -0
- package/lattice_brain/ingestion/folder_scan.py +57 -0
- package/lattice_brain/ingestion/folders.py +258 -0
- package/lattice_brain/ingestion/hashing.py +26 -0
- package/lattice_brain/ingestion/jobs_api.py +107 -0
- package/lattice_brain/ingestion/models.py +80 -0
- package/lattice_brain/ingestion/pipeline.py +486 -0
- package/lattice_brain/ingestion/quality.py +209 -0
- package/lattice_brain/ingestion/routing.py +295 -0
- package/lattice_brain/multimodal/__init__.py +164 -0
- package/lattice_brain/multimodal/audio.py +77 -0
- package/lattice_brain/multimodal/common.py +118 -0
- package/lattice_brain/{multimodal.py → multimodal/images.py} +22 -262
- package/lattice_brain/multimodal/ports.py +169 -0
- package/lattice_brain/multimodal/video.py +410 -0
- package/lattice_brain/portability/__init__.py +90 -0
- package/lattice_brain/portability/_contract.py +42 -0
- package/lattice_brain/portability/backups.py +338 -0
- package/lattice_brain/portability/bundles.py +136 -0
- package/lattice_brain/portability/constants.py +93 -0
- package/lattice_brain/portability/fsops.py +138 -0
- package/lattice_brain/portability/service.py +41 -0
- package/lattice_brain/portability/sharing.py +714 -0
- package/lattice_brain/runtime/__init__.py +1 -1
- package/lattice_brain/runtime/multi_agent.py +1 -1
- package/lattice_brain/sealed_box.py +244 -0
- package/lattice_brain/synthesis.py +24 -1
- package/latticeai/__init__.py +1 -1
- package/latticeai/api/brain_intelligence.py +4 -0
- package/latticeai/api/chat.py +11 -0
- package/latticeai/api/chat_helpers.py +16 -3
- package/latticeai/api/chat_hybrid.py +32 -1
- package/latticeai/api/chronicle.py +63 -0
- package/latticeai/api/features.py +70 -0
- package/latticeai/api/local_files.py +102 -0
- package/latticeai/api/portability.py +39 -4
- package/latticeai/api/review_queue.py +126 -0
- package/latticeai/api/search.py +16 -2
- package/latticeai/core/agent/__init__.py +93 -0
- package/latticeai/core/agent/_contract.py +79 -0
- package/latticeai/core/agent/context.py +57 -0
- package/latticeai/core/agent/deps.py +125 -0
- package/latticeai/core/agent/execution.py +622 -0
- package/latticeai/core/agent/planning.py +145 -0
- package/latticeai/core/agent/recovery.py +157 -0
- package/latticeai/core/agent/runtime.py +210 -0
- package/latticeai/core/agent/verification.py +231 -0
- package/latticeai/core/config.py +4 -1
- package/latticeai/core/context_builder.py +6 -3
- package/latticeai/core/embedding_providers/__init__.py +151 -0
- package/latticeai/core/embedding_providers/base.py +199 -0
- package/latticeai/core/embedding_providers/captions.py +162 -0
- package/latticeai/core/embedding_providers/profiles.py +126 -0
- package/latticeai/core/embedding_providers/text.py +350 -0
- package/latticeai/core/embedding_providers/vision.py +352 -0
- package/latticeai/core/file_generation/__init__.py +115 -0
- package/latticeai/core/file_generation/bundles.py +76 -0
- package/latticeai/core/file_generation/extraction.py +154 -0
- package/latticeai/core/file_generation/inference.py +235 -0
- package/latticeai/core/file_generation/orchestration.py +152 -0
- package/latticeai/core/file_generation/prompting.py +117 -0
- package/latticeai/core/file_generation/repair.py +114 -0
- package/latticeai/core/file_generation/sanitize.py +61 -0
- package/latticeai/core/file_generation/validation.py +201 -0
- package/latticeai/core/legacy_compatibility.py +1 -1
- package/latticeai/core/marketplace.py +1 -1
- package/latticeai/core/messages.py +152 -0
- package/latticeai/core/model_compat.py +73 -2
- package/latticeai/core/workspace_os_constants.py +1 -1
- package/latticeai/integrations/telegram_bot/__init__.py +123 -0
- package/latticeai/integrations/telegram_bot/__main__.py +17 -0
- package/latticeai/integrations/telegram_bot/config.py +86 -0
- package/latticeai/integrations/telegram_bot/dispatch.py +311 -0
- package/latticeai/integrations/telegram_bot/flows.py +478 -0
- package/latticeai/integrations/telegram_bot/helpers.py +322 -0
- package/latticeai/integrations/telegram_bot/screens.py +394 -0
- package/latticeai/models/model_providers.py +12 -4
- package/latticeai/models/router/__init__.py +88 -0
- package/latticeai/models/router/_contract.py +66 -0
- package/latticeai/models/router/branding.py +56 -0
- package/latticeai/models/router/catalog.py +69 -0
- package/latticeai/models/router/documents.py +199 -0
- package/latticeai/models/router/errors.py +37 -0
- package/latticeai/models/router/generation.py +258 -0
- package/latticeai/models/router/loading.py +291 -0
- package/latticeai/models/router/local_models.py +85 -0
- package/latticeai/models/router/registry.py +147 -0
- package/latticeai/runtime/build_phases/__init__.py +82 -0
- package/latticeai/runtime/build_phases/features.py +407 -0
- package/latticeai/runtime/build_phases/foundation.py +555 -0
- package/latticeai/runtime/build_phases/web.py +492 -0
- package/latticeai/runtime/chat_wiring.py +4 -0
- package/latticeai/runtime/feature_toggle_wiring.py +163 -0
- package/latticeai/runtime/router_registration.py +11 -0
- package/latticeai/runtime/runtime_context.py +1 -0
- package/latticeai/services/app_context.py +8 -0
- package/latticeai/services/architecture_readiness.py +48 -19
- package/latticeai/services/automation_intelligence.py +22 -2
- package/latticeai/services/brain_intelligence/__init__.py +58 -0
- package/latticeai/services/brain_intelligence/_contract.py +71 -0
- package/latticeai/services/brain_intelligence/consistency.py +193 -0
- package/latticeai/services/brain_intelligence/constants.py +47 -0
- package/latticeai/services/brain_intelligence/digest.py +258 -0
- package/latticeai/services/brain_intelligence/health.py +331 -0
- package/latticeai/services/brain_intelligence/proposals.py +264 -0
- package/latticeai/services/brain_intelligence/sampling.py +84 -0
- package/latticeai/services/brain_intelligence/service.py +48 -0
- package/latticeai/services/chronicle.py +557 -0
- package/latticeai/services/command_center.py +10 -4
- package/latticeai/services/feature_toggles.py +502 -0
- package/latticeai/services/folder_watch.py +122 -1
- package/latticeai/services/hybrid_chat.py +56 -5
- package/latticeai/services/interop_bridges.py +978 -0
- package/latticeai/services/memory_service/__init__.py +52 -0
- package/latticeai/services/memory_service/_contract.py +100 -0
- package/latticeai/services/memory_service/brief.py +431 -0
- package/latticeai/services/memory_service/constants.py +57 -0
- package/latticeai/services/memory_service/maintenance.py +138 -0
- package/latticeai/services/memory_service/manager.py +186 -0
- package/latticeai/services/memory_service/proof.py +136 -0
- package/latticeai/services/memory_service/recall.py +225 -0
- package/latticeai/services/memory_service/service.py +48 -0
- package/latticeai/services/memory_service/stores.py +110 -0
- package/latticeai/services/model_capability_registry.py +434 -261
- package/latticeai/services/model_catalog.py +95 -61
- package/latticeai/services/model_recommendation.py +18 -11
- package/latticeai/services/model_runtime/__init__.py +322 -0
- package/latticeai/services/model_runtime/cloud.py +87 -0
- package/latticeai/services/model_runtime/download.py +282 -0
- package/latticeai/services/model_runtime/engines.py +341 -0
- package/latticeai/services/model_runtime/loading.py +178 -0
- package/latticeai/services/model_runtime/service.py +129 -0
- package/latticeai/services/model_runtime/state.py +131 -0
- package/latticeai/services/model_runtime/status.py +255 -0
- package/latticeai/services/multimodal_ports.py +26 -1
- package/latticeai/services/obsidian_bridge.py +16 -25
- package/latticeai/services/product_readiness.py +15 -7
- package/latticeai/services/search_service.py +149 -2
- package/latticeai/services/tool_dispatch.py +4 -0
- package/latticeai/setup/auto_setup.py +27 -30
- package/latticeai/setup/wizard/__init__.py +126 -0
- package/latticeai/setup/wizard/catalog.py +172 -0
- package/latticeai/setup/wizard/detect.py +323 -0
- package/latticeai/setup/wizard/install.py +348 -0
- package/latticeai/setup/wizard/paths.py +168 -0
- package/latticeai/setup/wizard/plans.py +74 -0
- package/latticeai/setup/wizard/recommend.py +320 -0
- package/package.json +6 -2
- package/scripts/bump_version.py +14 -0
- package/scripts/capture_release_evidence.mjs +33 -21
- package/scripts/check_current_release_docs.mjs +1 -1
- package/scripts/check_i18n_namespace_coverage.mjs +41 -4
- package/scripts/check_max_file_lines.mjs +102 -0
- package/scripts/check_release_evidence_bound.mjs +30 -15
- package/scripts/check_screenshot_pixel_delta.py +34 -4
- package/scripts/check_server_i18n.mjs +2 -0
- package/scripts/generate_rust_parity_fixtures.py +562 -0
- package/scripts/lib/mock_server_fingerprint.mjs +94 -0
- package/scripts/release_screen_claims.json +44 -2
- package/scripts/verify_hf_model_registry.py +253 -218
- package/src-tauri/Cargo.lock +361 -3
- package/src-tauri/Cargo.toml +6 -1
- package/src-tauri/src/backend.rs +349 -0
- package/src-tauri/src/folder.rs +33 -0
- package/src-tauri/src/main.rs +97 -399
- package/src-tauri/tauri.conf.json +1 -1
- package/static/app/asset-manifest.json +41 -37
- package/static/app/assets/Act-yYpYnn0v.js +1 -0
- package/static/app/assets/AdminConsole-DL3Cr5pL.js +1 -0
- package/static/app/assets/{Brain-CzCsI1mi.js → Brain-C1HBN0Wf.js} +2 -2
- package/static/app/assets/BrainHome-DoXRhUUC.js +2 -0
- package/static/app/assets/BrainSignals-6yR6ir5t.js +1 -0
- package/static/app/assets/Capture-CFIRsFNE.js +1 -0
- package/static/app/assets/Chronicle-BZbEgiwN.js +1 -0
- package/static/app/assets/CommandPalette-D2pMxC2I.js +1 -0
- package/static/app/assets/Library-DwO3yZST.js +1 -0
- package/static/app/assets/{LivingBrain-BXMWIK_2.js → LivingBrain-Jn1GK0-S.js} +1 -1
- package/static/app/assets/ProductFlow-B-w1R4Oo.js +1 -0
- package/static/app/assets/ReviewCard-6B27X8Vg.js +3 -0
- package/static/app/assets/System-DW8F-2xL.js +1 -0
- package/static/app/assets/arrow-left-DXvKg9U6.js +1 -0
- package/static/app/assets/{bot-4BvN07ux.js → bot-IM_E_Y12.js} +1 -1
- package/static/app/assets/brain-Ci1CkWjM.js +1 -0
- package/static/app/assets/{button-CDjtnAoU.js → button-COwyqfHM.js} +1 -1
- package/static/app/assets/circle-check-DfInj-qD.js +1 -0
- package/static/app/assets/{circle-pause-D_RMn7tp.js → circle-pause-DEM4A1Y5.js} +1 -1
- package/static/app/assets/{circle-play-B5OpB8ae.js → circle-play-C9djDuLd.js} +1 -1
- package/static/app/assets/{cpu-BIlWInHf.js → cpu-DFdo1gw-.js} +1 -1
- package/static/app/assets/{download-BtjXfL3z.js → download-SnJL6oqk.js} +1 -1
- package/static/app/assets/{folder-open-DefMpxI2.js → folder-open-CqZeDkjE.js} +1 -1
- package/static/app/assets/{hard-drive-BQ8NZVkw.js → hard-drive-j1jJXYYf.js} +1 -1
- package/static/app/assets/{index-vtEfYvQY.css → index-BLPb5lmE.css} +1 -1
- package/static/app/assets/index-_u5iUHDr.js +10 -0
- package/static/app/assets/input-B0lPdRQZ.js +1 -0
- package/static/app/assets/link-2-CoFbooHS.js +1 -0
- package/static/app/assets/{permissionCopy-BqZ5tsgL.js → permissionCopy-BsyLxtao.js} +1 -1
- package/static/app/assets/primitives-DEbN-d6p.js +1 -0
- package/static/app/assets/search-BybIWPNd.js +1 -0
- package/static/app/assets/{share-2-D5zg_0fY.js → share-2-CVtZ_ewX.js} +1 -1
- package/static/app/assets/{shield-alert-B5pZzkUb.js → shield-alert-CBi2GNWM.js} +1 -1
- package/static/app/assets/{textarea-nEVIweKY.js → textarea-DNMpB5ih.js} +1 -1
- package/static/app/assets/{useFocusTrap-Cm99AHlz.js → useFocusTrap-C83t3GXF.js} +1 -1
- package/static/app/assets/useMutation-DtbJDoyz.js +1 -0
- package/static/app/assets/{useQuery-Dm__N6bL.js → useQuery-Dcp1OChy.js} +1 -1
- package/static/app/assets/utils-BlZr7Pd4.js +4 -0
- package/static/app/assets/workspace-jJY4RuAV.js +1 -0
- package/static/app/index.html +4 -4
- package/static/sw.js +1 -1
- package/lattice_brain/graph/_kg_common.py +0 -1331
- package/lattice_brain/graph/discovery_index.py +0 -1141
- package/lattice_brain/graph/retrieval.py +0 -1120
- package/lattice_brain/graph/retrieval_vector.py +0 -1293
- package/lattice_brain/ingestion.py +0 -1377
- package/lattice_brain/portability.py +0 -1210
- package/latticeai/core/agent.py +0 -1412
- package/latticeai/core/embedding_providers.py +0 -1196
- package/latticeai/core/file_generation.py +0 -1047
- package/latticeai/integrations/telegram_bot.py +0 -1390
- package/latticeai/models/router.py +0 -1007
- package/latticeai/runtime/build_phases.py +0 -1422
- package/latticeai/services/brain_intelligence.py +0 -967
- package/latticeai/services/memory_service.py +0 -1177
- package/latticeai/services/model_runtime.py +0 -1281
- package/latticeai/setup/wizard.py +0 -1277
- package/static/app/assets/Act-D0HWqtn0.js +0 -1
- package/static/app/assets/AdminConsole-D-QDW-A4.js +0 -1
- package/static/app/assets/BrainHome-Btns-_TA.js +0 -2
- package/static/app/assets/BrainSignals-2dHQNkns.js +0 -1
- package/static/app/assets/Capture-CT8v1StE.js +0 -1
- package/static/app/assets/CommandPalette-DoLXC2KH.js +0 -1
- package/static/app/assets/Library-DDoxFE5c.js +0 -1
- package/static/app/assets/ProductFlow-DOYf7JIs.js +0 -1
- package/static/app/assets/ReviewCard-COQsqidK.js +0 -3
- package/static/app/assets/System-BRllvYXd.js +0 -1
- package/static/app/assets/arrow-left-DnyMzss-.js +0 -1
- package/static/app/assets/brain-uMb_5hnO.js +0 -1
- package/static/app/assets/index-0AvoEBzJ.js +0 -10
- package/static/app/assets/input-B_5ZJ9oy.js +0 -1
- package/static/app/assets/primitives-CVwew78r.js +0 -1
- package/static/app/assets/search-DkhnOKZt.js +0 -1
- package/static/app/assets/utils-DcDMoZIe.js +0 -4
- package/static/app/assets/workspace-LtRRSKTf.js +0 -1
|
@@ -60,12 +60,36 @@ class FolderWatchEnableRequest(BaseModel):
|
|
|
60
60
|
path: str
|
|
61
61
|
recursive: bool = True
|
|
62
62
|
workspace_id: Optional[str] = None
|
|
63
|
+
#: ``folder`` (default, unchanged) or ``vault`` — a watched external
|
|
64
|
+
#: Obsidian vault, which re-runs the whole bridge sync when it changes and
|
|
65
|
+
#: carries its own opt-in gate on top of this approval.
|
|
66
|
+
kind: str = "folder"
|
|
63
67
|
# Watching continuously reads local disk → same approval dance as
|
|
64
68
|
# /api/ingestion/folder. This is the explicit opt-in the review requires.
|
|
65
69
|
approved: bool = False
|
|
66
70
|
approval_token: Optional[str] = None
|
|
67
71
|
|
|
68
72
|
|
|
73
|
+
class InteropIngestRequest(BaseModel):
|
|
74
|
+
"""Read one local interop source through the one ingestion gate (v11.2.0).
|
|
75
|
+
|
|
76
|
+
``source`` picks the bridge — ``notion`` (an export directory or ``.zip``),
|
|
77
|
+
``git`` (a local repository), ``mail`` (``.eml``/``.ics`` files or a folder
|
|
78
|
+
of them). Every one of them reads a path the user approves through the same
|
|
79
|
+
local-read dance as ``/api/ingestion/folder``, and ``dry_run`` reports what
|
|
80
|
+
a real run would touch without writing anything.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
source: str
|
|
84
|
+
path: str
|
|
85
|
+
workspace_id: Optional[str] = None
|
|
86
|
+
dry_run: bool = False
|
|
87
|
+
#: Git only: how far back to read. Ignored by the other bridges.
|
|
88
|
+
max_commits: Optional[int] = None
|
|
89
|
+
approved: bool = False
|
|
90
|
+
approval_token: Optional[str] = None
|
|
91
|
+
|
|
92
|
+
|
|
69
93
|
class ObsidianSyncRequest(BaseModel):
|
|
70
94
|
"""One-shot sync of an *external* Obsidian vault (v11.1.0).
|
|
71
95
|
|
|
@@ -107,10 +131,18 @@ def create_local_files_router(
|
|
|
107
131
|
if folder_watch is None and ingestion_pipeline is not None and data_dir is not None:
|
|
108
132
|
try:
|
|
109
133
|
from latticeai.services.folder_watch import FolderWatchService
|
|
134
|
+
from latticeai.services.obsidian_bridge import ObsidianVaultBridge
|
|
110
135
|
|
|
111
136
|
folder_watch = FolderWatchService(
|
|
112
137
|
pipeline=ingestion_pipeline,
|
|
113
138
|
config_path=Path(data_dir) / "folder_watch.json",
|
|
139
|
+
# A watched vault re-runs the *whole* bridge sync, which is what
|
|
140
|
+
# makes its link edges real; the bridge is handed in rather than
|
|
141
|
+
# imported inside the poller so the watch service keeps knowing
|
|
142
|
+
# nothing about how a vault is parsed.
|
|
143
|
+
vault_bridge=ObsidianVaultBridge(
|
|
144
|
+
pipeline=ingestion_pipeline, knowledge_graph=knowledge_graph,
|
|
145
|
+
),
|
|
114
146
|
)
|
|
115
147
|
folder_watch.restore()
|
|
116
148
|
except Exception: # noqa: BLE001 — watch mode is optional, never blocks routes
|
|
@@ -405,6 +437,66 @@ def create_local_files_router(
|
|
|
405
437
|
dry_run=req.dry_run,
|
|
406
438
|
)
|
|
407
439
|
|
|
440
|
+
# ── interop bridges: Notion export / git history / mail + calendar ───────
|
|
441
|
+
@router.get("/api/ingestion/interop")
|
|
442
|
+
async def interop_status(request: Request):
|
|
443
|
+
"""Which interop bridges this machine can actually run, and why not."""
|
|
444
|
+
require_user(request)
|
|
445
|
+
from latticeai.services.interop_bridges import bridge_status
|
|
446
|
+
|
|
447
|
+
return bridge_status()
|
|
448
|
+
|
|
449
|
+
@router.post("/api/ingestion/interop")
|
|
450
|
+
async def interop_ingest(req: InteropIngestRequest, request: Request):
|
|
451
|
+
"""Read an approved local interop source through the one gate.
|
|
452
|
+
|
|
453
|
+
Same approval dance and the same ``IngestionPipeline`` door as the
|
|
454
|
+
vault bridge: no vendor API, no credentials, nothing leaves the
|
|
455
|
+
machine. ``dry_run`` writes nothing and reports what a real run would.
|
|
456
|
+
"""
|
|
457
|
+
current_user = permission_gateway.require_local_user(request)
|
|
458
|
+
_require_pipeline()
|
|
459
|
+
workspace_id = _ingestion_write_workspace(request, req.workspace_id, current_user)
|
|
460
|
+
path = (req.path or "").strip()
|
|
461
|
+
if not path:
|
|
462
|
+
raise http_error(400, "ingestion.interop_path_required", resolve_language(request))
|
|
463
|
+
from latticeai.services.interop_bridges import build_bridge
|
|
464
|
+
|
|
465
|
+
try:
|
|
466
|
+
bridge = build_bridge(
|
|
467
|
+
req.source, pipeline=ingestion_pipeline, knowledge_graph=knowledge_graph,
|
|
468
|
+
)
|
|
469
|
+
except ValueError:
|
|
470
|
+
raise http_error(
|
|
471
|
+
400,
|
|
472
|
+
"ingestion.interop_unknown_source",
|
|
473
|
+
resolve_language(request),
|
|
474
|
+
source=req.source,
|
|
475
|
+
)
|
|
476
|
+
if not req.approved:
|
|
477
|
+
return permission_gateway.local_permission_response(path, "read", current_user)
|
|
478
|
+
permission_gateway.require_local_approval(
|
|
479
|
+
token=req.approval_token,
|
|
480
|
+
path=path,
|
|
481
|
+
action="read",
|
|
482
|
+
user_email=current_user,
|
|
483
|
+
)
|
|
484
|
+
options: Dict[str, Any] = {}
|
|
485
|
+
if req.max_commits is not None:
|
|
486
|
+
options["max_commits"] = req.max_commits
|
|
487
|
+
# Walking an export and embedding its pages is blocking work; the server
|
|
488
|
+
# owns one event loop and it may not sit here (10.9.0 ASYNC gate).
|
|
489
|
+
return await asyncio.to_thread(
|
|
490
|
+
lambda: bridge.sync(
|
|
491
|
+
path,
|
|
492
|
+
owner=current_user or None,
|
|
493
|
+
workspace_id=workspace_id,
|
|
494
|
+
user_email=current_user or None,
|
|
495
|
+
dry_run=req.dry_run,
|
|
496
|
+
**options,
|
|
497
|
+
)
|
|
498
|
+
)
|
|
499
|
+
|
|
408
500
|
# ── folder watch mode: opt-in, off by default (backlog #8) ────────────────
|
|
409
501
|
def _require_folder_watch(request: Request):
|
|
410
502
|
_require_pipeline()
|
|
@@ -446,7 +538,16 @@ def create_local_files_router(
|
|
|
446
538
|
owner=current_user or None,
|
|
447
539
|
workspace_id=workspace_id,
|
|
448
540
|
recursive=req.recursive,
|
|
541
|
+
kind=req.kind,
|
|
449
542
|
)
|
|
543
|
+
if result.get("status") == "disabled":
|
|
544
|
+
# Turned off rather than broken: 403 with the reason, the same shape
|
|
545
|
+
# every other opt-in gate in this product answers with.
|
|
546
|
+
raise HTTPException(
|
|
547
|
+
status_code=403,
|
|
548
|
+
detail=result.get("detail")
|
|
549
|
+
or translate("ingestion.vault_watch_disabled", resolve_language(request)),
|
|
550
|
+
)
|
|
450
551
|
if result.get("status") != "ok":
|
|
451
552
|
raise HTTPException(
|
|
452
553
|
status_code=400,
|
|
@@ -518,6 +619,7 @@ def create_local_files_router(
|
|
|
518
619
|
__all__ = [
|
|
519
620
|
"FolderIngestRequest",
|
|
520
621
|
"FolderWatchEnableRequest",
|
|
622
|
+
"InteropIngestRequest",
|
|
521
623
|
"LocalAccessRequest",
|
|
522
624
|
"LocalWriteRequest",
|
|
523
625
|
"ObsidianSyncRequest",
|
|
@@ -87,8 +87,16 @@ class SubgraphSelection(BaseModel):
|
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
class SubgraphArchiveRequest(SubgraphSelection):
|
|
90
|
+
"""Exactly one recipient mechanism — a passphrase, or a public key.
|
|
91
|
+
|
|
92
|
+
Both optional at the schema level and validated in the service, so the
|
|
93
|
+
error a caller gets names the rule ("choose one") instead of a field.
|
|
94
|
+
"""
|
|
95
|
+
|
|
90
96
|
path: Optional[str] = None
|
|
91
|
-
passphrase: str
|
|
97
|
+
passphrase: Optional[str] = None
|
|
98
|
+
#: The recipient's X25519 public key, from their ``/share/recipient-key``.
|
|
99
|
+
recipient_public_key: Optional[str] = None
|
|
92
100
|
|
|
93
101
|
|
|
94
102
|
class SubgraphImportRequest(BaseModel):
|
|
@@ -269,6 +277,22 @@ def create_portability_router(
|
|
|
269
277
|
except (ValueError, RuntimeError) as exc:
|
|
270
278
|
raise HTTPException(status_code=400, detail=str(exc))
|
|
271
279
|
|
|
280
|
+
@router.get("/api/knowledge-graph/share/recipient-key")
|
|
281
|
+
async def share_recipient_key(request: Request):
|
|
282
|
+
"""This Brain's X25519 receiving key, for a sender to seal a bundle to.
|
|
283
|
+
|
|
284
|
+
Public by construction — a public key encrypts, it does not decrypt —
|
|
285
|
+
so handing it out is the whole point. Still admin-gated and still
|
|
286
|
+
behind the share flag, because minting the key is a decision to
|
|
287
|
+
participate in sharing at all.
|
|
288
|
+
"""
|
|
289
|
+
require_admin(request)
|
|
290
|
+
_require_service(request)
|
|
291
|
+
try:
|
|
292
|
+
return service.recipient_key()
|
|
293
|
+
except PermissionError:
|
|
294
|
+
raise http_error(403, "portability.brain_network_disabled", resolve_language(request))
|
|
295
|
+
|
|
272
296
|
@router.post("/api/knowledge-graph/share/archive")
|
|
273
297
|
async def share_archive(req: SubgraphArchiveRequest, request: Request):
|
|
274
298
|
"""Same bundle, written as an encrypted ``.latticebrain`` file."""
|
|
@@ -277,8 +301,14 @@ def create_portability_router(
|
|
|
277
301
|
body = req.model_dump()
|
|
278
302
|
path = body.pop("path")
|
|
279
303
|
passphrase = body.pop("passphrase")
|
|
304
|
+
recipient_public_key = body.pop("recipient_public_key")
|
|
280
305
|
try:
|
|
281
|
-
return service.export_subgraph_archive(
|
|
306
|
+
return service.export_subgraph_archive(
|
|
307
|
+
path,
|
|
308
|
+
passphrase=passphrase,
|
|
309
|
+
recipient_public_key=recipient_public_key,
|
|
310
|
+
**body,
|
|
311
|
+
)
|
|
282
312
|
except PermissionError:
|
|
283
313
|
raise http_error(403, "portability.brain_network_disabled", resolve_language(request))
|
|
284
314
|
except (ValueError, RuntimeError) as exc:
|
|
@@ -294,8 +324,13 @@ def create_portability_router(
|
|
|
294
324
|
try:
|
|
295
325
|
artifact = req.artifact
|
|
296
326
|
if artifact is None:
|
|
297
|
-
if not req.path
|
|
298
|
-
raise ValueError(
|
|
327
|
+
if not req.path:
|
|
328
|
+
raise ValueError(
|
|
329
|
+
"Provide an artifact, or the path of a bundle on disk."
|
|
330
|
+
)
|
|
331
|
+
# A sealed bundle needs no passphrase — the envelope says which
|
|
332
|
+
# mechanism it used and the service refuses if the wrong one is
|
|
333
|
+
# supplied, so the route does not have to guess here.
|
|
299
334
|
artifact = service.read_subgraph_archive(req.path, passphrase=req.passphrase)
|
|
300
335
|
return service.import_subgraph_proposals(
|
|
301
336
|
artifact,
|
|
@@ -70,6 +70,39 @@ class ReviewCounts(BaseModel):
|
|
|
70
70
|
pending_by_source: Dict[str, int] = Field(default_factory=dict)
|
|
71
71
|
|
|
72
72
|
|
|
73
|
+
class BulkActionRequest(BaseModel):
|
|
74
|
+
"""Decide several review items at once, named explicitly.
|
|
75
|
+
|
|
76
|
+
``ids`` is required and never defaults to "everything pending": a bulk
|
|
77
|
+
action whose scope is implicit is how an inbox gets emptied by accident.
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
ids: List[str] = Field(default_factory=list)
|
|
81
|
+
reason: str = ""
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class BulkActionOutcome(BaseModel):
|
|
85
|
+
"""Per-item verdict, so a partial success is legible rather than a total."""
|
|
86
|
+
|
|
87
|
+
id: str
|
|
88
|
+
status: str # ok | not_found | conflict | failed
|
|
89
|
+
item_status: Optional[str] = None
|
|
90
|
+
detail: Optional[str] = None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class BulkActionResult(BaseModel):
|
|
94
|
+
action: str
|
|
95
|
+
requested: int
|
|
96
|
+
succeeded: int
|
|
97
|
+
failed: int
|
|
98
|
+
results: List[BulkActionOutcome] = Field(default_factory=list)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
#: Ceiling on one bulk call. Large enough for "clear today's inbox", small
|
|
102
|
+
#: enough that one request cannot walk the whole table inside a web worker.
|
|
103
|
+
BULK_ACTION_CAP = 200
|
|
104
|
+
|
|
105
|
+
|
|
73
106
|
def create_review_queue_router(
|
|
74
107
|
*,
|
|
75
108
|
service: ReviewQueueService,
|
|
@@ -123,6 +156,19 @@ def create_review_queue_router(
|
|
|
123
156
|
scope = gate_read(request)
|
|
124
157
|
return service.counts(workspace_id=scope, user_email=user)
|
|
125
158
|
|
|
159
|
+
# NOTE: declared *before* /automation/reviews/{item_id} for the same reason
|
|
160
|
+
# "counts" is — routes match in declaration order, so a later /bulk/... would
|
|
161
|
+
# be swallowed by the {item_id} matcher and answer 404 for a missing item.
|
|
162
|
+
@router.post("/automation/reviews/bulk/approve", response_model=BulkActionResult)
|
|
163
|
+
async def bulk_approve(req: BulkActionRequest, request: Request):
|
|
164
|
+
"""Approve several items, reporting each one's outcome individually."""
|
|
165
|
+
return _bulk(request, req, "approve")
|
|
166
|
+
|
|
167
|
+
@router.post("/automation/reviews/bulk/dismiss", response_model=BulkActionResult)
|
|
168
|
+
async def bulk_dismiss(req: BulkActionRequest, request: Request):
|
|
169
|
+
"""Dismiss several items, reporting each one's outcome individually."""
|
|
170
|
+
return _bulk(request, req, "dismiss")
|
|
171
|
+
|
|
126
172
|
@router.get("/automation/reviews/{item_id}", response_model=ReviewItem)
|
|
127
173
|
async def get_item(item_id: str, request: Request):
|
|
128
174
|
require_user(request)
|
|
@@ -205,6 +251,86 @@ def create_review_queue_router(
|
|
|
205
251
|
async def unsnooze_item(item_id: str, request: Request):
|
|
206
252
|
return _act(request, item_id, "unsnooze")
|
|
207
253
|
|
|
254
|
+
def _bulk(request: Request, req: BulkActionRequest, action: str) -> Dict[str, Any]:
|
|
255
|
+
"""One transition applied N times through the *same* single-item guard.
|
|
256
|
+
|
|
257
|
+
Deliberately not a bulk UPDATE. Every id goes through the ordinary
|
|
258
|
+
service call, so an already-approved item still 409s, a
|
|
259
|
+
``change_proposal`` still applies its staged content, and the audit
|
|
260
|
+
trail records N decisions — because that is what happened. A failure
|
|
261
|
+
on one id never aborts the rest, and the response says exactly which
|
|
262
|
+
ones did not land instead of returning a single number the caller has
|
|
263
|
+
to interpret.
|
|
264
|
+
"""
|
|
265
|
+
user = require_user(request)
|
|
266
|
+
scope = gate_write(request)
|
|
267
|
+
language = resolve_language(request)
|
|
268
|
+
wanted = [str(item).strip() for item in req.ids if str(item).strip()]
|
|
269
|
+
if not wanted:
|
|
270
|
+
raise http_error(422, "review.bulk_ids_required", language)
|
|
271
|
+
if len(wanted) > BULK_ACTION_CAP:
|
|
272
|
+
raise http_error(422, "review.bulk_too_many", language, cap=BULK_ACTION_CAP)
|
|
273
|
+
results: List[Dict[str, Any]] = []
|
|
274
|
+
succeeded = 0
|
|
275
|
+
for item_id in wanted:
|
|
276
|
+
outcome = _bulk_one(request, item_id, action, user=user, scope=scope, reason=req.reason)
|
|
277
|
+
if outcome["status"] == "ok":
|
|
278
|
+
succeeded += 1
|
|
279
|
+
results.append(outcome)
|
|
280
|
+
return {
|
|
281
|
+
"action": action,
|
|
282
|
+
"requested": len(wanted),
|
|
283
|
+
"succeeded": succeeded,
|
|
284
|
+
"failed": len(wanted) - succeeded,
|
|
285
|
+
"results": results,
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
def _bulk_one(
|
|
289
|
+
request: Request,
|
|
290
|
+
item_id: str,
|
|
291
|
+
action: str,
|
|
292
|
+
*,
|
|
293
|
+
user: str,
|
|
294
|
+
scope: Optional[str],
|
|
295
|
+
reason: str,
|
|
296
|
+
) -> Dict[str, Any]:
|
|
297
|
+
try:
|
|
298
|
+
if action == "dismiss":
|
|
299
|
+
item = service.dismiss(item_id, workspace_id=scope, reason=reason or None)
|
|
300
|
+
else:
|
|
301
|
+
item = _approve_one(request, item_id, user=user, scope=scope)
|
|
302
|
+
except (FileNotFoundError, KeyError):
|
|
303
|
+
return {"id": item_id, "status": "not_found", "detail": None}
|
|
304
|
+
except InvalidReviewTransition as exc:
|
|
305
|
+
return {"id": item_id, "status": "conflict", "detail": str(exc)}
|
|
306
|
+
except ProposalConflictError as exc:
|
|
307
|
+
return {"id": item_id, "status": "conflict", "detail": str(exc)}
|
|
308
|
+
except HTTPException as exc:
|
|
309
|
+
return {
|
|
310
|
+
"id": item_id,
|
|
311
|
+
"status": "conflict" if exc.status_code == 409 else "failed",
|
|
312
|
+
"detail": str(exc.detail),
|
|
313
|
+
}
|
|
314
|
+
except ValueError as exc:
|
|
315
|
+
return {"id": item_id, "status": "failed", "detail": str(exc)}
|
|
316
|
+
append_audit_event(f"review_item_{action}", user_email=user, item_id=item_id)
|
|
317
|
+
return {"id": item_id, "status": "ok", "item_status": item.get("status"), "detail": None}
|
|
318
|
+
|
|
319
|
+
def _approve_one(
|
|
320
|
+
request: Request, item_id: str, *, user: str, scope: Optional[str]
|
|
321
|
+
) -> Dict[str, Any]:
|
|
322
|
+
"""Approve exactly the way the single-item route does, staged content included."""
|
|
323
|
+
if change_proposals is not None:
|
|
324
|
+
stored = service.get(item_id, workspace_id=scope)
|
|
325
|
+
if stored.get("source") == "change_proposal":
|
|
326
|
+
if stored.get("effective_status") not in ("pending", "snoozed"):
|
|
327
|
+
raise InvalidReviewTransition("approve", str(stored.get("status")))
|
|
328
|
+
applied = change_proposals.approve_and_apply(
|
|
329
|
+
item_id, user_email=user, workspace_id=scope
|
|
330
|
+
)
|
|
331
|
+
return dict(applied["item"])
|
|
332
|
+
return service.approve(item_id, workspace_id=scope)
|
|
333
|
+
|
|
208
334
|
@router.post("/automation/reviews/{item_id}/run_now", response_model=ReviewItem)
|
|
209
335
|
async def run_now_item(item_id: str, request: Request):
|
|
210
336
|
user = require_user(request)
|
package/latticeai/api/search.py
CHANGED
|
@@ -25,6 +25,11 @@ class HybridSearchRequest(SearchRequest):
|
|
|
25
25
|
vector_limit: int = 30
|
|
26
26
|
graph_limit: int = 30
|
|
27
27
|
weights: Optional[Dict[str, float]] = None
|
|
28
|
+
#: Opt in to scoring this text query against the *image* index too
|
|
29
|
+
#: (v11.2.0). Only possible when a shared-space vision model is
|
|
30
|
+
#: configured; when it is not, the response says so instead of quietly
|
|
31
|
+
#: returning the text-only ranking as if fusion had happened.
|
|
32
|
+
image_fusion: bool = False
|
|
28
33
|
|
|
29
34
|
|
|
30
35
|
class GraphNodeRequest(BaseModel):
|
|
@@ -106,17 +111,26 @@ def create_search_router(
|
|
|
106
111
|
vector_limit=req.vector_limit,
|
|
107
112
|
graph_limit=req.graph_limit,
|
|
108
113
|
weights=req.weights or DEFAULT_HYBRID_WEIGHTS,
|
|
114
|
+
image_fusion=req.image_fusion,
|
|
109
115
|
)
|
|
110
116
|
except ValueError as exc:
|
|
111
117
|
_raise_graph_error(exc)
|
|
112
118
|
|
|
113
119
|
@router.get("/api/search/hybrid")
|
|
114
|
-
async def hybrid_search_get(
|
|
120
|
+
async def hybrid_search_get(
|
|
121
|
+
q: str, request: Request, limit: int = 30, image_fusion: bool = False,
|
|
122
|
+
) -> Dict[str, Any]:
|
|
115
123
|
try:
|
|
116
|
-
return _guarded(request).hybrid_search(q, limit=limit)
|
|
124
|
+
return _guarded(request).hybrid_search(q, limit=limit, image_fusion=image_fusion)
|
|
117
125
|
except ValueError as exc:
|
|
118
126
|
_raise_graph_error(exc)
|
|
119
127
|
|
|
128
|
+
@router.get("/api/search/image-query")
|
|
129
|
+
async def image_query_status(request: Request) -> Dict[str, Any]:
|
|
130
|
+
"""Whether a typed question can reach the image index on this install."""
|
|
131
|
+
require_user(request)
|
|
132
|
+
return service.image_query_status()
|
|
133
|
+
|
|
120
134
|
@router.post("/api/search/keyword")
|
|
121
135
|
async def keyword_search(req: SearchRequest, request: Request) -> Dict[str, Any]:
|
|
122
136
|
try:
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Single-agent runtime — the Discover→Plan→Implement→Verify state machine.
|
|
2
|
+
|
|
3
|
+
This package is the deep single-agent loop: a small interface (``AgentDeps``
|
|
4
|
+
ports + ``SingleAgentRuntime.run_to_completion``) over the whole role-phased
|
|
5
|
+
state machine (planner → executor → critic → rollback → memory). It carries no
|
|
6
|
+
FastAPI, no globals, and no I/O of its own — every collaborator is injected
|
|
7
|
+
through ``AgentDeps``.
|
|
8
|
+
|
|
9
|
+
Two adapters justify the seam:
|
|
10
|
+
|
|
11
|
+
* production wires ``AgentDeps`` from ``latticeai.server_app``'s ``LLMRouter``, governance
|
|
12
|
+
map, audit log, and prompts;
|
|
13
|
+
* tests pass fake ports (an LLM that returns canned JSON, a recording tool
|
|
14
|
+
executor) and drive a full PLAN→EXECUTE→VERIFY→DONE cycle without a server.
|
|
15
|
+
|
|
16
|
+
HTTP concerns — request parsing, chat-history persistence, response shaping,
|
|
17
|
+
scheduling the background memory update — stay in the app layer. This package
|
|
18
|
+
only owns the state machine.
|
|
19
|
+
|
|
20
|
+
v10.0.1 split the pure helpers and the state vocabulary out to sibling modules
|
|
21
|
+
(``agent_state``, ``agent_helpers``, ``agent_trace``, …). v11.3.0 finished the
|
|
22
|
+
job on what was left, turning the module into a package whose submodules are
|
|
23
|
+
one phase each:
|
|
24
|
+
|
|
25
|
+
* :mod:`.context` — ``AgentRunContext``, the state one run carries;
|
|
26
|
+
* :mod:`.deps` — ``AgentDeps``, the ports;
|
|
27
|
+
* :mod:`.planning` / :mod:`.execution` / :mod:`.verification` / :mod:`.recovery`
|
|
28
|
+
— the four phase mixins;
|
|
29
|
+
* :mod:`.runtime` — ``SingleAgentRuntime``, which composes them and drives the
|
|
30
|
+
loop;
|
|
31
|
+
* :mod:`._contract` — the typing-only seam the mixins share.
|
|
32
|
+
|
|
33
|
+
Every name this module exported still resolves from ``latticeai.core.agent``.
|
|
34
|
+
|
|
35
|
+
Stubbing note: a name rebound *here* changes only this module's binding — the
|
|
36
|
+
submodule that calls it holds its own, so a test standing in for a collaborator
|
|
37
|
+
patches the submodule that reads it.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
from __future__ import annotations
|
|
41
|
+
|
|
42
|
+
# The state vocabulary and the pure helpers live in sibling modules so the loop
|
|
43
|
+
# holds only the loop. They are re-exported (see ``__all__``) because callers —
|
|
44
|
+
# the HTTP layer, run_store, the eval harness, and the tests — have always
|
|
45
|
+
# imported them from here, and that contract does not change.
|
|
46
|
+
from latticeai.core.agent_helpers import PhaseBudgets as PhaseBudgets
|
|
47
|
+
from latticeai.core.agent_helpers import TranscriptBudget as TranscriptBudget
|
|
48
|
+
from latticeai.core.agent_helpers import _truncate_strings as _truncate_strings
|
|
49
|
+
from latticeai.core.agent_helpers import artifact_checklist as artifact_checklist
|
|
50
|
+
from latticeai.core.agent_helpers import compact_transcript as compact_transcript
|
|
51
|
+
from latticeai.core.agent_helpers import extract_action as extract_action
|
|
52
|
+
from latticeai.core.agent_helpers import (
|
|
53
|
+
extract_action_details as extract_action_details,
|
|
54
|
+
)
|
|
55
|
+
from latticeai.core.agent_helpers import files_written as files_written
|
|
56
|
+
from latticeai.core.agent_helpers import filter_learnings as filter_learnings
|
|
57
|
+
from latticeai.core.agent_helpers import (
|
|
58
|
+
format_artifact_checklist as format_artifact_checklist,
|
|
59
|
+
)
|
|
60
|
+
from latticeai.core.agent_helpers import (
|
|
61
|
+
format_requirement_coverage as format_requirement_coverage,
|
|
62
|
+
)
|
|
63
|
+
from latticeai.core.agent_helpers import normalize_plan as normalize_plan
|
|
64
|
+
from latticeai.core.agent_helpers import requirement_coverage as requirement_coverage
|
|
65
|
+
from latticeai.core.agent_state import AGENT_TERMINAL_STATES as AGENT_TERMINAL_STATES
|
|
66
|
+
from latticeai.core.agent_state import AgentState as AgentState
|
|
67
|
+
|
|
68
|
+
from .context import AgentRunContext as AgentRunContext
|
|
69
|
+
from .deps import AgentDeps as AgentDeps
|
|
70
|
+
from .runtime import SingleAgentRuntime as SingleAgentRuntime
|
|
71
|
+
|
|
72
|
+
__all__ = [
|
|
73
|
+
# this module
|
|
74
|
+
"AgentDeps",
|
|
75
|
+
"AgentRunContext",
|
|
76
|
+
"SingleAgentRuntime",
|
|
77
|
+
# re-exported from agent_state
|
|
78
|
+
"AGENT_TERMINAL_STATES",
|
|
79
|
+
"AgentState",
|
|
80
|
+
# re-exported from agent_helpers
|
|
81
|
+
"PhaseBudgets",
|
|
82
|
+
"TranscriptBudget",
|
|
83
|
+
"artifact_checklist",
|
|
84
|
+
"compact_transcript",
|
|
85
|
+
"extract_action",
|
|
86
|
+
"extract_action_details",
|
|
87
|
+
"files_written",
|
|
88
|
+
"filter_learnings",
|
|
89
|
+
"format_artifact_checklist",
|
|
90
|
+
"format_requirement_coverage",
|
|
91
|
+
"normalize_plan",
|
|
92
|
+
"requirement_coverage",
|
|
93
|
+
]
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""The seam the four phase mixins share.
|
|
2
|
+
|
|
3
|
+
``SingleAgentRuntime`` is assembled from the planning, execution, verification
|
|
4
|
+
and recovery mixins. Each of them reads state it does not own and calls back
|
|
5
|
+
into helpers defined on the runtime itself — the point of the split is that
|
|
6
|
+
"how a plan is approved" and "how a tool call is gated" stop sharing a
|
|
7
|
+
1,465-line file, not that they stop sharing ``self``.
|
|
8
|
+
|
|
9
|
+
Typing-only, exactly like :mod:`lattice_brain.ingestion._contract`: the
|
|
10
|
+
declarations below are never the implementation, so the MRO and every method
|
|
11
|
+
resolution stay byte-for-byte what the single-file class had. Adding a
|
|
12
|
+
cross-mixin call without declaring it here is a type error.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Any, FrozenSet, Optional
|
|
18
|
+
|
|
19
|
+
from latticeai.core.agent_helpers import PhaseBudgets, TranscriptBudget
|
|
20
|
+
from latticeai.core.agent_profiles import AgentProfile
|
|
21
|
+
from latticeai.core.permission_mode import PermissionMode
|
|
22
|
+
|
|
23
|
+
from .context import AgentRunContext
|
|
24
|
+
from .deps import AgentDeps
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class AgentCore:
|
|
28
|
+
"""What any phase mixin may assume about ``self``.
|
|
29
|
+
|
|
30
|
+
Never instantiated directly — see the module docstring. Members are
|
|
31
|
+
declared, not implemented: the implementation lives in ``runtime.py`` or in
|
|
32
|
+
whichever mixin owns it.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
# ── State owned by SingleAgentRuntime.__init__ ───────────────────────────
|
|
36
|
+
deps: AgentDeps
|
|
37
|
+
_env_phase_budgets: Optional[PhaseBudgets]
|
|
38
|
+
_env_transcript_budget: Optional[TranscriptBudget]
|
|
39
|
+
|
|
40
|
+
# ── runtime.py: budgets, resolved from deps or the environment once ──────
|
|
41
|
+
@property
|
|
42
|
+
def phase_budgets(self) -> PhaseBudgets:
|
|
43
|
+
raise NotImplementedError
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def transcript_budget(self) -> TranscriptBudget:
|
|
47
|
+
raise NotImplementedError
|
|
48
|
+
|
|
49
|
+
# ── runtime.py: the autonomy dial every gate in one run agrees on ────────
|
|
50
|
+
def resolve_permission_mode(
|
|
51
|
+
self,
|
|
52
|
+
ctx: Optional[AgentRunContext] = None,
|
|
53
|
+
*,
|
|
54
|
+
user_email: Optional[str] = None,
|
|
55
|
+
workspace_id: Optional[str] = None,
|
|
56
|
+
) -> PermissionMode:
|
|
57
|
+
raise NotImplementedError
|
|
58
|
+
|
|
59
|
+
# ── runtime.py: change-governance classification helpers ─────────────────
|
|
60
|
+
def _governed_tools(self) -> FrozenSet[str]:
|
|
61
|
+
raise NotImplementedError
|
|
62
|
+
|
|
63
|
+
def _governed_path_exists(self, name: str, path: str) -> bool:
|
|
64
|
+
raise NotImplementedError
|
|
65
|
+
|
|
66
|
+
# ── runtime.py: how hard the loop works to keep this model on contract ───
|
|
67
|
+
def profile_for(self, model_id: Optional[str]) -> AgentProfile:
|
|
68
|
+
raise NotImplementedError
|
|
69
|
+
|
|
70
|
+
# ── runtime.py: advisory telemetry every phase emits ─────────────────────
|
|
71
|
+
def _emit_step(
|
|
72
|
+
self, ctx: AgentRunContext, phase: str, event: str, **details: Any
|
|
73
|
+
) -> None:
|
|
74
|
+
raise NotImplementedError
|
|
75
|
+
|
|
76
|
+
# ── runtime.py: project-session prompt block, or "" for a standalone run ─
|
|
77
|
+
@staticmethod
|
|
78
|
+
def _project_block(ctx: AgentRunContext) -> str:
|
|
79
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""The mutable state one agent run carries from phase to phase.
|
|
2
|
+
|
|
3
|
+
Every phase reads and writes this object and nothing else: the loop itself is
|
|
4
|
+
stateless, so a run is exactly what its :class:`AgentRunContext` says it is.
|
|
5
|
+
``__slots__`` is deliberate — a typo'd attribute is an error, not a silently
|
|
6
|
+
ignored write that a later phase never sees.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from typing import Any, Callable, Dict, Optional
|
|
12
|
+
|
|
13
|
+
from latticeai.core.agent_state import AgentState
|
|
14
|
+
from latticeai.core.agent_trace import LoopTrace
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AgentRunContext:
|
|
18
|
+
"""Mutable state carrier passed through all agent phases."""
|
|
19
|
+
__slots__ = ("state", "plan", "transcript", "retry_count",
|
|
20
|
+
"state_history", "corrections", "final_message", "rollback_log",
|
|
21
|
+
"executing_model", "reviewing_model", "approved_by_human", "trace",
|
|
22
|
+
"on_step", "project_context", "permission_mode",
|
|
23
|
+
"self_model_summary")
|
|
24
|
+
|
|
25
|
+
def __init__(self) -> None:
|
|
26
|
+
self.state: AgentState = AgentState.IDLE
|
|
27
|
+
self.trace: LoopTrace = LoopTrace()
|
|
28
|
+
self.plan: dict = {}
|
|
29
|
+
self.transcript: list = []
|
|
30
|
+
self.retry_count: int = 0
|
|
31
|
+
self.state_history: list = []
|
|
32
|
+
self.corrections: list = []
|
|
33
|
+
self.final_message: str = ""
|
|
34
|
+
self.rollback_log: list = []
|
|
35
|
+
self.executing_model: Optional[str] = None
|
|
36
|
+
self.reviewing_model: Optional[str] = None
|
|
37
|
+
self.approved_by_human: bool = False
|
|
38
|
+
# Per-run step observer (review Wave 1.1): the HTTP layer attaches a
|
|
39
|
+
# callback here so live SSE clients see progress while EXECUTING.
|
|
40
|
+
# Never serialized; a broken observer never breaks the loop.
|
|
41
|
+
self.on_step: Optional[Callable[[Dict[str, Any]], None]] = None
|
|
42
|
+
# Multi-turn project loop (v9.9.6): a prompt block describing where the
|
|
43
|
+
# project stands — files already produced, open TODOs, the last honest
|
|
44
|
+
# verification. Empty for a standalone run, which behaves exactly as
|
|
45
|
+
# before. Set by the HTTP layer, read by plan/execute/verify.
|
|
46
|
+
self.project_context: str = ""
|
|
47
|
+
# Autonomy dial resolved once per run (v9.9.8). The HTTP layer stamps
|
|
48
|
+
# the user/workspace-scoped mode here so the plan gate and every
|
|
49
|
+
# per-tool gate in the same run agree; ``None`` falls back to the
|
|
50
|
+
# process-wide resolver on ``deps``.
|
|
51
|
+
self.permission_mode: Optional[str] = None
|
|
52
|
+
# Self-Model summary resolved once per run (v11.2.0). The executor
|
|
53
|
+
# prompt is rebuilt on every turn of the loop; reading the profile
|
|
54
|
+
# once and reusing it keeps a graph query off that hot path — and
|
|
55
|
+
# keeps every turn of one run describing the same person. ``None``
|
|
56
|
+
# means "not resolved yet"; ``""`` is a resolved, empty profile.
|
|
57
|
+
self.self_model_summary: Optional[str] = None
|