@yahyahammad/venastine 0.1.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.
Files changed (143) hide show
  1. package/.env.example +14 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +14 -0
  4. package/PRIVACY.md +66 -0
  5. package/README.md +878 -0
  6. package/SECURITY.md +88 -0
  7. package/THIRD_PARTY_NOTICES.md +100 -0
  8. package/agents/builtin/compactor.md +75 -0
  9. package/agents/builtin/explore.md +77 -0
  10. package/agents/builtin/grill-me.md +27 -0
  11. package/agents/builtin/initializer.md +94 -0
  12. package/agents/builtin/pipeline-reviewer.md +100 -0
  13. package/agents/builtin/plan.md +88 -0
  14. package/agents/builtin/review.md +74 -0
  15. package/agents/manager.py +195 -0
  16. package/agents/subagent_tool.py +215 -0
  17. package/agents/tui_commands.py +136 -0
  18. package/bin/venastine.mjs +382 -0
  19. package/config.py +1198 -0
  20. package/core/__init__.py +0 -0
  21. package/core/approval.py +115 -0
  22. package/core/client.py +1548 -0
  23. package/core/compaction.py +959 -0
  24. package/core/config_loader.py +1563 -0
  25. package/core/events.py +61 -0
  26. package/core/interaction.py +328 -0
  27. package/core/loop.py +1353 -0
  28. package/core/memory.py +370 -0
  29. package/core/model_windows.py +175 -0
  30. package/core/pipeline_models.py +176 -0
  31. package/core/reasoning/__init__.py +0 -0
  32. package/core/reasoning/authorization.py +130 -0
  33. package/core/reasoning/base.py +219 -0
  34. package/core/reasoning/confidence_scoring.py +468 -0
  35. package/core/reasoning/events.py +149 -0
  36. package/core/reasoning/json_retry.py +219 -0
  37. package/core/reasoning/orchestrator.py +1382 -0
  38. package/core/reasoning/output_writer.py +286 -0
  39. package/core/reasoning/payload_validation.py +398 -0
  40. package/core/reasoning/pipeline_storage.py +361 -0
  41. package/core/reasoning/review.py +615 -0
  42. package/core/reasoning/scholar.py +434 -0
  43. package/core/reasoning/source_corpus.py +327 -0
  44. package/core/reasoning/source_scoring.py +855 -0
  45. package/core/replay.py +167 -0
  46. package/core/session.py +153 -0
  47. package/core/workspace_trust.py +207 -0
  48. package/credentials.py +180 -0
  49. package/database.py +252 -0
  50. package/env_secrets.py +77 -0
  51. package/json_store.py +123 -0
  52. package/logging_setup.py +185 -0
  53. package/main.py +1959 -0
  54. package/mcp_client/__init__.py +15 -0
  55. package/mcp_client/client.py +499 -0
  56. package/mcp_client/config.py +379 -0
  57. package/mcp_client/registration.py +182 -0
  58. package/memories/manager.py +132 -0
  59. package/memories/tui_commands.py +232 -0
  60. package/package.json +73 -0
  61. package/project_init/config_files.py +278 -0
  62. package/project_init/doc_sets.py +330 -0
  63. package/project_init/generator.py +564 -0
  64. package/project_init/manifest.py +406 -0
  65. package/project_init/tui_commands.py +144 -0
  66. package/prompts/__init__.py +0 -0
  67. package/prompts/annotate.md +14 -0
  68. package/prompts/assumption_audit.md +27 -0
  69. package/prompts/claim_extraction.md +34 -0
  70. package/prompts/completeness.md +18 -0
  71. package/prompts/confidence_tiers.md +23 -0
  72. package/prompts/critic_pass.md +24 -0
  73. package/prompts/final_synthesis.md +13 -0
  74. package/prompts/initial_generation.md +14 -0
  75. package/prompts/preliminary_plan.md +23 -0
  76. package/prompts/revalidate.md +25 -0
  77. package/prompts/revise.md +15 -0
  78. package/prompts/source_grounding.md +66 -0
  79. package/prompts/system_prompts.py +262 -0
  80. package/prompts/universal_system_prompt +7 -0
  81. package/prompts/untrusted_content +1 -0
  82. package/providers.json.example +92 -0
  83. package/pyproject.toml +100 -0
  84. package/requirements.txt +72 -0
  85. package/safety/__init__.py +0 -0
  86. package/safety/policy_enforcement.py +682 -0
  87. package/security/__init__.py +0 -0
  88. package/security/capability.py +177 -0
  89. package/security/permissions.py +190 -0
  90. package/security/posture.py +302 -0
  91. package/security/protected_paths.py +309 -0
  92. package/security/sandbox.py +985 -0
  93. package/skills/builtin/crypto/cryptography-verification.md +66 -0
  94. package/skills/builtin/math/formal-specification.md +67 -0
  95. package/skills/builtin/math/numerical-methods.md +66 -0
  96. package/skills/builtin/math/proof-writing.md +61 -0
  97. package/skills/builtin/research/experiment-design.md +62 -0
  98. package/skills/builtin/research/literature-review.md +65 -0
  99. package/skills/builtin/research/reproducibility.md +55 -0
  100. package/skills/builtin/research/source-evaluation.md +70 -0
  101. package/skills/builtin/research/statistical-inference.md +63 -0
  102. package/skills/builtin/research/technical-writing.md +59 -0
  103. package/skills/builtin/security/cybersecurity-research.md +63 -0
  104. package/skills/builtin/software/code-review.md +61 -0
  105. package/skills/builtin/software/debugging.md +61 -0
  106. package/skills/builtin/software/test-design.md +67 -0
  107. package/skills/manager.py +138 -0
  108. package/skills/tui_commands.py +111 -0
  109. package/storage.py +1005 -0
  110. package/tools/base.py +305 -0
  111. package/tools/builtin/__init__.py +0 -0
  112. package/tools/builtin/_math_common.py +377 -0
  113. package/tools/builtin/_net_common.py +61 -0
  114. package/tools/builtin/arxiv.py +223 -0
  115. package/tools/builtin/ask_user.py +213 -0
  116. package/tools/builtin/discrete_math.py +134 -0
  117. package/tools/builtin/fetch_url.py +153 -0
  118. package/tools/builtin/file_ops.py +412 -0
  119. package/tools/builtin/geometry.py +148 -0
  120. package/tools/builtin/get_time.py +20 -0
  121. package/tools/builtin/linear_algebra.py +155 -0
  122. package/tools/builtin/load_skill.py +66 -0
  123. package/tools/builtin/logic.py +96 -0
  124. package/tools/builtin/pin.py +193 -0
  125. package/tools/builtin/probability_stats.py +228 -0
  126. package/tools/builtin/project_docs.py +405 -0
  127. package/tools/builtin/remember.py +158 -0
  128. package/tools/builtin/shell.py +461 -0
  129. package/tools/builtin/symbolic_math.py +119 -0
  130. package/tools/builtin/todo.py +147 -0
  131. package/tools/builtin/web_search.py +151 -0
  132. package/tools/context.py +136 -0
  133. package/tools/isolation.py +314 -0
  134. package/tools/registry.py +897 -0
  135. package/tui/app.py +3423 -0
  136. package/tui/app.tcss +458 -0
  137. package/tui/commands.py +61 -0
  138. package/tui/diffs.py +265 -0
  139. package/tui/preferences.py +182 -0
  140. package/tui/ravens.py +146 -0
  141. package/tui/screens.py +943 -0
  142. package/tui/themes.py +366 -0
  143. package/tui/widgets.py +1239 -0
@@ -0,0 +1,148 @@
1
+ """
2
+ tools/builtin/geometry.py
3
+
4
+ Classical 2D/3D geometry: distances, midpoints, lines, circles, polygons,
5
+ and triangles. Matrix/vector/tensor work lives in linear_algebra.py --
6
+ this tool is specifically for geometric objects and their properties.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import Literal, Optional
12
+
13
+ from sympy.geometry import Point, Line, Circle, Polygon, Triangle
14
+ from pydantic import BaseModel, Field
15
+
16
+ from tools.builtin._math_common import safe_parse, serialize, MathParseError
17
+
18
+ _OPERATIONS = Literal[
19
+ "distance", "midpoint", "is_collinear", "line_intersection",
20
+ "circle_area", "circle_circumference",
21
+ "polygon_area", "polygon_perimeter", "triangle_properties",
22
+ ]
23
+
24
+
25
+ class GeometryParams(BaseModel):
26
+ operation: _OPERATIONS = Field(..., description="Which operation to perform")
27
+ points: Optional[list[list[str]]] = Field(
28
+ None, description="List of points, each as [x, y] coordinate strings (numbers or symbolic expressions)"
29
+ )
30
+ radius: Optional[str] = Field(None, description="Radius, for circle operations (required for circle_area/circle_circumference)")
31
+ center: Optional[list[str]] = Field(None, description="Center point [x, y] for circle operations - optional, defaults to [0, 0] (origin) when omitted")
32
+ evaluate: bool = Field(False, description="If true, return numeric approximation (e.g. 12.566... instead of 4*pi). Default false keeps exact symbolic form.")
33
+ precision: int = Field(15, ge=1, le=50, description="Significant digits when evaluate is true")
34
+
35
+
36
+ TOOL_SCHEMA = {
37
+ "name": "geometry",
38
+ "description": (
39
+ "Classical geometry operations: distance and midpoint between "
40
+ "points, collinearity check, line intersection, circle area and "
41
+ "circumference, polygon area and perimeter, and triangle "
42
+ "properties (area, perimeter, right/equilateral/isosceles checks). "
43
+ "Circle operations default the center to the origin when not supplied; results are exact symbolic "
44
+ "expressions (e.g. 4*pi, sqrt(2)) unless 'evaluate' is true, which returns a numeric approximation with 'precision' digits."
45
+ ),
46
+ "input_schema": GeometryParams.model_json_schema(),
47
+ }
48
+
49
+
50
+ def _to_point(coords: list[str]) -> Point:
51
+ return Point(*[safe_parse(c) for c in coords])
52
+
53
+
54
+ def run(params: dict) -> dict:
55
+ parsed = GeometryParams(**params)
56
+
57
+ try:
58
+ op = parsed.operation
59
+ pts = [_to_point(p) for p in parsed.points] if parsed.points else []
60
+
61
+ if op == "distance":
62
+ if len(pts) < 2:
63
+ return {"error": "distance requires 2 points (each [x, y])."}
64
+ result = pts[0].distance(pts[1])
65
+ elif op == "midpoint":
66
+ if len(pts) < 2:
67
+ return {"error": "midpoint requires 2 points (each [x, y])."}
68
+ result = pts[0].midpoint(pts[1])
69
+ elif op == "is_collinear":
70
+ if len(pts) < 2:
71
+ return {"error": "is_collinear requires at least 2 points."}
72
+ result = Point.is_collinear(*pts)
73
+ elif op == "line_intersection":
74
+ if len(pts) < 4:
75
+ return {"error": "line_intersection requires 4 points (two per line: [p0,p1] and [p2,p3])."}
76
+ if pts[0] == pts[1]:
77
+ return {"error": "line_intersection: the first two points must be distinct (first line is degenerate)."}
78
+ if pts[2] == pts[3]:
79
+ return {"error": "line_intersection: the last two points must be distinct (second line is degenerate)."}
80
+ line_a = Line(pts[0], pts[1])
81
+ line_b = Line(pts[2], pts[3])
82
+ result = line_a.intersection(line_b)
83
+ elif op == "circle_area":
84
+ if parsed.radius is None:
85
+ return {"error": "circle_area requires 'radius'."}
86
+ center = _to_point(parsed.center) if parsed.center is not None else Point(0, 0)
87
+ result = Circle(center, safe_parse(parsed.radius)).area
88
+ elif op == "circle_circumference":
89
+ if parsed.radius is None:
90
+ return {"error": "circle_circumference requires 'radius'."}
91
+ center = _to_point(parsed.center) if parsed.center is not None else Point(0, 0)
92
+ result = Circle(center, safe_parse(parsed.radius)).circumference
93
+ elif op == "polygon_area":
94
+ if len(pts) < 3:
95
+ return {"error": f"polygon_area requires at least 3 points (got {len(pts)})."}
96
+ # Pre-check collinear/degenerate that would surface as Segment2D
97
+ if len(pts) == 3 and Point.is_collinear(*pts):
98
+ return {"error": "polygon_area: degenerate polygon (collinear points) - at least 3 non-collinear points required."}
99
+ result = Polygon(*pts).area
100
+ elif op == "polygon_perimeter":
101
+ if len(pts) < 3:
102
+ return {"error": f"polygon_perimeter requires at least 3 points (got {len(pts)})."}
103
+ if len(pts) == 3 and Point.is_collinear(*pts):
104
+ return {"error": "polygon_perimeter: degenerate polygon (collinear points) - at least 3 non-collinear points required."}
105
+ result = Polygon(*pts).perimeter
106
+ elif op == "triangle_properties":
107
+ if len(pts) != 3:
108
+ return {"error": f"triangle_properties requires exactly 3 points (got {len(pts)})."}
109
+ if Point.is_collinear(*pts):
110
+ return {"error": "triangle_properties: degenerate triangle (collinear points) - Segment2D has no triangle properties."}
111
+ tri = Triangle(*pts)
112
+ if parsed.evaluate:
113
+ result = {
114
+ "area": str(tri.area.evalf(parsed.precision)),
115
+ "perimeter": str(tri.perimeter.evalf(parsed.precision)),
116
+ "is_right": tri.is_right(),
117
+ "is_equilateral": tri.is_equilateral(),
118
+ "is_isosceles": tri.is_isosceles(),
119
+ }
120
+ else:
121
+ result = {
122
+ "area": str(tri.area),
123
+ "perimeter": str(tri.perimeter),
124
+ "is_right": tri.is_right(),
125
+ "is_equilateral": tri.is_equilateral(),
126
+ "is_isosceles": tri.is_isosceles(),
127
+ }
128
+ else:
129
+ return {"error": f"Unknown operation: {op}"}
130
+
131
+ except MathParseError as e:
132
+ return {"error": str(e)}
133
+ except (IndexError, TypeError) as e:
134
+ return {"error": f"Missing or malformed points/parameters for '{op}': {e}"}
135
+ except Exception as e:
136
+ return {"error": f"Computation failed: {e}"}
137
+
138
+ # Numeric-evaluate path: keep exact by default, evaluate only when asked.
139
+ if parsed.evaluate and not isinstance(result, (bool, dict)):
140
+ try:
141
+ if isinstance(result, list):
142
+ result = [r.evalf(parsed.precision) if hasattr(r, "evalf") else r for r in result]
143
+ elif hasattr(result, "evalf"):
144
+ result = result.evalf(parsed.precision)
145
+ except Exception:
146
+ pass
147
+
148
+ return {"result": serialize(result), "operation": op}
@@ -0,0 +1,20 @@
1
+ """
2
+ tools/builtin/get_time.py
3
+
4
+ Simple, dependency-free tool -- the current UTC date/time. Useful for
5
+ grounding "as of today" or "current events" style claims during research
6
+ passes without needing a network call.
7
+ """
8
+
9
+ from datetime import datetime, timezone
10
+
11
+ TOOL_SCHEMA = {
12
+ "name": "get_time",
13
+ "description": "Get the current date and time (UTC).",
14
+ "input_schema": {"type": "object", "properties": {}}, # takes no arguments
15
+ }
16
+
17
+
18
+ def run(params: dict) -> dict:
19
+ now = datetime.now(timezone.utc)
20
+ return {"utc_datetime": now.isoformat()}
@@ -0,0 +1,155 @@
1
+ """
2
+ tools/builtin/linear_algebra.py
3
+
4
+ Matrices, vectors, and low-order tensors (i.e. rank <= 2 -- this doesn't
5
+ attempt full tensor-index calculus, just matrix/vector operations, which
6
+ covers the overwhelming majority of research-applicable linear algebra).
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from typing import Literal, Optional
12
+
13
+ import sympy
14
+ from pydantic import BaseModel, Field
15
+
16
+ from tools.builtin._math_common import safe_parse, serialize, MathParseError
17
+
18
+ _OPERATIONS = Literal[
19
+ "add", "subtract", "multiply", "transpose", "determinant",
20
+ "inverse", "eigenvalues", "eigenvectors", "rank",
21
+ "solve_linear_system", "dot_product", "cross_product", "norm",
22
+ ]
23
+
24
+
25
+ class LinearAlgebraParams(BaseModel):
26
+ operation: _OPERATIONS = Field(..., description="Which operation to perform")
27
+ matrix_a: Optional[list[list[str]]] = Field(
28
+ None, description="First matrix, as rows of string entries (numbers or symbolic expressions)"
29
+ )
30
+ matrix_b: Optional[list[list[str]]] = Field(
31
+ None, description="Second matrix -- needed for add/subtract/multiply/solve_linear_system"
32
+ )
33
+ vector_a: Optional[list[str]] = Field(None, description="First vector -- needed for dot_product/cross_product/norm")
34
+ vector_b: Optional[list[str]] = Field(None, description="Second vector -- needed for dot_product/cross_product")
35
+ scalar: Optional[str] = Field(None, description="Scalar value, for scalar multiplication of matrix_a")
36
+
37
+
38
+ TOOL_SCHEMA = {
39
+ "name": "linear_algebra",
40
+ "description": (
41
+ "Perform matrix and vector operations: arithmetic, transpose, "
42
+ "determinant, inverse, eigenvalues/eigenvectors, rank, solving "
43
+ "linear systems (Ax=b where b is a column vector/matrix with the same "
44
+ "number of rows as A, e.g. [[7],[5]] for a 2-row system), dot product, "
45
+ "cross product, and norm. Entries can be exact numbers or symbolic "
46
+ "expressions."
47
+ ),
48
+ "input_schema": LinearAlgebraParams.model_json_schema(),
49
+ }
50
+
51
+
52
+ def _to_matrix(rows: list[list[str]]) -> sympy.Matrix:
53
+ return sympy.Matrix([[safe_parse(cell) for cell in row] for row in rows])
54
+
55
+
56
+ def _to_vector(values: list[str]) -> sympy.Matrix:
57
+ return sympy.Matrix([safe_parse(v) for v in values])
58
+
59
+
60
+ def run(params: dict) -> dict:
61
+ parsed = LinearAlgebraParams(**params)
62
+
63
+ try:
64
+ op = parsed.operation
65
+
66
+ if op == "add":
67
+ if parsed.matrix_a is None or parsed.matrix_b is None:
68
+ return {"error": "add requires 'matrix_a' and 'matrix_b' (each a list of rows)."}
69
+ result = _to_matrix(parsed.matrix_a) + _to_matrix(parsed.matrix_b)
70
+ elif op == "subtract":
71
+ if parsed.matrix_a is None or parsed.matrix_b is None:
72
+ return {"error": "subtract requires 'matrix_a' and 'matrix_b' (each a list of rows)."}
73
+ result = _to_matrix(parsed.matrix_a) - _to_matrix(parsed.matrix_b)
74
+ elif op == "multiply":
75
+ if parsed.matrix_a is None:
76
+ return {"error": "multiply requires 'matrix_a'."}
77
+ a = _to_matrix(parsed.matrix_a)
78
+ if parsed.scalar is not None:
79
+ result = safe_parse(parsed.scalar) * a
80
+ else:
81
+ if parsed.matrix_b is None:
82
+ return {"error": "multiply requires 'matrix_b' or 'scalar'."}
83
+ result = a * _to_matrix(parsed.matrix_b)
84
+ elif op == "transpose":
85
+ if parsed.matrix_a is None:
86
+ return {"error": "transpose requires 'matrix_a'."}
87
+ result = _to_matrix(parsed.matrix_a).T
88
+ elif op == "determinant":
89
+ if parsed.matrix_a is None:
90
+ return {"error": "determinant requires 'matrix_a'."}
91
+ m = _to_matrix(parsed.matrix_a)
92
+ if m.rows != m.cols:
93
+ return {"error": f"determinant requires a square matrix (got {m.rows}x{m.cols})."}
94
+ result = m.det()
95
+ elif op == "inverse":
96
+ if parsed.matrix_a is None:
97
+ return {"error": "inverse requires 'matrix_a'."}
98
+ m = _to_matrix(parsed.matrix_a)
99
+ if m.rows != m.cols:
100
+ return {"error": f"inverse requires a square matrix (got {m.rows}x{m.cols})."}
101
+ result = m.inv()
102
+ elif op == "eigenvalues":
103
+ if parsed.matrix_a is None:
104
+ return {"error": "eigenvalues requires 'matrix_a'."}
105
+ m = _to_matrix(parsed.matrix_a)
106
+ if m.rows != m.cols:
107
+ return {"error": f"eigenvalues requires a square matrix (got {m.rows}x{m.cols})."}
108
+ result = m.eigenvals()
109
+ elif op == "eigenvectors":
110
+ if parsed.matrix_a is None:
111
+ return {"error": "eigenvectors requires 'matrix_a'."}
112
+ m = _to_matrix(parsed.matrix_a)
113
+ if m.rows != m.cols:
114
+ return {"error": f"eigenvectors requires a square matrix (got {m.rows}x{m.cols})."}
115
+ result = m.eigenvects()
116
+ elif op == "rank":
117
+ if parsed.matrix_a is None:
118
+ return {"error": "rank requires 'matrix_a'."}
119
+ result = _to_matrix(parsed.matrix_a).rank()
120
+ elif op == "solve_linear_system":
121
+ if parsed.matrix_a is None or parsed.matrix_b is None:
122
+ return {"error": "solve_linear_system requires 'matrix_a' and 'matrix_b' (b as column vector/matrix with same rows as A, e.g. [[7],[5]])."}
123
+ a = _to_matrix(parsed.matrix_a)
124
+ b = _to_matrix(parsed.matrix_b)
125
+ if a.rows != b.rows:
126
+ return {"error": f"solve_linear_system: 'matrix_b' has {b.rows} rows but 'matrix_a' has {a.rows} — b must be a column vector/matrix with the same number of rows as A (e.g. [[7],[5]] for a 2-row system)."}
127
+ result = a.solve(b)
128
+ elif op == "dot_product":
129
+ if parsed.vector_a is None or parsed.vector_b is None:
130
+ return {"error": "dot_product requires 'vector_a' and 'vector_b'."}
131
+ result = _to_vector(parsed.vector_a).dot(_to_vector(parsed.vector_b))
132
+ elif op == "cross_product":
133
+ if parsed.vector_a is None or parsed.vector_b is None:
134
+ return {"error": "cross_product requires 'vector_a' and 'vector_b'."}
135
+ va, vb = _to_vector(parsed.vector_a), _to_vector(parsed.vector_b)
136
+ if len(va) != 3 or len(vb) != 3:
137
+ return {"error": "cross_product requires 3-dimensional vectors"}
138
+ result = va.cross(vb)
139
+ elif op == "norm":
140
+ if parsed.vector_a is None:
141
+ return {"error": "norm requires 'vector_a'."}
142
+ result = _to_vector(parsed.vector_a).norm()
143
+ else:
144
+ return {"error": f"Unknown operation: {op}"}
145
+
146
+ except MathParseError as e:
147
+ return {"error": str(e)}
148
+ except Exception as e:
149
+ # SymPy's NonSquareMatrixError has an empty string, which previously
150
+ # surfaced as "Computation failed: " with nothing after the colon.
151
+ if type(e).__name__ == "NonSquareMatrixError" or "NonSquareMatrix" in type(e).__name__:
152
+ return {"error": "Computation failed: determinant/inverse/eigen requires a square matrix — the supplied matrix is not square."}
153
+ return {"error": f"Computation failed: {e}"}
154
+
155
+ return {"result": serialize(result), "operation": op}
@@ -0,0 +1,66 @@
1
+ """
2
+ tools/builtin/load_skill.py
3
+
4
+ Skill progressive disclosure (ROADMAP_v2 §14): the model's system prompt
5
+ lists available skills as name + one-line description only; this tool
6
+ returns a skill's full body on request. View-only -- activation
7
+ semantics (additional_tools, slash commands) belong to §19's
8
+ SkillManager, not here.
9
+ """
10
+
11
+ from core import config_loader
12
+
13
+ TOOL_SCHEMA = {
14
+ "name": "load_skill",
15
+ "description": "View the full instructions of an available skill. "
16
+ "The system prompt lists available skills by name and "
17
+ "one-line summary; call this with a skill name to load "
18
+ "its complete methodology before following it.",
19
+ "input_schema": {
20
+ "type": "object",
21
+ "properties": {
22
+ "name": {
23
+ "type": "string",
24
+ "description": "Skill name exactly as listed in the "
25
+ "Available skills catalog.",
26
+ },
27
+ },
28
+ "required": ["name"],
29
+ },
30
+ }
31
+
32
+
33
+ def has_skills() -> bool:
34
+ """ToolSpec.available_check (ROADMAP_v2 §15, review finding F5).
35
+
36
+ With no skills discovered -- or before config_loader.initialize() has
37
+ run at all -- the system prompt carries no catalog, so this tool's
38
+ only possible answer is "Unknown skill". Advertising it anyway is the
39
+ same defect shape as the fetch_url one §15 exists to fix: a schema the
40
+ model can see, choose, and never get value from. Returning False here
41
+ keeps it out of registry.schemas() until there is something to load.
42
+
43
+ Reads the SAME function prompt assembly uses (skill_catalog_text, via
44
+ prompts/system_prompts.with_skill_catalog) rather than a parallel
45
+ check, so "advertised" and "catalogued" cannot drift apart.
46
+ """
47
+ return bool(config_loader.skill_catalog_text())
48
+
49
+
50
+ def run(params: dict) -> dict:
51
+ # params.get, not params[]. NO provider validates tool inputs against
52
+ # the schema, so a call with the key missing or misspelled raised a
53
+ # bare KeyError -- and _run() catches only ToolCallDenied, so it
54
+ # aborted the whole turn, skipped any remaining batched tool calls,
55
+ # and persisted no tool_result for the tool_use id. An error dict
56
+ # lets the model see what it got wrong and correct itself, which is
57
+ # what the unknown-name branch two lines down already does.
58
+ name = params.get("name")
59
+ if not name:
60
+ return {"error": "load_skill requires a 'name' -- the skill's name "
61
+ "exactly as listed in the available skills catalog."}
62
+ skill = config_loader.get_skill(name)
63
+ if skill is None:
64
+ return {"error": f"Unknown skill: {name!r} is not in "
65
+ f"the available skills catalog."}
66
+ return {"result": skill.body}
@@ -0,0 +1,96 @@
1
+ """
2
+ tools/builtin/logic.py
3
+
4
+ Propositional logic: simplification, equivalence checking, satisfiability,
5
+ tautology checking, and truth tables.
6
+
7
+ SCOPE NOTE, worth being honest about: this mechanically verifies
8
+ PROPOSITIONAL claims (is this specific expression a tautology, are these
9
+ two expressions equivalent, is this satisfiable). It is NOT a full
10
+ first-order proof assistant -- it can't verify a multi-step natural-
11
+ deduction proof or reason over quantifiers. What it CAN do is give the
12
+ model a deterministic ground-truth check for a specific logical claim,
13
+ which is still real uplift over the model reasoning about it unaided.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ from typing import Literal, Optional
19
+
20
+ import sympy
21
+ from sympy.logic.boolalg import simplify_logic, truth_table
22
+ from sympy.logic.inference import satisfiable
23
+ from pydantic import BaseModel, Field
24
+
25
+ from tools.builtin._math_common import safe_parse, MathParseError
26
+
27
+ _OPERATIONS = Literal["simplify", "equivalent", "satisfiable", "tautology", "truth_table"]
28
+
29
+
30
+ class LogicParams(BaseModel):
31
+ operation: _OPERATIONS = Field(..., description="Which operation to perform")
32
+ expression: str = Field(
33
+ ...,
34
+ description="Boolean expression using variables and operators & (and), | (or), ~ (not), >> (implies)",
35
+ )
36
+ expression_b: Optional[str] = Field(None, description="Second expression, for the 'equivalent' operation")
37
+ variables: Optional[list[str]] = Field(
38
+ None, description="Explicit variable names/order -- mainly useful for truth_table"
39
+ )
40
+
41
+
42
+ TOOL_SCHEMA = {
43
+ "name": "logic",
44
+ "description": (
45
+ "Mechanically check propositional logic claims: simplify a boolean "
46
+ "expression, check whether two expressions are logically "
47
+ "equivalent, check satisfiability, check whether an expression is "
48
+ "a tautology (always true), or generate a full truth table (inputs and output as true/false booleans)."
49
+ ),
50
+ "input_schema": LogicParams.model_json_schema(),
51
+ }
52
+
53
+
54
+ def run(params: dict) -> dict:
55
+ parsed = LogicParams(**params)
56
+
57
+ try:
58
+ var_names = parsed.variables or []
59
+ expr = safe_parse(parsed.expression, symbols=var_names)
60
+ op = parsed.operation
61
+
62
+ if op == "simplify":
63
+ result = str(simplify_logic(expr))
64
+
65
+ elif op == "equivalent":
66
+ if not parsed.expression_b:
67
+ return {"error": "expression_b is required for 'equivalent'"}
68
+ expr_b = safe_parse(parsed.expression_b, symbols=var_names)
69
+ result = simplify_logic(expr) == simplify_logic(expr_b)
70
+
71
+ elif op == "satisfiable":
72
+ result = bool(satisfiable(expr))
73
+
74
+ elif op == "tautology":
75
+ result = not satisfiable(sympy.Not(expr))
76
+
77
+ elif op == "truth_table":
78
+ free_syms = sorted(expr.free_symbols, key=str)
79
+ rows = list(truth_table(expr, free_syms))
80
+ result = [
81
+ {
82
+ "inputs": {str(s): bool(v) for s, v in zip(free_syms, row[0])},
83
+ "output": bool(row[1]),
84
+ }
85
+ for row in rows
86
+ ]
87
+
88
+ else:
89
+ return {"error": f"Unknown operation: {op}"}
90
+
91
+ except MathParseError as e:
92
+ return {"error": str(e)}
93
+ except Exception as e:
94
+ return {"error": f"Computation failed: {e}"}
95
+
96
+ return {"result": result, "operation": op}