@yahyahammad/venastine 0.1.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.
Files changed (130) hide show
  1. package/.env.example +19 -14
  2. package/CONFIG_ARCHITECTURE.md +2002 -0
  3. package/NOTICE +1 -1
  4. package/README.md +249 -93
  5. package/agents/builtin/build.md +73 -0
  6. package/agents/builtin/general.md +80 -0
  7. package/agents/builtin/plan.md +23 -5
  8. package/agents/builtin/test.md +65 -0
  9. package/agents/builtin/writer.md +67 -0
  10. package/agents/manager.py +261 -195
  11. package/agents/subagent_tool.py +280 -23
  12. package/agents/tui_commands.py +31 -21
  13. package/bin/venastine.mjs +528 -382
  14. package/bin/venastine.py +71 -0
  15. package/cli_commands.py +835 -0
  16. package/config.py +95 -1198
  17. package/config.yaml +1090 -0
  18. package/config_edit.py +1301 -0
  19. package/config_schema.py +966 -0
  20. package/config_update.py +749 -0
  21. package/core/agent_activity.py +256 -0
  22. package/core/ansi.py +452 -0
  23. package/core/approval.py +27 -5
  24. package/core/call_view.py +364 -0
  25. package/core/cancel.py +121 -0
  26. package/core/chatgpt_auth.py +747 -0
  27. package/core/claims_view.py +107 -0
  28. package/core/client.py +1249 -82
  29. package/core/commands.py +454 -0
  30. package/core/compaction.py +1735 -959
  31. package/core/config_loader.py +516 -97
  32. package/core/connect.py +686 -0
  33. package/core/events.py +68 -6
  34. package/core/file_mentions.py +280 -0
  35. package/core/interaction.py +87 -4
  36. package/core/line_pattern.py +128 -0
  37. package/core/loop.py +2566 -1353
  38. package/core/memory.py +482 -370
  39. package/core/pipeline_models.py +23 -9
  40. package/core/provider_errors.py +234 -0
  41. package/core/reasoning/confidence_scoring.py +70 -54
  42. package/core/reasoning/json_retry.py +19 -1
  43. package/core/reasoning/orchestrator.py +232 -53
  44. package/core/reasoning/output_writer.py +90 -31
  45. package/core/reasoning/payload_validation.py +133 -7
  46. package/core/reasoning/pipeline_storage.py +427 -361
  47. package/core/reasoning/review.py +659 -615
  48. package/core/reasoning/scholar.py +38 -14
  49. package/core/reasoning/source_corpus.py +110 -4
  50. package/core/replay.py +315 -167
  51. package/core/session.py +36 -12
  52. package/core/session_view.py +259 -0
  53. package/core/session_wake.py +259 -0
  54. package/core/shell_sessions.py +1553 -0
  55. package/core/workspace_trust.py +1 -1
  56. package/credentials.py +308 -180
  57. package/database.py +82 -1
  58. package/{PRIVACY.md → docs/PRIVACY.md} +19 -7
  59. package/docs/SECURITY.md +108 -0
  60. package/docs/THIRD_PARTY_NOTICES.md +148 -0
  61. package/env_secrets.py +118 -77
  62. package/json_store.py +236 -16
  63. package/logging_setup.py +121 -11
  64. package/main.py +1672 -198
  65. package/mcp_client/client.py +257 -23
  66. package/mcp_client/config.py +484 -379
  67. package/mcp_client/registration.py +163 -2
  68. package/memories/manager.py +15 -0
  69. package/memories/tui_commands.py +21 -14
  70. package/package.json +303 -73
  71. package/project_init/config_files.py +4 -0
  72. package/project_init/generator.py +201 -37
  73. package/project_init/manifest.py +418 -406
  74. package/project_init/tui_commands.py +7 -4
  75. package/prompts/revalidate.md +1 -1
  76. package/prompts/revise.md +17 -15
  77. package/prompts/system_prompts.py +64 -10
  78. package/providers.json.example +94 -92
  79. package/pyproject.toml +149 -100
  80. package/requirements.txt +252 -29
  81. package/safety/policy_enforcement.py +1082 -682
  82. package/security/askpass.py +419 -0
  83. package/security/capability.py +37 -7
  84. package/security/confine.py +484 -0
  85. package/security/hosted.py +182 -0
  86. package/security/permissions.py +54 -7
  87. package/security/posture.py +124 -12
  88. package/security/protected_paths.py +198 -6
  89. package/security/sandbox.py +3262 -139
  90. package/security/secrets.py +855 -0
  91. package/skills/tui_commands.py +3 -4
  92. package/storage.py +1338 -1005
  93. package/tools/base.py +465 -305
  94. package/tools/builtin/_math_common.py +306 -16
  95. package/tools/builtin/_net_common.py +267 -61
  96. package/tools/builtin/arxiv.py +681 -223
  97. package/tools/builtin/ask_user.py +231 -213
  98. package/tools/builtin/discrete_math.py +35 -4
  99. package/tools/builtin/fetch_url.py +239 -21
  100. package/tools/builtin/file_ops.py +341 -33
  101. package/tools/builtin/geometry.py +184 -148
  102. package/tools/builtin/get_time.py +2 -2
  103. package/tools/builtin/linear_algebra.py +66 -23
  104. package/tools/builtin/load_skill.py +10 -0
  105. package/tools/builtin/logic.py +171 -12
  106. package/tools/builtin/pin.py +46 -12
  107. package/tools/builtin/probability_stats.py +224 -228
  108. package/tools/builtin/project_docs.py +80 -21
  109. package/tools/builtin/remember.py +21 -4
  110. package/tools/builtin/shell.py +586 -67
  111. package/tools/builtin/shell_sessions.py +613 -0
  112. package/tools/builtin/symbolic_math.py +80 -10
  113. package/tools/builtin/todo.py +5 -3
  114. package/tools/builtin/web_search.py +329 -151
  115. package/tools/context.py +23 -0
  116. package/tools/isolation.py +387 -314
  117. package/tools/registry.py +374 -29
  118. package/tui/app.py +5281 -397
  119. package/tui/app.tcss +290 -9
  120. package/tui/commands.py +26 -61
  121. package/tui/diffs.py +286 -265
  122. package/tui/history.py +128 -0
  123. package/tui/hosted_driver.py +102 -0
  124. package/tui/markdown.py +1329 -0
  125. package/tui/meters.py +364 -0
  126. package/tui/screens.py +346 -92
  127. package/tui/themes.py +599 -366
  128. package/tui/widgets.py +2673 -116
  129. package/SECURITY.md +0 -88
  130. 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 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}
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 datetime, timezone
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(timezone.utc)
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 safe_parse, serialize, MathParseError
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) for cell in row] for row in rows])
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) for v in values])
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
- parsed = LinearAlgebraParams(**params)
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 = _to_matrix(parsed.matrix_a) + _to_matrix(parsed.matrix_b)
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 = _to_matrix(parsed.matrix_a) - _to_matrix(parsed.matrix_b)
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 = _to_matrix(parsed.matrix_a)
109
+ a = to_matrix(parsed.matrix_a)
78
110
  if parsed.scalar is not None:
79
- result = safe_parse(parsed.scalar) * a
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 * _to_matrix(parsed.matrix_b)
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 = _to_matrix(parsed.matrix_a).T
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 = _to_matrix(parsed.matrix_a)
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 = _to_matrix(parsed.matrix_a)
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 = _to_matrix(parsed.matrix_a)
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 = _to_matrix(parsed.matrix_a)
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 = _to_matrix(parsed.matrix_a).rank()
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 = _to_matrix(parsed.matrix_a)
124
- b = _to_matrix(parsed.matrix_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 = _to_vector(parsed.vector_a).dot(_to_vector(parsed.vector_b))
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 = _to_vector(parsed.vector_a), _to_vector(parsed.vector_b)
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 = _to_vector(parsed.vector_a).norm()
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
- return {"result": serialize(result), "operation": op}
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 "