lighten 0.3.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.
- lighten/__init__.py +1 -0
- lighten/api/app.py +19 -0
- lighten/api/routes.py +35 -0
- lighten/api/schemas.py +41 -0
- lighten/audit/__init__.py +0 -0
- lighten/audit/pricing.py +111 -0
- lighten/audit/report.py +670 -0
- lighten/auth/api_key.py +30 -0
- lighten/clearing/__init__.py +0 -0
- lighten/clearing/distillers.py +491 -0
- lighten/clearing/engine.py +21 -0
- lighten/clearing/history.py +65 -0
- lighten/clearing/legacy_detector.py +545 -0
- lighten/clearing/renderer.py +195 -0
- lighten/clearing/thinking.py +250 -0
- lighten/cli/__init__.py +0 -0
- lighten/cli/main.py +411 -0
- lighten/detection/__init__.py +7 -0
- lighten/detection/tool_detector.py +42 -0
- lighten/hooks/__init__.py +0 -0
- lighten/hooks/__main__.py +84 -0
- lighten/hooks/dispatch.py +470 -0
- lighten/install/__init__.py +0 -0
- lighten/install/settings.py +414 -0
- lighten/integration/__init__.py +0 -0
- lighten/integration/claude_code.py +41 -0
- lighten/integration/request_adapter.py +51 -0
- lighten/integration/response_builder.py +37 -0
- lighten/memory/__init__.py +0 -0
- lighten/memory/handoff.py +319 -0
- lighten/memory/store.py +415 -0
- lighten/models/__init__.py +22 -0
- lighten/models/context.py +10 -0
- lighten/models/decision.py +27 -0
- lighten/models/tokenization.py +49 -0
- lighten/models/tool_result.py +109 -0
- lighten/pipeline/__init__.py +0 -0
- lighten/pipeline/curator.py +89 -0
- lighten/policy/__init__.py +0 -0
- lighten/policy/clearing_policy.py +257 -0
- lighten/policy/threshold.py +11 -0
- lighten/profiling/__init__.py +5 -0
- lighten/profiling/fidelity.py +27 -0
- lighten/profiling/refetchability.py +42 -0
- lighten/profiling/repetition.py +37 -0
- lighten/profiling/size.py +14 -0
- lighten/profiling/structure.py +29 -0
- lighten/profiling/tool_profiler.py +322 -0
- lighten-0.3.0.dist-info/METADATA +180 -0
- lighten-0.3.0.dist-info/RECORD +53 -0
- lighten-0.3.0.dist-info/WHEEL +4 -0
- lighten-0.3.0.dist-info/entry_points.txt +3 -0
- lighten-0.3.0.dist-info/licenses/LICENSE +35 -0
lighten/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.0"
|
lighten/api/app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from fastapi import FastAPI
|
|
2
|
+
|
|
3
|
+
from .routes import router
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
app = FastAPI(
|
|
7
|
+
title="Trippy V2 API",
|
|
8
|
+
version="0.1.0",
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
app.include_router(router)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@app.get("/health")
|
|
15
|
+
def health() -> dict[str, str]:
|
|
16
|
+
return {
|
|
17
|
+
"status": "ok",
|
|
18
|
+
"service": "trippy-v2",
|
|
19
|
+
}
|
lighten/api/routes.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from fastapi import APIRouter
|
|
2
|
+
|
|
3
|
+
from .schemas import (
|
|
4
|
+
PostToolUseEvent,
|
|
5
|
+
PostToolUseHookResponse,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
from lighten.integration.request_adapter import (
|
|
9
|
+
adapt_post_tool_use,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
from lighten.pipeline.curator import (
|
|
13
|
+
TrippyCurator,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
router = APIRouter()
|
|
18
|
+
|
|
19
|
+
curator = TrippyCurator()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@router.post(
|
|
23
|
+
"/hooks/claude/post-tool-use",
|
|
24
|
+
response_model=PostToolUseHookResponse,
|
|
25
|
+
response_model_exclude_none=True,
|
|
26
|
+
)
|
|
27
|
+
def post_tool_use(
|
|
28
|
+
event: PostToolUseEvent,
|
|
29
|
+
) -> dict:
|
|
30
|
+
|
|
31
|
+
request = adapt_post_tool_use(event)
|
|
32
|
+
|
|
33
|
+
result = curator.curate(request)
|
|
34
|
+
|
|
35
|
+
return result.to_hook_response()
|
lighten/api/schemas.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PostToolUseEvent(BaseModel):
|
|
9
|
+
"""
|
|
10
|
+
Claude Code PostToolUse event.
|
|
11
|
+
|
|
12
|
+
extra='allow' is intentional because Claude Code can add
|
|
13
|
+
fields without Trippy needing to reject the request.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
model_config = ConfigDict(extra="allow")
|
|
17
|
+
|
|
18
|
+
session_id: str | None = None
|
|
19
|
+
transcript_path: str | None = None
|
|
20
|
+
cwd: str | None = None
|
|
21
|
+
permission_mode: str | None = None
|
|
22
|
+
|
|
23
|
+
hook_event_name: str = "PostToolUse"
|
|
24
|
+
|
|
25
|
+
tool_name: str
|
|
26
|
+
tool_input: Any = None
|
|
27
|
+
tool_response: Any = None
|
|
28
|
+
|
|
29
|
+
tool_use_id: str | None = None
|
|
30
|
+
duration_ms: float | None = None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class HookSpecificOutput(BaseModel):
|
|
34
|
+
hookEventName: str = "PostToolUse"
|
|
35
|
+
|
|
36
|
+
updatedToolOutput: Any | None = None
|
|
37
|
+
additionalContext: str | None = None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class PostToolUseHookResponse(BaseModel):
|
|
41
|
+
hookSpecificOutput: HookSpecificOutput
|
|
File without changes
|
lighten/audit/pricing.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""
|
|
2
|
+
API list prices, $ per million tokens: (input, output, cache read).
|
|
3
|
+
Cache writes are priced at 1.25 x input (5-minute cache).
|
|
4
|
+
|
|
5
|
+
These are estimates for comparing sessions. Pro / Max subscribers pay
|
|
6
|
+
a flat fee; for them the numbers mean "how much usage", not dollars.
|
|
7
|
+
Unknown models fall back to their family, then to Opus.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
PRICES = {
|
|
14
|
+
"claude-fable-5-1": (10.0, 50.0, 0.25),
|
|
15
|
+
"claude-mythos-5-1": (10.0, 50.0, 0.25),
|
|
16
|
+
"claude-fable-5": (10.0, 50.0, 1.00),
|
|
17
|
+
"claude-opus-5-5": (4.0, 20.0, 0.20),
|
|
18
|
+
"claude-opus-5": (5.0, 25.0, 0.50),
|
|
19
|
+
"claude-opus-4-8": (5.0, 25.0, 0.50),
|
|
20
|
+
"claude-opus-4-7": (5.0, 25.0, 0.50),
|
|
21
|
+
"claude-opus-4-6": (5.0, 25.0, 0.50),
|
|
22
|
+
"claude-sonnet-5-5": (2.0, 10.0, 0.20),
|
|
23
|
+
"claude-sonnet-5": (2.0, 10.0, 0.20),
|
|
24
|
+
"claude-sonnet-4-6": (3.0, 15.0, 0.30),
|
|
25
|
+
"claude-haiku-5-5": (0.10, 0.50, 0.01),
|
|
26
|
+
"claude-haiku-4-5": (1.0, 5.0, 0.10),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
FAMILY_FALLBACK = (
|
|
30
|
+
("fable", "claude-fable-5-1"),
|
|
31
|
+
("mythos", "claude-mythos-5-1"),
|
|
32
|
+
("opus", "claude-opus-5-5"),
|
|
33
|
+
("sonnet", "claude-sonnet-5-5"),
|
|
34
|
+
("haiku", "claude-haiku-5-5"),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
DEFAULT_MODEL = "claude-opus-5-5"
|
|
38
|
+
|
|
39
|
+
CACHE_WRITE_MULTIPLIER = 1.25
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _normalise(
|
|
43
|
+
model: str,
|
|
44
|
+
) -> str:
|
|
45
|
+
|
|
46
|
+
model = re.sub(r"\[.*?\]", "", model or "").strip().lower()
|
|
47
|
+
|
|
48
|
+
for prefix in ("anthropic.", "us.anthropic.", "eu.anthropic."):
|
|
49
|
+
if model.startswith(prefix):
|
|
50
|
+
model = model[len(prefix):]
|
|
51
|
+
|
|
52
|
+
return model.split("@")[0]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def rates(
|
|
56
|
+
model: str,
|
|
57
|
+
) -> tuple[float, float, float, float, bool]:
|
|
58
|
+
"""
|
|
59
|
+
Returns (input, output, cache_read, cache_write, exact) in $/M.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
name = _normalise(model)
|
|
63
|
+
|
|
64
|
+
matches = [
|
|
65
|
+
key
|
|
66
|
+
for key in PRICES
|
|
67
|
+
if name == key or re.fullmatch(re.escape(key) + r"-\d{8}", name)
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
exact = bool(matches)
|
|
71
|
+
|
|
72
|
+
if matches:
|
|
73
|
+
key = max(matches, key=len)
|
|
74
|
+
else:
|
|
75
|
+
key = next(
|
|
76
|
+
(
|
|
77
|
+
target
|
|
78
|
+
for word, target in FAMILY_FALLBACK
|
|
79
|
+
if word in name
|
|
80
|
+
),
|
|
81
|
+
DEFAULT_MODEL,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
price_in, price_out, price_read = PRICES[key]
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
price_in,
|
|
88
|
+
price_out,
|
|
89
|
+
price_read,
|
|
90
|
+
price_in * CACHE_WRITE_MULTIPLIER,
|
|
91
|
+
exact,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def call_cost(
|
|
96
|
+
model: str,
|
|
97
|
+
*,
|
|
98
|
+
input_tokens: int,
|
|
99
|
+
cache_read: int,
|
|
100
|
+
cache_write: int,
|
|
101
|
+
output_tokens: int,
|
|
102
|
+
) -> float:
|
|
103
|
+
|
|
104
|
+
price_in, price_out, price_read, price_write, _ = rates(model)
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
input_tokens * price_in
|
|
108
|
+
+ cache_read * price_read
|
|
109
|
+
+ cache_write * price_write
|
|
110
|
+
+ output_tokens * price_out
|
|
111
|
+
) / 1_000_000
|