shellbrain 0.1.0__py3-none-any.whl
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.
- app/__init__.py +1 -0
- app/__main__.py +7 -0
- app/boot/__init__.py +1 -0
- app/boot/admin_db.py +88 -0
- app/boot/config.py +14 -0
- app/boot/create_policy.py +52 -0
- app/boot/db.py +70 -0
- app/boot/embeddings.py +55 -0
- app/boot/home.py +45 -0
- app/boot/migrations.py +61 -0
- app/boot/read_policy.py +179 -0
- app/boot/repos.py +15 -0
- app/boot/retrieval.py +3 -0
- app/boot/thresholds.py +19 -0
- app/boot/update_policy.py +34 -0
- app/boot/use_cases.py +22 -0
- app/config/__init__.py +1 -0
- app/config/defaults/create_policy.yaml +7 -0
- app/config/defaults/read_policy.yaml +25 -0
- app/config/defaults/runtime.yaml +10 -0
- app/config/defaults/thresholds.yaml +3 -0
- app/config/defaults/update_policy.yaml +5 -0
- app/config/loader.py +58 -0
- app/core/__init__.py +1 -0
- app/core/contracts/__init__.py +1 -0
- app/core/contracts/errors.py +29 -0
- app/core/contracts/requests.py +211 -0
- app/core/contracts/responses.py +15 -0
- app/core/entities/__init__.py +1 -0
- app/core/entities/associations.py +58 -0
- app/core/entities/episodes.py +66 -0
- app/core/entities/evidence.py +29 -0
- app/core/entities/facts.py +30 -0
- app/core/entities/guidance.py +47 -0
- app/core/entities/identity.py +48 -0
- app/core/entities/memory.py +34 -0
- app/core/entities/runtime_context.py +19 -0
- app/core/entities/session_state.py +31 -0
- app/core/entities/telemetry.py +152 -0
- app/core/entities/utility.py +14 -0
- app/core/interfaces/__init__.py +1 -0
- app/core/interfaces/clock.py +12 -0
- app/core/interfaces/config.py +28 -0
- app/core/interfaces/embeddings.py +12 -0
- app/core/interfaces/idgen.py +11 -0
- app/core/interfaces/repos.py +279 -0
- app/core/interfaces/retrieval.py +20 -0
- app/core/interfaces/session_state_store.py +33 -0
- app/core/interfaces/unit_of_work.py +50 -0
- app/core/policies/__init__.py +1 -0
- app/core/policies/_shared/__init__.py +1 -0
- app/core/policies/_shared/executor.py +132 -0
- app/core/policies/_shared/side_effects.py +9 -0
- app/core/policies/create_policy/__init__.py +1 -0
- app/core/policies/create_policy/pipeline.py +96 -0
- app/core/policies/read_policy/__init__.py +1 -0
- app/core/policies/read_policy/bm25.py +114 -0
- app/core/policies/read_policy/context_pack_builder.py +140 -0
- app/core/policies/read_policy/expansion.py +132 -0
- app/core/policies/read_policy/fusion_rrf.py +34 -0
- app/core/policies/read_policy/lexical_query.py +101 -0
- app/core/policies/read_policy/pipeline.py +93 -0
- app/core/policies/read_policy/scenario_lift.py +11 -0
- app/core/policies/read_policy/scoring.py +61 -0
- app/core/policies/read_policy/seed_retrieval.py +54 -0
- app/core/policies/read_policy/utility_prior.py +11 -0
- app/core/policies/update_policy/__init__.py +1 -0
- app/core/policies/update_policy/pipeline.py +80 -0
- app/core/use_cases/__init__.py +1 -0
- app/core/use_cases/build_guidance.py +85 -0
- app/core/use_cases/create_memory.py +26 -0
- app/core/use_cases/manage_session_state.py +159 -0
- app/core/use_cases/read_memory.py +21 -0
- app/core/use_cases/record_episode_sync_telemetry.py +19 -0
- app/core/use_cases/record_operation_telemetry.py +32 -0
- app/core/use_cases/sync_episode.py +162 -0
- app/core/use_cases/update_memory.py +40 -0
- app/migrations/__init__.py +1 -0
- app/migrations/env.py +65 -0
- app/migrations/versions/20260226_0001_initial_schema.py +232 -0
- app/migrations/versions/20260312_0002_add_hard_invariants.py +60 -0
- app/migrations/versions/20260312_0003_drop_create_confidence.py +40 -0
- app/migrations/versions/20260313_0004_episode_sync_hardening.py +71 -0
- app/migrations/versions/20260313_0005_evidence_episode_event_refs.py +45 -0
- app/migrations/versions/20260318_0006_usage_telemetry_schema.py +175 -0
- app/migrations/versions/20260319_0007_identity_session_guidance.py +49 -0
- app/migrations/versions/20260320_0008_instance_metadata_and_backup_safety.py +31 -0
- app/migrations/versions/__init__.py +1 -0
- app/periphery/__init__.py +1 -0
- app/periphery/admin/__init__.py +1 -0
- app/periphery/admin/backup.py +360 -0
- app/periphery/admin/destructive_guard.py +32 -0
- app/periphery/admin/doctor.py +192 -0
- app/periphery/admin/init.py +996 -0
- app/periphery/admin/instance_guard.py +211 -0
- app/periphery/admin/machine_state.py +354 -0
- app/periphery/admin/privileges.py +42 -0
- app/periphery/admin/repo_state.py +266 -0
- app/periphery/admin/restore.py +30 -0
- app/periphery/cli/__init__.py +1 -0
- app/periphery/cli/handlers.py +830 -0
- app/periphery/cli/hydration.py +119 -0
- app/periphery/cli/main.py +710 -0
- app/periphery/cli/presenter_json.py +10 -0
- app/periphery/cli/schema_validation.py +201 -0
- app/periphery/db/__init__.py +1 -0
- app/periphery/db/engine.py +10 -0
- app/periphery/db/models/__init__.py +1 -0
- app/periphery/db/models/associations.py +55 -0
- app/periphery/db/models/episodes.py +55 -0
- app/periphery/db/models/evidence.py +19 -0
- app/periphery/db/models/experiences.py +33 -0
- app/periphery/db/models/instance_metadata.py +17 -0
- app/periphery/db/models/memories.py +39 -0
- app/periphery/db/models/metadata.py +6 -0
- app/periphery/db/models/registry.py +18 -0
- app/periphery/db/models/telemetry.py +174 -0
- app/periphery/db/models/utility.py +19 -0
- app/periphery/db/models/views.py +154 -0
- app/periphery/db/repos/__init__.py +1 -0
- app/periphery/db/repos/relational/__init__.py +1 -0
- app/periphery/db/repos/relational/associations_repo.py +117 -0
- app/periphery/db/repos/relational/episodes_repo.py +188 -0
- app/periphery/db/repos/relational/evidence_repo.py +82 -0
- app/periphery/db/repos/relational/experiences_repo.py +41 -0
- app/periphery/db/repos/relational/memories_repo.py +99 -0
- app/periphery/db/repos/relational/read_policy_repo.py +202 -0
- app/periphery/db/repos/relational/telemetry_repo.py +161 -0
- app/periphery/db/repos/relational/utility_repo.py +30 -0
- app/periphery/db/repos/semantic/__init__.py +1 -0
- app/periphery/db/repos/semantic/keyword_retrieval_repo.py +63 -0
- app/periphery/db/repos/semantic/semantic_retrieval_repo.py +111 -0
- app/periphery/db/session.py +10 -0
- app/periphery/db/uow.py +75 -0
- app/periphery/embeddings/__init__.py +1 -0
- app/periphery/embeddings/local_provider.py +35 -0
- app/periphery/embeddings/query_vector_search.py +18 -0
- app/periphery/episodes/__init__.py +1 -0
- app/periphery/episodes/claude_code.py +387 -0
- app/periphery/episodes/codex.py +423 -0
- app/periphery/episodes/launcher.py +66 -0
- app/periphery/episodes/normalization.py +31 -0
- app/periphery/episodes/poller.py +299 -0
- app/periphery/episodes/source_discovery.py +66 -0
- app/periphery/episodes/tool_filter.py +165 -0
- app/periphery/identity/__init__.py +1 -0
- app/periphery/identity/claude_hook_install.py +67 -0
- app/periphery/identity/claude_runtime.py +83 -0
- app/periphery/identity/codex_runtime.py +32 -0
- app/periphery/identity/compatibility.py +38 -0
- app/periphery/identity/resolver.py +163 -0
- app/periphery/session_state/__init__.py +1 -0
- app/periphery/session_state/file_store.py +100 -0
- app/periphery/telemetry/__init__.py +33 -0
- app/periphery/telemetry/operation_summary.py +299 -0
- app/periphery/telemetry/session_selection.py +156 -0
- app/periphery/telemetry/sync_summary.py +65 -0
- app/periphery/validation/__init__.py +1 -0
- app/periphery/validation/integrity_validation.py +253 -0
- app/periphery/validation/semantic_validation.py +94 -0
- shellbrain-0.1.0.dist-info/METADATA +130 -0
- shellbrain-0.1.0.dist-info/RECORD +165 -0
- shellbrain-0.1.0.dist-info/WHEEL +5 -0
- shellbrain-0.1.0.dist-info/entry_points.txt +2 -0
- shellbrain-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""This module defines CLI hydration helpers that infer missing contextual request fields."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from app.periphery.admin.repo_state import (
|
|
8
|
+
load_repo_registration,
|
|
9
|
+
resolve_git_root,
|
|
10
|
+
resolve_repo_identity,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True)
|
|
15
|
+
class RepoContext:
|
|
16
|
+
"""Resolved repository context for one CLI invocation."""
|
|
17
|
+
|
|
18
|
+
repo_root: Path
|
|
19
|
+
repo_id: str
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def infer_repo_id(repo_root: Path) -> str:
|
|
23
|
+
"""This function infers repo_id from one resolved repository root."""
|
|
24
|
+
|
|
25
|
+
registration = _load_registration_for_root(repo_root)
|
|
26
|
+
if registration is not None:
|
|
27
|
+
return registration.repo_id
|
|
28
|
+
identity = resolve_repo_identity(repo_root=repo_root)
|
|
29
|
+
return identity.repo_id
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def resolve_repo_context(*, repo_root_arg: str | None, repo_id_arg: str | None) -> RepoContext:
|
|
33
|
+
"""Resolve repo_root and repo_id from explicit CLI flags or the current working directory."""
|
|
34
|
+
|
|
35
|
+
repo_root = Path(repo_root_arg).expanduser().resolve() if repo_root_arg else Path.cwd().resolve()
|
|
36
|
+
if not repo_root.exists():
|
|
37
|
+
raise ValueError(f"repo_root does not exist: {repo_root}")
|
|
38
|
+
if not repo_root.is_dir():
|
|
39
|
+
raise ValueError(f"repo_root must be a directory: {repo_root}")
|
|
40
|
+
repo_id = repo_id_arg or infer_repo_id(repo_root)
|
|
41
|
+
return RepoContext(repo_root=repo_root, repo_id=repo_id)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _load_registration_for_root(repo_root: Path):
|
|
45
|
+
"""Return a repo registration from the target root or its git root."""
|
|
46
|
+
|
|
47
|
+
direct = load_repo_registration(repo_root)
|
|
48
|
+
if direct is not None:
|
|
49
|
+
return direct
|
|
50
|
+
git_root = resolve_git_root(repo_root)
|
|
51
|
+
if git_root is None or git_root == repo_root:
|
|
52
|
+
return None
|
|
53
|
+
return load_repo_registration(git_root)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def hydrate_read_payload(payload: dict[str, Any], *, inferred_repo_id: str, defaults: dict[str, Any]) -> dict[str, Any]:
|
|
57
|
+
"""This function hydrates read payloads with inferred defaults before strict validation."""
|
|
58
|
+
|
|
59
|
+
if not isinstance(defaults.get("limits_by_mode"), dict):
|
|
60
|
+
raise ValueError("read hydration defaults must include limits_by_mode")
|
|
61
|
+
if not isinstance(defaults.get("expand"), dict):
|
|
62
|
+
raise ValueError("read hydration defaults must include expand")
|
|
63
|
+
if "default_mode" not in defaults:
|
|
64
|
+
raise ValueError("read hydration defaults must include default_mode")
|
|
65
|
+
if "include_global" not in defaults:
|
|
66
|
+
raise ValueError("read hydration defaults must include include_global")
|
|
67
|
+
|
|
68
|
+
merged = dict(payload)
|
|
69
|
+
merged.setdefault("op", "read")
|
|
70
|
+
merged.setdefault("repo_id", inferred_repo_id)
|
|
71
|
+
merged.setdefault("mode", defaults["default_mode"])
|
|
72
|
+
merged.setdefault("include_global", defaults["include_global"])
|
|
73
|
+
if "limit" not in merged:
|
|
74
|
+
mode = str(merged["mode"])
|
|
75
|
+
limits_by_mode = defaults["limits_by_mode"]
|
|
76
|
+
if mode not in limits_by_mode:
|
|
77
|
+
raise ValueError(f"read hydration defaults must define limit for mode: {mode}")
|
|
78
|
+
merged["limit"] = limits_by_mode[mode]
|
|
79
|
+
expand_defaults = dict(defaults["expand"])
|
|
80
|
+
incoming_expand = merged.get("expand")
|
|
81
|
+
if isinstance(incoming_expand, dict):
|
|
82
|
+
merged_expand = dict(expand_defaults)
|
|
83
|
+
merged_expand.update(incoming_expand)
|
|
84
|
+
merged["expand"] = merged_expand
|
|
85
|
+
else:
|
|
86
|
+
merged.setdefault("expand", dict(expand_defaults))
|
|
87
|
+
return merged
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def hydrate_create_payload(payload: dict[str, Any], *, inferred_repo_id: str, defaults: dict[str, Any]) -> dict[str, Any]:
|
|
91
|
+
"""This function hydrates create payloads with inferred scope defaults."""
|
|
92
|
+
|
|
93
|
+
if "scope" not in defaults:
|
|
94
|
+
raise ValueError("create hydration defaults must include scope")
|
|
95
|
+
merged = dict(payload)
|
|
96
|
+
merged.setdefault("op", "create")
|
|
97
|
+
merged.setdefault("repo_id", inferred_repo_id)
|
|
98
|
+
if isinstance(merged.get("memory"), dict):
|
|
99
|
+
merged["memory"].setdefault("scope", defaults["scope"])
|
|
100
|
+
return merged
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def hydrate_events_payload(payload: dict[str, Any], *, inferred_repo_id: str) -> dict[str, Any]:
|
|
104
|
+
"""This function hydrates events payloads with inferred repo defaults."""
|
|
105
|
+
|
|
106
|
+
merged = dict(payload)
|
|
107
|
+
merged.setdefault("op", "events")
|
|
108
|
+
merged.setdefault("repo_id", inferred_repo_id)
|
|
109
|
+
merged.setdefault("limit", 20)
|
|
110
|
+
return merged
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def hydrate_update_payload(payload: dict[str, Any], *, inferred_repo_id: str) -> dict[str, Any]:
|
|
114
|
+
"""This function hydrates update payloads with inferred repo defaults."""
|
|
115
|
+
|
|
116
|
+
merged = dict(payload)
|
|
117
|
+
merged.setdefault("op", "update")
|
|
118
|
+
merged.setdefault("repo_id", inferred_repo_id)
|
|
119
|
+
return merged
|