typesafeai-cli 0.3.1__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.
- typesafe_cli/__init__.py +1 -0
- typesafe_cli/cli.py +93 -0
- typesafe_cli/client.py +106 -0
- typesafe_cli/commands/__init__.py +0 -0
- typesafe_cli/commands/agent.py +12 -0
- typesafe_cli/commands/ask.py +90 -0
- typesafe_cli/commands/auth.py +28 -0
- typesafe_cli/commands/decide.py +43 -0
- typesafe_cli/commands/eval.py +37 -0
- typesafe_cli/commands/extract.py +83 -0
- typesafe_cli/commands/find.py +53 -0
- typesafe_cli/commands/models.py +30 -0
- typesafe_cli/commands/oneshot.py +91 -0
- typesafe_cli/commands/rank.py +49 -0
- typesafe_cli/commands/screen.py +38 -0
- typesafe_cli/commands/skills.py +138 -0
- typesafe_cli/commands/smoke.py +35 -0
- typesafe_cli/commands/suggest_skill.py +48 -0
- typesafe_cli/commands/verify.py +53 -0
- typesafe_cli/config.py +37 -0
- typesafe_cli/data/__init__.py +0 -0
- typesafe_cli/data/typesafe-ai/CLI.md +7 -0
- typesafe_cli/data/typesafe-ai/SKILL.md +149 -0
- typesafe_cli/data/typesafe-cli/SKILL.md +137 -0
- typesafe_cli/detect.py +83 -0
- typesafe_cli/format.py +22 -0
- typesafe_cli/help.py +36 -0
- typesafe_cli/io.py +17 -0
- typesafe_cli/questions.py +96 -0
- typesafe_cli/recipes/__init__.py +3 -0
- typesafe_cli/recipes/decide.py +64 -0
- typesafe_cli/recipes/extract.py +42 -0
- typesafe_cli/recipes/find.py +90 -0
- typesafe_cli/recipes/rank.py +97 -0
- typesafe_cli/recipes/screen.py +68 -0
- typesafe_cli/recipes/skills.py +148 -0
- typesafe_cli/recipes/thresholds.py +24 -0
- typesafe_cli/recipes/verify.py +48 -0
- typesafe_cli/schema.py +150 -0
- typesafeai_cli-0.3.1.dist-info/METADATA +137 -0
- typesafeai_cli-0.3.1.dist-info/RECORD +44 -0
- typesafeai_cli-0.3.1.dist-info/WHEEL +4 -0
- typesafeai_cli-0.3.1.dist-info/entry_points.txt +2 -0
- typesafeai_cli-0.3.1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
|
|
8
|
+
from typesafe_cli.commands.eval import call_system_one
|
|
9
|
+
from typesafe_cli.io import emit_success, fail
|
|
10
|
+
from typesafe_cli.questions import QuestionError
|
|
11
|
+
from typesafe_cli.recipes.rank import load_candidates, rank_chunks, rank_questions, sort_ranked
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def rank(
|
|
15
|
+
query: str = typer.Option(..., "--query"),
|
|
16
|
+
candidates_file: Path = typer.Option(..., "--candidates-file", help="JSON array of objects"),
|
|
17
|
+
id_field: str = typer.Option("id", "--id-field"),
|
|
18
|
+
text_field: str = typer.Option("text", "--text-field"),
|
|
19
|
+
model: str | None = typer.Option(None, "--model"),
|
|
20
|
+
key: str | None = typer.Option(None, "--key"),
|
|
21
|
+
creds: Path | None = typer.Option(None, "--creds"),
|
|
22
|
+
) -> None:
|
|
23
|
+
"""Rerank a local shortlist with one Score per candidate."""
|
|
24
|
+
try:
|
|
25
|
+
items = load_candidates(json.loads(candidates_file.read_text(encoding="utf-8")))
|
|
26
|
+
except (OSError, json.JSONDecodeError, QuestionError) as exc:
|
|
27
|
+
fail(code="usage", message=str(exc), exit_code=2)
|
|
28
|
+
|
|
29
|
+
answers: dict = {}
|
|
30
|
+
model_id = None
|
|
31
|
+
usage = {"input_tokens": 0, "output_tokens": 0}
|
|
32
|
+
try:
|
|
33
|
+
for chunk in rank_chunks(items):
|
|
34
|
+
state, questions = rank_questions(
|
|
35
|
+
chunk, query=query, id_field=id_field, text_field=text_field
|
|
36
|
+
)
|
|
37
|
+
data = call_system_one(state=state, questions=questions, key=key, creds=creds, model=model)
|
|
38
|
+
answers.update(data["answers"])
|
|
39
|
+
model_id = data.get("model") or model_id
|
|
40
|
+
usage["input_tokens"] += int((data.get("usage") or {}).get("input_tokens") or 0)
|
|
41
|
+
usage["output_tokens"] += int((data.get("usage") or {}).get("output_tokens") or 0)
|
|
42
|
+
ranked = sort_ranked(items, answers, id_field=id_field)
|
|
43
|
+
except QuestionError as exc:
|
|
44
|
+
fail(code="usage", message=str(exc), exit_code=2)
|
|
45
|
+
|
|
46
|
+
emit_success(
|
|
47
|
+
data={"query": query, "ranked": ranked, "model": model_id, "usage": usage},
|
|
48
|
+
command="rank",
|
|
49
|
+
)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from typesafe_cli.commands.eval import call_system_one
|
|
8
|
+
from typesafe_cli.io import emit_success, fail
|
|
9
|
+
from typesafe_cli.questions import QuestionError
|
|
10
|
+
from typesafe_cli.recipes.screen import SCREEN_QUESTIONS, interpret_screen
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def screen(
|
|
14
|
+
text_file: Path = typer.Option(..., "--text-file"),
|
|
15
|
+
model: str | None = typer.Option(None, "--model"),
|
|
16
|
+
key: str | None = typer.Option(None, "--key"),
|
|
17
|
+
creds: Path | None = typer.Option(None, "--creds"),
|
|
18
|
+
) -> None:
|
|
19
|
+
"""Guardrail pack: jailbreak, injection, sensitive data, harm. Suggested action is policy."""
|
|
20
|
+
try:
|
|
21
|
+
text = text_file.read_text(encoding="utf-8")
|
|
22
|
+
if not text.strip():
|
|
23
|
+
raise QuestionError("text file is empty")
|
|
24
|
+
except (OSError, QuestionError) as exc:
|
|
25
|
+
fail(code="usage", message=str(exc), exit_code=2)
|
|
26
|
+
|
|
27
|
+
data = call_system_one(
|
|
28
|
+
state={"text": text},
|
|
29
|
+
questions=SCREEN_QUESTIONS,
|
|
30
|
+
key=key,
|
|
31
|
+
creds=creds,
|
|
32
|
+
model=model,
|
|
33
|
+
)
|
|
34
|
+
interpreted = interpret_screen(data["answers"])
|
|
35
|
+
interpreted["model"] = data.get("model")
|
|
36
|
+
interpreted["usage"] = data.get("usage")
|
|
37
|
+
interpreted["answers"] = data["answers"]
|
|
38
|
+
emit_success(data=interpreted, command="screen")
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import urllib.error
|
|
4
|
+
import urllib.request
|
|
5
|
+
from importlib.resources import files
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import typer
|
|
9
|
+
|
|
10
|
+
from typesafe_cli.detect import detect_agent_info, resolve_agent
|
|
11
|
+
from typesafe_cli.io import emit_success, fail
|
|
12
|
+
|
|
13
|
+
OFFICIAL_SKILL_URL = (
|
|
14
|
+
"https://raw.githubusercontent.com/typesafe-ai/skills/main/skills/typesafe-ai/SKILL.md"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
SKILL_DIR_BY_AGENT = {
|
|
18
|
+
"claude-code": ".claude/skills",
|
|
19
|
+
"cursor": ".cursor/skills",
|
|
20
|
+
"windsurf": ".windsurf/skills",
|
|
21
|
+
"gemini-code": ".gemini/skills",
|
|
22
|
+
"codex": ".agents/skills",
|
|
23
|
+
"opencode": ".agents/skills",
|
|
24
|
+
"grok": ".agents/skills",
|
|
25
|
+
"generic-agent": ".agents/skills",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
USER_SKILL_DIR_BY_AGENT = {
|
|
29
|
+
"claude-code": Path.home() / ".claude" / "skills",
|
|
30
|
+
"cursor": Path.home() / ".cursor" / "skills",
|
|
31
|
+
"windsurf": Path.home() / ".windsurf" / "skills",
|
|
32
|
+
"gemini-code": Path.home() / ".gemini" / "skills",
|
|
33
|
+
"codex": Path.home() / ".agents" / "skills",
|
|
34
|
+
"opencode": Path.home() / ".agents" / "skills",
|
|
35
|
+
"grok": Path.home() / ".agents" / "skills",
|
|
36
|
+
"generic-agent": Path.home() / ".agents" / "skills",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
EXISTING_PROJECT_DIRS = (
|
|
40
|
+
".agents/skills",
|
|
41
|
+
".claude/skills",
|
|
42
|
+
".cursor/skills",
|
|
43
|
+
".windsurf/skills",
|
|
44
|
+
".gemini/skills",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def install(
|
|
49
|
+
target: str = typer.Option("auto", "--target", help="claude, cursor, codex, grok, or auto"),
|
|
50
|
+
directory: Path | None = typer.Option(None, "--dir", help="Explicit skills directory"),
|
|
51
|
+
project: bool = typer.Option(True, "--project/--global", help="Install into the current project (default)"),
|
|
52
|
+
offline: bool = typer.Option(False, "--offline", help="Use the vendored official skill, skip GitHub"),
|
|
53
|
+
) -> None:
|
|
54
|
+
try:
|
|
55
|
+
official = load_official_skill(offline=offline)
|
|
56
|
+
cli_note = _vendored("typesafe-ai", "CLI.md")
|
|
57
|
+
cli_skill = _vendored("typesafe-cli", "SKILL.md")
|
|
58
|
+
except OSError as exc:
|
|
59
|
+
fail(code="request", message=f"could not load skills: {exc}", exit_code=1)
|
|
60
|
+
|
|
61
|
+
agent = resolve_agent(target=target)
|
|
62
|
+
dest_root = directory if directory is not None else _skills_root(agent=agent, project=project)
|
|
63
|
+
written: list[str] = []
|
|
64
|
+
try:
|
|
65
|
+
pairs = [
|
|
66
|
+
(dest_root / "typesafe-ai" / "SKILL.md", official),
|
|
67
|
+
(dest_root / "typesafe-ai" / "CLI.md", cli_note),
|
|
68
|
+
(dest_root / "typesafe-cli" / "SKILL.md", cli_skill),
|
|
69
|
+
]
|
|
70
|
+
for path, body in pairs:
|
|
71
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
72
|
+
path.write_text(body, encoding="utf-8")
|
|
73
|
+
written.append(str(path))
|
|
74
|
+
except OSError as exc:
|
|
75
|
+
fail(code="request", message=str(exc), exit_code=1)
|
|
76
|
+
|
|
77
|
+
emit_success(
|
|
78
|
+
data={
|
|
79
|
+
"agent": agent,
|
|
80
|
+
"written": written,
|
|
81
|
+
"source": "offline-vendored" if offline else "github-or-vendored",
|
|
82
|
+
"note": "Installed typesafe-ai (design) and typesafe-cli (collect state, then typesafe ask). Agents cannot access TYPESAFE_* env vars.",
|
|
83
|
+
},
|
|
84
|
+
command="skills install",
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def list_skills() -> None:
|
|
89
|
+
info = detect_agent_info()
|
|
90
|
+
emit_success(
|
|
91
|
+
data={
|
|
92
|
+
"skills": [
|
|
93
|
+
{
|
|
94
|
+
"name": "typesafe-cli",
|
|
95
|
+
"description": "Collect local context, then run the typesafe CLI for a Jev judgment.",
|
|
96
|
+
"type": "skill",
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "typesafe-ai",
|
|
100
|
+
"description": "Official TypeSafe skill: design typed judgments and compose them in code.",
|
|
101
|
+
"type": "skill",
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
"detected_agent": info.name or None,
|
|
105
|
+
},
|
|
106
|
+
command="skills list",
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def load_official_skill(*, offline: bool = False) -> str:
|
|
111
|
+
if not offline:
|
|
112
|
+
try:
|
|
113
|
+
with urllib.request.urlopen(OFFICIAL_SKILL_URL, timeout=10) as response:
|
|
114
|
+
text = response.read().decode("utf-8")
|
|
115
|
+
if text.strip().startswith("---") and "typesafe-ai" in text:
|
|
116
|
+
return text
|
|
117
|
+
except (urllib.error.URLError, TimeoutError, OSError):
|
|
118
|
+
pass
|
|
119
|
+
return _vendored("typesafe-ai", "SKILL.md")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _vendored(*parts: str) -> str:
|
|
123
|
+
path = files("typesafe_cli.data")
|
|
124
|
+
for part in parts:
|
|
125
|
+
path = path / part
|
|
126
|
+
return path.read_text(encoding="utf-8")
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _skills_root(*, agent: str, project: bool) -> Path:
|
|
130
|
+
if project:
|
|
131
|
+
cwd = Path.cwd()
|
|
132
|
+
for rel in EXISTING_PROJECT_DIRS:
|
|
133
|
+
candidate = cwd / rel
|
|
134
|
+
if candidate.is_dir():
|
|
135
|
+
return candidate
|
|
136
|
+
rel = SKILL_DIR_BY_AGENT.get(agent, ".agents/skills")
|
|
137
|
+
return cwd / rel
|
|
138
|
+
return USER_SKILL_DIR_BY_AGENT.get(agent, Path.home() / ".agents" / "skills")
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from typesafe_cli.commands.ask import run_evaluation
|
|
8
|
+
from typesafe_cli.questions import load_questions
|
|
9
|
+
|
|
10
|
+
SMOKE_STATE = (
|
|
11
|
+
"Hi, I've been trying to connect my Stripe account for 3 days and it keeps failing. "
|
|
12
|
+
"I'm losing sales. Please help ASAP."
|
|
13
|
+
)
|
|
14
|
+
SMOKE_QUESTIONS = {
|
|
15
|
+
"urgency": {
|
|
16
|
+
"type": "noul",
|
|
17
|
+
"instructions": "Does this message express urgency?",
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def smoke(
|
|
23
|
+
key: str | None = typer.Option(None, "--key"),
|
|
24
|
+
creds: Path | None = typer.Option(None, "--creds"),
|
|
25
|
+
model: str | None = typer.Option(None, "--model"),
|
|
26
|
+
) -> None:
|
|
27
|
+
questions = load_questions(SMOKE_QUESTIONS)
|
|
28
|
+
run_evaluation(
|
|
29
|
+
state=SMOKE_STATE,
|
|
30
|
+
questions=questions,
|
|
31
|
+
key=key,
|
|
32
|
+
creds=creds,
|
|
33
|
+
model=model,
|
|
34
|
+
command="smoke",
|
|
35
|
+
)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from typesafe_cli.commands.eval import call_system_one
|
|
8
|
+
from typesafe_cli.io import emit_success, fail
|
|
9
|
+
from typesafe_cli.questions import QuestionError
|
|
10
|
+
from typesafe_cli.recipes.skills import (
|
|
11
|
+
discover_skills,
|
|
12
|
+
pick_skill,
|
|
13
|
+
rank_questions,
|
|
14
|
+
reread_questions,
|
|
15
|
+
shortlist_from_rank,
|
|
16
|
+
)
|
|
17
|
+
from typesafe_cli.recipes.thresholds import SKILL_TOP_K
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def suggest_skill(
|
|
21
|
+
task: str = typer.Option(..., "--task"),
|
|
22
|
+
skills_dir: Path = typer.Option(..., "--skills-dir"),
|
|
23
|
+
model: str | None = typer.Option(None, "--model"),
|
|
24
|
+
key: str | None = typer.Option(None, "--key"),
|
|
25
|
+
creds: Path | None = typer.Option(None, "--creds"),
|
|
26
|
+
) -> None:
|
|
27
|
+
"""Pick at most one skill: cheap rank, then reread the top three. The agent still decides."""
|
|
28
|
+
try:
|
|
29
|
+
skills = discover_skills(skills_dir)
|
|
30
|
+
rank_state, rank_qs = rank_questions(task, skills)
|
|
31
|
+
except QuestionError as exc:
|
|
32
|
+
fail(code="usage", message=str(exc), exit_code=2)
|
|
33
|
+
|
|
34
|
+
rank_data = call_system_one(state=rank_state, questions=rank_qs, key=key, creds=creds, model=model)
|
|
35
|
+
shortlist = shortlist_from_rank(skills, rank_data["answers"], top_k=SKILL_TOP_K)
|
|
36
|
+
reread_state, reread_qs = reread_questions(task, shortlist)
|
|
37
|
+
fit_data = call_system_one(state=reread_state, questions=reread_qs, key=key, creds=creds, model=model)
|
|
38
|
+
chosen = pick_skill(rank_answers=rank_data["answers"], fit_answers=fit_data["answers"], shortlist=shortlist)
|
|
39
|
+
emit_success(
|
|
40
|
+
data={
|
|
41
|
+
"skill": chosen,
|
|
42
|
+
"shortlist": [skill["name"] for skill in shortlist],
|
|
43
|
+
"rank": rank_data["answers"],
|
|
44
|
+
"fits": fit_data["answers"],
|
|
45
|
+
"model": fit_data.get("model") or rank_data.get("model"),
|
|
46
|
+
},
|
|
47
|
+
command="suggest-skill",
|
|
48
|
+
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from typesafe_cli.commands.eval import call_system_one
|
|
8
|
+
from typesafe_cli.io import emit_success, fail
|
|
9
|
+
from typesafe_cli.questions import QuestionError
|
|
10
|
+
from typesafe_cli.recipes.verify import interpret_verify, quote_in_source, verify_questions, verify_state
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def verify(
|
|
14
|
+
claim: str = typer.Option(..., "--claim"),
|
|
15
|
+
source_file: Path = typer.Option(..., "--source-file"),
|
|
16
|
+
quote: str | None = typer.Option(None, "--quote", help="If set, must appear in the source"),
|
|
17
|
+
model: str | None = typer.Option(None, "--model"),
|
|
18
|
+
key: str | None = typer.Option(None, "--key"),
|
|
19
|
+
creds: Path | None = typer.Option(None, "--creds"),
|
|
20
|
+
) -> None:
|
|
21
|
+
"""Check whether a source supports a claim. Missing quotes are fabricated locally."""
|
|
22
|
+
try:
|
|
23
|
+
source = source_file.read_text(encoding="utf-8")
|
|
24
|
+
if not claim.strip() or not source.strip():
|
|
25
|
+
raise QuestionError("claim and source must be non-empty")
|
|
26
|
+
except (OSError, QuestionError) as exc:
|
|
27
|
+
fail(code="usage", message=str(exc), exit_code=2)
|
|
28
|
+
|
|
29
|
+
if quote and not quote_in_source(source, quote):
|
|
30
|
+
emit_success(
|
|
31
|
+
data={
|
|
32
|
+
"verdict": "fabricated",
|
|
33
|
+
"confidence": 1.0,
|
|
34
|
+
"auto": False,
|
|
35
|
+
"review": True,
|
|
36
|
+
"skipped": True,
|
|
37
|
+
},
|
|
38
|
+
command="verify",
|
|
39
|
+
)
|
|
40
|
+
return
|
|
41
|
+
|
|
42
|
+
data = call_system_one(
|
|
43
|
+
state=verify_state(claim=claim, source=source, quote=quote),
|
|
44
|
+
questions=verify_questions(claim=claim),
|
|
45
|
+
key=key,
|
|
46
|
+
creds=creds,
|
|
47
|
+
model=model,
|
|
48
|
+
)
|
|
49
|
+
interpreted = interpret_verify(data["answers"]["support"])
|
|
50
|
+
interpreted["skipped"] = False
|
|
51
|
+
interpreted["model"] = data.get("model")
|
|
52
|
+
interpreted["usage"] = data.get("usage")
|
|
53
|
+
emit_success(data=interpreted, command="verify")
|
typesafe_cli/config.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
DEFAULT_BASE_URL = "https://api.typesafe.ai"
|
|
9
|
+
DEFAULT_MODEL = "jev-latest"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class Config:
|
|
14
|
+
api_key: str | None
|
|
15
|
+
base_url: str
|
|
16
|
+
model: str
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def load_config(
|
|
20
|
+
*,
|
|
21
|
+
key: str | None = None,
|
|
22
|
+
creds: Path | None = None,
|
|
23
|
+
model: str | None = None,
|
|
24
|
+
base_url: str | None = None,
|
|
25
|
+
) -> Config:
|
|
26
|
+
api_key = key
|
|
27
|
+
if api_key is None and creds is not None:
|
|
28
|
+
payload = json.loads(creds.read_text(encoding="utf-8"))
|
|
29
|
+
if not isinstance(payload, dict) or "api_key" not in payload:
|
|
30
|
+
raise ValueError("creds file must be JSON with an api_key field")
|
|
31
|
+
api_key = payload["api_key"]
|
|
32
|
+
if api_key is None:
|
|
33
|
+
api_key = os.environ.get("TYPESAFE_API_KEY") or None
|
|
34
|
+
|
|
35
|
+
resolved_base = base_url or os.environ.get("TYPESAFE_BASE_URL") or DEFAULT_BASE_URL
|
|
36
|
+
resolved_model = model or os.environ.get("TYPESAFE_DEFAULT_MODEL") or DEFAULT_MODEL
|
|
37
|
+
return Config(api_key=api_key, base_url=resolved_base, model=resolved_model)
|
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Using the typesafe CLI
|
|
2
|
+
|
|
3
|
+
Live evaluations: follow the **typesafe-cli** skill. Prefer `find`, `rank`, `extract`, `verify`, `screen`, `suggest-skill`, and `decide` when those flags fit; otherwise collect local state, write JSON under `${TMPDIR:-/tmp}/codex/<project>/`, then `typesafe ask`. Never drop those files in the git tree. This sidecar does not replace that skill or the official TypeSafe skill.
|
|
4
|
+
|
|
5
|
+
## Secrets
|
|
6
|
+
|
|
7
|
+
You cannot read, print, or inspect typesafeai-cli env vars or key files (`TYPESAFE_*`, `~/.config/typesafe/env`, `.env.local`). Run `typesafe auth status` (`has_key` only). If false, ask the human.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: typesafe-ai
|
|
3
|
+
license: MIT
|
|
4
|
+
description: >
|
|
5
|
+
Build AI-powered software with TypeSafe: small units of AI intelligence you
|
|
6
|
+
can use like programming primitives. Its System One models, including Jev,
|
|
7
|
+
turn natural language and application state into typed judgments and
|
|
8
|
+
probabilities that code can combine. Use when a feature needs programmable
|
|
9
|
+
common sense, when brainstorming what AI could make possible in an app, or
|
|
10
|
+
when an LLM prompt-and-parse step could become a structured decision.
|
|
11
|
+
Applications include routing, ranking, extraction, verification, and
|
|
12
|
+
interactive experiences; these are starting points, not the limits.
|
|
13
|
+
Read live docs and cookbooks to find useful patterns and discover new combinations.
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
# Build with TypeSafe
|
|
17
|
+
|
|
18
|
+
TypeSafe makes units of AI intelligence usable like programming primitives: small
|
|
19
|
+
judgments you can compose into larger capabilities. Its **System One models** return
|
|
20
|
+
fast, focused judgments that software can consume directly. **Jev** is TypeSafe's
|
|
21
|
+
flagship and first System One model. It understands natural language and returns
|
|
22
|
+
typed answers and probabilities rather
|
|
23
|
+
than generating text or reasoning explanations. Code owns the workflow; the model
|
|
24
|
+
supplies programmable common sense where ordinary code needs semantic understanding.
|
|
25
|
+
|
|
26
|
+
## Read the live docs
|
|
27
|
+
|
|
28
|
+
**The live TypeSafe docs are the source of truth. Read them as part of the task.**
|
|
29
|
+
This skill gives direction; the docs carry current concepts, prompting guidance,
|
|
30
|
+
API contracts, SDK usage, models, limits, and worked examples.
|
|
31
|
+
|
|
32
|
+
- Start with the [documentation index](https://docs.typesafe.ai/llms.txt) to discover
|
|
33
|
+
relevant pages and cookbooks. Use targeted reads rather than loading the entire site.
|
|
34
|
+
- Mintlify serves Markdown by appending `.md` to a page path, for example
|
|
35
|
+
[how to build with TypeSafe](https://docs.typesafe.ai/concepts/how-to-build-with-system-one.md).
|
|
36
|
+
Follow links from the index; convert extensionless documentation page links to
|
|
37
|
+
`.md` when useful. Resolve relative links against `https://docs.typesafe.ai`.
|
|
38
|
+
- Before writing an integration, read the current API or chosen SDK page and the
|
|
39
|
+
question guidance relevant to the design. For a new workflow, also inspect the
|
|
40
|
+
closest cookbook: it often shows a better decomposition than a generic classifier.
|
|
41
|
+
- If the index is unavailable, use the direct links below or the site's navigation.
|
|
42
|
+
If Markdown fetching fails, try the normal page. If live access is unavailable,
|
|
43
|
+
use available local docs or installed SDK types, state that limitation, and avoid
|
|
44
|
+
inventing version-dependent details.
|
|
45
|
+
|
|
46
|
+
| Task | Start here; follow the relevant details |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| Understand the programming model | [System One](https://docs.typesafe.ai/concepts/system-one.md), [building guide](https://docs.typesafe.ai/concepts/how-to-build-with-system-one.md) |
|
|
49
|
+
| Explore what to build | [Use-case map](https://docs.typesafe.ai/concepts/use-case-map.md), then relevant cookbooks from the index |
|
|
50
|
+
| Prepare inputs and questions | [State](https://docs.typesafe.ai/concepts/state.md), [primitives](https://docs.typesafe.ai/primitives.md), then the chosen primitive's page |
|
|
51
|
+
| Decide how to handle uncertainty | [Confidence](https://docs.typesafe.ai/confidence.md) |
|
|
52
|
+
| Write API code | [HTTP API](https://docs.typesafe.ai/api.md), [Python SDK](https://docs.typesafe.ai/sdk/python.md), or [JavaScript SDK](https://docs.typesafe.ai/sdk/javascript.md) |
|
|
53
|
+
| Update an older integration | [Migration guide](https://docs.typesafe.ai/migrating-to-v1.md) and the installed SDK's current reference |
|
|
54
|
+
|
|
55
|
+
## Find the useful shape
|
|
56
|
+
|
|
57
|
+
Start from the behavior the user wants: what will the application show, select,
|
|
58
|
+
change, or hand off? Work backward to the judgments it needs. Keep known rules,
|
|
59
|
+
calculations, exact lookups, and execution in code. Preserve the user's chosen stack
|
|
60
|
+
and scope; add TypeSafe where semantic understanding helps.
|
|
61
|
+
|
|
62
|
+
When brainstorming or choosing an architecture, consider more than classification.
|
|
63
|
+
The patterns below are starting points: combine primitives around the user's goal,
|
|
64
|
+
including ideas that do not fit an established recipe.
|
|
65
|
+
|
|
66
|
+
- **Route and fill known arguments.** A request can select a handler and its typed
|
|
67
|
+
parameters. Ask useful branch-specific questions up front and consume only the
|
|
68
|
+
relevant answers. Explore [function calling](https://docs.typesafe.ai/cookbooks/function_calling.md)
|
|
69
|
+
and [speculative fan-out](https://docs.typesafe.ai/patterns/fan-out.md).
|
|
70
|
+
- **Select instead of generate.** Find candidate values or source spans in code,
|
|
71
|
+
use a judgment to select the intended one, then copy or normalize it. Code can
|
|
72
|
+
also assemble source text into a formatted document or reading guide. Explore
|
|
73
|
+
[value extraction](https://docs.typesafe.ai/cookbooks/pre_parsed_value_extraction_cookbook.md)
|
|
74
|
+
and [structure recovery](https://docs.typesafe.ai/cookbooks/autoformat.md).
|
|
75
|
+
- **Find and judge evidence.** Retrieve candidates, compare their relevance to a
|
|
76
|
+
query, and select useful context. Explore [reranking](https://docs.typesafe.ai/cookbooks/rerank_typesafe.md)
|
|
77
|
+
and [hierarchical classification](https://docs.typesafe.ai/cookbooks/hierarchical_classification.md).
|
|
78
|
+
- **Turn judgments into reusable data.** Score dimensions once, then let code or
|
|
79
|
+
user controls change weights, thresholds, rankings, and views. With labeled
|
|
80
|
+
outcomes, those signals can become classical ML features. Explore
|
|
81
|
+
[composite scoring](https://docs.typesafe.ai/patterns/composite-scoring.md) and
|
|
82
|
+
[feature discovery](https://docs.typesafe.ai/cookbooks/autoresearch_feature_discovery.md).
|
|
83
|
+
- **Verify and escalate.** Check specific claims or fields against their evidence;
|
|
84
|
+
send uncertain or failing cases to a person or reasoning model. Explore
|
|
85
|
+
[citation checks](https://docs.typesafe.ai/cookbooks/citation_check.md) and
|
|
86
|
+
[extraction cascades](https://docs.typesafe.ai/cookbooks/sde_cascade.md).
|
|
87
|
+
- **Respond to changing state.** Code can retain goals and observations while fresh
|
|
88
|
+
judgments guide the next bounded step. Keep inferred state distinct from observed
|
|
89
|
+
facts, and check freshness before applying a result to a changed situation.
|
|
90
|
+
|
|
91
|
+
For open-ended requests, offer the few directions that best serve the user's goal
|
|
92
|
+
and recommend a starting point. For a concrete request, choose the relevant pattern
|
|
93
|
+
and build; a brainstorm is not a mandatory detour.
|
|
94
|
+
|
|
95
|
+
## Design the judgments
|
|
96
|
+
|
|
97
|
+
Choose by what the answer means, then read the relevant primitive page:
|
|
98
|
+
|
|
99
|
+
| Need | Primitive | Important distinction |
|
|
100
|
+
| --- | --- | --- |
|
|
101
|
+
| One of a defined set | [Choice](https://docs.typesafe.ai/primitives/choice.md) | Picks one option; its distribution compares competing options |
|
|
102
|
+
| Whether a condition holds | [Noul](https://docs.typesafe.ai/primitives/noul.md) | Probability of yes; no separate confidence; use one per label when several may apply |
|
|
103
|
+
| Degree along a described dimension | [Score](https://docs.typesafe.ai/primitives/score.md) | Probability-weighted position on ordered levels; use comparable per-item Scores for graded ranking |
|
|
104
|
+
|
|
105
|
+
Give each question enough relevant **state** to answer: source text, identities,
|
|
106
|
+
relationships, policies, and current facts. Prefer named JSON fields when context
|
|
107
|
+
has several parts. Put the judgment in **instructions** and define its possible
|
|
108
|
+
answers in **criteria**. Question IDs are for code and are not sent to the model;
|
|
109
|
+
include complete meaning in the question. Reference nested state with backticked
|
|
110
|
+
paths such as `ticket.messages[0].text`.
|
|
111
|
+
|
|
112
|
+
Ask one narrow, coherent judgment per question. Split independently useful dimensions,
|
|
113
|
+
without destroying the relationship being judged. A bounded action selection or
|
|
114
|
+
contextual interpretation is valid; atomic does not mean literal fact extraction
|
|
115
|
+
or a one-sentence limit. Strings work for simple questions. Use structured objects
|
|
116
|
+
or arrays when definitions, contrasts, exclusions, or examples clarify instructions
|
|
117
|
+
or criteria. Score levels must describe concrete situations and stand on their own.
|
|
118
|
+
|
|
119
|
+
Keep the needed answers available. Include a no-match outcome when nothing may fit;
|
|
120
|
+
use a separate presence judgment when it is independently useful. For source-value
|
|
121
|
+
selection, check candidate coverage: the model cannot choose an omitted value.
|
|
122
|
+
|
|
123
|
+
## Compose and verify
|
|
124
|
+
|
|
125
|
+
**Ask independent questions over the same state together**, including useful
|
|
126
|
+
speculative questions. They run in parallel and cannot see one another's answers.
|
|
127
|
+
State each speculative premise explicitly; code consumes the applicable answers.
|
|
128
|
+
A second request is warranted when an earlier answer is needed to fetch evidence,
|
|
129
|
+
construct new state, or determine the next options. Extra questions still use tokens;
|
|
130
|
+
measure actual request budgets, cost, and end-to-end latency.
|
|
131
|
+
|
|
132
|
+
Use probabilities and confidence to guide behavior, with thresholds evaluated on
|
|
133
|
+
the user's data and consequences. Choice/Score confidence summarizes distribution
|
|
134
|
+
concentration, not overall workflow correctness or permission to act. A Noul near
|
|
135
|
+
0.5 means similar probability for yes and no, not medium intensity. Several
|
|
136
|
+
acceptable alternatives can also spread probability; low confidence need not
|
|
137
|
+
invalidate a harmless preference choice. Ignore uncertainty on unused branches.
|
|
138
|
+
|
|
139
|
+
Keep policy explicit and raw judgments reusable. Weighted scores suit compensating
|
|
140
|
+
preferences; an “any serious violation” rule needs separate conditions. Changing a
|
|
141
|
+
weight or display filter need not rerun inference when evidence and question meanings
|
|
142
|
+
are unchanged. Typed output guarantees the interface, not truth. System One models
|
|
143
|
+
are trained for calibrated decisions; validate their performance in the target domain.
|
|
144
|
+
|
|
145
|
+
Test representative cases and the resulting application behavior. For failures,
|
|
146
|
+
inspect the exact state, questions, candidates, answers, composition, and observed
|
|
147
|
+
outcome. Separate missing evidence, model errors, code errors, and service failures.
|
|
148
|
+
Treat cookbook thresholds and demo results as examples to evaluate, not universal
|
|
149
|
+
rules or permanent model limitations. Keep API credentials server-side in web apps.
|