@yahyahammad/venastine 0.2.0 → 0.3.8
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.
- package/.env.example +19 -14
- package/CONFIG_ARCHITECTURE.md +2002 -0
- package/NOTICE +1 -1
- package/README.md +233 -94
- package/agents/builtin/build.md +73 -0
- package/agents/builtin/general.md +80 -0
- package/agents/builtin/plan.md +23 -5
- package/agents/builtin/test.md +65 -0
- package/agents/builtin/writer.md +67 -0
- package/agents/manager.py +261 -195
- package/agents/subagent_tool.py +277 -43
- package/agents/tui_commands.py +7 -12
- package/bin/venastine.mjs +528 -382
- package/bin/venastine.py +71 -0
- package/cli_commands.py +835 -0
- package/config.py +95 -1198
- package/config.yaml +1090 -0
- package/config_edit.py +1301 -0
- package/config_schema.py +966 -0
- package/config_update.py +749 -0
- package/core/agent_activity.py +158 -20
- package/core/ansi.py +452 -0
- package/core/approval.py +27 -5
- package/core/call_view.py +364 -0
- package/core/cancel.py +121 -0
- package/core/chatgpt_auth.py +747 -0
- package/core/claims_view.py +107 -0
- package/core/client.py +1238 -82
- package/core/commands.py +454 -0
- package/core/compaction.py +830 -66
- package/core/config_loader.py +516 -97
- package/core/connect.py +686 -0
- package/core/events.py +68 -6
- package/core/file_mentions.py +280 -0
- package/core/interaction.py +87 -4
- package/core/line_pattern.py +128 -0
- package/core/loop.py +1516 -440
- package/core/memory.py +120 -8
- package/core/pipeline_models.py +23 -9
- package/core/provider_errors.py +234 -0
- package/core/reasoning/confidence_scoring.py +70 -54
- package/core/reasoning/json_retry.py +19 -1
- package/core/reasoning/orchestrator.py +232 -53
- package/core/reasoning/output_writer.py +90 -31
- package/core/reasoning/payload_validation.py +133 -7
- package/core/reasoning/pipeline_storage.py +427 -361
- package/core/reasoning/review.py +659 -615
- package/core/reasoning/scholar.py +38 -14
- package/core/reasoning/source_corpus.py +110 -4
- package/core/replay.py +158 -26
- package/core/session.py +36 -12
- package/core/session_view.py +259 -0
- package/core/session_wake.py +259 -0
- package/core/shell_sessions.py +1553 -0
- package/core/workspace_trust.py +1 -1
- package/credentials.py +308 -180
- package/database.py +82 -1
- package/{PRIVACY.md → docs/PRIVACY.md} +19 -7
- package/docs/SECURITY.md +108 -0
- package/docs/THIRD_PARTY_NOTICES.md +148 -0
- package/env_secrets.py +118 -77
- package/json_store.py +236 -16
- package/logging_setup.py +121 -11
- package/main.py +1671 -199
- package/mcp_client/client.py +257 -23
- package/mcp_client/config.py +484 -379
- package/mcp_client/registration.py +163 -2
- package/memories/manager.py +15 -0
- package/memories/tui_commands.py +7 -12
- package/package.json +234 -4
- package/project_init/config_files.py +4 -0
- package/project_init/generator.py +201 -37
- package/project_init/manifest.py +418 -406
- package/project_init/tui_commands.py +7 -4
- package/prompts/revalidate.md +1 -1
- package/prompts/revise.md +17 -15
- package/prompts/system_prompts.py +64 -10
- package/providers.json.example +94 -92
- package/pyproject.toml +51 -2
- package/requirements.txt +252 -29
- package/safety/policy_enforcement.py +353 -17
- package/security/askpass.py +419 -0
- package/security/capability.py +37 -7
- package/security/confine.py +484 -0
- package/security/hosted.py +182 -0
- package/security/permissions.py +54 -7
- package/security/posture.py +124 -12
- package/security/protected_paths.py +198 -6
- package/security/sandbox.py +3262 -139
- package/security/secrets.py +855 -0
- package/skills/tui_commands.py +3 -4
- package/storage.py +368 -35
- package/tools/base.py +465 -305
- package/tools/builtin/_math_common.py +306 -16
- package/tools/builtin/_net_common.py +267 -61
- package/tools/builtin/arxiv.py +681 -223
- package/tools/builtin/ask_user.py +231 -213
- package/tools/builtin/discrete_math.py +35 -4
- package/tools/builtin/fetch_url.py +239 -21
- package/tools/builtin/file_ops.py +341 -33
- package/tools/builtin/geometry.py +184 -148
- package/tools/builtin/get_time.py +2 -2
- package/tools/builtin/linear_algebra.py +66 -23
- package/tools/builtin/load_skill.py +10 -0
- package/tools/builtin/logic.py +171 -12
- package/tools/builtin/pin.py +46 -12
- package/tools/builtin/probability_stats.py +224 -228
- package/tools/builtin/project_docs.py +80 -21
- package/tools/builtin/remember.py +21 -4
- package/tools/builtin/shell.py +586 -67
- package/tools/builtin/shell_sessions.py +613 -0
- package/tools/builtin/symbolic_math.py +80 -10
- package/tools/builtin/todo.py +5 -3
- package/tools/builtin/web_search.py +329 -151
- package/tools/context.py +23 -0
- package/tools/isolation.py +387 -314
- package/tools/registry.py +347 -30
- package/tui/app.py +4645 -438
- package/tui/app.tcss +185 -2
- package/tui/commands.py +10 -154
- package/tui/diffs.py +286 -265
- package/tui/hosted_driver.py +102 -0
- package/tui/markdown.py +60 -10
- package/tui/meters.py +103 -7
- package/tui/screens.py +346 -92
- package/tui/themes.py +59 -19
- package/tui/widgets.py +1575 -111
- package/SECURITY.md +0 -88
- package/THIRD_PARTY_NOTICES.md +0 -100
|
@@ -1,148 +1,184 @@
|
|
|
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
|
|
14
|
-
from
|
|
15
|
-
|
|
16
|
-
from tools.builtin._math_common import
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if
|
|
90
|
-
return {"error": "
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if len(pts)
|
|
98
|
-
return {"error": "
|
|
99
|
-
result =
|
|
100
|
-
elif op == "
|
|
101
|
-
if len(pts) <
|
|
102
|
-
return {"error":
|
|
103
|
-
if
|
|
104
|
-
return {"error": "
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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 pydantic import BaseModel, Field
|
|
14
|
+
from sympy.geometry import Circle, Line, Point, Polygon, Triangle
|
|
15
|
+
|
|
16
|
+
from tools.builtin._math_common import (
|
|
17
|
+
MathParseError,
|
|
18
|
+
_split_warnings,
|
|
19
|
+
parse_params,
|
|
20
|
+
safe_parse,
|
|
21
|
+
serialize,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
_OPERATIONS = Literal[
|
|
25
|
+
"distance", "midpoint", "is_collinear", "line_intersection",
|
|
26
|
+
"circle_area", "circle_circumference",
|
|
27
|
+
"polygon_area", "polygon_perimeter", "triangle_properties",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class GeometryParams(BaseModel):
|
|
32
|
+
operation: _OPERATIONS = Field(..., description="Which operation to perform")
|
|
33
|
+
points: Optional[list[list[str]]] = Field(
|
|
34
|
+
None, description="List of points, each as [x, y] coordinate strings (numbers or symbolic expressions)"
|
|
35
|
+
)
|
|
36
|
+
radius: Optional[str] = Field(None, description="Radius, for circle operations (required for circle_area/circle_circumference)")
|
|
37
|
+
center: Optional[list[str]] = Field(None, description="Center point [x, y] for circle operations - optional, defaults to [0, 0] (origin) when omitted")
|
|
38
|
+
evaluate: bool = Field(False, description="If true, return numeric approximation (e.g. 12.566... instead of 4*pi). Default false keeps exact symbolic form.")
|
|
39
|
+
precision: int = Field(15, ge=1, le=50, description="Significant digits when evaluate is true")
|
|
40
|
+
symbols: Optional[list[str]] = Field(
|
|
41
|
+
None,
|
|
42
|
+
description=(
|
|
43
|
+
"Multi-character symbol names used in the coordinates or radius, "
|
|
44
|
+
"e.g. ['mass', 'width']. Declare them or they are read as "
|
|
45
|
+
"products of single letters: 'mass' becomes a*m*s**2. Single "
|
|
46
|
+
"letters and names containing an underscore are safe without this."
|
|
47
|
+
),
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
TOOL_SCHEMA = {
|
|
52
|
+
"name": "geometry",
|
|
53
|
+
"description": (
|
|
54
|
+
"Classical geometry operations: distance and midpoint between "
|
|
55
|
+
"points, collinearity check, line intersection, circle area and "
|
|
56
|
+
"circumference, polygon area and perimeter, and triangle "
|
|
57
|
+
"properties (area, perimeter, right/equilateral/isosceles checks). "
|
|
58
|
+
"Circle operations default the center to the origin when not supplied; results are exact symbolic "
|
|
59
|
+
"expressions (e.g. 4*pi, sqrt(2)) unless 'evaluate' is true, which returns a numeric approximation with 'precision' digits."
|
|
60
|
+
),
|
|
61
|
+
"input_schema": GeometryParams.model_json_schema(),
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _to_point(coords: list[str], symbols=None, rewritten=None) -> Point:
|
|
66
|
+
return Point(*[safe_parse(c, symbols=symbols, rewritten=rewritten)
|
|
67
|
+
for c in coords])
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def run(params: dict) -> dict:
|
|
71
|
+
try:
|
|
72
|
+
parsed = parse_params(GeometryParams, params)
|
|
73
|
+
except MathParseError as e:
|
|
74
|
+
return {"error": str(e)}
|
|
75
|
+
# One `rewritten` set across every coordinate and the radius: this tool
|
|
76
|
+
# could not reach `symbols=` at all, so a multi-character coordinate was
|
|
77
|
+
# rewritten into a product of single letters (batch 131).
|
|
78
|
+
rewritten: set = set()
|
|
79
|
+
syms = parsed.symbols or None
|
|
80
|
+
|
|
81
|
+
def to_point(coords):
|
|
82
|
+
return _to_point(coords, syms, rewritten)
|
|
83
|
+
|
|
84
|
+
try:
|
|
85
|
+
op = parsed.operation
|
|
86
|
+
pts = [to_point(p) for p in parsed.points] if parsed.points else []
|
|
87
|
+
|
|
88
|
+
if op == "distance":
|
|
89
|
+
if len(pts) < 2:
|
|
90
|
+
return {"error": "distance requires 2 points (each [x, y])."}
|
|
91
|
+
result = pts[0].distance(pts[1])
|
|
92
|
+
elif op == "midpoint":
|
|
93
|
+
if len(pts) < 2:
|
|
94
|
+
return {"error": "midpoint requires 2 points (each [x, y])."}
|
|
95
|
+
result = pts[0].midpoint(pts[1])
|
|
96
|
+
elif op == "is_collinear":
|
|
97
|
+
if len(pts) < 2:
|
|
98
|
+
return {"error": "is_collinear requires at least 2 points."}
|
|
99
|
+
result = Point.is_collinear(*pts)
|
|
100
|
+
elif op == "line_intersection":
|
|
101
|
+
if len(pts) < 4:
|
|
102
|
+
return {"error": "line_intersection requires 4 points (two per line: [p0,p1] and [p2,p3])."}
|
|
103
|
+
if pts[0] == pts[1]:
|
|
104
|
+
return {"error": "line_intersection: the first two points must be distinct (first line is degenerate)."}
|
|
105
|
+
if pts[2] == pts[3]:
|
|
106
|
+
return {"error": "line_intersection: the last two points must be distinct (second line is degenerate)."}
|
|
107
|
+
line_a = Line(pts[0], pts[1])
|
|
108
|
+
line_b = Line(pts[2], pts[3])
|
|
109
|
+
result = line_a.intersection(line_b)
|
|
110
|
+
elif op == "circle_area":
|
|
111
|
+
if parsed.radius is None:
|
|
112
|
+
return {"error": "circle_area requires 'radius'."}
|
|
113
|
+
center = to_point(parsed.center) if parsed.center is not None else Point(0, 0)
|
|
114
|
+
result = Circle(center, safe_parse(parsed.radius, symbols=syms, rewritten=rewritten)).area
|
|
115
|
+
elif op == "circle_circumference":
|
|
116
|
+
if parsed.radius is None:
|
|
117
|
+
return {"error": "circle_circumference requires 'radius'."}
|
|
118
|
+
center = to_point(parsed.center) if parsed.center is not None else Point(0, 0)
|
|
119
|
+
result = Circle(center, safe_parse(parsed.radius, symbols=syms, rewritten=rewritten)).circumference
|
|
120
|
+
elif op == "polygon_area":
|
|
121
|
+
if len(pts) < 3:
|
|
122
|
+
return {"error": f"polygon_area requires at least 3 points (got {len(pts)})."}
|
|
123
|
+
# Pre-check collinear/degenerate that would surface as Segment2D
|
|
124
|
+
if len(pts) == 3 and Point.is_collinear(*pts):
|
|
125
|
+
return {"error": "polygon_area: degenerate polygon (collinear points) - at least 3 non-collinear points required."}
|
|
126
|
+
result = Polygon(*pts).area
|
|
127
|
+
elif op == "polygon_perimeter":
|
|
128
|
+
if len(pts) < 3:
|
|
129
|
+
return {"error": f"polygon_perimeter requires at least 3 points (got {len(pts)})."}
|
|
130
|
+
if len(pts) == 3 and Point.is_collinear(*pts):
|
|
131
|
+
return {"error": "polygon_perimeter: degenerate polygon (collinear points) - at least 3 non-collinear points required."}
|
|
132
|
+
result = Polygon(*pts).perimeter
|
|
133
|
+
elif op == "triangle_properties":
|
|
134
|
+
if len(pts) != 3:
|
|
135
|
+
return {"error": f"triangle_properties requires exactly 3 points (got {len(pts)})."}
|
|
136
|
+
if Point.is_collinear(*pts):
|
|
137
|
+
return {"error": "triangle_properties: degenerate triangle (collinear points) - Segment2D has no triangle properties."}
|
|
138
|
+
tri = Triangle(*pts)
|
|
139
|
+
if parsed.evaluate:
|
|
140
|
+
result = {
|
|
141
|
+
"area": str(tri.area.evalf(parsed.precision)),
|
|
142
|
+
"perimeter": str(tri.perimeter.evalf(parsed.precision)),
|
|
143
|
+
"is_right": tri.is_right(),
|
|
144
|
+
"is_equilateral": tri.is_equilateral(),
|
|
145
|
+
"is_isosceles": tri.is_isosceles(),
|
|
146
|
+
}
|
|
147
|
+
else:
|
|
148
|
+
result = {
|
|
149
|
+
"area": str(tri.area),
|
|
150
|
+
"perimeter": str(tri.perimeter),
|
|
151
|
+
"is_right": tri.is_right(),
|
|
152
|
+
"is_equilateral": tri.is_equilateral(),
|
|
153
|
+
"is_isosceles": tri.is_isosceles(),
|
|
154
|
+
}
|
|
155
|
+
else:
|
|
156
|
+
return {"error": f"Unknown operation: {op}"}
|
|
157
|
+
|
|
158
|
+
except MathParseError as e:
|
|
159
|
+
return {"error": str(e)}
|
|
160
|
+
except (IndexError, TypeError) as e:
|
|
161
|
+
return {"error": f"Missing or malformed points/parameters for '{op}': {e}"}
|
|
162
|
+
except Exception as e:
|
|
163
|
+
return {"error": f"Computation failed: {e}"}
|
|
164
|
+
|
|
165
|
+
# Numeric-evaluate path: keep exact by default, evaluate only when asked.
|
|
166
|
+
if parsed.evaluate and not isinstance(result, (bool, dict)):
|
|
167
|
+
try:
|
|
168
|
+
if isinstance(result, list):
|
|
169
|
+
result = [r.evalf(parsed.precision) if hasattr(r, "evalf") else r for r in result]
|
|
170
|
+
elif hasattr(result, "evalf"):
|
|
171
|
+
result = result.evalf(parsed.precision)
|
|
172
|
+
except Exception:
|
|
173
|
+
pass # no numeric form; the exact result is still a correct answer
|
|
174
|
+
|
|
175
|
+
# H6, one batch late (batch 143). The evaluate block above stays where it is: a tail
|
|
176
|
+
# handler contains the one call that can fail without restructuring the
|
|
177
|
+
# function around it, which is `discrete_math`'s shape.
|
|
178
|
+
try:
|
|
179
|
+
out: dict = {"result": serialize(result, what=op), "operation": op}
|
|
180
|
+
except MathParseError as e:
|
|
181
|
+
return {"error": str(e)}
|
|
182
|
+
if rewritten:
|
|
183
|
+
out["warnings"] = _split_warnings(rewritten)
|
|
184
|
+
return out
|
|
@@ -6,7 +6,7 @@ grounding "as of today" or "current events" style claims during research
|
|
|
6
6
|
passes without needing a network call.
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
-
from datetime import
|
|
9
|
+
from datetime import UTC, datetime
|
|
10
10
|
|
|
11
11
|
TOOL_SCHEMA = {
|
|
12
12
|
"name": "get_time",
|
|
@@ -16,5 +16,5 @@ TOOL_SCHEMA = {
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def run(params: dict) -> dict:
|
|
19
|
-
now = datetime.now(
|
|
19
|
+
now = datetime.now(UTC)
|
|
20
20
|
return {"utc_datetime": now.isoformat()}
|
|
@@ -13,7 +13,13 @@ from typing import Literal, Optional
|
|
|
13
13
|
import sympy
|
|
14
14
|
from pydantic import BaseModel, Field
|
|
15
15
|
|
|
16
|
-
from tools.builtin._math_common import
|
|
16
|
+
from tools.builtin._math_common import (
|
|
17
|
+
MathParseError,
|
|
18
|
+
_split_warnings,
|
|
19
|
+
parse_params,
|
|
20
|
+
safe_parse,
|
|
21
|
+
serialize,
|
|
22
|
+
)
|
|
17
23
|
|
|
18
24
|
_OPERATIONS = Literal[
|
|
19
25
|
"add", "subtract", "multiply", "transpose", "determinant",
|
|
@@ -33,6 +39,15 @@ class LinearAlgebraParams(BaseModel):
|
|
|
33
39
|
vector_a: Optional[list[str]] = Field(None, description="First vector -- needed for dot_product/cross_product/norm")
|
|
34
40
|
vector_b: Optional[list[str]] = Field(None, description="Second vector -- needed for dot_product/cross_product")
|
|
35
41
|
scalar: Optional[str] = Field(None, description="Scalar value, for scalar multiplication of matrix_a")
|
|
42
|
+
symbols: Optional[list[str]] = Field(
|
|
43
|
+
None,
|
|
44
|
+
description=(
|
|
45
|
+
"Multi-character symbol names used in the entries, e.g. "
|
|
46
|
+
"['mass', 'velocity']. Declare them or they are read as products "
|
|
47
|
+
"of single letters: 'mass' becomes a*m*s**2. Single letters and "
|
|
48
|
+
"names containing an underscore are safe without this."
|
|
49
|
+
),
|
|
50
|
+
)
|
|
36
51
|
|
|
37
52
|
|
|
38
53
|
TOOL_SCHEMA = {
|
|
@@ -49,16 +64,33 @@ TOOL_SCHEMA = {
|
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
|
|
52
|
-
def _to_matrix(rows: list[list[str]]) -> sympy.Matrix:
|
|
53
|
-
return sympy.Matrix([[safe_parse(cell
|
|
67
|
+
def _to_matrix(rows: list[list[str]], symbols=None, rewritten=None) -> sympy.Matrix:
|
|
68
|
+
return sympy.Matrix([[safe_parse(cell, symbols=symbols, rewritten=rewritten)
|
|
69
|
+
for cell in row] for row in rows])
|
|
54
70
|
|
|
55
71
|
|
|
56
|
-
def _to_vector(values: list[str]) -> sympy.Matrix:
|
|
57
|
-
return sympy.Matrix([safe_parse(v
|
|
72
|
+
def _to_vector(values: list[str], symbols=None, rewritten=None) -> sympy.Matrix:
|
|
73
|
+
return sympy.Matrix([safe_parse(v, symbols=symbols, rewritten=rewritten)
|
|
74
|
+
for v in values])
|
|
58
75
|
|
|
59
76
|
|
|
60
77
|
def run(params: dict) -> dict:
|
|
61
|
-
|
|
78
|
+
try:
|
|
79
|
+
parsed = parse_params(LinearAlgebraParams, params)
|
|
80
|
+
except MathParseError as e:
|
|
81
|
+
return {"error": str(e)}
|
|
82
|
+
# EVERY parsed field gets `symbols` and shares one `rewritten` set: this
|
|
83
|
+
# tool had no way to reach `symbols=` at all, so a multi-character entry
|
|
84
|
+
# was silently rewritten into a product of single letters and the answer
|
|
85
|
+
# named a different quantity (batch 131).
|
|
86
|
+
rewritten: set = set()
|
|
87
|
+
syms = parsed.symbols or None
|
|
88
|
+
|
|
89
|
+
def to_matrix(rows):
|
|
90
|
+
return _to_matrix(rows, syms, rewritten)
|
|
91
|
+
|
|
92
|
+
def to_vector(values):
|
|
93
|
+
return _to_vector(values, syms, rewritten)
|
|
62
94
|
|
|
63
95
|
try:
|
|
64
96
|
op = parsed.operation
|
|
@@ -66,80 +98,81 @@ def run(params: dict) -> dict:
|
|
|
66
98
|
if op == "add":
|
|
67
99
|
if parsed.matrix_a is None or parsed.matrix_b is None:
|
|
68
100
|
return {"error": "add requires 'matrix_a' and 'matrix_b' (each a list of rows)."}
|
|
69
|
-
result =
|
|
101
|
+
result = to_matrix(parsed.matrix_a) + to_matrix(parsed.matrix_b)
|
|
70
102
|
elif op == "subtract":
|
|
71
103
|
if parsed.matrix_a is None or parsed.matrix_b is None:
|
|
72
104
|
return {"error": "subtract requires 'matrix_a' and 'matrix_b' (each a list of rows)."}
|
|
73
|
-
result =
|
|
105
|
+
result = to_matrix(parsed.matrix_a) - to_matrix(parsed.matrix_b)
|
|
74
106
|
elif op == "multiply":
|
|
75
107
|
if parsed.matrix_a is None:
|
|
76
108
|
return {"error": "multiply requires 'matrix_a'."}
|
|
77
|
-
a =
|
|
109
|
+
a = to_matrix(parsed.matrix_a)
|
|
78
110
|
if parsed.scalar is not None:
|
|
79
|
-
result = safe_parse(parsed.scalar
|
|
111
|
+
result = safe_parse(parsed.scalar, symbols=syms,
|
|
112
|
+
rewritten=rewritten) * a
|
|
80
113
|
else:
|
|
81
114
|
if parsed.matrix_b is None:
|
|
82
115
|
return {"error": "multiply requires 'matrix_b' or 'scalar'."}
|
|
83
|
-
result = a *
|
|
116
|
+
result = a * to_matrix(parsed.matrix_b)
|
|
84
117
|
elif op == "transpose":
|
|
85
118
|
if parsed.matrix_a is None:
|
|
86
119
|
return {"error": "transpose requires 'matrix_a'."}
|
|
87
|
-
result =
|
|
120
|
+
result = to_matrix(parsed.matrix_a).T
|
|
88
121
|
elif op == "determinant":
|
|
89
122
|
if parsed.matrix_a is None:
|
|
90
123
|
return {"error": "determinant requires 'matrix_a'."}
|
|
91
|
-
m =
|
|
124
|
+
m = to_matrix(parsed.matrix_a)
|
|
92
125
|
if m.rows != m.cols:
|
|
93
126
|
return {"error": f"determinant requires a square matrix (got {m.rows}x{m.cols})."}
|
|
94
127
|
result = m.det()
|
|
95
128
|
elif op == "inverse":
|
|
96
129
|
if parsed.matrix_a is None:
|
|
97
130
|
return {"error": "inverse requires 'matrix_a'."}
|
|
98
|
-
m =
|
|
131
|
+
m = to_matrix(parsed.matrix_a)
|
|
99
132
|
if m.rows != m.cols:
|
|
100
133
|
return {"error": f"inverse requires a square matrix (got {m.rows}x{m.cols})."}
|
|
101
134
|
result = m.inv()
|
|
102
135
|
elif op == "eigenvalues":
|
|
103
136
|
if parsed.matrix_a is None:
|
|
104
137
|
return {"error": "eigenvalues requires 'matrix_a'."}
|
|
105
|
-
m =
|
|
138
|
+
m = to_matrix(parsed.matrix_a)
|
|
106
139
|
if m.rows != m.cols:
|
|
107
140
|
return {"error": f"eigenvalues requires a square matrix (got {m.rows}x{m.cols})."}
|
|
108
141
|
result = m.eigenvals()
|
|
109
142
|
elif op == "eigenvectors":
|
|
110
143
|
if parsed.matrix_a is None:
|
|
111
144
|
return {"error": "eigenvectors requires 'matrix_a'."}
|
|
112
|
-
m =
|
|
145
|
+
m = to_matrix(parsed.matrix_a)
|
|
113
146
|
if m.rows != m.cols:
|
|
114
147
|
return {"error": f"eigenvectors requires a square matrix (got {m.rows}x{m.cols})."}
|
|
115
148
|
result = m.eigenvects()
|
|
116
149
|
elif op == "rank":
|
|
117
150
|
if parsed.matrix_a is None:
|
|
118
151
|
return {"error": "rank requires 'matrix_a'."}
|
|
119
|
-
result =
|
|
152
|
+
result = to_matrix(parsed.matrix_a).rank()
|
|
120
153
|
elif op == "solve_linear_system":
|
|
121
154
|
if parsed.matrix_a is None or parsed.matrix_b is None:
|
|
122
155
|
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 =
|
|
124
|
-
b =
|
|
156
|
+
a = to_matrix(parsed.matrix_a)
|
|
157
|
+
b = to_matrix(parsed.matrix_b)
|
|
125
158
|
if a.rows != b.rows:
|
|
126
159
|
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
160
|
result = a.solve(b)
|
|
128
161
|
elif op == "dot_product":
|
|
129
162
|
if parsed.vector_a is None or parsed.vector_b is None:
|
|
130
163
|
return {"error": "dot_product requires 'vector_a' and 'vector_b'."}
|
|
131
|
-
result =
|
|
164
|
+
result = to_vector(parsed.vector_a).dot(to_vector(parsed.vector_b))
|
|
132
165
|
elif op == "cross_product":
|
|
133
166
|
if parsed.vector_a is None or parsed.vector_b is None:
|
|
134
167
|
return {"error": "cross_product requires 'vector_a' and 'vector_b'."}
|
|
135
|
-
va, vb =
|
|
168
|
+
va, vb = to_vector(parsed.vector_a), to_vector(parsed.vector_b)
|
|
136
169
|
if len(va) != 3 or len(vb) != 3:
|
|
137
170
|
return {"error": "cross_product requires 3-dimensional vectors"}
|
|
138
171
|
result = va.cross(vb)
|
|
139
172
|
elif op == "norm":
|
|
140
173
|
if parsed.vector_a is None:
|
|
141
174
|
return {"error": "norm requires 'vector_a'."}
|
|
142
|
-
result =
|
|
175
|
+
result = to_vector(parsed.vector_a).norm()
|
|
143
176
|
else:
|
|
144
177
|
return {"error": f"Unknown operation: {op}"}
|
|
145
178
|
|
|
@@ -152,4 +185,14 @@ def run(params: dict) -> dict:
|
|
|
152
185
|
return {"error": "Computation failed: determinant/inverse/eigen requires a square matrix — the supplied matrix is not square."}
|
|
153
186
|
return {"error": f"Computation failed: {e}"}
|
|
154
187
|
|
|
155
|
-
|
|
188
|
+
# H6, one batch late (batch 143). `determinant([["factorial(3000)","0"],["0","1"]])` is a
|
|
189
|
+
# correct answer this call could not print, and the ValueError left
|
|
190
|
+
# `run()` for dispatch's containment -- the branch reserved for a real
|
|
191
|
+
# bug. See `_math_common.serialize`.
|
|
192
|
+
try:
|
|
193
|
+
out: dict = {"result": serialize(result, what=op), "operation": op}
|
|
194
|
+
except MathParseError as e:
|
|
195
|
+
return {"error": str(e)}
|
|
196
|
+
if rewritten:
|
|
197
|
+
out["warnings"] = _split_warnings(rewritten)
|
|
198
|
+
return out
|
|
@@ -55,6 +55,16 @@ def run(params: dict) -> dict:
|
|
|
55
55
|
# and persisted no tool_result for the tool_use id. An error dict
|
|
56
56
|
# lets the model see what it got wrong and correct itself, which is
|
|
57
57
|
# what the unknown-name branch two lines down already does.
|
|
58
|
+
#
|
|
59
|
+
# THE ONE OF THESE WRITTEN IN THE PAST TENSE, and therefore the one
|
|
60
|
+
# that stayed true: four siblings said the same thing in the PRESENT
|
|
61
|
+
# tense, and dispatch() has contained a handler's exception since
|
|
62
|
+
# well before they were written. The last two clauses are the
|
|
63
|
+
# precise ones -- the parallel path converts a raise into THIS call's
|
|
64
|
+
# error result so the siblings' finished work and the tool_use id's
|
|
65
|
+
# reply both survive. tools/base.py carries the one copy of all of it
|
|
66
|
+
# now, including the half none of these mentioned: a GATE's raise is
|
|
67
|
+
# not contained (batch 146).
|
|
58
68
|
name = params.get("name")
|
|
59
69
|
if not name:
|
|
60
70
|
return {"error": "load_skill requires a 'name' -- the skill's name "
|