@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,228 +1,224 @@
|
|
|
1
|
-
"""
|
|
2
|
-
tools/builtin/probability_stats.py
|
|
3
|
-
|
|
4
|
-
Descriptive statistics on raw data (using the stdlib `statistics` module
|
|
5
|
-
-- deterministic, no need for sympy here) and probability distributions
|
|
6
|
-
(using sympy.stats, kept exact/symbolic where possible).
|
|
7
|
-
|
|
8
|
-
Named probability_stats rather than statistics.py specifically to avoid
|
|
9
|
-
any reader confusion with the stdlib module of the same name, even though
|
|
10
|
-
Python 3's absolute-import default would resolve `import statistics`
|
|
11
|
-
correctly regardless.
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
from __future__ import annotations
|
|
15
|
-
|
|
16
|
-
import statistics as pystats
|
|
17
|
-
from typing import Literal, Optional
|
|
18
|
-
|
|
19
|
-
import sympy
|
|
20
|
-
import sympy.stats as sstats
|
|
21
|
-
from pydantic import BaseModel, Field
|
|
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
|
-
"are
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return sstats.
|
|
98
|
-
if name == "
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
"
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
"
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if parsed.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
out: dict = {"result": result, "operation": parsed.operation}
|
|
226
|
-
if warnings:
|
|
227
|
-
out["warnings"] = warnings
|
|
228
|
-
return out
|
|
1
|
+
"""
|
|
2
|
+
tools/builtin/probability_stats.py
|
|
3
|
+
|
|
4
|
+
Descriptive statistics on raw data (using the stdlib `statistics` module
|
|
5
|
+
-- deterministic, no need for sympy here) and probability distributions
|
|
6
|
+
(using sympy.stats, kept exact/symbolic where possible).
|
|
7
|
+
|
|
8
|
+
Named probability_stats rather than statistics.py specifically to avoid
|
|
9
|
+
any reader confusion with the stdlib module of the same name, even though
|
|
10
|
+
Python 3's absolute-import default would resolve `import statistics`
|
|
11
|
+
correctly regardless.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import statistics as pystats
|
|
17
|
+
from typing import Literal, Optional
|
|
18
|
+
|
|
19
|
+
import sympy
|
|
20
|
+
import sympy.stats as sstats
|
|
21
|
+
from pydantic import BaseModel, Field
|
|
22
|
+
|
|
23
|
+
from tools.builtin._math_common import MathParseError, parse_params
|
|
24
|
+
|
|
25
|
+
_OPERATIONS = Literal["describe", "distribution_stats", "distribution_pdf", "distribution_cdf"]
|
|
26
|
+
_DISTRIBUTIONS = Literal["normal", "binomial", "poisson", "uniform", "exponential"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ProbabilityStatsParams(BaseModel):
|
|
30
|
+
operation: _OPERATIONS = Field(..., description="Which operation to perform")
|
|
31
|
+
data: Optional[list[float]] = Field(None, description="Dataset, for the 'describe' operation")
|
|
32
|
+
distribution: Optional[_DISTRIBUTIONS] = Field(
|
|
33
|
+
None, description="Distribution family, for distribution_* operations"
|
|
34
|
+
)
|
|
35
|
+
distribution_params: Optional[dict[str, float]] = Field(
|
|
36
|
+
None,
|
|
37
|
+
description=(
|
|
38
|
+
"Parameters for the chosen distribution: normal={mu, sigma}, "
|
|
39
|
+
"binomial={n, p}, poisson={lambda}, uniform={a, b}, "
|
|
40
|
+
"exponential={rate}"
|
|
41
|
+
),
|
|
42
|
+
)
|
|
43
|
+
x: Optional[float] = Field(None, description="Point to evaluate pdf/cdf at")
|
|
44
|
+
evaluate: bool = Field(False, description="If true, return numeric approximation (evalf) instead of exact symbolic form (e.g. 0.84... instead of erf(...)). Default false keeps exact symbolic.")
|
|
45
|
+
precision: int = Field(15, ge=1, le=50, description="Significant digits when evaluate is true")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
TOOL_SCHEMA = {
|
|
49
|
+
"name": "probability_stats",
|
|
50
|
+
"description": (
|
|
51
|
+
"Compute descriptive statistics on a dataset (mean, median, "
|
|
52
|
+
"variance, stdev, min, max), or work with probability "
|
|
53
|
+
"distributions (normal, binomial, poisson, uniform, exponential): "
|
|
54
|
+
"expected value, variance, pdf at a point, or cdf at a point. "
|
|
55
|
+
"Results are exact symbolic expressions (e.g. erf(...), sqrt(pi)) unless 'evaluate' is true, "
|
|
56
|
+
"which returns a numeric approximation with 'precision' digits. When distribution parameters "
|
|
57
|
+
"are omitted, defaults are used (normal mu=0 sigma=1, uniform a=0 b=1, exponential rate=1) and a "
|
|
58
|
+
"'warnings' field explains what was defaulted."
|
|
59
|
+
),
|
|
60
|
+
"input_schema": ProbabilityStatsParams.model_json_schema(),
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _build_distribution_with_warnings(name: str, dp_orig: Optional[dict]):
|
|
65
|
+
"""Build distribution and collect warnings for defaulted params.
|
|
66
|
+
|
|
67
|
+
Returns (dist, warnings). Warnings is a list of strings for each param
|
|
68
|
+
that fell back to a default, per decision 2 (keep forgiving but explain).
|
|
69
|
+
Binomial/poisson have no defaults — missing required keys become a
|
|
70
|
+
friendly error at the caller, not a warning.
|
|
71
|
+
|
|
72
|
+
THE ONE BUILDER (#208). A warning-free twin, `_build_distribution`, sat
|
|
73
|
+
above this with no caller and the same five distributions and defaults,
|
|
74
|
+
so a change to one would have left the other silently wrong. It is
|
|
75
|
+
deleted; a caller that wants no warnings takes `[0]` of this.
|
|
76
|
+
"""
|
|
77
|
+
dp = dp_orig or {}
|
|
78
|
+
warnings: list[str] = []
|
|
79
|
+
if name == "normal":
|
|
80
|
+
if "mu" not in dp:
|
|
81
|
+
warnings.append("mu not supplied - defaulted to 0")
|
|
82
|
+
if "sigma" not in dp:
|
|
83
|
+
warnings.append("sigma not supplied - defaulted to 1")
|
|
84
|
+
return sstats.Normal("X", dp.get("mu", 0), dp.get("sigma", 1)), warnings
|
|
85
|
+
if name == "uniform":
|
|
86
|
+
if "a" not in dp:
|
|
87
|
+
warnings.append("a not supplied - defaulted to 0")
|
|
88
|
+
if "b" not in dp:
|
|
89
|
+
warnings.append("b not supplied - defaulted to 1")
|
|
90
|
+
return sstats.Uniform("X", dp.get("a", 0), dp.get("b", 1)), warnings
|
|
91
|
+
if name == "exponential":
|
|
92
|
+
if "rate" not in dp:
|
|
93
|
+
warnings.append("rate not supplied - defaulted to 1")
|
|
94
|
+
return sstats.Exponential("X", dp.get("rate", 1)), warnings
|
|
95
|
+
if name == "binomial":
|
|
96
|
+
# No defaults — caller validates presence
|
|
97
|
+
return sstats.Binomial("X", int(dp["n"]), dp["p"]), warnings
|
|
98
|
+
if name == "poisson":
|
|
99
|
+
return sstats.Poisson("X", dp["lambda"]), warnings
|
|
100
|
+
raise ValueError(f"Unsupported distribution: {name}")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _maybe_evalf(value, do_eval: bool, precision: int):
|
|
104
|
+
if not do_eval or value is None:
|
|
105
|
+
return value
|
|
106
|
+
try:
|
|
107
|
+
if hasattr(value, "evalf"):
|
|
108
|
+
return value.evalf(precision)
|
|
109
|
+
except Exception:
|
|
110
|
+
pass # no numeric form; the exact value is still a correct answer
|
|
111
|
+
return value
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _cdf_at(dist, x):
|
|
115
|
+
"""Evaluate CDF at x, handling discrete binomial's dict return."""
|
|
116
|
+
try:
|
|
117
|
+
return sstats.cdf(dist)(x)
|
|
118
|
+
except TypeError as e:
|
|
119
|
+
if "'dict' object is not callable" in str(e):
|
|
120
|
+
# Binomial (and some discretes) return a dict table via two-arg form
|
|
121
|
+
table = sstats.cdf(dist, x)
|
|
122
|
+
if isinstance(table, dict):
|
|
123
|
+
import math
|
|
124
|
+
|
|
125
|
+
try:
|
|
126
|
+
# Discrete CDF at x is sum up to floor(x)
|
|
127
|
+
key = int(math.floor(float(x)))
|
|
128
|
+
except Exception:
|
|
129
|
+
return table
|
|
130
|
+
if key in table:
|
|
131
|
+
return table[key]
|
|
132
|
+
# find greatest key <= x
|
|
133
|
+
sorted_keys = sorted(table.keys())
|
|
134
|
+
candidate = None
|
|
135
|
+
for k in sorted_keys:
|
|
136
|
+
if k <= key:
|
|
137
|
+
candidate = table[k]
|
|
138
|
+
else:
|
|
139
|
+
break
|
|
140
|
+
if candidate is not None:
|
|
141
|
+
return candidate
|
|
142
|
+
if key < sorted_keys[0]:
|
|
143
|
+
return sympy.Integer(0)
|
|
144
|
+
return sympy.Integer(1)
|
|
145
|
+
return table
|
|
146
|
+
raise
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def run(params: dict) -> dict:
|
|
150
|
+
try:
|
|
151
|
+
parsed = parse_params(ProbabilityStatsParams, params)
|
|
152
|
+
except MathParseError as e:
|
|
153
|
+
return {"error": str(e)}
|
|
154
|
+
|
|
155
|
+
try:
|
|
156
|
+
if parsed.operation == "describe":
|
|
157
|
+
data = parsed.data
|
|
158
|
+
if not data:
|
|
159
|
+
return {"error": "data is required for 'describe'"}
|
|
160
|
+
result = {
|
|
161
|
+
"mean": pystats.mean(data),
|
|
162
|
+
"median": pystats.median(data),
|
|
163
|
+
"stdev": pystats.stdev(data) if len(data) > 1 else 0.0,
|
|
164
|
+
"variance": pystats.variance(data) if len(data) > 1 else 0.0,
|
|
165
|
+
"min": min(data),
|
|
166
|
+
"max": max(data),
|
|
167
|
+
"n": len(data),
|
|
168
|
+
}
|
|
169
|
+
return {"result": result, "operation": parsed.operation}
|
|
170
|
+
|
|
171
|
+
if not parsed.distribution:
|
|
172
|
+
return {"error": "distribution is required for this operation"}
|
|
173
|
+
|
|
174
|
+
dp = parsed.distribution_params or {}
|
|
175
|
+
# Friendly validation for distributions with no defaults
|
|
176
|
+
if parsed.distribution == "binomial":
|
|
177
|
+
if "n" not in dp or "p" not in dp:
|
|
178
|
+
return {"error": "binomial requires 'n' (number of trials) and 'p' (success probability) in distribution_params."}
|
|
179
|
+
if parsed.distribution == "poisson":
|
|
180
|
+
if "lambda" not in dp:
|
|
181
|
+
return {"error": "poisson requires 'lambda' in distribution_params."}
|
|
182
|
+
|
|
183
|
+
dist, warnings = _build_distribution_with_warnings(parsed.distribution, parsed.distribution_params)
|
|
184
|
+
|
|
185
|
+
if parsed.operation == "distribution_stats":
|
|
186
|
+
mean_v = _maybe_evalf(sstats.E(dist), parsed.evaluate, parsed.precision)
|
|
187
|
+
var_v = _maybe_evalf(sstats.variance(dist), parsed.evaluate, parsed.precision)
|
|
188
|
+
# std is sqrt(var) — eval the sqrt when numeric
|
|
189
|
+
raw_var = sstats.variance(dist)
|
|
190
|
+
std_v = _maybe_evalf(sympy.sqrt(raw_var), parsed.evaluate, parsed.precision)
|
|
191
|
+
result = {
|
|
192
|
+
"mean": str(mean_v),
|
|
193
|
+
"variance": str(var_v),
|
|
194
|
+
"std": str(std_v),
|
|
195
|
+
}
|
|
196
|
+
elif parsed.operation == "distribution_pdf":
|
|
197
|
+
if parsed.x is None:
|
|
198
|
+
return {"error": "x is required for distribution_pdf"}
|
|
199
|
+
x_arg = parsed.x
|
|
200
|
+
# Discrete distributions expect int; float 5.0 should be treated as 5
|
|
201
|
+
if parsed.distribution in ("binomial", "poisson") and isinstance(x_arg, float) and x_arg.is_integer():
|
|
202
|
+
x_arg = int(x_arg)
|
|
203
|
+
raw = sstats.density(dist)(x_arg)
|
|
204
|
+
val = _maybe_evalf(raw, parsed.evaluate, parsed.precision)
|
|
205
|
+
result = str(val)
|
|
206
|
+
elif parsed.operation == "distribution_cdf":
|
|
207
|
+
if parsed.x is None:
|
|
208
|
+
return {"error": "x is required for distribution_cdf"}
|
|
209
|
+
x_arg = parsed.x
|
|
210
|
+
if parsed.distribution in ("binomial", "poisson") and isinstance(x_arg, float) and x_arg.is_integer():
|
|
211
|
+
x_arg = int(x_arg)
|
|
212
|
+
raw = _cdf_at(dist, x_arg)
|
|
213
|
+
val = _maybe_evalf(raw, parsed.evaluate, parsed.precision)
|
|
214
|
+
result = str(val)
|
|
215
|
+
else:
|
|
216
|
+
return {"error": f"Unknown operation: {parsed.operation}"}
|
|
217
|
+
|
|
218
|
+
except Exception as e:
|
|
219
|
+
return {"error": f"Computation failed: {e}"}
|
|
220
|
+
|
|
221
|
+
out: dict = {"result": result, "operation": parsed.operation}
|
|
222
|
+
if warnings:
|
|
223
|
+
out["warnings"] = warnings
|
|
224
|
+
return out
|
|
@@ -52,13 +52,25 @@ right for `packages/foo/package.json` in a monorepo and wrong for
|
|
|
52
52
|
source lives, and it is the one place these five are not this project's own
|
|
53
53
|
statement about itself.
|
|
54
54
|
|
|
55
|
-
THE RESIDUAL
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
THE RESIDUAL THAT WAS STATED HERE IS CLOSED, and what is left of the
|
|
56
|
+
paragraph is the part that was always the point. `check_output_policy` scans
|
|
57
|
+
every value (#47), so `sk-ant-...`, `ghp_...`, `AKIA...` and a PEM header
|
|
58
|
+
are redacted out of a result. A plaintext `<password>` element, a Gradle
|
|
59
|
+
`password "..."` and a `user:token@host` URL were NOT, and those are the
|
|
60
|
+
credential shapes that occur in exactly these five files -- so they were
|
|
61
|
+
filed against the REDACTOR rather than fixed here, because a pattern added
|
|
62
|
+
there redacts content out of every tool result in the harness and one added
|
|
63
|
+
here would serve one tool.
|
|
64
|
+
|
|
65
|
+
That filing is #167, closed 2026-08-23: `safety/policy_enforcement.py` now
|
|
66
|
+
carries `_URL_USERINFO_RE`, `_XML_PASSWORD_RE` and `_ASSIGNMENT_RE`, whose
|
|
67
|
+
`[ \t]` alternative is there for Gradle's space form specifically. All
|
|
68
|
+
three shapes are redacted out of a `read_project_doc` result today, driven
|
|
69
|
+
on all four file types, with a credential-free document passing through
|
|
70
|
+
byte-identical as the control. This paragraph went on claiming the leak for
|
|
71
|
+
seven weeks after the leak was fixed, which is why it now names the issue
|
|
72
|
+
and the patterns: a security residual that reads as OPEN costs every later
|
|
73
|
+
reader what it cost the reader who re-measured it (batch 146).
|
|
62
74
|
"""
|
|
63
75
|
|
|
64
76
|
from __future__ import annotations
|
|
@@ -69,6 +81,7 @@ from typing import Optional
|
|
|
69
81
|
|
|
70
82
|
import config
|
|
71
83
|
from core import config_loader, workspace_trust
|
|
84
|
+
from json_store import write_text_atomic
|
|
72
85
|
from security import protected_paths
|
|
73
86
|
|
|
74
87
|
logger = logging.getLogger(__name__)
|
|
@@ -100,6 +113,13 @@ _ROOT_ONLY_FILENAMES = frozenset({
|
|
|
100
113
|
_DENIED_SEGMENTS = (protected_paths.PROTECTED_SEGMENTS
|
|
101
114
|
| {".git", "node_modules", ".venv", "venv",
|
|
102
115
|
"__pycache__", ".pytest_cache"})
|
|
116
|
+
|
|
117
|
+
#: And compared the way the FILESYSTEM will compare them (batch 146),
|
|
118
|
+
#: through the one spelling of the fold that `protected_segment` uses. This
|
|
119
|
+
#: set unioned the segment list in and then compared it case-sensitively,
|
|
120
|
+
#: so the two consumers of one fact disagreed about the only thing left to
|
|
121
|
+
#: disagree about. `.VENASTINE/agents/foo.md` was a readable `.md`.
|
|
122
|
+
_DENIED_FOLDED = protected_paths.folded_segments(_DENIED_SEGMENTS)
|
|
103
123
|
_DENIED_FILENAMES = frozenset({"providers.json"})
|
|
104
124
|
|
|
105
125
|
#: Re-exported so callers name one constant. The name lives in
|
|
@@ -153,7 +173,7 @@ def _resolve_in_project(root: str, user_path: str) -> Optional[str]:
|
|
|
153
173
|
def _is_readable_doc(root: str, resolved: str) -> bool:
|
|
154
174
|
rel = os.path.relpath(resolved, root)
|
|
155
175
|
parts = rel.split(os.sep)
|
|
156
|
-
if any(segment in
|
|
176
|
+
if any(segment.casefold() in _DENIED_FOLDED for segment in parts):
|
|
157
177
|
return False
|
|
158
178
|
name = os.path.basename(resolved).lower()
|
|
159
179
|
if name in _DENIED_FILENAMES or name.startswith(".env"):
|
|
@@ -239,9 +259,12 @@ def _skip(handle, offset: int) -> None:
|
|
|
239
259
|
|
|
240
260
|
|
|
241
261
|
def read_run(params: dict) -> dict:
|
|
242
|
-
# params.get throughout, not params[]
|
|
243
|
-
#
|
|
244
|
-
#
|
|
262
|
+
# params.get throughout, not params[]. tools/base.py carries the one
|
|
263
|
+
# copy of why, under "WHAT A CALLABLE REGISTERED BELOW MAY RAISE": a
|
|
264
|
+
# handler's exception IS contained, so the reason this is right is that
|
|
265
|
+
# an error dict the model can read beats the generic wrapper it would
|
|
266
|
+
# get -- not the turn-ending raise six comments in this directory used
|
|
267
|
+
# to claim (batch 146).
|
|
245
268
|
root = _project_root()
|
|
246
269
|
if root is None:
|
|
247
270
|
return {"error": "read_project_doc: no project directory has been "
|
|
@@ -283,7 +306,7 @@ def read_run(params: dict) -> dict:
|
|
|
283
306
|
# streams, so the offset is walked rather than jumped: correctness
|
|
284
307
|
# over cleverness, and it still holds one chunk rather than the file.
|
|
285
308
|
try:
|
|
286
|
-
with open(resolved,
|
|
309
|
+
with open(resolved, encoding="utf-8", errors="replace") as f:
|
|
287
310
|
_skip(f, offset)
|
|
288
311
|
chunk = f.read(config.INIT_READ_CHARS)
|
|
289
312
|
more = f.read(1) != ""
|
|
@@ -361,10 +384,22 @@ def approval_notice(params: dict, context) -> str:
|
|
|
361
384
|
"""
|
|
362
385
|
root = _project_root()
|
|
363
386
|
name = params.get("name") or HUB_FILENAME
|
|
364
|
-
where = doc_path(root, name) if root else name
|
|
365
387
|
size = len(params.get("content") or "")
|
|
366
|
-
|
|
367
|
-
|
|
388
|
+
if not root:
|
|
389
|
+
return f"Create {name} ({size} characters)."
|
|
390
|
+
|
|
391
|
+
# RESOLVED, so the consent can never name a file the bytes will not
|
|
392
|
+
# land on (batch 146). `_project_root()` is already a realpath, so for
|
|
393
|
+
# an ordinary document this is the same string the join produced and
|
|
394
|
+
# the prompt is unchanged; where it differs, the difference IS the
|
|
395
|
+
# thing the person needs to see.
|
|
396
|
+
resolved = _resolve_in_project(root, name)
|
|
397
|
+
if resolved is None:
|
|
398
|
+
return (f"REFUSE {doc_path(root, name)} ({size} characters): that "
|
|
399
|
+
f"name resolves outside the project, so write_project_doc "
|
|
400
|
+
f"will not write it.")
|
|
401
|
+
verb = "Overwrite" if os.path.exists(resolved) else "Create"
|
|
402
|
+
return f"{verb} {resolved} ({size} characters)."
|
|
368
403
|
|
|
369
404
|
|
|
370
405
|
def write_run(params: dict) -> dict:
|
|
@@ -393,13 +428,37 @@ def write_run(params: dict) -> dict:
|
|
|
393
428
|
f"maximum writable size "
|
|
394
429
|
f"({config.MAX_FILE_SIZE_BYTES} bytes)."}
|
|
395
430
|
|
|
431
|
+
# RESOLVED BEFORE WRITING, which the read path has always done and this
|
|
432
|
+
# one did not (batch 146). The module's invariant is that the
|
|
433
|
+
# destination is derived from a name "so it cannot be aimed elsewhere",
|
|
434
|
+
# and a document name that is a LINK aims it elsewhere: a cloned project
|
|
435
|
+
# carrying `ARCHITECTURE.md -> ~/.bashrc` took the bytes to the link
|
|
436
|
+
# target, under a consent that named the in-project path. git stores
|
|
437
|
+
# symlinks natively, so the layout needs no privilege to arrive.
|
|
438
|
+
#
|
|
439
|
+
# An error rather than a coercion, in the sense the unknown-name branch
|
|
440
|
+
# above means: a name that leaves the project is not one of this
|
|
441
|
+
# project's documents.
|
|
396
442
|
destination = doc_path(root, name)
|
|
443
|
+
resolved = _resolve_in_project(root, name)
|
|
444
|
+
if resolved is None:
|
|
445
|
+
logger.warning("write_project_doc refused %s: resolves outside the "
|
|
446
|
+
"project", destination)
|
|
447
|
+
return {"error": f"write_project_doc: {name!r} resolves outside the "
|
|
448
|
+
f"project directory, so it is not one of this "
|
|
449
|
+
f"project's documents."}
|
|
450
|
+
|
|
397
451
|
try:
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
452
|
+
# REPLACES THE NAME RATHER THAN WRITING THROUGH IT, which closes the
|
|
453
|
+
# half `realpath` cannot see: a hardlink is not a link to anything,
|
|
454
|
+
# so the resolution above admits one. And `newline=""`, so the bytes
|
|
455
|
+
# the model supplied are the bytes that land -- this tool is the one
|
|
456
|
+
# write path in the harness reachable with no config edit, and its
|
|
457
|
+
# whole purpose is to overwrite a document in place, under an
|
|
458
|
+
# approval that was shown a diff of the lines that changed.
|
|
459
|
+
write_text_atomic(resolved, content)
|
|
401
460
|
except OSError as e:
|
|
402
|
-
logger.warning("write_project_doc failed for %s: %s",
|
|
403
|
-
return {"error": f"Could not write {
|
|
461
|
+
logger.warning("write_project_doc failed for %s: %s", resolved, e)
|
|
462
|
+
return {"error": f"Could not write {resolved}: {e}"}
|
|
404
463
|
|
|
405
|
-
return {"result": f"Wrote {len(content)} characters to {
|
|
464
|
+
return {"result": f"Wrote {len(content)} characters to {resolved}"}
|