openpitch 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.
- openpitch/__init__.py +10 -0
- openpitch/config.py +109 -0
- openpitch/mcp_server/__init__.py +12 -0
- openpitch/mcp_server/server.py +83 -0
- openpitch/mcp_server/tools.py +176 -0
- openpitch/models.py +192 -0
- openpitch/paths.py +69 -0
- openpitch/pipeline/__init__.py +11 -0
- openpitch/pipeline/classify.py +116 -0
- openpitch/pipeline/dashboard.py +359 -0
- openpitch/pipeline/discover.py +330 -0
- openpitch/pipeline/extract/__init__.py +21 -0
- openpitch/pipeline/extract/extract.py +255 -0
- openpitch/pipeline/extract_cache.py +65 -0
- openpitch/pipeline/llm/__init__.py +198 -0
- openpitch/pipeline/publish/__init__.py +9 -0
- openpitch/pipeline/publish/events.py +89 -0
- openpitch/pipeline/publish/publish.py +63 -0
- openpitch/pipeline/quality.py +280 -0
- openpitch/pipeline/run.py +413 -0
- openpitch/pipeline/score.py +49 -0
- openpitch/pipeline/sources/__init__.py +28 -0
- openpitch/pipeline/sources/article.py +119 -0
- openpitch/pipeline/sources/base.py +74 -0
- openpitch/pipeline/sources/company_site.py +68 -0
- openpitch/pipeline/sources/edgar.py +80 -0
- openpitch/pipeline/sources/news.py +152 -0
- openpitch/pipeline/sources/podcast_rss.py +93 -0
- openpitch/pipeline/transcribe/__init__.py +75 -0
- openpitch/reconcile/__init__.py +12 -0
- openpitch/reconcile/confidence.py +108 -0
- openpitch/reconcile/derive.py +203 -0
- openpitch/reconcile/engine.py +215 -0
- openpitch/reconcile/reliability.py +19 -0
- openpitch/store.py +185 -0
- openpitch-0.1.0.dist-info/METADATA +238 -0
- openpitch-0.1.0.dist-info/RECORD +40 -0
- openpitch-0.1.0.dist-info/WHEEL +4 -0
- openpitch-0.1.0.dist-info/entry_points.txt +3 -0
- openpitch-0.1.0.dist-info/licenses/LICENSE +21 -0
openpitch/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""OpenPitch — open, real-time, fully-sourced intelligence on top AI startups.
|
|
2
|
+
|
|
3
|
+
Package layout:
|
|
4
|
+
models.py core data model (the spine; FRD §3)
|
|
5
|
+
pipeline/ the daily producer: collect → transcribe → extract → reconcile → publish
|
|
6
|
+
reconcile/ confidence model + reconciliation engine (FRD §4–5)
|
|
7
|
+
mcp_server/ the local read interface for AI coding agents (FRD §8)
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__version__ = "0.0.1"
|
openpitch/config.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Config loaders for the metric registry, scoring weights, watchlist, and podcasts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from functools import lru_cache
|
|
7
|
+
|
|
8
|
+
import yaml
|
|
9
|
+
|
|
10
|
+
from . import paths
|
|
11
|
+
from .paths import config_dir
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _config_file(name: str):
|
|
15
|
+
"""Local config if present, else the remote-cached copy (no-clone installs)."""
|
|
16
|
+
local = config_dir() / name
|
|
17
|
+
if local.exists():
|
|
18
|
+
return local
|
|
19
|
+
remote = paths.resolve_remote(f"config/{name}")
|
|
20
|
+
return remote if remote else local
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True)
|
|
24
|
+
class MetricDef:
|
|
25
|
+
key: str
|
|
26
|
+
label: str
|
|
27
|
+
unit: str
|
|
28
|
+
tau: float
|
|
29
|
+
cluster_tolerance: float
|
|
30
|
+
implied_v1: bool
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@lru_cache(maxsize=1)
|
|
34
|
+
def load_metrics() -> dict[str, MetricDef]:
|
|
35
|
+
raw = yaml.safe_load(_config_file("metrics.yaml").read_text())["metrics"]
|
|
36
|
+
return {
|
|
37
|
+
k: MetricDef(
|
|
38
|
+
key=k, label=v["label"], unit=str(v["unit"]),
|
|
39
|
+
tau=float(v["tau"]), cluster_tolerance=float(v["cluster_tolerance"]),
|
|
40
|
+
implied_v1=bool(v["implied_v1"]),
|
|
41
|
+
)
|
|
42
|
+
for k, v in raw.items()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def metric_keys() -> list[str]:
|
|
47
|
+
return list(load_metrics().keys())
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@lru_cache(maxsize=1)
|
|
51
|
+
def load_scoring() -> dict:
|
|
52
|
+
return yaml.safe_load(_config_file("scoring.yaml").read_text())
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@lru_cache(maxsize=1)
|
|
56
|
+
def load_watchlist() -> list[dict]:
|
|
57
|
+
"""Global + MENA companies, each tagged with a `segment` and (if classified)
|
|
58
|
+
a two-level taxonomy (category/subcategory/specialty) from taxonomy.yaml."""
|
|
59
|
+
raw = yaml.safe_load(_config_file("watchlist.yaml").read_text())
|
|
60
|
+
out: list[dict] = []
|
|
61
|
+
for c in raw.get("companies", []):
|
|
62
|
+
out.append({**c, "segment": c.get("segment", "global")})
|
|
63
|
+
for c in raw.get("mena", []):
|
|
64
|
+
out.append({**c, "segment": c.get("segment", "mena")})
|
|
65
|
+
# Auto-discovered companies (config/discovered.yaml) — curated file stays untouched.
|
|
66
|
+
# Tagged `discovered` so downstream (e.g. quality) can tell a curated commitment
|
|
67
|
+
# from a funnel candidate awaiting its first corroboration run.
|
|
68
|
+
disc = config_dir() / "discovered.yaml"
|
|
69
|
+
if disc.exists():
|
|
70
|
+
have = {c["id"] for c in out}
|
|
71
|
+
for c in (yaml.safe_load(disc.read_text()) or {}).get("companies", []):
|
|
72
|
+
if c.get("id") and c["id"] not in have:
|
|
73
|
+
out.append({**c, "segment": c.get("segment", "global"), "discovered": True})
|
|
74
|
+
return [apply_taxonomy(c) for c in out]
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@lru_cache(maxsize=1)
|
|
78
|
+
def load_taxonomy() -> dict:
|
|
79
|
+
"""The controlled taxonomy: {'vocab': {main: [subs]}, 'companies': {id: {...}}}.
|
|
80
|
+
|
|
81
|
+
Generated by `openpitch classify`; absent until first run (returns empty).
|
|
82
|
+
"""
|
|
83
|
+
path = config_dir() / "taxonomy.yaml"
|
|
84
|
+
if not path.exists():
|
|
85
|
+
return {"vocab": {}, "companies": {}}
|
|
86
|
+
return yaml.safe_load(path.read_text()) or {"vocab": {}, "companies": {}}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def taxonomy_vocab() -> dict[str, list[str]]:
|
|
90
|
+
return load_taxonomy().get("vocab", {})
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def apply_taxonomy(meta: dict) -> dict:
|
|
94
|
+
"""Overlay category/subcategory/specialty from taxonomy.yaml onto a company meta
|
|
95
|
+
by id. The classified main `category` wins (it normalizes messy discovered values)."""
|
|
96
|
+
tax = load_taxonomy().get("companies", {}).get(meta.get("id"))
|
|
97
|
+
if not tax:
|
|
98
|
+
return meta
|
|
99
|
+
return {**meta, **{k: v for k, v in tax.items()
|
|
100
|
+
if k in ("category", "subcategory", "specialty", "summary") and v}}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@lru_cache(maxsize=1)
|
|
104
|
+
def load_podcasts() -> list[dict]:
|
|
105
|
+
path = _config_file("podcasts.yaml")
|
|
106
|
+
if not path or not path.exists():
|
|
107
|
+
return []
|
|
108
|
+
data = yaml.safe_load(path.read_text()) or {}
|
|
109
|
+
return [f for f in data.get("feeds", []) if f.get("feed_url")]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Local MCP server — the primary read interface (FRD §8).
|
|
2
|
+
|
|
3
|
+
Runs on the user's machine (stdio), plugged into Claude Code / Codex.
|
|
4
|
+
Makes ZERO LLM calls of its own: it reads the git-tracked JSON and returns
|
|
5
|
+
structured data; the user's own agent does the reasoning (FRD §8.6).
|
|
6
|
+
Every numeric response carries value, range, confidence, estimate_type,
|
|
7
|
+
as_of, and sources — provenance is never stripped.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from . import tools
|
|
11
|
+
|
|
12
|
+
__all__ = ["tools"]
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""OpenPitch MCP server (FRD §8, MCP-SPEC).
|
|
2
|
+
|
|
3
|
+
Local stdio server exposing the committed data to the user's agent. Read-only,
|
|
4
|
+
no LLM calls, no API key. Tool logic lives in `tools.py` (unit-tested); this
|
|
5
|
+
file is just the FastMCP wiring.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from . import tools
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_server():
|
|
14
|
+
from mcp.server.fastmcp import FastMCP
|
|
15
|
+
from mcp.types import ToolAnnotations
|
|
16
|
+
|
|
17
|
+
mcp = FastMCP("openpitch")
|
|
18
|
+
|
|
19
|
+
# Every tool here only READS the committed JSON: no writes, no side effects, no
|
|
20
|
+
# network/LLM. Declare that so clients know they're safe to call freely.
|
|
21
|
+
_READONLY = ToolAnnotations(
|
|
22
|
+
readOnlyHint=True, destructiveHint=False, idempotentHint=True, openWorldHint=False,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
@mcp.tool(annotations=_READONLY)
|
|
26
|
+
def list_companies(filter: str | None = None, segment: str = "all",
|
|
27
|
+
sort_by: str = "universe_rank", limit: int = 50) -> dict:
|
|
28
|
+
"""List covered AI companies with headline metrics."""
|
|
29
|
+
return tools.list_companies(filter, segment, sort_by, limit)
|
|
30
|
+
|
|
31
|
+
@mcp.tool(annotations=_READONLY)
|
|
32
|
+
def get_company(id: str, include_sources: bool = True) -> dict:
|
|
33
|
+
"""Full profile for one company: all resolved metrics with provenance."""
|
|
34
|
+
return tools.get_company(id, include_sources)
|
|
35
|
+
|
|
36
|
+
@mcp.tool(annotations=_READONLY)
|
|
37
|
+
def get_metric(company_id: str, metric: str, with_history: bool = False) -> dict:
|
|
38
|
+
"""One metric with value/range, confidence, estimate_type, as_of, and sources."""
|
|
39
|
+
return tools.get_metric(company_id, metric, with_history)
|
|
40
|
+
|
|
41
|
+
@mcp.tool(annotations=_READONLY)
|
|
42
|
+
def get_provenance(company_id: str, metric: str) -> dict:
|
|
43
|
+
"""Underlying claims + confidence factors behind a metric."""
|
|
44
|
+
return tools.get_provenance(company_id, metric)
|
|
45
|
+
|
|
46
|
+
@mcp.tool(annotations=_READONLY)
|
|
47
|
+
def compare_companies(ids: list[str], metrics: list[str]) -> dict:
|
|
48
|
+
"""Side-by-side metric comparison across companies."""
|
|
49
|
+
return tools.compare_companies(ids, metrics)
|
|
50
|
+
|
|
51
|
+
@mcp.tool(annotations=_READONLY)
|
|
52
|
+
def what_moved(since: str | None = None, min_confidence: float = 0.0,
|
|
53
|
+
include_contradictions: bool = True) -> dict:
|
|
54
|
+
"""Material changes, contradictions, and universe entries/exits since a date."""
|
|
55
|
+
return tools.what_moved(since, min_confidence, include_contradictions)
|
|
56
|
+
|
|
57
|
+
@mcp.tool(annotations=_READONLY)
|
|
58
|
+
def get_events(since: str | None = None, type: str | None = None,
|
|
59
|
+
company_id: str | None = None, min_confidence: float = 0.0) -> dict:
|
|
60
|
+
"""Filtered event stream (the push layer)."""
|
|
61
|
+
return tools.get_events(since, type, company_id, min_confidence)
|
|
62
|
+
|
|
63
|
+
@mcp.tool(annotations=_READONLY)
|
|
64
|
+
def search(query: str) -> dict:
|
|
65
|
+
"""Lexical search over companies, aliases, categories, and metric keys."""
|
|
66
|
+
return tools.search(query)
|
|
67
|
+
|
|
68
|
+
return mcp
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def main() -> None:
|
|
72
|
+
try:
|
|
73
|
+
server = build_server()
|
|
74
|
+
except ModuleNotFoundError:
|
|
75
|
+
raise SystemExit(
|
|
76
|
+
"The 'mcp' package is required. Install with: pip install 'openpitch[mcp]' "
|
|
77
|
+
"(or pip install mcp). See README."
|
|
78
|
+
)
|
|
79
|
+
server.run()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if __name__ == "__main__":
|
|
83
|
+
main()
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""MCP tool logic (MCP-SPEC) — pure functions over the committed data.
|
|
2
|
+
|
|
3
|
+
Separated from the MCP wiring (server.py) so it's unit-testable without the SDK.
|
|
4
|
+
Read-only; makes ZERO LLM calls; never strips provenance; explicit no-data.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from .. import store
|
|
10
|
+
from ..config import load_metrics, metric_keys
|
|
11
|
+
from ..reconcile.confidence import base_confidence, current_confidence
|
|
12
|
+
|
|
13
|
+
_TODAY = None # injected for deterministic tests via _today()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _today():
|
|
17
|
+
from datetime import date
|
|
18
|
+
return _TODAY or date.today()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _not_found(company_id: str, metric: str | None = None) -> dict:
|
|
22
|
+
return {
|
|
23
|
+
"status": "not_found",
|
|
24
|
+
"message": "No sourced value is available for this company/metric.",
|
|
25
|
+
"company_id": company_id,
|
|
26
|
+
**({"metric": metric} if metric else {}),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _headline(company) -> dict:
|
|
31
|
+
out = {}
|
|
32
|
+
for k in ("valuation", "arr"):
|
|
33
|
+
rv = company.metrics.get(k)
|
|
34
|
+
if rv:
|
|
35
|
+
out[k] = {"value": rv.value, "unit": rv.unit, "confidence": rv.confidence}
|
|
36
|
+
return out
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def list_companies(filter: str | None = None, segment: str = "all",
|
|
40
|
+
sort_by: str = "universe_rank", limit: int = 50) -> dict:
|
|
41
|
+
comps = store.read_all_companies()
|
|
42
|
+
if segment in ("global", "mena"):
|
|
43
|
+
comps = [c for c in comps if (c.segment or "global") == segment]
|
|
44
|
+
if filter:
|
|
45
|
+
f = filter.lower()
|
|
46
|
+
comps = [c for c in comps if f in c.name.lower() or f in (c.category or "").lower()
|
|
47
|
+
or f in (c.subcategory or "").lower() or f in (c.specialty or "").lower()]
|
|
48
|
+
keyers = {
|
|
49
|
+
"universe_rank": lambda c: (c.universe_rank is None, c.universe_rank or 1e9),
|
|
50
|
+
"name": lambda c: c.name.lower(),
|
|
51
|
+
"last_updated": lambda c: str(c.last_updated),
|
|
52
|
+
"vc_attention_score": lambda c: -(c.vc_attention_score or 0),
|
|
53
|
+
}
|
|
54
|
+
comps.sort(key=keyers.get(sort_by, keyers["universe_rank"]))
|
|
55
|
+
return {
|
|
56
|
+
"status": "ok",
|
|
57
|
+
"companies": [
|
|
58
|
+
{
|
|
59
|
+
"id": c.id, "name": c.name, "category": c.category,
|
|
60
|
+
"subcategory": c.subcategory, "specialty": c.specialty, "summary": c.summary,
|
|
61
|
+
"segment": c.segment,
|
|
62
|
+
"universe_rank": c.universe_rank, "vc_attention_score": c.vc_attention_score,
|
|
63
|
+
"last_updated": str(c.last_updated), "headline_metrics": _headline(c),
|
|
64
|
+
}
|
|
65
|
+
for c in comps[:limit]
|
|
66
|
+
],
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def get_company(id: str, include_sources: bool = True) -> dict:
|
|
71
|
+
c = store.read_company(id)
|
|
72
|
+
if not c:
|
|
73
|
+
return _not_found(id)
|
|
74
|
+
out = {"status": "ok", "company": c.model_dump(mode="json")}
|
|
75
|
+
if include_sources:
|
|
76
|
+
out["sources"] = {m: _sources_for(id, m) for m in c.metrics}
|
|
77
|
+
return out
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _sources_for(company_id: str, metric: str) -> list[dict]:
|
|
81
|
+
out = []
|
|
82
|
+
for cl in store.read_claims(company_id):
|
|
83
|
+
if cl.metric == metric and cl.source.type.value != "derived":
|
|
84
|
+
out.append({"name": cl.source.name, "type": cl.source.type.value,
|
|
85
|
+
"url": cl.source.url, "published_at": str(cl.source.published_at) if cl.source.published_at else None})
|
|
86
|
+
return out
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def get_metric(company_id: str, metric: str, with_history: bool = False) -> dict:
|
|
90
|
+
if metric not in metric_keys():
|
|
91
|
+
return {"status": "invalid_metric", "message": f"Metric '{metric}' is not in the registry.",
|
|
92
|
+
"allowed_metrics": metric_keys()}
|
|
93
|
+
c = store.read_company(company_id)
|
|
94
|
+
if not c:
|
|
95
|
+
return _not_found(company_id, metric)
|
|
96
|
+
rv = c.metrics.get(metric)
|
|
97
|
+
if not rv:
|
|
98
|
+
return _not_found(company_id, metric)
|
|
99
|
+
resp = {"status": "ok", "company_id": company_id, "metric": rv.model_dump(mode="json"),
|
|
100
|
+
"sources": _sources_for(company_id, metric)}
|
|
101
|
+
if with_history:
|
|
102
|
+
resp["history"] = store.read_history(company_id, metric)
|
|
103
|
+
return resp
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def get_provenance(company_id: str, metric: str) -> dict:
|
|
107
|
+
c = store.read_company(company_id)
|
|
108
|
+
if not c or metric not in c.metrics:
|
|
109
|
+
return _not_found(company_id, metric)
|
|
110
|
+
defs = load_metrics()
|
|
111
|
+
tau = defs[metric].tau if metric in defs else 180
|
|
112
|
+
claims_out = []
|
|
113
|
+
for cl in store.read_claims(company_id):
|
|
114
|
+
if cl.metric != metric:
|
|
115
|
+
continue
|
|
116
|
+
claims_out.append({
|
|
117
|
+
"id": cl.id, "value": cl.value, "unit": cl.unit, "raw_text": cl.raw_text,
|
|
118
|
+
"qualifiers": cl.qualifiers, "speaker": {"role": cl.speaker.role.value},
|
|
119
|
+
"source": cl.source.model_dump(mode="json"),
|
|
120
|
+
"base_confidence": round(base_confidence(cl), 4),
|
|
121
|
+
"current_confidence": round(current_confidence(cl, as_of=_today(), tau=tau), 4),
|
|
122
|
+
"derivation": cl.derivation.model_dump(mode="json") if cl.derivation else None,
|
|
123
|
+
})
|
|
124
|
+
return {"status": "ok", "company_id": company_id, "metric": metric,
|
|
125
|
+
"claims": claims_out, "contradiction": c.metrics[metric].contradiction,
|
|
126
|
+
"methodology_url": "docs/METHODOLOGY.md"}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def compare_companies(ids: list[str], metrics: list[str]) -> dict:
|
|
130
|
+
rows = []
|
|
131
|
+
for cid in ids:
|
|
132
|
+
c = store.read_company(cid)
|
|
133
|
+
if not c:
|
|
134
|
+
rows.append({"company_id": cid, "status": "not_found"})
|
|
135
|
+
continue
|
|
136
|
+
cells = {}
|
|
137
|
+
for m in metrics:
|
|
138
|
+
rv = c.metrics.get(m)
|
|
139
|
+
cells[m] = ({"value": rv.value, "unit": rv.unit, "confidence": rv.confidence,
|
|
140
|
+
"as_of": str(rv.as_of), "estimate_type": rv.estimate_type.value,
|
|
141
|
+
"contradiction": rv.contradiction} if rv else None)
|
|
142
|
+
rows.append({"company_id": cid, "name": c.name, "metrics": cells})
|
|
143
|
+
return {"status": "ok", "comparison": rows}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def get_events(since: str | None = None, type: str | None = None,
|
|
147
|
+
company_id: str | None = None, min_confidence: float = 0.0) -> dict:
|
|
148
|
+
evs = store.read_events(since=since)
|
|
149
|
+
if type:
|
|
150
|
+
evs = [e for e in evs if e.get("type") == type]
|
|
151
|
+
if company_id:
|
|
152
|
+
evs = [e for e in evs if e.get("company_id") == company_id]
|
|
153
|
+
evs = [e for e in evs if (e.get("confidence") or 0) >= min_confidence]
|
|
154
|
+
return {"status": "ok", "events": evs}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def what_moved(since: str | None = None, min_confidence: float = 0.0,
|
|
158
|
+
include_contradictions: bool = True) -> dict:
|
|
159
|
+
evs = get_events(since=since, min_confidence=min_confidence)["events"]
|
|
160
|
+
if not include_contradictions:
|
|
161
|
+
evs = [e for e in evs if e.get("type") != "contradiction_flagged"]
|
|
162
|
+
uni = store.read_universe() or {}
|
|
163
|
+
return {"status": "ok", "events": evs,
|
|
164
|
+
"universe_entries": uni.get("entries", []), "universe_exits": uni.get("exits", [])}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def search(query: str) -> dict:
|
|
168
|
+
q = query.lower()
|
|
169
|
+
hits = []
|
|
170
|
+
for c in store.read_all_companies():
|
|
171
|
+
hay = " ".join([c.name, c.category or "", c.subcategory or "", c.specialty or "",
|
|
172
|
+
c.segment or "", *(c.aliases or []), *c.metrics.keys()]).lower()
|
|
173
|
+
if any(tok in hay for tok in q.split()):
|
|
174
|
+
hits.append({"id": c.id, "name": c.name, "category": c.category,
|
|
175
|
+
"subcategory": c.subcategory})
|
|
176
|
+
return {"status": "ok", "query": query, "results": hits}
|
openpitch/models.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"""Core data model for OpenPitch (FRD §3).
|
|
2
|
+
|
|
3
|
+
These Pydantic models are the spine of the system. Everything else — the
|
|
4
|
+
pipeline that produces them, the MCP server and dashboard that read them —
|
|
5
|
+
depends on these shapes. They mirror the published JSON Schemas in `schemas/`.
|
|
6
|
+
|
|
7
|
+
Design invariants (BRD NFR-06/07):
|
|
8
|
+
* No numeric value exists without provenance (sources) and a confidence score.
|
|
9
|
+
* Values are never overwritten in place — history is append-only (see history JSONL).
|
|
10
|
+
* Confidence is always < 1.0; we never assert certainty.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from datetime import date, datetime
|
|
16
|
+
from enum import Enum
|
|
17
|
+
|
|
18
|
+
from pydantic import BaseModel, Field
|
|
19
|
+
|
|
20
|
+
SCHEMA_VERSION = "1.0"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# ── Enums ────────────────────────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class SourceType(str, Enum):
|
|
27
|
+
FILING = "filing" # SEC EDGAR (Form D, S-1) — highest trust
|
|
28
|
+
NEWS = "news" # press / journalism
|
|
29
|
+
PODCAST = "podcast" # founder/operator interviews — the freshness edge
|
|
30
|
+
WEB = "web" # company site, careers page, traffic signals
|
|
31
|
+
SOCIAL = "social" # social posts / rumor — lowest trust
|
|
32
|
+
DERIVED = "derived" # computed from other claims (FRD §5.6); confidence is propagated
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class SpeakerRole(str, Enum):
|
|
36
|
+
FOUNDER = "founder"
|
|
37
|
+
EXEC = "exec"
|
|
38
|
+
INVESTOR = "investor"
|
|
39
|
+
JOURNALIST = "journalist"
|
|
40
|
+
UNKNOWN = "unknown"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class EstimateType(str, Enum):
|
|
44
|
+
REPORTED = "reported" # a source stated it directly
|
|
45
|
+
CONSENSUS = "consensus" # synthesized from multiple agreeing sources
|
|
46
|
+
IMPLIED = "implied" # derived from leading indicators (FRD §5.5)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class EventType(str, Enum):
|
|
50
|
+
FUNDING_ROUND = "funding_round"
|
|
51
|
+
VALUATION_UPDATE = "valuation_update"
|
|
52
|
+
METRIC_UPDATE = "metric_update"
|
|
53
|
+
METRIC_THRESHOLD_CROSSED = "metric_threshold_crossed"
|
|
54
|
+
UNIVERSE_ENTRY = "universe_entry"
|
|
55
|
+
UNIVERSE_EXIT = "universe_exit"
|
|
56
|
+
CONTRADICTION_FLAGGED = "contradiction_flagged"
|
|
57
|
+
NEW_NOTABLE_CUSTOMER = "new_notable_customer"
|
|
58
|
+
LEADERSHIP_CHANGE = "leadership_change"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# ── Provenance ───────────────────────────────────────────────────────────────
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Speaker(BaseModel):
|
|
65
|
+
name: str | None = None
|
|
66
|
+
role: SpeakerRole = SpeakerRole.UNKNOWN
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class Source(BaseModel):
|
|
70
|
+
type: SourceType
|
|
71
|
+
name: str
|
|
72
|
+
url: str | None = None
|
|
73
|
+
locator: str | None = None # e.g. "ep1042@00:34:12" or a text anchor
|
|
74
|
+
published_at: date | None = None
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# ── Claim: the atomic extracted assertion (FRD §3.1) ─────────────────────────
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Derivation(BaseModel):
|
|
81
|
+
"""Provenance for a derived claim (FRD §5.6)."""
|
|
82
|
+
|
|
83
|
+
kind: str # identity | benchmark | concordance | surge
|
|
84
|
+
formula: str # e.g. "ARR = MRR × 12"
|
|
85
|
+
inputs: list[str] = Field(default_factory=list) # input claim ids
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class Claim(BaseModel):
|
|
89
|
+
id: str
|
|
90
|
+
company_id: str
|
|
91
|
+
metric: str
|
|
92
|
+
value: float | str | dict | None = None
|
|
93
|
+
unit: str | None = None
|
|
94
|
+
raw_text: str
|
|
95
|
+
qualifiers: list[str] = Field(default_factory=list) # run_rate, rounded, ...
|
|
96
|
+
speaker: Speaker = Field(default_factory=Speaker)
|
|
97
|
+
source: Source
|
|
98
|
+
extracted_at: datetime
|
|
99
|
+
extractor_model: str
|
|
100
|
+
base_confidence: float = Field(ge=0.0, le=1.0)
|
|
101
|
+
derivation: Derivation | None = None # set for DERIVED claims
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# ── ResolvedValue: the reconciled best estimate (FRD §3.2) ───────────────────
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class Range(BaseModel):
|
|
108
|
+
low: float | None = None
|
|
109
|
+
high: float | None = None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class Delta(BaseModel):
|
|
113
|
+
previous: float | None = None
|
|
114
|
+
change_pct: float | None = None
|
|
115
|
+
since: date | None = None
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class ResolvedValue(BaseModel):
|
|
119
|
+
metric: str
|
|
120
|
+
value: float | str | dict | None = None
|
|
121
|
+
unit: str | None = None
|
|
122
|
+
range: Range | None = None
|
|
123
|
+
as_of: date
|
|
124
|
+
estimate_type: EstimateType
|
|
125
|
+
confidence: float = Field(ge=0.0, le=0.97) # never assert certainty
|
|
126
|
+
supporting_claims: list[str] = Field(default_factory=list)
|
|
127
|
+
contradiction: bool = False
|
|
128
|
+
delta: Delta | None = None
|
|
129
|
+
history_ref: str | None = None
|
|
130
|
+
# Recency is the edge: the headline `value` is the freshest figure even when it's
|
|
131
|
+
# an "in talks"/rumored mark. These differentiate it from the last CONFIRMED number
|
|
132
|
+
# so the dashboard can show e.g. "$15B in talks · $4B confirmed '26".
|
|
133
|
+
unconfirmed: bool = False
|
|
134
|
+
confirmed_value: float | None = None
|
|
135
|
+
confirmed_as_of: date | None = None
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
# ── Company profile (FRD §3.3) ───────────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class Company(BaseModel):
|
|
142
|
+
id: str
|
|
143
|
+
name: str
|
|
144
|
+
aliases: list[str] = Field(default_factory=list)
|
|
145
|
+
website: str | None = None
|
|
146
|
+
category: str | None = None # controlled MAIN category
|
|
147
|
+
subcategory: str | None = None # controlled sub (e.g. video/voice/world-model)
|
|
148
|
+
specialty: str | None = None # free-text nuance ("AI video for marketers")
|
|
149
|
+
summary: str | None = None # 1-2 sentence plain-English business description
|
|
150
|
+
segment: str | None = None # global | mena
|
|
151
|
+
in_universe: bool = True
|
|
152
|
+
vc_attention_score: float | None = None
|
|
153
|
+
universe_rank: int | None = None
|
|
154
|
+
metrics: dict[str, ResolvedValue] = Field(default_factory=dict)
|
|
155
|
+
last_updated: date
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# ── Event: the push/integration layer (FRD §8.5) ─────────────────────────────
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
class EventPayload(BaseModel):
|
|
162
|
+
metric: str | None = None
|
|
163
|
+
previous: float | str | None = None
|
|
164
|
+
current: float | str | None = None
|
|
165
|
+
change_pct: float | None = None
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class Event(BaseModel):
|
|
169
|
+
id: str
|
|
170
|
+
schema_version: str = SCHEMA_VERSION
|
|
171
|
+
type: EventType
|
|
172
|
+
company_id: str
|
|
173
|
+
company_name: str | None = None
|
|
174
|
+
summary: str
|
|
175
|
+
payload: EventPayload = Field(default_factory=EventPayload)
|
|
176
|
+
confidence: float = Field(ge=0.0, le=1.0)
|
|
177
|
+
estimate_type: EstimateType | None = None
|
|
178
|
+
sources: list[Source] = Field(default_factory=list)
|
|
179
|
+
detected_at: datetime
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
# ── Source registry entry (FRD §3.6) — learned reliability ───────────────────
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class SourceReliability(BaseModel):
|
|
186
|
+
type: SourceType
|
|
187
|
+
tier_prior: float = Field(ge=0.0, le=1.0)
|
|
188
|
+
reliability: float = Field(default=0.5, ge=0.0, le=1.0) # learned over time
|
|
189
|
+
claims_made: int = 0
|
|
190
|
+
claims_confirmed: int = 0
|
|
191
|
+
claims_contradicted: int = 0
|
|
192
|
+
last_updated: date | None = None
|
openpitch/paths.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Filesystem locations (env-overridable). The git-tracked `data/` IS the database."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import time
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def remote_base() -> str:
|
|
13
|
+
"""Public repo raw base for no-clone installs (override via OPENPITCH_REMOTE)."""
|
|
14
|
+
return os.environ.get(
|
|
15
|
+
"OPENPITCH_REMOTE", "https://raw.githubusercontent.com/Avierovich/openpitch/main"
|
|
16
|
+
).rstrip("/")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def cache_root() -> Path:
|
|
20
|
+
return Path(os.environ.get("OPENPITCH_CACHE", Path.home() / ".cache" / "openpitch"))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def resolve_remote(relpath: str) -> Path | None:
|
|
24
|
+
"""Fetch a repo-relative file from the public repo into a TTL cache.
|
|
25
|
+
|
|
26
|
+
Lets `uvx openpitch-mcp` read committed data/config with NO clone. Returns a
|
|
27
|
+
cached local Path, or None if unavailable. Falls back to a stale cache on
|
|
28
|
+
network failure (better than nothing).
|
|
29
|
+
"""
|
|
30
|
+
ttl = int(os.environ.get("OPENPITCH_CACHE_TTL", "3600"))
|
|
31
|
+
cache = cache_root() / relpath
|
|
32
|
+
if cache.exists() and (time.time() - cache.stat().st_mtime) < ttl:
|
|
33
|
+
return cache
|
|
34
|
+
try:
|
|
35
|
+
import httpx
|
|
36
|
+
|
|
37
|
+
r = httpx.get(f"{remote_base()}/{relpath}", timeout=20, follow_redirects=True)
|
|
38
|
+
if r.status_code == 200:
|
|
39
|
+
cache.parent.mkdir(parents=True, exist_ok=True)
|
|
40
|
+
cache.write_bytes(r.content)
|
|
41
|
+
return cache
|
|
42
|
+
except Exception: # noqa: BLE001
|
|
43
|
+
pass
|
|
44
|
+
return cache if cache.exists() else None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def data_dir() -> Path:
|
|
48
|
+
return Path(os.environ.get("OPENPITCH_DATA_DIR", REPO_ROOT / "data"))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def config_dir() -> Path:
|
|
52
|
+
return Path(os.environ.get("OPENPITCH_CONFIG_DIR", REPO_ROOT / "config"))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def load_dotenv() -> None:
|
|
56
|
+
"""Load REPO_ROOT/.env into the environment (existing env vars win).
|
|
57
|
+
|
|
58
|
+
Dependency-free. The .env file is gitignored — it holds local secrets like
|
|
59
|
+
LLM_API_KEY and is never committed.
|
|
60
|
+
"""
|
|
61
|
+
env = REPO_ROOT / ".env"
|
|
62
|
+
if not env.exists():
|
|
63
|
+
return
|
|
64
|
+
for line in env.read_text().splitlines():
|
|
65
|
+
line = line.strip()
|
|
66
|
+
if not line or line.startswith("#") or "=" not in line:
|
|
67
|
+
continue
|
|
68
|
+
key, val = line.split("=", 1)
|
|
69
|
+
os.environ.setdefault(key.strip(), val.strip().strip("\"'"))
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""The daily producer pipeline (FRD §7).
|
|
2
|
+
|
|
3
|
+
Stages, each an independent/resumable module:
|
|
4
|
+
1. select universe (VC-attention score → top 50)
|
|
5
|
+
2. collect (per-source adapters)
|
|
6
|
+
3. transcribe (podcasts without published transcripts)
|
|
7
|
+
4. extract (LLM → Claims)
|
|
8
|
+
5. reconcile (Claims → ResolvedValues + history)
|
|
9
|
+
6. score sources (reliability meta-learning)
|
|
10
|
+
7. publish (JSON, history, events, digest, dashboard build)
|
|
11
|
+
"""
|